From: Brian Wisti Date: 2004-08-19T04:52:35+09:00 Subject: Re: When to use parentheses around method args? The sad truth is that my own rule of thumb is vague: "Use parens in a method call when it feels right." The pattern that eventually emerges is that I *don't* use parens when I want the method call to look like a field access. fruit_salad << tomato.to_fruit real_savings -= debt.in_dollars puts great_ideas.as_haiku But I *do* use parens when I want it to be very obvious that I'm making a method call. So if my method is using an argument or has a lot of side effects, I'll probably use parens. Maybe. In my own libraries, I tend to suffix the method name with "!" if it is going to have a lot of non-obvious side effects, which may make parens feel redundant. physician.heal(me) physician.heal_thyself! But sometimes I'll throw the whole thing out the window because I think it makes my code easier to read. Maybe *that's* my rule of thumb: "Use parens whenever it makes it easier for me to read my own code." Just thought I'd throw my own stray thoughts into the mix :-) Kind Regards, Brian Wisti http://coolnamehere.com/ --- Joel VanderWerf wrote: > Richard Dale wrote: > > Are there any rules of thumb for when it's a good > idea to leave out the > > brackets and when to use them? > > One rule that has been put forth is: > > "Use parens in a method call if you are making use > of the return value." > > So, even though every expression in ruby does return > a value, in those > cases where you are not interested in it, omit > parens if you feel like it. > > One case where I almost always omit parens is: > > iterator_with_args arg1, arg2 do > ... > end > > (You have to use parens if you use the {...} form > instead of do...end.) > > __________________________________ Do you Yahoo!? New and Improved Yahoo! Mail - Send 10MB messages! http://promotions.yahoo.com/new_mail