[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Well?

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 169
Thread images: 23

File: vmjzfg5svzapgsppmxwe.jpg (12KB, 479x310px) Image search: [Google]
vmjzfg5svzapgsppmxwe.jpg
12KB, 479x310px
Well?
>>
>>60823160
i dont program but left
>>
>>60823160
if (condition)
statement
>>
>>60823160
left for functions right for if statements and stuff
>>
File: 1485473684854.png (408KB, 824x792px) Image search: [Google]
1485473684854.png
408KB, 824x792px
>>60823160
if (condition);
statement();

Is the only correct solution
>>
>OOP
lol
>>
if (condition)
single_line_statement;

if (condition) {
multi_line_statements;
}

if (condition) {
single_line_statement;
} else {
multi_line_statements;
}

Only way to fly
>>
I use left for C++ and right for Java.
>>
left if more readable when nesting.
>>
a good thread had to die for this piece of retarded shit
kill yourself
>>
>>60823160
left is more readable.
>>
>>60823221
>line bloat
>more readable
No.
>>
>>60823160
Whatever's the standard in the environment I work in. Say, on work I use left one since I'm doing C++ stuff, when I write Java or Go I use right style.

The only thing I care about is consistency, anything else is supeficial.
>>
>>60823160
Right is how you spot Pajeet.
>>
>>60823230
>a good thread
right, like your retarded /v/-tier graphics card threads. kys
>>
File: 10987f_6174967.jpg (134KB, 1140x813px) Image search: [Google]
10987f_6174967.jpg
134KB, 1140x813px
>>60823188
>if (condition);
>;
baka

Did you forget to wear pic related, Anon?
>>
>>60823160
I only use the ? operator and or single line if statements.

If it's multi line it should be a function.
>>
>>60823307
>>>/loo/
>>
>>60823301
No, it's supposed to be there, you degenerate.
>>
>>60823258
My man
>>
>>60823266

My ocd kicks in when I see right one.

{

code
{
moar code
}
}

Is how I envision statements. A pieces of blocks nested inside.
>>
>>60823177
This
>>
>>60823160
left makes it clear which parenthesis closes which without having to look at the end of the lines

so left
>>
File: 1483914634545.jpg (110KB, 400x300px) Image search: [Google]
1483914634545.jpg
110KB, 400x300px
>>60823160
Right because I like writing }else{
Also camelCase while we are at it

>>60823266
I learned from pajeet, guess that's the same. She forced me to write c++ on paper every week with strict grading requirements. I thought it was dumb at the time but I appreciate it a lot more now that I watch people fumble over basic bitch syntax errors on a regular basis. Would pajeet again desu.
>>
Sign that you're an idiot who can't program at all: you bikeshed about insignificant issues like this to make yourself feel smart.

Kill yourselves.
>>
>>60823177
kys
>>
File: Plank.png (225KB, 960x640px) Image search: [Google]
Plank.png
225KB, 960x640px
>>60823410
>>
>>60823221
>Nesting
You should be nesting more than 1 or at most 2 ifs.
>>
>>60823160
right
>>
>>60823160
Always left. I spent a lot of years programming Windows apps using MFC, and that's the MFC style.

Also, my brain is wired to be ultra-fast at spotting matching (or mismatched) braces if they're lined up vertically. (Kind of like Rain Man could instantly count 100 toothpicks.) I line up the braces vertically so that I can take advantage of my freakish ability. If braces aren't lined up, then it takes me somewhere between 10 to 20 times longer to check if braces are lined up.
>>
>>60823160
I'm right, but I understand those that are left.
>>
>>60823160
condition&&(statements)
>>
if
(
condition
)
{
statement
}
else
if
(
condition
)
{
statement
}


the only way
>>
function name() {
...
}

class name
{
...
}

if () {
...
}
>>
[CODE] if(condition) {statements} [/CODE]
>>
>>60823476
You're retarded
>>
File: Screenshot_20170609-095212.png (419KB, 1440x2560px) Image search: [Google]
Screenshot_20170609-095212.png
419KB, 1440x2560px
>>60823160

>>60823177
>>60823211
Are correct

>>60823431
No, YOU kys.

Source: https://www.kernel.org/doc/html/latest/process/coding-style.html

Capcha gave me a sign that this is /thread
>>
>>60823476
if you have to write another if in the else you do something wrong
>>
>>60823160
which language?
>>
>>60823610
Only point I vehemently disagree with Linus is 8-space tabs.
>>
Right is always the right side
>>
>>60823805
I can agree with that. I understand why 8, but I like looking at four character wide tabs. As long as you are inserting a \t character however, it only matters what your editor is set to. Reading the same code, I'll see four and Linus 8.
>>
>>60823889
>\t
Negative, spaces are superior and tabs will be autoconverted to spaces.
>>
One True Brace is the gayest shit in all software development.
Even gayer than >>60823301
>>
>>60823211
I do it like that as well..
Never thought about the 'else' brace though.. That's pretty neat, thanks anon!
>>
class Balls
{
function bool SuckEm()
{
if (tasty)
{
return true;
}
else
{
throw OutOfThroatException;
}
}
}


If you prefer this code style, take it from the bright side: you can always make the World slightly better place by killing yourself.
>>
int
main(int argc, char *argv)
{
if(statement)
//do stuff

if(multi_line) {
//do stuff
//do stuff
}

return 0;
}
>>
>>60823610
Torvald's promotes 8 space tabs? Disgusting.

He's not a pussy that uses the same C source indentation as every other brainwashed bondage and discipline C programmer. i.e. Linus torvalds 8 space tabs. Tabs are cool, but so are 2 space indentations, and lisp indentation is also interesting.

Note: as I said, not all GNG folk would agree here, many people love their 8 space tabs. I'm a fan of 4 space tabs or 2 spaces depending on the language. 8 space linus torvalds style code just has too much useless whitespace.
-RMS
http://gng.z505.com/stallman-good.htm
>>
statement ? return true : return false;
>>
>>60824595
Yeah but GNU code uses 8 levels if indentation like nothing. Torvald claims that if you use more than 3, you might just rethink your code. C is overall good at avoiding indent.
>>
>>60824509

I never followed one of these autism threads to determine what's "correct". This is the way I learned, so, what is wrong with it from a more experienced programmer's pov?
>>
>>60824714
6 lines of actual content, 8 lines of brackets
>>
>>60823211
Exactly.
>>
File: 1481607770215.jpg (23KB, 480x320px) Image search: [Google]
1481607770215.jpg
23KB, 480x320px
>>60823177
>Using braces inconsistenly
>>
>>60823160
Left for C and right for Java.
>>
Does putting { on separate line comes from old-school C function definitions and it just somehow survived?

int main(argc, argv)
int argc;
char *argv[];
{
>>
>>60824509

So much wasted space..

class Balls {
function bool SuckEm() {
if (tasty) {
return true;
} else {
throw OutOfThroatException;
}
}
}
>>
>>60823177
Here lies truth, blessed with dobs, underated
>>
File: 1490853257616.png (214KB, 1048x1024px) Image search: [Google]
1490853257616.png
214KB, 1048x1024px
The only right way:
if (x < foo (y, z))
haha = bar[4] + 5;
else
{
while (z)
{
haha += foo (z, z);
z--;
}
return ++x + bar ();
}
>>
The Haskell way:
if (condition) { do_something()
; do_something()
; do_something()
;
}
>>
>>60823211
>No blank line before } else {

So close but no cigar
>>
>>60823160
Used to be left, then right. The opening bracket doesn't need to be on its own line unless you're retarded and like wasting screen space.
>>
my imbecile embedded systems prof. made us indent C like this:
void whatever(int x)
{
for (;;) {
doShit();
}
}


he refused to look at any code that used any other indenting
>>
>>60825178
doesn't emacs do some shit like that by default in c mode?
>>
>>60823917
> confused
I've never had this issue. I force \t characters. Possibly vanilla installing an editor defaults to \t -> space conversion?
>>
Right
>>
File: i.png (10KB, 510x102px) Image search: [Google]
i.png
10KB, 510x102px
>not using horstmann style
>>
>>60823212
this + >>60823177 for plain C
>>
if 
{statement
statement

statement}
condition
>>
>>60825333
>can't delete the brace with kdd or k$xx
>>
>>60825333
Now what is that sexy colorscheme's name?
>>
>>60824671
Agreed. At least in C, as most of my programming is done in C or ASM, each function should do ONE thing and ONE thing well. If you create one function that for example opens a file, reads from it, writes to it, and then closes the file, it would be rather long and a pain to read. I would rather have:

int fileoperation(void)
{
open(file);
read(file, variable);
write(string, file);
close(file);
}


With each task being its own function. Less indentation, less screen space per function, more readable, easier to understand. I don't have to look through a clusterfuck to figure out how something is read.
>>
ITT: dyslexics
Right > left
>>
>>60823177
this makes sense, but I do right for everything.

>>60824509
this hurts my eyes.
>>
File: colors.png (984B, 159x291px) Image search: [Google]
colors.png
984B, 159x291px
>>60825381
picked colors from kate's breeze color scheme
>>
>>60823160
Obviously neither of these
/**
* @brief function
* description of the function,
* the format of the variables
* and what it returns etc.
*/
void function(type &var)
{
if(condition) {
statements
}
}
>>
Right always. Left adds a ton of unnecessary lines, and will just straight up produce errors in some languages. Plus it feels awkward.

Even when I write C# I change it so it does right by default
>>
>>60823805
I like 8 char wide tabs.
>>
>>60823211
Voting with a (You)
>>
File: 1496771589964.png (2MB, 1400x2100px) Image search: [Google]
1496771589964.png
2MB, 1400x2100px
>>60823160

left

BUT, it's 2017 so i use spaces instead of tabs
>>
>>60825710
>BUT, it's 2017 so i use spaces instead of tabs
nice bait
>>
>>60825746
hi richard
>>
>>60823160
Only Left, you don't need to save paper in a book.
>>
>>60825081
breaks in tcl
>>
Literally dependent on the convention of the language.
Anybody who declares a hard difference is wrong.
>>
>>60824714

Ultimately, it is 100% subjective. Kind of why this debate even exists.

The left is more space out, what is actually happening sticks out like a sore thumb, the right is very condensed, so it can be easy to miss things.

The left contains a shit load of empty space while the right makes better uses of its space.

They both have their merits and the absolute most important thing is to pick one and stick with it or follow the established guidelines within the project you're working on. Consistency trumps any instance of autistic hand-waving.
>>
File: dhjdyj5.jpg (44KB, 451x392px) Image search: [Google]
dhjdyj5.jpg
44KB, 451x392px
>>60825746

>needing all that space on the left

lel looks retarded
>>
>>60823160


if (a == b) {
c = a;
d = b;
}

lw 1, 0, if # r1 <- a
lw 2, 0, b # r2 <- b
bne 1, 2, next # if (a != b)
sw 1, 0, c # c = a
sw 2, 0, d # d = b

>>
>>60824831

It's how K&R do it, how Linus Torvalds does it, and how Bjarne Stroustrup do it. Functions place the brace on a new line because they're unique; you can't nest them in standard C or C++.

>>60825917

In C and C++, there is no standard convention for the language.
>>
File: 1496687544036.png (663KB, 1200x776px) Image search: [Google]
1496687544036.png
663KB, 1200x776px
function he {var doesnt = do.this }
>>
>>60823177
This, plus this is a requirement for the linux kernel
>>
>>60825454
You're a god. Thx for this
>>
>>60823160
Left, because I am not a lazy faggot.
>>
File: 1476807881140.jpg (55KB, 712x559px) Image search: [Google]
1476807881140.jpg
55KB, 712x559px
(if condition
if-branch
else-branch)
>>
left.
>>
File: fzk3.png (12KB, 375x375px) Image search: [Google]
fzk3.png
12KB, 375x375px
>>60823212
>>60823258
>>60825342
>>60825391
>>60826177

>2017
>Using programming languages with unsafe memory
>Not using an elegant modern language with zero cost abstractions which produces safe programs
>>
File: 1458423871335.jpg (28KB, 450x600px) Image search: [Google]
1458423871335.jpg
28KB, 450x600px
>>60827753
>elegant
>>
>>60823160
Left is the only right one.

People who use right can read left easier than right. People on left can read left much easier than right.
>>
Which single statement should I use?
if (condition)
return x;

if (condition) {
return x;
}

if (condition) { return x; }


I actually use the last one the most.
>>
>>60828024
The first one. It's criticized to use single-line statement without parenthesis but if it terminates function or loop then it's ok. (return, break, continue, err). Imo the last one looks ugly.
>>
>>60823160
I follow actual guidelines, not just subjective feelings. So, left for global function declaration, right for any other code block.
>>
>>60825200
It's GNU style (uses only 2 spaces though). So yes, Emacs does this by defaul.
>>
>>60827753
>needing kid gloves to help make 'safer' code
I don't need kid gloves, don't assume everyone does just because you do.
>>
>>60828642
how many CVE numbers are you planning to occupy?
>>
>>60823160
was left when I was noob

gravitated towards right over time
>>
>>60823177
you inconsistent fuck, kill yourself
>>
Whichever I'm paid to be.

For personal projects, right. It's just as readable for me and saves lines.
>>
>>60828689
less than you would in the same position. if you think rust stops bugs then i'm going to have to give you a pretty harsh reality check.
>>
>>60823476
dude you forgot to split statement into two lines, your style sucks wtf
>>
>>60828024
The last one without the brackets
>>
>>60828759
what is your position?
fizzbuzz professional?
>>
Left, imho

Just look at the picture, you can clearly see where the block of code begins and where it ends, if there are many statements like that it will be easier for your eyes to separate different blocks of code.

Right side makes code much less readable because you cannot quickly connect the closing brace to the opening brace.

Code is made for humans to read, not computers, so I would rather have readable code than save a line.

Just my 2 cents
>>
>>60823211
exactly the same for me
>>
Right, it's way more readable to me.
>>
>>60823160
Right
>>
>>60828835
Left is harder to read because my eyes have to skip over that space between the if statement and the code block.
>>
File: 1488758298634.jpg (51KB, 500x594px) Image search: [Google]
1488758298634.jpg
51KB, 500x594px
>>60823211
I had to scroll to far to find this. The rest of you are retarded
>>
left: pleb
right : patrician

/thread
>>
>>60823160
Left
>>
>>60823160
>Using braces while programming
Disgusting.
let function arg = 
if condition then
statement
done
;;
>>
>>60823160
if //start of conditional
( //true-false holder
condition //begin true-false evaluator
) //end true-false holder
{ //begin logic container
statement //first logical statement
; //end of first logical statement
otherStatement //second logic statement
; //end of second logic statement
} //end logic container

fully documented code with one identifier per line is optimal for maximum readability
>>
>>60823160
Whatever happens when I type it—I just leave as is. I know, I know, kms, but It's never been a problem, even with >400 lines of code.
>>
>>60823188
Also known as the goto failâ„¢ style.
>>
I auto format all my code before commit even if I don't own the file. :^)
>>
>>60823177
This.
Gives a nice visual distinction between functions and other language constructs.
>>
File: voimt.jpg (335KB, 700x910px) Image search: [Google]
voimt.jpg
335KB, 700x910px
>>60823211
} else {
>>
>>60833721
>being disgusted with superiority
kys
>>
>>60826177
>In C and C++, there is no standard convention for the language.
For C at least, K&R is considered the defacto standard.
>>
>>60824509
It may look wasteful for a small program like this but this is honestly needed for any decently sized program

Drop the brackets on one line statements and you have beautiful code
>>
var foo = function(){bar: meep}
>>
>>60833563
this
>>
if ( stupid === 0 ) {
rightWay = "is right";
}
>>
>>60823177
/thread

Hail the prophets Kernighan and Ritchie
>>
File: knight-in-spewy-armour.jpg (71KB, 621x621px) Image search: [Google]
knight-in-spewy-armour.jpg
71KB, 621x621px
>>60834084
>===
>>
Anyone go to college for Computer Science? All my professors are Asian next semester rather than Indian. Are they any better at teaching clean coding? Anyway, I took C last semester and left applies more towards the way I taught myself from my C Primer Plus textbook.
>>
File: zuck_php.jpg (100KB, 1224x648px) Image search: [Google]
zuck_php.jpg
100KB, 1224x648px
if bool ? doTrue() : doFalse()
>>
>>60834137

if that's true then why didn't they make that a C standard at compile time? then we wouldn't have to endure batshit retarded threads like this..
>>
Right, I'm a space nazi. If the statement's short enough I'll just put the entire function on one line.
>>
>>60823172
https://www.dwheeler.com/essays/apple-goto-fail.html
no thanks
>>
File: tmp_9874-1479700790911577911878.jpg (42KB, 604x453px) Image search: [Google]
tmp_9874-1479700790911577911878.jpg
42KB, 604x453px
Am I being paid by LoC?
>>
>>60823160
ur all faggits
if (condition) { statement; statement; statement }  else { statement; statement; statement;}
>>
>>60827753
>elegant
>zero cost
>safe
choose two
>>
>>60828024
second one always for consistency
>>
if(condition){
statements
}else{
more statements
}
if(condition){short statement}
>>
>>60823160
>/**/

1989 call, they want their comments back.
>>
>>60823164
>I don't program
Then stfu
>>
>>60823255

Yes

Matching curly braces ~not~ on the same column is retarded. Just setup your display to portrait for better viewing.
>>
>>60836402

leave, kid.
>>
>>60836402
kys retard
>>
>>60823177
Yes, PSR-2 coding standards.
>>
>>60824714
its subjective, people here will bitch about this crap to feed their superiority complex than actually writing stuff.
>>
File: tumblr_oomqlhxVJt1sndzdgo1_1280.jpg (259KB, 879x1200px) Image search: [Google]
tumblr_oomqlhxVJt1sndzdgo1_1280.jpg
259KB, 879x1200px
>>60823160
Right if you're writing a book, left if you're programming.
/thread
>>
>>60823160

There is just no argument for the left style, apart form "hurr, my favorite coder does it as well"..

It's simply a waste of space.
It's not more readable.
If you want it more readable, you should still use the style on the right and add a one-line comment.
>>
>>60836445
but he's right you know.
>>
if(condition)
DoShit();

if(condition)
{
DoShit();
DoOtherShit();
}

// occasionally if similar code.

if(condition) DoShit1();
else if(condition) DoShit2();
else if(condition) DoShit3();
else if(condition) DoShit4();
else if(condition) DoShit5();
>>
>>60835544
>look at me being edgy
>>
>>60834203
I've started taking a liking to ternary operators.
The only thing I don't like about them are return statements.

return var < otherVar ? true : false; // makes sense
var < otherVar ? return true : return false; // Also makes sense but doesn't work.
>>
>>60837805
Nigga it's an expression not a function
>>
>>60837830
in my mind they work like macros.
>>
I used left in university like 6 years ago. But once I started working on other peoples codebases I realized most people are right. I couldn't go back to left now as I just don't like the white space.

As a matter of fact, I'm having a hard time remembering the last time I saw right code styling.
>>
>>60834146
javascript
>>
>>60823160
For { }, I make sure they always appear in the same column (left).
For ( ) or [ ], I make no such guarantee (right).
>>
>>60823160
if (Condition)
{ Statements
//
//
//
}
>>
File: 1452467102221.jpg (866KB, 800x2500px) Image search: [Google]
1452467102221.jpg
866KB, 800x2500px
>>60823160
Left
>>
>>60834293
Most IDEs and linters nowadays will warn you about indentation. The lack of an ending curly should be a tip-off anyway, even if you don't look at the start of the first line. Curlies on their own line avoids this too (the lack of space after the if making it obvious). It's really not that common of an issue, anon. There are a lot of easier ways to do something dumb in programming.
>>
>>60823160
(if test-expr then-expr else-expr)
>>
>>60823610
>https://www.kernel.org/doc/html/latest/process/coding-style.html
>not using GNU coding style
>>
>>60823211
Mein negger
>>
>>60823160
left is easier to read but eats up listing space
Thread posts: 169
Thread images: 23


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.