3 ms·
An often better solution is to have a type which is not an integer/string as input and have various ways to convert from/to integers in a unit showing way. Typ
by dathinab 5y ago
An often better solution is to have a type which is not an integer/string as
input and have various ways to convert from/to integers in a unit showing way.
Types like e.g. Duration (for e.g. sleep), Instance (for calculating time passed based on monotonic timestamps), Distance etc.
Through at the same time in static typed languages being generic over the unit is often unnecessarily and hinders productivity (e.g. Duration<TimeUnit> with types Duration<Seconds>, Duration<Hours>) similar having unit types (e.g. passing instances of Seconds, Hours to sleep) is also often not necessary and more harmful then good. (Exceptions exists, where you e.g. need to have where high precision and range while at the same time need to keep storage constraints as small as possible while also juggling units, like some scientific or embedded applications).