This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Building Blockchain Apps and have Michael Yuan on-line!
See this thread for details.
Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Coding conventions

 
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.
 
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.
 
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.
 
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...
 
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
 
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
 
Ranch Hand
Posts: 854
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.
 
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 ]
 
Replace the word "snake" with "danger noodle" in all tiny ads.
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!