Guest User

Untitled

a guest
Jun 19th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. # Generic Code Review Checklist
  2.  
  3. 1. Encapsulate conditional
  4.  
  5. ```js
  6. //bad
  7. if (person.age > 21 && person.hasCar && person.hasHouse) {
  8. //marry him
  9. }
  10.  
  11. //good
  12. function isEligibleBachelor(person) {
  13. return person.age > 21 && person.hasCar && person.hasHouse;
  14. }
  15.  
  16. if (isEligibleBachelor(person)) {
  17. //marry him
  18. }
  19. ```
  20.  
  21. 1. Avoid negative conditionals
  22.  
  23. ```java
  24. //bad
  25. public boolean isCatNotGrumpy() {
  26. //...
  27. }
  28.  
  29. if (!isCatNotGrumpy()) {
  30. //avoid the claws!
  31. }
  32.  
  33. //good
  34. public boolean isCatGrumpy() {
  35. //...
  36. }
  37.  
  38. if(isCatGrumpy()) {
  39. //avoid the claws
  40. }
  41. ```
  42.  
  43. 1. Remove dead code
  44.  
  45. ```js
  46. //bad
  47. // function prepareForBattle() {
  48. // buyArmor();
  49. // equipArmor();
  50. // sharpenWeapon();
  51. // makePactWithDevil();
  52. // }
  53. ```
Add Comment
Please, Sign In to add comment