Writing code with readability in mind
Code that you write will not only be executed by the computer. It will also be read both by yourself and by others. Therefore, is it essential that you write code that is as easy to read and understand as possible.
There are some simple rules we can follow that will assist in achieving readable code.
Using comments and documentation wisely
When creating code, you need an understanding what you do and why you do it. But when coming back to your code a couple of months later, it is not always as clear what these thoughts were and why you wrote things the way you did. Commenting on tricky lines of code is a great way to document your thoughts for both your future self and others that will read your code.
But comments can also make the code less readable. Never comment on things that are obvious – things that any programmer, including yourself, will understand.
You should use comments when you look at a line of code and understand...