From: Brian Adkins Date: 2008-12-30T04:34:40+09:00 Subject: Re: Syntax error I don't understand Albert Schlef writes: > Dave Bass wrote: >> >> "When in doubt, use parentheses." This avoids having to learn >> complicated rules > > Matt Harrison wrote: >> >> It would be my guess ruby is trying to do "a << rand" and then finds >> an extra integer stuck on the end. > > No doubt. But could anybody describe this special case more accurately > so I recognize it in the future? It even happens for "2 + rand 3". I > don't want to add parentheses in all my function calls, because I > understand that's contrary to Ruby's coding style. I may use parentheses on function invocations more than most, but I don't think it's contrary to "Ruby's coding style". Invocations without parentheses can be nice for simpler statements and dsl-like usage, but I personally prefer parentheses for invocations that aren't of the "function [argument, ...]" form - such as the one you began the thread with. On a related note, using parentheses in expressions generally, as Dave Bass mentioned, is not a bad practice. When I was younger, I would pride myself in memorizing the operator precedence of various languages, and use the minimum parentheses necessary because I thought I was being "cool" or "smart". I now feel I was being neither, and it was of little benefit to others when reading my code. -- Brian Adkins http://www.lojic.com/