• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Coding conventions

 
Jamie Veranos
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Has anyone lost any points for not placing the opening '{' on the same line as the start of compound statements? I have been using the form:

instead of:

Although I have been VERY CONSISTENT throughout my code, I am concerned with losing points over something so seemingly minor.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the book by Kathy Sierra and Bert Bates "Sun Certified Programmer and Developer for Java 2", in the Developer section, chapter 11, Coding Standards, p 579, they say
The opening brace for classes, interfaces, constructors, and methods should occur at the end of the same line as the declaration. The closing brace starts a new line by itself, and is indented to match the beginning of the corresponding declaration.

For flow control (ifs and whiles, etc):
Your flow control blocks should always be enclosed in curly braces. There are places where the compiler will let you get away with not using curly braces, such as for loops and if tests with only one statement in the body, but skipping the braces is considered uncivilized ...snip... For the exam, always use curly braces...snip...- pin this baby to your wall!

The examples following are like:
 
Jamie Veranos
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was afraid of that!
Thanks.
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I was afraid of that!

Don't be afraid, it's just a Java coding convention!
Eugene.
 
Ben Ritchie
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Being forced to code in a style you do not like is probably the most realistic thing about this assignment. Happens to me at work too...
 
Qusay Jaafar
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way, is there any software for testing the Code Convention??? :roll:
Regards
 
Rahel Luethy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i always postponed the coding convention issue and thought that i would do it right before submission. while developing, i just used the settings of my IDE with braces on new line and i used underscores as prefixes for instance variables. though this approach is quite consistent (my IDE even reformatted the original code) it is not at all what sun recommends.
as you can probably guess, i forgot to do the formatting later
i received my result last week (144/155) and fortunately, i did not get any deductions in the coding standards section whatsoever (lost 11 points in the docs )
although i don't really like sun's standards, i strongly believe that the assignment is not the right place to be bullheaded -- as i said, i didn't do it on purpose, i just forgot
 
Burk Hufnagel
Ranch Hand
Posts: 814
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
FYI -- JBuilder8 lets you "import" different formatting styles so when you're writing code it "auto-formats" it for you. They've got one for Sun's coding conventions, though I haven't gone through to verify everything (yet) it sure looks like they do a lot of it.
 
BJ Grau
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Qusay Jaafar:
By the way, is there any software for testing the Code Convention??? :roll:
Regards

Here you go:
http://sourceforge.net/projects/checkstyle
It defaults to Sun's conventions.
And here are three important links:
Sun Coding Conventions
Java Language Spec (you will find some convention guidelines hidden in here)
Writing Comments for Javadoc
[ March 03, 2003: Message edited by: BJ Grau ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic