TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Layered Design in Go

141 pointsby misonic29 days ago

8 comments

nickcw28 days ago
In my opinion, not allowing circular dependencies is a great design choice for building large programs. It forces you to separate your concerns properly.<p>If you get a circular dependency something is wrong with your design and the article does a good job on how to fix them.<p>I sometimes use function pointers which other packages override to fix circular dependencies which I don&#x27;t think was mentioned in the article.<p>My only wish is that the go compiler gave more helpful output when you make a circular dependency. Currently it gives a list of all the packages involved in the loop which can be quite long, though generally it is the last thing you changed which caused the problem.
评论 #43743850 未加载
评论 #43744002 未加载
评论 #43744288 未加载
评论 #43745211 未加载
breadchris28 days ago
great blog post! also this website has a lot of incredible posts, if you like learning about functional programming, you should check out<p><a href="https:&#x2F;&#x2F;jerf.org&#x2F;iri&#x2F;blogbooks&#x2F;functional-programming-lessons-in-imperative-code&#x2F;" rel="nofollow">https:&#x2F;&#x2F;jerf.org&#x2F;iri&#x2F;blogbooks&#x2F;functional-programming-lesson...</a>
shizcakes28 days ago
One bonus technique related to the “move to a third package” advice: generating many of your model structures (SQL, Protobuf, graphql, etc) allows you to set up obvious directionality between generated layers and to provide all generated code as “base packages” to your application code, which then composes everything together.<p>Prior to this technique we often had “models importing models circularly” as an issue but that’s entirely disappeared due to the introduction of the structural additional layer.
pjmlp28 days ago
Looks like I am reading a book about Yourdon structured method.
评论 #43743075 未加载
rapidlua28 days ago
&gt; Packages may not circularly reference each other.<p>Actually possible with go:linkname.
评论 #43743039 未加载
__s28 days ago
Kind of reminds me of the concept of spheres in randomizers
darioush28 days ago
A funny quirk about golang is you cannot have circular dependencies at the package level, but you can have circular dependencies in go.mod<p>The tl;dr is don&#x27;t do that either.
评论 #43760927 未加载
kubb28 days ago
Cool description of how jerf thinks about packages and how he deals with circular dependencies!