Accurate code is always a good code, but accurate and organized code is the better code. Your program should be quick to scan and easy to understand. Few habits to take care of while writing code, can make your code readable and lovable.
1 of 12
More Related Content
Best coding practices to follow - to write a code, like a boss
2. Tab key is your friend
Indentation increases the readability of your code.
Its quick to understand the beginning and end of
loops, while revisiting the lines, if your code is
properly indented.
3. use _ (underscore) to make
long variables names more readable
The variables are the blood veins for your code.
Do not take names of your variables for-granted,
they should clearly express their role, wherever and
whenever used.
4. user_generated_last_yield()
is better than u_g_l_y()
Abbreviations create confusions. DO NOT use
abbreviations for your method/function or variable
names. Its better to write
5. Dont call it a function if it has
hundreds of lines of code
Functions and methods are meant to make your code
modular, do not write lump of lines it and make it
complex.
6. Dont let your variables
survive like orphans
Always assign a default value to your variables and
function arguments. A value less variable is always more
dangerous than you think.
7. Sometimes a single clue or a hint
can solve a huge puzzle in seconds
Comments help you when you are lost.
When you write a code of thousand lines, its difficult to
recall the strategy when you go back to line 1.
8. Destroy/flush the variables
when you are done with them, to reuse
Yes they dont cost you, but it doesnt mean you can use
hundreds of them together in a single scope.
Too many variables create a mess.
9. You should be able to understand
It, just while going through it
Use a good code-editor, apply proper line breaks, avoid
un-necessary whitespace as they will increase the scroll
length.