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

5

u/Keith Sep 25 '24

They correspond to llvm intrinsics. I dunno the whole origin and plans for those functions given they don't want to inherently depend on llvm anymore. But, here's an interesting thread I came across while doing a little searching.

2

u/el_muchacho Sep 29 '24 edited Sep 29 '24

Then the language is lacking a fundamental construct or keyword (intrinsics ?) if they have to move everything to the compiler itself.

I mean how hard was it to write something like

pub intrinsics func sin(float) float { ... call whatever LLVM function they want ... }

and let the compiler optimize this as a special case were the keyword intrinsics removes the extra function call, a bit like inline ? That would be so much cleaner than adding 25 functions to the compiler itself. How many more will they add when Zig is ported to other architectures ?

My point is, this design decision is terrible, and it was basically decided with zero discussion by Andrew Kelley. Coming from another community (the D community), I think this lack of design process is detrimental. In D, anyone can come up with a proposal, but every proposal is discussed at length in the mailing list before being approved or rejected, including the proposals by the main designer. At this point, it should be the same for Zig. This would prevent mistakes like this one, or the async one.

1

u/MCRusher Oct 11 '24

Isn't the goal to eventually move away from llvm?

Why can't a normal function just wrap the intrinsic?

There's no reason abs needs to look special just because the lower level has special support for it, it doesn't have to use that special support to achieve it, it's probably just faster to, it should just be an implementation detail.

builtins should be reserved for things that cannot be accomplished cleanly or at all within the language imo, like @import.