News for hackers. Stuff that matters.
Re:Your test suite is trying to tell you something by jcampbell1 on Wednesday July 03, 2013 @11:05AM (#5984975)
The real problem is `duration * time.Millisecond` makes no sense. The time api seems a bit obtuse. Why not `duration.milliseconds`?
Re:Your test suite is trying to tell you something by jgrahamc on Wednesday July 03, 2013 @11:28AM (#5985156)
Agree. Part of the problem here is that the Go time.Duration is just an int64 so you can do arithmetic on them. It would be better if there was something like NewDurationMilliseconds(). Thus the type here allowed me to shoot myself in the foot.

Having said that it doesn't change the fact that looking into the 'flaky' test was the right thing to do. Even if the type system were different I'm sure I would have shot myself in the foot in some other way.

Re:Your test suite is trying to tell you something by barrkel on Wednesday July 03, 2013 @05:38PM (#5987702)
Seems it would rather be better if there was a .net TimeSpan / JodaTime Duration type, or better yet, a type system that understood units.
Re:Your test suite is trying to tell you something by Titanous on Wednesday July 03, 2013 @11:30AM (#5985175)
time.Duration is a count of nanoseconds, and time.Millisecond is a constant that represents the number of nanoseconds in a millisecond.

http://golang.org/pkg/time/#Duration

Re:Your test suite is trying to tell you something by AaronFriel on Wednesday July 03, 2013 @02:00PM (#5986337)
This is the sort of thing having a Haskell-like typesystem would fix - multiplying something by "time.Millisecond" is difficult to discern the semantic meaning of, especially when nothing in the code/language prevents you from doing it multiple times.

The idea of storing this information as just a regular Int64 bothers me after spending so much time in type system nirvana.

Re:Your test suite is trying to tell you something by dragonwriter on Wednesday July 03, 2013 @07:24PM (#5988165)
> The idea of storing this information as just a regular Int64 bothers me after spending so much time in type system nirvana.

Its not a regular int64, its a distinct named type (Duration) where int64 is the underyling time. I'm still getting familiar with Go -- and don't have it on the machine I'm using at the moment -- but from the docs named types are incompatible with other named types with the same underlying types in numerous contexts, but it looks like one place where named types are leaky abstractions is their interaction with operators.

Re:Your test suite is trying to tell you something by dragonwriter on Thursday July 04, 2013 @01:42PM (#5991661)
To illustrate this point, this code:

  package main

  import ( 
        "time"
	"fmt"
  )
  
  func ident(x int64) int64 {
      return x
  }

  func main() {
      t := time.Duration(1)
      v := math.Inf(t)
  }
produces the error:

  cannot use t (type time.Duration) as type int64 in function argument
The issue is with Go's arithmetic operators subverting the type system more than with the type system itself.