If you use the layout on the right, you're an asshole.
If you use the layout on the right, you're an asshole
kys
kys pls now
Only one right
us programmers, right guys?
If short loop
for (int x; x < 10; x++) { cout 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
kys. Both are functional equally but right is
A E S T H E T I C
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);
?
shit I thought this was dpt
I use left. Its easier to read.
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 ;
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
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.
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
i thought you didn't needed to place flower bracket in if statements
javascript -> right, c#/c++ -> left
>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
this
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.
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.
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"
Exactly. Was taught this way in the mid 90s. Op left style is disgusting.
You should also put a fucking space between the if and the parentheses.
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.
>Single line statement
>Curly brackets
Get the fuck out.
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.
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}.
>easier to read
in the sense that
const char* constCharPointer_theFormatString = "%.2f";
printf
( // calling printf
constCharPointer_theFormatString, // argument 1
3.0 // argument #2
); // end of calling printf
is easier to read than
printf("%.2f", 3.0)
if ( statement ) {
foo();
bar();
} else if ( statement ) {
foo();
bar();
} else {
foo();
bar();
}
*if ( (statement == true) )
what about the 3rd type
people who like whitespace
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
>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.
what you use should be circumstantial
but in order of importance, comply with:
>the code base you're working on
>language convention
>personal preference
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.
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
K brb guys