From: Jamis Buck Date: 2005-06-02T06:51:52+09:00 Subject: Re: ternary operator confusion On Jun 1, 2005, at 3:47 PM, Austin Ziegler wrote: > On 6/1/05, Eric Mahurin wrote: > >> --- "Marcel Molina Jr." wrote: >> >>> On Thu, Jun 02, 2005 at 01:40:23AM +0900, Phrogz wrote: >>> >>>> true ? a.push(1) : a.push(2) >>>> >>> i suspect this could have been just a contrived example but you >>> could also do: >>> >>> a.push true ? 1 : 2 >>> >> I wish Ruby didn't make the () optional when passing args >> (probably from Perl which wanted to be like shells/tcl/lisp where >> command/function and arguments are space separated). >> >> When you don't put the () in, the precendence can get confusing >> and you arbitrarily prevent the first arg to start with a "(" >> (otherwise it will treat that "(" as what starts the argument >> list). >> >> Why do people feel the need to drop the ()? I didn't like it in >> Perl and I don't like it in Ruby. Do people just want something >> that is kind of like shell syntax? >> > > I use it in PDF::Writer because it makes certain parts feel more > like a DSL (domain specific language) than a program. And that is _precisely_ why I like the technique as well. It is wonderful for making a Ruby program read (more or less) like a domain document. And when ambiguity raises its ugly head, I can always throw in the parens to disambiguate. But as someone else pointed out, if you don't like it, no one is forcing you to drop the parens in your own programs. Choose the technique that works best for you. - Jamis