rust icon indicating copy to clipboard operation
rust copied to clipboard

assembly-line: What should happen with unexpected speeds?

Open gsilvapt opened this issue 3 years ago • 1 comments

Hello everyone :wave:

Came across this exercise recently and I was thinking about what should happen when the provided speed is above the maximum level.

The problem clearly states a range from 0 (off) to 10 (maximum), so I think something should happen in the function if the provided speed is more than 10. Perhaps I’m over engineering this problem, so before opening up a PR with a test to ensure the function panics, I would like to discuss if it makes sense to do so for this exercise. This is a very early stage in the track, perhaps too soon to introduce panic! macro.

Please let me know your thoughts. Ultimately, my intention is to avoid solutions that introduce a default match clause to catch everything from 9 and beyond, although that’s not wrong! Perhaps I am pet peeving here and if that is so, I am sorry :stuck_out_tongue:

gsilvapt avatar Feb 22 '22 13:02 gsilvapt

The challenge here is balancing a correct, idiomatic solution against requiring the smallest number of dependencies for an exercise which should come very early in the track's sequence. The fundamental options as I see them are as follows:

  • Have student code panic on invalid input. Unidiomatic; this is very rarely the right solution for production code. Requires an additional prerequisite concept: panics.
  • Return an Option. This is questionable; it's not that the computation may not return a result, it's that there may be an error case. Requires an additional prerequisite concept: options.
  • Return a Result. This is probably how we'd structure production code. However, it requires an additional prerequisite concept: results.
  • Don't explicitly check for out-of-bounds inputs, and just trust that the inputs provided are valid per the problem statement.

Clearly, we're currently using the last strategy, on the basis of avoiding prerequisites. I could potentially be convinced that Result is the right way to go, but I'd want to see a dependency analysis showing a reasonable path that a student could take through the track in that case. I want to avoid prerequisite cycles.

coriolinus avatar Feb 27 '22 18:02 coriolinus

I'm going to close this, since it's about a concept exercise and the syllabus has been deactivated. Future work on the syllabus is likely going to rework much of the existing concept exercises. My gut feeling is that it would be ideal if we only had exerices where all possible inputs are valid before we introduce error handling.

senekor avatar Dec 14 '23 23:12 senekor