4 ms·
`bool metric` does not ring any bells (I never lived in US, so I had to refer to the comment to understand it), and units of `a` and `b` and result are missing.
by dottedmag 5y ago
`bool metric` does not ring any bells (I never lived in US, so I had to refer to the comment to understand it), and units of `a` and `b` and result are missing.
- mst 5y agoI'd imagine in an ideal world they'd've gone with `enum(Metric, Imperial) units` but as a direct rewrite of the original function signature it was probably the least worst available option.
- lionkor 5y ago`bool metric` implies that `metric` can be YES or NO, that's clearer than what was there before. Its a made-up example, this discussion is about style, not about semantics. To please those who would like to see a semantically improved version: (C++) enum class Unit { Meter, Inch, Foot, // ... }; template<Unit U> struct UnitValue { double value; }; template<Unit U> UnitValue<U> rectangle_area(UnitValue<U> side_a, UnitValue<U> side_b); // invocation example constexpr Unit unit = Unit::Meter; UnitValue<unit> result = rectangle_area<unit>({5.3}, {1.5}); std::cout << result.value << std::endl; There is still room for improvement, maybe some concepts to further generify it, some more comments, maybe a PDF with full documentation, ...