back

The random person test

My mother is not a programmer. Ruby lets me easily write code that I could send to her.

I can write:

1
2
3
4
5
6
7
8
9

class FlowerArrangement
  def new
    find_store
    buy_flowers
    put_in(Vase)
  end
end

Of course, I could have written this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

class FArrange
  TWENTY_EIGHT = 30
   INFINITY = -1

  def new
    i = 0
    loc = Store.all.map(&:location).select{|l| l.z == 28281}.last
    fs = loc.flowers.select{|f| f.beauty > f.max_b}
    while (@v ||= Vase.create!).flower_count < TWENTY_EIGHT
      @v.flowers[0..INFINITY].z_power!
      @v << fs[i]
       i += 1
    end
  end

end

But why? What on earth is the point of writing convoluted code? What does line 11 even do? My mother certainly wouldn’t know.

And while a programmer could figure it out, who am I to waste their time like that? Why not try to write code that future programmers will thank me for because it was so clear and obvious? Programmer skill should be measured not only in the complexity of the problems that they can solve, but in the clarity of their solutions.

I often run into code that looks like the second example above. It makes me feel the same way that I do when I open an e-mail about ideas that is 10 pages long. It feels like this wave of bullshit just rushing up to drown me.

It’s definitly possible to go overboard with english-ness (This.is.kind.of.dumb). Code != English. But, generally, I see no reason to write code that you couldn’t send to anyone.

The guy on the street test

Next time you’re writing Ruby, try asking yourself:

If I sent this to a random person could they answer the questions “what is happening here?” and “how is it happening?” either immediately, or within a few seconds of my explaining the problem domain?

May 21, 2009