News for hackers. Stuff that matters.
Re:Zig's dot star syntax (value.*) by FlyingSnake on Saturday March 08, 2025 @06:35PM (#43304607)
At this point &var and *var are pretty much an established way across languages, like if-else. I don’t see any benefit of reinventing this paradigm.
Re:Zig's dot star syntax (value.*) by epolanski on Sunday March 09, 2025 @04:50AM (#43307385)
The fact that the author of Zig who's extremely well versed in C and C++ went this way should make you at least try to think why he went that way before dismissing it.
Re:Zig's dot star syntax (value.*) by FlyingSnake on Sunday March 09, 2025 @05:14PM (#43313911)
Sounds like Appeal to Authority fallacy.
Re:Zig's dot star syntax (value.*) by xigoi on Sunday March 09, 2025 @05:50AM (#43307675)
> Copying bad design is not good design.

—Andreas Rumpf

Re:Zig's dot star syntax (value.*) by nineteen96 on Sunday March 09, 2025 @06:18AM (#43307804)
Agreed. And p.* is remarkably unintuitive and nonsensical compared to *p.
Re:Zig's dot star syntax (value.*) by int_19h on Sunday March 09, 2025 @07:08AM (#43307995)
It's remarkably intuitive and sensible if you remember that . in Zig auto-dereferences for field access and then treat `*` in this construct as field name denoting the entire object.

Ada does the same exact thing, except there you write `p.all` instead.

In any case, while the exact syntax may not be ideal, using a postfix operator for dereferencing is vastly better than prefix in practice due to typical patterns of use. There's a reason why you end up writing () a lot in C code with heavy pointer operations - the things they end up mixed with most often turn out to have the wrong kind of priority and/or precedence more often than not. Things are much simpler when everything is postfix and code reads naturally left-to-right.

Re:Zig's dot star syntax (value.*) by IshKebab on Sunday March 09, 2025 @09:44AM (#43309020)
It's not at all unintuitive of nonsensical. You're just really used to *p because it what C uses.
Re:Zig's dot star syntax (value.*) by wruza on Sunday March 09, 2025 @07:31AM (#43308120)
You mean like if-else if, if-elseif, if-elsif, if-elif? I think I should use eif for my next language. You can have elsf and elf.

It’s not that important though. Many people write two or more languages without mixing the syntax.

p.* and lv.& would be good post-operators, imo. Less going left and parenthesizing.

Re:Zig's dot star syntax (value.*) by FlyingSnake on Sunday March 09, 2025 @05:18PM (#43313966)
But those are all variations of if-else, right?

The alternative to if-else would be something like `assuming-otherwise`.

The point was that there wasn’t really a pressing need to reinvent the *p/&p syntax.