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



Thread archived.
You cannot reply anymore.



File: PwK.png (32 KB, 479x330)
32 KB
32 KB PNG
>>
File: 1514641159377.jpg (38 KB, 510x680)
38 KB
38 KB JPG
>>64099601
>9GAG
>>
>>64099601
Use the style recommended by whatever project you are working on.
Use the style you prefer when working on your own projects.
>>
>>64099601
>9gag
>>
>>64099601
don't you mean 10 types of people?
>>
>>64099711
Lol ecksdee. It's easy as 1 10 11
>>
File: 100-100.jpg (49 KB, 907x661)
49 KB
49 KB JPG
>>64099981
HAHAHA HE MADE THAT JOKE AGAIN :D
>>
File: 1512957400443.png (423 KB, 808x805)
423 KB
423 KB PNG
>>64099601
>If programming languages were X
>>
New line for JavaScript. Same line for everything else.
>>
>>64100266
>4/4
>>
>>64100321
This is why everyone hates JS except developers that only know JS
>>
what about

if (Condition) {
Statements
/*
...
*/}
>>
>>64100592
>triggered
>>
File: CvH9gfFWcAA2knK.jpg (29 KB, 594x249)
29 KB
29 KB JPG
Plebs
>>
>>64099601
>not a programmer
>still know

LOCK ME UP
>>
>>64099601
>putting space between "if" and opening parenthesis
cancer
>>
>>64100682
>when you like python for all the wrong reasons
>>
static void Main(string[] args)
{
int = 5 ;
int = 5 ;
bool = false ;

if ( = )
{
= true ;
}
>>
>>64100868
Code tags evidently do not support my emoji variables
>>
>>64100682
Cancer
>>
>>64100682
truly nothing better
>>
>>64099632
THIS.
honestly took me years to fully accept this. I used to enforce my own style in every language and every project I worked on. Now I finally started following the style guide for the specific language I'm working with because i wouldn't want some random person to write ruby style in my java code, etc
>>
>>64100868

>>64100888

It's cool, you seem like a faggot either way.
>>
>>64100682
Commit suicide
>>
The cleanest style:

if (condition)
/* Single statement */

if (condition) {
/* Multiple statements go here */
}

if (condition) {
/* Single or multiple statements */
} else {
/* Multiple statements */
}

void function()
{
/* Anything goes here */
}
>>
>>64101591
at least please be consistent, please use the same brackets for functions. thank you
>>
>>64100682
This is a neat way to enforce a 80 chars limit, but the benefit of parenthesis are a very clear way to describe encapsulation of scope.
While there will always be someone who thinks this is a "issue" (even though the majority agrees on B for if, for and while statements and A for functions), it is not an issue because there will always be a rule of law when it comes to this: The coding standard.
If you can't follow a coding standard when contributing to a project, you need to get the fuck out.
If you can't mentally handle that someone uses a different standard than what you would prefer, then you are a bad programmer.
The same goes for standards regarding whitespace/indentation width, which parts should be indented etc.
Ideally we would have a "coding standard standard" which would be an easy and concise way to describe how the code should be formatted which automatically could be picked up by checkers.
There might be a solution like this, but I am not aware of this.
The same tool could even generate an estimate given an existing project.
>>
>>64101591
There is no reason to use brackets for a single statement just because you have an else.
>>
>>64099601
depending on the language... one of those won't compile
>>
>>64099631
That's pretty much the state of >>>/g/ these days
>>
>>64101591
close, but the first one will lead to bugs guaranteed.
t. professional programmer that has seen many bugs due to leaving out braces for single line if statements

if you're really anal about it being a one-liner, try to turn it into a ternary instead
>>
>>64101622
It may not be important in C, but in C++, it makes a lot of sense to use braces on a separate line for functions.
Take this example of a class constructor:
example::example() :
val(0.1),
ptr(new other_class(val))
{
ptr->some_function();
}

It is easier to read when you do it this way.
Furthermore, it makes it easy to copy paste to your class declaration.

If statements on the other hand will be written several times over and saving space is a better as the statements and the conditions are closely linked.
I often do
if (condition) statement;

when there is multiple tests to be made as it aligns better.
if (condition) statement;
if (condition) statement;
if (condition) statement;
if (condition) statement;
>>
>>64101955
ah yes i do agree in that instance when u have initialization lists it is more elegant to have each on a separate line, sorry.
also the simple inline ifs are also quite elegant i agree.
>>
>>64102117
I never really thought that it also solves the problem >>64101953
states, I just thought it was more readable.
But I guess this is a reason as well.
I basically judge it case by case, some times it is more readable to use braces even if there is just a single argument.
I guess I am not that consistent when I write my own projects
>>
>>64099601
Left is correct.
Right breaks as soon as you need an initializer list.
>>
>>64099601
i'm not a programmer and i get it you stupid sack of faggot nigger shit with down syndrome
>>
>>64100742
K&R can never be wrong you degenerate
>>
>>64099601
There should be one kind of people, the one that stick to the fucking project guidelines.
>>
/*
* ...
*/
>>
>>64102391
This
>>
File: 1511434446.jpg (23 KB, 600x484)
23 KB
23 KB JPG
>using code formatter
>>
>>64101591
>} else {
wrong
>>
>>64099601
Im the one on the right
tend to be alot more compact than that though, much more compact
> multiple statements per line
>>
>>64100682
What's the idea behind this? Are they trying to make C++ (or whatever language that is) look like Python?
>>
>>64100682
fuck I love how compartmentalized this is... I may start doing this
>>
File: emoticonprogramming2.png (428 KB, 1008x872)
428 KB
428 KB PNG
>>64099601
Either is fine as long as you don't cuddle your else statements
>>
>>64101801
>baited
>>
>>64101591
almost correct but the function definition is wrong

int
main(int argc, char *argv[])
{
if(condition)
do_stuff();

if(multi_line) {
do_stuff();
other_stuff();
} else {
do_stuff();
other_stuff();
}

return 0;
}
>>
>>64106081
I personally don't like putting the type specifier on its own line but I do put a storage class specifier on its own line.

I also greatly dislike "array" parameters in C.
>>
>>64100682
>>64100868
autism
>>
>>64105054
It's Java. learn your languages!
>>
>>64099601
I use this
if (cont) {func1;
func2;}
>>
Left is for functions, right is for conditions/loops
This is standard pretty much everywhere
>>
>>64099601
>capital letters
>>
>>64100592
go back to python retard
>>
>>64099601
>There are two types of people.
No, there are a lot more than that.
See <https://en.wikipedia.org/wiki/Programming_style>
and <https://en.wikipedia.org/wiki/Indent_style>
>>
>>64101804
>Not knowing about K&R.
>>
>>64100682
ew
>>
i'm accustomed to assembler so everything i write follows that format
>>
>>64101591
>no bracket if
It's like you want Pajeet to come in, break your code, then blame you for later. Always add the brackets; it's four god damn characters including the newline characters and it prevents so many issues later.
>>
>>64099631
fucking hell came here to post this desu, this should be bannable where the fuck is moot




Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

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.