Does the rigidity of clear interfaces mean that flexible code must be ugly? I'll use Java and Perl as respective examples.
Clarification: it's not that code being messy makes it flexible; but that code being flexible makes it messy.
Clarification: "flexibility" almost has a different meaning in exploratory code vs older code. Perhaps "raw flexibility" vs. "compatible flexibility"? I'm talking about "raw flexibility" - thanks to Mario Ortegón
Java
Java pays much attention to compatibility: the content of the language and standard libraries are steeped in OO design, and it even has the extensively used keyword interface; the JVM and language themselves have specifications of external behaviour. Sun has a history of clear and open specifications (e.g NFS).
Designing a clear interface that works well is very difficult to do - but when done right, the result can be very clear. A specification (including an OO design) is by its nature rigid - any flexibility it has is rigidly circumscribed by the spec.
The result is that if you correctly predicted the the degrees of freedom needed, the design has great clarity and precision - it will actually act as a guide towards the right questions to ask, and give you useful terms with which to think about the problem.
Perl
One spirit of Perl is "there's more than one way to do it". and the language syntax itself has evolved considerably over the years (including incompatible changes). Like Java, this attitude carries on into programs written in the language.
Although one can write Perl to clear interfaces, it isn't enforced, and often isn't done. This can result is "write only" code - but if you understand it, you can change it in arbitrary ways. That is, it is ugly but flexible - perhaps my definition of ugly needs to change?
Apparently mjd said of Higher Order Perl that he couldn't have written it with test-driven development, because it would lack the flexibility he needed. I hope I'm not putting words in his mouth here, but I think the same would apply to interfaces and specifications (because that is something that TDD enforces).
It seems to me that Java code tends to be neat but rigid; and Perl code tends to be messy but flexible. Java favors upfront design; and Perl favors rapid prototyping.
In my code (Java) I keep facing a choice between neat vs. flexible. For example, I compared a Visitor pattern against one big function of cascading if's.
The latter is ugly, but it is many times easier to add parameters to the recursive method calls (this is only a problem if you need that degree of flexibility (which I find I do in exploratory prototyping).
Clarification: The visitor pattern refactors the cascading-if's as method overriding, at the cost of defining and calling those methods, one class per if, so that an added argument must be added to all those methods and all the calls of them, in all those classes. I coded these designs and counted how many places needed arguments added: 9 places for Visitor (across different files); 3 places for cascading-ifs (all in one file). The cascading-ifs solution is much easier to modify, even though it's ugly.
This question isn't about Java and Perl - I'm just using them as illustrative examples to make the question more concrete and definite, and hopefully easier to consider.
Is arbitrarily flexible code necessarily messy?