When to use a module vs. writing own code? At the risk of asking a "too open ended question" I'm giving it a try:

I'm running into more and more situations where I have to decide to either use a module that does a lot more than what I need or just writing my own code or template mod.

For example, the password policy has features that I need, but also has a lot that I don't. The 47kb zip file size tells me that it's a lot of code for my small problem. I implemented my own password policy with less than 20 lines of code in a hook.

I'm trying to limit the total amount of modules installed to a max of around 100. However, since signups don't happen that frequently this module probably won't affect the overall site performance.

Does anyone have specific recommendations on when to use a module vs. writing own code? Especially when better runtime performance and reduced overall complexity are the main goals.
The way I go about deciding whether to use a module or write my own code is roughly the following:


If the functionality I need can be written with a couple of lines of code I don't even start looking for a module to do it. Using a module for every little thing often gets you a good portion of extra code and other data that you don't need. All the unnecessary extras could:


negatively affect performance
make the site more complex and harder to maintain
result in more bugs

If there would be a considerable amount of code to write I'll look for possibly existing modules to make the task easier. Good reasons to use a existing module in my book:


it fits the requirements fairly well: using the module (and altering it with hooks, adding extra functionality via a custom module where needed) to get exactly what's needed is easier/faster than writing everything from scratch.
the site administrator needs to be able to change specific settings via the GUI and the module already offers that.