Eliminating a tiny OSS dependency #
This may be of limited applicability. As more cases are discovered, this maturity level will increase.
There are many ideas to avoid reinventing the wheel, On the other hand, we must also pay attention to external code that can have a significant impact. If the provided code’s scope is very limited, it might be better to contain it internally rather than depending on an external source.
Implementing a left-pad function can be done as shown below:
def leftpad(string, length, char = ' ') string.rjust(length, String(char)) end
- Exercise 1: Implement the left-pad function that takes the string, length, and character to pad with. The default character should be a space.
- Exercise 2: Consider a scenario where multiple small external dependencies exist in a project. Identify a small utility function that can replace one such dependency and implement it.
Checklist for Further Learning #
- Have you considered the trade-offs between using an external dependency and implementing the code yourself?
- How might this pattern of eliminating tiny dependencies affect the maintainability of the code?
- What principles or guidelines can be used to decide when to replace a tiny external dependency with an internal implementation?