[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
I prefer the top one.
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 123
Thread images: 15
I prefer the top one.
>>
>>53697631
the second one fucks me up. if you're going to inline the first brace why don't you inline the second one.
>>
>>53697672
Because I want start of function to take 1 line, and end of function to take 1 line - instead of having the start of function take 2 lines.
>>
>>53697697
>Because I want start of function to take 1 line, and end of function to take 1 line

why isn't the end of the function denoted with the last instruction
>>
>>53697723
Stick with python kid
>>
>>53697723
Because the last instruction does not necessarily have anything to do with the end of function.
>>
File: second.jpg (9 KB, 200x200) Image search: [Google]
second.jpg
9 KB, 200x200
>>53697737
>>
Bottom one is best.
>>
>>53697631
>Tony is an actual engineer who does things right.
>Capt. doesn't even know what a computer is

No surprises here
>>
tony's is the correct answer
fuck you op
>>
>>53697786
Tony is actually an actor with zero programming skills and most definitely does not give a fuck about your shit programming style
>>
>>53697833
The fact that you used the character's name suggests that you are incapable of logical thinking and reasoning. Thus, your opinion is hereby discared.
>>
File: stallman.jpg (28 KB, 220x330) Image search: [Google]
stallman.jpg
28 KB, 220x330
The second one is proper, at least thats what class taught me.

>>53697672

Because i'm not autistic.

>>53697723

Because real programming languages weren't made for retards, or to hold your hand. That's a lot of compiler work better spent on optimizations.

>>53697737

kek

>>53697833
>being this retarded

No Tony Stark is a comic book/cartoon/movie character who is an engineer. Robert Downy, Jr is the actor.
>>
i use the bottom one, the asymmetry makes it easier to see the hierarchy

however it may also be because i learned CSS before i learned a programming language, and that's how CSS does it, because CSS was cobbled together by retards
>>
Hi 9gag!
>>
>>53698012
CSS can do either or just like every other programming language, faggot.
>>
I love languages with code formatting standards. Python has PEP 8 and Go had go fmt, and both of them allow people to stop arguing about irrelevant minutiae of coding formating and keep programming.
>>
>>53698059
nobody writing CSS uses top style. literally nobody. not even a debate
>>
>>53697631
function()
{//code}
>>
>>53698337
>closing bracket commented out
>>
Only further proves that Stark is a genius.
>>
>>53698353
function()
{//code}
}
>>
>>53698397
what the fuck is this
>>
>>53698397
why stop there

function()
{
//code
// }
}
>>
doesnt even matter what you like, you'll end up working in some shop that makes you conform to their standard anyway
>>
>>53698397
well meme'd my friend
>>
>>53697631
The second one. Either way is fine, but I'm lazy so keypresses are difficult.
>>
File: 1454903821436.jpg (128 KB, 530x600) Image search: [Google]
1454903821436.jpg
128 KB, 530x600
i find myself doing both
fight me
>>
>>53698421
function(){code}}
>>
Depends on the language, conform to their style. Anyone arguing for one style over another is autistic.
>>
>>53697631
Me too.
>>
File: fruit.jpg (76 KB, 358x477) Image search: [Google]
fruit.jpg
76 KB, 358x477
/* gcd:  return the greatest common divisor of two integers */
int gcd(int m, int n) {
assert(m > 0 && n > 0);
/* if m < n, remainder will always be 0 */
if (m < n) {
swap(&m, &n);}

int r = m % n; /* r is the remainder of m / n */
if (r == 0) {
return n;}
else {
m = n;
n = r;
gcd(m, n);}}
>>
It depends what language I'm using.
>>
The top one is actually the preferred choice.
Fucking read K&R
>>
def main():
print("Hello World")
return 0
>>
>>53698279
I do.
>>
White space and comments make 0 difference to execution. Use whatever format makes the code more readable for humans.

Which is the top one, obvs.
>>
function :: a -> b
function =
--code
>>
>>53700848
Fuck K&R style
>>
>>53701442
Fuck you
>>
void why_this_is_bad(int op, int is, int a, int faggot,
int for_reals) {
puts("Can you tell where the function body starts?")
puts("FUCK NO YOU CAN'T.");
}
>>
>>53699012
Bisexuals are still faggots so I guess that makes you one too
>>
File: 1455115395397.jpg (23 KB, 396x360) Image search: [Google]
1455115395397.jpg
23 KB, 396x360
>>
>>53701463
void why_this_is_bad(int op, int is, int a, int faggot,
int for_reals) {

puts("Can you tell where the function body starts?")
puts("FUCK NO YOU CAN'T.");
}


that's why I put a space after lol
>>
File: 1298678332158.jpg (177 KB, 600x740) Image search: [Google]
1298678332158.jpg
177 KB, 600x740
I do it like this

function(int x){

//code
}

>>
(fucking (plebs (fucking seriously)))
>>
>>53701542
So I'm a Python fag nowadays, and I'd ident the second line so that "int for_reals" would sit below "int op" (the 'i' in int aligned) - what's the reason not to do it that way?

I guess C style recommendations are different from PEP8..
>>
>>53701589
that's just gross

come on.
>>
>>53701463
[/code]
void why_this_is_fine(int you, int are, int a, int faggot,
int for_reals) {
printf("%s", "BSD style uses 4column tabs for alignment");
puts("and 8 column tabs for indentation.");
}[/code]
>>
>>53701463
>>53701624
void why_this_is_fine(int op, int is, int a, int faggot,
int for_reals) {
printf("%s", "BSD style uses 4column tabs for alignment");
printf("%s\n", "and 8 column tabs for indentation.");
}
>>
Top master race, way easier to read and scan through code
>>
>>53701636
Just use puts, desu.
>>
(lambda ()
(code))
>>
>>53697631
Depends on the language. For C you use top, Java you use bottom.
>>
>>53697631
Second for everything
>>
>>53701721
compiler will optimise it
>>
>>53701748
Why do lispfags always use 2 spaces for indent? That's unreadable as shit. Use 4 spaces or preferably use tabs and have them be 3-char wide.
>>
>>53697723
Because it makes reading, editing, and bug fixing code way easier. Also how would that work when you have classes?
>>
>>53697697

return returnValue;
}

kek
>>
>>53697631
This is the proof that Iron man always wins.
>>
No.

void this_is_correct(int you, int are, int all, int wrong)
{
if (everyone_in_this_thread_is_a_fag) {
printf("I knew it.\n");
} else {
printf("Impossible.\n");
}
}
>>
>>53701898
Lisp tends to be indented to line things up more than just to indent things to fixed tab stops. And otherwise, those two spaces seem pretty clear to me to show that (code) is part of the (lambda). Minimal indentation is good to fit lots of deeply nested things on the screen.

Also Emacs seems to indent stuff like that by default so it must be right.
>>
>>53702044
I sometimes lose sense of the scope I'm inside when reading 2-space indented code. Not good. With 3 or 4 cols that never happens. I doubt I'm the only one who has this problem

Also arbitrarily lining things up is from satan, even in lisp
>>
>>53702106
It makes sense in lisp.
(define (avg-sum-squares x y z)
(/ (+ (square x)
(square y)
(square z))
3))
>>
>>53702167
This is infinitely more readable to me even though I've read some lisp code
(define (avg-sum-squares x y z)
(/
(+
(square x)
(square y)
(square z))
3))


Keep the functions and parameters clearly separate. it displays better the tree structure that function calls have
>>
>>53702283
ofc misaligned the 3...
>>
FUNCTION() { //CODE }
>>
func(  )          {

//code

return 0;}
>>
>>53697631
void fn( int arg1 ) {
do_stuff( arg1 );
no_arg_fn( );
}
>>
>>53698397
my sides
>>
File: ratemycode.png (9 KB, 542x207) Image search: [Google]
ratemycode.png
9 KB, 542x207
>>53697631
>>
>>53701463
void why_this_is_bad(int op, int is, int a, int faggot,
int for_reals) {
puts("Can you tell where the function body starts?")
puts("FUCK NO YOU CAN'T.");
}
>>
Jst fk(Shit mine){
return up(mine);
}
>>
>>53699693

#include <stdio.h>

int gcd( int a, int b ) {
int result ;
/* Compute Greatest Common Divisor using Euclid's Algorithm */
__asm__ __volatile__ ( "movl %1, %%eax;"
"movl %2, %%ebx;"
"CONTD: cmpl $0, %%ebx;"
"je DONE;"
"xorl %%edx, %%edx;"
"idivl %%ebx;"
"movl %%ebx, %%eax;"
"movl %%edx, %%ebx;"
"jmp CONTD;"
"DONE: movl %%eax, %0;" : "=g" (result) : "g" (a), "g" (b)
);

return result ;
}

int main() {
int first, second ;
printf( "Enter two integers : " ) ;
scanf( "%d%d", &first, &second );

printf( "GCD of %d & %d is %d\n", first, second, gcd(first, second) ) ;

return 0 ;
}
>>
>>53697631
People like you OP make the world a terrible place
>>
>>53699012
This.
The top one for main or classes and the bottom one for helper functions and methods.
>>
>>53697631

The only reason to choose the second one is when dealing with awful languages that were conceived over a weekend and are rife with dumb choices, resulting in ambiguous meaning unless you put the open braces on the same line.

The top version places the function signature on its own line, then the statement block begins.

Putting the open curly on the same line as the function declaration means that your statement block indicator has polluted your function signature.
>>
>>53698421
why stop there
function()
{
//function()
//{
//code
// }
// }
}
>>
>>53703506
i dont know how absolutely retarded you have to be for needing the brace to be on a line entirely by itself for it to be more clear to you

even the indentation itself if there were no brackets would show you're in the function

splitting apart parts of statements like "function signature" to "statement" only makes sense in your diseased mind only for this one example, do you newline indent the condition after if statements too??? because hey first it's operator then expression, so new line required right?
>>
>>53697631
a beautiful single line
function(){//code}
, and is easy to debug cause you'll already know error is on first line
>>
OP and anyone like them needs to fuck right off. Such an ugly way of having your code.
>>
>>53703470
I'm glad I'm not the only one who does that.
>>
File: 1322510546560.png (24 KB, 400x400) Image search: [Google]
1322510546560.png
24 KB, 400x400
>>53703227

are u a wizard
>>
>>53702026
This.
>>
CamelCase or underscores
>>
>>53704063
> CamelCase
thats pascal case
>>
>>53704063
functions_have_underscore_names
variables_do_too
ClassesArePascalCase
CONSTANTS_ARE_THIS
kOrTheyCanBeThis
>>
File: 1455094642173.gif (3 MB, 547x334) Image search: [Google]
1455094642173.gif
3 MB, 547x334
>>53704395
opinionsAre_Subjective
YOU_ARE_A_FAG
>>
>>53704447
my opinion is better than yours.
and i mean that in the least shitposty way possible.
>>
>>53704467
>"im less retarded than you"
ftfy
>>
function () {

//I use spaces for all my code

}

//like this
>>
File: 1458845577357.gif (379 KB, 500x374) Image search: [Google]
1458845577357.gif
379 KB, 500x374
>>53704595
you're writing code, not a college essay
>>
>>53704595
i


love whitespace

too anon.
>>
>>53704624

just too /CLEAN/

I like it because I condense code that is grouped up and space out things that arenot.

seriously it is logical as fuck and makes it easier to look at.

WHITE

SPACE

GET

FUCKED
>>
>>53703227
AT&T SYNTAX A SHIT
>>
>not uglifying all your code
>>
this is how you write R E A L code f͏a͏m
a82e_a928_bbc1_a0e9(){x2f0x2f0x430x4f0x440x45}
>>
>>53704624
>Not puting your code in MLA format
>2016
>>
File: 1455011867006.gif (729 KB, 716x620) Image search: [Google]
1455011867006.gif
729 KB, 716x620
>>53704807
>mfw instead of imports we use citation
>>
>>53703027
This is the correct version.
>>
Everything in one line, fuck you.
function() {code; code; code}
>>
>>53703027
1) >puts
2) Actually it's very easy to tell
>>
>>53697631
I seriously don't understand this. Type 2 is literally the industry standard. Even FLOSS does the same thing. Go look at source code for just about any real open source project (linux kernel, gnome stuff, etc.)...

Anyone using type 1 is probably a freshman in college/communtiy college/highschool taking java for this first time... or even worse, the type of kids who haven't studied formal math/logic but think they can program because codeacademy taught them to print hello world

Just look at the fucking code, we're clearly starting a declaration, why would we need to waste a line on a {
>>
WHO FUCKING CARES
>>
>>53706669
gtfo code monkey
>>
function()    {
code; }
>>
>>53706827
If you're not writing serious code then your opinion is completely irrelevant on the matter

Write your little autohotkey scripts and codeacademy assignments however you want, nobody gives a shit about how you "code"
>>
>>53706267
Why not puts?
You know your printf("%s\n") calls are replaced by puts by the compiler, right?
>>
>>53706669
You know the Linux kernel uses a newline on function declarations? Fucking clown, don't act like you know shit you clearly don't
>>
function
(){ print("line 1")
; print("line 2")
;}
>>
>>53697631

Top one for the win. Proper use of white space and indentation helps readability tremendously.
>>
>>53706941
do you think "serious code" depends in any capacity on the preference anyway?
>>
>>53698097

One thing I'll give to Visual Studio is that C# and VB are formatted automatically and beautifully. Microsoft actually thought about presentation and readability.
>>
>>53706669
>the type of kids who haven't studied formal math/logic but think they can program because codeacademy taught them to print hello world

>projecting this hard
>>
>>53700927
>takes 23 seconds to execute
>>
File: 1380130008287.jpg (17 KB, 500x500) Image search: [Google]
1380130008287.jpg
17 KB, 500x500
>>53701542
>adding a space this time
>not moving the bracket down
>not being consistent with all functions
>>
>>53702026
>beautiful
>>
>>53698397
>>53698421
I'm laughing harder at this than seems healthy
>>
>>53703227
NOT PORTABLE
O
T

P
O
R
T
A
B
L
E
>>
File: 1450866578825.jpg (16 KB, 552x450) Image search: [Google]
1450866578825.jpg
16 KB, 552x450
>>53697631
There's no use for those brackets in this situation.

I'd write this whole function in one line.
>>
>functions
Plebs
>>
def shit = println("lolfuckyou")
>>
File: 00.png (42 KB, 757x437) Image search: [Google]
00.png
42 KB, 757x437
>>53709376
>implying they're set in stone
Thread replies: 123
Thread images: 15

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

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.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.