The Power of Naming
“A rose by any other name would smell as sweet”. I don’t often disagree with Shakespeare but in this case I might make an exception. As programmers the importance and difficulty of naming is something that is regularly emphasised.
A major pain point with naming is that our views on what makes a good name can be skewed by personal preferences and context. This was really hammered home to me today while looking at some Haskell in order to prepare a Zagaku on functional programming.
I distinctly remember when first learning Haskell having problems immediately grok-ing the
foldl function. This function takes a list and reduces it to a single value by applying a function with accumulator. As an example imagine we want to calculate the sum of a list of numbers:
sum xs = foldl (+) 0
-- example usage: sum [1, 4, 5]
The zero here is our initial accumulator value. The function we are applying is +. We will iterate through each element of the list adding to the accumulator to produce the final sum.
Note that in describing how
foldl works I have not used the word fold from the name once! Although after the fact I can see that fold is kind of appropriate my brain went instead to the word reduce. Interestingly the equivalent function in Elixir is named
Clearly for me the Elixir api is easier to understand but for others maybe it would be the other way around. What this does demonstrate is the conceptual power associated to words.
No wonder naming is one of the two hard things…