Hacker News new | past | comments | ask | show | jobs | submit
And this is exactly the kind the language should have a type for, Duration.
Not really.

I don't want to have a type for an integer in seconds, a type for an integer in minutes, a type for an integer in days, and so forth.

Just like I don't want to have a type for a float that means width, and another type for a float that means height.

Putting the unit (as oppose to the data type) in the variable name is helpful, and is not the same as types.

For really complicated stuff like dates, sure make a type or a class. But for basic dimensional values, that's going way overboard.

> I don't want to have a type for an integer in seconds, a type for an integer in minutes, a type for an integer in days, and so forth.

This is not how a typical Duration type works.

https://pkg.go.dev/time#Duration

https://doc.rust-lang.org/nightly/core/time/struct.Duration....

https://docs.rs/jiff/latest/jiff/struct.SignedDuration.html

I'm just saying, this form of "Hungarian" variable names is useful, to always include the unit.

Not everything should be a type.

If all you're doing is calculating the difference between two calls to time(), it can be much more straightforward to call something "elapsed_s" or "elapsed_ms" instead of going to all the trouble of a Duration type.