If you use the layout on the right, you're an asshole.
>>58119731
kys
>>58119731
kys pls now
Only one right
>>58119731
us programmers, right guys?
>>58119734
If short loopfor (int x; x < 10; x++) { cout << "faggot";}
typical style guide for c++
class Foo
{
private:
int num;
public:
void set(int&);
int get(int&);
};
void Foo::set(int &x) {
this->x = x;
}
int Foo::get(int &x) {
this->x = x;
}
Can't help but think that people who prefer the left would be much better of with a bracketless language like Python
>>58119731
>>58119731
kys. Both are functional equally but right is
A E S T H E T I C
>>58119872
learn to code
x isn't an attribute of Foo, num is.
Used the right style as a C programmer for the last 15 years, been using Go for the last year or so and quite happy that it enforces the same style.
when using memcpy to copy over a single uint32_t, is it better to do:memcpy(buf, num, sizeof(uint32_t));
//or
memcpy(buf, num, 4);
?
>>58120047
shit I thought this was dpt
>>58119731
I use left. Its easier to read.
>>58119731
I have a phobia of collapsing blocks of code in editors, so need to save all the lines I can, so I use right.
Also helps the strange little Java convention of 'you've fucked up if your line doesn't end with one of {, }, or ;
>>58119731
pretty sure theres a third kind that doesnt obsess over indentation or language
people who prefer right are the same idiots that take 2min to find a missing brace
if you think of opening curly brace as "then" then left one starts to look like something a complete spastic who breaks lines mid sentence could write.
Only right.
Left is more readable
Right saves vertical space
pick your poison
>>58119731
Right is just better. If indentation isn't enough and your brain only can match braces to braces, go see a psychiatrist. And then kys.
>>58120347
You are thinking wrong.
braces don't signify "then" or "do these things"
they signify blocks. if you don't know what that means then stop what you are doing right now and pick up a book.
You can easily tell someone is code monkeys who use shit languages like java, javascript etc. when they open brackets in the middle of a line
I don't care as long as it's indented properly
>>58119731
i thought you didn't needed to place flower bracket in if statements
javascript -> right, c#/c++ -> left
>>58120538
>if you think of opening curly brace as
Can you into basic linguistic devices or is everything literal to you?
java/javascript: right
C,C#,C++: left
ez pz
>>58121143
this
>>58119731
for anyone who has had a job as a programmer, left is completely superior in every way. If you write bad minecraft clones in java all day, own a mac, and just love fat hairy dick, the right is for you.
>>58120743
don't have to. you should though.
if your statement is
if(...)
statement1;
and you later remember that you want it to do statement2 before statement1 you could make the mistake of simply adding it in front of it like
if(...)
statement2;
statement1;
that will make statement1 unconditional, ruining the behaviour of your code. usually you notice things like this, but everyone has a bad day/bad co-worker sometimes, and having things break over two keypresses is usually not worth it.
>>58121143
Fuck off, right is literally K&R guidelines for writing proper C.
I don't understand how people can prefer left, other than "it's what i was taught"
>>58121284
Exactly. Was taught this way in the mid 90s. Op left style is disgusting.
>>58121245
You should also put a fucking space between the if and the parentheses.
>>58120538
An if statement implies a block. Having the curly brace on an extra line is simply redundant and a waste of space if that's your whole point.
Left is superior in that you can comment out the iff statement without breaking your code. This can be useful sometimes. However, nothing's stopping you from moving the brace down for the sake of disabling the statement, should the need arise.
So for cleanliness' sake and readability, I still prefer right, even though I am awar that left may have subtle benefits in some cases.
>>58119872
>Single line statement
>Curly brackets
Get the fuck out.
>>58119731
kys
Left is more readable and elegant.
Right looks nice as well, but not as neat as the left.
I used to HATE the one on the right, but now I don't mind it.
>>58119941
I see a lot of that too in Nginx configs, but why not left? It's really easier to read.
You may also use if (condition) {statement}.
>>58121533
>easier to read
in the sense thatconst char* constCharPointer_theFormatString = "%.2f";
printf
( // calling printf
constCharPointer_theFormatString, // argument 1
3.0 // argument #2
); // end of calling printf
is easier to read thanprintf("%.2f", 3.0)
>>58119731if ( statement ) {
foo();
bar();
} else if ( statement ) {
foo();
bar();
} else {
foo();
bar();
}
>>58121681
*if ( (statement == true) )
>>58119731
what about the 3rd type
people who like whitespace
>>58119872
For C++, what you usually see is that for class declarations and method definitions, the curly brace goes on the new line, but that for other stuff like if statements, for loops etc, the curly brace goes on the same line (K&R). I've never seen anyone say that class declarations go on a new line, but that method definitions don't.
Also:
> not prefixing your privates with an underscore
> Making the int in the setter a ref, therefore forcing it to be an lvalue. set(3) isn't possible this way. I fucking hate people who make everything a ref for no fucking reason.
> getter actually setting something
> using some undeclared x member
> using a single line for loop without actually making it a proper single line statement (single line statements are bug magnets either way)
Linux kernel style uses layout on the right for everything other than functions, which use the left layout. Same for Stroustrup style and K&R style. I generally tend to prefer these styles.
And for what it's worth, there's more than just these two styles.
I use left for C#, right for js/ts
>>58121533
>easier to read
Well this is subjective. I'm used to the style on the right so I find it easier to read, and I'm sure the same is true for people who prefer the left.
>>58119731
what you use should be circumstantial
but in order of importance, comply with:
>the code base you're working on
>language convention
>personal preference
>>58121681
this reminds me of something but I don't know what it is
Usually most people are fine with either one as long as it's consistent, which is why I try to mix both of them to fuck everything up.
>>58119731
newsflash, if you plan on being a programmer, you will be reading/fixing a lot of peoples legacy code. You will see much more triggering stuff than this.
This is literally nothing
>>58119734
>>58119764
K brb guys