zig
zig copied to clipboard
exercises: consider replacing some errors with optionals/asserts/assumes
For example, for binary-search
, the Zig track currently requires the user to return an error when the input is empty:
https://github.com/exercism/zig/blob/c5ece12152f8086e77db85f825d9d673f0cda1af/exercises/practice/binary-search/test_binary_search.zig#L56-L58
or the value is not found:
https://github.com/exercism/zig/blob/c5ece12152f8086e77db85f825d9d673f0cda1af/exercises/practice/binary-search/test_binary_search.zig#L44-L46
But we can consider the empty array to be a normal case of "value not found", in which case the only possibilities are "value found, or value not found". Then we can return an optional. The Zig stdlib does that - the implementation of binarySearch
returns ?usize
I'll propose changing this one. But we should look at all the exercises and think about whether it's better to return an optional, rather than an error union. Especially exercises where the error set is of length 1.
As of 2023-03-16, the exercises that can return a custom error are:
-
collatz-conjecture
-
grains
-
hamming
-
queen-attack
-
triangle
(considered in #257)
We previously had:
-
binary-search
(removed in #259) -
rna-transcription
(removed in #258)
I might propose removing more custom errors.