Symbol#to_proc: hack or syntactical sugar?
jd / Tue, 29 Aug 2006 03:18:00 GMT
This article has moved over to our sister spin-off blog, RubyJudo, which focuses on more arcane technical topics than NotRocketSurgery.
jd / Tue, 29 Aug 2006 03:18:00 GMT
This article has moved over to our sister spin-off blog, RubyJudo, which focuses on more arcane technical topics than NotRocketSurgery.
Hi JD,
I’m so glad to see you post this. I was wondering if I was the only one who thought this was a bit of an ugly hack.
Something makes me definitely uneasy about it, in ways that other Ruby syntactical sugar doesn’t.
I could see it being useful, but it just doesn’t seem “conceptually appropriate.” Given how much attention has been paid to readability in Ruby and Rails, I wonder what the point of making this one aberrant hack was.
Hi jd,
I kinda agree with you that it shouldn’t be in Rails. It was cool hackery when first introduced but at what cost to understanding the code?
Bob
Why couldn’t they implement something like the following instead?
StupidUsers.each.destroy
It would be harder to do, but it would make much more sense, semantically than:
StupidUsers.each(&:destroy)
There’s probably some technical hurdle I’m not seeing here, but couldn’t one just rewrite each to proxy whatever method you’re sending it over to every object in the collection?
It definitely would follow Matz’s putative principle of least surprise.