From: Jacob Fugal Date: 2005-12-10T06:14:21+09:00 Subject: Re: do/end vs braces On 12/9/05, Chad Perrin wrote: > ... It just seems to me that, > for consistency's sake, what you use as block delimiters shouldn't > affect whether parentheses for method parameters have to be flush with > the method name itself. 1) Choice of block delimiters has no more influence on whether parentheses for method parameters have to be flush with the method name itself than choosing 'and' vs. '&&' does... and that is none. In my ruby (1.8.2, 2005-04-11, i386-linux) I don't even get the warning about not putting spaces in. As far as I can tell, putting a space between the method and the open parenthesis is equivalent to not parenthesizing your argument list; the parentheses that had been an argument list marker are now only a precedence operation. On that assumption, the warning is either newer or older, and only serves to chastise (ie. *warn*) those that are making the mistake of thinking their parens are marking the parameter list when they really aren't. 2) With regards to implicit method parameters, the effect of choosing do/end over braces is no different than the choice of 'and' over '&&' -- or 'or' over '||'. Example: puts(false) or true # explicit, or => prints false, returns true puts(false) || true # explicit, || => prints false, returns true puts false or true # implicit, or => prints false, returns true puts false || true # implicit, || => prints true, returns nil Both explicit method calls know their arguments exactly. The implicit method calls, however, get different argument lists depending on the *precedence*. The || operator binds higher than the implicit method call, but the 'or' operator does not. Similarly, the {} block syntax binds higher than the implicit method call. The 'do ... end' block syntax does not: def foo block_given? end def bar( arg ) puts arg block_given? end bar(foo) do ; end # explicit, do/end => prints false, returns true bar(foo) { ; } # explicit, braces => prints false, returns true bar foo do ; end # implicit, do/end => prints false, returns true bar foo { ; } # implicit, braces => prints true, returns false That's it. That's the difference between do/end and braces. Period. Any other difference is only convention and personal preference. Jacob Fugal