Wednesday, January 28, 2009

Brain Rules

I just read John Medina’s book Brain Rules. It is a book about how our brains work. What I find most interesting is how it applies to learning.


Our brains are able to pay attention to three things. It can be characterized by these questions.

  • Does it want to kill me?
  • Can I have sex with it?
  • Does it remind me of anything?

All three questions are relevant to how you give a presentation. If everyone seems to be dozing off they can be awakened by I sudden sound or a picture of something sexy. But these measures are just that, attention grabbers, and if a presentation is so boring that I have to slam the table all the time I’m definitely doing something wrong.

The third question: Does it remind me of anything? is different. It is very important both to giving presentations and to learning. If I can find a way while giving a presentation to have the audience relate to my subject in any way, they are more likely to pay attention. It’s the same with learning. If I’m learning something that reminds me of something else it will be easier for me to put it in a context that means something to me and that will enable me to learn it much better.

I find this very interesting since lately I’ve found that I like doing things that I suck at. The things I like and suck at are very diverse. I have started to like skateboarding, playing Guitar Hero, and even carpentry. I think that it is because I know more now and even if I’m no good at these things they remind me of other things that I’m better at. And just as important, they widen my frame of reference, so next time when maybe I have to weld something I wont find the entrance barrier to high to even imagine doing it. The more I recognize, the more I relate to, the more I like. It is a good loop.


In the book Medina also talks about memory. There are, at least, two kinds of memory, short-term memory and long-term memory. The short-term memory is our working memory and it is good for very short periods of time. To store something in long-term memory, repetition is required. The more I repeat something, the better I will learn it.

The best books I have read that take advantage of repetitions without being boring are The Little Schemer-series, The Little Schemer, The Seasoned Schemer and The Reasoned Schemer. These books are built up as a series of questions in one column and the answers in another. The difficulty increases gradually as you read more.

The point of The Little Schemer is to teach to think recursively in Scheme. It does a great job of teaching this, probably because of all the repetitions that are involved.

The point of The Seasoned Schemer is to teach more advanced concepts of functional programming in Scheme, such as continuations.

The point of The Reasoned Schemer is to teach logic programming in a functional context.

It is interesting that the concepts taught in the books are quite complex and still they never feel hard when presented in this way. I highly recommend them to anyone.

Another interesting thing about repetition is that it seems to be happening while we sleep. When we are sleeping our brains keep repeating things that we learned during the day. After going to sleep while reading The Seasoned Schemer, I remember waking up one morning and finally getting how continuations work. Quite a good feeling.


Stress affect learning in a bad way for almost everybody. Stress is defined, to allow researchers to measure it, as having three criteria.

  • It has to create physical arousement.
  • If you could avoid it, you would.
  • It has to feel like it is out of your control.

If any of the above is true, it is said to be stress. When we are stressed our brains cannot focus on the task at hand and this will decrease our learning abilities severely.

You can also listen to John Medina talking about the book on the Ruby on Rails Podcast.

Monday, January 19, 2009

Making the Mac OS X Terminal Hum

I recently had reason to get back to hacking at the command line again and it certainly is a pleasure. At least it was before some annoyances started to ruin my day.

The Terminal in the Mac has been improved with tabs in Leopard making the iTerm application that I used on Tiger redundant. New tabs are easily opened with Cmd-T and closed again with Cmd-W. But if I want to move between them I have to press Cmd-{ and Cmd-} which is closer to a vulcan nerve pinch than I am comfortable with.

Luckily my old license of Menu Master comes to my rescue. Menu Master ($12) is a simple tool that lets you reconfigure the menu shortcuts painlessly. So now the tabs can be easily switched with Cmd-Left and Cmd-Right as they should.

Next step is to configure bash to support my commands. My Emacs days are long gone and I don’t like to have different sets of shortcuts for the same thing in different applications. Bash uses readline for editing on the command line. I can choose between Emacs-mode and VI-mode. Emacs is still closer to my heart so I start out with this.

Aaargh!, What!, the Option key is not sent as a Meta-key and nothing works as it should. A quick look in the Terminal preference window on the Keyboard tab, shows me that I can check the use option as meta key. That sounds right…ok, here we go: Meta-delete – deletes word, Meta-. – inserts last argument of previous command, Meta-T transpose words,... Hey, we’re moving!

Ok, now I’ll just check what I did since yesterday:

git log @{yesterday}

What! No friendly at-sign appeared by the cursor, instead we move into some stupid digit-argument mode. Bastard international keyboard requiring me to use the Option key to write a simple at-sign. Ok, back to the drawing board. readline can be configured with an .inputrc file. Here’s a fix to all the number keys.

"\e1": "©"
"\e2": "@"
"\e3": "£"
"\e4": "$"
"\e5": "∞"
"\e6": "§"
"\e7": "|"
"\e8": "["
"\e9": "]"
"\e0": "≈"
"\e/": "\\"
"\e(": "{"
"\e)": "}"

While we’re editing this file we might as well add some candy to the sugar.

# Shows all files instead of beep when tab-completing
set show-all-if-ambiguous on
# Ignore case when completing, very nice!
set completion-ignore-case on

"\e[1~": beginning-of-line    # Home key
"\e[4~": end-of-line    # End key
"\e[3~": delete-char    # Delete key
"\e[5C": forward-word    # Ctrl+right 
"\e[5D": backward-word    # Ctrl+left 
"\e\e[C": forward-word    # Alt+right 
"\e\e[D": backward-word    # Alt+left
"\C-K": unix-line-discard   # Ctrl+K 
"\e\"": "@{}\e[D"     # Insert @{} move cursor into braces

Thanks to Antibaddy on Stack Overflow for help with the last one. Ok, we’re on track again. I’ll just update my .bashrc with the nice git bash extension, git-completion.bash.

mate ~/.bashrc

Sure enough, no tilde appears. I thought I could go back to .inputrc again to fix this. But the tilde is a dead key on my Swedish keyboard and it does not even seem to arrive to the Terminal when the option as meta is on. I never liked dead keys anyway but how can I get rid of them. When installing Ubuntu it is as easy as selecting a Swedish keyboard with no dead keys. Not as easy on the user friendly Mac… Can mighty Google help me. Not really. I found a couple a clues in the Apple developer notes, but it seemed to involve firing up XCode and hacking away at a brand new keyboard layout!

I’ll ask Stack Overflow again. Sure enough, a tool called Ukelele can be used. Just start it up, base your new keyboard layout on the one you are using, double-click on the dead keys, and terminate them. I got rid of all my dead keys and while I was at it I changed my umlaut (¨) to tilde (~) and vice versa. I type tilde quite often in comparison with umlaut and I’m wiling to make the mistakes I will make on a foreign keyboard.

Now I’m finally set to go. :)