Declare and initialize your variables at the beginning
Late declaration can disrupt your entire codes readability. Just as it’s easier to take out all your tools before starting a job, it’s simpler to declare all variables before getting into the nitty-gritty of your function. By declaring at the start, it will make tweaking easier down the line and ensure none variables left behind.
Recognize and remove duplicate code
You should look out for identical lines of duplicate code. When this happened, we highly recommend you to transform the duplicate code into a function and call them in the instances it was used before. This practice will be helpful later in debugging as you and your team can check on one function rather than multiple code lines and it also make your codes look clean.
Beware of recursion overuse
Be mindful of nesting recursive functions too many levels. In one hand could be very handful to solve a lot of issues, but in other hand it is extremely difficult to understand at a glance. Pull out recursive functions out of their nested whenever it is possible without costing significant runtime to avoid confusion. If you have 3 or more levels of nested functions, we can almost a hundred percent sure that your team might face hard time to follow it.
Build modular, specialized functions
For both efficiency and readability’s sake, there is no one function that could (and have to) do it all. Instead, design a function that has specific task and name the function accordingly. This makes the code easier for others to read. Because of the simplicity, it allows you and your team to reuse this function to another program that might need it later.
Comment your code often
Save your developer team members’ time by writing comments that summarize a code fragment’s purpose. They will be glad you done it. Those comments not only give them explanation but also allows them to catch possible mistakes if the code does not complete the task it is commented to complete. As a rule of thumb, it’s best to leave one comment on every function. You can always delete them later if it’s too much clutter.