code review guidelines
Published in
2 min readMay 5, 2018
1. do not repeat yourself (dry):
- redundant code is not only error prone but also a maintenance overhead.
- make sure redundant code is re factored into a class or function.
2. avoid hard coding:
- code should be configurable and not to use hard coding.
- if possible create separate configuration file which contains all the constants, enums, choices etc.
- this will make your application settings more manageable.
3. call out tight inner loops:
- call out tight inner loops. (anything that iterates > 100 000 times)
- this need to be reviewed intensely
4. use standard library/third party tools:
- check if the functionality can be achieved by using existing libraries.
- have a good understanding of standard libraries
- don’t reinvent wheel, use 3rd party tools
5. use right data structure:
- selecting the most appropriate data structure to store your application’s data is important.
- your choice of data structure affects the operation and performance of your application.
6. call out thread/ process usage:
- avoid threads if possible.
- if using them please call out as the code will be reviewed intensely.
7. call out long blocking calls explicitly:
- call out the code which taking long time. esp in tight inner loops
8. prefer streaming:
- do not hog memory.
- huge read and writes should be buffered. use generators, yield
- use lazy ready where all is possible
9. use connection pool:
- use db connection pool
- configure proper pool parameters
- validate the connection
- make sure queries use appropriate index
10. resource leak:
- follow first in, last out approach
- do not leave foot prints
- close necessary connection (db, file, client etc)
11. reduce dependencies
- organize/ package code so that there are minimal dependencies
- import modules which are required
12. use prepare statement:
- use prepare statement to avoid sql injection attacks.
- when more insert,update query execute use prepare statement for dynamic and parametric query.
13. minimize loc in function:
- write small functions
- they are easy to code, review, test etc
14. comment your code:
- explain why the following block of code is written the way it is.
- if you use any fancy tricks or do anything that isn’t obvious from a quick glance, explain
- its good to be verbose
15. log writing:
- write logs with uniform format across services.
- log from a point of view of operations/qa team.
16. error handling:
- don’t fail silently
- catch as specific errors as possible
- context specific error messages are easy to fix
17. unit test:
- test your building blocks
- each bug identified should get translated to a testcase
- more is better
Read this also on
https://english.pratilipi.com/read/code-review-guidelines-GJORmoCBhFAU-6601405i4805124