Wednesday, March 19, 2014

Learning C & Clojure In 2014

A tweet got me started on the idea.

(I started with BASIC when I was 11, and began doing all kinds of random web stuff long before I ever learned Lisp, but better late than never.)

To be fair, I basically already learned Clojure last year, in the sense that I took a workshop on algorithmic music in Common Lisp and translated what I was learning into Clojure so I could use Overtone and Quil to make MIDI-controlled generative art and Markov chain basslines. But translating entry-level Common Lisp into entry-level Clojure is pretty damn far from really learning Clojure, so that's still happening in 2014.

I built this with Clojure last year.

I normally scoff a little at the "learn a new language every year" thing, for a few reasons. First, there's a risk there of creating language hipsters, and that theoretical danger is quite obviously often realized. (You know who you are.) Second, the whole idea came from the Pragmatic Programmers, who are book publishers after all. Can we say "conflict of interest?" It doesn't completely invalidate the idea, but it's still pretty sensible to take "learn a new language every year" with a grain of salt when it's coming from a book publisher.

Third, in every programming language that I know well, I can very quickly spot the difference between somebody who's been using the language for years vs. somebody who's been using it for a year or less. It might take more than a year to learn any given language. You can write a lot of things in JavaScript before you ever have to give any serious thought to bind, call, apply, or this.

I first built something with Clojure in 2008 or 2009, so it's safe to say I've spent more than a year learning Clojure already, and I'm pretty damn sure it'll take me more than a year to get anywhere serious with C, but that's fine. I'm learning C because it's the foundation for Objective-C (along with Smalltalk), and because I ultimately would like to be able to build synthesizers for iOS with Objective-C. I'm pretty certain that if/when I do that, I'll want to drop down to C for some of the heavy lifting. Most of the serious literature on writing synths uses C or C++, and although I haven't been able to find a link for this post, I once saw John Carmack say that in developing Infinity Blade for iOS, they saw massive performance gains (something like 20x) just by abandoning NSString in favor of traditional C strings.

Another major reason I'm learning C and Clojure: the evolution of JavaScript. I mainly work in JavaScript and Ruby, and while Ruby's not changed very much in the 8 or 9 years I've been working with it, JavaScript's morphed into a completely different beast. Today, if you want to use JavaScript to its fullest potential, you're getting into WebGL, and that requires a very C-like mentality. But if you want to write clean, readable JavaScript, you're also getting into functional programming. So I think this work with C and Clojure will make me better at JavaScript.

There's yet another reason:

This excellent piece of work was put together by friends of friends, who are looking for a CTO. This was the first "we're hiring!" email I've seen in a long time where I just wasn't qualified at all -- background required in electrical engineering and embedded systems -- and it was also the most appealing. This prompted me to look into similar job postings, and all of them require Processing, which is easy, and openFrameworks, which requires C++, which is of course built on C.

(In fact, pretty much everything is built on C. If you're interested in hacking on Ruby's internals, or Python's, you need C. If you want to hack on the V8 JavaScript engine, or WebKit, you need C++. Come to think of it, I saw another interesting job ad which required a C background - Mozilla's hiring a research engineer to help them build Rust.)

I've also seen some very inspiring work in Clojure, and everything Arduino runs on C.

Anyway, just to end with some useful tips, I haven't gotten into the classic text yet, but I've found these books useful for C, and I personally like The Joy of Clojure over either Clojure Programming or Programming Clojure, although I've gotten some mileage out of both of those, despite their repetitive naming scheme.

(Actually, when it comes to books, Pat Shaughnessy's Ruby Under A Microscope is another major reason I got curious about C.)