Coding standard are common patterns we follow while writing our application. This makes our code consistent across application. This is quite useful when multiple developers are working on the same application. A few coding standards are as follows:
- Naming Conventions: It is extremely important to have consistent naming conventions for our filename, class name, and so on. This is essential from the maintainability and readability point of view. This also helps in understanding the code faster, and debugging becomes easier.
- Filename: The recommended pattern for a filename in Angular is feature.type.ts. For example, the name of the authentication component file is
authentication.component.ts
. - Class name: The class name follows the camel case and takes the name from the filename. For example, the class name for the authentication component file is
AuthenticationComponent
. - Method and properties name: We follow camel case to name our class method and properties. We don't prefix private variables with an underscore.
- Selector name: The selector name in a component is hyphenated, and all characters are in lowercase. The name of our login component is shown here:
selector: 'app-friends-login'
Pipe name: Pipes are named after their features. For example, the currency pipe name is'currency'
, as follows:name: 'currency'
- Filename: The recommended pattern for a filename in Angular is feature.type.ts. For example, the name of the authentication component file is
- Constant: The constant is the final variable that is declared using the const keyword, and the constant value is assigned once. Constant variables are declared in uppercase, as follows:
export const USER_DETAILS_CHILD = 'user-details';
- Members sequence: All member variables are declared first, followed by the method. Private members are named after public members.