[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
What indent style do you prefer?
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: 242
Thread images: 22
File: codestyle.png (74 KB, 420x297) Image search: [Google]
codestyle.png
74 KB, 420x297
What indent style do you prefer?
>>
>>54774597
Right.
Both are ugly as fuck tough.
>>
>>54774597
Right but I use left for functions.
>>
>>54774597
right for fewer keystrokes

left for aesthetics

t. non-programmer
>>
>>54774597
Second way for life
>>
>>54774597
>not using python

Enjoy your unstandardized style faggots
>>
>>54774597
What ever the company code style dictates.
I have my vim setup to auto-format and it can enforce one bracket style or the other. I just type normally and regardless if I put them in the "wrong" place it will move them to meet the given style.
>>
>>54774623
Since both are ugly, how do you do it?
>>
File: indent1.png (96 KB, 299x348) Image search: [Google]
indent1.png
96 KB, 299x348
GNU style is the only right way.
>>
>>54774597

Left for adults, right for newfags who think less lines and more information density is better.
>>
>>54774691
Literally why
>>
>>54774707

To be edgy and different and unique and Lisp-like and completely incomprehensible and useless. Basically everything GNU stands for.
>>
Left for functions and higher level, right for everything else.
>>
>not indenting the curly brackets to be in line with the block
Left would be my choice if the brackets weren't a tab behind.
>>
>>54774597
I use both.
>>
Right. Always right. Left is the fedora tier "classy" way.
>>
>>54774597
Always left. Then again I like to use a lot of whitespace, not just vertically, but also horizontally.
>>
>>54774597
Left for c and c++, right for java and perl.
>>
>>54774636
>right for fewer keystrokes
you could have your ide arrange them and fix the stiles on save, so key stroke argument doesnt really matter

also, fucking JS looks like shit whichever style you use
>>
right
>>
>>54774832
Maybe if you didn't use such a shitty font
>>
>>54774832

You could literally have your IDE do all the heavy lifting and generate most code for you, but apparently the Luddites at /g/ get enraged at that idea.
>>
>>54774683
if (
condition
)
{Statements
;}
>>
>>54775009
:^)
>>
I reserve left exclusively for main()
>>
>>54775009
oh god no
>>
>>54774992
>pragmata
>shitty font
>>
Left for insufferable men with unshaved necks who use debian and claim to be more mature and sophisticated than you because all their shit is retro, right for normal people.

Left for old farts with vision problems, right for people under 50.

Left for baby ducks, right for people with vision unclouded by nostalgia and dogma.
>>
>>54775051
What's the point of that? Is inconsistent style what all the cool kids are doing?
>>
Left....but then I minify everything later to fuck with any parjeet that needs to maintain my code.
>>
>>54775089
He's the first in >>54775079, but he might use BSD instead

>>54775110
>pongjeet knows how to use GNU format
>>
        Chapter 3: Placing Braces and Spaces

The other issue that always comes up in C styling is the placement of
braces. Unlike the indent size, there are few technical reasons to
choose one placement strategy over the other, but the preferred way, as
shown to us by the prophets Kernighan and Ritchie, is to put the opening
brace last on the line, and put the closing brace first, thusly:

if (x is true) {
we do y
}

This applies to all non-function statement blocks (if, switch, for,
while, do). E.g.:

switch (action) {
case KOBJ_ADD:
return "add";
case KOBJ_REMOVE:
return "remove";
case KOBJ_CHANGE:
return "change";
default:
return NULL;
}

However, there is one special case, namely functions: they have the
opening brace at the beginning of the next line, thus:

int function(int x)
{
body of function
}

Heretic people all over the world have claimed that this inconsistency
is ... well ... inconsistent, but all right-thinking people know that
(a) K&R are _right_ and (b) K&R are right. Besides, functions are
special anyway (you can't nest them in C).
>>
>>54775009
kek
>>
>>54775154
Note that the closing brace is empty on a line of its own, _except_ in
the cases where it is followed by a continuation of the same statement,
ie a "while" in a do-statement or an "else" in an if-statement, like
this:

do {
body of do-loop
} while (condition);

and

if (x == y) {
..
} else if (x > y) {
...
} else {
....
}

Rationale: K&R.

Also, note that this brace-placement also minimizes the number of empty
(or almost empty) lines, without any loss of readability. Thus, as the
supply of new-lines on your screen is not a renewable resource (think
25-line terminal screens here), you have more empty lines to put
comments on.

Do not unnecessarily use braces where a single statement will do.

if (condition)
action();

and

if (condition)
do_this();
else
do_that();

This does not apply if only one branch of a conditional statement is a single
statement; in the latter case use braces in both branches:

if (condition) {
do_this();
do_that();
} else {
otherwise();
}
>>
>>54774597
I use both. right in Java and JavaScript. left in C and C#
>>
>>54775079
Agreed, left is what the geezer who wrote my computer science course writes in, as well the teacher, right is how I write code, and now all the little code cadets are gonna be writing like a polish woman attempting to copy an old man. Except they all have inconsistent indents and use fucking spaces instead tabbing because that's what the teacher did. TEACHIN THEM RIGHT
>>
Sue me
#include <stdio.h>

int is_odd ( int n ) {
return n % 2 ;}

int main () {
const int N = 100 ;
for ( int i = 0; i < N; ++i ) {
if ( is_odd ( i ) ) {
printf ( "Odd\n" ) ;}
else {
printf ( "Even\n") ;}}}
>>
>>54775057
Yes, you're correct.
>>
I'm fine with both. It just depends on what the existing code already uses. Consistency trumps all.

If I'm starting from scratch, I think I would probably do the left, though.
>>
>>54775193
>space between function name and parameters
>>
>>54775175
>use fucking spaces instead tabbing
That's actually proper practice. Different editors render tabs differently, so for best portability you should be sure to use spaces (and change settings in your editor to use spaces instead of the indent character)
>>
>>54775193
:^(
>>
>>54775168
>Do not unnecessarily use braces where a single statement will do.

Until someone rewrites

if (condition)
do_this();


into

if (condition)
do_this()
and_that()
>>
>>54774597
I do the one on the right because my first language was [spoiler]action script[/spoiler]
>>
>>54775199
which is a good font, what about this??
>>
>>54775154
>tehnical reasons for indentation

oh man this is old

>muh character cell terminal only has 80 columns and indentation aware line wrapping doesn't exist, stop making me scroll horizontally

>>54775220
See above

Spaces for alignment, tabs for levels of indentation

This will align everywhere with a monospaced font
T->T->int a
T->T->____ b
>>
>>54775225
This does not apply if only one branch of a conditional statement is a single
statement; in the latter case use braces in both branches:

if (condition) {
do_this();
do_that();
} else {
otherwise();
}
>>
>>54775244
Liking it, what is it?
>>
>>54775009
ew.
>>
>>54775220
I always make sure my editor uses spaces instead of tabs characters I just like the consistency of tabbed indents. Also, many editors allow you to highlight several lines and indent them all at once with tab, but if you do the same with spaces, you just erase all of your code
>>
>>54775271
its called monoid, found it the other day
>>
>>54775300
Thanks man. Take a look at inputfont
>>
>>54775079
Efficient code design says you are a fucking idiot. Lining up code block brackets is a good, beautiful, and efficient code practice that allows for better maintenance, debugging, and editing.

Stop being a fucking contrarian "old people code like this hurhur" moron, child. Let me know when you've written thousands upon thousands of lines of mission-critical goddamn code and fucking rely on the formatting of your code to make the most sense possible.

Oh wait, that will never happen. Because people will take one look at your ugly code and never even consider hiring you.
>>
>>54775193
...acceptable. Carry on.
>>
>>54775079
Yeah show him how real apps are made.
>>
>>
>>54775324
You sound like you wear a classy hat and cultivate hair on your neck
>>
>brackets
>2016
>>
>>54774597
left

making working pages longer is something I don't mind considering it also increases clarity of visualized code.
>>
>>54775352
why not inline it?
>>
>>54775193
Beautiful.
Teach me your ways, master.
>>
>>54775352
Most unreadable shit ever. Sure it looks nice in the example, but a soon as you a have a file with a few thousand lines of code, it just turns into a mess.
>>
>>54775373
don't you own a 16:9 monitor?
>>
>>54775324
>Don't ask me for evidence, I have none. Only autistic conjecture i thought of in the shower.
>Now, if you'll excuse me, I have an irresistible urge to suck a dick
>Hey, is that dog not neutered? Score!
>>
>>54774597

Right, because I prefer the opening of the conditional and the closing of the conditional to each occur on exactly one line.
>>
Left. My vision's kinda shit and the left is easier for me to read.
>>
File: 1464390797751.png (145 KB, 907x600) Image search: [Google]
1464390797751.png
145 KB, 907x600
>>54775352
>>
>>54775499
Too bad for you, I'm the type of architect that only designs buildings with stairs because ramps are an ugly waste of space and elevators are bloat
>>
>>54775513
Fine, I'll just use a different building.
>>
>>54775193
#include <stdio.h>

int is_odd ( int n )
{ return n % 2
;}

int main ()
{ const int N = 100
; for ( int i = 0; i < N; ++i )
{ if ( is_odd ( i ) )
{ printf ( "Odd\n" )
;} else
{ printf ( "Even\n" )
;}}}
>>
>>54775531
Your style is autistic and you don't even know to write a simple odd number checking function. I can feel the tumors growing
>>
>>54774597
why do people not put brackets on their own lines

it's so easy to identify code blocks with it, you just look up and down and you instantly know what is what
>>
>>54775589
Do you really think I write code like that?

Also, the function works, so who gives a shit.
>>
>>54774597
I use both.
>>
>>54775629
You are a fucking idiot.
>>
>>54775529
Good, I don't want any crippled members of the untermensch in my non harmful UNIX way building.
>>
>>54774597
Right.

Left is objectively shit.
>>
>>54774597
>indent style

I use python
>>
>>54774597
None. It was hard to write, it should be hard to read.
>>
>>54774597
Left if I'm writting C#, right if I'm writing Javascript.
>>
>>54774597
Both are fine.
But I use right.
>>
>>54774597
Left for functions.
Right for initializer lists, structs, unions, and enums.
>>
>>54775009
if 
(
condition
){
Statements
;}
>>
File: cthread.jpg (235 KB, 898x1146) Image search: [Google]
cthread.jpg
235 KB, 898x1146
>>54774597
Mothers and current crushes
>>
>>54775684
good job not answering my question
>>
File: going all the way.png (10 KB, 602x871) Image search: [Google]
going all the way.png
10 KB, 602x871
>>54775531
Why not just go all the way?
>>
>>54775997
This thread has gone too far.
>>
>>54775225

if(something)
goto fail;
goto fail;
>>
>>54774597
Left always. Right is useless.

>>54774636
fewer keystroke* if you are using a good editor.

Python is not a real programming language, it is a scripting language.
>>
>>54775997
No.

#include <stdio.h>
int is_odd(int n){return n%2;}int main(){const int N = 100;for(int i=0;i<N;++i ){if(is_odd(i)){printf("Odd\n");}else{printf("Even\n");}}}
>>
>>54774597
I often use
if() myfunction() else myotherfunction()
this looks great
>>
Left, but I was always taught to add a space between alphanumerics and symbols. Is that bad?
>>
#include <stdio.h>

int is_odd( int n ) {
return n % 2;
}

int main ( ) {
const int n = 100;
for( int i = 0; i < n; ++i ) {
if( is_odd i ) ) {
printf( "Odd\n" );
}
else {
printf( "Even\n" );
}
}
return 0;
}
>>
Left. For some reason it's much easier to read.
>>
Right is an artifact of the old times when screens were only 25 lines tall.

Now that we live in the era of 1200+ pixels of vertical space, left is the clear aesthetically sound choice.
>>
>>54774597
Left.
>>
File: cat in bath.webm (386 KB, 261x194) Image search: [Google]
cat in bath.webm
386 KB, 261x194
>>54774597
Right. For some reason it's much easier to read.
>>
>>54776565
Left is like. putting a period in the middle of a sentence.
>>
does it matter? every company needs a benevolent dictator to just decide stupid shit like this.
>>
>>54775352
Sasuga Windows Phone poster
>>
<code>while true</code>
>>
Left for people with a real education and right for self-"taught" webdevs
>>
>>54776490
No, just no.
>>
Language syntax specific faggot. You aren't a programmer
>>
>>54777043
Nice justification, faggot.
>>
>>54775009
Here is your reply
>>
>>54775009
5 lines of code, that's a lot anon!
>>
>>54774691
>Return types on the previous line
>plez halp
>>
>>54775997
>indenting
wtf
>>
>>54775324
The only thing that makes things more maintainable w.r.t. this is that convention is consistent in the project.
>>
Left looks like a waste of space desu
Like I have to do a double take
>>
>>54777453
thats so you can grep for ^func, it's what people did before tags existed.
>>
>>54774597
Right one.
>>
>>54774597
Right is more readable.
>>
>>54775511
if (true) Method();
>>
Where's that one where they replaced everything using macros at the beginning of the program? That one was neat.
>>
Right is fucking disgusting.
>>
>>54774597
Egyptian braces best.
>>
>>54774636
>fewer keystrokes
it's literally exactly the same
>>
>>54776027
>goto
it's shit
>>
>>54774597
right
>>
Left
For me it's more easy to skim and understand if the syntax is like the left
>>
>>54776105

I code like this all the time. it's really not that bad. keeping each chain of statements on a single line instead of having them broken up by tons of line breaks makes it much easier to scroll through the code and quickly find the chain of code that you're looking for. you only have to scroll horizontally once you've already found the line that you need to be on.
>>
public class PEP9{
public static void main(String[] args){
for(double x = 1; x < 1000; x++){
for(double y = 1; y < 1000; y++){
for(double z = 1; z < 1000; z++){
if(x + y + z == 1000 && z*z == x*x + y*y){
long product = (long) (x*y*z);
System.out.println("x = " + x);
System.out.println("y = " + y);
System.out.println("z = " + z);
System.out.println(product);
break;
}
}
}
}
}
}
>>
I like left more but don't care much
>>
>>54774597
I use right for real programming and for Javascript, left for CSS.
>>
>>54774597
if (condition)
{ Statements
/*
...
*/
}
>>
>>54774597
Left
>>
>>54774704
this
>>
>>54779181
autism
>>
>>54774661
How does one achieve this? N00b vim user here
>>
>>54775225
That's why conditionals without braces should be on a single line. Helps people to remember to add braces if they add another condition later on.
>>
>>54774597
Who gives a fuck? Just use whatever convention is already in place on your team. Any IDE can easily reformat to either option anyways. Fuck off with your autistic bullshit.
>>
>>54779232
:set expandtab
gg=G

or

:set noexpandtab
gg=G
>>
>>54779407
>what is :retab?
>>
>>54774993
having an IDE do work for you doesn't fix the fundamental flaws of a language (i know that's not really relevant in this case but i'm tired of hearing javacurries use eclipse as a response to java being called verbose)
>>
plebs

condition? do_true() : do_false();
>>
left
right is unreadable
>>
>>54775009
proof that /g/ can have good humor sometimes
>>
>>54775009
lel
>>
File: vomit.jpg (82 KB, 680x680) Image search: [Google]
vomit.jpg
82 KB, 680x680
>>54779968
>>
>>54774597

The one Linus Torvalds use.
>>
>>54774597
(if condition?
'then
'else)
>>
>>54774832
It doesn't look too bad if you format it right. I've always put try and catch on their own lines and used OTBS though.
>>
>>54774597
Neither.
I prefer taking open source software and using it for my own benefit without caring about what you hackers do. :^)
>>
The only sane choice:

int foo(int a, int b, int c)
{
// ...
}

inline int bar(int a, int b)
{ return a + b; }

int main()
{
if (condition) {
// ...
}
}
>>
>>54774597
I prefer the left one but I adapt to the code base.
I'm not going to be the faggot who makes running a formatting script a rquirement for each merge.
>>
The left one is way more readable when you have a big amount of code
>>
if (condition) { action(); }
>>
combine both
if (true)
{
do_this();
} else {
do_that();
}
>>
>>54774597
if(condition){//Statements}
>>
>>54774597

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

>>
Used to do left, now switched to right because I can do /}V% to select the entire block in vim.
>>
>>54779077
>scrolling horizontally
>>
>>54774597
You can easily comment out an if-statement without breaking your code using the left style.

This is not possible with the style on the right.

So whatever stylistic preferences you may have, there's a 100% objective and purely functional advantage to the left style.
>>
File: 1418355429081.png (46 KB, 627x404) Image search: [Google]
1418355429081.png
46 KB, 627x404
Best coding style coming in
>>
>>54774597
Left.
>>
Right - don't even know anyone who would do left, but so long as you're consistent about it I won't put you in the bag with people who mix their tabs and spaces (I'll just quietly think less of you instead)
>>
>>54774597
Right
>>
>>54781867
what language is that even supposed to be?
>>
>>54774691
Why is GNU style so fucking ugly?
>>
>>54781944
c++
>>
>>54781995
why is she assigning Gamergater to Tweeter? why not just check if (Gamergater) ? wtf is with the weird bitshifting on the strings and shit? that can't be legal.
>>
File: 1460718908183.jpg (23 KB, 320x310) Image search: [Google]
1460718908183.jpg
23 KB, 320x310
>>54781867
>assignment operator inside a conditional instead of a boolean
>>
>>54775089
main is a special function that gets s(slightly) special formatting. It's hardly inconsistent.
>>
>>54774597
Maybe that is retarded, but I usually write like
if (x is true) {

statement1();
statement2();
}

because I dont like putting a curly bracket on its own line and when statements are too close and melting with a condition
>>
>>54775247
ive had problems where i wrote a program in some IDE and went to upload it to like github or some shit (can't remember where), and suddenly the tabs were 3 times longer and my code went from being bad to looking like utter shit.

so i just configured my IDE to auto-replace tabs with 4 spaces.
>>
oh god, definitely left

been learning C recently and never even seen anyone do the right method
>>
>>54778328
just wanted to say that this clear and nice looking font was really refreshing after scrolling through a bunch of garbage
>>
>>54774597
Right
>>
>Aesthetics in code
Am I in >>/f/?

Stick to community-standard (your company, organization, project), but for fuck sakes, who cares beyond that? Besides you eternal shitlords.
>>
>>54775009
>not
(cond     ((test1) a1)
((test2) a2)
...
((testn) an))
>>
File: phl.pm.org-monk.png (110 KB, 480x250) Image search: [Google]
phl.pm.org-monk.png
110 KB, 480x250
>>54774597
Since I'm programming everything in Perl, I follow the perlstyle guide 'cause I'm not a faggot.

NAME
perlstyle - Perl style guide

DESCRIPTION
Each programmer will, of course, have his or her own preferences in
regards to formatting, but there are some general guidelines that will
make your programs easier to read, understand, and maintain.

The most important thing is to run your programs under the -w flag at
all times. You may turn it off explicitly for particular portions of
code via the "no warnings" pragma or the $^W variable if you must. You
should also always run under "use strict" or know the reason why not.
The "use sigtrap" and even "use diagnostics" pragmas may also prove
useful.

Regarding aesthetics of code lay out, about the only thing Larry cares
strongly about is that the closing curly bracket of a multi-line BLOCK
should line up with the keyword that started the construct. Beyond that,
he has other preferences that aren't so strong:

* 4-column indent.

* Opening curly on same line as keyword, if possible, otherwise line
up.

* Space before the opening curly of a multi-line BLOCK.

* One-line BLOCK may be put on one line, including curlies.

* No space before the semicolon.

* Semicolon omitted in "short" one-line BLOCK.

* Space around most operators.

* Space around a "complex" subscript (inside brackets).

* Blank lines between chunks that do different things.

* Uncuddled elses.

* No space between function name and its opening parenthesis.

* Space after each comma.

* Long lines broken after an operator (except "and" and "or").

* Space after last parenthesis matching on current line.

* Line up corresponding items vertically.

* Omit redundant punctuation as long as clarity doesn't suffer.
>>
>>54774691
disgusting
>>
>>54782044
never change /g/
>>
>>54779015
>Doesn't recognise the gotofail exploit
http://arstechnica.com/security/2014/02/extremely-critical-crypto-flaw-in-ios-may-also-affect-fully-patched-macs/
>>
>his language doesn't have a fmt command

lmao do you program on an abacus or something old timer
>>
>>54779138
What's faster, A a square root calculation ignoreing non perfect squares or a thousand comparisons?
>>
>>54774597
There are more styles than that, your image has a limited choice fallacy.
>>
>>54774597
Neither https://en.wikipedia.org/wiki/GNU_coding_standards#Code_formatting
>>
>>54774597
I'm prone to using either depending on the situation because I'm not a monkey
>>
What really pisses me off is people using 3-4 spaces instead of a fucking tab. Literally WHY?
>>
Nobody has mentioned banner style yet.
if (condition) {
statement1();
statement2();
}
else {
statement3();
statement4();
}
>>
>>54784162
this
>>
left always.
>>
File: shig.png (68 KB, 187x219) Image search: [Google]
shig.png
68 KB, 187x219
if(condition){statement();
statement();}
else{statement();
statement();}
>>
File: 1395572351911.jpg (135 KB, 386x426) Image search: [Google]
1395572351911.jpg
135 KB, 386x426
>>54775009
>;}
>>
>>54784162
see
>>54776332
>>
(if (condition)
(expression)
(expression))
>>
>>54778328
> all that nonstandard whitespace around parens and before opening curlies...
>>
>>54775009
 if  
(
condition
)
{
statement
}
 is clearly the superior way
>>
File: Tyrone_casts_Metronome.gif (925 KB, 500x281) Image search: [Google]
Tyrone_casts_Metronome.gif
925 KB, 500x281
>>54784162
 a e s t h e t i c s 
>>
>>54775511
;}
>>
>>54775009
haha what
>>
if condition:
stuff

If condition Then
Action
End If
>>
Can we argree on
for(int x=0; x < MAX_X; x++)
for(int y=0; y < MAX_Y; y++)
{
array[x][y] = waifu;
}
>>
>>54785049
I hate languages that end condition statements with words, like "End X" or "fi"

Idk why it bugs me, but it seems extremely unnecessarily verbose.
>>
>>54776079
>Python is not a real programming language, it is a scripting language.
Nigga what you talking bout
> only real programming language is RISC 1
> ia32 and x64 are just for script kiddies
>>
>>54785213
I like the way lua does it with just an end. Fuck shit like end if or begin though.
>>
>>54785129
There's literally no reason that you shouldn't indent that. Also, you're missing curly braces.
>>
>>54778552
Method();
>>
>>54774691
>nano
LOL
>>
>>54778552
>>54785567
holy
k e k
>>
>>54785620
there's no nano in that pic you fool
>>
The right. Unfortunately, coding style standards exist, so I'm forced to use this atrocity:

void foo
(
uint16 bar //!< Widget count
)
{
return; // Do nothing
}
>>
>>54785830
lrn2embedcode
>>
>>54785129
Stop using MAX when it's not a max.
>>
>>54785857
happynow?

void foo
(
uint16 bar //!< Widget count
)
{
return; // Do nothing
}
>>
>>54774597
Allman style or GTFO
>>
>>54774661
>implying /g/ is employed
>>
>>54774597
Right or GTFO. Left's only purpose is for Enterprise ® programmers to inflate their SLOC.
>>
>>54774683
If(Condition){Statements/*...*/}
>>
>>54786006
There are no serious people who do that.
>>
>>54774691
Mint imho mate
>>
>>54775193
/* Fizzbuzz */

#include <stdio.h>

int i;

int main(void) {
for (i = 1; i < 101; i++) {
if (i % 5 == 0 && i % 3 == 0) {
printf("Fizzbuzz \n"); }
else if (i % 3 == 0) {
printf("Fizz \n"); }
else if (i % 5 == 0) {
printf("Buzz \n"); }
else {
printf("%d \n", i); } }
return 0; }



I avoid stray braces.
>>
>>54786640
Why did you use a global variable?
>>
File: whitesmiths.png (21 KB, 433x480) Image search: [Google]
whitesmiths.png
21 KB, 433x480
I like Whitesmith' style best, pic related.

Sadly it's not very common, so I am trying to get used to Allman style as I'd likely be forced to use that anyway when I get a job etc
>>
>>54786752
Because I'm new to C, but I wanted to learn it because I'm using Linux.
>>
>>54775193
;}
>>
>>54781326
I do that but with indents
if (true)
{
do_this();
} else {
do_that();
}
>>
>>54786828
Put your variable in the header of your main function.
>>
>>54786756
>I have never done a sizeable project before, and thus do not understand the value of proper indentation.
>>
>>54787227
I have actually done several sizable projects, I've spent close to a thousand hours by myself on a commercial program, so I'm not sure why you say that. Also I don't even see why Whitesmith's is less "proper indentation" than anything else in your opinion. Only reason to switch is that other people don't use it, what is better or worse is entirely subjective.
>>
>>54782363
>Am I in >>/f/?
Why would /f/ care? They mostly just enjoy circlejerking about old 4chan.
>>
>>54774597
    fun foo(num: Int) {
when (num) {
0, 1, 2 -> println("is 0, 1 or 2")
in 3..5 -> println("between 3-5")
!in 6..600 -> println("Not 6-600")
else -> {
if (num.mod(3) == 0) println("mod 3")
else println("unknown")
}
}
}
>>
>>54785129
Constants should be in NAME_ATTRIBUTE style and also put braces and stop being cool.
>>
>>54779138
>declaring y one thousand times
>declaring z one million times
>>
>>54787525
>implying the compiler won't handle that.
>>
>>54774597
I like right more but left is the standard for a reason unfortunately.
>>
>>54787717
What is that reason
>>
>>54788539
More readable/clear. Not much, but it is.
>>
>>54774597

The only reason to ever use the one on the right is if you're writing JavaScript. And that's solely due to the retarded optional semicolon bullshit.
>>
is there a reason you shouldn't just follow the Google style guide for a given language to the T?

i mean, you can assume they know what they're doing better than anyone else
>>
if (x == 10)
{
something();
something_else();
}
else if (!x)
{
not_something();
not_something_else();
}


I don't use "else" statements. If it HAS to be sequential then it's going to be "else if". Just an empty hanging "else" with no condition at all makes me nervous. All functionality must be defined.
>>
>>54788584
Ultimately these things are mostly a matter of opinion. And it's important to be consistent. If you're contributing to an established project, they may have their own style guide. Even if you're not directly contributing to a project, you may be part of an ecosystem. For example, probably just about any Python extension module written in C should follow PEP 7, even though space-based indents are retarded otherwise. Anything contributed to GNU should use the GNU coding style, even though as you can see from >>54774691 it's completely idiotic.
>>
>>54788707
>space-based indents are retarded
You're a code monkey.
>>
>>54774597
>>54774597
Left. I tend to lose track of brackets of i use the method on the right.
>>
>>54788652
But an else with no condition is clearly defined. It will happen in every case the if condition is not satisfied. That is clear. You are autistic and the shit you're adding is probably removed by the compiler anyways
>>
I just write however I write.
I don't let formatting distract me.

Every now and then I click the 'gib nice pls' button in my IDE and it tidies it however the file of the day needs to be formatted. Usually to right for personal shit and left for uni (and if I forget to change the setting in the IDE after doing some uni biz).
>>
if                                                                                                                                                                                                                    (Condition)

//that feel when you will never have a qt trap gf

{S(t(a(t(e(m(e(n(t(s)))))))))}
>>
>>54784933
I like this emem
>>
>>54774625
meirl
Thread replies: 242
Thread images: 22

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.