Running: how to keep on keeping on

Running can be a tough way to stay fit so you need a way to keep going.

Why technical blogging is hard

Writing blog posts about code is a tricky business. Here's why...

Why clever coding is inefficient

2017-04-01 21:59:45

Writing clever code is likely to cause you a maintenance nightmare later. Here's why...

There's always another bug. It's a fact of life in any discipline that requires writing code. There is nothing wrong with a piece of code getting more complex. Especially as it expands to meet the need, but it's what you start out with that's important.

Brian Kernighan is a coding hero. He co-authored the best programming manual ever written. He is often quoted, but this one supports the argument I'm making here:

Debugging is twice as hard as writing the code in the first place. So, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
Brian Kernighan

So let's think about that for a moment. Let's think about in the context of web development.

Don't we all use frameworks these days?

That's true, frameworks play a big part in how we do web development. We still end up writing code to build our web app/site, though.

It's that code that we are talking about. We have to assume the framework code we are using is bug free. Or, we will debug it by using it - we'll get to that.

The point here is: as you begin to write the code you need, it's easy to be clever. And you can be even more clever when you refine your code further.

This situation is framework agnostic. It's more to do with how individual developers write code. That means the choices you make as you write, are linked to how difficult you code will be to debug.

Unit testing is a big deal. And it does make a lot of sense. Frameworks are unit tested by the creators (usually). Any bugs get reported and squished by people using said framework.

Imagine how hard that would be, if the framework contained masses of clever code.

It has to be clever - there's are many complex requirements

Writing code that conforms with simplicity is hard when the brief is complex. But that's why we are developers. We develop solutions for difficult problems.

Our code doesn't need to get so clever (complex) that debugging becomes impossible. We have programmatic building blocks to help. Classes, functions etc. make sure our code answers the question.

While I'm here, I'll throw another Kernighan quote into the mix:

Controlling complexity is the essence of computer programming.
Brian Kernighan

Exactly. That's what I'm saying. When we write web code it may not be programming as such, not in the strictest sense. But the principles still apply. Keep it clean, keep it simple, let it evolve.

What's with the debugging obsession?

It might sound old school to talk about debugging. But even if you only ever write code and test in the browser, you'll still be trying to squish bugs. That's debugging. It's when stuff doesn't work as expected.

The bottom line...

Writing code cleverly is not efficient. It makes said code harder to work with debugging and maintenance. Aim for elegant simplicity instead. Or at least write code that achieves it's purpose through efficiency, not cleverness.