Doesn't it just hurt your eyes...

Pages: 123... 5
Doesn't it just hurt your eyes when you see code written like

1
2
3
4
5
int main(){
   std::cout << "O Hai Thar";

   return 0;
}


How can anyone stand putting the bracket on the same line?
The guys that wrote Doom 3, the source code to which has been proclaimed to be the most readable that has ever been written, use that style of bracketing. Not a problem for me, better than the other methods to some.
closed account (3qX21hU5)
That is actually a very common style and a lot of people prefer it over other common styles. I have actually been debating on switching to K&R from my usual Allman style because of how many lines it can save you.
Last edited on
Nah, I use that all the time. I find it a waste of space to put the brace on its own line.
closed account (Dy7SLyTq)
i dont like that style fredbill30, but its easier to read
closed account (S6k9GNh0)
I use that style. I even even more radical styles as well:

http://liveworkspace.org/code/1Wg1vY$0

Of course, I would only do that in the case the arguments are verbose and go too far right to the screen.
closed account (Dy7SLyTq)
now, i know hes a beginner, but this hurts my eyes
http://www.cplusplus.com/forum/beginner/95900/#msg514657
:| I can't believe so many use that style (*puts gun to head*) :P
closed account (Dy7SLyTq)
live workspace or my link?
Live workspace. The link is disappointment only.
closed account (S6k9GNh0)
It's a personal style only. When I contribute to a project, I'll format using astyle, beautifier, or similar so people won't complain.

Some projects even have specifications as to how a certain piece of code should be formatted and provide commands to do it automatically using tools like stated above.
closed account (Dy7SLyTq)
whats the most common style out there when your writing software with a group (professionaly)
closed account (3qX21hU5)
It depends on the project. I wouldn't say there is a most common style. Usually in the beginning the project lead's will set out some guidelines on what formatting the project will use, how the documentation will be done, ect.

The general thing is they want everyone to be using the same formatting on the project because it increases readability.
Fredbill30 wrote:
:| I can't believe so many use that style (*puts gun to head*) :P


It even has its own name "Egyptian brackets" (:
closed account (3qX21hU5)
Actually it is called the K&R style, but it could be called that to just never heard it before.
@ tntxtnt * Pulls Trigger *
Last edited on by Fredbill30
I use mixed style. I think it helps with readability.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
void f()
{
    if (true)
    {
        do
        {
        }
        while (true);
    }
}

enum {
    ZERO,
    ONE
};

struct S {
    int i;
};

class C {
public:

    void mf() const
    {
    }
};

Last edited on
closed account (3qX21hU5)
Interesting so kind of like using different parentheses style's in loops, conditions and function calls. Which is quite common I have found.

1
2
3
4
5
6
7
8
9
while (something)

for (something, something, something)

if (something)

myFunctionCall(something, something);

string myString("String");


That is how I do it, anything that not a function, or initialization gets a space.
some people code like this, and it bugs the sh!t out of me when I want to read it. Especially on this website.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <stdio.h>
#include <stdlib.h>

int main(){
while(true)
{
int upper_bound = 1+ rand()%31;
while( upper_bound <= 32 ){
int sum = 0;
for(int i = 1; i <= upper_bound; i++){
sum += i;
}
printf("upper_bound = %d\nsum= %d\n", upper_bound, sum);
upper_bound++;
}
}
return 0;
}


Yeah, I coded that myself just to proof how bad of a style that can be especially without indentinng. I code like this, its called discipline and knowing how to use an ide.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int main()
{
   int a = 10, b = 2;  
   int temp = 0;
 
   temp = a;
   a = b;
   b = temp;   

   if( a == 2 && b == 10 )
         printf("success\n");
   else 
         printf("failure.\n");

   return  ( a * b );
}
Last edited on
This bracket style is part of Java coding standard, isn't it?

I use this style for struct declaration and (long) array initialization only, but when I first tried Java I saw it everywhere (:
Last edited on
Pages: 123... 5