Learning to Love Bad Code

Dear programmer,

The majority of code in existence is one or more of:

  • Duplicated
  • Buggy
  • Confusing
  • Poorly Named
  • Overly verbose
  • Inefficient

You need to learn to be comfortable and effective working with “bad” code, because thats the most common kind.

(Also, code that is written to different styles & conventions than your own can appear worse than it really is.)

An inability to stomach bad code can lead to:

  • Obsession with code and design aesthetics of little practical impact
  • Scrapping code when it becomes ugly or or stressed, and thus losing the value in it
  • Difficulty making forward progress on legacy code without first refactoring it

Why is code normally bad?

The obvious explanation is the limitations and imperfections of human programers.

But I think there is a second, more innate cause.

As any system evolves, the assumptions under which code was written change, and the code & design needs to stretch. As a system grows, code duplicates and the copies diverge. Bugs emerge The system becomes stressed, and it requires active effort, in the form of refactoring, testing and bug investigation, to catch bugs, relieve stress, and factor out the duplication.

However, this effort costs money and/or time. This money/time is often better spent on adding new features. If code is really ugly, it may make sense to refactor, but refactoring can quickly incur higher costs than benefits. Thus, much mature code exists in a perpetual state of mild ugliness and design stress. The codebase hovers just under the “fix threshold”, in a zone where the cost/benefit ratio of removing its imperfections cannot compete against the value of additional new features.

If we programmers are going to inhabit such a world, we better get comfortable and learn to love, or at least tolerate, the flaws of the inhabitants.

Advertisements

Civilization & SimCity

I have loved the Civilization game series since 91 – Civ 1 was my first truly engrossing game experience, at age 18.

I consider the latest incarnation, Civ 4, to be my all time favorite game.

Unlike so many sequels, its emphatically superior to all predecessors and derivatives (AFAIK), and displays a profound level of richness and subtle game balance. And its still really fun to play.

Follow Through

To me, Civ creator Sid Meier and SimCity creator Will Wright are both game design geniuses. But the diverging trajectories of SimCity and Civ 4 reveal some interesting differences in their characters and illustrates the great value of Follow Through (something I myself often struggle with, but are determined to improve through my life’s learning):

Sid Meier & Civ

Sid Meier created Civ in 90/91 and has continued to guide it’s evolution since. Each Civ title has been a refinement of the last without varying the fundamental formula.

  • Civ 2 managed simultaneously to be massively and incrementally better than 1.
  • Civ 3 introduced key new concepts Resources and Culture, both very cool, but strayed a bit with rampant Corruption.
  • Civ 4 threw away stinky features like Corruption, Civil Disobedience and alot of Micro-management, and added Religion, Promotions, Great People and better Displomacy.

Its amazing how the Firaxis design team stuck at the problem and got the decicions right time after time, so that the resultant game has kept evolving better and better. Sid could have gone and done something completely different (he did: Railroad Tycoon, Colonisation, Gettysburg), but he kept on following through with his original creation. A+

Will Wright & SimCity

Will Wright, on the other hand, didn’t follow through as well.

  • Simcity was brilliant, but a beginning, like Civ 1 was.
  • Simcity 2 was great, the highpoint of the series.
  • SimCity 3 felt like Simcity 2.1, technically better and yet a dissapointment.
  • And then, along came SimCity 4,which is a nice looking, but really awfullly designed game that is not much fun to play! Not much Will Wright left in it by then.

Wright was no doubt already consumed by Spore. Im sure Spore is going to be brilliant; it’s recently infected Civ4’s lead designer Soren Johnson, who moved over to EA from Firaxis. But surely Will could have spared a day a month to keep an eye over his firstborn, have ensured whoever led design on SimCity 4 was competent, and have taken corrective action when it became apparent the game was on the wrong track. Now it seems like there wont be anymore SimCity, which is sad because the idea of a City Simulator is still as awesome as ever. More Follow Through needed. A-