On Sunday, October 10, 2010 07:25:15 pm egervari wrote:
I just started playing around with ruby and rails, and one thing I’ve
noticed is that the style of the code is a little odd. People don’t
use parenthesis most or even all of the time.
I find this to look messy.
I find redundant crap looks messy. Without parentheses, it can often
English, and it’s very easy to build remarkable DSLs.
It’s hard to tell what is the method, what
is the variable, and how the code is formed at a glance.
I don’t agree, but maybe I’ve been looking at it for too long. Maybe it
takes practice. However, I think it’s much more important whether I can
what a piece of code is trying to do – it may be slightly more
I can always figure out how it works.
Is there any reason tastes in style have changed? I think it would be
best to stick with the parenthesis just to make everything consistent.
I am consistent. I don’t use parentheses unless I have to. This is true
in languages where parentheses are required for method calls. Consider:
distance = Math.sqrt(xx + yy)
Yes, I had to write parens around the body of the square root to make it
unambiguous. Were this Java, I would also be required to because
a method call. But I didn’t do this, though I could have:
distance = (Math.sqrt((xx) + (yy)))
I don’t know about you, but I find that a lot less readable.
I’m also consistent with the majority of the Ruby community, so about
adding parens would help with is being consistent with other programming
languages – but I think we should celebrate Ruby’s strengths, not try
bring it down to the lowest common denominator.
I’m also consistent with how you run commands. After all, you don’t do
‘gem’ ‘install’ ‘rails’
…do you? Single-quotes would be unambiguous, and it would make your
more consistent with the times when you actually need them to escape
characters, like spaces:
rm ‘My Essay.odt’
But even though it’s only a few extra keystrokes, I think most of us
find the extra noise to be less readable, not more. Quoting, in this
is a tool to remove ambiguity, nothing more – and I would argue parens
the same purpose in most languages, and should not be required when the
meaning is unambiguous.
Same with semicolons. You can put them at every line, but Ruby is smart
to figure out what you mean most of the time, so instead, you only need
semicolons (or a backslash at the end of a line) as an exception to the
as a tool to remove ambiguity.
It should be easier to refactor code and inline things if the
parenthesis were already there after all.