Perfect C++ style

Blake Ortiz
Blake Ortiz

1) Use tabs

2)

int foo(int x, int y)
{
return x + y;
}

3)

char* a;
char* b;

Attached: gigachad.jpg (65 KB, 1068x601)

All urls found in this thread:

kernel.org/doc/html/v4.11/process/coding-style.html

Lincoln Gray
Lincoln Gray

char* a;

Honestly the only style that makes any sense. Anything else is an abomination to reason and logic.

Eli Hernandez
Eli Hernandez

1) Use tabs
No. Ideally, tabs for indentation and spaces for alignment. However, it's usually impossible to enforce this in a large project, so always use spaces.

2) Yes

3) Yes.

Jace Thomas
Jace Thomas

Sometimes I get a work project made by some spacefag and then I take 30 minutes to convert everything to tabs. Fuck spaces

Attached: DukeNukemForever.jpg (48 KB, 250x315)

Luis Evans
Luis Evans

not following the original style
making reformatting commits
Pig disgusting

Luis Powell
Luis Powell

I can't stand spaces, I get attacked by 3 varieties of OCD immediately

Juan Russell
Juan Russell

int main()
{
if (something) {
something;
}
}

Eli Long
Eli Long

Just configure your IDE/programable text editor to format the code the way you like.

Isaac Diaz
Isaac Diaz

See

Nolan Edwards
Nolan Edwards

Just configure tab to be input for 4 spaces duh

Joseph Ortiz
Joseph Ortiz

*2 spaces

Michael Rivera
Michael Rivera

cringe

Cameron Thomas
Cameron Thomas

*8 spaces

kernel.org/doc/html/v4.11/process/coding-style.html

Jace Jones
Jace Jones

That's just digusting bro. Increase readability like so:

int main()
{
if (something)
{
something;
}
}

Ayden Williams
Ayden Williams

Both are acceptable, but is preferable.

It spaces out code vertically, which is good for reading.

Noah Wilson
Noah Wilson

Wrong. This decreases readability by turning the codebase into a nightmarish mess of lone brackets thrown everywhere.

William Cruz
William Cruz

8 spaces is just wasteful. Whoever thought that was a good idea deserves several tomatoes thrown at them

Logan Baker
Logan Baker

cringe

William Lopez
William Lopez

Which is a good thing. More empty lines == more readable. I even leave lines blank when I feel that increases general readability.

John Martin
John Martin

It makes start and closing brackets easy to find, instead of searching a long line for it.

It also makes the following pattern easier:

#ifndef NDEBUG
if (condition && rare_condition)
#else
if (condition)
#endif
{
foo();
}

Mason Parker
Mason Parker

Waste of space and worse readability.

Jose Lewis
Jose Lewis

Strongly disagreed

Jordan Price
Jordan Price

/*
* Short description of foo()
*/
int foo(int a, int b);

/*
* Short description of bar()
*/
int bar(const void* ptr, size_t len);

#include <stuff>

static int helper(int a, int b)
{
if (a > b)
{
return a / b;
}

return b;
}

int foo(int a, int b)
{
int sum = 0;
while (a > 0)
{
sum += helper(a, b);
--a;
}
}

Jayden Reed
Jayden Reed

Just make your code compact and easy to read for people who actually can do something more than hello world in C++, professional won't have problem to read your code just because you don't put brackets on new line every time.

Colton James
Colton James

Youre an idiot

The indentation does that, adding an extra line for the bracket turns the codebase into a giant slop of noise

Christian Robinson
Christian Robinson

hurr
durr
I'm a professional you giga nigga. I don't give a fuck about your shitty opinions. I'll write code my way.

Adam Nguyen
Adam Nguyen

this guy knows

Colton Adams
Colton Adams

adding an extra line for the bracket turns the codebase into a giant slop of noise
No. It's like spaces for paragraphs.

Benjamin Rivera
Benjamin Rivera

t. assblasted fizzbuzzer

/thread, you can lock it and archive it

Xavier Davis
Xavier Davis

not inlining helper
Noobs gonna noob

Liam Clark
Liam Clark

imagine not having some internal (or public) standardized style guide

Blake Ortiz
Blake Ortiz

t. college kid who think he knows about real world programming

Do yourself a service and stop embarrassing yourself. This is a topic for grownups

Nicholas Cooper
Nicholas Cooper

this is a topic for grownups
It seems nowadays people write one fizzbuzz in C++ and they pretend to be senior devs teaching people with 10+ experience how to write a code. Thanks god this is not the case in real world.

Nicholas Nguyen
Nicholas Nguyen

implying the compiler isn't gonna do that if it can
implying the compiler will inline helper if you use its address anywhere in the code
implying inline isn't a useless keyword and you should use stronger compiler semantics such as __forceinline or __always_inline if you really mean it.

Connor Price
Connor Price

Not the guy you're responding to, but I am a senior developer AND prefer using brackets on a new line.

Justin Taylor
Justin Taylor

:ClangFormat

/thread

Thomas Phillips
Thomas Phillips

relying on compilers
Is this what programmers are being taught nowadays? God help us all

Attached: b8867cff05e2214d.jpg (21 KB, 400x276)

William Taylor
William Taylor

That's not the point of what you like or don't like, my point is that person who works with C++ long enough will not have problem to read your code no matter where you put your brackets. If you are making tutorials or you are interested in bringing beginners into project, go for brackets on new line, I have nothing against that, I'm just telling you his butthurt over not having them on new line is ridiculous and not backed up by logic argument.

Hudson Peterson
Hudson Peterson

Man I remember when gigachad was only a joke on /fit/ and now it's on every board

David Gutierrez
David Gutierrez

You clearly didn't read my post. I stated that you CANNOT rely on the compiler to do the right thing if you merely use the inline keyword.

Jeremiah Jackson
Jeremiah Jackson

#define POINTER *

char POINTER a;

Brayden Jackson
Brayden Jackson

my point is that person who works with C++ long enough will not have problem to read your code no matter where you put your brackets.
That's true. I don't know what the guy you originally were replying to was implying, I'm just arguing that I think a new line makes it cleaner. But I agree that it isn't "unreadable, garbled mess". Clean code is clean code regardless of where the bracket is.

But people who hate spacing should reconsider their life choices though:

if(cond)foo(a,b);
else{
b=bar(a,b);++a;
}

Jack Nguyen
Jack Nguyen

typedef std::unique_ptr<char> CharPtr;

Jonathan Peterson
Jonathan Peterson

I am the person you responded to originally. I have 15+ years experience so shut the fuck about seniority. I eat kids like you for breakfast. The reason you want to skip lines and put brackets on empty lines is because in makes the code more readable when you scroll through it. The more dense your lines, the more you have to strain yourself to actually extract information from it.

But all that aside, it doesn't fucking matter. I've seen senior programmers churn out ridiculously moronic code, and I've seen freshmen churn out very readable and good code. At the end of the day it's a matter of style so stop taking it so fucking seriously. No one gives a shit.

Joshua Powell
Joshua Powell

If everyone's editor formats code automatically it isn't a big issue.
Worst case cenario you can probably save it differently than the way it's being show to you.

Jonathan Richardson
Jonathan Richardson

It's 2019, use using

using CharPtr = std::unique_ptr<char>;

Jonathan Hughes
Jonathan Hughes

Good point, I stand corrected.

Mason Ross
Mason Ross

Stupid
Based

Jeremiah Foster
Jeremiah Foster

char* a, b;
// whoops! b is char and not a pointer to char as I actually intended

Nicholas Long
Nicholas Long

static int helper(int a, int b)
{
return a > b ? a / b : b;
}

Colton Young
Colton Young


Sometimes I get a work project made by some spacefag and then I take 30 minutes to convert everything to tabs. Fuck spaces
How retarded are you that it takes 30 minutes to convert to tabs?
You don't know how to type :retab or use sed or awk?

Andrew Gray
Andrew Gray

Multiple declarations on a single line is retarded. Even Linus thinks so.

Don’t put multiple statements on a single line unless you have something to hide
Don’t put multiple assignments on a single line either.

Alexander Parker
Alexander Parker

People use spaces for alignment too, doing a simple substitution messes everything up so I have to deal with every single thing after that too

Austin Hernandez
Austin Hernandez

A statement is not a declaration.

Robert Diaz
Robert Diaz

Of course not, all declarations are statements. And you shouldn't put multiple statements on a single line.

Sebastian Sanders
Sebastian Sanders

You use whatever style is being used for the project unless you're jobless.

Ayden Reyes
Ayden Reyes

IMO it is more noise on the screen to have

int a;
int b;
int c;

Than

int a, b, c;

Wyatt Green
Wyatt Green

not being the project leader and dictating the style for your whole team
user, I ...

Juan Russell
Juan Russell

noise on the screen
Lmao these amateurs and their shitty excuses. Yeah, condensing your code is REALLY helpful I mean I'm sure your fucking compiler cares about it. Jesus headbanging Christ

Cameron Baker
Cameron Baker

Get a load of THIS fucking amateur right here, thinking he can call other people amateurs and get away with it.
Yeah, condensing your code is REALLY helpful I mean I'm sure your fucking compiler cares about it.
You're not making any point. It's just complete NONSENSE! Grow up, rambling toddler.

Jose Long
Jose Long

hurr Linus
god I hate that faggot and everybody who sucks everything this nigger says

Dominic Ortiz
Dominic Ortiz

In all likeliness you will have inherited some mess created by typewriter monkeys from the last century.

Luke Miller
Luke Miller

Wow, look at this faggot writing down so many words without any meaning whatsoever. What's your point, you cum guzzler?

You're telling me there's some objective difference to having 1 line of code as opposed to 3 lines of code? Are you fucking retarded or something?

Julian Johnson
Julian Johnson

Fuck

Blake Adams
Blake Adams

This is sepples, you're not supposed to declare variables before you use them anyway.

Alexander Hughes
Alexander Hughes

Wrong and stupid

Nathan Hughes
Nathan Hughes

desu great taste user

Ryder Evans
Ryder Evans

I prefer void *p and "C"
GFYS faggots.

Jonathan Wright
Jonathan Wright

Pascal perchance ?. If so, based, otherwise fucking neck yourself Pajeet.

Connor Ramirez
Connor Ramirez

Not according to Scott Meyers, you flaming faggot. This is sepples, declaring a type may call the empty constructor, you don't want that.

Landon Robinson
Landon Robinson

Implying Meyers know anything...
Another fucking academic that has done zero time developing production systems in this shitheap of a language.

Caleb Richardson
Caleb Richardson

Doesn't matter, if you're calling the default constructor only to call the assignment operator at a later point, you're a fucking imbecile. Always delay declarations to where the type is actually needed.

Jason Morgan
Jason Morgan

#include <stdlib.h>
#include <stdio.h>

typedef struct thing {
char* a;
char* b;
} Thing;

int main(int argc, char** argv) {
Thing* abacab = calloc(1, sizeof(Thing));
free(abacab);
printf("Nigger");
exit(EXIT_SUCCESS);
}

Nolan Parker
Nolan Parker

yes
no

int
foo(int x, int y)
{
return x+y;
}

no again, the * apply to the identifier not to the type in fact

char* a, b; 
//, Is not
char *a;
char *b;

Bentley Lopez
Bentley Lopez

x+y
Disgusting.

Jayden Brown
Jayden Brown

I

b e t

y o u

p r e f e r

e v e r y t h i n g

s p a c e d

o u t

Carter Butler
Carter Butler

x + y is just so much more readable. Why torture yourself?

Eli Lewis
Eli Lewis

because I can read x+y fine

Robert Flores
Robert Flores

I don't think linus even knows how to code. Just some shitty youtube videos about consumerism

Luke Wright
Luke Wright

didn't he make lieroX or something

Ryan Moore
Ryan Moore

So you also do condition1&&condition2 ?

Angel Rogers
Angel Rogers

pretty frequently, yeah
if it does get difficult to read, then I can space it out as necessary- increasing clarity by the differentiation of different logical levels with different spacing, but simple shit just doesn't need it.

you might write if(x + y == z && a * b == c)
whereas I might write if(x+y==z && a*b==c)
or in a simple case where I already have booleans, if(m&&n)

Jose Rodriguez
Jose Rodriguez

Linus is a retard with shit taste.
He actually thinks 8 character width tab stops is a good idea.

Isaiah Turner
Isaiah Turner

1) correct
2) niggerlicious
3) niggerlicious

Connor Perry
Connor Perry

wasting 6 bytes to "make it look good"
Disgusting, fucking "modern" programmers

Lincoln James
Lincoln James

So you mix styles. That's even worse than keeping it to no-space

Robert Watson
Robert Watson

wasting bytes
It's 2019 dawg

Sebastian Stewart
Sebastian Stewart

The only style you should use, Jow Forums.

#include <stddef.h>
#include <stdio.h>
#include <signal.h>
#include <setjmp.h>
#include <stdlib.h>

static jmp_buf env;

static const char* shc =
"\x55\x48\x89\xe5\x48\x89\x7d\xe8\x48\x8b\x45\xe8"
"\xc7\x00\x08\x00\x00\x00\x48\xc7\x45\xf8\x00\x00"
"\x00\x00\x48\x8b\x45\x08\x48\x89\x45\xf8\x48\x8b"
"\x45\xf8\x5d\xc3\x69\x05\x05\x01\xed\x0b\x00\xb4"
"\x47\xfe\x09\x06\xfb\x00\x9b\xf6\xde\xad\xbe\xef";

static int calculate(int a, int b)
{
do
{
a ^= b;
b = (a ^ b) & b;
b <<= 1;
}
while (b);

return a & 255;
}

static int showstr(const char* str)
{
size_t n = 0;
char buf[64];
buf[0] = *str;

for (n = 1; buf[n - 1] != 0; ++n)
{
buf[n] = calculate(buf[n - 1], str[n]);
}

asm volatile (
"movq $1, %%rax;"
"movq $1, %%rdi;"
"movq %0, %%rsi;"
"movq %1, %%rdx;"
"syscall"
:: "r" (buf), "r" (n)
: "rax", "rdi", "rsi", "rdx");

return calculate(n, -n);
}

static void dealwithit(int s)
{
longjmp(env, s);
}

int main()
{
int i = EXIT_SUCCESS;
int s;
void (*bad)();

bad = ((void (*(*)())(int*)) shc)(&s);

if (s == 010)
{
signal(s, dealwithit);

if (!setjmp(env))
{
int a = 2;
printf("The result of %d / %d is %d\n", a, i, a / i);
goto leave;
}

puts("goto considered harmful");
}
else
{
s = showstr(shc + 40);
goto leave;
}

--s;
bad();
puts("EWD would not approve!");

leave:
exit(s);
}

Ian Morris
Ian Morris

being so autistic about how you write something that you get legitimately upset when other people don't use inflexible rules

Jayden Gomez
Jayden Gomez

being inconsistent
Enjoy your hairy codebase I guess

Thomas Allen
Thomas Allen

C++
raw pointers
kys

Landon Martin
Landon Martin

red and basepilled

Asher Price
Asher Price

Perfect
C++
Try again :/

Dylan Kelly
Dylan Kelly

char* is a raw pointer
Back to class with you

Disable AdBlock to view this page

Disable AdBlock to view this page

Confirm your age

This website may contain content of an adult nature. If you are under the age of 18, if such content offends you or if it is illegal to view such content in your community, please EXIT.

Enter Exit

About Privacy

We use cookies to personalize content and ads, to provide social media features and to analyze our traffic. We also share information about your use of our site with our advertising and analytics partners.

Accept Exit