4 ms·
I think there is a point to "less function arguments is better". A good example is difficult to come up with, but the basic idea is usually a function with 4+
by ParetoOptimal 5y ago
I think there is a point to "less function arguments is better".
A good example is difficult to come up with, but the basic idea is usually a function with 4+ args can either be split into two functions or args can be turned into a sensible data type.
Here's an okay example:
areaIrregOctagon :: Int -> Int -> Int -> Int -> Int -> Int -> Int -> Int -> Int
type Octagon = (Int,Int,Int,Int,Int,Int,Int,Int)
areaIrregOctagon :: Octagon -> Int
- Silhouette 5y agoI think there is a point to "less function arguments is better". I think the real problem in your example isn't the number of arguments but passing separate values that logically belong together as a single coherent piece of data. You could make the same argument about passing a Point parameter for a 2D position instead of a pair of separate co-ordinates (and the argument would still be just as valid if you did). Of course that isn't what Martin said anyway. He said the ideal number of arguments is zero, which is absurd. The ideal number of arguments is however many you need to pass in the relevant information for your function to do its job, hopefully in a representation that is clear and easy to work with. If he'd suggested that this will often be a small number because there are often more effective ways to represent the data in functions taking many arguments (and look, here are some examples of those ways) I might well have agreed with him.