Hacker News new | past | comments | ask | show | jobs | submit
I do that, but I can't help thinking that it smells like Hungarian notation.

The best alternative I've found is to accept units in the values, "5 seconds" or "5s". Then just "1" is an incorrect value.

That’s not automatically bad. There are two kinds of Hungarian notation: systems Hungarian, which duplicates information that the type system should be tracking; and apps Hungarian, which encodes information you’d express in types if your language’s type system were expressive enough. [1] goes into the difference.

[1] https://www.joelonsoftware.com/2005/05/11/making-wrong-code-...

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

loading story #42773239