Is the rigidity of intuitive interfaces that flexible code should be ugly? I will use Java and Perl as relevant examples.
Clarification: this is not the code that is confused, makes it flexible; but this code is flexible, makes it dirty.
Clarification: "flexibility" almost has a different meaning in search code versus old code. Perhaps raw flexibility and compatible flexibility? I'm talking about "raw flexibility" - thanks to Mario Ortegon
Java
Java pays great attention to compatibility: the content of the language and standard libraries is saturated with the OO design and even has a widely used keyword interface; The JVM and the language itself have characteristics of external behavior. Sun has a history of clear and open specifications (such as NFS).
Developing a clear interface that works well is very difficult to do, but when done correctly, the result can be very clear. The specification (including the design of OO) is rigid in nature - any flexibility that it has is severely limited by the specification.
The result is that if you correctly predicted the required degrees of freedom, the design has great clarity and accuracy - it will actually serve as a guide for the right questions to ask, and give you useful conditions that you might think about the problem.
Perl
One Perl spirit is "there is more than one way to do this." and the syntax language itself has changed significantly over the years (including incompatible changes). Like Java, this relationship extends to programs written in this language.
Although you can write Perl to clean up interfaces, it does not apply and often fails. This may mean âwriting onlyâ code, but if you understand it, you can change it arbitrarily. That is, it is ugly, but flexible - perhaps my change in ugliness needs to be changed?
Apparently, mjd said of a higher order Perl, which he could not write with a test development, because he lacked the necessary flexibility. Hopefully I wonât put words into his mouth here, but I think the same applies to interfaces and specifications (because this is what TDD provides).
It seems to me that Java code tends to be neat but tough; and Perl code is dirty but flexible. Support Java preliminary design; and Perl promotes rapid prototyping.
In my code (Java), I am confronted with the choice between neat and flexible. For example, I compared the Visitor template with one large if cascading function.
The latter is ugly, but in many cases it is easier to add parameters to the calls of the recursive method (this is only a problem if you need such a degree of flexibility (which I find in search prototyping).
Explanation: The visitor template reorganizes the cascading one â if the method overrides, by defining and calling these methods, one class for each, so the added argument must be added to all these methods and all calls from them, in all these classes. I coded these projects and calculated how many places the arguments added: 9 places for visitors (in different files); 3 places for cascading-ifs (all in one file). The cascading-ifs solution is much easier to modify, although it is ugly.
This question is not about Java and Perl - I just use them as illustrative examples to make the question more specific and specific, and hopefully easier to consider.
Is arbitrarily flexible code necessarily messy?