ocamlformat icon indicating copy to clipboard operation
ocamlformat copied to clipboard

Style suggestion: Don't treat `not` as a special case.

Open polytypic opened this issue 1 year ago • 5 comments

Current formatting (tested with version 0.27.0) treats the not operation differently from other unary functions in some contexts:

let foo () = bax (bay ()) && baz ()
let foo () = (not (bay ())) && baz ()

What I'd prefer is to not treat not as a special case:

let foo () = bax (bay ()) && baz ()
let foo () = not (bay ()) && baz ()

I just don't find this more difficult to read.

To me the extra parentheses in (not x) && y just appear noisy.

polytypic avatar Dec 31 '24 11:12 polytypic

As a random user, I agree. ocamlformat's choice is highly unconventional, in that I have never seen anyone write such parens even once, nor any confusion resulting from the lack of parens.

v-gb avatar Jan 06 '25 17:01 v-gb

I think the special handling was requested by @mshinwell at some point

hhugo avatar Jan 06 '25 19:01 hhugo

see https://github.com/ocaml-ppx/ocamlformat/issues/266#issuecomment-409892953

hhugo avatar Jan 06 '25 20:01 hhugo

and some discussion in https://github.com/ocaml-ppx/ocamlformat/pull/686

hhugo avatar Jan 06 '25 20:01 hhugo

In the mentioned discussions, I see: one request with no reasoning from mshinwell, and jberdine saying not a && b is confusing without parens, which is not at all in line with my experience, as I indicated above.

I do think the conventional profile should drop these parens.

v-gb avatar Feb 14 '25 22:02 v-gb