Language Design: Once and Only Once?

ziggy on 2003-05-16T17:39:29

Python's irreverent motto, "There's Only One Way To Do It" is simply a jab at TMTOWTDI. In reality, Guido admits that in some cases, TMTOWTDI works -- especially at the lower layers of a language. A better statement of the Python philosophy is that higher level constructs benefit from using the one, simple, obvious way to do it.

Pragmatic Programming and The Practice of Programming both promote the principle of "once and only once" (OOO), or "don't repeat yourself" (DRY). This is a great piece of advice when writing programs, but doesn't really apply when designing a language. Larry has proven this time and time again with Perl, yet people still like to misapply the OOO principle to the domain of language design.

Here's a case in point, courtesy of David Megginson via the xml-dev list:

 > W3C has violated a first-order principle of language design; that
 > there should only be one way of doing something, such that everyone
 > ought to devise the 'same' program to solve the 'same' problem.


 int x = 0;
 while (x < 10) {
   printf("hello\n");
   x++;
 }

 int x;
 x = 0;
 do {
   printf("hello\n");
 } while (x++ < 10);

 int x;
 for (x = 0; x < 10; x++)
   printf("hello\n");

 /* etc. */

It's clearly a principle rarely put into practice (I won't even start on the Common LISP looping constructions).


Why OOO doesn't apply

barries on 2003-05-16T18:36:38

People seem to think that, for example, one looping construct should suffice for all needs. They don't realize that you want different constructs for different needs.

Different looping constructs may be used to acheive the same end, yet their means may differ; there are often memory, performance, or maintainability (ie readability/debugability/ease of alteration, etc) tradeoffs involved.

Even though TIMTOWTDI may seem profligate, in reality there are often subtleties at play that are not manifest in the source text of the program.

Personally, I think perl5 doesn't have enough looping constructs...

- Barrie

Re:Why OOO doesn't apply

ziggy on 2003-05-16T19:02:48

People seem to think that, for example, one looping construct should suffice for all needs. They don't realize that you want different constructs for different needs.
Yep. Someone said later in that thread that OOO is fundementally wrong at the language design level, using Scheme as an example. Specifically, the idea that you do not need iteration whatsoever, since all iteration can be expressed in terms of recursive functions.

Don't even get me started on the fallacy that the only data structure you need is a linked list. For all of their reductionalism, Scheme folks sure do love arrays, vectors and hash tables. :-)

In the realm of XML vocabulary design, I'm surprised no one has noticed the Orwellian nature of OOO...