3 ms·
*cough* Golang *cough* time.Sleep(42 * time.Millisecond) time.Sleep(42 * time.Second) time.Sleep(42 * time.Nanosecond) time.Sleep(42 * time.Hou
by usrbinbash 5y ago
*cough* Golang *cough*
time.Sleep(42 * time.Millisecond)
time.Sleep(42 * time.Second)
time.Sleep(42 * time.Nanosecond)
time.Sleep(42 * time.Hour)
- conradludgate 5y agoThe 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
- int_19h 5y agotime.Sleep(time.Second * time.Second)
- usrbinbash 5y agoSo? Non Canonical code can be written in any language. The important thing is: There is a canonical way in the stdlib to specify durations that is easy to read for the programmer.