This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Code indentation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Code indentation" Watch "Code indentation" New topic
Author

Code indentation

Amit Kr Kumar
Ranch Hand

Joined: Feb 08, 2002
Posts: 100
Hi Ranchers
I am using the following java indentation style in all the new classes i have created
public methodA()
{
for()
{
.....
}
...
}
However in Data.java, Fieldinfo.java, Datainfo.java claasses supplied
by sun follows the following indentation style
public methodA(){
for(..){
}
...
}
Should i change this indentation style in Data.java, Fieldinfo.java, Datainfo.java so that it becomes consistent with my code ?
Amit
BJ Grau
Ranch Hand

Joined: Jul 10, 2001
Posts: 234
Personally, I would make sure all of the code follows the same style. You can do that either by coding to the style established by the exisitng code or by changing the style of the exisitng code to fit your style.
I don't see any problem with changing the style of the existing code, as there is not much there to begin with and you are currently the only developer working on it. If this was already a large application with other developers working on it, you would want to conform with whatever style was already established.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17258
    
    6

I always liked the way that Sun does it, it is also the way C programmers do it to.
putting the opening braces on the same line.
At first I didn't like it that way, but I got used to it, and now really find it much more cleaner and more readable
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Jason Boutwell
Ranch Hand

Joined: Apr 02, 2002
Posts: 40
I wouldn't deviate too much from this:
Java Code Conventions
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17258
    
    6

Good Link Jason
Mark
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
In my assignment, Data and DatabaseException were formatted with indent 4, but DataInfo and FieldInfo used indent 2. It looks like two different persons coded these classes. I just reformatted everything to use indent 4.
Eugene.
Arup Chowdhury
Greenhorn

Joined: Jan 20, 2002
Posts: 10
Hi
There are some more coding convention guides on the net. Follow the newer vesion. The one on Sun s site is pretty old.
try this. this one is relatively newer
http://www.ambysoft.com/javaCodingStandards.html
With Regards
Arup
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4787
    
    8

That ambysoft Java Coding Standards is 76 pages long!
I remember seeing a one-page coding standard once but for the life of me can't remember where it was or who wrote it.
The more concise the standard, the better chance that people will follow it. The most important thing is to be consistent though, IMO. My $0.02...
Junilu
Jason Boutwell
Ranch Hand

Joined: Apr 02, 2002
Posts: 40

There are some more coding convention guides on the net. Follow the newer vesion. The one on Sun s site is pretty old.

Whew. That's not a guide on Ambysoft, its a dissertation.
The age difference between the Sun and Ambysoft guides is a mere 9 months. I doubt that there were any major breakthroughs in coding standards in that time.
 
Don't get me started about those stupid light bulbs.
 
subject: Code indentation