topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Friday March 29, 2024, 9:59 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: indent wars..  (Read 9276 times)

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
indent wars..
« on: February 09, 2006, 08:46 PM »
personally i have always been deeply in love with whitesmith style, which is how i learned to write c code..

http://everything2.o...?node=indent%20style

what's your favorite?

Gothi[c]

  • DC Server Admin
  • Charter Honorary Member
  • Joined in 2006
  • ***
  • Posts: 873
    • View Profile
    • linkerror
    • Donate to Member
Re: indent wars..
« Reply #1 on: February 09, 2006, 09:28 PM »
I've always been coding like so:

#someInclude

// Some comment

int someFunc()
{
  blah() ;
}


allen

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 1,206
    • View Profile
    • Donate to Member
Re: indent wars..
« Reply #2 on: February 09, 2006, 09:30 PM »
Closest match to me is GNU.

I like two spaces.  Just enough to make a distinction, without consuming line space.

I hadn't realized there were all thse named indentation styles.  I'm unedumicated.

// some comment
someFunc() {
  blah;
  moreFunc() {
    meh;
  }
}

jgpaiva

  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • View Profile
    • Donate to Member
Re: indent wars..
« Reply #3 on: February 10, 2006, 05:31 AM »
I also use a similar indentation to the one Allen uses, but with a tab instead of two spaces. IMO it makes more sense to have the last bracket aligned with the function that opened it, it's easier to know when there's a bracket missing.
I think this indentation is the default for emacs, at least, i use it in emacs. Although in the page mentions that it should be "gnu style" indentation, i think it's more similar to K&R indentation, if not that one.

allen

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 1,206
    • View Profile
    • Donate to Member
Re: indent wars..
« Reply #4 on: February 10, 2006, 05:54 PM »
I originally started using spaces rather than tabs after writing a web-based file editor for use away from home.  Pressing tab would knock me out of the box, so I just got accustomed to double tapping the space bar.  (as it was, I'd already decreased tab size to 3, then 2 spaces to decrease wasted whitespace).

It does make sense to match start/end brackets in the same column for easy glancing for unclosed brackets.  I end up relying on my text's matching bracket highlighter.  If it matches with the wrong bracket or none at all, I missed something ;)

jgpaiva

  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • View Profile
    • Donate to Member
Re: indent wars..
« Reply #5 on: February 10, 2006, 06:05 PM »
I end up relying on my text's matching bracket highlighter.  If it matches with the wrong bracket or none at all, I missed something ;)
Exactly my point!  :Thmbsup: :Thmbsup:

Rover

  • Master of Smilies
  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 632
    • View Profile
    • Donate to Member
Re: indent wars..
« Reply #6 on: February 10, 2006, 07:09 PM »
Everyone read _Code Complete_ by MS Press?  It discusses indent techniques plus standards for loops and if/then structures.  I read it in the early 90's, and it's still around.
Insert Brilliant Sig line here

allen

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 1,206
    • View Profile
    • Donate to Member
Re: indent wars..
« Reply #7 on: February 10, 2006, 08:38 PM »
Reading related information . . . now there's a thought :D

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: indent wars..
« Reply #8 on: February 11, 2006, 02:09 AM »
code complete 2 is out now (updated version of first book) -  i highly recommend it for all programmers.
http://www.amazon.co...p/product/0735619670

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: indent wars..
« Reply #9 on: February 11, 2006, 10:15 AM »
A sample of my code style...

extern std::string GetUserName();

const unsigned IterationCount = 1024;

void MyFunction()
{
unsigned myVariable = 42;

// 4-space tab - space indentation is evil.
// Multi-statement loops and if sentences use blocks
for(unsigned i=0; i<IterationCount; i++)
{
TweakSystem(i*2);
PrintOut(i);
}

// Single-statement loop and if sentences don't use blocks
if(GetUserName() == "f0dder")
GiveRootPrivileges();
}

Also, for classes, I never define functions inline in the class block - for member functions that are supposed to be inline, I do define them in the header, but below the class.
- carpe noctem