C Function naming rules have evolved from the classic "Hungarian notation" to modern descriptive naming. Modern rules include: use meaningful names, abstract, avoid prefixes, use camelCase, and consider namespaces. Modern naming is more readable and descriptive compared to the classic rules, for example "sum(int first, int second)" is clearer than "AddNumbers(int nNum1, int nNum2)".
The evolution of C function naming rules
Introduction
Function naming is C A key style guide in programming. Good function naming can improve the readability and maintainability of code. Over time, C's function naming conventions have changed.
Classic Naming Rules
Early versions of C adopted "Hungarian notation", in which a prefix identifier indicates the type and scope of a variable. For example:
int nCount; char* szName;
Modern Naming Rules
In recent years, the C community has moved toward more readable and descriptive function naming. Modern rules follow these principles:
sumNumbers()
, not Sum_numbers()
. Practical
Classic naming rules:
int AddNumbers(int nNum1, int nNum2) { // ... }
Modern naming rules:
int sum(int first, int second) { // ... }
The modern version is more descriptive and the code is more readable.
Advantages of CamelCase Nomenclature
CamelCase nomenclature is more consistent with natural language than underline nomenclature and reduces cognitive load. For example, the function get_count()
is not as easy to read as getCount()
.
Conclusion
C's function naming rules have evolved from classic Hungarian notation to modern descriptive naming. By following modern rules, you can write code that is easier to read and maintain.
The above is the detailed content of The evolution of C++ function naming rules. For more information, please follow other related articles on the PHP Chinese website!