Generated Java code |
From JAXXWiki
There are many examples throughout this site which display some JAXX code and then the equivalent Java code. In these examples, the Java code displayed is not the code you would actually get from compiling the JAXX file, but rather hand-written code that works equivalently. Here are the primary reasons behind this decision:
JAXX doesn't produce pretty code
The jaxxc compiler works by first compiling the JAXX file into a .java file, and then using javac to compile the .java file.
Ideally, jaxxc would produce 'pretty' Java code very similar to what you would have written yourself, but in practice clean machine-generated code is very hard to produce. In addition to being a hard problem to solve, it is an unrewarding one: generally there is no significant difference in efficiency or usefulness between 'pretty' and 'ugly' code.
Improving the quality of JAXX's generated code is a definite goal, but at the moment there are more significant issues to worry about.
Compiler is expected to evolve
Even if JAXX produced beautiful code today, there is no guarantee that the next version will produce the exact same code given the same input files. Optimizations, adjustments, and new features will be implemented, and all of these will affect how compiled Java files are produced. Rather than have to go through the site updating all of the examples every time the compiler changed (and be needlessly concerned with maintaining the code's attractiveness throughout), it's easiest to just have a blanket disclaimer and avoid the issue altogether.
Hand-written examples are more instructive anyway
No matter how smart JAXX gets, it will never be able to write code as well as a human. Since the differences between JAXX's machine-generated code and carefully hand-written code are largely irrelevant, calling attention to them generally serves no purpose other than to obscure what the example is trying to get across. It is important to demonstrate what the code does, but not necessarily the ugly contortions it has to go through to get there.

