Frequently there simply isn't a good name as FP tends to heavily rely on generic algorithms. For instance, consider a definition of map (in say Haskell):
map _ [] = []
map f (x:xs) = f x : map f xs
f is a normal variable name in math meaning a function. x is a normal variable in math meaning an argument. xs is therefore just more arguments we're going to apply f to. In this case, the conventions are straightforward.
There seems to be very few people who find the following easier to read (note there are obviously names somewhere in between so this is sort of a strawman):
map _ [] = []
map function (someThing:restOfList) = function someThing : map function restOfList
Unfortunately, the habit of short names leaks into situations where there actually are decent names to be had.
The other reason is that at least in a heavily typed languages like Haskell, the type signature is often very indicative of what the function actually does.
For generic functions it may indeed be (a -> b -> c) -> a -> b -> c which translates to just f, x, y because there is nothing more concrete to be said about those arguments. But even when it's something more specific such as parseArgv :: [Text] -> Parser a -> Config, you don't really need more than one-letter argument names to figure out what's happening.
I think it may be a culture coming from the closeness to theoretical computer science, who in turn inherited it from mathematics.
My guess is that code written early in the history of software suffered the same problem, when the field was more tightly linked to the university. Then a cultural shift happened, likely due to computers getting more ram, where we as an industry started to have longer and more descriptive naming.
I am also going to guess that precisely because the more academic functional programming languages such as lisp or ML didn't get adopted by the industry in as big a scale as the imperative ones, they never picked up this new trend; instead staying with the older convention of short variable names.
12
u/kindofdynamite May 25 '17
As a newcomer to FP, one of the biggest hurdles has been trying to decipher one letter variables, imports without a namespace and general terse code.
It seems to me that there is less of a focus on code readability ("plain english") in FP languages.
Why is terse code so common in Clojure/Haskell/et all? Is there something I'm missing that will cause me to "see the light"?