
Functional Options in Go when constructing a struct
Composition over Inheritance From my understanding, there is no constructor in Go, since Go does not advocate the concept of Object-Oriented Programming. Go prefers the idea of composition, which is more flexible than inheritance. Also, this is how C works, and Go is a language that is inspired by C. How to construct structs? My personal ranking of these 3: Functional Options > Direct Field Access > “Constructors” 0. Setting Suppose we have this Pineapple struct, with 3 fields:...