๐ง๐ถ๐ฝ๐ ๐ณ๐ผ๐ฟ ๐๐น๐ฒ๐ฎ๐ป ๐๐ผ๐ฑ๐ฒ
When we code, we write it for others to read later on, not for ourselves. Even if a person is working on an individual project itโs crucial that your code is readable to another developer.
๐ญ. ๐๐๐ผ๐ถ๐ฑ ๐ฝ๐ผ๐ผ๐ฟ ๐ป๐ฎ๐บ๐ถ๐ป๐ด
Variables should be meaningful, reveal intention, and should be chosen from the problem domain
๐ฎ. ๐๐ผ๐น๐น๐ผ๐ ๐ฐ๐ผ๐ฟ๐ฟ๐ฒ๐ฐ๐ ๐ป๐ฎ๐บ๐ถ๐ป๐ด ๐ฐ๐ผ๐ป๐๐ฒ๐ป๐๐ถ๐ผ๐ป๐
Itโs important that you follow the correct naming convention to avoid being a chaotic coder. Be consistent with the casing.
๐ฏ. ๐๐ฒ๐ฒ๐ฝ ๐ณ๐๐ป๐ฐ๐๐ถ๐ผ๐ป ๐ฝ๐ฎ๐ฟ๐ฎ๐บ๐ฒ๐๐ฒ๐ฟ ๐ฐ๐ผ๐๐ป๐ ๐๐ผ ๐ฎ ๐บ๐ถ๐ป๐ถ๐บ๐๐บ
The best practice is to keep your method to 3 or fewer parameters. While it can become hard sometimes when you look closely there are situations where you can split the method into different functions.
๐ฐ. ๐๐ฒ๐ฐ๐น๐ฎ๐ฟ๐ฒ ๐๐ฎ๐ฟ๐ถ๐ฎ๐ฏ๐น๐ฒ๐ ๐ฎ๐ ๐๐ต๐ฒ ๐ฝ๐น๐ฎ๐ฐ๐ฒ ๐ผ๐ณ ๐๐๐ฒ
Variables should be declared at the place where they are actually being used. That way you wonโt have to scroll back and forth to understand your code.
๐ฑ. ๐๐๐ผ๐ถ๐ฑ ๐๐๐ถ๐ป๐ด ๐ฐ๐ผ๐ป๐ณ๐๐๐ถ๐ป๐ด ๐บ๐ฎ๐ด๐ถ๐ฐ ๐ป๐๐บ๐ฏ๐ฒ๐ฟ๐
If you are using numbers in if-else-if conditional statements, declare constants to explain their meaning. Also, you can create an enumeration if the value is being used at multiple places.
๐ฒ. ๐ ๐ถ๐ป๐ถ๐บ๐ถ๐๐ฒ ๐ฒ๐ ๐๐ฒ๐ป๐๐ถ๐๐ฒ ๐ป๐ฒ๐๐๐ฒ๐ฑ ๐ฐ๐ผ๐ป๐ฑ๐ถ๐๐ถ๐ผ๐ป๐
Multiple nested conditions make it hard to read your code. Always try to simplify them. Hint: use the switch statement or combine them using conditional operators.
๐ณ. ๐๐ผ๐ปโ๐ ๐ถ๐บ๐ฝ๐น๐ฒ๐บ๐ฒ๐ป๐ ๐๐๐ฝ๐ฒ๐ฟ ๐น๐ผ๐ป๐ด ๐ณ๐๐ป๐ฐ๐๐ถ๐ผ๐ป๐
The function should be short and do just 1 thing. Try to avoid creating long functions. Just because you can read it and understand that doesnโt mean itโs a good practice. Most of the time itโs hard to understand, change and reuse.
๐ด. ๐๐๐ผ๐ถ๐ฑ ๐ฐ๐ผ๐ฑ๐ฒ ๐ฑ๐๐ฝ๐น๐ถ๐ฐ๐ฎ๐๐ถ๐ผ๐ป Do you find yourself copy-pasting the same code to different places with small changes? Bad..Use the DRY principle instead
๐ต. ๐ ๐ฎ๐ธ๐ฒ ๐ป๐ฒ๐ฐ๐ฒ๐๐๐ฎ๐ฟ๐ ๐ฐ๐ผ๐บ๐บ๐ฒ๐ป๐๐
Use your comments to explain the whys and hows. Never state the obvious using comments. Donโt keep dead code in comments, use version control