News for hackers. Stuff that matters.
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

  _ = file.write(data) catch |err| { silence_err_somehow(err); ... }.
You can just write

  _ = file.write(data) catch { ... }.
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

  file.writeAll(data) catch { ... }
[0]: https://ziglang.org/documentation/master/#catch
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.
Re:Looking at Zig Programming Language by 0des on Tuesday April 05, 2022 @07:42PM (#30926593)
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.
Re:Looking at Zig Programming Language by wyldfire on Tuesday April 05, 2022 @01:20PM (#30921873)
That makes sense. But it's easy to confuse a prose ellipsis with the C++ notation for indicating the wildcard exception acceptance pattern.
Re:Looking at Zig Programming Language by kjs3 on Tuesday April 05, 2022 @05:03PM (#30925002)
Zig is not C++.
Re:Looking at Zig Programming Language by hibbelig on Tuesday April 05, 2022 @05:33PM (#30925326)
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.
Re:Looking at Zig Programming Language by wyldfire on Tuesday April 05, 2022 @06:44PM (#30926070)
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.
Re:Looking at Zig Programming Language by karmakaze on Tuesday April 05, 2022 @01:56PM (#30922478)
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?
Re:Looking at Zig Programming Language by lhorie on Tuesday April 05, 2022 @02:30PM (#30922942)
Re:Looking at Zig Programming Language by elcritch on Tuesday April 05, 2022 @09:53PM (#30927567)
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").
Re:Looking at Zig Programming Language by nrclark on Tuesday April 05, 2022 @02:12PM (#30922715)
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`.