Andrew wants to ban tabs again?

Trying to stop reading this thread, but can’t help myself, so I might as well add my two cents.

Enforced formatting is a nested tragedy of the commons.

Everybody collectively wins if there is some enforced formatting (because it’s easier to read for everybody) but everybody loose on the personal level (because some preferences are overruled)

The tricky part is that the lost is asymmetric. If you like tabs and the consensus goes to space, you loose big. But the other camp gets the advantage without the inconvenience.

Therefore you have level 2 where everybody collectively win if we just settle on one formatting (because you stop spending time arguing on the topic) but everybody has much to loose on the group level if the choice goes against their preference. This feed the tribal instinct.

On the bright side, nobody’s life depend on that particular tragedy of the commons, so at least there’s that …

9 Likes

From the perspective of supply chain security, quite a few open-source projects have repository source code using \n while the release version source code uses \r\n, or the repository source code has one more or one less line compared to the release version. These fmt format differences can cause headaches for automated audits. Although some preprocessing can be done manually to deal with it, it’s still annoying.

So Zig unifying these style issues when compiling rather than fixing them through fmt actually brings some convenience for auditing.

Overall, I’m in favor of having only one format, but it would be perfect if Zig enforced tabs for indentation instead of spaces. Unfortunately, it currently enforces spaces, but it’s still better than not intervening in style at all.

6 Likes

In a perfect world, indentation, alignment, and maybe even line length would be like syntax highlighting. When you write code, you don’t have to write \color{yellow} in front of every keyword. In theory an editor could add this in for you, but really it just doesn’t belong in the code. It’s kind of a wacky thought, but maybe indentation and alignment characters also don’t belong in the source code. The editor would still display the code in a readable way, of course. Also when you resize your editor window, it could reflow the text and resize the indentation automatically (just how it’s displayed) without actually changing the text.

It doesn’t even seem like it would be that hard to do, but of course the code would look unreadable in unenlightened editors.

3 Likes

…or potentially even just tools like grep.

Me: Where’s the symbol blah in this file?

Grep: Well, it’s in there, on line 1. Of course, everything is on line 1 in that file because your editor will reformat it for display.

1 Like

Yeah, the line length thing is pushing it. It could just be soft-wrapping with actual newlines as normal.

But if grep gave you any of the lines from this, I think you would still be able to understand it.

pub fn jsonParseFromValue(allocator: Allocator, source: Value, options: ParseOptions) !@This() {
if (source != .object) {
return error.UnexpectedToken;
}

var map: std.StringArrayHashMapUnmanaged(T) = .empty;
errdefer map.deinit(allocator);

var it = source.object.iterator();
while (it.next()) |kv| {
try map.put(allocator, kv.key_ptr.*, try innerParseFromValue(
T,
allocator,
kv.value_ptr.*,
options,
));
}

return .{
.map = map,
};
}

fn funWithBits(
a: i16,
) u16 {
const i: u16 = @bitCast(a);
return ((i & 0xF000) >> 12)
| ((i & 0x0F00) >> 4)
| ((i & 0x00F0) << 4)
| ((i & 0x000F) << 12);
}

You are definitely not the only one.

1 Like

Talking about Go, I am sure that of those three (Rob Pike, Ken Thompson and Robert Griesemer), Rob is the guy who wanted to clean up the most, and Robert was the guy who came up with the formatting, and thanks to his Oberon experiences he came up with the grouping ideas, such as import, type, var and const. Formatting - and grouping - is very important and it is such a waste to have to write so much to gain so little.

My two cents.