News for hackers. Stuff that matters.
Re:Please put units in names by aasasd on Sunday March 20, 2022 @11:54PM (#30750046)
Perhaps the function shouldn't accept the unit of sec². Not least because I have no idea what a delay in that unit could signify.
Re:Please put units in names by ironmagma on Monday March 21, 2022 @12:01AM (#30750094)
It doesn't actually use units. Everything is in nanoseconds, so time.Second is just another unitless number.

  const (
   Nanosecond  Duration = 1
   Microsecond          = 1000 * Nanosecond
   Millisecond          = 1000 * Microsecond
   Second               = 1000 * Millisecond
   Minute               = 60 * Second
   Hour                 = 60 * Minute
  )
Re:Please put units in names by rsa25519 on Monday March 21, 2022 @12:01AM (#30750092)
Note that the wonderful Go type system interprets time.Second * time.Second as 277777h46m40s with the type time.Second (not sec^2)
Re:Please put units in names by frozenice on Monday March 21, 2022 @04:16AM (#30751567)

  time.Second * time.Second
The type of this is `time.Duration` (or int64 internally), not `time.Second` (which is a const with a value).

I agree, though, that this is not quite sound, because it can be misused, as shown above with `time.Sleep(delaySecs * time.Second)`.

In Kotlin you can do `1.seconds + 1.minutes` but not `1.seconds * 1.minutes` (compilation error), which I quite like. Here is a playground link: https://pl.kotl.in/YZLu97AY8

Re:Please put units in names by nine_k on Monday March 21, 2022 @12:09AM (#30750148)
Certainly, but for that the type system should be rich enough to support unit designators.

I know how to implement that in Haskell, and that it can be implemented in C++ and Rust. I know how to logically implement that in Java or Typescript, but usability will suck (no infix operators).

Re:Please put units in names by int_19h on Monday March 21, 2022 @04:55AM (#30751808)
Go tends to cover such things by incorporating them directly in the language. But then it tends to not cover them at all because it would "overcomplicate" the language...

For a good example of what it looks like when somebody does bother to do it, see F# units of measure.