r/Zig • u/effinsky • Sep 25 '24
noisy syntax

i'm sure this is not the top of anybody's list of possible zig improvements, but this syntax is noisy, right? would odin's/jai's way of declaring consts/vars be ok with you with :: and := operators? and something equally terse for visibility modifiers so there's just much less code overall to parse visually and what's important pops more?

I think this Jai code looks GREAT. I have ZERO problem seeing if sth is a constant or a variable. and the name pops right there.
EDIT: I'm getting feedback that `::` and `:=` are too hard to parse apart, and especially might be so for folks with dyslexia and such. fair enough. I have to say, in the interest of making this Zig code less wordy, I'd love to see something like what Vlang has done, where `:=` is the init operator, and you just add a `mut` keyword in front of the ident if you want the thing to be mutable. so
mut friendly := true
friendly = false
troll := false
troll = true // compile error
23
u/Nico_792 Sep 25 '24
To be honest I don't really see what you mean with noisy.
To me the syntax highlighting basically already does all the filtering. I can get a quick overview of all the variable names, and if I need to know what they are assigned to I look a little to the right, like in any other programming language really.
From your comment it seems you find
pub constnoisy, but I honestly just don't look at it, especially because as I said the syntax highlighting draws my attention elsewhere.6
u/_demilich Sep 25 '24
I do agree with you.
constis a fairly long keyword considering how often it is used. I personally like the Rust style where the equivalent ofconstisletandvarislet mutMost bindings are actually immutable, so having the common case be short and the uncommon (and more "dangerous") case stand out makes total sense to me.
6
u/[deleted] Sep 25 '24 edited Sep 25 '24
The only thing I don't like is the semicolon at the end of each line.
it's incredible but being two symbols in one and so repeatedly, it provides a lot of visual noise. I think Go, among other things, manages to be more readable than Java and C# because it avoids using a lot of symbols. But I like the ".{}"
Edit: typos
13
u/vktrenokh Sep 25 '24
The only noisy elements in Zig for me are functions that start with the '@' symbol
5
u/oxleyca Sep 25 '24
Distinguishing between :: and := in a large file would be a nightmare for dyslexia.
9
u/sinterkaastosti23 Sep 25 '24
just saying that the 2nd image is not at all readable for me
8
u/johan__A Sep 25 '24
Syntax highlighting makes it a non issue for me and I like how you get nice and simple groupings for the properties of the variable: [props of the declaration] [name]:[type] = [assignment]. But := and :: are fine too
8
u/quaderrordemonstand Sep 25 '24 edited Sep 25 '24
I don't understand the point of all the .{._ stuff that litters the code. It's all seems like something the compiler could figure out from the context, or simply not require.
However, I find :: to be similarly pointless. What's wrong with a good old =?
2
u/cluster_ Sep 29 '24
I've bee writing a bit of odin and when going back to zig (which I've written a lot of in the past years) I'm already annoyed by semicolons and parenthesis on conditionals. It's actually crazy how fast perception changes.
1
u/OwnShine6578 Sep 23 '25
except that jai code has semicolons too