Skip to content

Latest commit

 

History

History
28 lines (20 loc) · 596 Bytes

struct-zero.md

File metadata and controls

28 lines (20 loc) · 596 Bytes

Use var for Zero Value Structs

When all the fields of a struct are omitted in a declaration, use the var form to declare the struct.

BadGood
user := User{}
var user User

This differentiates zero valued structs from those with non-zero fields similar to the distinction created for map initialization, and matches how we prefer to declare empty slices.