Synonyms Need Love Too

In the humane vs inhumane… err, I mean “minimal”… interface debatesJoey DeVilla has done a pretty nice summary of the discussion. synonyms don’t seem to get much respect. You would expect this from the minimalist crowd but many otherwise humane people seem to have little regard for method aliases. Here are a couple of examples.

Charles Miller

Having two otherwise equivalent ways to perform the same operation is bad user-interface design, and it’s bad library interface design, because the existence of the synonyms actually adds to your cognitive load by making you choose between them.

Joey DeVilla

I do have one complaint about the Ruby approach — method aliases. While it’s convenient for luring in programmers from other languages, I think it actually detracts from code readability to have two method names mean the same thing.

I think that synonyms are a valuable tool. Even if Charles Miller is correct that having multiple names for a method “adds to your cognitive load by making you choose between them” I still think that method aliases are great.

Any given piece of code is likely to be read a lot more than it will be written so it is far more important to optimize the reading of the code than the writing of the code. The fact that it takes the original author an extra tenth of a second to decide between length and size does not really concern me because every time I read the code and see that they choose size it indicates that the Array I am looking at is being treated more like a set or bag than an ordered list. Expressing the intent of the code effectively is worth the slight additional cognitive load for the original author.

I would argue that synonyms reduce the overall complexity. From an interface consumers point of view an alias is just another behavior of the interface, the fact that it is exactly the same as some other method is an implementation detail that should be of little or no interest. From the interface producers point of view they are an efficient and low cost way to provide a nuanced variety of similar behaviors. Humans are well suited to handling multiple words with similar meanings. No one argues that we should rid english of it’s synonyms, because while synonyms increase the number of words one must know they also increase the expressiveness of the language

If you think of method aliasing as an implementation detail to make the implementation of certain methods less costly (and that is exactly how you should think about it), the argument against method aliases sounds pretty much like the argument for minimal interfaces. That the clients don’t really need those extra methods because they can affect the same outcome using a more limited set of behaviors. While this is true it misses the point. Programming is, first and foremost, about is about expressing the intent of a program to other humans, not performing a mathematical reduction. Humane interfaces allow interface consumers to be written in a more expressive and intentional way.

{Update: Fixed main link to point to Martin Fowler’s bliki page like I had meant to do the first time.}

Comments 2

  1. Akshay wrote:

    +1

    This is by far the best comment, aside from that of Martin himself, that I have read in this debate!

    It just makes sense to treat computer programming languages as a languages that we humans speak between ourselves. That would be natural selection, working to to make things a lot more ‘usable’, as compared to making things more mathematically correct.

    Posted 28 Dec 2005 at 8:26 am
  2. truth machine wrote:

    Reducing the number of methods in Array would mean reducing the number of things I can do to x = [], which would be stupid. Array isn’t a container class, it provides a user-facing facility in a scripting language. Martin Fowler picked a terrible example and made a ridiculous comparison.

    Posted 05 Aug 2007 at 12:03 am