zlacker

[parent] [thread] 3 comments
1. pansa2+(OP)[view] [source] 2025-08-22 12:51:42
As long as you don’t need to do `hours := 8` and `+= hours * time.Hour`. Incredibly the only way to get that multiplication to work is to cast `hours` to a `time.Duration`.

In Go, `int * Duration = error`, but `Duration * Duration = Duration`!

replies(1): >>porrid+py
2. porrid+py[view] [source] 2025-08-22 15:58:02
>>pansa2+(OP)
That is consistent though. Constants take type based on context, so 8 * time.Hour has 8 as a time.Duration.

If you have an int variable hours := 8, you have to cast it before multiplying.

This is also true for simple int and float operations.

  f := 2.0
  3 * f
is valid, but x := 3 would need float64(x)*f to be valid. Same is true for addition etc.
replies(1): >>throwa+B31
◧◩
3. throwa+B31[view] [source] [discussion] 2025-08-22 18:33:55
>>porrid+py
It's also completely insane if youve ever done any scientific work.
replies(1): >>porrid+hz3
◧◩◪
4. porrid+hz3[view] [source] [discussion] 2025-08-23 17:47:11
>>throwa+B31
Apart from the extra verbosity, what gives?
[go to top]