Skip to main content

Why are Sun's code examples such bad examples of coding?

Posted by gvix on October 11, 2006 at 3:38 AM PDT

I was browsing through the Sun supplied Location API examples in the latest Wireless Toolkit when I came upon this:


Ok, so it's just a few lines of code that are, to put it mildly, exceeding the generally accepted 80 character limit. The fact that there is no explanation of what this class actually does in the Javadoc comments is to be expecting too much. Hey, it's the 'Main CityGuide MIDlet'. What more explanation do you want?

So, I decided to investigate further. At random, I picked another code example, the BallCanvas class in AudioDemo. Just a small snippet from this:


The formatting is all over the place, the commenting is, as you can see in the highlighted section, verbose (Destroy for the method called destroy()!).

OK, so these are just two examples, but when you look at the rest of the code examples, two things stick out.

1. Code comments were not a priority of the engineers writing the code samples for Java ME. There is no consistency.

2. Code formatting is all over the place. There is no adherence to any established guidelines or any semblance of quality control.

Why does Sun think it is ok that these code samples be released without mandating that a due QC be applied to them? Is this the same for examples of Java EE and Java SE? I know these are just code samples and Sun is doing us a favor by releasing them, but it shouldn't take me the better part of a day trying to gloss over badly formatted and incompletely commented code for a technology that Sun is trying to sell.

When you are trying to learn a new facet of Java ME technology based on these code samples, it would help if you have spent your years doing code reviews for undergraduates.

Related Topics >>