Naming classes such as "com.facebook.FacebookClient" and "com.facebook.Client"

I am looking for opinions, or if there is an agreed way to do this, regarding naming classes with names.

eg:.

com.facebook.FacebookClient vs com.facebook.Client 

or

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

I currently prefer the first name in each example, but the extra word seems a little wasteful.

+4
source share
6 answers

Using ActionScript as an example, I would say FacebookClient on the client. For this reason:

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

You will need to reference the class in its full package to create an instance in the same class:

 new com.facebook.Client(); 

If it was FacebookClient, I could have

 new FacebookClient(); new TwitterClient(); 

Plus, the client will annoy me when the completion code appears. Extra click to select the correct Client;)

+6
source

Usually I use something like:

<company name]. [the name of the project]. [functional area]. [category]

i.e.

com.dave.megaproject.dataaccesslayer.postcodelookup

or in the .net world:

namespace DaveFirm.MegaProject.DataAccessLayer.PostCodeLookup

+3
source

Are there other types of clients in the facebook domain? Are there other types of engines in the javax.script domain? Most likely they will want in the future? If so, you need something to distinguish them. Otherwise, it may be a lost space.

Of course, the future is almost not necessary.

0
source

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

0
source

In a language where the class name and file name are one-to-one, there is an argument that must be created for namespacing the class name, regardless of the package. Many people search for files by class name, opening a file called <class>.java or using the "Quick Open" in their IDE. An extra bit of mental obstruction to decide which Client.java you need may be annoying enough that you appreciate the extra naming convention.

And it simplifies reading and is not pleasant in any modern editor (for example, vi or higher) that you ever needed to print it several times (sometimes even more than once).

0
source

I will use the extra word in FacebookClient style every time just because the more descriptive the smallest form of a name is, the easier it is to find links to that name in multi-threaded search queries.

0
source

Source: https://habr.com/ru/post/1311785/


All Articles