Zig doesn't have `goto` because it's a redundant language feature.

Zig uses an idiom that is, in effect, a structured subset of goto functionality: labelled blocks, `break`s, and `continue`s. The ability to label `for`, `while`, and `switch` expressions, along with blocks, means that the use case of navigating nested control structures is already done.

`errdefer` (https://ziglang.org/documentation/0.14.1/#errdefer) facilitates the `goto err` pattern, while allowing you to keep the cleanup code close to the code that necessitates it, rather than lumping everything together at the tail end of the function. It also covers every exit path, inferring whether to run the blocks from the return type, which you'd have to do manually with `goto`s.

In fact, this redundancy is exactly why the developers removed `goto` eight years ago: https://github.com/ziglang/zig/issues/630

       - Willow

On 13/08/2025 13:33, Alyssa M via 9fans wrote:
On Tuesday, August 12, 2025, at 2:07 PM, David Leimbach wrote:
Simple can be nice. I happen to like languages with a bit more expressive type systems. Sum types without unions is not something I’ve tried to do before.

Mostly I just use a struct with all the members instead. But you can do a lot with a type tag and a cast.

On Tuesday, August 12, 2025, at 2:40 PM, sirjofri wrote:
Honestly, I really like typedef and goto, at least the way they are used in Plan 9 code.

As someone once said: "if you want to go somewhere, a goto is the quickest way to get there." I can't argue with that. But I haven't used a goto in a long time now: see https://xkcd.com/292 <https:// xkcd.com/292> :-) Looking at their grammars, I think Zig has no goto statement! Neither does Rust from the look of it. Not surprisingly (given the origin of the above quote) Go does, however, and so possibly puts you at the risk of raptor attack... ;)

On Tuesday, August 12, 2025, at 2:40 PM, sirjofri wrote:
All that said, this is all syntactic sugar, as C could also be described as syntactic sugar on top of assembly. In the end, you can deal with the memory as you like. C just gives you a bit more type safety.

That's very much how I look at it. It's my favourite macro assembler with type checking. :)

On Tuesday, August 12, 2025, at 2:40 PM, sirjofri wrote:
I never understood why people have so much trouble understanding pointers, so maybe I'm the weird guy.

I feel a good grasp of assembly language/machine code is important for programmers. Without that I'd never really feel I had my feet on the ground. I think pointers and addresses are much harder to understand in the abstract.


One of these days I'd like to write a 9P server in LOLcode (https:// en.wikipedia.org/wiki/LOLCODE <https://en.wikipedia.org/wiki/LOLCODE>). It's on my bucket list :)
Something like:

IM IN YR NAMESPACE
I HAS A msg ITZ A Fcall
I IZ convM2S YR msg AN YR buffer MKAY
BOTH SAEM msg'Z type AN Twalk, O RLY?
YA RLY,
...
OIC
KTHXBYE


But it would have to run on Plan 9, FTW, and someone would have to port the interpreter...

On Tuesday, August 12, 2025, at 4:58 PM, ron minnich wrote:
The acid test for portability, for me, is simple: if it can run on Plan 9 and Unix and WIndows and OSX and bare metal, it's portable. Anything else is not.

I gather LOLcode runs on Unix, Windows and OSX, and has been stable for longer than Zig has existed. Or Go for that matter...

IM IN YR BIOS
...

Please no!
*9fans <https://9fans.topicbox.com/latest>* / 9fans / see discussions <https://9fans.topicbox.com/groups/9fans> + participants <https://9fans.topicbox.com/groups/9fans/members> + delivery options <https://9fans.topicbox.com/groups/9fans/subscription> Permalink <https://9fans.topicbox.com/groups/9fans/Ta74fdc99bf0151a0-

------------------------------------------
9fans: 9fans
Permalink: 
https://9fans.topicbox.com/groups/9fans/Ta74fdc99bf0151a0-M7f97c316e6cbc5271a55f881
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription

Reply via email to