logoalt Hacker News

do_not_redeemlast Sunday at 4:06 PM3 repliesview on HN

Since we're talking syntax... it's mildly infuriating that the zig parser is not smart enough to understand expressions like `const x=a()orelse b();`. You have to manually add a space before `orelse` -- but isn't that what `zig fmt` is for? I have RSI and it's maddening having to mash the arrow keys and add/remove whitespace until the parser is happy.

I've heard the argument that people might confuse binary operators for prefix/postfix operators, but I don't buy it. Who would think an operator named `orelse` is anything but binary?


Replies

hmrylast Sunday at 4:09 PM

"Read the file, or else!" The threatening postfix operator

hiccuphippolast Sunday at 7:00 PM

No idea why it wouldn't add the space, but you could configure your editor to always add a space after `)` and let zig fmt remove the space when not needed.

nateglimslast Sunday at 5:08 PM

The error when you accidentally pass a variable directly instead of in a .{} is also really unclear.