Introducing
The Slant team built an AI & it’s awesome
Find the best product instantly
Add to Chrome
Add to Edge
Add to Firefox
Add to Opera
Add to Brave
Add to Safari
Try it now
4.7 star rating
0
Development
Java
Programming
Programming Language
styles
What is the best indentation style in Java?
3
Options
Considered
3
User
Recs.
Jan 31, 2020
Last
Updated
Related Questions
Activity
Have feedback or ideas?
Join our community
on Discord
Ad
3
Options
Considered
Best indentation style in Java
Price
Last Updated
--
Allman Style
-
Jan 31, 2020
--
K&R (UNIX Kernel) Style
-
Jan 31, 2020
--
GNU style
-
Jan 31, 2020
See Full List
--
Allman Style
My Rec
ommendation
for
Allman Style
My Recommendation for
Allman Style
All
3
Pros
2
Cons
1
Top
Pro
•••
The block of code is disconnected from the control statement
The block of code itself is disconnected from the control statement which allows developers to comment out or remove entirely a control statement without having a large risk of encountering syntax errors because of extra or missing braces.
See More
Top
Con
•••
Uses more vertical space than other styles
Since each bracket is its own line, the Allman style takes more vertical space than other indent styles. This is one of the reasons that a lot of book authors do not prefer to use Allman style in their texts.
See More
Top
Pro
•••
Easy to find matching braces
The code is clearly set apart from the statement by lines that are almost completely whitespace and the fact that the opening braces line up in the same column as the closing braces makes it easier to match them.
See More
Hide
See All
Recommend
1
--
K&R (UNIX Kernel) Style
My Rec
ommendation
for
K&R (UNIX Kernel) Style
My Recommendation for
K&R (UNIX Kernel) Style
All
2
Pros
1
Cons
1
Top
Pro
•••
No space is wasted with the opening brace
With this style, one of the advantages is that the opening brace does not take a whole line for itself, wasting a lot of space. The closing brace though is indented on the same level as the control statement it belongs to, making it easier to understand which block of code it's closing.
See More
Top
Con
•••
May be hard to insert new lines inside statements if there are no braces
The K&R style uses braces only when necessary. So for example: if(condition) doSomething(); But this can be annoying if you need to put something inside that if statement, because you have to go and add braces to make sure that will be grouped correctly with the statement that was before.
See More
Hide
Recommend
1
--
GNU style
My Rec
ommendation
for
GNU style
My Recommendation for
GNU style
All
1
Cons
1
Top
Con
•••
Harder to understand which statement the ending brace belongs to
Since braces are in a newline and indented by two spaces, it may be hard to understand what statement the ending brace belongs to.
See More
Hide
Recommend
1
Don't see your favorite option? Add it.
Built By the Slant team
Find the best product instantly.
4.7 star rating
Add to Chrome
Add to Edge
Add to Firefox
Add to Opera
Add to Brave
Add to Safari
Try it now - it's free
One sec!
Are you sure that you want to abandon your hard work?
Delete Work
Continue working
{}
undefined
url next
price drop