• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Formatting rule for braces - some specifics please.

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,
A code formatting question where I cannot derive to 'when to' and 'when not to' from the style guide..

I fear I am in breach of some formatting rules when it comes to using my braces and indenting. Now, reading the style guide it recommends an indentation of 4 spaces but where it is not clear is when to indent. Using the example below, I start with the class definition, open my braces and then indent 4 spaces for my method.I have then indented for the if and so on as I go along, matching the closing braces up with the opening one. My question is wen to indent as I fear I'm doing too much indentation- Any hard and fast rules such as always indent after class name? Always for method etc..Basically..when should a next line line up with the brace before and when should an indent be used?




Thanks,

Colm
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What you have looks fine to me--I think you're interpreting the rules exactly as they are intended. Anything that represents a nested block of code gets indented. A lot of programmers like to put the opening brace at the end of the preceding line instead of on a line by itself, and that makes the cattle drive code look a little bit spaced out. But the indentation itself is, I think, pretty standard. (I personally agree with putting the opening brace on a line by itself, it makes it a lot easier to identify the start and end of a block of code.)
 
Colm Dickson
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Kurt.
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic