DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: indent wars..  (Read 13,384 times)

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,931
    • Gathering Badge
    • Plugin Coding Medal
    • Participated in NANY Challenge Seventeen Times
    • Cody Award
    • Coding Snacks
    • Volunteers/Staff
indent wars..
« on: February 10, 2006, 02:46 AM »
personally i have always been deeply in love with whitesmith style, which is how i learned to write c code..

http://everything2.org/index.pl?node=indent%20style

what's your favorite?

Gothi[c]

  • DC Server Admin
  • Charter Honorary Member
  • Joined in 2006
  • ***
  • Posts: 873
    • Gathering Badge
    • Coding Snacks
Re: indent wars..
« Reply #1 on: February 10, 2006, 03:28 AM »
I've always been coding like so:

Code
#someInclude

// Some comment

int someFunc()
{
  blah() ;
}

allen

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 1,206
    • Participated in NANY Challenge Once
    • Cody Award
    • Programming School - Deluxe Bonus Medal
    • Military Service Badge - US Navy
    • Linux User
    • Writer
Re: indent wars..
« Reply #2 on: February 10, 2006, 03:30 AM »
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.

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

jgpaiva

  • Artificial Idiocy
  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • Cody Award
    • Participated in NANY Challenge Once
    • Coding Snacks
    • Portugal Inhabitant
    • Linux User
Re: indent wars..
« Reply #3 on: February 10, 2006, 11: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
    • Participated in NANY Challenge Once
    • Cody Award
    • Programming School - Deluxe Bonus Medal
    • Military Service Badge - US Navy
    • Linux User
    • Writer
Re: indent wars..
« Reply #4 on: February 10, 2006, 11: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

  • Artificial Idiocy
  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • Cody Award
    • Participated in NANY Challenge Once
    • Coding Snacks
    • Portugal Inhabitant
    • Linux User
Re: indent wars..
« Reply #5 on: February 11, 2006, 12:05 AM »
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: 633
    • Linux User
Re: indent wars..
« Reply #6 on: February 11, 2006, 01:09 AM »
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
    • Participated in NANY Challenge Once
    • Cody Award
    • Programming School - Deluxe Bonus Medal
    • Military Service Badge - US Navy
    • Linux User
    • Writer
Re: indent wars..
« Reply #7 on: February 11, 2006, 02:38 AM »
Reading related information . . . now there's a thought :D

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,931
    • Gathering Badge
    • Plugin Coding Medal
    • Participated in NANY Challenge Seventeen Times
    • Cody Award
    • Coding Snacks
    • Volunteers/Staff
Re: indent wars..
« Reply #8 on: February 11, 2006, 08:09 AM »
code complete 2 is out now (updated version of first book) -  i highly recommend it for all programmers.
http://www.amazon.com/gp/product/0735619670

f0dder

  • [Well, THAT escalated quickly!]
  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
    • Participated in NANY Challenge Once
Re: indent wars..
« Reply #9 on: February 11, 2006, 04:15 PM »
A sample of my code style...

Code
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

Original address: https://www.donationcoder.com/forum/index.php?topic=2401.0