DEV Community

Discussion on: 3 difference between make and new in Go

Collapse
 
anusha_bhat profile image
Anusha Bhat

Even I use &StructType{} most of the times. During initialization if the values of the fields are not known, new(StructType) is good to use as it initialises them to zero values of the fields.

Collapse
 
ndane profile image
Nathan Dane

I’ve attempted to use new(StructType) for the last 2 days and I’ve found that it does make intention easier to read when skimming through code. It especially helps when unmarshaling json/protobuf into a struct as I quite often miss out the & to create a pointer in my haste and wonder why it doesn’t work later! new eliminates this as it is always a pointer! 😋