DEV Community

Using functional options instead of method chaining in Go

Jon Calhoun on August 10, 2017

This post was original posted at calhoun.io In Java, it is pretty common to see libraries that use method chaining (aka the builder pattern) to ...
Collapse
 
bgadrian profile image
Adrian B.G.

I like that you offer an alternative, I loved chaining in JS but I don't think they belong to a Go code.

Offtopic: I am surprised that ORM's are still used nowdays. So many restrictions, is like a framework over a framework that tells you how to do it. I hit so many problems over the years that I don't get it how is still alive. The only benefit it offers will most probably fail and I never saw a team use it (switch to other SQL database).

Especially now when you have so many data storage types accessible and services (loggers, graph databases, noSQL documents, event sourcing).
Especially in a language where you do not have Objects! from ORM

Collapse
 
foresthoffman profile image
Forest Hoffman

Well said Jon! I use the functional approach to handle mocking methods that handle API requests, in my tests. It may take more effort up front, but the long term rewards are very real.