lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Since this is probably a matter of opinion, let me add one:

Always add parentheses, except for +, -, * and ^, since these are the only ones everybody is supposed to learn in school.

Even / can lead to confusion:  a*b/c*d
- Usually read by programmers as (((a*b)/c)/d)
- Sometimes read by mathematicians as ((a*b)/(c*d)), with / as fraction line

Once you know multiple programming languages with different paradigms, it becomes pointless knowing all precedence rules.
Sometimes you copy some code from one language to another (e.g., prototype with Lua but finally copy some mathematical algorithms to C for performance reasons).

repeat
until (l > (a + b*c));

No bracket required, but readable in one second.
Also properly placed spaces significantly improve readability.



On Thu, Jan 7, 2021 at 2:15 PM frank@kastenholz.org <frank@kastenholz.org> wrote:

Parentheses are free
In any programming language, as well as plain text documentation, I almost always use parentheses to indicate the exact order of things.

As a corollary, if the parens would end up making the _expression_ unwieldy or too complex then I take that as an indication that the original _expression_ is too complex and I try to rewrite it.

Frank