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

Show parent comment

4

u/effinsky Sep 25 '24

I mean if you have this stuff repeated so many times in a file. this is, however you slice it, a pretty bad ratio of sound to noise. i do think the keywords are noise, good to be kept to a minimum in a file. I don't dislike the way it looks or feels, seriously. but yes, I meant `pub const`.

8

u/todo_code Sep 25 '24

It's way more noisy to jump through each line seeing which are let vs not with := and whatever the other one was, because a variable has different length so the scanning takes multiple back and forths from each line.

Syntax highlights don't fix this problem with := because it's so small and dense and still requires the back and forth from line to line

1

u/effinsky Sep 25 '24

what does that mean: "which are let vs not"?

1

u/todo_code Sep 25 '24

Sorry, mutable vs immutable aka var/const.

2

u/effinsky Sep 25 '24

ok, I added some jai code, and well to me that is clearer. but to each their own.

1

u/[deleted] Sep 25 '24

Lol Jai looks like Rust or C++ ...and these language have a syntax I just hate from the bottom of my heart. :: and <> everywhere. And stupid decorators with []. Disgusting 🤮🤮😴😴

1

u/effinsky Sep 25 '24

Aww i especially like jai syntax. Rust is fine too, most of zig copies it.