I just learned about the Functional Options
pattern in golang.
what are the benefits of using it over just allowing to pass a config struct and just overriding the default values provided in the config?
why do i need the complication of passing a function?
I saw here is that the advantages are that with this pattern you don't have to edit instantiations of classes if edit the structure of the config of a class.
however in cases of removed params for example, you still have to change every time you make an instance with the removed param. Even if you add a value to the config you would have to add it every where you want to use it, on a change of name you can change a config param only in the functional option (the presumed advantage), but then the function name would be misleading about which option it changes.
In which real life examples would i receive benefits from this pattern?
Explanation of the pattern
The Functional Options pattern in Go is a design pattern used to configure objects in a flexible and extensible way. It involves defining a set of options as functions that modify the state of an object. This pattern is particularly useful when you have a constructor or initializer function with many optional parameters.