Guest User

Untitled

a guest
Aug 17th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.
  2. _____________________________________
  3.  
  4. ## General rules
  5. 1. Follow standard conventions.
  6. 2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  7. 3. Boy scout rule. Leave the campground cleaner than you found it.
  8. 4. Always find root cause. Always look for the root cause of a problem.
  9.  
  10. ## Design rules
  11. 1. Keep configurable data at high levels.
  12. 2. Prefer polymorphism to if/else or switch/case.
  13. 3. Separate multi-threading code.
  14. 4. Prevent over-configurability.
  15. 5. Use dependency injection.
  16. 6. Follow Law of Demeter. A class should know only its direct dependencies.
  17.  
  18. ## Understandability tips
  19. 1. Be consistent. If you do something a certain way, do all similar things in the same way.
  20. 2. Use explanatory variables.
  21. 3. Encapsulate boundary conditions. Boundary conditions are hard to keep track of. Put the processing for them in one place.
  22. 4. Prefer dedicated value objects to primitive type.
  23. 5. Avoid logical dependency. Don't write methods which works correctly depending on something else in the same class.
  24. 6. Avoid negative conditionals.
  25.  
  26. ## Names rules
  27. 1. Choose descriptive and unambiguous names.
  28. - They are a powerful tool, use them communicate with others.
  29. 2. Make meaningful distinction.
  30. - Always communicate your intent, if you have to put a comment, your name is a bad one.
  31. 3. Avoid disinformation
  32. - A name must says what it means, and means what it says
  33. - Remember, people will have to talk about your code
  34. 4. Use pronounceable names
  35. - If you have to read the code to understand the meaning, it's a bad name.
  36. 5. Avoid encoding.
  37. - Encodings are distracting. They obfuscate the code. They make it hard to read
  38. - No Hungarian Notation, "m_", "p_"
  39. 6. Clean code should always read like well-written prose
  40. - Classes: noun
  41. - Variables: nouns
  42. - Methods: Verb names. If they're Booleans, make them predicates.
  43. - Make sure that when you write a line of code, it looks like and reads like a sentence.
  44. 7. Scope rule
  45. - Variable names: short, even one letter, if they're in a tiny little scope, but variable names should be long if they're in a big long scope.
  46. - Function names: short if they've got a long scope. Long and descriptive, if they have a short scope.
  47. - Classes names. Short names for public classes. Longer names for private classes in tiny scopes.
Add Comment
Please, Sign In to add comment