Cookie Notice

As far as I know, and as far as I remember, nothing in this page does anything with Cookies.
Showing posts with label beautiful code. Show all posts
Showing posts with label beautiful code. Show all posts

2008/12/30

Contemplating Beautiful Code...


Honestly, I thought I had written this a year ago.

I received a review copy of the O'Reilly book Beautiful Code over a year ago, and I was hopeful from the time I heard about it. For any technical subject I knew, the go-to book was always the O'Reilly. I learned C++ from O'Reilly. I learned lex and yacc from O'Reilly. I learned Perl from a book with a Camel on the front. Later, when Linux and Open Source started to get a foothold in the mainstream computer world, O'Reilly published an excellent oral history with Open Sources. When I saw O'Reilly and Beautiful Code together, I thought it would be an excellent resource.

And then I started to read.

I just couldn't finish.

There are many words in the jargon file that can lean toward implying beauty. Elegant, for example, or clean. "Clever" is used but has no entry. Many more describing variations on ugly, but this is understandable. "Readable" isn't in the Jargon File but is a common complaint against Perl, my language of choice.

Absence of complication leads to elegance, but is elegance beauty? Is cleverness beauty? If code is readable, is makes it easier to understand, easy to change, but does that mean beauty? The Keats test, "Beauty is truth, truth beauty,—that is all Ye know on earth, and all ye need to know", seems insufficient. And nothing I read made a utilitarian or functional argument for the benefit of beauty in a code base.

I was disappointed in O'Reilly for this. They're still my go-to supplier for technical books. As I write this, I'm waiting with bated breath for Amazon to deliver The Productive Programmer. It should arrive today. Productivity, that's something measurable, something I understand the value of. I hope it's more ueseful than Beautiful Code.

2007/10/30

Reading Beautiful Code, Chapter Two ...

I was reminded of this by reading an article on keeping all your important files aligned with Subversion. Chapter two is on Subversion's Delta Editor. Delta means change, and Delta (&916;) is math for change.

I cannot claim that the beauty of this interface was immediately obvious to me. My quick read of the interface sees tight but well-commented code. I'm hesitant to dive further in, as I'm already lots of review behind. The part that I think is most worthy of comment, right now, is that it's an interface. This differs from previous standards for code beauty (the author lists Duff's Device and rsync's checksum as examples) because it's not an algorithm, and because it's longer than what would fit on the back of an envelope. Five pages in the book, mostly comments. But the beauty of Perl that I see every day is that I can abstract, for example, the process of downloading a web page from a series of network pokes to something close to get($url) ;. If the foundations are solid, you can build on them. But nobody normally looks and says "My, what a great foundation."

2007/10/25

Reading Beautiful Code, Chapter One ...

This is Brian Kernighan's chapter, on Regular Expressions. This amuses me, because Regular Expressions are widely considered to be an ugly thing. More than just ugly, too. "Some people, when confronted with a problem, think 'I know, I'll use regular expressions.'" wrote Jamie Zawinski. "Now they have two problems." I'm not there. I can read Perl-style regular expressions,

(I'll drop into an aside here and complain. Why is it that Perl has begun to complain when I write something like this:
my $foo = '' ;
print "XXX" if $foo =~ m{xxx}mx ;

????
Seriously, if a string has nothing, it clearly will not have the string xxx in it. '' should no more pop up an error than 'aaa' should.)

This chapter focuses on an implementation of a regular expression engine written by Rob Pike for the book The Practice of Programming. Chosen because it's a clear usage of recursion that isn't Quicksort or walking a tree. If I was Norm MacDonald, I'd note that programmers love recursion like Germans love David Hasselhoff. I suppose I might anyway.

But it's clear that Kernighan is fairly uncomfortable with the concept of beauty as applicable to computer science. He says "elegant" and "novel" and "compact". Those are three common metrics for beauty, but then, the standard of beauty would be Ingrid Bergman. She's beautiful, true, but hardly the only standard.