Search⌘ K
AI Features

Writing Code Badly

Understand why bad code is difficult to read and unsafe to change. Learn from real-world examples how lack of testing, unclear structure, and external pressures affect code quality. Discover the reasons behind writing bad code and why applying test-driven development can lead to better software.

Good vs. bad code

As every developer knows, it seems a lot easier to write bad code than to engineer good code. We can define good code as being easy to understand and safe to change. Bad code is therefore the opposite of this, where it is very difficult to read the code and understand what problem it is supposed to be solving. We fear changing bad code—we know that we are likely to break something.

Author’s experience: coding nightmare

My own troubles with bad code go all the way back to my first program of note. This was a program written for a school competition, which aimed to assist realtors in helping their customers find the perfect house. Written on the 8-bit Research Machines 380Z computer at school, this was 1981’s answer to Rightmove.

In those pre-web days, it existed as a simple desktop application with a green-screen text-based user interface. It did not have to handle millions, never mind billions, of users. ...