[COFF] Formatting of Expressions. (Was: Re: FD 2)

Ralph Corderoy ralph at inputplus.co.uk
Wed Feb 1 19:36:31 AEST 2023


Hi Dave,

COFF'd.

> > I'll never do if (a==b&&c==d), always if ((a==b)&&(c==d)).
>
> Indeed; I *always* use parentheses even if they are not necessary (for
> my benefit, at least).

I find unnecessary parenthesis annoying and clutter which obscures
reading.  If parenthesis are used only when overriding the default
precedence then this beneficially draws attention to the exception.

I doubt mandatory parenthesis are used in maths formulas by those that
use them in expression.

Whitespace is beneficial in both maths formulas and expressions.  The
squashed expression above will often be spaced more.

    if (a==b && c==d)
    if (a == b && c == d)

Go's source formatter will vary which operators get spaces to reflect
precedence, e.g. https://go.dev/play/p/TU95Oz57GuF shows ‘4*3’ differs.

    fmt.Println(4 * 3)
    fmt.Println(5 ^ 4*3)
    fmt.Println(5 ^ 4*3 + 2/1.9)

-- 
Cheers, Ralph.


More information about the COFF mailing list