[ / / / / / / / / / ] [ dir / ask / dcaco / fur / hypno / o / sl / ttgg / u ][Options][ watchlist ]

/prog/ - Programming

Programming board

Catalog

You can now write text to your AI-generated image at https://aiproto.com It is currently free to use for Proto members.
Name
Email
Subject
Comment *
File
Select/drop/paste files here
* = required field[▶ Show post options & limits]
Confused? See the FAQ.
Expand all images

File (hide): 1420093141344.png (762.67 KB, 415x863, 415:863, Screen Shot 2014-12-31 at ….png) (h) (u)

[–]

b1ab21 (2) No.992>>1010 >>1390 >>1395 >>2949 >>2971 [Watch Thread][Show All Posts]

Sorry guys, but I have seen that many people are using curly braces in a manner that is quite erroneous to the readability of code standards. pic related…

faaa71 (2) No.995

i guess you mean mixing different coding styles. *rolleyes*
actually I'm doing exactly that right now because I want to see what the recent trend about putting opening brackets on the same line is all about.
if I like it more than separate lines I'll switch.

b46afb (3) No.997>>1003 >>2574

I do the shitty version, which I actually find preferable to read but at some points I think I'm breaking lines too much especially when there's only 2 statements for the block.

But what about


if (condition)
{ statement;
statement;
} else
{ statement;
statement;
}

b1ab21 (2) No.1003

File (hide): 1420161123217.png (7.83 KB, 409x258, 409:258, Rage_face.png) (h) (u)

>>997
OH GOD! NO!

617ec5 (1) No.1005

I hate the curly braces opening at the end of a line thing that java and web artisans use.

6be6dc (1) No.1006>>1010


if (condition) {
statement;
} else {
statement;
}

master race

89907a (1) No.1010>>2581

>>1006
>>992 (OP)

I'm using the 'good' medium Stroustrup style.

Lines beginning with a symbol instead of a word hurts my readability, that's why I ditched } else {

6e910e (1) No.1012>>1015 >>1035 >>1037

    if(condition)
{ statement
; statement
;
} else
{ statement
; statement
;
}

faaa71 (2) No.1015

>>1012 I do hope it is a service oriented test-driven performance-aware real-time computing agile solution

6cf0d5 (1) No.1035>>1036

>>1012
GNU QUALITY

157c97 (1) No.1036

>>1035
GNU/Quality

6dac47 (1) No.1037

>>1012
Actually that's functional programming style

6b2700 (2) No.1038>>1092

Why is the shitty one shit?

190890 (1) No.1075>>2800


if(condition)
{statement
;statement
;}else
{statement
;statement
;}

b46afb (3) No.1092>>1242

>>1038
IMO it's non-issue for me, but my guess is that when the line is collapsed in w/e text editor the entire block is hidden like:

if {
————————

and not

if
{
—————————

6b2700 (2) No.1242

>>1092
I see. When I fold the code I usually get something like:

int blahblah(string inp)
____________________________

when I type out all my brackets like the shitty version. I suppose it does really just depend on the editor other people are using.

1d3c70 (5) No.1243>>1248 >>1271

This argument fascinates me. "BEST" and "GOOD" are clearly pure shit for a very simple reason: THEY ARE NOT SYMMETRICAL. They leave the eye wandering around for the closing brace. It's impossible to have the opening and closing braces at an equal spacing from the margin with either style.

"SHIT" is the only logical solution. It makes your code easy to read.

Anyone who supports anything else is a faggot edgelord who wants compact "hacker" code and revels in the illegibility of his retarded, malformed code.

Can no one else articulate a reason for their preference? Perhaps not, because what I said is true.

fa5694 (2) No.1248>>1250 >>1368

>>1243
In the BEST style, the opening brace clearly belongs to the if statement and the block of code to be executed begins under the statement.

In the SHIT style, the if statement and the opening brace appear independent and the block of code begins under the brace, separated from the if statement.

Your eye is wandering because you are thinking of the closing brace as belonging to the opening brace rather than the if.

1d3c70 (5) No.1250>>1252

>>1248
What.

The if statement attaches to the code block, not the other way around. The most important part is the code block. The first thing you should see is the code block. Then you wonder, what is this code block for? Then you look at the beginning of the block and see the explanation directly above. All too logical.

How does the closing brace NOT belong to the opening brace in any case?

fa5694 (2) No.1252>>1254

>>1250
>The first thing you should see is the code block
If you're reading the file backwards.

>How does the closing brace NOT belong to the opening brace in any case?

Because both braces belong to the if.

1d3c70 (5) No.1254>>2574

>>1252
You ought see and read the most important thing first. The importance is in the functionality of the block, not whether or not it's executed, which is something that is not even decided until run-time….

OPEN and CLOSE. That's a pair. In every situation in the universe.

The if belongs to the block you fucking retard. The block is a whole fucking block of code. The if is a single line, a control statement.

Just quit now

b46afb (3) No.1271

>>1243
>This argument fascinates me. "BEST" and "GOOD" are clearly pure shit for a very simple reason: THEY ARE NOT SYMMETRICAL. They leave the eye wandering around for the closing brace. It's impossible to have the opening and closing braces at an equal spacing from the margin with either style.
I'm okay with either, but for the BEST/GOOD ones, the closing brace would be aligned with the if.

Though at most with the "SHIT" style I get antsy about the extra mostly blank space between the if statement and the block, especially when the block is only a few statements.

I'm mainly looking at indents even when I read C/C++ code.

1ec067 (1) No.1273

The 'SHIT' one unless the code between brackets is only 1 line.

7e3286 (1) No.1316>>1318 >>1323

Always use best, no matter how short.


//master race
if (bool) {
doSomething();
} else {
doSomethingElse();
}

//kill yourslef
if (bool)
doSomething();
else
doSomethingElse();

1d3c70 (5) No.1318>>1533

>>1316
wow, you are dumb

you are basically making the top one look like bottom one except with a bunch of fucking retardedly placed curly brackets everywhere

this is why i bomb people

c56275 (1) No.1321

I use 'shit' always. Even if it's just one line.

71b830 (1) No.1323>>1533

>>1316
Retardation.

ff4d00 (1) No.1327>>1353 >>2517

File (hide): 1424129481648.jpg (538.96 KB, 2559x1439, 2559:1439, oN6Bj.jpg) (h) (u)


c60cef (1) No.1337>>2959

File (hide): 1424176629813.jpg (330.55 KB, 900x848, 225:212, HA HA HA.jpg) (h) (u)

>using braces

14d33f (1) No.1341

I like C style because in my opinion having braces on the same line ends up making the code feel to squeezed.

94d6e1 (1) No.1353

>>1327

fucking this

4ee918 (2) No.1368

>>1248

>Your eye is wandering because you are thinking of the closing brace as belonging to the opening brace rather than the if.


Because that's true.

61a57c (1) No.1390

>>992 (OP)
I use //good on personal projects, but the project I'm working on at the moment uses the //shit style, and since it's not my project, I'm using it too.

742625 (1) No.1392>>1527 >>1528 >>2574

> writing code on several lines
lol what, can't you side scroll?
fucking plebs
if(condition){statement;}else{statement;}

668a1e (3) No.1394>>1396

I am learning ruby cna you help me out

print "What is best number?"
N= gets
if
N= 50
print "gj"
else
print "fucktard"
end


What is wrong here I cant figure it out.

dde62d (3) No.1395

>>992 (OP)
It really does not matter. I prefer the "SHIT" way because it makes it easier to see nested statements.

dde62d (3) No.1396>>1398

>>1394
print "What is best number?"
N = Integer(gets.chomp)

if N === 50
print "gj"
else
print "fucktard"
end

668a1e (3) No.1398>>1399

>>1396
Thank you jesus.

dde62d (3) No.1399>>1401

>>1398
Fuck Jesus, thank me.

668a1e (3) No.1401

>>1399
l-lewd.

4d059c (2) No.1527

>>1392
Or some editors, like vim, have wrapping.

11847f (1) No.1528

>>1392
this.

Widescreen monitors of the "FUUUUTURE" (
aka: today
); let you type full lines of code now.

no need to break anything

up

right
guys?

21f71f (1) No.1533>>1535

>>1318
>>1323

Faggots detected

if (am1318)
suckCocks();

But then you want to quickly add something else

if (am1318)
log("I don't have enough experience. Otherwise I'd always use braces.");
suckCocks(); // Uh oh, you're always sucking cock

4d059c (2) No.1535>>1536

>>1533
Don't be a sucky programmer and that won't happen to you.

1d3c70 (5) No.1536

>>1535
YES ITS TRUE

3ad4ae (1) No.2517

>>1327

I read from the first post with this image in the quick reply. Thanks for sparing me the effort of actually posting it.


2a59a0 (1) No.2543>>2574 >>2581

I use this:


if (condition) {
}
else {
}


8876a3 (1) No.2574>>2645

>>997

Oh sweet christ that is hideous.

>>1254

Holy fuck sperg harder. And be more wrong while you're at it.

Yeah, it's a code block. But it is defined by the if. Without the if, it's useless. If you use the SHIT style you are intentionally detaching the code block from its purpose, making it both harder to read and easier to make mistakes.

You are a SHITlord.

>>1392

R lets you write conditionals and functions with no braces if they evaluate on one line. I don't use it a lot but it is pretty nice.

>>2543

According to OP that is "GOOD". Honestly that is the most common format that I see. I prefer the "BEST" style myself because it helps group my conditional statements but your style is fine too. It's only the "SHIT" style that makes me want to kick babies.


bfd2e0 (1) No.2581

>>2543

I do that too. Mostly for the reasons >>1010 mentioned.


0de1f7 (1) No.2582

Is it bad if I do this


if ( 000 ) { 000 //000 = 000
} //if (000) close
if (111) {
111 //111 = 111
} //if (111) close


c80144 (1) No.2645

>>2574

>Without the if, it's useless.

Except for avoiding polluting your scope and marking the start/end of conceptual phases in a function.


ab3ea9 (1) No.2674

In VB.Net it uses the funny brace style as intellisense gets confused otherwise

Dim anonType = New With {
.Id = 1,
.Value = 999
}


3e06a5 (1) No.2708

How about this?


if
(condition)
{
statement;
}
else
{
statement;
}


2a2fc6 (1) No.2712

What is this weird blub language? I prefer normal, mainstream languages like Common Lisp.


{if (condition)
{(statement);}
else {(statement);}}


adac0d (1) No.2766


if (short) statement;

if (medium_length)
statement;

if (multiple_statements) {
statement;
statement;
}
else
statement;


59c8e9 (1) No.2777

(if condition then else)

postfix master race coming through.


45711d (1) No.2800>>2903

>>1075

nah


<predicate> ? <consequent> ! <alternative>;

master-race

also c++ master-race :^)


1e11ac (1) No.2834>>2913

The "Shit" one is the only one that has consistent spacing and indentation. The first 2 look much worse when nested.


ef8497 (1) No.2903

>>2800

javascript masturbace


440e17 (1) No.2913>>3201

>>2834

The shit one is also the only style that creates security holes.


9abd7a (1) No.2949

>>992 (OP)

<code>

switch(condition) {

case 0:

break;

case 1:

break;

}

</code>


6530a8 (1) No.2959

>>1337

pic src? it's so hawt i wanna fuck it D:


fa7da2 (1) No.2961

Either of these when it fits into 80-ish chars

if (condition) statement;
if (condition) {statement1; statement2}
If it doesn't then

if (condition) {
statement;
}
Doing this

if (condition)
{
statement;
}
just wastes so much space that it's not even funny. It's not that bad when it's just one or two conditions, but when you have 10 short conditions in a row, than the first option already saves 30 lines and if you add spaces to align similar parts it's also much more readable.


611b80 (1) No.2968

You do this


if
{
statement;
}

to match the braces up, otherwise finding and matching blocks is harder.


4ee918 (2) No.2971

>>992 (OP)

These ratings are in reverse.


ff3208 (1) No.2976



if(wat && areYouGuysFuckingSerious){
thisIsTheOnlyAcceptableAlternative();
}else{
dieInAFire();
}


17371f (1) No.2997>>3052

picked at random from GNU coreutils

http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/whoami.c

void
usage (int status)
{
if (status != EXIT_SUCCESS)
emit_try_help ();
else
{
printf (_("Usage: %s [OPTION]...\n"), program_name);
fputs (_("\
Print the user name associated with the current effective user ID.\n\
Same as id -un.\n\
\n\
"), stdout);
fputs (HELP_OPTION_DESCRIPTION, stdout);
fputs (VERSION_OPTION_DESCRIPTION, stdout);
emit_ancillary_info (PROGRAM_NAME);
}
exit (status);
}

if (year >= 2015 && !half_indented_braces)
{
shig(dig);
}


03889f (1) No.3002>>3053

Given we're talking about readability of code, the best way is the easiest way to read code, which means brackets need to be in line with each other.

If you have to spend any time looking or searching for another bracket, its bad. Should be a straight up its directly above or below.

Also fuck using any editor that doesn't highlight the opposing bracket.


97b0b6 (1) No.3052

>>2997

There's an emacs plugin to fix that


0913ec (1) No.3053

>>3002


if
(
bracketsInLine
)
{
print(
"
holy fuck you're retarded
"
);
}


2e1fd2 (1) No.3201

>>2913

How does it create security holes? It's more readable and the compiler can't tell the difference anyways.




[Return][Go to top][Catalog][Screencap][Update] ( Scroll to new posts) ( Auto) 5
70 replies | 3 images | 55 UIDs | Page ???
[Post a Reply]
[ / / / / / / / / / ] [ dir / ask / dcaco / fur / hypno / o / sl / ttgg / u ][ watchlist ]