A Wheel With Corners
Posted: Sat, 26 January 2008 | permalink | No comments
How often have you said to yourself "this programming language's if statement is too flexible, I need to make it more rigid, and with a syntax nobody else understands"?
If you've ever said that to yourself, then take a look at this Rails plugin. From the brief description of the plugin:
Allows developers to execute or not execute given code block depending on a set of conditions, written in intuitive manner. Especially useful within view templates, where it can eliminate the need for multiple if ... else ... statements.
That screams "overkill" to me, but for the sake of my morbid curiousity (and on the very, very off chance that it's something not entirely ridiculous) I took a look at the detailed documentation. At least there is detailed documentation for this plugin.
I didn't get any further than the first example, though. Take a look at this monster:
How often do you find yourself writing something like that in your views:
<% if current_user != :false && (current_user.administrator? || current_user == @profile.user) %> <%= button_to('Big Red Button', destroy_everything_path) %> <% else %> <%= button_to('Hands off!!!', access_denied_path) %> <% end %>It works, but, you know, it's not what you would call beautiful, is it?
What about something like that:
<% access.to_administrator.or_user_of(@profile) do %> <%= button_to('Big Red Button', destroy_everything_path) %> <% end.else do %> <%= button_to('Hands off!!!', access_denied_path) %> <% end %>At least conditions are looking much better, aren't they?
Hopefully, most people out there answered a resounding "no" to that last question. A plugin which causes you to write just as many lines and very nearly as many characters, whilst using a completely different minilanguage to what every Ruby programmer already knows, does not sound "much better" to me. Ruby people tend to love little minilanguages to get things done, but this... I just don't have the words to properly describe it.
I'm going to start a list of "poison plugins" -- ones that, if I see any of them in or around the code of a Rails project I'm looking at working on, immediately doubles the hourly rate and the time estimates. Stupidity is toxic, and working with hazardous substances is always more expensive. Other current candidates include the old-world auth generator I gutted while I was at Vquence, and annotate_models -- the former because it's shocking code, and the latter because anyone who uses it has some seriously scary ideas about what constitutes acceptable documentation and development practices.
Post a comment
All comments are held for moderation; markdown formatting accepted.