You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// ... Book version
interval(const interval& a, const interval& b) {
// Create the interval tightly enclosing the two input intervals.
min = a.min <= b.min ? a.min : b.min;
max = a.max >= b.max ? a.max : b.max;
}
and
// ... Alternative approach
Interval(const Interval& a, const Interval& b)
{
this->min = std::min(a.min, b.min);
this->max = std::max(a.max, b.max);
}
I understand that it is mostly a matter of taste, but I think using ternary operator hurts readability a bit and makes you read into the code more than it needs to. I think it is especially true for not very experienced and new-school programmers (which is who I consider myself to be).
Thank you so much for the book and for keeping it alive!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I think it is better for readability to use
std::min
andstd::max
functions instead of a ternary operator. Here are some examples:and
Also:
and
I understand that it is mostly a matter of taste, but I think using ternary operator hurts readability a bit and makes you read into the code more than it needs to. I think it is especially true for not very experienced and new-school programmers (which is who I consider myself to be).
Thank you so much for the book and for keeping it alive!
Beta Was this translation helpful? Give feedback.
All reactions