I love when snares don’t keep time

In the majority of music you’ll hear after 1960, the drummer does most of the time keeping with their snare. On 100% of Bruce Springsteen songs, time is kept entirely with the snare. I listen to a lot of The Boss; it’s a little surprising when I don’t here a consistent 1/3 or 2/4 snare keeping time.

That makes the drumming on most jazz albums pretty delightful. For example, Cannonball Adderley, “Games” (Roy McCurdy on drums):

We should make jokes about tech millionaires

I try not to respond to the bullshit in this world with “this person is awful and they should feel awful”. Except for politicians. I try not to participate in witch hunts. I cope via jokes and satire.

After making a few jokes about Paul Graham at RubyConf, a fellow asked me why I made fun of that poor kingmaker (not his words). In short, I think everyone should make jokes about multimillionaires, especially Paul Graham.
He’s a celebrity-of-sorts, making the idea of Paul Graham completely open to satire and ridicule. My favorite such satire was a composite character from Silicon Valley who, due to the actor’s passing, will sadly not recur on the show. So it’s up to us, the unwashed internet people, to poke sticks in his platonic sides.

The thing to illuminate is how past Paul Graham used to have the analytical and rational skills to tell when someone like current Paul Graham is acting a fool. Graham suffers from confirmation bias and billionaire bias. He thinks his rational skills are still sharp enough to help him write about extremely tricky and irrational topics like diversity or inequality and he thinks his monetary success makes him doubly qualified to write about these topics from his own first principles. In other words, Past Paul Graham should know enough to tell Current Paul Graham when he’s out of his league.

I feel Paul Graham is an example of the geeks-shall-inherit-the-world and corruption of money that is bullshit in this world and everyone should apply satire to him whenever possible.

Why I blog in bursts

I write here in bursts. It confounds me as to what marks the beginning and end of those spikes. I have a few hunches:

  • ambitions grow larger than my free time: it’s easier to hit publish on a self-contained thought than a connected series or magnum-opus essay
  • intervention of life: work, vacation, various chores adults are expected to perform
  • self-distraction: acting as a novelty junky rather than pushing one thing through to completion
  • tweeting less: putting little thoughts into tweets means I’m driven to put slighly-not-little thoughts into blog posts
  • reading less: reading interesting things drives me to (attempt to) write interesting things
  • skipping record: I worry I’ve already had this thought and published it somewhere

Also sometimes I’m not quite sure how to end a thought like this and I wonder if I should worry about that and then I decide to let it slide.

A few folks suggested I try lazy enumerables to make my extremely chained style practical. I was curious about the actual costs of my style, so it’s time for lies and microbenchmarks! Turns out naively chaining a bunch of maps together isn’t very costly, so go with that to start.

Lazy came in much slower than consolidating the logic in one loop or chaining them without lazy. I thought, I must not have used lazy properly. Turns out, I’m probably showing that laziness isn’t well suited to iterating over collections without an early termination clause (e.g. a take, first, or find) and that for small collections (like an 87-line /etc/passwd), the cost of the lazy plumbing can noticeably outweigh the work done inside the loops. Thanks to Rein Heinrich for talking me to the bottom line!

One idea per line

Lately, I’m doing a weird thing when writing Ruby code. I’m trying to only put one idea or action per line. I’m not sure about it yet.

Here’s what a method to fetch item-y things might look like:

def fetch_items(options={})
  limit = options.fetch(:limit)
  timestamp = options.fetch(:timestamp)
  paged_helper = PagedHelper
  client = OurHttpClient

  responses = paged_helper.
    new(limit, timestamp).
    fetch_pages { |params| client.get(params) }

    map { |r| JSON.parse(r) }.
    map { |h| ItemCollection.new(h) }.
    map { |ic| ic.items }.

For the sake of comparison, here’s how I may have written that method a couple years ago:

def fetch_items(options={})
  helper = PagedHelper.new(limit, timestamp)
  responses = helper.fetch_pages { |params| OurHttpClient.get(params) }
  responses.map { |r| ItemCollection.new(JSON.parse(r)).items }.flatten

I like that the pace of reading the first example is even. You don’t arrive upon some monster line of code that does a multiple things. You don’t have to unpack what’s happening in a situation where you’re calling f(g(h(some_args))). It makes moving lines of code around much simpler because each one is only dependent on what comes before, and not what happens inside. It’s a little easier to write a three-part method, which I really like.

But still, I hesitate. My methods end up about 50% longer. Breaking up the Enumerable transformations into multiple loops instead of one loop doing a bunch of work is probably pretty slow. I have to come up with a lot of names (which is, I think a net good), some of which end up a little redundant.

I’ll let you know how it goes. It may not even survive code review, who knows!

Programming is easier when you know how to stop solving 100 problems with 1 fancy thing and solve 100 problems with 20 plain things.

Ember is probably leading the JavaScript framework pack by supporting releases with security patches for slight more than a year. By comparison, there’s a cottage industry of garages restoring and updating old Porsche sports cars then selling them for ridiculous prices. The USAF (the same one, curiously, that is spending $1.5 trillion on a useless jet, somehow) is going to use their largest strategic bomber, the B-52, for one hundred years.

I’m always thinking about Greg Borenstein’s words when it comes to technology churn:

The constant churn of web technologies hobbles the creation of timeless learning materials and continuity of knowledge across generations.

We should try harder on this.

Code that resists

Kellan Elliott-McCrea, on the way towards an understanding of technical debt, catalogs the ways we end up with code that resists our efforts to change it:

Therefore the second common meaning of “technical debt” is the features of the codebase we encounter in our work that make it resist change. Examples of features that can make a codebase resist change include: poor modularization, poor documentation or poor test coverage. Just as easily though an abundance of modularization (and complexity) or an abundance documentation, and tests encoding the now the incorrect old behavior can apply a strong downward pressure on change.

A little discussed and poorly understood design goal for code is disposability. Given change, what design patterns can we follow that allow us to quickly expunge incorrect behavior from our codebase? Interestingly it is a much more tractable metric for measuring as opposed to more popular criteria like “elegance”. (a post for another day)

Put that in your thinker. Does something like Strategy or Adapter let you throw out whole classes when they prove unnecessary? Or is that so only when you luck out and chose the exact right axes of disposability? Does a microservice really let you discard codebases wholesale? Can maps and functions free you from intertwingled state and behavior or does it move the resistance somewhere else?

Grumpy, opinionated answers: possibly! Even more possibly! Meh. Very meh.

Three part method

I find methods/functions decomposed into three parts really satisfying. Consider a typical xUnit test:

def test_grants_new_role
  # setup
  user = make_user
  new_role = make_new_role
  # behavior under test
  # assert results
  assert_equal [new_role], user.roles

Lately I’ve been structuring Rails controller similarly:

def create
  # Extract inputs/parameters from HTTP request
  person_params = params.require(:person).permit(:name, :age)

  # Invoke behavior encapsulated in a Plain(ish) Ruby object somewhere
  user = UserService.create_user(person_params)
  # Check the result and make some HTTP output
  if user.persisted?
    redirect_to user_path(user.id)
    @user = user
    render :new

Clojure even has the let form which encourages this style:

; annotated from clj-http
; https://github.com/dakrone/clj-http/blob/master/src/clj_http/util.clj
(defn gzip
  "Returns a gzip'd version of the given byte array."
  (when b
    ; set the table
    (let [baos (ByteArrayOutputStream.)
          gos  (GZIPOutputStream. baos)]
      ; do the work and clean up
      (IOUtils/copy (ByteArrayInputStream. b) gos)
      (.close gos)

      ; produce a result
      (.toByteArray baos))))

I don’t think there’s anything inherently wrong if a method or function isn’t organized this way. But when I read code structured this way, it feels less like a bunch of random logic and more like a cohesive unit that someone put time into thinking through how someone might try to understand it later. The Rule of Three rules everything around us.