3 ms·
What you're suggesting is obviously more foolproof for sure. However it's definitely my observation that there are lots of times when we're passing numbers aro
by JohnBooty 4y ago
What you're suggesting is obviously more foolproof for sure.
However it's definitely my observation that there are lots of times when we're passing numbers around and we don't need something quite as robust. I'm not sure that replacing every number in an application with a custom type is typically the best use of time, and certainly there are performance reasons why we might sometimes want to pass fundamental numbers around instead of complex types.
In those cases, adding units/types to identifiers offers an awful lot of value for close to zero effort.
The case you claim requires drugs will happen
eventually even if everybody is sober. I've seen
it many times, and I doubt I'm the only one.
I've never seen it, but that's probably because in my 25 years of writing code I have rarely seen the convention followed in the first place because coders tend to be aggressively disinterested in writing maintainable code.
But seriously, if `launch_rocket(distance_km: distance_miles)` eludes the original coder and the code reviewers and future coders working with that code and it eludes your test suite... damn. You've got big problems.
- nyanpasu64 4y agoI wish more languages had keyword arguments. In the unfortunate languages I've used without them (C++/Rust), I usually avoid mixing up units/types through naming, but in the rare situations I do find myself confusing similar but distinct dimensions despite clear naming, I selectively opt into custom types where their utility justifies their interoperability/arithmetic/conversion downsides.