In 35 years of writing code, I have taken advantage of plenty of modules and libraries written by other people. It is part of what makes programming so fantastic. You never have to reinvent the wheel unless you really want to.
Despite that, I have never contributed a module myself. The excuse is that it would take a lot of time to make my modules available to others.
- Modifying for others' use - I'd need to rewrite parts of my modules to take into account factors that don't affect my narrow use of the module but need to be there for other people's use.
- More comprehensive unit tests - For the same reason as above. What I need for tests isn't what would be expected for more general use.
- More documentation - When you write documentation for modules you use yourself or within your own organization, you can make assumption about the knowledge level of the reader. It doesn't need to be as comprehensive as it would be for general use.
- Packaging - Modules need to go somewhere. For node.js, that's NPM. For Perl, it's CPAN. Each repository has its own requirements.
Despite those hurdles, I was determined to publish something. I published a small chunk of code I was using to validate user input. It's not very exciting and there are plenty of other modules that do something similar, but none of them do it quite how I would like.
Of the hurdles, #1 was not so bad. I like programming after all and adding a few more functions to make it complete was fun.
#2 was a little more painful and, although I hate to admit it, was useful since my more comprehensive tests uncovered some bugs. I probably should have been putting more into my unit tests anyway.
#3, the documentation, took the longest probably because I am a programmer and not a writer. I rewrote and expanded the documentation many times as I thought of ways it could be misunderstood or didn't describe something in enough detail.
#4, packaging the module, was actually pretty easy.
All in all, I probably spent three times as much time on the module than I would normally, just to benefit strangers if it even gets used at all. You might think that after that experience, I would never publish another module again, but that's not true.
In programming, it helps to invest time in the future. The better you write a module, the more time you save down the road. I have seen that payoff time and again. A quick bit of code is sometimes useful, but more often than not, comes back to haunt you as poor performance or bugs in the larger piece of software that relies on that code. However, a well-written module might take more time to develop upfront, but pays off repeatedly over the quick bit of code.
It's like a variation of the George Santayana quote, "Those who cannot remember the past are condemned to repeat it." Those who don't program for the future are doomed to repeat the past.
The module I just published actually has functions I wrote at least ten years ago in another programming language. I use some of those functions in almost everything I write. Any one of those functions isn't worth much, but the collection of functions, taken as a whole, allows me to develop code at twice the speed because I've already solved all those recurring time-consuming problems long ago and I'm just left with writing new code and solving new problems.
I don't regret the extra time I spent on this module. It know it will pay off down the road.