Structure vs Flexibility in Programming Languages
JavaLobby had linked to a very interesting blog post Java is my corral. Ruby is my open range by a Mr. Ted. The post is well worth reading. Here is an excerpt (emphasis mine):
| Quote: |
| Ruby is a wonderfully expressive and unrestrictive language, allowing you to perform gloriously clever feats of logic with such esoteric syntactic sugar. This makes it a pleasure for me to work with in my free time, on my pet projects, but the thought of introducing Ruby into my office chills me to the bone.At the office, I manage a team. Teams have to work together. They have to be on the same page. They have to drink the Kool-Aid, so to speak. They have to be able to touch each others code and play well together. Structure is very important to productivity in a team environment. When somebody tries to get clever, other members of the team get confused, and productivity flies out the window. Any tools that provide inherent structure for my team are welcomed with open arms. Java provides us with a lot of structure that Ruby cannot.
… Essentially, what makes Ruby so powerful and so liberating is also what makes it so dangerous in the wrong environment. Sometimes you need structure. Yes, you could achieve the same level of structure through documentation, training, process, testing, and peer review. But if the language enforces it for you out of the box, amen to that! It’s easier to herd the cats in a corral than on the open range. Java is my corral. Ruby is my open range. |
This is a very important insight. I have tried to say something like this about Lisp in Lisp is Poetry and Most Programmers want Prose but I don’t think I captured it quite as well as he has done. In hindsight, the essential point is that poetry permits a lot more individualized expression than prose. And it is almost blasphemous to think of “team poetry”.
Since my political philosophy inclines towards libertarianism, should I not favor individualized expression in code? Libertarianism stresses voluntary cooperation over coercion. It is hard to imagine producing an operating system or a web browser without voluntary cooperation among a lot of different programmers. One form of voluntary cooperation for a programmer is to write his/her code in a style that another programmer can understand and enhance - perhaps long after the original code was written. Part of that cooperation is code having a clear, widely-understood structure, or better still, program in a language that provides pre-built structure. Inevitably, such structure constrains flexibility, and the trick in language design is to make that trade-off intelligently.
Of course, it is possible to have that structure in a very individualized language like Lisp or Ruby - indeed almost every non-trivial program in Ruby will have some sort of structure. But requiring every programmer to invent that structure requires a programmer to be a language designer, sort of like requiring every driver to be an auto-mechanic. Even if that were possible, agreement is difficult to achieve on the “correct” structure between different programmers. And if a common structure were agreed upon at the beginning [say something like “Thou shall not add methods to existing classes in different files”], the effect would effectively be a custom dialect of Ruby or Lisp. A much more structured [and therefore less flexible] language like Java supplies that structure ahead of time. And it has the benefit that the structure is standard across the industry.
None of that should be controversial. Where it becomes controversial is when the flexible language enthusiasts start to say things that effectively mean “If you prefer to code in Java, you must have low IQ” - see for example “Blub Paradox”. There are a whole range of pragmatic reasons other than low IQ to prefer Java. This is not to say that Java programmers should not learn flexible languages - they should. But learning it for expanding your horizons and using it for work are two different animals. Ted captures this distinction so well.