It might be an opinion piece, but I’ll do my best to look at it constructively, and objectively as soon as I get it out of my chest first: input validation in programming exercises can be really frustrating!
OK. Now, let’s look at the problem and potential solutions.
Exercism is great at teaching new programming languages, especially when exercises are grouped in syllabi, so you can explore specific topics, one by one. It is so good, in my opinion, because you can focus on a concept and try to explore, understand and practice it. Any accidental complexity is not only distracting from learning and detracting from the effect, but can be really frustrating. Input validation is particularly bad in that regard.
Here is an anecdote to illustrate it. It is my own experience from the last two days, but it happened to me many times before, and I’d like to think I’m not the only one so challenged.
I was doing an exercise All Your Bases, to do with integers on the Elixir track. A possible solution, one I followed was a recursive one. Some things were working, but then at one step all I was getting are timeouts, clearly I’ve got an infinite recursion somewhere. I spent a lot of time trying to figure out how
div functions in Elixir could not follow normal math rules that would cause my end recursion guard not trigger only to eventually realising that the problem was, that the test I was working on passed, and moved to the next one, which was feeding the function with rubbish data.
Of course, there is the argument that real programmes have to take care of the input data. I know. Input validation is an important concept but is it something we should be practicing with every exercise? Wouldn’t it be better to focus on the topic taught? After all, it is not real life applications we write, but we engage in educational exercises. I have some 20 years of programming experience and a number of languages I’m familiar with, and yet I still get caught by things like that when I try to learn something new. If something is not working and I get a generic error message, is spend a lot of time and eventually get annoyed with myself, the platform, the language. Is the problem that I misunderstood the syntax? Is the problem that I did something wrong? Or is it that there is a concept I haven’t considered yet, or that the tests feed some incorrect data? And in real applications, I think it is a good practice, to handle the validation ahead of time, and definitely outside of the business logic, isn’t it?
I think “fixing” it would make learning much easier and here are a few, non-exclusive, options to make it better, and I think it should apply to all the tracks. I would like to know what you think about the options
- Have tests that deal with input validation first, so input is handled before the main exercise begins in earnest. This alone will provide much better user/learner experience without changing the exercises themselves.
- Clearly state at the top of the exercise whether input validation is necessary or not. The current descriptions often send learners to focus on the algorithm rather than input validation first which ends in errors.
- Remove tests that feed incorrect data from most exercises, and keep them only in exercises that teach input validation.
- Create input validation concepts in syllabi to focus on good, idiomatic ways of handling input validation
While I would love to see points 3 and 4 above implemented, I think that option 1 is simple enough to do with little effort and huge benefit to people new to languages. And I’d be happy to make the changes as I go along through exercises.
What do you think? Has this been discussed before?