Over the last couple of weeks I’ve been thinking, is there such a thing as being a “code snob”, and if so am I one?
The reason I’ve been thinking about this is that I have been slowly picking up more and more small projects, where I’m having to either repair or update the existing code, which were created by other companies. Nine times out of ten I find myself starring at badly written code. For those of you not into programming, there are a number of metrics that can be used to classify how well code is written. I spent ten years being both taught and teaching students how to write “good code”. The majority of these rules are simple to follow, and are even common sense. For example, “name variables appropriately with a descriptive name”, so when you need a variable to store the total of a sum you might call it “total”, but don’t call it something random like “b” or “jklgh” (and yes I’ve seen undergraduate students do this).
The reason we have these metrics and guidelines to writing code is pretty simple. Good code is easier to read and understand, which means when it comes time for you or someone else to modify the code it will take them less time and more importantly be less frustrating. Whereas badly written code is just a nightmare to understand, let alone alter. I’ve even heard young developers say, “well it’s my code and I’ll be the only one that will be modifying it”, which is giving them false hope. Generally you as a developer will work on a piece of code and then move onto something new. Sometime later, could be a couple of months or a couple of years, you will need to revisit this code and make alterations to it, and trust me when I say you will have forgotten some of the fine details of why you did things in certain ways. Now if your code is well written it won’t be a problem to work everything out, but if it’s badly written code then the problem starts. There isn’t an excuse for badly written code.
My biggest pet hate, and any of the students I’ve taught programming to vouch for this, is code indentation. Some people say you must use tab characters to indent code, whilst others say spaces. Personally, I don’t care how you indent your code, just as long as you do and that you are consistent and use the same indentation throughout your code.
There are so many resources around to day that there is just no excuse for writing code badly. Even if you know you are never going to look at the code again, have a heart and think about the next person that will. You know the old saying what goes around comes around.
So to answer the starting question is there such a thing as being a “code snob”, I still don’t know. However, if there is then I think I might have membership to that club.