Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Indentation for Throws clause of a method

 
Sam Codean
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this indentation correct as per Java Standards?
I mean can we align the Throws Clause right at the bottom of the Method Declaration?

 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See page 5 and 6 of the Java code conventions.
Subsequent indentation levels should indent 4 spaces from the previous indentation level, or 8 if that makes the code clearer.

In your case I'd use the following:


Far easier to read.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JTW++
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
next you're going to claim I posess multiple inheritance...
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11855
186
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JTW-- (Sorry Jeroen, you are back to your default value).

Section 4.2: Wrapping Lines of the Code Conventions gives two examples of indenting method declarations. Note that they indicate that the first example is the convential case. They also indicate that where the "rules lead to confusing code or to code that's squished up against the right margin, just indent 8 spaces instead."

So I would take that to mean:Regards, Andrew
 
Sam Codean
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmm thanks actually eclipse indents it that way so got confused.
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out Eclipse's settings. It can be changed to reflect different coding guidelines set as several defaults.
It is quite possible that IBM likes this style, Sun likes another.
And for the assignment you'd better do things the way Sun likes them, even if you prefer to do things differently yourself.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still think JTW's is prettier Andrew, so JTW += JTW++ + JTW++ (to remind you guys of the good old SCJP days)
 
Sam Codean
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still would prefer Andrew's Style as that makes it look more "as per Java Standards"
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I admit that my style is more useful when there are so many exceptions that they no longer fit on a single line than in this scenario.
I also admit I don't follow it religiously, but then I'm called a heretic by most religions
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic