Re:Go Developer Survey 2022 Q2 Results
by bilinguliar on Thursday September 08, 2022 @02:22PM
(#32769701)
Indeed, this may be the use case.
I am curious how often you may need a pointer to an int.
[ Parent
| on HN ]
Re:Go Developer Survey 2022 Q2 Results
by marwatk on Thursday September 08, 2022 @02:42PM
(#32770098)
In things like rest APIs you need them quite a bit to distinguish between a value being the zero value and not present at all. Most libraries I've seen have an IntPointer or similar function exposed globally.
Re:Go Developer Survey 2022 Q2 Results
by bilinguliar on Thursday September 08, 2022 @02:54PM
(#32770289)
This is true. In the case of REST, it is your “encoding/json” who will allocate for int pointer. So I do not see why new() is needed.
Re:Go Developer Survey 2022 Q2 Results
by 37ef_ced3 on Thursday September 08, 2022 @03:05PM
(#32770436)
Are you seriously suggesting that the language should not have notation for allocating zeroed primitive types and receiving the address of the allocation?
var (
p1 = new(int)
p2 = new(*int)
p3 = new(**int)
p4 = new(complex64)
p5 = new(complex128)
)
I feel like you must be joking. Should we say var (
c complex128
p = &c
)
every time?
Re:Go Developer Survey 2022 Q2 Results
by bilinguliar on Thursday September 08, 2022 @03:17PM
(#32770605)
In five years, I needed to do the latter only once or twice because a library I was using demanded a pointer to a primitive.
Forgive my arrogance, but why does one need a pointer to a zero-value primitive in Go? I sincerely believe there is a use case for it, but I never needed this.