Programmers differ in coding style, manner, proficiency level, etc. But if you follow certain rules, your code will be clear and readable to any programmer. Keep in mind that the code you write might be modified or added by other programmers. So, follow the rules to make them admire your code. Regardless of the programmer’s proficiency level, some codes look neat and readable, while others look like they have been mixed in a blender.
Use meaningful variables
Many programmers neglect this rule, using variables that have nothing to do with the code’s logic. Or they use variables like $a, $b throughout the whole code. Meaningful variables make the code readable and perceivable. While reading the code, the programmer interprets it in his head to understand its end result. While for the code creator there may be no difference between the variables $a and $history_list, it can significantly help an ordinary person to perceive the information easier.
Keep the style from the beginning to the end
Choose a code style and keep it throughout the project. Do the same while naming the variables. Here are examples of some popular styles: my_history_list, MyHistoryList, myHistoryList, myhistorylist. Choose one of them and use it throughout the project. The format myHistoryList, is very popular. Use it if you like it.
Make comments to the code
This is very important, especially when the code has complex logic. In comments you can explain complex functions, all entry data and code result. This will be of great help not only to the further developer, but also to yourself, if in a year or two you will have to make changes in your own code and will have forgotten it; you will spend tons of time trying to understand your own code.
Divide the code into files
It’s a good idea to have 10 files containing 1,000 lines instead of a single file containing 10,000 lines. Small files are easier to read and perceive. Divide big files into small ones (modules) to be able to find the necessary codes easier.
Also, make sure to give meaningful names to the files (modules). Spend extra 10 minutes doing it now to save you time in the future. Your code will be clear and your accuracy will be appreciated.
Know how your code works
"Wow, it’s working, but it shouldn’t be! Doesn’t matter….as long as it’s working!" – this is not how a professional should react. You must have 100% understanding of your code - how it should work and how it shouldn’t. You must be absolutely sure that your code is working now and will be working tomorrow regardless of entry data.
Keep things arranged
While writing your code you might deal with graphic and text content. The code should contain only instructions and variables. All the rest must be on their places. Keep graphics and texts in separate files and folders. Add all components separately using them through variables and constants. This will make the code readable and will make it easier to change the interface or add languages in the future.
Optimize resources usage
There is not always enough time to optimize the code, so we often leave it until problems arise. Maybe it’s a good decision, but not for self-development. Invest in yourself. Spend some more time today to improve your code and your skills. Your program uses 14 MB of the memory? Try to reduce it to 10. You did it? Now reduce it to 5 MB. It doesn’t matter how much time you spend – the result is worth it!
On production always delete all that is unnecessary. Why keep 80% of commented code? Hardly will you ever need it. Make reserve copies and delete unnecessary stuff. No unnecessary code pieces in wrong places! You have a website with news module? Why load the news from the base to the variable if you are not using it on feedback page? Use each code piece only where it is needed!
Keep improving your code
Do you agree that you are smarter and cooler today than you were yesterday? It’s great! Improve the codes you wrote two years ago even if they are working perfectly. There’s always room for improvements!
Perfecto Web team