Naming Conventions
Among the things that matter greatly in programming is writing elegant, or clean, code. One of the things that helps you have elegant and clean code is following naming conventions. In programming, you can use various methods to name classes, variables, and so on. Naming conventions follow the standard principles below:
camelCase
The camelCase method, also known as camel notation. In this method, the first word starts with a lowercase letter and the other words start with an uppercase letter, while their remaining letters are lowercase; in this method there is no separator between words.
Example:
camelCase, userId, lastOnline
PascalCase
In the PascalCase method, all words start with an uppercase letter and their remaining letters are lowercase. In this method there is no separator between words.
Example:
PascalCase, NewObject, UserTypes
snake_case
The snake_case method, also known as snake notation. In this method, all letters are lowercase and words are separated by an underscore ( _ ).
Example:
snake_case, first_name, contact_us
SCREAMING_SNAKE_CASE
A variant of snake notation in which all letters are written in uppercase.
Example:
SCREAMING_SNAKE_CASE, PI_NUMBER, WAIT_FOR_ACCEPT
kebab-case
The kebab-case method, also known as kebab notation. In this method, all letters are lowercase and words are separated by a dash ( - ).
Namespaces do not support this naming method, which is why you cannot use it to name packages. In general, according to the naming conventions defined in Jalno, this method is not used anywhere.
Example:
kebab-case, read-only
Using any of the methods above in programming is generally a matter of preference, but to keep your code consistent it is recommended that you use specific rules for naming each parameter.
You can follow the conventions below to keep your code consistent.
| Parameter | Naming Method | Example |
|---|---|---|
| Class | PascalCase | BankAccount |
| Interface | PascalCase, starting with I | ITemplate |
| Abstract classes | PascalCase, ending with Abstract. | SessionAbstract |
| Method | camelCase | doLogin |
| Package | snake_case | my_package |
| Database table and column names | snake_case | userpanel_users |
| Constant | SCREAMING_SNAKE_CASE | PI_NUMBER |
A few important points
- Controller names should generally be used in the plural form.
- Model names should generally be used in the singular form.
- Database table names should generally be used in the plural form.
- Define at most one class/interface/Trait per file, and the file name must be exactly the same as its name.