【Foreword】
There has always been a bit of code cleanliness. I use strict camel case for file names, interface names, class names, method names, etc., but sometimes I hesitate to distinguish between uppercase letters and underscores.
Brief summary and stipulation today
【Details】
1. File name
The file name uses the big camel case naming method uniformly, that is, the first letter of all words is capitalized, such as: UserLoginController.php
2. Class name
The class name also uses the big camel case nomenclature, and the length should be controlled within five words as much as possible. If the logical description is good, the abbreviated form is used, such as: class Account, class RealNameVerify.
3. Class method name
The class method name uses the small camel case notation, that is, the first word is all lowercase, and the first letter of the following words is all uppercase, and the first letter describes the operation type as much as possible, such as: getUserInfo, updateGameConfig, bindPhone.
For private methods of classes, they should start with a single underscore, such as: _guestLogin
4. Class member variables and method variables
Although many people advocate that class member variables start with m, it is customary for all variables to be defined in the form of lowercase letters and underscores, such as: gamerepository, gamerepository, table_config, $return_data.
5. Class constants, global constants
For constants, use all uppercase letters and connect words with underscores, such as: PAYMENT_METHOD_TTBANK.
【expand】
By the way, let’s talk about a better variable naming method:
1. Member variables start with m, such as: mTable,mTable,mUrl
2. Static variables start with s, such as: sCount,sCount,sStatus
3. Global variables start with g, such as: $gConnectTime
【end】
Last but not least, there is no absolute best naming convention, only the most suitable naming convention for the team. The specific and detailed naming convention should be changed according to the framework used and the specific project background.
But a unified, clear, and simple naming convention is very useful for project development and maintenance.