7 ms·
The 'inline switch else' seems easy, no? "inline switch" should be self-explanatory. It expands at compile time like inline for loops or inline functions. It is
by audunw 4y ago
The 'inline switch else' seems easy, no? "inline switch" should be self-explanatory. It expands at compile time like inline for loops or inline functions.
It is somewhat unique that the switch case gives you a reference to what you matched with |x|, but isn't it essentially just shorthand for self.x? And that |x| is necessary when you want to do self.x.talk() where you don't know x
I can agree that async/await is tricky to understand properly. I managed to use it to write some nice code for a demo of a Verilog simulator, but it took a few tries to get it right, because async/await/suspend/resume definitely isn't intuitive to start with. Once you understand it the rules are quite simple though. I'm sure a well written tutorial could make most people understand it.
And it depends what you're trying to do. Using suspend and resume correctly can be hard. But most of the time that will be done by people writing libraries, and when you have an async aware library and an event loop, using just async and await isn't that hard.
Zig is a new language that isn't really finished. Documentation is sparse and they're still making breaking changes. To me, Zig is a very simple and concise language, much simpler than C in many ways (we're just used to C's quirkiness), and I'm sure when it's stable and there's better documentation and tutorials it'll be easy for most people to get a thorough understanding of it quickly.
- anonymoushn 4y ago> but isn't it essentially just shorthand for self.x At least in the `else` prong of the switch, if you want to do anything with the value you have to capture it, because `self` will be the union type, not the particular type within the union. I've previously asked about whether this could be done away with, like if you write `if (x != null)`, could that create a scope in which x refers to the non-null value in rvalue-ish contexts but to the nullable value if you want to set it to null? Some compilers like Sorbet do this and call the feature "type narrowing." It seems like it is a bit too magical to make it into Zig though.