- Class NameOneTwo
- Class Name
-
2. class library naming Currently, namespaces are becoming more and more widely used to avoid class name conflicts between different vendors and group class libraries. When namespace is not used, to avoid class name conflicts, the general practice is to add a unique prefix before the class name, the two characters can be used, of course, it will be better to use more. For example:
- John Johnson's data structure class library can use Jj as the prefix, as shown below:
- Class JjLinkList
- {
- }
3. method naming The same rule as the class naming rule also serves to interpret the method using English words. For example:
- Class NameOneTwo
- {
- Function DoIt (){};
- Function HandleError (){};
- }
4. class attribute naming The attribute name should be prefixed with the character'm. The prefix 'M' follows the same class naming rule. 'M' always acts as a modifier at the beginning of the name, just like a reference starting with 'R. The prefix 'M' prevents any conflicts between class attributes and method names. Your method name and attribute name are often very similar, especially for accessing elements. For example:
- Class NameOneTwo
- {
- Function VarAbc (){};
- Function ErrorNumber (){};
- Var mVarAbc;
- Var mErrorNumber;
- Var mrName;
- }
5. name parameters in the method The first character uses lowercase letters. All words after the first character are capitalized according to the class naming rules. In this way, you can know which variable corresponds to which variable at any time. In addition, you can use a name similar to the class name without duplicate name conflicts. For example:
- Class NameOneTwo
- {
- Function StartYourEngines (
- & $ RSomeEngine,
- & $ RAnotherEngine );
- }
6. variable naming All letters are in lower case. Use '_' as the boundary of each word. In many php tutorials, I have done this. In this way, the scope of variables in the code is clear. All variables look different in the code and are easy to identify. For example:
- Function HandleError ($ errorNumber)
- {
- $ Error = OsErr ();
- $ Time_of_error = OsErr-> getTimeOfError;
- $ Error_processor = OsErr-> getErrorProcessor;
- }
7. global variable naming The global variable must have the prefix 'G '. It is very important to know the scope of a variable. For example:
- Global $ gLog;
- Global & $ grLog;
8. function naming The function name follows the c gnu convention. all letters use lowercase letters and '_' to separate words. This makes it easier to distinguish the names of associated classes. For example:
- Function some_bloody_function ()
- {
- }
|