GeeCON Prague 2014*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Code conventions & design doc size Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Code conventions & design doc size" Watch "Code conventions & design doc size" New topic
Author

Code conventions & design doc size

Patrick Cobbett
Ranch Hand

Joined: Jul 10, 2003
Posts: 44
Hi all, i have a couple small queries so i've slung them together.
Firstly, i follow all the proper coding conventions but is code style considered part of the proper coding conventions? When i talk about code style i am specifically talking about how curly-brackets are placed.
I write code like this:
public void doThis(){
// code
}
for(int i=0; i<size; i++){
// code
if (true){
// code
}
}
However, most code i see is written like this:
public void doThis(){
// code
}
for(int i=0; i<size; i++){
// code
if (true){
// code
}
}
Does it matter which way the brackets are placed as long as they are consistent or is the second the proper way it should be done? Does anyone share my style of code?
And my second question is my concern about how much to write for the design document. I don't want to bore the marker to bits and have him get irritated if i point out points which may be obvious. In the URlyBird assignment i think alot of marks are awarded for this, by in mine, FBNS, there is very little in comparison. Is the design document mainly to help the examiner understand the program, or it is assess my abilities at documenting it? Sun told me NOT to go over-board on this.
If people aren't sure then chuck in a small post indicating how much you have or intend to write for it. I just wanna get a feel for how much people are writing for this.


[SCJP, SCJD]
Patrick Cobbett
Ranch Hand

Joined: Jul 10, 2003
Posts: 44
The indents were ommited when i submitted my last reply, lets see if this works:

My code:

Other code:
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11464
    
  94

Hi Patrick
I have heard several people saying that we must follow Sun's Coding Conventions. According to that document your second example is the more correct one (still doesnt have the correct white space though).
I cannot find anything in the instructions that state this though, so I don't know how mandatory it is (or isn't).
The nice things about using the Sun standards are that there are some nice tools around that can programatically check your code to ensure that you are adhering to that standard. Checkstyle is the one I use. You can configure this (and presumably other) tools to meet your coding style, but if you use the Sun style, then the configuration is already done for you.
As for design choices document - I went overboard. You can see what I did in this post. I got 100% for documentation, so going overboard didnt hurt.
Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Damian Ryan
Ranch Hand

Joined: May 09, 2003
Posts: 117
I tend to agree with what Andrew has said, but would reiterate that use of Sun's conventions is not mandatory (though perhaps the safest plan).
There are a couple of things I don't like about Sun's conventions so I tend to go my own way on those, because that's the way I've been writing my Java code for years now. I didn't lose any marks for not following Sun's conventions to the letter.
I think that what is most important is that your code formatting is consistent across all your sources.
I know a lot of people use Checkstyle (mentioned by Andrew above) but I'm quite fond of Jalopy which I use as a plugin with NetBeans. It is also usable standalone, and as a plugin for several other IDEs (such as Eclipse, JBuilder, jEdit and JDeveloper).
[ July 25, 2003: Message edited by: Damian Ryan ]
[ July 25, 2003: Message edited by: Damian Ryan ]

Always proofread carefully to see if you any words out.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Patrick, your other code looks more to the standard. It is funny because where curly braces are can really just be a personal preference. I mean opening curly braces on the same line, or on the next line. Closing braces tabbed in, not tabbed in.
I think the point of the standards are not to push their will onto programmers, but to make uniformity with all coders.
It is usually just a matter of getting used to the way the standard looks. At first you will be like, "Well, I don't like the way that looks". But after you get used to the standard you will feel the same way as to the look as you might do now with how you do it now.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
GeeCON Prague 2014
 
subject: Code conventions & design doc size