Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming conventions of composed package names

I want to create a package named form validator.

Is it better to write

  • form_validator,
  • formValidator or
  • formvalidator?

I want to mention that I want to avoid form.validator. And that form-validator is forbidden.

like image 954
Mohamed Taboubi Avatar asked Apr 18 '18 03:04

Mohamed Taboubi


People also ask

What are the naming conventions of packages?

Naming ConventionsPackage names are written in all lower case to avoid conflict with the names of classes or interfaces. Companies use their reversed Internet domain name to begin their package names—for example, com. example. mypackage for a package named mypackage created by a programmer at example.com .

Should package names be singular or plural?

singular just like database table names should always be singular but for different reasons. Look at any popular standard library like Java or Python for example.

Can package name CamelCase?

The package names do not follow camel casing or underscores or hyphens package naming convention.


4 Answers

From the documentation on package naming convention:

Package names are written in all lower case to avoid conflict with the names of classes or interfaces

So this would leave you with the following two possibilities:

form_validator
formvalidator

Actually the documentation also makes it clear that underscore plays a special role when it appears in package names:

if the package name begins with a digit or other character that is illegal to use as the beginning of a Java name, or if the package name contains a reserved Java keyword, such as "int" ... the suggested convention is to add an underscore.

So, underscore is suggested only in special cases, into which your naming problem does not seem to fall. So I would recommend formvalidator as the package name.

like image 115
Tim Biegeleisen Avatar answered Oct 07 '22 20:10

Tim Biegeleisen


The most conventional one would be the 3rd one: formvalidator.

The Google Java Style guide notes:

5.2.1 Package names

Package names are all lowercase, with consecutive words simply concatenated together (no underscores). For example, com.example.deepspace, not com.example.deepSpace or com.example.deep_space.

As @teppic said, the Oracle Java Docs state that

Package names are written in all lower case to avoid conflict with the names of classes or interfaces.

like image 26
srath Avatar answered Oct 07 '22 20:10

srath


In Java package names are written in all lower case. Which means following would be the most ideal packaging name.

formvalidator

This is also accepted.

form_validator 
like image 6
Dulith De Costa Avatar answered Oct 07 '22 19:10

Dulith De Costa


Package names are written in all lower case to avoid conflict with the names of classes or interfaces. So

  • form_validator or
  • formvalidator.

For details see here.

like image 4
Rafiqul Hasan Avatar answered Oct 07 '22 20:10

Rafiqul Hasan