Examples of both beautiful and ugly java code?
- by tputkonen
I would like to demonstrate how difficult it is for a layman to identify high quality code from flawed code.
I'm thinking of doing this with the help of two java methods. Both of the methods should look like they do the same, pretty simple thing. However one of them should have several kind of flaws, for example:
iteration with array off by one error
string concatenations causing lots of objects to be created (as opposed to StringBuffer in the "good" code, which looks more complicated)
possibly null pointer exception (but it should not be trivial to spot)
Those are just some examples, all kinds of other issues including bugs and performance related structures are highly appreciated.
Methods should be around 10-20 lines of length, and the task they do should be something simple - preferably printing something in an iteration.