Programming style

which one Sup Forums is the right way?

Attached: 2typesOfPpl.png (456x324, 60K)

Always 2.

The best move is not to code.

Haterz incoming.

Whilst I didn't initially like it, I am now fond of Windows style programming. When working on large Windows projects with other people, it's a breeze to read through other people's code on a 2k monitor. However you can't over do it with comments unlike what average programmers do. I doubt as solo devs you'll see this though.

DWORD
SomeFunction
(
DWORD varA,
PCHAR varB,
PBLA_STRUCT varC
)
{
DWORD ret = 0xFFFFFFFF;
HANDLE hVarD = INVALID_HANDLE;

if (varA && varB && varC)
{

//
// Ensure magic byte has been passed in
//

if (varA == 0xCC)
{

//
// Decrypt our secret message
//

varC->SomeField = varB ^ varA;
}
}
else
{
ret = BAD_ARG;
}

return ret;
}

left for functions, right for if, for and while

this

fuck the haterz lol, honestly C++ code can get ugly. using this/similar win style programming is so nice.

(if (test) (then) (else))

Superior.

if(something) {something
something
/*something*/
something}

Number 2

if (Condition) {
Statements
/*
...
*/ }

I like the indent so all variables are aligned.
But what is the point of redeclaring all variable types to something even worse than the shitty defaults? Is there a point besides making your code not portable?

Number 2

The only answer.

And your find this more comfy than this? Breaking return types, qualifiers and function arguments on their on their own lines is sometimes unavoidable, but putting parentheses on their own line is retarded.
DWORD
SomeFunction(DWORD varA,
PCHAR varB,
PBLA_STRUCT varC) {
DWORD ret = 0xFFFFFFFF;
HANDLE hVarD = INVALID_HANDLE;

if (varA && varB && varC) {
//
// Ensure magic byte has been passed in
//

if (varA == 0xCC) {
//
// Decrypt our secret message
//

varC->SomeField = varB ^ varA;
}
} else {
ret = BAD_ARG;
}

return ret;
}

>not
if (condition) {
//Always an empty line
Statements
}

>/*
>(space)*/

why? or is this a text editor throat fucking you?

Initialize all variables to FALSEY values. Forcing all who work on the function to consciously return a TRUEY value in the correct place.

This. If { is followed by 10+ lines of code, you should have a newline for readability. Otherwise, inline is fine.

>FALSEY
>TRUEY
*cringe*

right side, except in the case of function definitions

2

Second one since I've accidentally started programming mostly in Go

Although I use style 2, I whole heartedly agree that style 1 is superior. Not only does it look cleaner, it allows for faster bracket matching.

Bracket matching is the least of a daily programmer's problem anyways. Using style 2 is for lazy people like me lol

void
function (int params)
{

}

Fpbp

>65290719
2 if the whole function signature is on one line. 1 if it's not.

left

I just do whatever, no one cares

bad
only expressions should have a space before the parenthesis

Like any of this stuff matters. Debate something important, like cereal first versus milk first.

...Yes, I do put my opening brackets on their own line. How did you guess? >_>

>...
>>_>
It’s like I’m really on GameFAQs.

if single_condition
single_statement;

Do you ever just skip the parenthesis and brackets altogether Sup Forums?

If it enhances code readability, on occasion:

if a0
return 1;
else
return 0;

struct DataTypeName
{
int classMethodName() const
{
return classMemberName;
}

private:
int classMemberName = 0;
};

void functionName(bool argumentName)
{
const bool CONSTANT_NAME = true;

bool local_variable_name = !argumentName;

if(local_variable_name) {
return CONSTANT_NAME;
} else if(argumentName) {
return !CONSTANT_NAME;
} else {
Log::Instance()->info("you are a faggot");
}
}

Incorrect note symbols on both.
It should be // for javascript. It currently has css3 notation symbols.

>programming
>scripting

The existing style of the project, or if it's a new project, whatever code style is mandated by your company. If it's a personal project, your choice.

if(condition){Statements/*...*/}

this one is very similar to my style.

//******************\\
//********************\\
//**********************\\
//************************\\
//**************************\\
//****************************\\
/********************************/
/* */ /* */
/* */ /* */
/* */ if (Condition) { /* */
/* */ Statements /* */
/* */ /* */
/* */ /* */
/* */ } /* */
/********************************/


i build little houses to keep my code comfy and warm at night

always follow the style guide laid out for the project. Otherwise, I prefer and default to option 2

I've been doing this in my own code for a while, how is it for readability?

if (a < 0) return -1;
else if (a > 0) return 1;
else return 0;

Whichever one works best with my ide or the one being used by the previous people that worked on the code.

I was an advocate for the first one, but when I started needing to look through large amounts of code more, the second one makes more sense, especially for code condensing.

/thread

keked

Attached: 1489798507811.gif (375x375, 168K)

hate this shit

I'd like it better if the return statements were all tabbed out to line up vertically, but that's just my own preference

Allman notation is for patricians

Only one I use.

>tfw you don't put all code in one line
Jeez, y'all young whippersnappers are so edgy!

>falsey
Found the "Javascript artisan".

if (a < 0)
return -1;
if (a > 0)
return 1;
return 0;

The only correct answer

K&R is always right

allman is the only correct style

everything else is asymmetrical bullshit and looks like garbage when there's a ton of code

1 for classes
2 for functions

jesus christ how do you live with yourself?

If you write an if statement without braces you deserve to be shot.

Unless you hate working with others, never skip out on the parenthesis unless it's a delegate that spans only one line.

Same thing with shorthand if statements, and absolutely never put two shorthand if statements in one declaration. As a rule I'd always opt for the longer but easier to read option over the short and vague.

>my style is better than yours (patronizing edition)

Checking for 0xCC is probably a bad idea since that's the value that uninitialized variables are set to when compiled with DEBUG, could lead to some hard to find bugs. But what do I know.

AFAIK ieach uninitialized BYTE is in debug mode initialized as 0xCC in Visual Studio.
varA is a DWORD, so if it was uninitialized it would be unintialized as 0xCCCCCCCC. 0xCC is the same as 0x000000CC, so those two are different.

Attached: coding.jpg (594x249, 33K)

For me, it's K&R
funtion()
{
if(...){
do
}
}

THIS
CMP EAX, EBX
JE label
label:
; some shit.

This:
if (condition){some; shit; here;}
Because fuck pajeets, that are working with me. Why I should make everything readable, if they comment in curry.

This is the only correct answer.

void
bstreeInit (BSTree * tree,
int (*pCompare) (void *pDataA, void *pDataB),
void (*pDestroy) (void *pData))
{
tree->size = 0;
tree->pRoot = NULL;
tree->pCompare = pCompare;
tree->pDestroy = pDestroy;
return;
}

void
bstreeDestroy (BSTree * tree)
{
if (bstree_root (tree) == NULL)
{
return;
}
else
{
bstreeDestroyNode (tree, bstree_root (tree));
bstree_root (tree) = NULL;
tree->pDestroy = NULL;
tree->pCompare = NULL;
tree->size = 0;
}
return;
}

you misspelled
/*something
*/something

Keked. Will use this in my next project.

fpbp

Attached: trump_laughter.webm (640x480, 167K)

>2017 + 1
>there are people on this board RIGHT NOW who DON’T make their code comfy with tiny houses

Attached: AC814121-789A-41CE-9E9F-2592A1FF54B0.jpg (1136x636, 99K)

#2 is the only answer. Anything else is for gayfers.

Oh right

I use
if( Condition ){
Statements
}
It may not be the most popular, but it is the best and the most logical.

Why the fuck would you put a space between syntax? It's useless. What's more important is the readability of the condition.
Do you really get confused that something is an if condition if it's "if( " instead of "if ("? That's why you have syntax highlighting.

oficially posting in epic bread

lel

I do the left thing but the right one looks way better actually

return a/abs(a);
*works in c*

>implying division with anything ever gives 0

I think the main point of writing stuff in C is getting the absolute most out of your CPU. But what the fuck is the point if you are doing it wrong anyways?

Oops, was stuck in math world for a sec. Anyways, the point still stands. Division one of the slowest things you can do on a CPU.

ok, this then:
return (x > 0) - (x < 0);

I started as left, ended up right.

how is this so good

Neither, I use Haskell and don't have to deal with this autistic shit

Attached: 1470554924512.png (1280x800, 341K)

disgusting

why not both?

>put code in fortress

secure.

inline that shit
return (a < 0) ? -1 : ((a > 0) ? 1 : 0 );

if (2 + 2 = 4) then
return "lua doesn't have this problem"
end

>no indents

fuck off

meant to say ==

K&R all the way. Allman is unaesthetic as fuck.

Left side for Function Definitions
Right side for if statements or loops