Live data from Hacker News

Zig's Lovely Syntax

matklad.github.io

241–246 of 246 posts

Re: Zig's Lovely Syntax

#241
post #166

I find Zig syntax noicy. I dont like the @TypeOf (at symbol) and pals, and the weird .{.x} syntax feels off. Zig has some nice things going on but somehow code is really hard to read, admitting its a skill issue as im not that versed in zig.

Zig is noisy and and the syntax is really not elegant. One reason I like odin's syntax, it's minimal and so well thought out.

Yes, Zig’s syntax is a bit noisier, but it enables things such as using if/for/while/switch in expressions, or using anonymous struct literals to emulate named and default parameters in functions.

Re: Zig's Lovely Syntax

#242
post #124

Earlier quoted context omitted.

I may be missing something but come Go has a simple: `A simple formatted string ` ?

Yours is rendered as: A\n\tsimple\n\t\tformatted\n\t\t\tstring\n\t If you wanted it without the additional indentation, you’d need to use a function to strip that out. Typescript has dedent which goes in front of the template string, for example. I guess in Zig that’s not necessary which is nice.

Okay I get it now. Formatted multiline string in code without an actual formatting and no string concat.

Re: Zig's Lovely Syntax

#243
post #238

Earlier quoted context omitted.

Well, your example seems to do something completely different, which is return an ArrayList!T rather than a type.

It achieves the same result in practice. The reason Zig needs to return a type is because it lacks a way to represent `T!A` where T is a parameterized type, and A is the parameter. In this case, that would've been better because you would be able to tell exactly what the type being returned was. If you must return different types depending on the argument in D, it's also possible. Here's a silly example: struct Array…

You still misunderstand the type type. "type" does not mean "generic over all types" but that you're returning a reified type. The original Zig function does not return an ArrayList value, it returns the ArrayList type.

Re: Zig's Lovely Syntax

#244
post #238

Earlier quoted context omitted.

Well, your example seems to do something completely different, which is return an ArrayList!T rather than a type.

It achieves the same result in practice. The reason Zig needs to return a type is because it lacks a way to represent `T!A` where T is a parameterized type, and A is the parameter. In this case, that would've been better because you would be able to tell exactly what the type being returned was. If you must return different types depending on the argument in D, it's also possible. Here's a silly example: struct Array…

It's now too late to edit my original comment but I've skimmed your code a little too fast and now I see that you do understand that Zig works with reified types. But in that case, why conflate too very different things? Returning values of different types is not the same as returning types.

Regardless, we are now very far removed from the original code I was commenting on, which doesn't use auto to return different types.

Re: Zig's Lovely Syntax

#245
post #57
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…

> I find that the most common reason I go back to check a variable declaration is to determine the type of the variable, Hover the mouse cursor over it. Any reasonable editor will show the type. > In Rust, in particular, this leads to some awkward syntactic verbosity, because mutable variables are declared with `let mut`, meaning that `let` is used in every declaration. Rust is very verbose for strange implementation…

>> I find that the most common reason I go back to check a variable declaration is to determine the type of the variable,

> Hover the mouse cursor over it. Any reasonable editor will show the type.

That applies to most of us, obviously, but in this context we're talking about Zig. Zig's lead developer, Andrew Kelley, programs in Vim with no autocomplete or mouse support.

Even though I sometimes use editors with these features, I find it frustrating when languages seem to be designed in such a way that presumes their availability. I found Rust particularly bad about this, for example.

Re: Zig's Lovely Syntax

#246
All of these examples look weird and unreadable to me. Rust borrows from decades of ML language syntax. I don't think that can go wrong. Not sure where the Zig choices come from but they seem to be there just to look "different"
Post reply on HN