3/29/2007

Zawinski's Law


Programs that mediate between the user and the rest of
the universe notoriously attract features. This includes not just
editors but Web browsers, mail and newsgroup readers, and other
communications programs. All tend to evolve in accordance with the Law
of Software Envelopment, aka Zawinski's Law: "Every program attempts
to expand until it can read mail. Those programs which cannot so
expand are replaced by ones which can".

Jamie Zawinski, inventor of the Law (and one of the principal authors
of the Netscape and Mozilla Web browsers), maintains more generally
that all really useful programs tend to turn into Swiss Army
knives. The commercial success of large, integrated application suites
outside the Unix world tends to confirm this, and directly challenges
the Unix philosophy of minimalism.

To the extent Zawinski's Law is correct, it suggests that some things
want to be small and some want to be large, but the middle ground is
unstable.

Eric S. Raymond, The Art of Unix Programming

3/19/2007

An Introduction to all these Emacs articles.

I had quite a bit fun hacking on Emacs lately, so I thought I write a little essay about it.

This is not going to be another Emacs tutorial that explains what keys you have to press to do XY. This wouldn’t make that much sense, because of the way Emacs was designed. The very most relevant argument for using Emacs is it’s extreme extensibility: It is not simply a scriptable text editor, but a construction kit for building editors.

So Emacs can use a modal approach like Vi(m) has them. It may be a slim tool that takes less than a second to load, or a full operating environment that takes a several seconds long startup time. Pressing the i key could write the letter ‘i’ into a text buffer, switch you to insertion mode or nuke the Vatican. Changing Emacs to act exactly as you want is how Emacs is supposed to be used. If there is a feature that you are missing, you will find it on the web. And if what you want is so special that no one did it before, you can hack it into Emacs yourself.

So it makes little sense to talk about the standard configuration and features that come with a fresh installation.

I’m also not going to list cool features that Emacs does nor will I give you tips on how to use it. Instead of repeating what others already wrote many many times before, I will add some links to tutorials, essays and communities at the end.

This article is about the first thing you want to know about Emacs: “Why do people care?”. I will try to explain why many are so dedicated to text editing that they keep writing about it and why they prefer a 25 years old tool over any other text editor.

Editing Text

If you do something very frequently, even the smallest shortcut will save you a lot of time in the end. And because editing text is one of the most frequent things people do with computers, it makes sense to optimize this task as much as possible. Editing text is such a common task that there are endless ways to make you more productive. And you will continue to write and edit text for many, many years, so even if it takes you a while to figure out how you can improve that one task you keep doing, it will still save you time in the long run.

Of course, even if mostly everyone who uses a computer writes a lot of text, not everyone will want to learn such a complex tool as Emacs. The time you spend can be worth it, yes, but not for everybody.

One very important requirement is that you use a single text editor as much as you can. You might hack a whole book each day into your keyboard, but if you write that letter in word, that 10 emails in Thunderbird and use the text area in your web browser to compose blogs, you will find yourself using half a dozen different editors. And because they are all written by different people for different tasks, the only things you can rely on is a very small subset of common features.

I write nearly every longer text in the same editor. As soon as I realize this is going to be more but a few sentences, I compose my Emails, Essays, Papers, Letters, Source Code, Instant Messages, Blog Posts, Wiki Pages, Bug Reports and so on in Emacs. After I’m done, I copy it to my browser, my word processor,… I’m not lying to you, there are exceptions. I produce most of my Java code in Eclipse, which really sucks at text editing but has other features that keep me from using Emacs.

Every now and then, I review the way I work. I search for tasks that require a lot of repetition and evaluate the options I have to automate this process. If there is a solution that will cost me a reasonable amount of time, I implement the solution. First into my tool, then into my daily routine.

Why Emacs?

Once you decided that you want to use a single editor all the time, for the rest of your life, you will agree that there are obvious minimum requirements this text editor should meet:

  • It should run on all the major operating systems. If you cannot guarantee that you will always have the freedom to choose what platform you are working on, and that you will never want to switch to another operating system, you surly don’t want to spend hours/days/months/years learning a tool that does not work on your next workplace. I am perfectly fine with tools that work only on a single system, as long as they are easy to replace. A text editor is not one of these tools.

  • It needs to be highly extensible. This is maybe the most important property you should consider. If you have to rely on the editors core development team, you will wait forever for the features you need. Development teams have schedules, priority lists, other projects and, most dreadful of all, their own vision of how to work with a text editor. But if anyone can extend the tool and put the extensions online, the number of your editors features raises from n to infinity.

  • Like with an operating system, a text editor is good for end users if it is easy for developers to build stuff on top of it. Things that make developers happy include rich APIs, a powerful programming language and seamless integration of the new features into the platform.

  • The editor needs to be popular. A huge community means active development, lots of existing extensions and support. If you want to use that thing 10 years from now, someone has to continue working on it.

Once you rule out all the editors that miss one of these requirements, you will find that there are not that many choices left anyway.

The next thing you have to decide is how much time you really want to to invest. If you do a lot of text processing and you are willing to study ways to improve it, you might first consider Vim. Vim is a beautiful and intelligent designed, scriptable and powerful text editor ready to use.

Consider Emacs if editing text is so important to your life that it makes sense to invest hours/days/month/years to create a tailor-made tool that is perfectly suited to exactly your way of working. A tool that does all the things that you want the way you like it. Be aware that you should bring some technical skills with you, and hacking lisp on a Sunday evening should sound like fun.

Emacs is different

As I wrote earlier, what makes Emacs interesting is its extreme focus on customization. Here is how most editors are designed: A group of (hopefully) skilled developers create the tool, which contains a lot of features. Then they create an interface that exposes parts of that functionality as an API. Most of the time, this interface is bound to some kind of scripting language that Users can then use to write plugins, which communicate with the editor through the provided functions.

Emacs is different. Instead of communicating through an API, you edit and add to the original code itself. So your own code becomes a coequal part of the system.

“Therac25” wrote a comment on reddit that explains the difference between the two styles:


"extension language"? "integrates with"? You don't even seem to get it :-)

1. Theres "Emacs the lisp machine", which is the lisp interpreter
   and core drawing libraries -- this provides a language called
   Emacs Lisp, and a runtime.

2. Then there's "Emacs the editor", which is implemented in Emacs
   Lisp (there's no "integration" to speak of -- they aren't
   separate things). This is what people usually mean when they
   say "Emacs".  

3. Then there's the set of packages which come with Emacs in a
   default installation -- some of which are loaded
   automatically (tramp being a useful example), some of which
   you have to explicitly load.

4. Then there's the code you write yourself, either as simple
   configurations in your .emacs, to functions that you can bind
   to a key, to changes or redefinitions of existing modules, to
   entirely new modules.

There is no physical, logical, or in any way material distinction
between code at levels 2, 3 and 4. You can redefine any of the
system-provided functions in your .emacs if you want to --
everything you write or create in Emacs Lisp is on equal footing
with all of the application logic of "Emacs the editor".

As an example of this, if you put this in your ~/.emacs:


(defun delete-backward-char (n &optional killflag)
  (interactive)
  (insert "stinky-poo"))


You've just overridden the built-in function that handles
deleting characters -- your backspace (or delete, depending on
your keyboard) key will now call you stinky-poo for trying to
delete characters.

Addendum: I should also clarify that the ~/.emacs file is in no
way special -- it's simply a convention. You can do the above by
typing it in an arbitrary buffer, selecting it and running M-x
eval-region or even by typing it out at the M-: prompt. You can
change how everything in the the system works, dynamically, to
suit your needs.

This kind of architecture has huge advantages oder the API approach:

  • your code feels like it actually belongs to the editor. No matter if you bind it to a key, use it in some other extension or if you ask the build in documentation, your new function behaves exactly like all the others.

  • It is very easy for the core developers to integrate code into the core distribution. This is how Emacs works for more than 20 Years.

  • You are not bound to the restrictions of an API. You have full access to the whole thing, so you can do with it whatever you want.

Of course you can just use Emacs in its default configuration, without any customizations. But then you don’t take advantage of it, and, honestly, I personally would prefer Vim over a new installed, unconfigured Emacs.

So that is why so many people use Emacs, after so many years: There simply are no other editors that you can extend so freely and so easy as Emacs. If customization is your highest priority, Emacs is the only one that is popular and runs everywhere.

Finally, customizing Emacs can be fun. This is not a hobby for everyone of course, but I don’t want to create the false impression that all the hype about Emacs is just about productivity. For many programmers, hacking on a beautiful and intelligently designed tool they use every day is actually quite fun. Sometimes this can be even more rewarding than the time you save using it.

Now, as promised, some pointers to more Emacs stuff:

Get Emacs

W32 Emacs GNU Emacs optimized for Windows.

Aquamacs and CarbonEmacs are Emacs distributions for OSX.

Learn Emacs

If you want to learn how to use Emacs, the slides from its class at MIT are very good. (Yes, there is a MIT class about Emacs).

You will find tons of advise, as well as lots of extensions at the Emacs Wiki.

Wikipedia’s Emacs Page has lots of information too, like the history of the Editor.

Steve Yegge has lots of good stuff to say about Emacs. Read his Effective Emacs and all the other Yegge-Emacs stuff.

Programming in Emacs Lisp, Emacs Lisp Manual, GNU Emacs Manual are all free books that do also all come with most Emacs distributions.

3/17/2007

My name is Ben and I'm a Social Software Junkie

I always knew that I'm somehow addicted to the internet but I just realized that it gets worse every day.

I cannot stop refreshing my news reader, techmeme.com, my reddit recommendations, my digg/de.licio.us mashup, my "read this" list in my google bookmarks, various community sites (newsgroups, discussion forums, wikis u.a.), some subscripted blog searches and more.

I'm serious, I'm totally screwed up. I feel like I'm in one of these drug experiments where the rat cannot stop hitting a button to get one more dose of cocaine. I call that damn button refresh, and I keep hitting it all the time.

I need to do something about this. Not sure what, but I will fight this ridiculous information overload. I want to consume less and produce more.

As a first step, I changed my browser setup. This is how it looked like when I opened Firefox this morning:

and this is my new setup:

Of course this is just a first, small step. I also consider pulling the plug from my router when I'm working at home.

3/16/2007

What Google is thinking about me (Part 2)

"Web pages related to your searches"

3/14/2007

Shakespeare

question = (0x2b||!0x2b)

3/12/2007

Pretty Print XML With Emacs

There seems to be no way in Emacs's nxml-mode to pretty format a block of xml code. However, here is one.


(defun bf-pretty-print-xml-region (begin end)
  "Pretty format XML markup in region. You need to have nxml-mode
http://www.emacswiki.org/cgi-bin/wiki/NxmlMode installed to do
this.  The function inserts linebreaks to separate tags that have
nothing but whitespace between them.  It then indents the markup
by using nxml's indentation rules."
  (interactive "r")
  (save-excursion
      (nxml-mode)
      (goto-char begin)
      (while (search-forward-regexp "\>[ \\t]*\<" nil t) 
        (backward-char) (insert "\n"))
      (indent-region begin end))
    (message "Ah, much better!"))

Update: I was wondering why I had to write such an obviously useful function by myself. Turns out that there is an interface to HTML Tidy, which, among many other ways to manipulate XML documents, also does pretty printing. Anyway, if you don't want to install tidy, the simple function above will work just fine.

3/11/2007

You and My Lovely Books

lovelybooks.de is a new player in the social book services game.

I find social book services quite interesting: They can help me find new books, people who read the same stuff as I do and provide a place to discuss a good read. I guess the most popular book community is currently Amazon, but that does not feel right because Amazon is not as much a community as it is a shop. When I was recently looking for books, I found 2 promising services:

Shelfari was recently acquired by amazon. Unfortunately, it only allows searching and adding books from amazon.com. This means that if I want to add my copy of Herbert Rosendorfers Briefe in die Chinesische Vergangenheit, I have to search for the English translation instead. And there is no way to add the Fischer Weltalmanach, since that book is only available via Amazon’s German branch.

buchpfade.de works with amazon.com, .de and .co.uk, so I can add almost any book I want. But the service is only available in German, and there are serious performance issues which takes the fun out of using the service.

However, buchpfade announced today that the started a partnership (whatever that means) with lovelybooks.de. lovelybooks is a new social book service from last.fm co-founder Michael Breidenbruecker.

The page is still beta (and currently only available in German), but looks very promising and might become my favourite social book application.

One thing I am missing in all these sercives however is a possiblity to export my booklist. Shelfari has at least an option to import books from a list of ISBN numbers, but it has to go the other way around as well. Adding every book I ever read will take a lot of time, and I really do not want to do this more than once. So please just give me an option to import and export my books as a simple list of ISBN-13 numbers. Thank you!

3/08/2007

God Wrote in Lisp Code (mp3 and lyrics)

eternalflame.mp3

(define lyrics '(

I was taught assembler in my second year of school.
It's kinda like construction work - with a toothpick for a tool.
So when I made my senior year, I threw my code away,
And learned the way to program that I still prefer today.

Now, some folks on the Internet put their faith in C++.
They swear that it's so powerful, it's what God used for us.
And maybe it lets mortals dredge their objects from the C.
But I think that explains why only God can make a tree.

For God wrote in Lisp code
When he filled the leaves with green.
The fractal flowers and recursive roots:
The most lovely hack I've seen.
And when I ponder snowflakes, never finding two the same,
I know God likes a language with its own four-letter name.

Now, I've used a SUN under Unix, so I've seen what C can hold.
I've surfed for Perls, found what Fortran's for,
Got that Java stuff down cold.
Though the chance that I'd write COBOL code
is a SNOBOL's chance in Hell.
And I basically hate hieroglyphs, so I won't use APL.

Now, God must know all these languages, and a few I haven't named.
But the Lord made sure, when each sparrow falls,
that its flesh will be reclaimed.
And the Lord could not count grains of sand with a 32-bit word.
Who knows where we would go to if Lisp weren't what he preferred?

And God wrote in Lisp code
Every creature great and small.
Don't search the disk drive for man.c,
When the listing's on the wall.
And when I watch the lightning
Burn unbelievers to a crisp,
I know God had six days to work,
So he wrote it all in Lisp.

Yes, God had a deadline.
So he wrote it all in Lisp.))

Parody of “God Lives on Terra” , words and music by Julia Ecklar

[via Bill Clementson]