Re:Looking at Zig Programming Language
by anonymoushn on Tuesday April 05, 2022 @12:19PM
(#30920940)
Regarding error handling verbosity, you don't actually have to write
You can just write
And the first example of using `catch` in the docs[0] does this. It may be useful to also use the non-error return value of `write` though, because partial writes will return an amount of written bytes less than the amount you asked to write. You need `writeAll` if you want to ignore this concern, and then you don't have to write `_ = ` because the non-error part of the error union is void (so you don't have to use it). Then you get
[0]: https://ziglang.org/documentation/master/#catch
[ Parent
| on HN ]
Re:Looking at Zig Programming Language
by nonsequitur on Tuesday April 05, 2022 @12:55PM
(#30921499)
Hint: It's `catch {}` instead of `catch { ... }`.
Re:Looking at Zig Programming Language
by anonymoushn on Tuesday April 05, 2022 @01:03PM
(#30921624)
That's right if you want to do nothing on error. I think TFA uses `...` to represent the code they would actually want to run if an error happened.
That's how I've always interpreted it unless its a convo about slices which are few. Everyone knows slices are the bees knees item 9, so not often does it need discussing.
That makes sense. But it's easy to confuse a prose ellipsis with the C++ notation for indicating the wildcard exception acceptance pattern.
Zig is not C++.
May no programming language ever introduce “foo” or “bar” keywords, lest mayhem be upon us.
Re:Looking at Zig Programming Language
by planckscnst on Wednesday April 06, 2022 @02:19AM
(#30929006)
Now I'm thinking there must be some brainfuck-like language called foobar.
Sorry, I suppose you could infer that but it was not my intent. It was merely my suggestion that someone's new exposure to Zig might be 'tainted' by previous exposure to C++ syntax.
One 'catch' that makes me uncomfortable with Zig is the camel/underscore-insensitivity. How do you find all references of a method? Does your editor/IDE know how to find writeAll when I search for references of write_all? Do you have lint rules that are enforced for a project's source?
That's nim[0], not zig
[0] https://nim-lang.org/docs/manual.html#lexical-analysis-ident...
Correct, though the case insensitivity hasn't ever cause me issues in Nim. Searching is easy or at most takes a simple regex. It's actually saved me from a few dumb overshadowing issues (as in "you can't redefine 'is_active' see 'isActive' here").
Is is possible you're mixing up Zig and Nim?
Re:Looking at Zig Programming Language
by AnIdiotOnTheNet on Tuesday April 05, 2022 @01:59PM
(#30922530)
Unless something has drastically changed since I last used Zig, it doesn't have the feature you're talking about except in the case of number literals. `write_all` is a completely different identifier from `writeAll`.