這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。
A topic that has weighed on my mind recently is the dichotomy of frameworks vs. libraries in the Go community.
Is the prevailing stance against complex frameworks a rejection of this purported labour saving automation, or an enlightened position that has weighed the pro’s and cons and found the costs of a framework based approached outweighs the benefits ?
A framework calls your code, you call a library.
If you want to call net/http
a framework under that definition, go for it. You can win that argument, but don’t let it fool you into thinking that this is the exception that proves the rule.
Frameworks, if they communicate with your code in simple terms are tone deaf. Unable to express the intent that they have been asked to pass on to you, they force you to glean meaning from their obscure requests via processes akin to psychic divination. Alternatively frameworks subject you to an increasingly bureaucratic interaction of call-backs, configuration settings, and rigid parameters.
By comparison, the best libraries are the ones with loose coupling, powered by the pervasive nature of Go’s interface. These simple abstractions allow you to compose your own grammar specialised to the task at hand.
Writing programs is fundamentally about interpreting data. If you outsource that interpreter to someone else, you have artificially constrained the vocabulary with which to describe and interact with that data.
Given these two choices, I am happy to stand with the camp who desire simple composable types and packages.
Related posts:
- Ice cream makers and data races
- Accidental method value
- Using // +build to switch between debug and release builds
- Functional options for friendly APIs