Let’s explore the importance of naming conventions for functions and variables.
Functions:
"The larger the scope, the shorter the function name."
A function used across a wide scope is likely called frequently throughout the codebase. These functions should have abstract, concise names that are easy to understand and remember.
"The smaller the scope, the longer the function name."
Functions with a smaller scope often perform a specific role. Their names should clearly express their intent, as they don’t occur often in the code and require more descriptive identifiers to enhance readability.
Variables:
"The larger the scope, the longer the variable name."
For variables in a large scope, descriptive names are crucial to maintain clarity and prevent confusion. For instance:
· const d; // What does 'd' mean?
· const shippingDays; // Clear and self-explanatory
Short variable names like d can make the code harder to understand and maintain, especially when used throughout a large codebase.
"The smaller the scope, the shorter the variable name."
Within smaller scopes (like inside a single function), shorter variable names are acceptable since their purpose is immediately apparent from the context.
Takeaway:
hashtag#FunctionNaming: The larger the scope, the shorter the name.
hashtag#VariableNaming: The larger the scope, the longer the name.
Adhering to these conventions not only improves code readability but also ensures better maintainability.
Top comments (0)