Recently READ Clean Code English original, two years into the line, it is time to gradually improve their Code quality (to avoid being mocked like XX Code), take this as a memory, to spur myself to strive to like a serious program girl!

About the name

  1. Elegant code: Passes all tests without repeating as few entities as possible, such as classes, methods, functions, etc
  2. The naming principle is worthy of the name: the specific meaning and type expressed by the name are clear to avoid misleading: avoid using fields with special meaning, avoid using similar names to cause misleading meaningful distinction: although productInfo and productData have different names, they do not distinguish
  3. Use readable names for easy searching
  4. Avoid coding
  5. Class or object names should use nouns or noun phrases, not verbs
  6. Method names should use verbs or phrasal verbs, prefixed by get set is if necessary
  7. Avoid puns, such as insert or append instead of add when inserting elements into an array
  8. Add meaningful contexts and avoid meaningless ones

About functions (methods)

  1. Short,
  2. Do one thing and do it well
  3. One level of abstraction per function, read the rules from the top down
  4. Open Closed principle: Software entities should be extensible, not modifiable. That is, open for extension and closed for modification.
  5. Use descriptive names and don’t be afraid to use long names
  6. Use as few parameters as possible, avoid using more than three parameters, try to convert binary parameters into unitary, if you have to pass multiple parameters, try to encapsulate them as an object.
  7. No side effects, reduced coupling, especially timing coupling
  8. Separate instructions and queries, that is, querying information about an object and modifying information about an object should be separated
  9. Replace return error code with an exception, and eliminate duplicate code by separating error handling from the main function path
  10. Structured programming principles: top-down, step-by-step refinement; Clarity first, efficiency second; Write standard, indent format; Basic structure, combined.
  11. Don’t be afraid to refactor your code

Only for reference, welcome all god criticism and correction, small woman in this thank!