Convention over configuration
When I used to be a programmer I was very hot on my own internal naming conventions and I was using my own variant of Hungarian notation long before I discovered there was such a thing. Writing systems by myself meant that I could enforce this internal consistency and make my life simpler. But I always longed for my conventions to be understood by the compiler. So, just by giving something a specific name the compiler would understand how to connect it to other code, without me needing to explicitly configure it.
I’ve now seen that in action in Ruby on Rails and I am well impressed. It even has a name – ‘convention over configuration’.
An example of how it works in Rails is simple enough. If you have a URL http://domain/x/y then Rails expects to invoke a method called y in a controller called x. So easy. But Rails does this in a few more places and is always looking to increase use further.
I find that this approach makes so many things easier that it should be considered as a general principle for software design, not just a quirk of Rails. The benefits that it brings are:
- You have to write much less code.
- Spotting a naming mistake is simpler because it stands out more.
- If you don’t know the name of a particular function then you have a lot more chance of making a successful guess.
- You have more chance of guessing how and where a function is used just from the name and context.
Brains are naturally pattern matching machines and I think convention over configuration appeals to them much more than a long XML file. I’m surprised I don’t see it being used much more often but I bet we will in the future.
Recent Comments