3 ms·
The trouble with Go is that you can't multiple ints by Durations, leading to people doing `time.Sleep(time.Duration(x) * time.Second)` which is fine by itself,
by conradludgate 5y ago
The trouble with Go is that you can't multiple ints by Durations, leading to people doing `time.Sleep(time.Duration(x) * time.Second)` which is fine by itself, but then I see often people refactor and accidentally remove the second part.
The fact you can go from int to duration without specifying the unit does not give you the strong benefits. It's better than nothing though
- usrbinbash 5y ago> The fact you can go from int to duration without specifying the unit The unit that is converted in, is in the first sentence of the two-sentence documentation of time.Duration(): A Duration represents the elapsed time between two instants as an int64 nanosecond count. https://pkg.go.dev/time@go1.18#Duration https://pkg.go.dev/time@go1.18#Duration
- conradludgate 5y agoYes, in the documentation. But if I'm reading the original code and refactoring, having the docs open might not be my top priority