From: Josh Cheek Date: 2010-10-11T16:17:29+09:00 Subject: Re: Why does a lot of code not include parenthesis? --001485f64aa8052e26049252275d Content-Type: text/plain; charset=ISO-8859-1 On Sun, Oct 10, 2010 at 10:50 PM, Scott Gonyea wrote: > - Declaring a method: Always use parenthesis > Same, though there are some prominent people who disagree (Aaron Patterson). I feel lost without them, though. > I'm also a sticker on return statements. Ruby will return the last value > in a method. That said, if your method is not simple, I'm very big on > making sure everything is explicit. Also, I'm big on using parenthesis in a > return statement. > return(num1 ** num2) # ahhh > > Not even C or Java make you do that. On Sun, Oct 10, 2010 at 11:04 PM, egervari wrote: > In the case of the sqrt line, those parenthesis are not required, and > you're right - they are less readable. > > But take for example this line: > > y = 10.div 10.div 5 > > It gets ambiguous if div takes more than one argument y = 1.div 2.div 3 , 4 Does 4 go to 1.div or to 2.div? I would write them like this, though as was pointed out, TIMTOWTDI 1.div(2.div 3) # one arg 1.div 2.div(3) , 4 # two args to 1.div 1.div(2.div 3 , 4) # two args to 2.div > See, in Scala, you don't need the "." when you drop the parenthesis, > so dropping them both turns out to be much nicer and clearer: > > val y = 10 div (10 div 5) > > Seriously? But that looks messy. It's hard to tell what is the method, what is the variable, and how the code is formed at a glance. If 10 were stored in a variable, it would look like div was an argument, not a method. Yeah, I'm kidding. The point is you say those things about Ruby, because you are used to Scala. But coming from Ruby, you'd say those things about Scala. --001485f64aa8052e26049252275d--