views:

87

answers:

6

I'm looking for opinions or if there is an agreed way of doing this, regarding to naming namespaced classes.

E.g.:

com.facebook.FacebookClient
vs
com.facebook.Client

Or

javax.script.ScriptEngine;
vs
javax.script.Engine;

I'm currently prefer the first name in each example but the extra word seems a bit wasteful.

+6  A: 

Using Actionscript as an example, I'd say FacebookClient over Client. For this reason:

import com.facebook.Client;
import com.twitter.Client;

You'd have to refer to the class by it's full package to create an instance in the same class:

new com.facebook.Client();

If it was FacebookClient, I could have both

new FacebookClient();
new TwitterClient();

Plus Client would be annoying to me when code completion pops up. An extra click to select the correct Client ;)

Typeoneerror
Optimizing for an edge case usually ends up being a bad idea in the long run. I would use Client and then re-factor (or simply wrap) in the event that their was need for more descriptive name.
sal
Probably true in the long run, but it's a pretty subjective question. I prefer clarity over optimization when the optimization is so trivial.
Typeoneerror
A: 

Does the facebook domain have other kinds of clients? Does the javax.script domain have other kinds of engines? Are they likely to want to in future? If so, you need something to differentiate them. Otherwise it might be wasted space.

Of course, the future is almost never certain.

walkytalky
A: 

The only thing I have to add is if you were to use using directives in C#. If you had two namespaces with the same method names like client then there would be a confict/confusion.

Dustin Laine
This conflict can easily be handled using aliases though.
Fredrik Mörk
@Fredrik: Definitely great point! Thanks
Dustin Laine
+3  A: 

I generally go with something like:

[company name].[project name].[functional area].[category]

i.e.

com.dave.megaproject.dataaccesslayer.postcodelookup

or in the .net world:

namespace DaveFirm.MegaProject.DataAccessLayer.PostCodeLookup

DaveRead
A: 

In a language where class name and filename are one-to-one, there's an argument to be made for namespacing the classname, regardless of the package. I lot of people locate files by classname, either by opening the file named <class>.java or by use of a "Quick Open" in their IDE. The extra bit of mental hurdling to decide which Client.java you need can be enough of an annoyance that you appreciate the extra naming.

And, it makes things easier to read and it's not like in any modern editor (e.g. vi or greater) you ever need to type it out more than once (sometimes not even once).

davetron5000
A: 

I'll go with the FacebookClient style extra-word every time just because the more descriptive the smallest form of the name is, the easier it is to find references to that name in multifile searches.

bucketmouse