oop - Constructors in Go -


i have struct , initialised sensible default values.

typically, thing here use constructor since go isn't oop in traditional sense these aren't true objects , has no constructors.

i have noticed init method @ package level. there else similar can used @ struct level?

if not accepted best practice type of thing in go?

there 2 accepted best practices:

  1. make 0 value of struct sensible default. (while looks strange people coming "traditional" oop works , convenient).
  2. provide function func new() yourtyp or if have several such types in package functions func newyourtype1() yourtype1 , on.

document if 0 value of type usable or not (in case has set 1 of new... functions. (for "traditionalist" oops: not read documentation won't able use types properly, if cannot create objects in undefined states.)


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -