News for hackers. Stuff that matters.
Re:I don’t like the Ruby 1.9 hash syntax by tptacek on Tuesday December 13, 2011 @11:38PM (#3350622)
I felt the same way, until I wrote my first program that used DSL-style. The parens-optional syntax thing is immensely useful in DSLs; it has saved me from writing tens of parsers.

I'll add the ()'s to intra-class method calls, though; the ambiguity between variable references and funcall expressions bothers the hell out of me, too.

Optional parens are a net win.

Re:I don’t like the Ruby 1.9 hash syntax by ericwaller on Wednesday December 14, 2011 @12:29AM (#3350761)
I think that ambiguity is important to the feel of ruby code. It encourages you to think about expressions in terms of their semantic meaning rather than their imperative effect^. I think python's @property decorator is a testament to the "nice"-ness of said ambiguity.

^ I realize this can also be dangerous and is the same reason '!' is encouraged as an annotation for methods which have significant side effects.

Re:I don’t like the Ruby 1.9 hash syntax by euroclydon on Wednesday December 14, 2011 @06:13AM (#3351420)
I've suspected Ruby's optional parentheses helped with some parsing or code generation activities, but after your comment I still can't find enough specific examples or general theory. Is there a stated design objective for this in Ruby or can you point me to a good article on optional parents and DSLs?

By the way, I'm pouring over the source for Nancy, a Sinatra inspired micro framework in C# and I see where extension methods and implicit conversion operators are helpful in a DSL.

Re:I don’t like the Ruby 1.9 hash syntax by chc on Wednesday December 14, 2011 @07:50PM (#3354506)
It's part of the language's overriding design philosophy of pervasive OO. As much of the language as possible is implemented in terms of objects and methods, including seemingly syntactic things like "private", "attr_accessor", the top-level scope and all member access to other objects. It's all objects and methods under the hood, but you shouldn't have to think about it in those terms. You're not supposed to be concerned with how the accessor for an object's name is implemented — you're just supposed to feel like you're accessing it.

Other languages have been moving in this direction, too. Objective-C has dot notation, C# lets you define getters and setters, Python has the @property decorator, Scala has special "magic" methods and quirky syntax rules to make this work, etc. All of these serve the same purpose as Ruby's optional parentheses: To make simple method calls less inherently "heavy".

Re:I don’t like the Ruby 1.9 hash syntax by tptacek on Wednesday December 14, 2011 @09:19PM (#3354761)
His specific question has a more prosaic answer, I think; optional parens make DSLs easier by making Ruby's syntax more flexible, thus allowing it to stand in for more languages.

For instance, a few years ago, a summer internship project was to build a native debugger for OS X in pure Ruby, and to help with that, I wrote a chunk of X86 assembly as a Ruby DSL:

http://news.ycombinator.com/item?id=284238

Re:I don’t like the Ruby 1.9 hash syntax by chc on Wednesday December 14, 2011 @10:14PM (#3354884)
I don't think so, at least not so directly. IIRC, this idea of "DSLs" in Ruby didn't gain currency until relatively late in the language's history, a little while after Rails made it explode and Why wrote his Poignant Guide featuring Dwemthy's Array. But Ruby had basically the same syntax long before that.

I think the real answer is what I said: It makes Ruby's syntax lighter and more flexible so the pony could get more mileage out of its one trick (pure OO), and the convenience of writing DSLs just falls out of that.

BTW, that DSL is an awesome hack.