Why having no space in one side of a binary operator a compiler error?

Example:

pub fn main() !void {
    const x: u8 = 1 +1;
    _ = x;
}

Will produce the following error message:

error: binary operator '+' has whitespace on one side, but not the other
    const x: u8 = 1 +1;
                             ^

What’s the reason this is a compiler error?

is Andrew not wanting to read poorly formatted code.
Here is discussion for it Proposal: Require whitespace on both sides of - or neither · Issue #7399 · ziglang/zig · GitHub

6 Likes

kinda related

To ensure that binary operators in Zig never look like the repulsive output that the Go formatter forces upon us.

Reasonable minds can disagree, but I am in the camp that opinionated and mandatory formatting is a good thing (as long as I agree with it, otherwise it is obviously a bad thing).

7 Likes

“Scriptio continua” vs “my lexer is really good”

:slight_smile: