DEV Community

Discussion on: Golang Patterns - Part 1

Collapse
 
msoedov profile image
Alex Miasoiedov • Edited

we want to group common constants in the same namespace.

This does not quite fit all use cases, this constants package introduces an inter package/module dependency which not always great especially in service oriented envs

Options shows a flexible way to construct an object.

NewGreeting(Name("Mickey"))
Actually is relatively harder to read and implement comparing to building pattern

NewGreeting().WithName("Mickey")

Collapse
 
napicella profile image
Nicola Apicella

Hi! Thanks for the feedback. I named the package after the example I wanted to show (I.e. maybe package, options package etc.). It is not required to have the constants in a different package (neither is required to name it constants in case you want to have a different package).
As for Options, it s a really valid point and I think the reason why options is more popular than builder(despite the fact that builder is slightly more readable) may be the lack of library like Lombok for example, which generates boiler plate code for you. Options is a bit more light from this point of view, but like you pointed out, might loose a bit in readability.