Wednesday, August 02, 2006

» To "do" or to "squiggle" +

Well, I've been waivering lately between using do...end and {...} for blocks. I like the way do...end looks, and the end flows nicely with all the other ends. But on the other hand, a block is a bundle of code that is contextually and syntactically distinct from the code around it on the interpreted level. So should it also be distinct on the implementation level also? Obviously do...end is a different implementation from, say, if...end, but that is not easy to see at a glance (you have to follow the block back to the initial keyword to see if it is a "do" or an "if" or whatever).

I know the (general) convention in the Ruby community is to use {...} for one-liners and do...end for multi-liners; but I think I'm going to start using {...} for all blocks.

And speaking of syntaxis and such, you'll notice that I use parentheses when calling methods which take arguments, when defining methods and for conditional clauses. I realize that this is not necessary, and is more akin to the evil C-family of languages that to the Smalltalk/Lisp side of the gene-pool. But it helps me to code better, and I can read more easily. Mabye that's because I come from a PHP/JavaScript background. Whatever the case, if you don't like it, get over it--Ruby is all about having the freedom to code as efficiently as you are able, and for me that means parentheses.

module I
def so(bool, &block); end
def you_dont_like_it?(); true end
def I.could(blah); end
def care(); false end
end
class FalseClass
def less!(); end
end
include(I)

Hehe...

so(you_dont_like_it?) { I.could(care.less!) }

;P

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home