1

I have discovered that reducing the arity of functions in my code to zero or one improves their non-functional characteristics significantly, such as testability, maintainability and their composability.

This must have been identified elsewhere - does this approach have a name?

52d6c6af
  • 730
  • 3
  • 14

1 Answers1

3

Yes, an arity of one is a property of a mathematical functions. The case arity=0 is really arity=1 with the parameter of void or unit. And 1 input is not the only property, but perhaps lends itself to some of the others (e.g. no side effects). Maybe your functions tend to conform to the definition of Mathematical functions?

Here is a good article on mathematical functions (the basis for functional programming) with their benefits and drawbacks in the context of programming. Here is an excerpt.

As you can see from the diagrams, there is always exactly one input and one output for a mathematical function. This is true for functional programming languages as well, although it may not be obvious when you first use them.

For people scratching their heads right now, in practice in functional programming, you don't really code only single-parameter functions and nothing else. Through math trickery, you can show that an N-parameter function can be changed into N single-parameter functions with currying. (So, the compiler does that for you.)

Maintainability probably has more to do with following DRY and SRP, since your functions are broken down into individual operations.

Composability is one of the primary strengths of math functions. I won't take time to go into all that f(g(x)) stuff here. And I'm probably not as good at explaining it as others, so here's another link on that subject.

Testability is also really high with math functions since they lack side effects which have to be accounted for. By definition they also give repeatable results.

Kasey Speakman
  • 4,341
  • 19
  • 26