rust-lang / rustlings

:crab: Small exercises to get you used to reading and writing Rust code!
https://rustlings.cool
MIT License
52.82k stars 10.03k forks source link

threads2.rs: Potentially misleading comment on second TODO #1965

Closed ComicSansMS closed 4 months ago

ComicSansMS commented 4 months ago

threads2.rs contains the following comment on the second TODO:

TODO: Print the value of the JobStatus.jobs_completed. Did you notice anything interesting in the output? Do you have to 'join' on all the handles?

I think the "did you notice..." here is potentially misleading. It is not unlikely that users will get an output of 10 times jobs completed 10, even several times in a row. In this case the note might mislead them into concluding that it is guaranteed that jobs_completed will always be at its maximum value after the first handle has joined, and it would therefore not be necessary to join all the handles.

I made the same mistake initially, but eventually realized that this behavior is timing dependent and can be changed very visibly by, for example, having each thread sleep for a different amount of time. If I had been less careful, I may have moved on believing that the note suggested it was not necessary to join all the handles.

Not wanting to call anyone out here for making a mistake, but a quick google search for "rustlings threads2" shows multiple examples of people falling into that same trap.

I am still unsure at this point what the original purpose of the question "Do you have to 'join' on all the handles?" is here. I feel it would be less misleading if it was phrased in a way like "Is the output always consistent between multiple runs? Why is it necessary to 'join' on all the handles?". Would such a phrasing still be in line with the original intention?

mo8it commented 4 months ago

Thank you for the feedback. Indeed, threads2 has been simplified in the main branch. The next release will ship the simplified exercise. Feedback to the simplified version is welcome: https://github.com/rust-lang/rustlings/blob/71053101c32d0fd374f8e122880b3d682519bac6/exercises/20_threads/threads2.rs

brunoparga commented 2 months ago

@mo8it I lost track of when my changes were made and when I updated the exercise, so my feedback is not super clear, but in terms of general feeling I find this exercise a bit confusing and not as well-written as the others. Same with threads3, I think - there is just no description at all of what the goal of the exercise is, other than the default "make it compile and tests pass". This is not as educational as actually describing what the exercise is about and what we're trying to accomplish.

Edit: basically, I am doing Rustlings so that I have to read the book as little as possible, and these two exercises don't really help with that. I hope the next chapter will get back to the previous level of doing-that-ness.

mo8it commented 2 months ago

@brunoparga I am open to suggestions for improving the current version of the exercise :)