zlacker

[parent] [thread] 3 comments
1. devjam+(OP)[view] [source] 2024-01-24 07:58:34
The author used:

    sum := float32(0)
Over Go's zero-value default initialization e.g.

    var sum float32
A nit stylistically but wondering if there was a good reason to do so?
replies(2): >>mehele+G >>abigai+s7
2. mehele+G[view] [source] 2024-01-24 08:04:11
>>devjam+(OP)
One advantage is that it makes the value explicit so anyone reading the code irregardless of their familiarity with Go will know it will be zero.
3. abigai+s7[view] [source] 2024-01-24 09:06:33
>>devjam+(OP)
i do the same because i find the var keyword ugly
replies(1): >>devjam+Re
◧◩
4. devjam+Re[view] [source] [discussion] 2024-01-24 10:19:39
>>abigai+s7
Sure, I understand that from the POV of making your code explicit. Personally I have always tended towards, for example:

    var x string
when initializing empty (zero-value) vars, versus:

    x := "hello"
when initializing variables that should hold an initial value.

To me as a Go programmer at least, this is more obvious and intuitive as to the intent of the declaration.

[go to top]