What is your indentation preference ?

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

cKGunslinger

Lifer
Nov 29, 1999
16,408
57
91
Phase 1: Code deliberately

Code:
/*
** Iterator for <item>
*/
uint32_t   i = 0;

/*
** Pointer to the thing
*/
uint32_t  *my_pointer = NULL;


if ( NULL != my_pointer)
{
   /*
   ** Do the thing that generates the thing for purpose
   */
   manipulate_pointer( my_pointer,     /* param 1 description */
                       parameter_2,    /* param 2 description */
                       parameter_3 );  /* param 3 description */
}
else
{
  printf( "ERROR:  NULL pointer\n" );
}

/*
** Do the thing for each individual thing
*/
for ( i = 0;
      i < (the_maximum_value_of_i);
      i++ )
{
   /*
   ** Do the thing with i
   */
}
 

Chaotic42

Lifer
Jun 15, 2001
33,939
1,119
126
In general I like to indent four spaces, keep it under 100 columns, *always* use braces, even if I'm only writing one line in that block, and I like to like up variable names when doing declarations:

Code:
int         x;
int         y;
double      z;

for (x = 0; x < 20; x++)
{
    y = x;
}

Since we're talking about code style, when I write Python I like to avoid the convoluted list comprehensions everyone seems so fond of. Readable is better than compact.
 
Reactions: cKGunslinger

you2

Diamond Member
Apr 2, 2002
6,088
1,199
126
I indent 4 spaces; but keep braces on same line:

Code:
for(int i=0; i < 10; i++) {
    if( i == 0 ) {
        printf("no.\n");
    } else {
        printf("yes.\n");
    }
}
 

nevbie

Member
Jan 10, 2004
150
5
76
Allman. I never omit braces as I want the linear structure to stay universal. An indentation of 2 spaces.

For heavy macro usage that others don't need to read I may switch to a wall of code style that is more like encoding than writing. As long as it remains systematic enough.
 

Ajay

Lifer
Jan 8, 2001
16,094
8,110
136
Mostly K & R with 4 space indent if it's up to me. Normally, whatever system a company is using - no matter how bizarre.
 

Ajay

Lifer
Jan 8, 2001
16,094
8,110
136
Wow, at least two ppl here use 2 spaces; I wouldn't have guessed that.
 
Last edited:

Ajay

Lifer
Jan 8, 2001
16,094
8,110
136
Wow, salaries must be awful in some states. Starting salaries in the North East are higher than the median in that survey - and higher still in big cities.
 

Gryz

Golden Member
Aug 28, 2010
1,551
204
106
There is this little thing called cost of living.

I used to work for a US company in Silicon Valley (in one of their European offices). Now I work for a European company, but one of the 3 offices of our department is again in Silicon Valley. Our VP tries to lure everybody from Canada and Europe to come to Silicon Valley.

For the price of a small house in Silicon Valley, I can retire for the rest of my life in the country I live in now. (And my country is in the top 15 of richest countries in the world). What's the value of a high salary if everything around you costs 2x to 10x more money than that it costs where I live now ? Sure, the cost of a smartphone or a new graphicscard is the same world-wide. But those things don't matter. What matters is my house, the area I live in, cost of weekly groceries, the cost of a meal in a restaurant, the price of a beer in a bar, and many other mundane things. I've lived in Silicon Valley for a short while. I wouldn't consider myself poor. But over there I felt like a real pauper. No thanks. I wouldn't live there if they offered me double of my current salary. Nor triple or quadruple.
 
Last edited:

you2

Diamond Member
Apr 2, 2002
6,088
1,199
126
Also that survey doesn't really take into account the type of job. The jobs you find in Boston or Silicon Valley are very different than those in Nashville or Las Vegas.

Wow, salaries must be awful in some states. Starting salaries in the North East are higher than the median in that survey - and higher still in big cities.
 
Last edited:
May 11, 2008
20,606
1,165
126
Wow, at least two ppl here use 2 spaces; I wouldn't have guessed that.

I prefer and use 2 spaces for indentations as well for c code or assembly (hobby related). Combined with allman style i find it pleasant reading.
 

clamum

Lifer
Feb 13, 2003
26,252
403
126
I'll typically use whatever the "most normal" way is for that language/IDE. For C# it's (and if I have to choose, this is my preferred way to arrange the braces):

Code:
if (i == 1)
{
    Console.WriteLine("hory shet");
}

If I'm working on a native Android app then it'll be in Android Studio and it'll look like this:

Code:
if (balls.size() > 0) {
    ballsTextView.setVisibility(View.VISIBLE);
}

However I do not like that GNU style in the OP. That redacted would drive me nuts.


I also align "BEGIN" and "END" statements in SQL to mimic how braces would be in C#:

Code:
IF NOT EXISTS(SELECT * FROM sys.columns
             WHERE name = N'Billy' AND object_id = OBJECT_ID(N'JoeMomma'))
BEGIN
   ALTER
   TABLE   JoeMomma
   ADD       Billy BIT NOT NULL DEFAULT(0)
END

My co-worker indents the BEGIN/END (I guess like the GNU style) and I redacted hate it. Head asplodes

Swearing redacted -- Programming Moderator Ken g6
 
Last edited by a moderator:

HumblePie

Lifer
Oct 30, 2000
14,665
440
126
Started using Visual Studio Code for Angular 4 projects and the GNU style bracing with spacing is driving me nuts as well. All the examples are a mismatch of Allman and GNU and it's frustrating trying to debug various code snippets. This is on top of the inherently already big annoyance of using angular 4 in the first place. That is a whole other level of frustration since I started with angular 4 cli, and most of the samples I've found are for regular angular 4 or 2. Which don't always translate over in structure to what I'm using.
 

urvile

Golden Member
Aug 3, 2017
1,575
474
96
I use either a) the coding style dictated by resharper or b) follow whatever previous programmers have done in the file. Unless the previous style is incomprehensible. Sometimes the style is dictated by the preference of the team lead.

I currently work with a guy who puts an empty line in between each line of code and he doesn't do it consistently either. It drives me nuts.
 
Last edited:

HumblePie

Lifer
Oct 30, 2000
14,665
440
126
Visual Studio Code for AngularTS and Typescript right now is driving me nuts with it's forced styling format. Worse with the TS lint making bright red squigglies all over my screen if I don't do it exactly the way it wants despite the webpack transpiler not carrying one wit about TS lint's writing style.

Speaking of which, I refuse to call it Angular 2/4/5 or whatever naming scheme abomonation the Green Tea Team wants to use. Would prefer not to call it Angular at all since it has nothing to do with the original Angular JS framework. So I call it AngularTS and the other AngularJS to avoid confusion.
 

ringtail

Golden Member
Mar 10, 2012
1,030
34
91
When you’re programming in Python, WATCH OUT about this, because indentation white space is meaningful.
 
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/    |