But personally I don't agree with the decision - it adds surprises when you try to convert times to other types and then compare things. Or convert to something else and then back to a time instance. I've watched things like this become the source of bugs many, many times - this will only make that worse, since now a "time" is two values but you can really only access one of them (the one that's equivalent to wall-clock, which is causing the problems). And they're particularly painful bugs, because the cause lies in implicit conversions and behavior. That seems to run counter to the "minimal surprises" that Go seems to prioritize.
But, I could easily see looking back in 2 years and realizing you were right.
That code-corpus-analysis is pretty neat, I hadn't looked through in detail before. Thanks for pointing it out!
---
Sorta as an aside, it seems the proposal can lead to:
t1 = time.Now()
...
t2 = time.Now()
diff = t2.Sub(t1)
t1.Add(diff) != t2
Times are hard :| t1.Add(diff).Equal(t2)
would still hold, because Now gets monontonic time, Add and Sub maintain it, and Equal checks it. // time = [wall, mono], just ints for simplicity
t1 = time.Now() = [10, 10]
t2 = time.Now() = [19, 20] // wall clock lags slightly on second measure
diff = t2.Sub(t1) = (20 - 10) == 10 // Sub only operates on mono-time
t1.Add(diff) == [20, 20] // Add adds `diff` to both wall and mono
[20, 20] ==?== [19, 20]
I'd expect those to be different, since they represent different wall-clock times.So t2.Equal(t1) is true.
You are right that "t1 == t2" (comparing the raw bytes of the time structures) is false, but that was already broken anyway (because time-zones break raw byte equality).
(Whether you think it's OK to have a language that doesn't overload == and makes you know that for complex structures you've got to call a method like Equal() probably correlates pretty highly with your opinion of Go.)
There will of course be other weird things, like:
print(t1) // "20 [20]"
print(t2) // "19 [20]"
But you could argue that's basically the least-surprising possible result in the face of the surprising fact time having gone backwards one second. :)By the way, worth mentioning that while this is all implemented in HEAD in Go, it's not a done deal yet -- it'll have a 3-month window for people to try it out in the real world, and if it's found to be problematic, it'll get backed out before becoming part of the official release.
Gotcha, I missed that somewhere. That's essentially fine - then the only real surprises are when you deserialize a Time (so it doesn't have a mono time), which should in principle have no interactions with this proposal.
And yeah, Equal vs ==, the meaning was clear enough that I didn't bother to be specific :) Thanks for the infos!