A cogent case for polyglotism in programming

When a dog owner wants to train his dog, the procedure is well-known and quite simple. The owner runs two loops: one of positive feedback and one of negative ditto. Whenever the dog does something right, the positive feedback loop is invoked and the dog is treated with a snack. Whenever the dog does something wrong, the dog is scolded and the negative feedback loop is used.

The result is positive and negative reinforcement of the dogs behavior. The dog will over time automatically behave as the owner wants and never even think of misbehaving

When a programming language trains its leashed programmer, it likewise uses positive and negative feedback. Whenever a problem is easily solvable in the constructs and features of said language, it reinforces the use of those features and constructs. And also in the same vein, if something is hard to do in the language, the programmer will shy away from thinking the idea, since it may be too hard to do in the language. Another negative feedback loop is when resource usage of a program is bad. Either it will use too much memory of too many CPU resources to carry out its work. This discourages the programmer from using that solution again.

The important point is that while all practical general purpose languages are Turing complete, the way they train programmers to behave as they want is quite different. In an Object Oriented language for instance, the programmer is trained to reframe most – if not all – questions as objects of bundled fields and methods. A functional programmer is trained to envision programs as transformations of data from the form X into the form Y through the application of a function. And so on.

(excerpt from One major difference – ZeroMQ and Erlang by Jesper Louis Andersen)

While I wouldn’t readily admit to the pertinence of  comparing a programming language to a canine owner in the way they interact with their primary subjects, the principle of positive and negative feedback loops extend beyond programming languages to the IDE‘s and platforms that we develop on. Beyond the industry, it is embedded in every tool and device we come in contact with, chipping away at every facet of daily life as we know it.

This is why I’ve spent significant pockets of my two week holiday wrapping my mind around the LISP-y Clojure and forcing myself to do it in Emacs (non-trivial, coming from many years of vimming). From the point of view of the final product, I’m hard pressed to point out any significant differences, i.e. It doesn’t matter what editor you use, or what language you code in; but from a educational and developmental angle, the benefits are rife and immense.

 

Day 95: Vim to Emacs

So it’s been 95 days since I decided that learning Emacs would be a worthy accomplishment, especially for someone whose grey matter has decidedly incurred permanent etchings from many years of vimming.

The process has been very start/stop. I probably only manage to persist at it for about 3 days before conceding temporal defeat and switching back to my old modal ways of text crafting. Since then, it has been pretty much stop.

Today presented itself as the perfect opportunity to dust of my C-c and M-x chordings and give it another short. Work brought Alexandre Salomé (of Symfony fame) all the way from Paris to give us a multi-day training seminar in the Symfony framework.

This first day was particularly suitable for reviving my latent Emacs chops because the Symfony topics covered were pretty basic. I was able to tweak the configuration files while listening in, and there were just enough type-along code exercises for me to, well, type along, and clock some time in this editor.

I’m led to believe I’ve made some good progress on this very long and arduous journey. I’ve got a git repository going for my .emacs files, copied stuff into my .emacs file mindfully, wrestled nxhtml-mode into running reasonably, and I’m begnning to enjoy C-x C-f-ing around my project tree in ido-mode and C-x b-ing between buffers.

The next things on my list to figure out is code folding (which I use a lot for work that I’m doing at the moment) and macros, which are just plain cool.

I also need a quicker way to modify/test my emacs config files.

Pity no one else at work uses Emacs.

Day 1: Vim to Emacs

Today’s my first day using Emacs at work. I picked a cognitively easy task (HTML markup editing) to practice on. Being somewhat wired up in Vim, I found myself thinking in terms of Vim operations, and trying to replicate it in Emacs. I know it’s not the most orthodox way of learning/doing Emacs, but it was the only way I knew to get started, and it’s helped me cope so far.

Here is my personal Vim to Emacs conversion table. It’s what I’ve been able to pick up and use fairly proficiently so far, in the order that made most sense to me as I picked the tool up.

“-” in the Vim column means I don’t know how it’s done, rather than Vim not being able to perform it. I expect that all these keys would work on a plain vanilla Emacs 23 install with no configuration or extra scripts added on.

You notice that I’ve used ctrl- and alt- notations directly instead of C- and M- which is the Emacs convention. I’ve done so because that’s what the labels say on the keyboard I use. Also, my brain is already bogged down enough making the cognitive leaps from Vim to Emacs, it doesn’t need to be bothered by M- to alt- and C- to ctrl- translations for now. If you’re not happy with it, go make your own list. Apologies to Mac users, you’ll have to think of alt- as your cmd- key.

Here we go.

 

Moving around

Vim Emacs
Left h ctrl-b (back)
Right l ctrl-f (forward)
Up j ctrl-p (previous)
Down k ctrl-n (next)
Start of Line ^ ctrl-a (alpha)
End of Line $ ctrl-e(end)
Left by a word w alt-f (forward, bigger)
Right by a word b alt-b (back, bigger)
Next paragraph ctrl-] alt-e (end of next line)
Previous paragraph ctrl-[ alt-a (alpha of previous line)
Start of buffer gg alt-<
End of buffer G alt->

 

Basic file and program operations

Vim Emacs
Cancel command esc ctrl-g
Open file :e ctrl-x ctrl-f
Save file :w ctrl-x ctrl-s
Quit :q ctrl-x ctrl-c

 

Making selections

Vim Emacs
Start selection v ctrl-space

 

Undo, Cut, Copy, Paste, Delete

Vim Emacs
Undo u ctrl-_ or ctrl-/
Cut d ctrl-w
Copy y alt-w
Paste p ctrl-y
Cycle through previous copies ctrl-y (once) alt-y (to iterate)
Delete x ctrl-d
Delete word dw (to clipboard) alt-d (no clipboard)
Cut line dd ctrl-a ctrl-k
Copy line yy ctrl-a ctrl-space ctrl-e alt-w
Copy entire buffer gg v G y alt-< ctrl-space alt-> alt-w

 

Move around with search

Vim Emacs
Search forward /[search chars] ctrl-s [search chars]
Search backwards ?[search chars] ctrl-r [search chars] (reverse)
Next result n ctrl-s (after Search forward)
Previous result N ctrl-r (after Search backwards)
Clear search :nohlsearch ret

 

Search and replace

Vim Emacs
Whole document :%s/[search]/[replace]/g alt-x replace-string ret [search] ret[replace]alt-x replace-regex ret [search] ret [replace]
Within selection (make selection):s/[search]/[replace]g (make selection)alt-x replace-string ret [search] ret [replace]

alt-x replace-regex ret [search] ret [replace]

 

Opening new lines

Vim Emacs
Before current line O ctrl-a ctrl-o
After current line o ctrl-e ctrl-o

 

Buffer splits

Vim Emacs
Split top/bottom ctrl-w s ctrl-x 2
Split left/right ctrl-w v ctrl-x 3
Close current split ctrl-w d ctrl-x 0
Close other splits ctrl-w o ctrl-x 1