DEV Community

Discussion on: how many parameters?

Collapse
 
daveparr profile image
Dave Parr

It seems that maybe if those functions with large numbers of arguments exist, it's because of 2 things:

1) the function is going to be called a lot, and should be simple. A single call, not a chain of five calls that are mostly the same.
2) tweaking the operation of the function is complicated, but the defaults are mostly sane. If there is a large amount of ways to customise the function, but practically only a few of them will be needed to be tweaked in a single call, then it seems to make sense.

Collapse
 
sckott profile image
Scott Chamberlain

Sorry for long delay in responding, i guess dev.to doesn't do email notifications? Makes sense. Curious, do you try to keep your number of parameters small or do you not really think about it?

Collapse
 
daveparr profile image
Dave Parr • Edited

No sweat. I tend to be able to keep the parameters small as a by product of consistent refactoring. I also have the happy by product of being able to work on very small focused projects. Nothing I write tends to have more than tens of programmers use it or multiple use cases :)

Thread Thread
 
sckott profile image
Scott Chamberlain

Right, and I imagine you can change the function interfaces more easily if there's a small set of users

Thread Thread
 
daveparr profile image
Dave Parr

Absolutely.