zig icon indicating copy to clipboard operation
zig copied to clipboard

proposal: change `zig fmt` to format lists of one item with spaces

Open nektro opened this issue 1 year ago • 2 comments

before:

.{x}
.{ x, y }

after:

.{ x }
.{ x, y }

love zig fmt and all it fights for. this feels like its one inconsistency though

nektro avatar Aug 11 '24 04:08 nektro

I like this. More consistency with tuple type declarations of one item adding a space and multi-item lists. Also makes it easier for me to read what's inside the list.

nickelca avatar Aug 11 '24 04:08 nickelca

somewhat related: https://github.com/ziglang/zig/issues/20349 (just wanted to link it so one isn't overlooked)

rohlem avatar Aug 11 '24 10:08 rohlem

I don't think it is necessary for a formater to be maximally consistent.

Consistency is not a terminal goal. Usually consistency is desired, because it helps the human to avoid decisions. If you can do X or Y, then you need to spend extra mental effort to choose which one of the two to use in any particular instance. In such cases, "always use X because consistency" is a useful mental effort saving heuristic, whose benefits usually outweigh relative merits of X or Y in any particular case.

But here, we are talking about a tool, and the tool is perfectly fine with using complex rules of decisions. So, in this case, there's no benefit to consistency as a coordination point.

Disregarding consistency, for me personally single-item list reads better as

.{x}

matklad avatar Aug 14 '24 09:08 matklad