Meaningful names and functions
Name:
- It takes a long time to select a good name, but it saves more time. If a better name is found, replace the old one.
- Avoid misleading --- for example, using accountlist to reference a group of accounts
- Use the read name --- for example, genymdhms (generation date, year, month, day, hour, minute, second). How can this be read ??
- Class Name --- class name and object name should be a noun or noun phrase, such as customer, wikipage, account, avoid using class names such as manager, processor, date.
- Method Name --- the method name should be a verb or verb phrase.
Function:
- Short-the first rule is short, and the second rule is short.
- Only do one thing-the function should do one thing; do it well; only do this thing;
- Each function has an abstract level-read code from top to bottom: downward rule
- Swith statement --- it is difficult to write short switch statements. If you cannot avoid using a switch, place it in a lower abstract level and only appear once.
- Use descriptive name ---
- Don't be afraid of long names. Long and descriptive names are better than short and confusing names.
- Long and descriptive names are better than descriptive long comments.
- Using a naming convention makes it easy to read multiple words in a function name;
- Don't be afraid to get a name for a long time. This will help you sort out the design ideas about the module;
- The naming method must be consistent, such as includesetupandteardownpages, includesetuppages, and includesuitesetuppage.
- Function parameters ---
- The ideal parameter is zero, followed by one, followed by two, and avoided as much as possible. Unless you have special reasons, do not use more than three.
- Do not use the identification parameter to input a Boolean value to the function, that is, the function does more than one thing. If it is true, false will certainly not do this. For example, render (Boolean issuite) has a little help, But you should split it into two. renderforsuite () and renderforsingletest ()
- No side effects ---
- The side effect is that you are lying. The function promises to do only one thing, but it will still do other things that are hidden.
- Do not repeat yourself