-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Rework health statistics exercise #909
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
Conversation
weight may be a sensitive topic for some readers; use height instead as this isn't important to the content of the course
this lets us see a non-setter use case for &mut self it also makes the 'statistics' side of this exercise more explicit as we count doctor visits
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, thanks!
And, good call on weight -> height ❤️
@@ -2,6 +2,20 @@ pub struct User { | |||
name: String, | |||
age: u32, | |||
height: f32, | |||
doctor_visits: usize, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intentionally different from HealthReport::visit_count
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes--a patient has visited the doctor a given number of times, but a health report corresponds to a particular visit whose count it carries. Maybe visit_index
could be used, but I thought that might suggest zero-indexing or that there's a vector of visits somewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The plural ("visits") suggests a count. If it's not zero-indexed, what is it -- a datestamp?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably least confusing if we just make these variable names match. I'll update them to both be visit_count
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@domenukk, see above for your question about usize
vs u32
.
Is there a suggested solution on this exercise? Turns out I need to implement some not so neat approach to solve the |
There isn't a solution in the repo, but perhaps you'd like to add one? This is one of a few questions in the exercise that always generates some interesting conversation that is, I think, instructive for students. A few ideas that have come up in these discussions:
This is an illustration of Rust's flexibility to meet the situation: |
I would probably do something like this: let blood_pressure_change = self.last_blood_pressure.map(|last| {
let meas = measurements.blood_pressure;
(meas.0 as i32 - last.0 as i32 , meas.1 as i32 - last.1 as i32)
}); However, this does handle overflow by implicitly panicking (in debug) wrapping (in release mode). I don't think there's a very sane behavior available for overflow here: any blood pressure greater than a few hundred is not a realistically possible measurement (much less medically possible) and should rather be caught at the construction of |
I believe that it would have made much more sense to just use i32 since there are no way to have blood pressure exceeding the i32 range. I also agree thst a BloodPressure type would make sense in production code but given the way that the tests are written correctly a solution that uses a custom BloodPressure type will not pass the test. It leads to me having to write custom method to do the subtraction work since it is not possible to implement methods on built-in types like tuples. |
When I teach the course, I encourage students to not feel boxed-in by the existing code, any more than they would be boxed-in by existing code when writing a pull request. But, that is less clear from the contents of this repo. |
* exercises: health-statistics: weight -> height weight may be a sensitive topic for some readers; use height instead as this isn't important to the content of the course * exercises: health-statistics: add health report this lets us see a non-setter use case for &mut self it also makes the 'statistics' side of this exercise more explicit as we count doctor visits * exercises: health-statistics: normalize variable names
No description provided.