Programming is for girls!

My buddy Anne recently posted some of her favourite articles on the subject of women in Computer Science. I wrote an article last year which presupposed her question, "Programming is for girls?" My answer? Programming is for everybody!

Granted, not everyone who writes an Excel macro will be so enamored with their creation that they feel the need to master Haskell. The wonderful thing about Computer Science today is that they could. Thanks to the tiny (almost negligible) barrier to entry, the only thing left to tackle is the stigma.

Programming is already social. I prefer pair programming because I'm ADHD and it's the only way I can ever accomplish anything. But I also get to hang out with friends all day as a side benefit. Code is literature, a communication medium. It's fascinating that our little code-robots do something but it's a great deal more important that it speaks to people.

But: Not every software company is an inherently social environment. Yet.

Programming is already creative. In many ways, it's a purely creative endeavour. Outside the speed of light, there aren't many limitations placed on the raw imagination in a world of code.

But: Many software projects are still about doing the same old thing to a different piece of data.

Programming is already sexy and relevant. Startups are sexy by their very nature. Everyone knows what you're talking about if you say you work for Google or Apple. Most people you know already have a phone they've used to install software while they ride the bus.

But: Not everyone gets to work for a startup or Apple.

You can't have it all but you can certainly have most of it. Think your job isn't sexy? Automate the boring parts or quit. It's a seller's market these days. Try out a new technology, if that excites you. Talk to your coworkers. Work with them directly. Find a broader solution to an entire category of problems. Send your resume to that one company you think is really kicking ass.

There is a real spectrum of significance to the machines we build and the companies we build them for. Create some partial orderings to demonstrate this to yourself. Which is more significant? Clean water or banking? Auto insurance or rice? Diabetes research or zinc? Middle school education or vodka? Public transportation or plywood?

Not everyone considers the world in the same way and most of us will change our opinions over the course of our lives... but some parts of our society have obvious gravity. If you're already in software, let that gravity pull you in. If you're considering a career in software, contemplate the fact that a career in software really means a career in any field you want: from water purification to zinc froth flotation.

Girls, software is already sexy. Get on the trolley.

Clojure Macros: How Evil?

Dan asked me at the Chicago Clojure Meetup this week if Clojure macros tend to send developers into the death spiral of metaprogramming Ruby's various hooks did when we first discovered those.

tl;dr: no.

The canonical example of evil Ruby metaprogramming is everyone's favourite this-will-trim-8-lines-of-code hack: strings to method names. Have you ever written something like this?


Sure you have. It's okay. We've all sinned. Are you prevented from doing this sort of thing in Clojure? Nope. No more than you are prevented from doing it in Java. But in Clojure and Java, the apparent innocence of Ruby's `send` method is revealed to be a sham: Reflection feels bad in these languages.

All of Ruby's other metaprogramming hooks have something in common: define_method, const_get, method_missing, every flavour of eval, monkey-patching... and all their friends... happen at runtime.

The behaviour of my first few Clojure macros confused me because I was accustomed to Ruby's runtime powers. Clojure's macros are expanded, go figure, at macro expansion time. As such, they have a few interesting and related properties:

  • macros feel like adding a feature to the language
  • ruby metaprogramming feels like mutating the language
  • macros cannot use runtime data to generate dynamic code
  • ruby metaprogramming requires runtime data to generate dynamic code
  • macros require a new way of thinking about code generation
  • ruby metaprogramming is just a higher-level imperative layer 
Macros also have a very clear usage pattern (see Christophe's wonderful (not= DSL macros) presentation from the first ClojureConj):

data formats > functions > macros

This is to say: Build your functions on top of your data. Build your macros on top of your functions. Macros should always be a convenience rather than a requirement. This one little rule is often enough to remind yourself that "write a macro!" usually isn't the solution you're looking for.

We're probably better off to avoid comparing Ruby's metaprogramming facilities with macros at all. It makes more sense to compare Ruby's hooks to Clojure's reflection and Ruby's eval to Clojure's eval -- neither of which I've seen used in a production Clojure application. Macros actually stand out on their own, since Ruby doesn't have an equivalent feature.

Can you still write a steaming pile of magic in Clojure? Of course. Once you suffocate your desire for elegance, you can reflect and eval and macro your way into a painful and confusing labyrinth of obfuscated code just as you can in any other modern language. But Clojure's libraries and language features usually display enough power on their own that you aren't tempted to shortcut your way into an impenetrable structural abstraction. At least, I haven't seen it yet.

Open Letter to Pascal

My friend Pascal recently asked me what books I would recommend he read to learn the basics of programming. He'd been looking into it for a while but simply couldn't decide where to start, given the multitude of programming books available.

I'd be the last to claim I've swum a majority of the book lagoon, but I have found over the years that the majority of programming books are neither timeless nor all that well-written. Pascal's response seems obvious, in retrospect: if I could start it all over, what would I read?

In Pascal's case, I'd recommend The Structure and Interpretation of Computer Programs. As a Math teacher, he should find the calculus-based examples in the early chapters relatively easy -- if not downright intuitive. SICP is easily the richest and most thoughtful programming book I've ever read. Were it not for all the math it assumed familiar to the reader, I'd recommend it to everyone above and beyond all other texts in the discipline.

For everyone else (myself included), I'd put The Little Schemer at the top of the list, quickly followed by The Seasoned Schemer and The Reasoned Schemer. The books are a joy to read thanks to their peculiar style and between them convey many of the ideas SICP presents as a more traditional academic text.

Why not Learn to Program or Learn Java in 21 Days?

Most introductory programming books and online tutorials (even Why the Lucky Stiff's Poignant Guide to Ruby, in all its humour and beauty) make a grave mistake in their introduction to programming: They misrepresent syntax as the first principle of writing code.

If the first chapter of your introductory literature explains the representation of strings and numbers in [insert-your-language-of-choice-here], you've already started your reader off on the wrong foot. Worse yet, there's a temptation to teach new programmers about variables, mutation of state, and side-effects -- such as printing to the console.

One does not require dozens of books and years of practice to understand the essence of writing software. But in my case, it took as much to unlearn the bad habits taught by my first texts.

FlyMake does not like JRuby

JRuby often works out-of-the-box wherever MRI does. FlyMake is not one of those cases.

Flymake expects a particular format for error messages returned from the interpreter: MRI error messages. Charlie and Friends have decided the MRI error messages can be a bit opaque, and upgraded them to something a little more readable. Sadly, this breaks anything attempting to parse those messages.

Gaz and I decided to try switching things back to MRI so we could get our syntax errors highlighted in emacs. Lo and behold! Everything's happy again. As an added bonus, you don't need to wait for JRuby (and thus, a JVM) to start up every time FlyMake runs.

You can grab our changes with our latest emacs-starter-kit:

If you're using Phil Hagelberg's emacs-starter-kit, make the appropriate change to starter-kit-ruby.el:

- (list "ruby" (list "-c" local-file))))
+ (list "/usr/bin/ruby" (list "-c" local-file))))