• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Code Convention: Placement of braces

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looking at the Sun's "Jave Code Conventions" (1997) document it has the placement of braces as the following:

class Blablabla {

.....

}

where I am used to (years of use):

class Blablabla
{

.......

}

In my exam instructions Sun supplies and interface that does the following:

public interface Blablabla
{

.......

}

I much prefer the placement that I am used and I am much more efficent this way but it is not worth failing the exam or even losing points . What is the general thought on this issue? Thanks!
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This a big controversy, but for the SCJD you should follow the Java Code Convention, which does not allow braces to be placed that way.

As far as the interface declared in the document, you should not take that into account, it does not even ident correctly.

Just curious: did you inherit that brace placement style from another language? It looks very object pascal (BEGIN...END)

http://java.sun.com/docs/codeconv/html/CodeConventions.doc5.html

# Open brace "{" appears at the end of the same line as the declaration statement
# Closing brace "}" starts a line by itself indented to match its corresponding opening statement, except when it is a null statement the "}" should appear immediately after the "{"


[ September 08, 2006: Message edited by: Dalton R. Filho ]
 
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For the SCJD assignment you MUST use the Sun coding conventions.

Better get used to it, in the real world you will often not be able to choose your own either.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use a code autoformatter, such Jalopy or the one built into Eclipse. They can be setup to very closely match the Sun coding standard.

Also download and use the program Checkstyle (also available as an Eclipse plugin), with settings for Sun coding standards. It detects code that doesn't conform to formatting rules you specify. Its helpful to detect the small things you can easily overlook. Such as using tab's instead of spaces, or finding problems where whitespace should or should not be (or for your situation, where braces should appear).

You could code in whatever format you want, then convert to Sun standards with an autoformatter (and verify with Checkstyle), before submitting.

Although I agree with the other posts, if you intend to write most of your future code in Java, you should directly code in the format Sun wants.
 
John Deal
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes I am an old hacker. COBOL Begin-Paragraph End-Paragraph (or something like that), Pascal Begin End, SPL (Algol 60 based language), C, C++ { }. I like to try to keep the same basic code layout across all languges. Personally the SUN standard for brace placement drives me crazy. I will most likely do it "My Way" then convert it at the end. I may just try the format converter.

I was a software programmer/engineer for 23 years before starting to teach at a community college for the last 3 years. Lots of languages, lots of targets, lots of operating systems. It has been quite a ride!

Thanks!
 
Dalton Filho
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by John Deal:
Yes I am an old hacker. COBOL Begin-Paragraph End-Paragraph (or something like that), Pascal Begin End, SPL (Algol 60 based language), C, C++ { }. I like to try to keep the same basic code layout across all languges. Personally the SUN standard for brace placement drives me crazy. I will most likely do it "My Way" then convert it at the end. I may just try the format converter.

I was a software programmer/engineer for 23 years before starting to teach at a community college for the last 3 years. Lots of languages, lots of targets, lots of operating systems. It has been quite a ride!

Thanks!



Thank you John, that explains it all. I remember one teacher saying in a data structures class (that was taught using Java) that we were not just programming in a new language (most people had an Object Pascal background), we had to "speak Javanese" - that included not writing method names starting with capital letters (we used to do that in OP), writing braces as if they were begin/end paragraphs, among other subtleties.

Not placing the braces the standard way, considering your experience, may lead people to think you despise other Java subtleties in favor of old (bad?) practices you consider correct.
reply
    Bookmark Topic Watch Topic
  • New Topic