development

Don't be over-clever in code

June 12, 2007 23:21:33.523

Urban Honking goes to great pains to explain why using syntax tricks in Ruby to get to something like this:

Hpricot(my_document)

Is a good thing. Here's a question - if you stumbled on that in code, would you have any idea what it did? That's why I left this comment over there:

In Smalltalk, methods can begin with capital letters; it's just not usually done. However, all messages do need a receiver, so in Smalltalk you would have to write something like:

Parser Hpricot: someXhtml.

Seeing as the method named Hpricot is badly named - it doesn't say anything about what the method does - I'd instead write something like:

Parser parseXhtml: someXhtml.

which is way, way more obvious for the poor follow on developer who has to read the code.

Which leaves me wondering why you think using clever syntax that obscures meaning is a good thing? I prefer to leave that the C programmers, myself...

I've out-clevered myself in Smalltalk many times; it's never a good idea.

Technorati Tags: ,

 Share Tweet This
-->