From: "Aleksi Niemelä" Date: 2001-02-26T07:37:52+09:00 Subject: [ruby-talk:11554] Re: Parentheses around method arguments On Sat, 24 Feb 2001, Robert Gustavsson wrote: Hi Rob, > if( (true == fExpression) && (true == fInHeader) ) > One note I'd like to give is that I read the topmost better as if fExpression and fInHeader and in Ruby everything is true except nil and false, so there's no need to show it explicitly. In C it might be helpful to note if you might get an integer back or if it's a boolean you're expecting. In Ruby you _have_ to write an integer comparison like if fExpression == 1 otherwise code like fExpression = 0 puts "surprise" if fExpression will surprise. But even bigger point is that most of the time you find yourself in need of explicit parentheses your code is screaming for simplification and self documentation. > if( (strOutput =~ /^\s*'/) and (0 == indentLevel) ) When I write code like this I feel I'm sure of precedence etc. If I'm unsure even a bit I know that I should be writing more like: strOutputIndented = /^\s*'/.match(strOutput) indented = indentLevel == 0 if strOutputIndented and indented (An overkill solution for this case but shows the idea.) This code is nicely waiting for simple refactoring of transforming the temporary boolean variables into method calls; and hopefully the method names carry the meaning. > Any thoughts, suggestions, experience (bad and/or good) on this issue would > be appreciated. Parentheses are not that often needed. When you have much of them you know the code would like to get written in multiple lines or maybe would like to document itself by using good method names. (Smaller methods are also easier to test. :) But as all the "rules" these are there just to be broken. Just do it consciously. - Aleksi