-
-
Notifications
You must be signed in to change notification settings - Fork 195
discussion: Should we return Maybe when there is a possibility of invalid input? #115
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
Those exercises fell awkward and force unidiomatic solutions. It's desirable, at least, to avoid promotion of bad coding practices. We should probably avoid demanding "error encoding" practices and partial functions most of the time. I'm not against having a few exercises with not-so-idiomatic interfaces, as they force people to learn other features, but I believe that should be the exception, not the rule. If the problem's description doesn't specify a behavior on invalid input, it should return a Maybe. I understand it's desirable to have exercises that allow a diversity of solutions, but the need - in Haskell - to type-check the solution with the tests forces us to choose an appropriate interface. So, I agree! 👍 |
If we are considering rewriting exercises, let's first see how this relates to
The way things are now, the four base-conversion exercises look essentially the same. We can correct their return types, but I guess the best thing is to ask in About About So I suggest we solve this issue like this:
What do you think, @petertseng ? Anyone else has anything to say about this? I would appreciate some feedback here. 😄 |
I'm surprised to learn that the specification for the base-conversion exercises is so different. To change the specification in x-common requires notifying all implementing tracks of the change; that would be made simpler if they were combined. We'll see what comes of that.
If you'd like to know why it is this way, we can look at the commit where it was added. noting that there was discussion on this very issue. Even knowing the rationale, I still slightly favor changing
Looks like nothing stops us from doing this, good. |
To try increasing visibility and maybe get a little more participation, I think we should open two issues:
|
Considering that exercism/problem-specifications#276 will probably take some time to finish, I don't see any problem in opening a new issue to change the return types of That's up to you, @petertseng, if you think it's worthy. |
It's altogether possible we could just go ahead and change the four base conversion exercises if the consolidation of |
You're right! exercism/problem-specifications#276 is going faster than expected. |
Looks like BTW, thanks for everything, @petertseng. 👍 |
Considering that...
...and that the initial demand was...
I think the initial demand was solved and this issue can be closed. Also, we can deal with other exercises that do not check for invalid inputs on their own issues on a case-by-case basis, as we are doing in #166. Are you satisfied with that solution, @petertseng 👍 ❓ |
Seems good to me, and since I can close it, and you seem to also be in favor, I'll go ahead and do it. If anyone has more to add here I'm sure they can speak up here or elsewhere. |
While working on #114 I noticed that the binary tests just return 0 when there is an error.
That's simpler to implement. The disadvantage is that it makes the two cases "valid input whose value is zero" and "invalid input" indistinguishable to someone who can only observe the output values. Would we like to return
None
s for invalid inputs? I did getMaybe
s added to largest-series-product in #89 .Personally I would argue for it since I think it's a common thing in Haskell and more exposure to it is good, but there may be a possibility that there's too much. Wonder what others think.
To clarify scope, this is not suggesting that every exercise that possibly can test invalid inputs should (for example, "should the meetup exercise test nonexistent months") - that is a separate question that is worth another issue if someone wish to discuss it. The question is simply: For the exercises that already test invalid inputs, should they return
Maybe
as the result?If this is done, at the very least all the base conversion exercises will want it (binary, trinary, octal, hexadecimal). I can possibly investigate the other exercises in Haskell to see where else it would make sense to add too.
Survey of existing exercises and how they handle invalid inputs:
error
https://github.com/exercism/xhaskell/blob/master/exercises/nucleotide-count/example.hs and the tests check for it viaControl.Exception
. Seems a big hammer, whereas I'd rather make the possibility of error apparent in the type system if we're going to check for it (it's one of the reasons why I use Haskell anyway)Maybe
say
,wordy
,zipper
already returnMaybe
s.The text was updated successfully, but these errors were encountered: