Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Code adherence

 
Tom Joiner
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to get my code to adhere to the developer standard.. are there some good example sites somewhere with code, not rules?

Here is a class I am creating.. how should it change?

Each face has one of three symbols, and one of three colors

 
Mark Smyth
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One thing I have spotted is that some of your method names begin with uppercase letters when they should begin with lower case letters also the opening brace should be on the same line as the method signature.



Not sure if there are any full examples to show the use of coding standards. Maybe have a look at the source code for the Java libraries to get a feel for the apropriate coding style.

The sun coding conventions document is here and has a few appropriate snippets of code to highlight each rule.
Code Conventions for the Java Programming Language
[ October 25, 2006: Message edited by: Mark Smyth ]
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Underscores are discouraged.
Javadoc is mandatory for all public entities and advisory for everything else.
Proper access modifiers should be used where appropriate (personally I tend to always comment a decision to go for package access as usually this level is chosen in error rather than deliberately).
Constructors should always be at the start of a class (right after the data members).
 
Tom Joiner
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the advice. Here I have changed the routine names, added javadoc, and changed the accessor status to be explicit rather than package.

What else should be done?

- If there are only three symbols, should I enumerate them in some way, and make that enumeration be the interface?

- How do I distinguish the class member variables from the ones coming in to the routine? I made up my solution "colorIn".. there must be a standard which is better.

- Any other ideas?

 
Tom Joiner
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, so I found that Java 5.0 now supports enums, which is a better solution for this than using ints, or homebrew enums (with static final int's in a class). here is the new version, but I still thing the get and setter methods could have better arguments

 
Mark Smyth
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alot of people use this kind of a style. You name the parameter the same as the member variable and then uses the this reference to assign the value to the member variable.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic