Pursuing Code Simplicity – Does Dr. Dobbs Miss the Point?

This article in Dr. Dobbs claims an obsession with code simplicity exists among some (i.e. agile) programmers. It refers to that old received hacker wisdom that any fool can write complex code, but it takes real talent to write simple code. The author attacks this point of view, saying that in reality some problems are genuinely complex and must be implemented in complex code.

I happen to agree that inherently complex problems sometimes can’t be reduced to “simple” solutions. I wasn’t aware any developer seriously thinks any different.

But I also think that this analysis misses the point. As I understand it, this old wisdom refers to problems that do have a simple solution, but require some time and skill to work out. I think every programmer can hark back to their very earliest coding days and recall the typical quality of programs from their youth. Or maybe they have a colleague who couldn’t give a stuff about code quality and sees what sort of code they produce? In any case, a solution that’s not sufficiently thought-out prior to implementation tends to become a mass of multiple-level if-statements, endless switch-case blocks or functions hundreds of lines long.

I see a striking similarity with writers. They also need to produce something that’s simple to digest, ideally so that the reader becomes so absorbed in the story they lose all awareness that they’re actually reading.  Rare is the writer who composes a novel by jumping straight into the implementation without any planning. Writers who do, as J. R. R. Tolkien famously did, will usually get into a mess. (Unconventionally, Tolkien wrote Lord of the Rings with lots of ideas but without any detailed story plan and had to restart multiple times. Luckily for us, he persisted and got his story worked out in the end.)

A writer needs to develop certain skills — like plot development, pacing, characterisation — and use these to compose a “plan of action”. Once that’s done, everything is in place: the characters are worked out, their relationships with one another are established, what happens when is settled, and so on. With a plan in place, the actual writing practically takes care of itself and the writer can focus purely on making the prose pleasurable to read.

Similarly, a programmer has a set of skills that he/she uses to analyse the initial problem, using their knowledge and experience to anticipate probable hotspots of complexity, and work out the steps, structures and relationships to mitigate them. If, let’s say, your new e-commerce app has to deal with different sales tax rates, it’s very easy to just choose between rates by way of a switch statement because we learn about switching very early in our programming career.

switch (country) {
  case UK:
    return 17.5;
    break;
  case IRELAND:
    return 23.0;
    break;
  // etc
}

But experienced programmers know that some parts of any program are volatile, changing often in response to new requirements. Just imagine that this e-commerce application became widespread and suddenly had to support the tax rates of more and more countries. Or maybe additional types of tax suddenly needed to be taken into account. The code could potentially become horrific.

As an alternative to switch statements, you could use a strategy pattern to implement taxation instead, sub-classing each variant. This would make the resulting program simpler and less brittle. But the pattern approach means you would need to possess knowledge about patterns, and patterns aren’t learned quickly or easily.

This example illustrates what I’ve always taken this old wisdom to mean. I’ve seen a fair few inexperienced programmers by now (I was one once), and I’ve even known a few coders who just didn’t give a damn about writing simple code. Their efforts, even when an alternative, simpler solution existed, was usually a nightmarish example of code spaghettification. With knowledge, experience and the right attitude, their solutions would no doubt have been much less complex.

Still, there’s plenty of room for agreement here, specifically the article’s championing of readability. Even some of the best programmers forget that source code is somewhat like a novel – a story from one coder to another. Like a novel, the source code should be a pleasurable read too… but I’m not convinced readability comes before simplicity. It wouldn’t matter how beautiful the writer’s language — if their story was a structurally complex mess then I would be putting it back on the bookshelf pretty quickly.

Git – A New Training

Git continues to encroach upon the space of existing version control systems. More and more development projects are opting for Git over the likes of CVS and Subversion. But Git is not an easy system to handle.

You’ll need someone to give you a nice, gentle introduction. I’ve long since elbowed out all other version control systems in favour of using this colourfully-named version control system exclusively. If you like, I’ll come along and be the one to give you that gentle introduction.

Git is a powerful, distributed version control system that is particular well-suited for large development projects that include numerous parallel development branches. The Linux Kernel developers use it for heaven’s sake, a project with thousands of contributors. Last I checked, Linux recently went beyond 15 million lines of code. Nevertheless, Git is just at home servicing more humbly-sized projects too.

I ordinarily cover the following core topics:

Introduction to Git

  • History and philopsophy
  • Centralised vs. distributed architecture
  • Local vs. remote operations
  • Comparisons to other VCSs (e.g. CVS, Subversion)

Installation (Windows and Linux)

  • Installing the core software
  • Installing GUI tools (e.g. TortoiseGit)

Basic Operations

  • Initialising
  • Cloning
  • Configuring
  • File tracking and statuses
  • Staging
  • Committing
  • Maintaining an ignore list
  • Tagging

Repository History

  • Viewing the log
  • Viewing diffs
  • Customising log output
  • Rewriting recent history (undoing)

Labels and Specifiers

  • Data structure of a Git repository
  • Revision specifiers
  • Branches
  • Visualing labels and specifiers

Working in Branches

  • Creating a branch
  • Basic merging
  • Three-way merging
  • Dealing with conflicts
  • Rebasing

Remotes

  • Cloning from remotes
  • Remote branches
  • Fetching and Pulling
  • Pushing

Using GitHub

  • Setting up a new project
  • Importing
  • Forking

Example Workflows

  • Branching workflows
    • Long-running branch
    • Topic branches
  • Organisational workflows
    • Centralised
    • Integration-manager
    • Dictator and lieutenants

Maintaining Your Own Server

  • Protocols (HTTP, SSH, Git)
  • Bare repositories
  • Securing with SSH

Submodules

Working with Subversion Repositories

  • Communicating with a SVN repo
  • Migrating from an SVN repo

Ruby on Rails – A New Training

In May, I spent a week in Hamburg giving a training in Ruby on Rails. I’ve already been a team-member on two Rails development projects, and it was as much a joy to teach as it is develop.

Ruby is a multi-paradigm, general-purpose programming language that particularly encourages simplicity and elegance in its users. Rails is a web application development framework built using Ruby. Like Ruby, Rails encourages you to develop elegant programs and has a very vibrant community of developers who provide a huge number of reusable components.

Web applications built on Rails include GitHub, Basecamp and Redmine.

The course I offer is summarised below and the recommended duration is 3-4 days.

Introduction to Ruby

  • Installation
  • Interactive Ruby Interpreter

Ruby Syntax

  • Variables and scope
  • Arrays and Hashes
  • Strings
  • Symbols
  • Flow control
  • Blocks

Object-Oriented Development with Ruby

  • Classes
  • Attributes and Accessors
  • Method scope
  • Mixins
  • Reflection

Typical Tasks with Ruby

  • File handling
  • XML/JSON processing
  • Times and dates
  • Debuggging Ruby
  • Using RubyGems
  • Exception handling

Rails Principles and Architecture

  • “Convention over Configuration”
  • MVC
  • REST
  • Folder layout

Installation and Configuration

  • Installation
  • Databases (e.g. SQLite, MySQL, PostgreSQL)
  • Using Rake

Developing a Typical Rails App

  • Creating controllers, models and views
  • Using scaffolding
  • Routing
  • Migrations
  • Templates
  • Validation
  • Associating models

Layout and Scripting

  • Scripting with JavaScript or CoffeeScript
  • Styling with CSS or SCSS
  • Templates with ERB or HAML

Making a Killer Rails App

  • User authentication
  • Automated Testing
  • Internationalisation
  • Deployment
  • Mobile Rails apps

More trainings. Updates will follow

My intense three-weeks/three-trainings period is now over. I’ve been all over Germany teaching and training various IT subjects, and now I’m home for some rest and recovery.

A couple of the trainings were actually new courses that I offer. I’ll write a couple of follow-up posts with details about them later… maybe… I’m enjoying Berlin in the sunshine a little too much right now.

Endocode is here!

It’s an unmercifully busy time for me right now. I’m up to my ears in consulting and training work, and in addition to that I’m busy founding a new company…

… oh yes, I might not have told you about that yet…

Endocode is here!

endocode-logo

Endocode is an awesome new company (but then, I would say that) which provides a range of software services, mainly in the FLOSS arena. I’m just one of a bunch of founding partners who together have extensive backgrounds and experience in open source software development. We’re pooling our talent to offer top-quality consulting, development and training services to enterprises large and small.

It’s all rather exciting.

As I said at the start, I’m incredibly busy right now. As much as love to write a big long post all about us, I don’t quite have the time. Luckily, my co-founder Mirko Boehm has already written the long version about Endocode over on his blog. Get over there and read all about us.