The article provides a practical look at reducing dependencies in Go libraries while offering a case study of dependency reduction in Huma. It gives reasons why reducing dependencies is beneficial such as reducing complexity, risk, build times and binary size. It explains how Go dependencies work and offers tips for reducing dependencies. It includes leveraging the Go standard library, creating a small functionalities instead of using a dependency or copying a section of a library you need. The article also mentions making the code more user-friendly by potentially moving Examples to a different package or directory. The end of the article presents a detailed analysis of Huma, the changes made, and the consequent results.
Here are a few general ideas around reducing dependencies in Go libraries:
Use The Standard Library: Use the Go standard library as much as possible. It's well-tested, well-documented, and has a lot of functionality built in. Sometimes a dependency is just a convenience wrapper around the standard library and isn't strictly necessary.
Build It Yourself: Sometimes it's easier to build a small piece of functionality yourself than to bring in a dependency. This can be especially true for small, well-defined pieces of functionality.
It's Okay To Copy: If you only need a small part of a library, consider copying the code into your own project. This can be a good idea if the library is large or has a lot of dependencies.
Reframe The Problem: Sometimes you can reframe the problem you're trying to solve to avoid a dependency. For example, if you're using a library to marshal to a specific format, you might be able to use a simpler format or a different approach to avoid the dependency.
Move Examples: It's common and helpful to include examples or demos in your codebase to make it easy for new users to adopt and experiment. However, these examples can sometimes bring in a lot of dependencies. Consider moving them to a separate package or directory to avoid adding unnecessary dependencies to your main package.
🤖 AI Summary
The article provides a practical look at reducing dependencies in Go libraries while offering a case study of dependency reduction in Huma. It gives reasons why reducing dependencies is beneficial such as reducing complexity, risk, build times and binary size. It explains how Go dependencies work and offers tips for reducing dependencies. It includes leveraging the Go standard library, creating a small functionalities instead of using a dependency or copying a section of a library you need. The article also mentions making the code more user-friendly by potentially moving Examples to a different package or directory. The end of the article presents a detailed analysis of Huma, the changes made, and the consequent results.
🖇️ Details
📝 Note
Here are a few general ideas around reducing dependencies in Go libraries:
Use The Standard Library: Use the Go standard library as much as possible. It's well-tested, well-documented, and has a lot of functionality built in. Sometimes a dependency is just a convenience wrapper around the standard library and isn't strictly necessary.
Build It Yourself: Sometimes it's easier to build a small piece of functionality yourself than to bring in a dependency. This can be especially true for small, well-defined pieces of functionality.
It's Okay To Copy: If you only need a small part of a library, consider copying the code into your own project. This can be a good idea if the library is large or has a lot of dependencies.
Reframe The Problem: Sometimes you can reframe the problem you're trying to solve to avoid a dependency. For example, if you're using a library to marshal to a specific format, you might be able to use a simpler format or a different approach to avoid the dependency.
Move Examples: It's common and helpful to include examples or demos in your codebase to make it easy for new users to adopt and experiment. However, these examples can sometimes bring in a lot of dependencies. Consider moving them to a separate package or directory to avoid adding unnecessary dependencies to your main package.