Sun Coding Conventions--The Only Standard (Stop Inventing)

Code written according to the Sun Coding Conventions looks like most of the …Java code.
The popular IDEs already come with the "Sun/Oracle Coding Conventions" out-of-the-box and any change introduces some friction. Getters / Setters generators usually do not rely on prefixes like "f" for fields, and would generate methods prefixed with the "f" as well. You could, of course, reconfigure your IDE to support your custom conventions, but could you explain something like that to an alien?

[The line width limitation of 80 characters is of course outdated. Printing out code is also less important, than it was in 1996. I prefer readability over fixed size length and e.g. cryptic (shortened) method and parameter names.]


Cloudy Jakarta EE and MicroProfile: Microservices, Clouds and Beyond Jakarta EE / MicroProfile airhacks workshops at MUC airport, Winter Edition

airhacks.fm the podcast:

Stay in touch: airhacks.news.

Comments:

Right, do not invent new coding conventions. BUT they reflect the java language syntax from April 1999. What about new language concepts? It is time to update the coding conventions.
- Markus

Posted by Markus on November 21, 2011 at 10:32 AM CET #

... or the infamous 'I' for interfaces. Yuck. Shudder.

Posted by Olaf Heimburger on November 21, 2011 at 10:45 AM CET #

Are there plans to update the Java Code Conventions, for generics, diamond syntax, enums, ... are far as you know?
They should do something better than that... I always use them but often I receive complains from teams that they're not complete and precise... :(

Posted by Marco on November 21, 2011 at 12:25 PM CET #

i feel 80 characters is just fine (ok 100 or so goes also). limiting the line length _does_ make stuff more readable.

i think the same age old principles apply than in "regular" stuff (books, newspapers) intended to be read, such as having the text in portrait layout and a decent font size, that essentially means something like 80-100 characters per line.

also, at least i don't blow up one source file to fill my whole landscape-type screen. for an example i could have a class and the unit test class for that side by side. working like that, it would sure be nice to have the source code fit into the two portrait-like frames that fit to my screen and not have a microscopic font size.

Posted by anon on November 21, 2011 at 01:41 PM CET #

Sometimes they're not enough, for instance interface and implementation class names, should they be:
- Thing and ThingImpl
- or IThing and Thing (DBUnit, Wicket, etc.)

Posted by Gerald on November 21, 2011 at 05:06 PM CET #

Gerald: In most cases your interface should be just "Thing" and the implementation name should give a hint about specific type, for example "XMLThing", "HttpSessionThing" for technical 'things' or "VIPCustomerThing" and "StandardCustomerThing" for business 'things'. There is a post dedicated for this subject: http://www.adam-bien.com/roller/abien/entry/service_s_new_serviceimpl_why

Posted by Krzysztof Ciesielski on November 22, 2011 at 06:02 PM CET #

@Markus,

although the coding conventions were created in 1999, they are lot better than the "alien" conventions (often c-based) I see in projects. But your are right: an update would be nice.

thanks!,

adam

Posted by Adam Bien on November 22, 2011 at 11:24 PM CET #

@Olaf,

if you get rid off the interface you get rid off the problem as well :-):

http://www.adam-bien.com/roller/abien/entry/service_s_new_serviceimpl_why

thanks for your comment!,

adam

Posted by Adam Bien on November 22, 2011 at 11:25 PM CET #

@Anon,

it is really hard for me to find proper (=non-cryptic) names for methods with parameters which fit to 80 characters.

I would like to see the 80 characters limit more as a recommendation, than a hard limit.

thanks for your thoughts!,

adam

Posted by Adam Bien on November 22, 2011 at 11:27 PM CET #

@Gerald,

if you are running to name clashes - just remove the interfaces. I think a convention here would be counter-productive: it would encourage the introduction of meaningless interfaces / implementations. See also: http://www.adam-bien.com/roller/abien/entry/service_s_new_serviceimpl_why

thanks!,

adam

Posted by Adam Bien on November 22, 2011 at 11:29 PM CET #

Actually the character num goes with the monitor/reso/font size parameter. Different hardware/software settings will affect readability.

If using method chaining to develope DSL it can(it will if it has a deep tree structure) screw your convention anyway.

As always, there is no silver bullet.

mfg :)

Posted by DevInstance on November 30, 2011 at 01:08 AM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
Online Workshops
realworldpatterns.com
...the last 150 posts
...the last 10 comments
License