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
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.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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 envsNewGreeting(Name("Mickey"))
Actually is relatively harder to read and implement comparing to building pattern
NewGreeting().WithName("Mickey")
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.