[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Starting to program, wondering about bracket placement. So..

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 19
Thread images: 1

File: mixed.jpg (17KB, 482x237px) Image search: [Google]
mixed.jpg
17KB, 482x237px
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.
>>
>>59260041
>>
>>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 do
if (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()
Thread posts: 19
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.