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.

Golang – Pull all the structs out???

2 pointsby brianvoeover 2 years ago
Something I am dealing with at work right now is the idea of pulling all the main structs of our packages into a single package to alleviate(not get rid of) cyclical import issue.<p>The issue I have with this is that when we pull all of the main structs from there packages you disconnect the logic from data structs that us it. Plus remove certain core functionality like more advance logic that would go into a method that cant be simple getters and setters in that struct package.<p>The other issue I contend with is that in doing so it just doesn&#x27;t &quot;feel&quot; like idiomatic Go. For the many years I have been using Go both core package and open source ones(big and small) and I just don&#x27;t see many cases where packages completely pull their main structs out. I also try to think about what more advanced developers would do like Rob Pike(https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=PAAkCSZUG1c&amp;t=568s), Brad Fitzpatrick, Russ Cox, I assume they wouldn&#x27;t think this is a good idea. Presenting various example and quotes from core Go developers didn&#x27;t seem to sway them.<p>Does anyone have experience in this area? Has anyone pulled their main structs out and have been better off for it? Has anyone pulled them out and then realized it was bad and moved them all back?<p>What are your thought?

3 comments

orbzover 2 years ago
This is a horrible idea that will eventually make the situation of cyclical dependencies even worse.<p>Hitting cyclical dependencies is an indication that the code base is not being built in a composable fashion with layers depending on other layers. This is usually solved with more packages of more focused independent functionality rather than less packages of less functionality.
评论 #33045008 未加载
评论 #33041470 未加载
daviddever23boxover 2 years ago
It might be worth hiring an experienced Go developer, even as an independent contractor, to review your codebase as well as to help you lint your code.
metadatover 2 years ago
Program against interfaces instead of concrete classes (i.e. structs). The coupling needs to be loosened.
评论 #33041502 未加载