3 ms·
This example is nice but if you put arguments metadata in the function name, you have to have one main argument, the function name can prove cumbersome if you h
by makapuf 5y ago
This example is nice but if you put arguments metadata in the function name, you have to have one main argument, the function name can prove cumbersome if you have 3 or 4 arguments with units like
.setPricePerMassInCentsPerKilogramsWithTimeoutInMilliSeconds(100,2,300)
- elcomet 5y agoI think you should rather do .setPrice(priceInCents=100, massInKg=2, timeoutInMs=300)
- gregmac 5y agoI'd argue there are better API patterns for this though -- keeping in mind this values code readability (and correctness) over micro-optimization: .setPriceInCents(100); .setMassInKilograms(2); .setTimeoutInMilliseconds(300); or .calculate({ priceInCents = 100, massInKilograms: 2, timeoutInMilliseconds: 300, });
- HelloNurse 5y agoValues 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))