From: Juan Zanos Date: 2009-02-18T03:13:21+09:00 Subject: Re: What are your favorite Ruby features? On 17 févr. 09, at 11:59, Rick DeNatale wrote: > On Tue, Feb 17, 2009 at 9:44 AM, Juan Zanos > wrote: > >> >> On 17 févr. 09, at 01:16, David Masover wrote: >> >>> I like Ruby's relaxed syntax. I like letting things like >>> parentheses be >>> implied, leading to interesting, emergent phenomena like hashes >>> as named >>> arguments. (Not that I would complain if the language implemented >>> named >>> arguments -- even better if I don't have to use them as a hash -- >>> so long as >>> I can if I need to.) >>> >>> I like the ability to create good-looking DSLs, but that's >>> similar to the >>> above. >>> >> >> It's possible that without the humble feature of optional >> parentheses Rake >> would never have been invented and I might never have been >> compelled to take >> a serious look at Ruby. Since then I've often wondered why >> parentheses are >> still so heavily used in most Ruby code even when they offer no >> compelling >> utility for most uses. In contrast, omitting unnecessary >> semicolons seems >> almost universal. I suppose parentheses are more habit forming >> for some >> reason. > > > IMHO, coding Ruby without parentheses is a particular kind of spice. > Whether you should use a particular spice depends on what you are > cooking. > > The parentheses free style works well for certain internal DSLs > like Rake or > ActiveRecord association declarations, since they make run-time > executed > expressions feel declarative. > > On the other hand, I've always found leaving out parentheses in > Ruby code, > "just because you can" to tend to look far stranger to my eye than > putting > them in. In fact, sometimes when reading code without them I find > myself > having to read very slowly in order to figure out just how Ruby is > parsing > what I'm reading. It seems to me as if the coding style and the language feature are at odds with regard to Ruby and optional parenthesis. And I wonder if this is a consideration in making a new language, choosing features, and determining coding style. Should you add features that you plane to avoid using in common practice? I don't know if DSLs were a consideration when deciding to have optional parenthesis. If they weren't, then maybe the utility of Ruby for DSLs required a bit more luck than otherwise. Parenthesis seem so often used at times that it's almost if the option doesn't exist. Strangeness is somewhat arbitrary. That's why a brought up the use of semicolons. Many languages require them all over the place. Ruby makes them optional. Yet Ruby style conventions universally omit them when they're superfluous. So it isn't strange to not use them even though many common languages do. And of course some language don't use parentheses nearly as much as is commonly practiced in Ruby and it isn't strange in those languages.