News for hackers. Stuff that matters.
Re:Please put units in names by bnegreve on Monday March 21, 2022 @05:35AM (#30752045)
> physical quantities should [...] be encoded in the type system.

But types are not just useful to specify the content of a variable, they are also useful to specify the required precision.

So, if there is a type for seconds in the type system, should it be a 32 bits int or a 64 bits float? Only the user can say.

Re:Please put units in names by valleyer on Monday March 21, 2022 @05:38AM (#30752064)
A generic type would be useful then:

type DurationSeconds<Value> where Value: Numeric { ... }

DurationSeconds<UInt32>

DurationSeconds<Float64>

Re:Please put units in names by account42 on Monday March 21, 2022 @10:11AM (#30754328)
This is exactly what C++ 11 did with std::chrono [0] except it goes one step further and makes the period generic too.

[0] https://en.cppreference.com/w/cpp/chrono/duration