One of the most important debates has now been settled.

Page 2 - Seeking answers? Join the AnandTech community: where nearly half-a-million members share solutions and discuss the latest tech.

brianmanahan

Lifer
Sep 2, 2006
24,300
5,730
136
And whyTF would you prefer K&R starting bracket toward the end of the line when it's so much easier/cleaner to read at the beginning of the next line?

spoiler: it is not easier or cleaner to read opening curly braces on their own line because they are, in fact, an eyesore and a blight
 

Alpha One Seven

Golden Member
Sep 11, 2017
1,098
124
66
I don't understand why anyone would prefer spaces over tabs. When I'm typing and coding I want to get shit done as fast as I can. Pressing 1 button vs. pressing 4 buttons is simply more efficient, especially over a period of time.
This and a lot of macros ftw.
 

brianmanahan

Lifer
Sep 2, 2006
24,300
5,730
136
For some reason I cannot believe this is the case.

oops i forgot - i do typescript too. even though it's a microsoft language, i allow it because it is much much nicer than javascript.

(i suppose you could say the same about c# and java but i gotta draw the line somewhere
)
 

Belegost

Golden Member
Feb 20, 2001
1,807
19
81
Man some of the formatting described in here makes me so ill I want to vomit. You people should be ashamed.

2 spaces shall you indent, not 1, not 3, 2. 4 is right out! Tabs are for godless heathens and their inbred devil spawn.

Curly braces are on their own line, with the indentation of the scope they are opened in. They are not just plastered willy-nilly at the end of lines like cheap semi-colon knockoffs, and they damned well are not indented to the level of the scope they open.

Local variables are lower case, underscore separated. CamelCase is for monsters.

Member variables are indicated by trailing underscore.

Classes, namespaces, and similar are denoted with a leading capital.

I would add a /s here, but I'm honestly so sick of seeing disgustingly formatted code that looks like it was shat out by a goat...
 

brianmanahan

Lifer
Sep 2, 2006
24,300
5,730
136
tbh it's best to just use python so there aren't even any curly braces to deal with

i was never able to get a job with python though
 

Red Squirrel

No Lifer
May 24, 2003
67,904
12,373
126
www.anyf.ca
Ugh I hate when people put curly braces on the same line as actual code. They should always be on their own line!

I want a very clear visual definition between blocks of code. The "wasted" space serves a purpose.

This:

Code:
function()
{
	for(int i=0;i<5;i++)
	{
		somecode();
		if(condition)
		{
			dosomething();
		}
	}
}

is cleaner than this:

Code:
function() {
	for(int i=0;i<5;i++) {
		somecode();
		if(condition){
			dosomething();
		}
	}
}

There is also less chance of accidentally deleting or moving a brace if modifying code.

Normally if I find myself going more than like 5-6 levels deep into nested statements, I start to look into if I can do better OOP to simplify it.

What is crazy is I wrote a forum software years back... before I even knew what OOP is, and before I learned the importance of indenting code. What a maintenance nightmare lol. It worked great though! But good luck maintaining it. There's actually not all that many decent free php forum scripts out there, I'd have to look at picking up that project again, but I think it would be easier to just do a rewrite.
 

purbeast0

No Lifer
Sep 13, 2001
52,930
5,802
126
Ugh I hate when people put curly braces on the same line as actual code. They should always be on their own line!

I want a very clear visual definition between blocks of code. The "wasted" space serves a purpose.

This:

Code:
function()
{
    for(int i=0;i<5;i++)
    {
        somecode();
        if(condition)
        {
            dosomething();
        }
    }
}

is cleaner than this:

Code:
function() {
    for(int i=0;i<5;i++) {
        somecode();
        if(condition){
            dosomething();
        }
    }
}

There is also less chance of accidentally deleting or moving a brace if modifying code.

Normally if I find myself going more than like 5-6 levels deep into nested statements, I start to look into if I can do better OOP to simplify it.

What is crazy is I wrote a forum software years back... before I even knew what OOP is, and before I learned the importance of indenting code. What a maintenance nightmare lol. It worked great though! But good luck maintaining it. There's actually not all that many decent free php forum scripts out there, I'd have to look at picking up that project again, but I think it would be easier to just do a rewrite.
So much wasted space in the first example.

Similarly, a thing I hate is when people put the closing } on the same line as the else in an if/else statement.

Code:
if (blah) {
  good();
} else {
  bad();
}

It just doesn't read well, especially if you have some else if statements in the mix, and not much functionality going on inside of the blocks.
 

brianmanahan

Lifer
Sep 2, 2006
24,300
5,730
136
Similarly, a thing I hate is when people put the closing } on the same line as the else in an if/else statement.

Code:
if (blah) {
  good();
} else {
  bad();
}

It just doesn't read well, especially if you have some else if statements in the mix, and not much functionality going on inside of the blocks.

i hate that too! but for some reason intellij has been complaining unless i do it that way in typescript files. i think maybe i need to edit the tslint configuration.
 

BurnItDwn

Lifer
Oct 10, 1999
26,127
1,604
126
ehh, mostly I'm woking in C or ksh in pure CLI environments. I like to use tabstop of 2, but most folks seem to prefer 4 or more. Helps to keep things from getting super wide when you have deeply nested code.

In any case, Indent with tabs as long as tabstop is consistent. (Worst is when you are maintaining legacy code which had been authored like 20 years ago, and 50 other people have touched things before you, so it's all completely crazy inconsistent)
 

Belegost

Golden Member
Feb 20, 2001
1,807
19
81
Ugh I hate when people put curly braces on the same line as actual code. They should always be on their own line!

I want a very clear visual definition between blocks of code. The "wasted" space serves a purpose.

This:

[omitted because "wasted space!!"]
is cleaner than this:


There is also less chance of accidentally deleting or moving a brace if modifying code.

Normally if I find myself going more than like 5-6 levels deep into nested statements, I start to look into if I can do better OOP to simplify it.

What is crazy is I wrote a forum software years back... before I even knew what OOP is, and before I learned the importance of indenting code. What a maintenance nightmare lol. It worked great though! But good luck maintaining it. There's actually not all that many decent free php forum scripts out there, I'd have to look at picking up that project again, but I think it would be easier to just do a rewrite.

I completely agree, and I don't know why people are worried about "wasted space" - you're not going to run out of lines in the file, and if you have anything like a modern display you'll have plenty of area to display on.

However, the indent is too much for me, 2 spaces is premium goodness:
Code:
function()
{
  for(int i=0;i<5;i++)
  {
    somecode();
    if(condition)
    {
      dosomething();
    }
  }
}
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |