[KongchangAI]
· 2 min read· 1,226 words

Go Proverbs: A Little Copying Is Better Than a Little Dependency

Go Proverbs: A Little Copying Is Better Than a Little Dependency

The Go proverb "A little copying is better than a little dependency" reminds developers to weigh the long-term costs of dependencies against the risks of copying.

The article discusses the Go community proverb "A little copying is better than a little dependency," which recently sparked discussion on Hacker News after Simon Willison cited it. It explains that the proverb does not encourage abusing copying but reminds developers to weigh the long-term burdens of external dependencies, such as version management, security vulnerabilities, compatibility, and build size. Copying applies only to simple, independent functionality that does not change often; complex or security-sensitive functionality should still rely on mature libraries. Community discussion shows divergence: some argue that modern package management tools have lowered dependency costs, while others emphasize that copying may lead to the spread of errors. Overall, the proverb offers a thinking framework based on scenario-specific trade-offs and reflects Go's design philosophy of emphasizing simplicity and maintainability.

In software development, we often face a choice: should we pull in a dependency library, or just copy a small piece of code? The Go proverb "A little copying is better than a little dependency" offers a concise yet profound answer. This proverb originates from the Go community, was recently cited by well-known developer Simon Willison, and sparked discussion on Hacker News.

Go proverb citation

The meaning and background of the proverb

"A little copying is better than a little dependency" literally means "a small amount of copying is better than a small dependency." It does not encourage abusing copy-paste; rather, it reminds developers to weigh the complexity and maintenance costs that external dependencies bring. Go's design philosophy emphasizes simplicity and maintainability, and this proverb embodies that philosophy. The Go Proverbs website collects many similar maxims intended to guide developers in writing clear, efficient Go code.

According to the Go Proverbs website and discussions on Hacker News, the core of this proverb is that dependencies introduce long-term burdens such as version management, security vulnerabilities, and compatibility issues, whereas copying a small piece of code increases code volume but avoids these hidden costs. Especially when the required functionality is very simple, copying may be the more pragmatic choice.

Go Proverbs is a series of maxims summarized by Go core team member Rob Pike in his famous 2015 GopherCon talk "Go Proverbs," later organized by the community into the Go Proverbs website. These proverbs are not language specifications but rather cultural consensus formed by the Go community through long-term engineering practice, used to guide how to write idiomatic, maintainable Go code. Besides "A little copying is better than a little dependency" and "Clear is better than clever" mentioned in this article, other well-known entries include "Don't communicate by sharing memory, share memory by communicating," "Errors are values," and "Simplicity is complicated." Together they reflect the Go language's pursuit of simplicity, readability, and pragmatism, and are often borrowed by other language communities to discuss engineering philosophy.

Why a small dependency can become a burden

Introducing a dependency, even a small library, means binding your project's fate to external maintainers. You need to track its updates, handle security patches, and respond to API changes. If the dependency is no longer maintained or introduces incompatible changes, your project may find itself in trouble. Additionally, dependencies increase build time and binary size, which is especially noticeable in a compiled language like Go.

In the Hacker News discussion, some developers pointed out that many projects become bloated due to excessive dependencies, while some simple utility functions can completely avoid dependencies by copying a few dozen lines of code. This view resonated with many.

In Go, the burden of dependencies is reflected in language-specific ways. Go uses static compilation, and all dependencies are linked into the final binary at build time, so each additional dependency directly increases artifact size and build time. Since Go Modules were introduced in version 1.11 and enabled by default in version 1.16, dependencies' versions and checksums are managed through go.mod and go.sum, which has improved version locking and reproducible builds to some extent but has not eliminated the long-term maintenance cost of dependencies. In addition, Go's "Minimal Version Selection" (MVS) mechanism selects the lowest version that satisfies all module requirements when resolving dependencies. Although this reduces version conflicts, it also means that upgrading indirect dependencies requires explicit action. The Go community also provides tools such as go mod graph and go mod why to help developers inspect the dependency tree, identify, and trim unnecessary dependencies.

When copying applies and its risks

Of course, the proverb does not encourage copying in all cases. It emphasizes the contrast between "a little copying" and "a little dependency." When the required functionality is complex, involves security-sensitive operations, or requires long-term maintenance, depending on a mature library is usually the better choice. The risks of copying lie in code duplication, the potential introduction of bugs, and difficulties in subsequent updates. Therefore, the key to the decision is evaluating the complexity of the functionality, the stability of the dependency, and the team's maintenance capacity.

When Simon Willison cited this proverb, he did not add much commentary, but the discussion on Hacker News presented differing views. Some developers believe that modern package management tools have reduced the cost of dependencies, while copying code may lead to the spread of errors. This divergence reflects the art of trade-offs in engineering practice.

When evaluating "copy or depend," a practical reference is the size of the dependency's transitive closure. A seemingly lightweight library may indirectly introduce dozens of other modules through go.mod, thereby enlarging the supply chain attack surface and maintenance burden. The frequent supply chain security incidents in the industry in recent years (such as malicious packages in the npm ecosystem and dependency confusion attacks) have made this consideration even more important. At the same time, license compliance should be noted when copying code: directly copying third-party code snippets may be subject to their open-source licenses, and copyright notices must be retained or license compatibility confirmed. Within a team, copied code should be incorporated into the project's testing and static analysis processes, and tools such as go vet and staticcheck can help reduce the risk of introducing hidden bugs.

Practical advice for developers

For day-to-day development, the following principles can be followed: for simple, independent functionality that does not change often, consider copying directly; for complex, core, or security-related functionality, prioritize well-maintained dependencies. At the same time, regardless of which approach is chosen, clear documentation and test coverage should be maintained. The Go proverb provides a thinking framework, not an absolute rule.

Community reaction and takeaways

This proverb sparked discussion about dependency management on Hacker News. Some developers shared their experiences of being burned by dependency issues, while others argued that copying code may cause inconsistency in team collaboration. Overall, the community generally agrees that trade-offs must be made according to specific scenarios.

Other proverbs on the Go Proverbs website similarly emphasize simplicity and readability, such as "Clear is better than clever." Together these maxims form the cultural cornerstone of the Go community and offer lessons for developers in any language.

In the era of microservices and cloud native, dependency management has become more complex, and this old proverb reminds us: the simplest solution is often the most effective.

One-line Summary

A Go proverb, "A little copying is better than a little dependency," reminds developers to weigh the long-term costs of dependencies against the risks of copying.

Paragraph Summary

The article centers on the Go community proverb "A little copying is better than a little dependency," which recently sparked discussion on Hacker News after being cited by Simon Willison. It explains the meaning: it does not encourage abusing copying but reminds developers to weigh the long-term burdens of external dependencies, such as version management, security vulnerabilities, compatibility, and build size. Copying applies only to simple, independent functionality that does not change often; complex or security-sensitive functionality should still rely on mature libraries. Community discussion shows divergence, with some arguing that modern package management tools have lowered dependency costs and others emphasizing that copying may lead to the spread of errors. Overall, the proverb provides a thinking framework based on scenario-specific trade-offs and reflects Go's design philosophy of emphasizing simplicity and maintainability.

#Go proverb#dependency management#code copying#Go language#Hacker News#supply chain security
Share:

Related articles