Dysfunctional Options Pattern in Go
The Functional Options Pattern in Go is compared to the Dysfunctional Options Pattern for configuring APIs. The latter, resembling the builder pattern, offers a simpler and faster alternative with method chaining.
Read original articleThe article discusses the Functional Options Pattern in Go, highlighting its benefits and drawbacks in configuring APIs. It explains how the pattern works, the challenges it poses in maintaining public APIs, and the need for workarounds due to Go's lack of default function arguments. The Dysfunctional Options Pattern is introduced as a simplified alternative, utilizing method chaining for configuring optional attributes without excessive indirection. A comparison between the two patterns shows the Dysfunctional Options Pattern to be significantly faster. The article concludes by mentioning the similarity of the Dysfunctional Options Pattern to the builder pattern in object-oriented languages, emphasizing its lightweight nature and efficiency. The Dysfunctional Options Pattern offers a more straightforward approach to configuring APIs in Go, addressing some of the complexities associated with the Functional Options Pattern.
Related
Interface Upgrades in Go (2014)
The article delves into Go's interface upgrades, showcasing their role in encapsulation and decoupling. It emphasizes optimizing performance through wider interface casting, with examples from io and net/http libraries. It warns about complexities and advises cautious usage.
Common Interface Mistakes in Go
The article delves into interface mistakes in Go programming, stressing understanding of behavior-driven, concise interfaces. It warns against excessive, non-specific interfaces and offers guidance from industry experts for improvement.
I Probably Hate Writing Code in Your Favorite Language
The author critiques popular programming languages like Python and Java, favoring Elixir and Haskell for immutability and functional programming benefits. They emphasize personal language preferences for hobby projects, not sparking conflict.
Synchronous Core, Asynchronous Shell
A software architecture concept, "Synchronous Core, Asynchronous Shell," combines functional and imperative programming for clarity and testing. Rust faces challenges integrating synchronous and asynchronous parts, prompting suggestions for a similar approach.
First impressions of Go 1.23's range-over-func feature
The author shares positive experiences with Go 1.23's range-over-func feature, initially skeptical but finding it easy to use. Successful adaptation in their project Kivik disproved initial concerns, highlighting benefits for codebase improvement.
To solve this problem, a language have to disallow null/nil as a bottom type and provide nice syntax to initialize types with optional types.
[1]: https://geeklaunch.io/blog/make-invalid-states-unrepresentab...
NewObject(
required1,
required2,
&ObjectOptions{
Option1: “foo”,
// Option2 skipped
Option3: “bar”,
})
I can see the merits of both (two structs is tedious, for sure), but I wanted to share in case others had thoughts or alternate ideas! func (c *Config) WithFizz(...) {...}
func (c *Config) WithBazz(...) {...}
Related
Interface Upgrades in Go (2014)
The article delves into Go's interface upgrades, showcasing their role in encapsulation and decoupling. It emphasizes optimizing performance through wider interface casting, with examples from io and net/http libraries. It warns about complexities and advises cautious usage.
Common Interface Mistakes in Go
The article delves into interface mistakes in Go programming, stressing understanding of behavior-driven, concise interfaces. It warns against excessive, non-specific interfaces and offers guidance from industry experts for improvement.
I Probably Hate Writing Code in Your Favorite Language
The author critiques popular programming languages like Python and Java, favoring Elixir and Haskell for immutability and functional programming benefits. They emphasize personal language preferences for hobby projects, not sparking conflict.
Synchronous Core, Asynchronous Shell
A software architecture concept, "Synchronous Core, Asynchronous Shell," combines functional and imperative programming for clarity and testing. Rust faces challenges integrating synchronous and asynchronous parts, prompting suggestions for a similar approach.
First impressions of Go 1.23's range-over-func feature
The author shares positive experiences with Go 1.23's range-over-func feature, initially skeptical but finding it easy to use. Successful adaptation in their project Kivik disproved initial concerns, highlighting benefits for codebase improvement.