sexta-feira, outubro 31, 2014

Code Belters from Hell: "Geek Sublime: Writing Fiction, Coding Software" by Vikram Chandra

Geek Sublime: Writing Fiction, Coding Software - Vikram Chandra

(my 3-volume-battered-copy of Donald E. Knuth's bible)

A long time ago when I was doing Software Engineering professionally (I was a C/C++ black belt coder back in the good old days of obfuscated coding practices…) I always of very keen to put lots of style and readability into my code. Then I moved on because I wanted my code to be beautiful as well. It took me longer to write agreed, but it was more pleasing to the eye and the brain. From that time on I’ve always considered Software Engineering and programming in particular, to be a creative art, which for me necessarily involved aesthetics. Unfortunately some people considered aesthetics the enemy of the pragmatic, which was a view I’ve never been particularly fond of. I used to argue at the time that my sense of beauty served pragmatism much better, because it lead to more concise and maintainable code, and was thereby far more effective. I still believe this to this day, even though I haven’t created professional source code for a long time. Now I only do it at home and just for fun. And for that I use Python, which has been my programming framework of choice in recent years, because of its high readability (vide “The Zen of Python” by Tim Peters). It satisfies all my aesthetic views on this subject. I know it’s not an industrial language (eg, the versions for Android leave a lot to be desired), but from the aesthetic point of view it’s one of the most eye-catching programming languages I know, and I know a lot of them.

I still remember the thrill of having written my first Basic code back in the 80’s in my still working Spectrum. When I saw it, it opened my eyes and my life was changed forever.

10 PRINT "HELLO WORLD"
20 GOTO 10

I know, I know. You’re all laughing in the back row, but you must remember it was the harbinger of a profound change in the way I think to this day. It shaped who I’m today.

In (obfuscated) C++ code the above would look something like this:

Class Program
{
                    Public static void
                    Main()
                    {
                                         System.Console.WriteLine(“Hello World!”);
                    }
}

In python I’d simply write ‘print “Hello World”’ (without the outer quotes). How simple can it get?

I was never quite sure why many programmers seemed to think their main objective was only to write code that only made things work. For me the job was dual: solve a problem with code in the most elegant way, such that your solution is easy to adapt, modify and reuse. Just like “Lisbon is a beautiful city” is not literature, although it might perfectly describe my feelings about the city I live in and love, coding something that just works is not programming. It’s another thing altogether. There are several terms for that. I’ll just use the polite one. “Dabbling”.

If painting is an art, why shouldn’t coding be? If what I do in my living room painting-wise is not art, it doesn’t mean it can’t be art. It’s all in the hands of the artist, in this case me (painting is not for me…). If I were a painting artist, ie, If I were able to apply paint in an artful way, I’d be an artist (in this book there’s a very interesting comparison between “The Hacker” and “The Painter”, which rang true to my finely attuned ears…). Likewise Software Engineering/Programming is usually art in the right hands. Unfortunately most software on the market today seems to have been written by the “Code Belters from Hell”... And there's a market for that. Hence, Visual Basic and its “look-a-likes” (VBScript, Visual Basic .NET, etc).

If programming languages were to be considered formal dialects, albeit less flexible and less forgiving of ambiguity than natural languages, coders, like poets, should be able to manipulate linguistic structures, always searching for expressivity and clarity.

Even though a piece of code passes instructions to a computer, its real target are the coders who will add features and remove bugs after the first versions were created. Donald Knuth, one of the unsung heroes of Computer Science (one of my boyhood heroes when I was a coding as if there was no tomorrow), stated in my 3-volume-battered-copy (vide image above) that coders write code for other humans, not for machines, which is a common misconception in today’s new programming class of coders. It’s in this aspect that for me Coding closely resembles Art. It’s all in the eyes of the beholder, and not in the “eyes” of the machine. It’s what you can picture inside your brain that can be called art, not what’s on the outside. We call it art, because we are able to picture it as art, be it an astonishingly beautiful piece of code, be it a Van Gogh. It doesn’t matter what kind of object we’re looking at. “Art” is inside us.

A programmer may imagine that to get the job done is what code is supposed to do. One may be forced to believe that code is, at the end of the day, a series of commands issued to a machine. What more could you want it to do? Knuth has already answered it a long time ago: “Code must be absolutely beautiful” (my italics). It’s still one of my favourite quotes Computer-Science-Wise.

As a side note, Chandra’s perambulations through Indian literature (eg, Sanskrit) was an added bonus for me. I knew next to nothing about this. Now I know a little bit more. On top of that, the connection he makes between the ancient Indian poets of long ago and the way we should look at art it’s quite entrancing and convincing.

It was a real pleasure reading this book. It introduced something new to me and it did so in a very “geek-like” way. I got the impression it was written by a geek for geeks, but maybe I’m reading too much into it, being a geek myself. Yes, I confess: I was once an “Einstein” (as opposed to being a ”Mort” or an “Elvis” programmer), using Microsoft’s terminology for programmers lol. Unfortunately (or not), I'm no longer that...

NB: See my Adam Greenfield's book review for an extensive list of seminal works in terms of Computer Science (my opinion).

Sem comentários: