Starting to program, wondering about bracket placement. So..
This
method() {
good = true;
}
or this
method()
{
good = true;
}
The last one is better
Most ide automatically does this if you format it
Personally I prefer the 2nd but it looks stupid for small methods or if statements that only have 1 line to execute.
Honestly do what works for you but be consistent.
Doesnt really matter. Second one is what your compiler makes it look like if you format it
>>59264879
If its only one line, make a one-liner out of it.
>>59264880
Compilers don't do code formatting you moron. That's the job of a text editor/IDE.
>>59264983
I think he was talking of the IDE. Since many people call the IDE, a compiler.
I use
if (bla)
{
bla();
bla();
}
if (bla) { bla(); }
>>59265127
But why? The whole point of wrapping braces around a single statement is to make it easier to add extra ones later. In your case you have to completely reformat the whole block anyway so might as well just leave the braces out.
>>59265169
Sometimes you might have things you really don't want to change. Like if something happens you just want to increment a number or something.
Then again there's also the simplified process.
n = (bool) ? n++ : n;
First one is the only correct one, anyone who uses anything else should be shot
>>59265215
What I'm saying is, for those simple things, you doif (cond) n++;
>>59265272
Oh motherfucker, didn't know that. Thanks.
That's what happens when you learn C++ from cheap locally-written books.
>>59265215
>n = (bool) ? n++ : n;
With postfix ++, the incrementation happens _after_ the assignment, so your n remains unchanged in either case.
>>59265319
Read "The C++ programming language". Written by Bjarne Stroustroup, the creator of C++. It's the only book you'll need.
>>59264849
spoken like a true non-programmer
>>59264849
method(good = true + (other bullshit)) { return good }
>>59265127
if (cuck)
welcome()