Skip navigation

Blog > Writing Understandable Code

Ok, so it's a bit boring, but writing understandable code is actually quite important. Whether it#s HTML, CSS, JavaScript or PHP, the key to good programming is being able to achieve complicated results with the simplest of mechanisms. Anyone can write code that is difficult to read and maybe looks clever, but distilling complex functionality into simple steps is almost an art form.

What is understandable code?

Understandable code is code that is written to be read - as simple as that. It's more than just commenting your code properly (although comments are an important aspect). Code should be expressed simply - there is nothing worse than reading code that looks as if it has been written as part of a competition to write something in less than 10 lines. Consistency of layout should also be considered in terms of indentation, variable naming and constructs used - all these things can help people find the section they are looking for and understand, at a glance, what is going on.

Sensible breakdowns of repetitive code into functions and classes with informative names also increases the speed which with a new person can understand old code. Even filenames can provide helpful pointers for anyone trying to pick up a piece of code with no previous knowledge.

Why is it important?

Complicated code is fine until you leave it for perhaps 12 months and then have to apply what seems like a simple change. Suddenly, it's like looking at code that someone else has written and that simple change is going to take a lot longer than you originally thought. Ultimately, complicated code is going to cost everyone more in the long run. Finding bugs is going to take longer, updates are going to take longer and extending the functionality is going to take longer. Your client is going to start asking questions as to why apparently simple changes are costing so much money.