Proper Formatting

It's getting really annoying guys.

Page 1 of 1

8 Replies - 1015 Views - Last Post: 04 July 2009 - 08:45 PM

#1 LegalBreaker  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 35
  • Joined: 25-June 09

Proper Formatting

Posted 04 July 2009 - 01:40 PM

First of all, this entire thread is comprised of my personal opinion. I just want to try and make a point.

That being said, what is proper formatting? It really depends on your preference but there are generally two styles that are easiest to read.

This one:
#include <iostream>
using namespace std;

int main(void) {
  cout << "Text" << endl;
  for(int ii = 0; ii < 10; ++ii) {
	cout << ii << endl;
  }
  return 0;
}



And this one:
#include <iostream>
using namespace std;

int main(void) 
{
  cout << "Text" << endl;
  for(int ii = 0; ii < 10; ++ii) 
  {
	cout << ii << endl;
  }
  return 0;
}



You'll notice the only difference is that when a curly brace is used, it's on the next line by itself. I think that indenting two spaces after a function or loop is the easiest to read. I'm sick of seeing this:

#include <iostream>
using namespace std;



int main(void) {
					cout << "Text" << endl;
					for(int ii = 0; ii < 10; ++ii) {
										cout << ii << endl;
					} 
  return 0;


}




And other similar posts that have no real formatting. If you format your code so it's easy to read and looks nice, we will have a much easier time reading it and helping you. I promise.

So I'm sure there are other widely popular formatting styles that are good looking. If you know of any, feel free to post them here. Also, discuss. :D

Is This A Good Question/Topic? 0
  • +

Replies To: Proper Formatting

#2 eker676  Icon User is offline

  • Software Engineer
  • member icon

Reputation: 378
  • View blog
  • Posts: 1,833
  • Joined: 18-April 09

Re: Proper Formatting

Posted 04 July 2009 - 03:47 PM

I like the spaced out version like you posted above

int main()
{
	cout << "Hello World!" << endl;
	
	return 0;
}

Was This Post Helpful? 0
  • +
  • -

#3 Zerobu  Icon User is offline

  • Black Hatter

Reputation: 13
  • View blog
  • Posts: 1,822
  • Joined: 14-January 08

Re: Proper Formatting

Posted 04 July 2009 - 04:23 PM

The second one.
Was This Post Helpful? 0
  • +
  • -

#4 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Proper Formatting

Posted 04 July 2009 - 04:28 PM

Not to burst your thread here, but you just rediscovered the topic of http://en.wikipedia....ki/Indent_style ]indent style[/URL].
Was This Post Helpful? 0
  • +
  • -

#5 igotthepancakes  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 16-March 09

Re: Proper Formatting

Posted 04 July 2009 - 05:30 PM

This thread helped me, thanks.
Was This Post Helpful? 0
  • +
  • -

#6 LegalBreaker  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 35
  • Joined: 25-June 09

Re: Proper Formatting

Posted 04 July 2009 - 05:55 PM

View PostOler1s, on 4 Jul, 2009 - 03:28 PM, said:

Not to burst your thread here, but you just rediscovered the topic of http://en.wikipedia....ki/Indent_style ]indent style[/URL].


Yeah but I was posting it to shed light on the subject. It's not like everyone has read that. I wasn't saying I invented those styles. Why don't you try and read the thread?
Was This Post Helpful? 0
  • +
  • -

#7 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Proper Formatting

Posted 04 July 2009 - 07:21 PM

Since this isn't a C or C++ issue (it's a general issue) I'm moving this to the Corner Cubical. Also, there have seen several threads started on this topic, including this one (The search feature on Dream.In.Code actually works :) )
Was This Post Helpful? 0
  • +
  • -

#8 jjsaw5  Icon User is offline

  • I must break you
  • member icon

Reputation: 90
  • View blog
  • Posts: 3,060
  • Joined: 04-January 08

Re: Proper Formatting

Posted 04 July 2009 - 07:58 PM

View Postigotthepancakes, on 4 Jul, 2009 - 07:30 PM, said:

This thread helped me, thanks.




Wow your sig has made me extremely hungry for pancakes right now
Was This Post Helpful? 0
  • +
  • -

#9 oppenheimer230  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 16
  • Joined: 03-July 09

Re: Proper Formatting

Posted 04 July 2009 - 08:45 PM

Ah, how about it when people don't even use the code tags and all the tabs get eaten...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1