by rob_rasmussen · 18y ago · 0 comments
merb is one of the best-written Ruby libraries I've seen, in large part because they're focused on avoiding clever code.
Instead, I note that neither of these things are part of the standard library today. Which means, you must open the Object or Symbol classes to implement them. Nothing wrong with that in your code, but when you do so in a framework like merb (or Rails!), everyone using your framework gets your little patches in their namespace as well.
My feeling is that with the way Ruby's global class namespace works today, opening a core class has much more serious consequences when you are writing a framework, gem, or plug-in then when you are writing code that does not have "downstream clients."
So the real-world experience for Smalltalk is that the former is mostly FUD. The latter is a real issue. I suspect that this pretty much applies to the other dynamic languages as well.
I also completely and totally disagree that they're not clever. There is nothing _not_ clever about #returning. It is second only to using inject because you're too lazy to assign to a variable first. Nevermind that every railz0r that does that ignores the fact that they've now assigned N times instead of once.
Clever code, in my mind, is a form of hidden cost. It seems to be what I get paid to deal with (read: remove) the most.
def squidget(options = {})
squid = { :foo => :bar, ... }.merge(options)
...
squid[:bash] = :blitz
end
The method was returning :blitz instead of the hash that the method was constructing. I changed it to a returning statement and to my eye it looks much more clear what is going on.Of course, you could add a "return squid" at the end, or just plain "squid," but somehow that seems less clear, since when you start manufacturing the squid, it isn't obvious what you are doing until you reach the end of the method. Witha returning statement, you know right away.
All in all, I feel good about all constructions in Ruby that use blocks to wrap around the stuff they are doing, like
Foo.transaction do
...
end
But you're younger than I am, so your brain is probably sharper. Maybe you find it easier to just work directly with imperitive-style code. Many people I know prefer it that way. I know I like to simulate Scheme as much as possible, and use expressions instead of assigning local variables as much as possible. It could be laziness on my part.Besides, I'm not that much younger than you. :P
I think it is mostly that you went the lispy route while I took the smalltalk route.
ETA:
actually... I'll go one step further...
`returning` violates "Do the Simplest Thing That Could Possibly Work" flat out without giving you anything in return.