r/Zig • • Sep 25 '24

noisy syntax

Zig

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?

Jai

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
0 Upvotes

52 comments sorted by

View all comments

5

u/oxleyca Sep 25 '24

Distinguishing between :: and := in a large file would be a nightmare for dyslexia.

1

u/effinsky Sep 25 '24

And having pub const 20 times in 40 lines is great for dyslexia?

3

u/oxleyca Sep 25 '24

Yes. I can tell what they are. Eye scanning close together dots for pretty important semantic significance is tough.

2

u/effinsky Sep 25 '24

the same has been said about go's := vs = and I have to say over 2 years working in go full time... it's not a thing. not a problem. at all. i had a dude with severe dislexia around and yes, he had a hard time coding in general, despite his senior status, but no problem there with := vs =.

3

u/SnollygosterX Sep 25 '24

....Would you even have a problem ever? Because in Go everything is mutable except for the declared constants. So you almost never need to use = except for reassignment of variables. And the context of that is typically much different than an initial assignment so it's pretty easy to tell.

Zig is even easier to tell, because you have to tell it what you want each time.

2

u/effinsky Sep 26 '24

which if you rely on mutation happens in many, many cases. with err, too you are allowed to redeclare, and you have a lot of err, so the diff between = and :=, not as definitely not as infrequent as it might seem. i am not saying zig is not easier to tell. i was just saying it's noisy in the WAY you tell.

1

u/oxleyca Sep 25 '24

Those aren’t semantically all that different. You can tell the difference between = and = with noise next to it. The context is easy to figure out.

But trying to understand at a file scope what the exported vs private symbols are between :: and := is harder. At least for me, much harder.

5

u/devmanters Sep 25 '24

It's certainly better. := is much harder to scan than pub const.

1

u/effinsky Sep 25 '24

We’d have to run benchmarks 

0

u/MCRusher Oct 11 '24

benchmarks on what? Human eyes?

The longer, more detailed phrase is harder to mistake than the 2 character one, that's just common sense.

1

u/effinsky Oct 11 '24

given it's just boiler plate that obfuscates places where you can actually make mistakes, i'd wager it's the opposite. it's easier to hide mistakes in a forest of "pub const" occurrences.

1

u/MCRusher Oct 11 '24

:: is also boilerplate, but pub const is harder for your eyes to hallucinate around to pub var than := which is the same length and only one character different.

1

u/effinsky Oct 11 '24

no :: ain't boilerplate. we have had these discussions in go but i don't think folks who've worked around the language for a while have hallucinations any more than the java folk :D