Blog Post

Functional Contagion Size

While there is some disagreement on the best way to use functions, whether you do almost everything in small functions or use more monolithic functions, both have their advantages. More functions can make it harder to follow the code and can make things confusing because the code won’t be as linear and will jump around from location to location wherever the function is defined. If something’s wrong, it’s confined to a rather small section of code. Using more monolithic functions can make it easier to find the function the problem is in, but that is often an extensive section of code.

I’d recommend a middle approach. When you start out, have your functions do one thing at a time and anything you do multiple times. They’re easier to debug (figure out where the code went wrong/why it’s not doing what you intend), and, once you have some practice, you’ll get a handle on when you need a function or not, and what makes sense to you.