One of the tips experienced chefs give, is to work clean while cooking. Which means to keep items you work with organized and the working environment clean. To clean during work as opposed to after. Some clean the working environment every second they have and some even go the distance and wash dishes while they cook. It requires discipline and it becomes a habit to notice how your environment looks like and make sure it’s in a good condition.

I believe the same applies to writing code. It’s important to have discipline to make sure the code base is clean and organized at all times. It might not affect functionality in the short term, but I believe it has an effect on mindset and clarity of the code in the long term. No one wants to get into inconsistent and messy code. Even the author can quickly get lost coming back to it after a while.

The first and basic rule is to keep a consistent style and naming conventions. The decision of what guidelines to use is secondary to consistency. It matters less which style of coding you have than it is to always stick with it.

Same rule goes to the code itself. It can be frustrating to get into code that is written by multiple developers that are not in sync. Each one has its own way of doing things and when you read code, you have a surprise for each section. That is why constant small refactoring is important. If you decide to switch to a new and better way to write code, make sure you take some time to adjust all the old code you have to this new standard. If it’s not possible, stick to the old way for consistency.

A way to cheat with keeping the environment clean is to make it smaller. Once you separate your code into smaller isolated modules and extract them to separate modules, you can treat them as black boxes. You don’t need to care or remember which style guide you used when you wrote that module because you’re not touching it when you work on your code. All you need to know is what goes in and what goes out of it.