|
|
|
|
|
by morelisp
1326 days ago
|
|
Go does not have operator overloading, and numeric operators must have identical types. So if you have `var x int = 5` and `var t time.Duration = 2500 * time.Millisecond`, you have to `time.Duration(x) * t` or `time.Duration(x * int(t))`. It's slightly better than languages with no operator overloading nor newtypes at all (well, actually a lot better given other things you can use newtypes for) but without operator overloading using it just for units, with no other API machinery, is usually a bad idea. |
|
1. Don't type units like that.
2. Allow the * operator to multiply a time-unitful value with an untimed scalar and disallow using it with two time-unitful values.
Presumably the requirement that * operands are the same is arbitrarily modifiable and go developers have control over what types operators take.