-
-
Notifications
You must be signed in to change notification settings - Fork 556
binary-search: Is searching for a nonexistent item an error? #1312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I agree it is not an error.
I'm fine with this. |
I do not think this were an error, as it just tells that we do not have an item there. I do not like it beeing I'd prefer specifiying If there is a literal |
The correct answer to this question is strongly dependent on the idoms of language being used. Some off the top of my head:
The problem, to me, is that it is possible to return For that reason, I prefer to represent it as an error; this more clearly signals to track maintainers that special handling and rewriting may be required. This doesn't preclude tracks from using a magic value in languages where that is idiomatic, and it allows tracks with better error handling than magic values to proceed with their native idioms. |
binary-search 1.2.0 As discussed in #1312 Although -1 is a sentinel value, using this sentinel value is not the usual course of action in some languages. In using an error object, we avoid giving the wrong idea that we are requiring the use of the sentinel value. This error value was defined in #401 Of course, languages that wish to use a sentinel value may continue to do so; this commit is not intended to decree that sentinel values are forbidden. Neither is this commit decreeing that all languages must represent this condition as an error; it is simply a declaration that this condition bears enough consideration that we'll represent it with a different type. Closes #1312 Checks the related box in #1311
Notice that https://github.com/exercism/problem-specifications/blob/master/exercises/binary-search/canonical-data.json uses
-1
to indicate "searched-for item is not in the array". The question: Should this be considered an error? If so,binary-search
is covered by #1311 .I consider searching for a nonexistent item an occurrence that the implementation should expect to routinely happen -- in a language with exceptions, for example, I would not recommend the use of an exception for this. A language with optionals would use its
None
for this case, and useSome(index)
when there actually is an index.However, I'll refrain from commenting on whether this should be represented in JSON as a
-1
sentinel or anerror
object ornull
.In the absence of any other preference, I would suggest to keep it as
-1
, and close this issue without changes.The text was updated successfully, but these errors were encountered: