Friday, July 16, 2010

The Lazy Programmer

In a comment on my The thing I hate about HTML post, a reader writes:

For me, this boils down to the fact that you're lazy.

He was objecting to me not wanting to write HTML end tags. If you ignore the tone, that might be read as snotty or offensive, then I think there's an important lesson.

Yes, I am a lazy programmer.

I am lazy in the sense that I don't want to spend my time doing hard, tedious work that a computer can do for me. In the HTML example a computer is ideally suited to figuring out which tag I was thinking of closing. And it can tell me when I've missed something. And it will go horribly wrong if I don't get the nesting right.

Here's the thing: getting the nesting right is the thing I need to do. That's what I need to be using my brain for, not for something the computer can do. And if you give me the 'freedom' to mess up the tag closing then you create the mess we have today in HTML: all sorts of documents that require someone else to spend enormous effort to write a parser to cope with my mess. Giving me the luxury of being lazy about not correctly balancing the tags, means someone else has to undertake the Herculean task of being compatible with all the web pages out there.

It's also a bit like garbage collection. Do I want to remember to call free() for every malloc()? Not really, I just want to get memory and use it and discard it when I'm done. And sometimes I want to use C and get into the guts of memory management for speed: that's when I've swapped laziness for hard work because I need to do that hard work.

And there's another sort of lazy that I want to be: lazily evaluated. Don't compute things until you need them, and don't make me figure out when they are going to be needed.

There's great freedom in laziness.

8 comments:

r_blair said...

And sir, a Lazy programmer is a great programmer. That same guy is the type guy who likely has no problem repeating code, or tasks, which to people like you and I seems absolutely redundant. The less time we spend playing with things like html end tags, the more time we can spend planning, and making truly beautiful code.

pixelbath said...

Probably the most telling thing about the person who wrote that comment is that they wrote an article on PHP's "variable variables" and using them to save programmer effort.

But it's not lazy when you save keystrokes in PHP, for some reason.

pixelbath said...

Probably the most telling thing about the person who wrote that comment is that they wrote an article on PHP's "variable variables" and using them to save programmer effort.

But it's not lazy when you save keystrokes in PHP, for some reason.

RBerenguel said...

Indeed, laziness is a great programmer treat. Finishing things off quickly is what makes for a great programmer. As I wrote in a post about reinventing the wheel (maybe you catched it in Reddit or HackerNews), I read about the 3 programmer sins: laziness, impatience and hubris (a greek term, meaning arrogance, even defying the gods). And is what makes for a great programmer: finish things quickly, doesn't want to wait and is arrogant enough to maintain big projects, or create new.

Ruben

Brian Button said...

Have you seen this post and its links before? Your idea is good, but not new :)

http://www.peterprovost.org/blog/post/The-Lazy-Programmer.aspx

D. W. said...

But HTML is designed to be human-readable. Closing tags help with that, especially when the HTML is not neatly indented or is buggy (as is frequently the case for machine-generated HTML). Think of it as being forced to write standard comments. Having the tag name in the closing tags really helps to indicate the author's intent when the document is not well formed. If the extra work bothers you that much, use an editor that automatically inserts paired tags.

Manni said...

I cannot, for the life of me, figure out how anyone in this day and age can defend the horrible, horrible mess that we call HTML. It is hard to read, it is hard to parse and when you look at the web, it is obviously impossible to write. Unfortunately, it seems that we'll never get rid of it.

sarmenb said...

Manni, i agree I hate html, css, anythign frontend. But there are ways aroudn it create a php class or whatever server side langauge you use and make one that generates it for you. problem solved.