This is a discussion on indenting code - different styles within the A Brief History of Cprogramming.com forums, part of the Community Boards category; Originally Posted by sept This 1) Code: ptr = static_cast <int *> ( realloc(ptr, sizeof(*ptr)) ); is far better readable ...
Is that when I became booksexual? phantomotap
I just want to use my computer in a productive manner, not learn how to use it. Elysia
A year spent in artificial intelligence is enough to make one believe in God. Alan J. Perlis
> For nuances for if, else and such I use tabs. Imho tabs are much more easy to write for me (using visual studio).
> It`s also more easy to change the nuances if you use tabs (in case of removing one of multiple ifs for example)
1. If you post code to a forum / mailing list, the result is almost always "what we get is NOT what you see". This is even more true if you've set the IDE to be something other than 8 spaces.
2. The IDE is smart enough to figure out indent. You can for example highlight a whole block of code and press tab to indent one level and shift-tab to undent one level.
Coupled with auto indent as you type, most of the time it isn't a problem at all.
> Is there already some program which can change the style of the source? Like 1) to 2) would be awesome.
Loads of them
If you have cygwin / Linux, then
> Which one does he want to see? Cater to him, because he's giving the grade.
The first style is that of whoever is giving the marks / writing the pay cheque.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
I have two styles.....
The style I use at work. I write assuming someone will have to fix the bugs in the code a few months/years down the track (train pun...).
I want to make my intent as clear as possible, the code as readable as I can and so (hopefully) make the fix easier. I even put braces around single lines of code. I use 'allman'.
The style I use when I write code that _only_ I will read again. I write it as fast as possible with few comments and no spaces.
"Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
"I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
"If you are going through hell....keep going."