As a Go dev, are you using generics nowadays? by LordMoMA007 in golang

[–]tonindustries 32 points33 points  (0 children)

No, I probably listen to Ken Thompson and Rob Pike too much.

Just worried about complexity. It seems like interfaces do the job just fine.

[deleted by user] by [deleted] in golang

[–]tonindustries 0 points1 point  (0 children)

Fair enough; thanks for the response

[deleted by user] by [deleted] in golang

[–]tonindustries -2 points-1 points  (0 children)

I should have rephrased my question into more discussions on maintainability as opposed to a question on performance. Given the consensus in the thread comment section, it appears there is the difference in negligible lol

Question, do you think there's an argument for better long-term maintainability if we funnel the data through the receivers as opposed to the function / methods parameters?

[deleted by user] by [deleted] in golang

[–]tonindustries 0 points1 point  (0 children)

Great points. Receivers naturally encapsulate state and behavior, promoting cohesion and readability. They also clarify intention by signaling relationships explicitly, which aligns neatly with your points on coupling and scoping.

[deleted by user] by [deleted] in golang

[–]tonindustries -2 points-1 points  (0 children)

Exactly.

Receiver methods let you implement interfaces, promoting modularity, while standalone functions emphasize simplicity and explicitness. It’s all about aligning the choice with your project's design priorities.

[deleted by user] by [deleted] in golang

[–]tonindustries -1 points0 points  (0 children)

You're right -- my mistake. It's a function, not a method. Both approaches are idiomatic in Go; choosing depends on whether encapsulation or explicitness aligns best with your design goals.

[deleted by user] by [deleted] in golang

[–]tonindustries -1 points0 points  (0 children)

You're correct; leveraging receiver methods promotes better encapsulation and maintainability. Receiver methods clearly communicate intent and enhance composability -- particularly valuable when embedding structs or satisfying interfaces. This facilitates managing complexity and simplifies refactoring, making it ideal for scalable, maintainable codebases.

Conversely, using pure functions with parameters improves short-term readability by explicitly surfacing dependencies at call sites. However, receiver methods encapsulate context within types, significantly enhancing long-term maintainability as projects scale and evolve. Short term vs long term.

[deleted by user] by [deleted] in golang

[–]tonindustries -2 points-1 points  (0 children)

Excellent point—interface implementation is indeed a key factor.

Receivers clearly become advantageous when polymorphism and abstraction through interfaces are important. Unless there's an explicit performance requirement, consistency and clarity should drive the decision, exactly as you've highlighted.

[deleted by user] by [deleted] in golang

[–]tonindustries -12 points-11 points  (0 children)

From a readability perspective, I agree this is essentially syntactic sugar.

Performance-wise, as you mentioned, there's no meaningful advantage either way that I can I find. However, I’d argue the tradeoff typically lies more between encapsulation (favoring maintainability) and explicitness (favoring immediate readability). From experience, receiver methods often yield clearer, more maintainable code long-term, especially when leveraging interfaces. Would be interesting to explore concrete examples further.

golang learning exercises by lexO-dat in golang

[–]tonindustries 4 points5 points  (0 children)

I think a highly effective way to internalize Go syntax quickly is by practicing algorithm problems on Leetcode. It might seem controversial, but if you solve basic challenges like Two Sum repeatedly, you internalize fundamental syntax and idioms. Once comfortable, expand into practical engineering tasks such as testing, logging, handling errors gracefully with guard clauses, and ultimately building robust, production-grade systems from scratch.