Re:Please put units in names
by gregmac on Monday March 21, 2022 @01:21PM
(#30756958)
I'd argue there are better API patterns for this though -- keeping in mind this values code readability (and correctness) over micro-optimization:
or
[ Parent
| on HN ]
Re:Please put units in names
by HelloNurse on Tuesday March 22, 2022 @06:52AM
(#30764625)
Values with an intrinsic unit scale up to many units and values. If you declare the parameters of a "calculate" function as USACurrency, Weight and Duration you can write
calculate(100cent, 2Kg, 300s)
calculate(0.1dollar,4.7lb/*approximate*/,5min)
calculate(something.price(),whatever.weight(),options.getDuration("exampleTimeout"))
calculate(USD(0.1),Kg(2),Minute(5))