Live data from Hacker News

Zig's Lovely Syntax

matklad.github.io

41–50 of 246 posts

Re: Zig's Lovely Syntax

#41
post #35
post #28

I like Zig as well, but I won't call its syntax lovely. Go shows you can do pretty well without ; for line breaks, without : for variable types etc. But sure, if you only compare it with Rust, it is a big improvement.

I personally find Go's bare syntax harder to parse when reading, and I spend more time reading code than typing it (even while writing). An excessively terse syntax becomes very unforgiving, when a typo is not noticed by the compiler / language server, but results in another syntactically correct but unexpected program, or registers as a cryptic error much farther downstream. Cases in point: CoffeeScript, J.

That is why syntax debates are so difficult. There is no objectively best syntax. So we are all stuck with subjective experience. For me I find Python (non-typed) and Golang syntax easiest to read.

Too many symbols like ., :, @, ; etc just mess with my brain.

Re: Zig's Lovely Syntax

#42
post #15

> C uses a needlessly confusing spiral rule Libellous! The "spiral rule" for C is an abomination and not part of the language. I happen to find C's type syntax a bit too clever for beginners, but it's marvellously consistent and straightforward. I can read types fine without that spiral nonsense, even if a couple of judicious typedefs are generally a good idea for any fancy function types.

> fancy function types

If the syntax were straightforward, plain old function types wouldn't be ‘fancy’ :)

Re: Zig's Lovely Syntax

#43

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…

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

Re: Zig's Lovely Syntax

#44

Everyone agrees that "syntax doesn't matter", but implicit in that is "syntax doesn't matter, so let's do what I prefer". So really, syntax does matter. Personally I prefer the Rust/Zig/Go syntax of vaguely C inspired with some nice fixes, as detailed in the post. Judging by the general success of that style, I do wonder if more functional languages should consider an alternative syntax in that style. The Haskell/OCa…

That saying never made any sense to me either. After all syntax is your main interface to a language. Anything you do has to go through the syntax.

Some people say the syntax just kind of disappears for them after some time. That never seems to happen with me. When I am reading any code the syntax gets even more highlighted.

Re: Zig's Lovely Syntax

#46
Zig is just fun to write. And to me, it’s actually what I wish Rust was like. Rust is a great language, and no one’s going to argue that point but writing Zig for the first time was so refreshing. That said, Rust is now basically default for systems and Zig came too late.

Re: Zig's Lovely Syntax

#47
> I think Kotlin nails it: val, var, fun. Note all three are monosyllable, unlike const and fn!

At least in my pronunciation, all five of those are monosyllabic! (/kQnst/, /f@n/).

(Nice to see someone agree with me on minimizing syllable count, though — I definitely find it easier to chunk[1] fewer syllables.)

[1]: https://en.m.wikipedia.org/wiki/Chunking_(psychology)

The use of Ruby block parameters for loops in a language without first-class blocks/lambdas is a bit weird to me. I might have preferred a syntax that looks more like normal variable binding.

Re: Zig's Lovely Syntax

#48
> Note all three are monosyllable, unlike const and fn!

I'm not sure if I'm parsing this right, but is the implication that "const" is not monosyllabic? It certainly is for me. How else do people say it? I get "fn" because people might say "eff enn" but I don't see what the equivalent for const would be.

Re: Zig's Lovely Syntax

#49
post #12

> Like Rust, Zig uses 'name' (':' Type)? syntax for ascribing types, which is better than Type 'name' I'm definitely an outlier on this given the direction all syntactically C-like new languages have taken, but I have the opposite preference. I find that the most common reason I go back to check a variable declaration is to determine the type of the variable, and the harder it is to visually find that, the more annoy…

Maybe it just have to do with what you are used to, it was one of the things that made me like Rust coming from F# it had the same `name : type` and `let mutable name` that I knew from there.
Post reply on HN