Home >Backend Development >C++ >C++ function naming: Comparison of Hungarian notation and naming conventions
C Comparison of function naming conventions: Hungarian notation and naming conventions. Hungarian notation indicates types through variable name prefixes, which enhances readability but is verbose; naming conventions use more concise names to improve readability. Hungarian notation enforces type checking, which improves maintainability but can be confusing; the naming convention is more flexible. Hungarian notation has better reusability but poorer naming convention.
C Function Naming: Comparison of Hungarian Notation and Naming Conventions
Introduction
Function naming is crucial to maintaining a clear, maintainable code base. Two popular naming conventions are provided in C: Hungarian notation and naming conventions. This article will compare these two methods and provide practical examples to illustrate their differences.
Hungarian notation
Hungarian notation indicates the variable type by adding a prefix before the variable name. For example, iAge
represents an integer age variable, and sName
represents a string type name variable.
Naming convention
Naming convention uses a more general naming convention. It is recommended to use:
ageInYears
). AgeInYears
). Practical case
The following two functions demonstrate the violation of Hungarian notation and naming conventions:
Hungarian notation
int getAge(int iAge) { return iAge; }
Naming convention (camel case)
int getAgeInYears(int ageInYears) { return ageInYears; }
Comparison
Conclusion
Hungarian notation and naming conventions each have their own advantages and disadvantages. The final choice depends on the specific needs of the project and the developer's personal preferences.
The above is the detailed content of C++ function naming: Comparison of Hungarian notation and naming conventions. For more information, please follow other related articles on the PHP Chinese website!