Peter Christian Fraedrich
1 min readJan 5, 2020

While it’s an interesting exercise to bring more OOP style to Go, I’m not sure it’s necessary. It’s fairly standard within Go to just do

myVar := &SomeStruct{}

Or

myVar := make(SomeStruct{})

Alternatively if you want to initialize a struct with default values, simply creating a New() function would satisfy this.

func NewStruct() *MyStruct {

return &MyStruct{Key: val}

}

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Peter Christian Fraedrich
Peter Christian Fraedrich

Written by Peter Christian Fraedrich

Entrepreneur, software developer, writer, musician, amateur luthier, husband, dad. All opinions are my own.

Responses (2)

Write a response

While it’s an interesting exercise to bring more OOP style to Go, I’m not sure it’s necessary. It’s fairly standard within Go to just do

Hi Peter, thanks for your comment. I think perhaps I wasn’t clear in my post above – I strongly believe the only ‘style’ is the one that is consistent amongst the team, and strongly discourage arguing about anything style-wise as it’s effectively a…

--

A New function is the kind of initializer that was mentioned earlier in the post. the problem with it is that you need to go to great lengths to ensure/enforce your structs being created ONLY via the initializer (i.e. only initialized in a valid…

--