[ home / board list / faq / random / create / bans / search / manage / irc ] [ ]

/prog/ - Programming

Programming board

Catalog

8chan Bitcoin address: 1NpQaXqmCBji6gfX8UgaQEmEstvVY7U32C
The next generation of Infinity is here (discussion) (contribute)
A message from @CodeMonkeyZ, 2ch lead developer: "How Hiroyuki Nishimura will sell 4chan data"
Name
Email
Subject
Comment *
File
* = required field[▶ Show post options & limits]
Confused? See the FAQ.
Embed
(replaces files and can be used instead)
Options
Password (For file and post deletion.)

Allowed file types:jpg, jpeg, gif, png, webm, mp4, pdf
Max filesize is 8 MB.
Max image dimensions are 10000 x 10000.
You may upload 1 per post.


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

9a74c7 No.992

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…

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

f2f13f No.997

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

9a74c7 No.1003

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

>>997
OH GOD! NO!

8ff1a8 No.1005

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

cdabc9 No.1006


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

master race

4259fe No.1010

>>1006
>>992

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 {

351b33 No.1012

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

164ab8 No.1015

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

7f9f8a No.1035

>>1012
GNU QUALITY

5d4014 No.1036

>>1035
GNU/Quality

6cb029 No.1037

>>1012
Actually that's functional programming style

01462e No.1038

Why is the shitty one shit?

06065f No.1075


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

f2f13f No.1092

>>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
{
—————————

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

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

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

b16891 No.1248

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

a79f07 No.1250

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

b16891 No.1252

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

a79f07 No.1254

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

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

01f84a No.1273

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

3031bb No.1316

Always use best, no matter how short.


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

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

a79f07 No.1318

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

952b31 No.1321

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

1891b2 No.1323

>>1316
Retardation.

d90d50 No.1327

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


f1f5bb No.1337

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

>using braces

47324c No.1341

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

b6aaf6 No.1353

>>1327

fucking this

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

165a45 No.1390

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

7c8157 No.1392

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

1c669b No.1394

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.

bc642b No.1395

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

bc642b No.1396

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

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

1c669b No.1398

>>1396
Thank you jesus.

bc642b No.1399

>>1398
Fuck Jesus, thank me.

1c669b No.1401

>>1399
l-lewd.

025b71 No.1527

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

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

e3553d No.1533

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

025b71 No.1535

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

a79f07 No.1536

>>1535
YES ITS TRUE

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


c9e1a1 No.2543

I use this:


if (condition) {
}
else {
}


064156 No.2574

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


4b5d36 No.2581

>>2543

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


83cc18 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


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


fbef71 No.2674

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

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


98ecad No.2708

How about this?


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


26675c No.2712

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


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


89e6ca No.2766


if (short) statement;

if (medium_length)
statement;

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


7448f4 No.2777

(if condition then else)

postfix master race coming through.


ff477d No.2800

>>1075

nah


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

master-race

also c++ master-race :^)


ae57cd No.2834

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


dbe54e No.2903

>>2800

javascript masturbace


f3b833 No.2913

>>2834

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


4a3d93 No.2949

>>992

<code>

switch(condition) {

case 0:

break;

case 1:

break;

}

</code>


23ea42 No.2959

>>1337

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


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


59aa4c No.2968

You do this


if
{
statement;
}

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


04118c No.2971

>>992

These ratings are in reverse.


249d0e No.2976



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


4e81de No.2997

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


c580b9 No.3002

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.


bc4bcf No.3052

>>2997

There's an emacs plugin to fix that


9525e5 No.3053

>>3002


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


64c529 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][Post a Reply]
Delete Post [ ]
[]
[ home / board list / faq / random / create / bans / search / manage / irc ] [ ]