Perfect C++ style

1) Use tabs

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


3)
char* a;
char* b;

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

Other urls found in this thread:

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

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

>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.

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 (250x315, 48K)

>not following the original style
>making reformatting commits
Pig disgusting

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

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

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

See

Just configure tab to be input for 4 spaces duh

*2 spaces

cringe

*8 spaces

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

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

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

Both are acceptable, but is preferable.

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

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

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

cringe

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

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();
}

Waste of space and worse readability.

Strongly disagreed

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


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


#include


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;
}
}

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.

Youre an idiot

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

>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.

this guy knows

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

t. assblasted fizzbuzzer

/thread, you can lock it and archive it

>not inlining helper
Noobs gonna noob

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

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

>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.

>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.

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

:ClangFormat

/thread

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

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

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.

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

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.

#define POINTER *

char POINTER a;

>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;
}

typedef std::unique_ptr CharPtr;

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.

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.

It's 2019, use using
using CharPtr = std::unique_ptr;

Good point, I stand corrected.

Stupid
Based

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

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

>
>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?

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.

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

A statement is not a declaration.

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

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

IMO it is more noise on the screen to have
int a;
int b;
int c;


Than
int a, b, c;

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

>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

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.

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

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

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?

Fuck

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

Wrong and stupid

desu great taste user

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

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

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

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

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.

#include
#include

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);
}

>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;

>x+y
Disgusting.

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

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

because I can read x+y fine

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

didn't he make lieroX or something

So you also do condition1&&condition2 ?

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)

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

1) correct
2) niggerlicious
3) niggerlicious

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

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

>wasting bytes
It's 2019 dawg

The only style you should use, Jow Forums.

#include
#include
#include
#include
#include

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

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

>being inconsistent
Enjoy your hairy codebase I guess

>C++
>raw pointers
kys

red and basepilled

>Perfect
>C++
Try again :/

>char* is a raw pointer
Back to class with you