Joe Van Dyk <joevandyk / gmail.com> writes:
> Generally people save do .. end for multiline stuff. Don't think
I am not sure why Pickaxe mentioned this convention that is based
on LOC factor rather than one that is based on intent.
Basing it on LOC is silly, IMO. It really is more suitable for
languages that are white-space sensitive.
Consider you wrote:
foo.bar {|a| zoo(a)}
Oh, further down the road you realise that it is valuable to log the
value of a or perhaps you are simply reformatting your code.
foo.bar {|a|
log.debug(a)
zoo(a)
}
Whoops, that's out of the convention. Your eyes are itchy at that, so
you spent some time fixing it like:
foo.bar do |a|
log.debug(a)
zoo(a)
end
Later on, you decided that logging the value of a is frivolous, so you
changed it again:
foo.bar do |a| zoo(a) end
That violates the convention as well, so you do yet another do-end to
{} transformation
foo.bar {|a| zoo(a)}
All that works is just for one method call. Imagine if there are more,
and there are likely to be more.
Basing it on intent (return value or side-effect or what-have-you)
seems a more rational guideline. For certain, that would make code
reformatting a more pleasurable exercise.
YS.