You use Allman style, right?

You use Allman style, right?

Other urls found in this thread:

man.openbsd.org/style
twitter.com/NSFWRedditVideo

I use a lint.

Yes.

hell no, that looks awful.

int topcode1(int a) {
if (a == 1) {
cout

No, I don't newline after the opening bracket.
int topcode1(int a)
{ if (a == 1)
{ cout

off yourself.

only correct answer

only wage cucks need to worry about style. I write all my code in one line, its more efficient and harder for people to understand it.

That must be a pain in the ass to manage

>the problems of lesser creatures

def topcode1(a):
if (a==1):
print("Hello World")
return 20
else:
print("Hi World")
return 10

>I don't understand why anyone would have different preferences or use cases to me
haha yeah why doesn't everyone write everything in python am I right?

int topcode1(int a)
{
if (a == 1) {
cout

Indentation got fucked up but you get the point

I'm closing this PR

Yes. Mainly because it's clearer in where the brackets are.

This is the patrician style. Everything else is plebeian.

>put open braces on the same line
>put some closing braces on their own line
??

either go all or nothing
int topcode1(int a) {
if (a == 1) {
cout

I use it in ROBLOX
:3

man.openbsd.org/style

I'm having trouble getting my team members to adopt my consistent styling. What's the problem guys.

int
topcode1 (int a)
{ if (a == 1)
{ cout

Yes, but with operators separated by spaces.

This and only this

What

this is only good for java

void function(int a)
{
if (a) {
puts("a");
} else {
puts("!a");
}
}

indents are way too large

Indents are perfectly sized, see linux coding style.

>cuddled else
Pig disgusting

We have a winner lady's and gentoomen.

Next Question:

Is it okay to use

1.

if (a == 1)
cout

autism++;

void function(int a)
{
if (a) {
puts("a");
} else {
puts("!a");
}
}

Fixed

You only have one line after that if statement, making braces be not required and thus bad to use.

If it's multiline, you need braces.

if (a==1)
{
some code;
more code;
}

Option 2. It's easier to read explicit blocks and less prone to mistakes for if you ever need to edit the condition

If you have good style, which is to put a line break in between functions, then this is not a problem.

Thanks for proving the point, lesser creature.

What does line breaks between functions have to do with conditional blocks?

I think not using braces in that case just looks inconsistent and therefore ugly

I use 1 but on the same line if it's really short, otherwise 2.

Option 2. If you've inherited code to maintain, it's easy to overlook the block delineated in the first version.

K&R is the only correct answer.
I hope whoever came up with the GNU code style dies painfully of pancreatic cancer and their pets too

>First off, I’d suggest printing out a copy of the GNU coding standards, and NOT read it. Burn them, it’s a great symbolic gesture.

I use the Linux kernel style/Stroustrup style. Brace goes on newline only for functions.

The true patrician way
void foo(int a)
{
if (a == 1) {
std::cout

if (such_condition_is_true) execute_this();

The best way to understand and read code - in my opinion - is to write it like you would for an English sentence.
I hate &&, ||, !, ... genuinely write and or not on conditional statements because wasting 0.5 seconds for writing an "and" instead of "&&" will make everything that much more readable.

void foo(int a)
{
if (a == 1) std::cout

I've fixed so many bugs, caused by not using braces, so I always go with option 2, and enforce my will on those who work with me.

Lose the spaces

} else {

That's really hard to read.

>or should everything use {}

Pretty sure if the condition isn't met then the computer skips reading everything in the brackets, so technically that's the better choice for performance.

I use a code formatter that runs before checking in.

>Pretty sure if the condition isn't met then the computer skips
That's by definition what a conditional statement is. Are you still in middle school?

Yeah, well two things:
1. How do we know that just because the computer skips the program if the condition isn't met it doesn't actually read what's in the brackets?
2. I'm very new to this, so eat my dick.

You have really no clue right?
Brackets are just an abstraction for you, the CPU can only reason in jumps.
When a condition isn't satisfied the CPU will literally jump across all that code, just like you would with a puddle of water.

>} else {

EVERYTHING should have {}, not having them is how the OpenSSL bug happened.

the brackets are for grouping together statements
if the if is only followed by one statement they can be omitted
if (...) { do_something(); }
is 100% semantically equivalent to
if (...) do_something();

>How do we know that just because the computer skips the program if the condition isn't met it doesn't actually read what's in the brackets?
you can actually look at the code the compiler generates and see the exact instructions that get executed on the CPU
the meaning of that syntax is also defined in the standard

>I'm very new to this
then I'm not sure why you felt the need to opine on it with that kind of authority
I think you should aim to know what you're talking about before you go trying to tell it to someone else user

Only when I'm tryin to make a living, doing the best I can.

No, i use my own style of coding.

Brackets on the same line as the declaration of class or function and no spaces within. Same thing for operators and statements brackets such if/else blocks.

No.

Custom coding style is the fuel of satan

1TBS is the best, and you know it!...
.
.
.
Bitches.

Use Perl syntax

chomp (my $search = );
exit 0 if ($search eq "");
if ($search eq "1"){$search = "Class:";}
if ($search eq "2"){$search = "Individual:";}
if ($search eq "3"){$search = "ObjectProperty:";}

sup plebs
int
topcode1(int a)
{
if (a == 1)
{
cout

isItGay(girl) {
gay = true;
if(girl !== female) {
if(cute) {
return !gay;
} else {
return gay;
}
}
return gay;
}

no.
local mustardracecode = function(num)
if num == 1 then
print("Hello Sup Forums")
return 20
else
print("Hi Sup Forums")
return 10
end
end
but why do we return 20/10?

Literally nothing wrong with this.
Wasting 3 lines for an else is braindead tier, it's almost a line per character.

int topcode1(int a) {
if(a==1) {
cout

} else {
//this is the only way you're not wasting tons of lines
int sqr(int a) {
return a*a;
}
//no spaces for next field/method
void Obj(int a, String b) {this.a = a; this.b = b;}
//for constructors and get/sets

>hur let me just waste 3 lines every-time i have an else

std::vector oResponse;
oResponse = (a==1) ? "Hello World" : "Hi World";
count

that's me

>not K&R
Bloated trash.

>lambda fag

>patrician
>using a non-sane subset of sepples
Pick one.

Yes.

>Not doing
if (a==1)
printf(shit);
if (a==1)
printf(moreshit);

I spat my beer all over my screen, you glorious bastard, I love you, no homo

This.
Why waste a line on a single opening bracket?

only this

Someone post the pic of the guy that put all delimiters in the same column.

>what is Lua

Fuck please don't beat me up. I'm a second year CS student trying to learn Racket. Looks cool though. Any recommended reading?

I use project guidelines as I'm not a retard

Im a bad person if i do this?

void function(int a)
{
puts(a?:"a":"!a");
}

int topcode1(int a){ if (a == 1){cout

I write C code with Stroustrup style

nope, i make ascii art with my code (any halfway decent language is of course space insensitive.)

No, that is the correct use of a ternary operator.

In fact as long as neither of the two branches of a ternary operator are state-changing, then it's probably fine.

I prefer it this way. Is there a name for it?

>EVERYTHING should have {}, not having them is how the OpenSSL bug happened.

Is thus true? Source?

int topcode1(int a){
if(a==1){
cout

disgusting.

Allman style is best. Very clear what level of logic you're on if everybody indents consistently.

You'd be surprised how many inferior coders demand shit like or and waste precious time squabbling over typing style despite their own code not even working. Especially indochimps and gurl gamurz. It's painful working with that kind of garbage.

i too do it this way, i mostly use powershell but also python and bash.

You're fucking disgusting.

True patrician style coming through
#include
#include
#include

void fizzbuzz(int f, int b, int m);

int main(int argc, char* argv[])
{
int fizz_number = 3;
int buzz_number = 5;
int max_number = 100;

switch (argc) {
case 1:
break;
case 2:
fizz_number = atoi(argv[1]);
break;
case 3:
fizz_number = atoi(argv[1]);
buzz_number = atoi(argv[2]);
break;
case 4:
fizz_number = atoi(argv[1]);
buzz_number = atoi(argv[2]);
max_number = atoi(argv[3]);
break;
default:
puts("Usage: fb [fizz_number] [buzz_number] [max_number]");
return 1;
break;
}
fizzbuzz(fizz_number, buzz_number, max_number);
return 0;
}

void fizzbuzz(int f, int b, int m)
{
for (int i = 0; i < m; i++) {
if (i % f == 0 && i % b == 0)
puts("Fizzbuzz");
else if (i % f == 0)
puts("Fizz");
else if (i % b == 0)
puts("Buzz");
else
printf("%d\n", i);
}
}

I use lots of tabs to pretend everything is python

int topcode1(int a) {
if(a==1) {
cout

this is called "1tbs" or "the one true brace style"

aye

why not stick them all into another file and import them? code would be so much cleaner.

lil pump