The wrong idea

My father tells a story of someone he used to work with – someone so totally unacquainted with social norms that he was thought of as ‘an alien’.

One day, this man was suggesting some boneheaded idea to his boss. The boss was not impressed with it. The man pressed on: “well, gee, you just don’t seem to be getting this…” His boss turned puce and said, threateningly: “maybe that’s because it’s just the wrong idea.”

It’s the wrong idea is a surprisingly useful concept.

Often you’ll have gone down a road so far that you’re blinded by context. Sometimes taking stock of your general direction can make you realise not that the details of your solution are wrong, but the whole approach. You need to start over.

Pair programming is nice for that reason: while you work on the nitty-gritty implementation details, your pair can keep the fifty-thousand foot view in the back of their mind. It’s easy to get lost down a rabbit hole; they can remind you why you’re going down this path in the first place.

Change your defaults

Most lives are lived by default, on David Cain’s blog Raptitude, is a favourite piece of mine.

The day-to-day feel and quality of each of our lives sits on a few major structures: where we live, what we do for a living, what we do with ourselves when we’re not at work, and which people we spend most of our time with.

Those four structures – which mostly are handed to us by happenstance – determine the shape of our lives. We choose from the options day-to-day life presents us, but these structures bound those options.

Of course, this raises a scary thought: your life is probably sub-optimal. “Chances are very slight that there isn’t a drastically better neighborhood for you out there, a more kindred circle of peers, a much better line of work, and a much more rewarding way to go about your day[.]”

Even worse, status quo bias blinds you to the possibility that some other life might be better for you.

But change any of those four structures, and your life changes substantially, too.

It might get better, or it might get worse. You don’t know until the change is made. This uncertainty is enough to keep most people from bothering. But they should bother, as a rule. … If the new situation does resonate, then you’re closer to finding what’s right for you, what’s optimal for your sense of well-being.

So change your defaults to change your life. A simple first step: break out of your script and do something that nobody’s expecting you to do – the more un-self-directed, the better.

Concourse: CI as Code

Josh Hill and I gave a talk at LOPUG on Concourse, our beloved continuous delivery and pipelining tool.

You can see the slides here. The highlights:

  • Unlike other CI systems, Concourse puts pipelines first.
  • Everyone has a pipeline of some sort – how automated and well-documented is yours?
  • A pipeline can be a CI/CD process (build → unit → integration → deploy), but can also be used to e.g. version a resource, push code to Amazon S3 or a BOSH release, and all sorts of other things.
  • Pipelines are made of three components: pipelines, resources and jobs. Any pipeline can be described with these primitives.
  • Concourse stores your entire configuration as YAML. Nothing in the UI is configurable, which means your entire pipeline can be stored under version control, and your Concourse instance can be easily rebuilt.
  • Concourse integrates beautifully with Cloud Foundry.

An eternal golden braid

From Life Is a Braid in Spacetime by Max Tegmark:

When we think about the present, we mean the time slice through spacetime corresponding to the time when we’re having that thought. We refer to the future and past as the parts of spacetime above and below this slice.

[Spacetime as a mathematical structure implies a] universe that can be beautifully described by mathematics. That this is true for our universe has become increasingly clear over the centuries, with evidence piling up ever more rapidly. The latest triumph in this area is the discovery of the Higgs boson, which, just like the planet Neptune and the radio wave, was first predicted with a pencil, using mathematical equations.

This view of ourselves as … patterns in spacetime challenges the assumption that we can never understand consciousness. It optimistically suggests that consciousness can one day be understood as a form of matter, a derivative of the most beautifully complex spacetime structure in our universe. Such understanding would enlighten our approaches to animals, unresponsive patients, and future ultra-intelligent machines, with wide-ranging ethical, legal, and technological implications.

Well worth reading.

Startup Lessons

Some thoughts on (tech) startups.

  1. Keep it simple. Every decision you make needs to have minimalism at its heart. On features: fewer is better. On copy: it doesn’t matter nearly as much as you think it does. On software: don’t reinvent the wheel. Use popular frameworks and don’t roll your own code when off-the-shelf will do.

  2. Shipped is better than smart. It’s easy to get carried away with exotic ideas and interesting code. Resist this urge at all costs. Everything takes so much longer to do than you think it will. Keeping your product feature-light and your code simple will defend against this. It doesn’t matter how crazy secure your custom encryption layer is if you die while building it.

  3. Fear the shadow of the future. It’s tempting to write bad code, skip testing, ignore design patterns, hack on production, let your codebase grow. But technical debt has to be paid back someday — and the longer you put it off, the bigger the interest gets.

  4. Technology is a tax on scaling1 so have as little of it as possible. If tumblr is good enough for Yahoo!’s engineering team, then you don’t need to host your own high-availability, DDoS-protected WordPress stack. Focus on your product’s core features, and don’t get distracted by crazy technical setups.

  5. Don’t break your own rules. If you need to, you’re doing something wrong. If you’ve said that your developers shouldn’t have access to the production database when you go live, don’t break that rule later on. The same is true of features: if you’ve pared down your roadmap to a single essential product, then don’t let feature creep push you off course.

  6. Don’t burn yourself out working crazy hours. Set a sustainable, measurable, predictable pace. If you have to work insane hours to make ends meet, you’re doing something wrong — either your code is bad, your product too complicated, or your team under-resourced.

  7. Be wary of growth through sheer force. Any product can get users, given enough funding. But if it costs you ten times more to acquire a user then they ever return you in profits, your business model is broken.

  8. Listen to your employees. They’re the ones at the coal-face working on your product, selling it to people, meeting your customers. They probably know the most about it. They need to care about it and believe in it. Take their opinions seriously.


  1. Stolen shamelessly from David Mack’s excellent Advice for first-time founders, which all tech startup founders should read. 

Kill your Buddhas

Kill the Buddha:

 I interpret Zen Buddhism as a set of practices for not tripping over your own mind – avoiding our tendency to bin experiences into categories so swiftly and completely that we stop actually paying attention to them, not becoming imprisoned by fixed beliefs, not mistaking maps for territories, always remaining attentive to what actually is. Perhaps the most elegant expression of this interpretation is this koan setting forth the problem: “The mind is like a dog. His master points at the moon, but he barks at the hand.”

Employed!

An update to my becoming a developer saga – I’m now working as a software engineer at startup MyGravity. I get to work with a great team, hacking on Ruby, Grape, systems architecture and other fun things.

I’m not sure I ever really believed it would happen, but here I am: a bona fide developer. It’s pretty sweet.

(We’re hiring, by the way.)

The Twelve-Second Code Year [part 4]

(I’m taking an intensive web development bootcamp. Part 1, part 2 and part 3 of the story. Names of students have been changed.)

10.

It’s over.

These students have what it takes to be developers. It’s not about knowing a language, it’s about knowing how to solve a problem; how to bring simplicity into the world.

— Enrique Comba Riepenhausen

11.

Makers has been a lot of fun. Twelve weeks of intensive work, learning a new skill, totally retraining, having only moments earlier thrown away a half-decent career. Other people have come from similar backgrounds to do the course: one worked in strategic consulting, and had a similar gradual realisation to me that his field was slowly sucking the life out of him.

I think everyone, with a single exception, got a lot out of the course. Not everyone is at the same place – those who had done more preparation when they started are further ahead than those who did less. But I think in terms of what’s been achieved and learnt in twelve weeks, everyone is amazed at their own progress.

(I should note that Makers recently updated their website to describe the course as being sixteen weeks: twelve weeks taught plus four weeks of full-time self-study beforehand. I suspect this is partly to get much of the boring material out of the way before students join, and partly to ensure everyone’s at the same level when they start.)

12.

Our final project was an internet-connected thermal printer that could read an RFID card (like an Oyster card), identify you from a database and print out a custom chit – with, say, your calendar events for the day, your current GitHub stats, or (if it’s getting late) any Tube delays and the weather for the next hour. The plan is that the device stays at Makers and using becomes part of the daily routine there. It’s based on Spark Core, so we call it Spark Printer. It’s pretty neat.

Engineering it was the biggest challenge I’ve faced so far. Specifically, working my way through the Spark documentation and figuring out how we were going to make this work – what functionality the Texas Instruments chip on the Core has, how it talks to their cloud server, the limits in size and number of API requests, using Spark.publish to listen to events from the Spark – all the technical stuff that makes the internet hard and is usually abstracted away for you.

But most final projects are pretty bog-standard Rails web applications. It was incredibly rewarding to go against the grain and build something different. We made a real product that lives in the physical world, and learnt a bunch of new technologies in the process.

While we were building this, the excellent Chris Waclawek from Estimote came in to talk about iBeacons and the Estimote product line. The audience was wowed – the more he spoke, the more use cases people dreamed up for these magical little devices that give your phone context and tell it what’s nearby. It was the kind of magic that the early iPhone had: none of the components were particularly innovative, but they were put together in such a way that opened up millions of possibilities that Apple had never thought of and that developers were free to implement.

13.

Whether working in tech will be the dream we hoped for has yet to be seen, but the signs are there. It has a vibrant community, it’s full of smart and engaged people, there’s a tremendous focus on continuous learning and understanding new technologies. It’s a huge world – some people work for giant corporates, some for small web shops, some for themselves, others remotely in far-flung countries. It’s meritocratic in a way that I don’t think exists elsewhere any more.

Now, we polish our GitHub profiles, ensure our code repos are well-documented, and wait to be placed.

I’m excited to get started.

Getting started with Sinatra and test-driven development

Sinatra is a DSL (domain-specific language, or a language written for a specific purpose) for building web applications.

It can be confusing. If you’re a beginner programmer fiddling around with Ruby, the single-user terminal apps you’ve been writing are suddenly up on the web for everyone to see, and they need to behave differently as a result.

require 'sinatra'

get '/' do
    'hello world!'
end

If you want to run this and get it working, save this into a file (say server.rb), go to that directory and run ruby server.rb (you’ll need Ruby installed on your machine, naturally).

This code, specifically the bit between get and end (called the controller) will intercept an HTTP GET request sent to ‘/’, and reply with ‘hello world!’ in plain text. Simple.

Routes

In the above example, ‘/’ is the route. You can define a bunch of other routes, too. For example:

get '/hi' do
    <h1>Hello Makers!</h1>
end

Now, accessing the website path /hi will yield the above message (which in this case will appear big and bold on the page, as we have wrapped it in h1 tags.)

Testing with Cucumber

Cucumber is used for acceptance testing – it acts as if it were a person using the application to make sure it works. You can use Cucumber with Sinatra by using the cucumber-sinatra gem.

Get started by running:

$ cucumber-sinatra init --app SampleApp lib/sample_app.rb
...
$ rackup

Run your Cucumber tests from the command line with $ cucumber.

Now, let’s describe a feature using Cucumber:

$ mkdir feature
$ touch homepage.feature
Feature: The homepage
  In order to show off Cucumber
  I want to present Cucumber

This will run, but doesn’t have any actual tests (or scenarios). Let’s add some in the same file.

  Scenario: Being greeted
    Given I am a site visitor
    When I am on the homepage
    Then I should see "Hello hello!"

This Given/When/Then notation is particular to Cucumber (or specifically Gherkin, the language Cucumber is written in).

For each step, you write a step definition in Ruby.

cucumber-sinatra has some built in step definitions, so you can write some steps without needing to define them (like When I am on the homepage). These built-in definitions live in features/step_definitions/, and there are support files in support/ which do things like substituting ‘homepage’ for ‘/’.

Cucumber also uses a language called Capybara, which can interact with a webpage — filling in forms, clicking links, looking for specific page content, and so on. Consider deleting features/step_definitions/web_steps.rb to get some practice in writing your own step definitions, which also makes the whole thing seem less like magic and gives you a better understanding of how Cucumber matches up your tests with Capybara methods behind the scenes.

Running the damn thing

Get your server up and running by typing

$ rackup

What this command actually does is read through your sample_app.rb file, looks at the various routes you’ve set, and creates a routing table from it. Then it starts an HTTP server on a particular port and makes it available for connections.

Config

Look at the following code from the Sinatra documentation:

set :views, Proc.new { File.join(root, "templates") }

Why do it this way? Seems kinda convoluted.

The reason this is so important is that it bases the path to your views directory on the site root. If you ran rackup from a different directory and you’d hard-coded the views path, then it would break – it wouldn’t be able to find views relative to where you’re running the server file from.

Using root gives a salient point that your site is always run from.

Sessions

HTTP by nature is stateless – so it doesn’t recognise repeat visitors, or even visitors across pages. A lot of basic things fail because of this – how could you log in to a site, for example, if it didn’t remember you?

This is where sessions come into play.

The server creates a unique ID (or UID) for each visitor and stores it in a hash table. This value is served back up to users to identify them, either in a cookie or (more rarely) in the URI itself. A cookie is returned as part of the header – it’s just a string inside the header.

A cookie sent by a particular site can only be read from the browser by that site.

So how do you use sessions in Sinatra?

sample_app.rb:

class SampleApp < Sinatra::Base
  enable :sessions

  get '/' do
    @number = session
    erb :index
  end

  get '/a/:number' do |number|
    session['number']= number
    redirect to '/'
  end

end

Bear in mind that sessions have a hard limit of 4KB! To store more than this, you would use a database — but that’s a topic for another time.