« Test-Driven Rails Studio | Main | Our take on presenting code »

May 14, 2008

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d83451c41c69e200e5523e8c408834

Listed below are links to weblogs that reference Silly Useful shoulda trick:

Comments

Ted

That looks to me like a "clever" trick that's due to bite you in the butt in the long run, especially if you have more than one programmer working one the code over a long period of time. I did a little Google on clever programing and came up with these gems:

Everyone knows that debugging is twice as hard as writing a program in the first place. So if you are as clever as you can be when you write it, how will you ever debug it? -Kernighan

The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague. -Dijkstra

Writing intention-revealing code is much more important than being clever. -Anonymous

Source: http://www.cse.iitb.ac.in/~kart/Quotes%20-%20Dev.html

Dave Thomas

Ted:

I'd be interested to know exactly what you feel makes this code hard to maintain, or “clever.” My personal believe is that it reads better than the alternatives.


Dave

Bruce Williams

Would be interested to hear why this is bad, "clever" usage. It's a simple, clear example of a closure; nothing scary, overly fancy, or hard to maintain/explain about it. It also looks like a pretty useful little approach.

If a person knows what a closure is, this should make immediate sense; if they don't know what a closure is, they should.

Tammer Saleh

We use this technique liberally when developing custom shoulda macros. I'm not sure how to post code snippets, but if you look at the lib/shoulda/active_record.rb file, you'll find plenty of examples.

And I can understand how some people may find that technique to be tricky, but I'd encourage them to learn more about and make more use of ruby blocks. It's really an aspect of the language that sets it apart.

Cheers,
Tammer

The comments to this entry are closed.

Now in Beta

  • Programming Ruby, 3rd Edition
    Third Edition, Covering Ruby 1.9, now available
My Photo

Pragmatic Stuff

Photos

  • www.flickr.com
    This is a Flickr badge showing public photos from pragdave tagged with pragdave_badge. Make your own badge here.