Guest User

Untitled

a guest
Mar 24th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.79 KB | None | 0 0
  1. What I look for when I do a code review:
  2.  
  3. __FOCUS__
  4. - Methods should do one thing and do that thing well.
  5. - Name methods and variables well. This is simple to do and most developers mess this up. A name is not a big deal until
  6. someone in a hurry needs to get context on a problem fast. For example: handler(), process(), flag, temp, all will only hurt.
  7. - Methods that group operations together and run them in a specific order should be named appropriately.
  8. - Each line in a method should do 1 thing.
  9. - Ternary operations are OK if they are simple and pass the glance test. If someone has to look at the code for more than 1 second to figure out what is going on it should be broken up right away.
  10. - Keep in mind in prod when a stack trace generates a line and it lands on ternary that is two different cases that will have to be considered. Code should be written such that a glance can yeild high amount of information regarding the issue.
  11. - An if statement ought to be accompanied by an else or an explicit return, if for nothing else but for testing purposes.
  12.  
  13. __Simplicity__
  14. - Fight hard to keep the code simple.
  15. - Fight any and all attempts to make the code more complex in the name of "performance". Rarely does the trade off between readability and performance pay off.
  16. - Avoid for loops or while loops to iterate over collections. Use `each`, `map`, etc.
  17. - Performance for the sake of performance is evil. Do not trade readability over performance unless the gain is orders of magnitude AND monetizable. Do not make useless things fast.
  18. - In ruby you don't need Parans, but use them liberally when readability is enhanced. Ex Large Math Equations that are mission critical. Wrapped method calls, parans can help reveal the order of operations.
  19. - Move complex boolean logic into methods with revealing names. Something like `disabled?` is far better
  20. `((expired == true && end_date < Time.now) || access_revoked == true)`
  21. - Avoid deep nesting. 3 levels is pushing it.
  22.  
  23. __HARDCODES__
  24. - No magic numbers or strings
  25. - Do not hardcode in values directly into production codebase. This style of coding if fine while prototyping or debugging but not for production.
  26.  
  27. __DELETE WITHOUT MERCY__
  28. - Remove all code that is unreachable
  29. - Remove comments that help describe code, the code should be readable without comments
  30. - Remove dead comments (yes this is a real thing)
  31. - Remove commented out code
  32. - Kill TODO comments, Comments regarding unfinished or broken code. All that is noise. Move into a tracking system or simply remove.
  33.  
  34. __COMMENTS__
  35. - Long paragraphs in the code are a smell.
  36. - Tech talk to be avoided in comments. Do not use terms like "stack", "map" etc. Communicate in terms of business process.
  37. - Comments should describe INTENT. Focus on what is to be achieved and NOT the code is doing.
  38. - Comments should summarize (as simple as possible ) what the process is.
  39. - OLD OUTDATED COMMENTS CAUSE MORE HARM THEN MISSING COMMENTS (Best of to avoid them or keep it super short).
  40. - NO marker commments. `Not quiet done` (two years old) OR `This is a hack and needs to be fixed` .
  41.  
  42.  
  43. __CONST__
  44. - When comparing always put constants on the left side of the comparison
  45.  
  46. __return__
  47. - Please try to limit returns to one per method/function
  48. - Sometimes it makes use to have multiple returns it increases readablility. But in long winding methods it is helpful
  49. to limit it to one.
  50.  
  51. __Nils__
  52. - Nils are a real pain.
  53. - Solve using sensible defaults.
  54. - Find of the root of the calculation and handle possible nils there and avoid nil checks at every level of the system.
  55.  
  56. __Divide by zero__
  57. - Any and all denominators should be checked for 0 when using % or /
  58.  
  59. __GLOBALS__
  60. - Should something really be Global. Spend time thinking about this. Using globals is addicitive, adding to the global scope should not be taken lightly. A bunch of stuff always hanging around in memory is a bad call.
  61.  
  62. __Caching__
  63. - Is always trickier than meets the eye.
  64. - Solves one problem and can create another (possible deeper).
  65. - Absolute and total dependence on cache can lead to vendor lockin and other vendor traps.
  66. - Just be careful and test well.
  67.  
  68. __General__
  69. - Check inputs before using them. It is _Defensive/Paranoid_ for sensitive data for sure.
  70. - Variable spans. Keep the distance in lines between initializing a var and seeing it for the last close as possible. The larger the span of lines the riskier it is that the var will be forgotten.
  71. - __DRY__
  72. - Work to keep all the code as unique as possible. It is a smell if you have code that is similar or shares common patterns but it is not unique. Attempt to remove duplicated patterns and move them into a method and keep everything as unique as possible. Too many times this is the result of a large copy-pastes and one or two lines added or removed to get a feature built. Look up OOP techniques to help with this.
Add Comment
Please, Sign In to add comment