defining the interface for rubymonk

Discussing an interview I had yesterday --quite interesting when delivered with Aninda-- with a non-technical friend, we stumbled on the fact that everything in Computer Science is an interface. From the moment you differentiate data from code, which wasn't immediately obvious to even the first computer programmers twiddling individual bits....

Everything you build in software is defined by an interface. These are the boundaries, but they're also where the magic happens.

Here are some interfaces:

http://www.c42.in/a_url_is_an_interface/
(We'll come back to this.)



$ ps aux | grep clojure




At this point, I had to stop to explain how a function works. Does this help? (Hey Blogger or Google or whoever the heck is in charge: why can't that image be an SVG?)




Objects are the next interface to consider. They are a bundle of functions. Actually, they're more complex than that. They are a bunch of closures... actually, dispatching closures. (Okay, I've lost my non-technical friend at this point. Oh well.) There are other ways of looking at them, but we'll take the perspective of the function, which we already agree is quite simple. To the function, the object looks like a set of rules about how one defines interfaces with functions. Objects can be made of functions but it's not quite so the other way around (though the object may consider this point contentious or even academic). The function doesn't care. To him, an object is just a cluster -- however small -- of functions who have been told in advance that part of how they behave must change, because of the way they were set up... this time, at least. And what's worse, just because an object has been set up -- it won't necessarily stay that way! Yikes. Looking at it from the outside, the function pities the object. The function can choose to behave this way but the default position of the function is, "I never change!" The object changes himself (or worse, allows other, unknown objects to change him). It takes some work for the function to behave so sloppily; you need multiple functions -- and functions returning functions, no less (as a type's constructor returns a function whose sole purpose is dispatch based on the type of the first parameter and the name of the second -- usually with these parameters taking special positions, like first_is_an_object.second_is_a_method. I digress.). Such effort forces a conscious choice on the part of the person writing that function. "This risk is worth it!" you say, and an interface of your choice, with complexity of your choice, emerges.




Finally, at the top of this scale are languages. They themselves are composed of functions and objects. In fact, most compilers and interpreters for languages can be thought of as pure functions: I give you the language, you give me the binary, assembly, bytecode, or runtime language (JS, these days). This is the most complex interface. Usually, a human still speaks to this interface. In 2012, this interface is fully-manual. These humans are called programmers. And the best of them will make it their task to automate away their own job. But, as of 2012, programs that write programs are risky and difficult. Automation can be seen on any of these other scales (functions and data) without writing your own macro or yet another compiler or parser. Choose a language which gives you this option when you have no other choice, but be careful to wield such a weapon when you see no other way out. Otherwise, it is a simple interface you want.



Kitty pointed out to me that I haven't called out a very important point: All these interfaces are fundamentally the same. They accept some input and produce some output (even if that output is a side-effect). Objects are built of functions, and they're both built of languages. And the languages are built of objects and functions. What differentiates each one is the mental energy required to contend with the interface's complexity. Stateless interfaces -- such as immutable objects, pure functions, and HTTP -- are always easier to understand because there are fewer balls in the air. The "given" of given-when-then doesn't apply if there's nothing to set up. There's only when and then.



This makes the interface for RubyMonk interesting. There is of course a very cute visual style to rubymonk.com (yeah, we love it too), but the real interface is the user's interaction with the mentor -- how we evaluate their progress and the programs they write. How we assert that something they've done is correct -- because the programs they write are data to us. As we teach more complex concepts, this interface itself will become increasingly complex by its very nature. Or, perhaps, we will realize the beautiful intrinsic quality of data that is code and code that is data, leading us to discover an elegant solution to the automation of the Hacker Mentor.


zero to emacs in under 5 minutes

You want to write Clojure. You want to write it in Emacs. Here's how.

1. Grab Leiningen.

mkdir -p ~/bin
cd ~/bin
wget https://raw.github.com/technomancy/leiningen/stable/bin/lein
chmod +x lein
echo 'PATH=$PATH:~/bin' >> ~/.profile
lein self-install

This will get you leiningen, Clojure's build tool.


2. Grab Clojure.


cd ~/code
lein new my-first-clojure-project
cd my-first-clojure-project
lein deps
`lein deps` will bring down a local copy of Clojure. Look in ~/code/my-first-clojure-project/lib !


3. Grab swank-clojure.


lein plugin install swank-clojure 1.4.0
This gives you the `clojure-jack-in` command in emacs. It's your samurai sword.


4. Grab a healthy .emacs config.

mv ~/.emacs ~/.emacs.bak
mv ~/.emacs.d ~/.emacs.d.bak
git clone git@github.com:c42/dotfiles.git
ln -s dotfiles/emacs.d ~/.emacs.d

5. Grab an emacs.

Ubuntu: https://launchpad.net/~cassou/+archive/emacs
OS X: http://emacsformacosx.com/emacs-builds/Emacs-pretest-24.0.94-universal-10.6.8.dmg

Running emacs for the first time will automatically install all the packages you need. Now run your first emacs repl!
M-x clojure-jack-in

TADA!

finger brains


Okay, so now I'm back on my own computerand it's a race against myself. Crap. I still seem to be making mistakes. I guess I just can't type all that well when I've had ad couple. Shit.
Well, this is all I can think of so I'm going to stop typing in 3 2 1....
My housemate Nikhil (and not my other housemate Nikhil) and I had a typing race on our two respective keyboards. It lasted only a few seconds. We were racing ourselves to test the keyboards (MacBook Air vs. ThinkPad 410-something-something). We each preferred each other's machines but I would only trade this for an X1 covered in leather. Our conversation led to a cross-comparative question "why should I care about my typing speed?" to which was returned one of my favourite stories:
Duke Huan was in his hall reading a book. The wheelwright P'ien, who was in the yard below chiseling a wheel, laid down his mallet and chisel, stepped up into the hall, and said to Duke Huan, "This book Your Grace is reading--may I venture to ask whose words are in it?"
 "The words of the sages," said the duke.
 "Are the sages still alive?"
"Dead long ago," said the duke.
"In that case, what you are reading there is nothing but the chaff and dregs of the men of old!"
"Since when does a wheelwright have permission to comment on the books I read?" said Duke Huan. "If you have some explanation, well and good. If not, it's your life!"
Wheelwright P'ien said, "I look at it from the point of view of my own work. When I chisel a wheel, if the blows of the mallet are too gentle, the chisel slides and won't take hold. But if they're too hard, it bites in and won't budge. Not too gentle, not too hard--you can get it in your hand and feel it in your mind. You can't put it into words, and yet there's a knack to it somehow. I can't teach it to my son, and he can't learn it from me. So I've gone along for seventy years and at my age I'm still chiseling wheels. When the men of old died, they took with them the things that couldn't be handed down. So what you are reading there must be nothing but the chaff and the dregs of the men of old."
Wait. Maybe I meant to read him the one about the buckle-maker who focuses so intently on his craft of making buckles that he couldn't see anything else. It wouldn't be the first time I've confused them. Anyway, if you can't type in one continuous stream (higher speeds are largely irrelevant but a 100wpm minimum wouldn't hurt), you're losing little tiny brain spasms to figuring out which keys to hit. These little tiny brain spasms could be helping you figure out what `self` is in the median of your code while trying to remember how to write a class method which generates class methods in Ruby. Because that's how brogrammers like you and me get our tickles. These little tiny brain spasms are basically the opposite of sleep. Shoot them down with your giant space laser-equipped pelican-shaped airship! And then just run under Bowser because you don't actually have to kill him. The beautiful Mavis Beacon awaits on the other side.