-
-
Notifications
You must be signed in to change notification settings - Fork 546
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
change: Which, if any, input/coin combinations are errors? #1313
Comments
I don't understand why an error even needs to be considered here. I propose all the |
@Insti there is a clear distinction between those cases. In the first, we need none of the coins available to create a stack of value In my opinion, there should be an error in the latter case. |
I oppose. It is not possible to make target 3 with coins 5 and 10. It is possible to make target 0 (use no coins). |
❤️ Thanks for clearing that up for me. proposal withdrawn. |
change 1.3.0 As proposed in #1313 #905 (comment) In contrast to the proposal in #336 (comment) Although -1 is a sentinel value, the sentinel value had been overloaded in this JSON file to mean two separate conditions: * "Can't make target" (ostensibly, we might be able to make the target with a different set of coins) * "Target is negative" (no matter what coins we provide, this target is always invalid) To make clear that these two conditions are different, we use an error object describing each. This error object was defined in #401 Note that this commit is not a decree that all languages must represent these conditions as errors; languages should continue to represent the conditions in the usual way for that language. It is simply a declaration that these two conditions bear enough consideration that we'll represent them with a different type and also clearly differentiate between the two. Closes #1313 Checks the related box in #1311
Notice that https://github.com/exercism/problem-specifications/blob/master/exercises/change/canonical-data.json uses
-1
to indicate "cannot make the target amount using the coins given". The question: Should this be considered an error? If so,change
is covered by #1311.I consider searching for a negative target an occurrence that an implementation should not be expected to handle. So I think using an
error
object is reasonable here. We can discuss implementations that should handle negative targets with negative coins, but I think it can be considered out of scope for the exercise. But you can see my previous comments #336 (comment) on it.I consider searching for a non-negative but unattainable target 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(coins)
when there actually is a coin combination.I would normally refrain from commenting on whether this should be represented in JSON as a
-1
sentinel or anerror
object ornull
.But, as I say in #905 (comment) , I also wouldn't encourage languages with both optionals and errors (Rust's
Option
andResult
, or Haskell'sMaybe
andEither
) to use both of those. So in the target language, I'd suggest just using one.So this leads me to think they should all be expressed as an
error
object.In the absence of any other preference, I would suggest to say that all of these should be represented by an
error
object, so this should be handled as part of #1311. In that case, we can close this issue, for #1311 will remind us to changechange
's JSON appropriately.The text was updated successfully, but these errors were encountered: