Home > Article > Backend Development > Should PHP function names use Hungarian notation?
No, Hungarian nomenclature is not recommended. Although it can improve readability, it will cause code redundancy, reduce maintainability, and violate the clear and concise style of modern programming languages. Alternatives include using meaningful names, type hints, and documentation comments.
#PHP Function Naming: Should I use Hungarian notation?
Introduction
Hungarian nomenclature is a naming convention that requires that the names of variables, functions, and classes include information about their data types or other attributes. . This convention is intended to improve code readability and maintainability.
Advantages
Disadvantages
Practical case
Suppose we have a function named calculate_area
, which calculates the area of a rectangle. Using Hungarian nomenclature, the function can be named:
function calculate_area_int($width, $height) { // ... }
In this example, the _int
suffix means that the width
and height
parameters are integers type.
Alternatives
Alternatives to Hungarian nomenclature include:
rectangle_width
and rectangle_area
. Conclusion
Although Hungarian nomenclature has certain advantages in improving readability, its shortcomings are often more obvious. Modern programming languages promote a clear and concise coding style, which is contrary to the Hungarian nomenclature. Therefore, alternatives such as meaningful names, type hints, and documentation comments are recommended.
The above is the detailed content of Should PHP function names use Hungarian notation?. For more information, please follow other related articles on the PHP Chinese website!