Hamon or the Skin Deep Beauty of Code

The craft of programming is a little depressing: you spend days and nights pushing bits inside a computer, weaving a pattern that will ignite the right pixels on monitors or magnetize the right atoms on disk platters. But it is craft nevertheless, except one where beauty matters very little. Coders create the true ukio-e – floating world, but one that is as ugly as it is fleeting.

I’ve read a good chunk of Beautiful Code: Leading Programmers Explain How They Think, but I’m still far from understanding what beauty is in code. Ugliness is self-explanatory: if you recoil in horror after reading a few files, it’s ugly. I recoil on the daily basis.

I’m not talking about the success or usefullness of things that code creates. I am pretty sure that the code that runs plentyoffish.com is as ugly as the website itself, but it does not detract from its success and utility.

I think the key to my preception of code beauty is related to “hamon”: a concept in Japanese swordmaking. If you’ll look at a Japanese sword, you’ll usually see a wavy pattern near the edge of the blade. Hamon literally means “blade pattern”. It is created when a swordsmith applies special mud to the edge of a in a wavy pattern of varying thickness and composition, and then heats the sword and plunges it into hot water. You can see the process in this video (it starts at about 1:30 mark).

The primary purpose of this treatment is to create a blade that is very hard and can take a lot of stress, which is a contradiction, as hard steel is very brittle. The edge gets the thinnest coating, and after heating and cooling turns into martensite hard crystals of high carbon steel. The thicker coated back turns into pearlite, which is a softer, but very flexible lower carbon steel. The hamon pattern is formed where these two types of steel interlock. The wavy shape makes the sword able to absorb shock better.

The absence of or inferior shape of hamon clearly indicates the inferiority of the sword. The aesthetics of it are just a coincidence, but it is also the resason why the craft of the samurai sword endures: collectors and museums purchase them as works of art. I’ve seen many swords in museums, and even though you can’t appreciate them as well as by holding them, the patterns in the hamon are hypnotic.

Here’s a good video of what hamon looks like in different ligting conditions.

There are many different styles of hamon, here are some examples from very excellent “The Craft of the Japanese Sword“:

There are of course many swords out there with fake blade patterns made with acid etch, wire brushing or other abrasives. Fakes are neither beautiful nor strong and easily identifiable.

When I look at a code listing I also see a wavy pattern. It’s nowhere near as connected to quality as the hamon, but it is still often an indicator of it. Indentation, spacing, length of keywords and function names, the amount of syntactic sugar, overall length of the listing: good code is sometimes beatiful to look at.

Sublime Text 2, a new programming editor that I am using, has an interesting feature: an insert that shows the whole file in miniature. Here are side by side beginnings of commit.c from (top to bottom) cvs, svn and git. I don’t know if anything can be determined by looking at these pretty skyscrapers of code, but aestetically I like git better.

This goes a level further – into software architecture. There’s this old chestnut of the maps of system calls in Apache and IIS web servers. You can easily tell which is the product of Redmond craftsmanship.

I would like to add that wavy patterns are the last things that I look for in code and this whole article is just a fluffy philosophical musing. Yet, maybe there’s something there in those patterns.

The Mystery of Obidos

Whoa, caught amazon.com while it was down.
They are showing a page with Rufus, the Amazon dog.

By the way, I was meaning to write about that for some time now. Did you ever notice enigmatic word “obidos” in Amazon url?

Some theories from usenet:

  • Castle near Lisbon
  • OBI (Wan Kenobi) + DOS (Disk Operating System)
  • ‘OBI’ = Object Broker Interface

    This seems to be the correct answer though: Obidos is is a major port on the Amazon river.

    [update]
    Livejournal user hallerlake had this to add:

    “I worked at Amazon for a couple of years, and can mostly answer that.

    Obidos is the area where the Amazon is “concentrated” – it narrows to a point about a mile wide and a couple hundred feet deep. It’s the chokepoint of the Amazon. A wry sense of humor turned that to the naming scheme.

    The Amazon Marketplace (auctions+zshops+third party) code was called Varzea for similar reasons – it’s the delta point of the amazon river, where the river fans out.

    Amazon wrote their own web serving environment because the selection of scripting/webcontrol languages when they got started was so lousy. They had to call it something, so obidos it was. :) ”


    Obidos is huge, it might be over a gig by now. I don’t think it’s that bad, though. I haven’t been at Amazon for a few years. For a long time Amazon ran on the Netscape web server environment, then eventually moved to a specially tuned Apache. But yeah, the webservers had a lot of RAM in them so that we could fork a bunch of different processes… and a garbage collector got added to take care of some of the memory leaks. Even still we had a service that killed and restarted processes every hundred accesses or so. It wasn’t pretty.

    I don’t know who came up with the name… I’d bet on Shel Kaphan or possibly Joel Spiegel. Shel set the direction for the company’s software development and architecture, including standardization on C (instead of C++) due to easier debugging. Certainly for the first few years he was The Guy for software architecture; these days I would imagine Al Vermeulen has that task.