Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

"Thirty arguments should be enough for everybody"


I would have stopped with far fewer arguments.

When did you last call a function with more than 10 arguments, let alone 30?

Now I'm tempted to go through my code to find the max number of arguments I've used.


Right, but you're calling into a huge dynamically typed external app, and that may have entirely different conventions for reasons that make sense in that app (here excel).

Normally, 30 is crazy. But in excel? Who knows...

Also, too many isn't a problem, they're optional, so in practice you'll be treating this as a varargs; there's not much cost to having a few more args. I haven't used this function, but I suspect I'd rarely call in directly anyhow, instead making sane wrappers for various apis you actually care about which in turn call this internally, making the direct call details even less relevant.


I wouldn't, but if I'm passing something to an external command line tool with many options like ffmpeg, it might be over 10.

Anyone regularly calling a function with actually 10+ parameters is calling for a refactor though.


It depends on your domain. Some functions are effectively entire programs which can have huge amounts of configuration required. Many R packages expose a single function that can easily take that number of arguments


My maximum is 13, a function that creates an object with 13 properties.


I have definitely seen more than 10 arguments. Usually these are the god functions that no one wants to touch and keep adding one too many parameters as it is updated to support new features.


My heuristic: If you have 5 or more arguments, you should use a config object.


My heuristic is to not be dogmatic like that. A constructor for a triangle class may reasonably want to take 6 arguments (3 x- and 3 y-coordinates). In other cases, even four arguments might be better as a config object if those 4 are all very rarely used.


How many do you want?




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: