Hari Krishna Dara wrote:
[...]
I know that this is possible, but as I said previously, it is a force of
habit to compact as much as possible in some situations, though I
normally prefer using whitespace and parenthesis to improve clarity.
Also, the reason I mentioned using spaces is not really as a workaround
but to show the subtle difference it makes to the parser. Once you use
parenthesis, there is nothing really ambiguous about it.
I have a suspcion that using parenthesis also didn't solve the issue in
one of the cases (I remember it was calling script-local functions as
part of map() expression). I have to try to reproduce it though, I don't
remember it now.
As Tim said, a liitle bit of paranoia is healthy here: If you write
if condition_1 || condition_2 && condition_3
the parser will interpret it in a well-defined way, determined by the
syntax of the language, but when you come back 2 years hence, will it
still be clear to you? Some languages mandate left-to-right order in
this case, which results in the equivalent of
if (condition_1 || condition_2) && condition_3
In others, "and" takes precedence over "or", which results in
if condition_1 || (condition_2 && condition_3)
With parentheses, precedence rules are unimportant and an error in logic
won't be overlooked even if you mistook a left-to-right language for an
and-before-or language or vice-versa. similarly for all other possible
ambiguities: remember, (x?a:1) is a valid expression if you have a
variable named a. You may even have an argument named a:a so what about
(x?a:a:a) if you have both a and a:a ? I repeat: don't trust priorities
and use parentheses. And if you caught a bad habit, reeducate yourself.
Best regards,
Tony.