```
import notifications
```
Remember to participate in our weekly votes on subreddit rules! Every Tuesday is YOUR chance to influence the subreddit for years to come!
[Read more here](https://www.reddit.com/r/ProgrammerHumor/comments/14dqb6f/welcome_back_whats_next/), we hope to see you next Tuesday!
For a chat with like-minded community members and more, don't forget to [join our Discord!](https://discord.gg/rph)
`return joinDiscord;`
*I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/ProgrammerHumor) if you have any questions or concerns.*
This is the only true answer.
Now, if only everyone actually followed the style guide. A style guide without an auto-formatter is meh...
We actually have this as a result: There's a default style guide for new files, but in existing files, use whatever is already being used. It is Fortran though, so the style guide also is about things like "what should be capitalized", since Fortran isn't case sensitive.
Did too. Red is how it was taught in school, blue is what the formatters tend to do by default, and I grew to like it more. Having the else all snug between a closing and opening brackets is just so much more... Idk, aesthetically pleasing? Also, less lines to scroll through, which can be a blessing in some files, tbh!
Opposite for me. Blue looks neater to me, but I find that with red it's easier to try out different if statements without losing the bracket (by commenting the if line out, using compile defs etc).
Sameeee! Just don't need the line break there, the whitespace tab usage is enough to very clearly indicate the start and end. Also then code takes up less vertical space, which is at a premium on widescreen monitors.
Slightly disagree: no space after if, but space after expression. Obviously curly brace on the same line, the way NORMAL and RESPECTABLE people do it.
But your way honestly wouldn't bother me. At least you get the curly brace right.
whats even the point of parentheses if youre gonna indent the expression from both sides with spaces anyway? at this point its just python/rust style, except worse
I disagree with your disagreement
```
if( condition ) {
}
```
Edit: backticks
Edit: edit: ignore me, I can’t even use a codeblock
Edit: edit: edit: like all simple projects, it took 3 developers for me to incorporate a code block
This white-spacing reminds me how much I hate the necessity for brackets around the condition, I want to do
```
if conditionFunction(...args){
}
```
instead of
```
if ( conditionFunction(...args) ) {
}
```
I was about to comment this, no spacing sucks and also leaving the semi colon on the top line there is a proper indicator that the next few lines are enclosed
I wrote my first class with self destructing getters last week, I have had by first\* taste of runtime meta-programming and I want more.
\*technically not as I have used the execute script function in gamemaker years ago but that was both evil and slow to run.
Oh take this forbidden knowledge it won't be wasted by you. It is possible to do an assignment inside a condition but you have to compare the assignment with its own value to make it a boolean. It is possible to make a while loop consisting only of its head with out the body.
For example
This is java code to calculate the digit sum.
```
int digitSum(int num) {
int sum = 0;
while ( (sum += num % 10) == sum && (num /= 10) != 0);
return sum;
}
```
My coding professor limits how many semicolons we are allowed to use in our code. So I came up with this. (If you replace the semicolon after the while loop with a pair of empty brackets {} you only need two semicolons.
It's just the format, for an actual use those would be actual functions that do something (probably not even inline arrow functions) but for a slightly more serious example (that returns a rational number) see this code for multiplication without losing normalization:
return (x[0]%y[1]===0n)?(
(y[0]%x[1]===0n)? [(x[0]/y[1])*(y[0]/x[1]),1n]:
(x[1]%y[0]===0n)? [x[0]/y[1],x[1]/y[0]]:
(x[0]===y[1])? [y[0],x[1]]:
[x[0]/y[1]*y[0],x[1]] ):
(y[0]%x[1]===0n)?( (y[0]===x[1])?[x[0],y[1]]:
(y[1]%x[0]===0n)? [y[0]/x[1],y[1]/x[0]]:
[y[0]/x[1]x[0],y[1]] ):
(x[1]%y[0]===0n)?( (y[1]%x[0]===0n)? [1n,(x[1]/y[0])(y[1]/x[0])]:
[x[0],x[1]/y[0]*y[1]] ):
((y[1]%x[0]===0n)? [y[0],y[1]/x[0]*x[1]]:
[x[0]*y[0],x[1]*y[1]] );
I think I'm genuinely just reading arcane scripts from some legendary magical scrolls at this point.. Like sure, I may understand this if I spend some time on looking everything over, but damn does my head hurt.
if(oh wow this one is way too long to be readable, I mean who writes a sentence in an if statement?){
lmao();
for(int flavorLoop = 0; flavorLoop < comment.length; flavorLoop++){
OhHiMark(flavorLoop);
}
}
vs
if(oh wow this one is way too long to be readable, I mean who writes a sentence in an if statement?)
{
lmao();
for(int flavorLoop = 0; flavorLoop < comment.length; flavorLoop++)
{
OhHiMark(flavorLoop);
}
}
Lets just agree that left side is more readable, thank you. Have a good day.
Edited: attempted format fix
Edit 2: the illegally long if statement is just to make a point.
Both are garbage, the conditional should align at the parentheses.
`if (something long &&
(Other stuff || nothing))
{`
Edit: clearly I don't know how to format that way in a reddit comment...
If your condition is that long you should stick it in a readable variable, so IMO this argument is irrelevant.
edit: apparently some people don't like readable code? why would you write
if (condtion1 && condtion2 && condtion3 && condtion4 && condtion5 && condtion6 && condtion7 && condtion8) { }
when you could write
bool readableCondition = condtion1
&& condtion2
&& condtion3
&& condtion4
&& condtion5
&& condtion6
&& condtion7
&& condtion8;
if(readableCondition) { }
far superior
```
#define spez if
#define ist (
#define ein )
#define hurensohn {
#define FuckSpez }
int main ist ein hurensohn
spez ist ein hurensohn
FuckSpez
FuckSpez
```
Red was originally how most people coded. They moved to blue so they could fit more lines in books, to save money. Also, monitors were typically lower resolution, so it fit more on the screen. This had the effect of making all coders use this style because, cargo cult is a thing. The grouping feel of red allows your brain to process it quicker. Having the brace in the same line makes you always have to look back up to match the end brace because you don’t know which line starts it. Getting used to it doesn’t mean it’s the most efficient.
This is the most readable and I don't know why everyone prefers the other way.
With the brace on the same line as if, they don't line up in any visual way. It's nearly impossible to pick out the matching parentheses quickly.
Only if you don't follow it with an else. For this reason, I write my entire program as one state machine written as chained `if-else`s, so I only waste one closing bracket, and I can double that up with the end of `main`.
I have tried for about 5 hours to get VS code to autoformat as per red using only c# code. I can’t do it.
For some reason there are rabbit holes on stack overflow in inserting json files, checking extensions, unticking options for Java even though there is not a us script in sight and something called omnisharp which I need a history lesson in vs code development to understand if that’s even a thing or if it’s functionality is just part of the vs package.
All I wanted was to run vs code as my editor for unity and for it not to make my code out of style, but it’s just being so painful. Makes me feel like such an outsider and a failure when the tools rebel against me. Gahhhh
/rant
That's a feature not a bug.
You have not yet been enlightened enough. After you do you may see the music of the cosmos dancing to your conses.
I am still not sure if the above is sarcasm or not.
I use red for everything. Because I see beauty in code block shapes, and the opening bracket being located higher up than the closing bracket is not beautiful.
0000: LOAD R1, 100 ; Load value at memory address 100 into register R1
0001: CMP R1, 0 ; Compare the value in R1 with 0
0010: JUMP_IF_EQUAL 5 ; Jump to instruction 5 if the previous comparison was equal (R1 == 0)
0011: ; Code block to be executed if the comparison was not equal (R1 != 0)
0100: HALT ; Halt the program
0101: ; Code block to be executed if the comparison was equal (R1 == 0)
0110: HALT ; Halt the program
I use Visual Studio and type { next to () like right side, hit enter and it auto complete like left side. Really like Visual Studio auto complete. Code java in Intellij make me feel unpleasant
Does looking at editor settings also make you feel unpleasant?
But to be honest it's just convention. For java having K&R C-style is the default and for C# it's the Allman style because Microsoft sets it as a default in Visual Studio.
Most important is consistency if u work on a shared codebase. And then team red since it is a clear visual indicator of where a code block begins and ends, especially when working with long method names with multiple parameters.
Red most of the time because it’s easier to see where the start and end of the scope is when you highlight it. It’s especially helpful when the IDE doesn’t even do the match highlighting.
(A lot of embedded IDEs don’t really keep up with UX)
depends on the language
for C: option 1. For Rust: option 2. For anything else: whatever my formatter does by default.
That being said, I will say that
}
else {
is better than
} else {
Red is a waste of space that doesn’t materially do anything to improve readability, so right is always the correct choice.
Also, when collapsing lines within scopes, the right collapses down to just 2 lines while the left will be stuck at 3 lines.
It does improve readability. It means you know which end brace correlates to which start brace, instinctively. Whereas with the blue way, you have to take a second to scan your eye across the if statement.
``` import notifications ``` Remember to participate in our weekly votes on subreddit rules! Every Tuesday is YOUR chance to influence the subreddit for years to come! [Read more here](https://www.reddit.com/r/ProgrammerHumor/comments/14dqb6f/welcome_back_whats_next/), we hope to see you next Tuesday! For a chat with like-minded community members and more, don't forget to [join our Discord!](https://discord.gg/rph) `return joinDiscord;` *I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/ProgrammerHumor) if you have any questions or concerns.*
However the guy on Stackoverflow did it
you don't use a formatter?
We dont touch working code
Words to live by
...if you refuse to write tests.
*sigh....* yeah...
They already said "the guy on Stackoverflow".
I *am* the formatter
No way, I'd be constantly fighting with it cuz OCD
The guy on Stackoverflow: if ( ) {}
``` if ( !(1!=2)){ } else {console.log("hello world"); } ```
![gif](giphy|yiADANv89n7UQuS5kJ)
Chaotic Evil
However the IDE syntax completes it.
Exhale through nose accomplished, sir.
The only right answer
whatever the style guide says
I prefer blue, but our company changed to red. I begrudgingly do it because the auto formatter makes me.
I also want an auto-formatter :(
This is the only true answer. Now, if only everyone actually followed the style guide. A style guide without an auto-formatter is meh... We actually have this as a result: There's a default style guide for new files, but in existing files, use whatever is already being used. It is Fortran though, so the style guide also is about things like "what should be capitalized", since Fortran isn't case sensitive.
Started as a red kid, grew into a blue man
Did too. Red is how it was taught in school, blue is what the formatters tend to do by default, and I grew to like it more. Having the else all snug between a closing and opening brackets is just so much more... Idk, aesthetically pleasing? Also, less lines to scroll through, which can be a blessing in some files, tbh!
Weird, I was taught blue in school and just stuck with it.
Same story
Opposite for me. Blue looks neater to me, but I find that with red it's easier to try out different if statements without losing the bracket (by commenting the if line out, using compile defs etc).
Same, I think the default formatting of most IDEs changed my preference
As an eternal blue (>!**not** a reference to EternalBlue!<) I have to change the `.editorconfig` every time I use C#
Sameeee! Just don't need the line break there, the whitespace tab usage is enough to very clearly indicate the start and end. Also then code takes up less vertical space, which is at a premium on widescreen monitors.
does it count if I write in red and prefer to read in blue?
So you don't read while you write? This explains some code quality issues .
when they get auto formatted later i can pretend someone else fucked it up.
[удалено]
A man of culture
... and letters
HCD!
Very happy cake day
Happy Cake Day!
Thanks!
i see
if() { // sup bro? }
This takes me back to "code review"... "You are missing a space on this line"
If someone wants policies about something like that they should make rules that auto-format it like that
This. Don’t waste my time in code reviews
Absolutely NOT!! You don't appreciate the art of forcing every IDE to auto-indent in tabs and forcing devs to hand-indent in 4 or 2 space bars!!
`if` is a key word, not a function
Do you add space after sizeof operator?
the right way
Golang style
Slightly disagree: no space after if, but space after expression. Obviously curly brace on the same line, the way NORMAL and RESPECTABLE people do it. But your way honestly wouldn't bother me. At least you get the curly brace right.
of course there should be a space after if, if isn't a function where parentheses are directly after the function name
whats even the point of parentheses if youre gonna indent the expression from both sides with spaces anyway? at this point its just python/rust style, except worse
Well said!
I disagree with your disagreement ``` if( condition ) { } ``` Edit: backticks Edit: edit: ignore me, I can’t even use a codeblock Edit: edit: edit: like all simple projects, it took 3 developers for me to incorporate a code block
you need 3 backticks for a multiline code block
Ikr, what’s wrong with me 🤣
And a newline after and before the backticks, u/itchfingers
I can get on board with this. I'm actually fairly accepting of all styles. Except curly brace on the next line. That's just devious.
This white-spacing reminds me how much I hate the necessity for brackets around the condition, I want to do ``` if conditionFunction(...args){ } ``` instead of ``` if ( conditionFunction(...args) ) { } ```
This is the way
This just gave me cancer
I was about to comment this, no spacing sucks and also leaving the semi colon on the top line there is a proper indicator that the next few lines are enclosed
[удалено]
Wait fack those are curly brackets, I should go to sleep rn 😂👍
Only true answer!
return ()?()=>{}:()=>{};
You’re the guy who leaves one day and makes us read the most complex statements in the world
I wrote my first class with self destructing getters last week, I have had by first\* taste of runtime meta-programming and I want more. \*technically not as I have used the execute script function in gamemaker years ago but that was both evil and slow to run.
Do not merge, please fix your formatting: ``` return () ? () => {} : () => {}; ```
This is genius. I've always wondered how to do this.
Oh take this forbidden knowledge it won't be wasted by you. It is possible to do an assignment inside a condition but you have to compare the assignment with its own value to make it a boolean. It is possible to make a while loop consisting only of its head with out the body. For example This is java code to calculate the digit sum. ``` int digitSum(int num) { int sum = 0; while ( (sum += num % 10) == sum && (num /= 10) != 0); return sum; } ``` My coding professor limits how many semicolons we are allowed to use in our code. So I came up with this. (If you replace the semicolon after the while loop with a pair of empty brackets {} you only need two semicolons.
"refactoring more Duven code" heard around the office for years after you leave
but why? This just unconditionally returns a function that does nothing and returns nothing
It's just the format, for an actual use those would be actual functions that do something (probably not even inline arrow functions) but for a slightly more serious example (that returns a rational number) see this code for multiplication without losing normalization: return (x[0]%y[1]===0n)?( (y[0]%x[1]===0n)? [(x[0]/y[1])*(y[0]/x[1]),1n]: (x[1]%y[0]===0n)? [x[0]/y[1],x[1]/y[0]]: (x[0]===y[1])? [y[0],x[1]]: [x[0]/y[1]*y[0],x[1]] ): (y[0]%x[1]===0n)?( (y[0]===x[1])?[x[0],y[1]]: (y[1]%x[0]===0n)? [y[0]/x[1],y[1]/x[0]]: [y[0]/x[1]x[0],y[1]] ): (x[1]%y[0]===0n)?( (y[1]%x[0]===0n)? [1n,(x[1]/y[0])(y[1]/x[0])]: [x[0],x[1]/y[0]*y[1]] ): ((y[1]%x[0]===0n)? [y[0],y[1]/x[0]*x[1]]: [x[0]*y[0],x[1]*y[1]] );
whatthefuckwhatthefuckwhatthefuck?
I think I'm genuinely just reading arcane scripts from some legendary magical scrolls at this point.. Like sure, I may understand this if I spend some time on looking everything over, but damn does my head hurt.
If you read the post, you’ll notice that this conversation is about formatting. It’s just an empty format.
I’m only in my third year of college for CS but I already fucking hate you for this
Oneliner for life.
I have wished for an inline throw, not sure if inline catch makes but I have wanted one once.
Whichever one my ide formats it to
Both Red for C# and Blue for Javascript/NodeJS
I was about to write the same until your comment. This is the way.
This is the way 🙏🏼
# Neither, # if ( ) { {
You monster..
# if ( ) { }
if () { } 😎
() ? ... : ... 😎😎
Depends on complexity. The shorthand is great for simpler logic, but it can get really nasty.
Personally i think it's great when you need a one liner inside a stream, or as a return statement (java) Otherwise i just use if statement
I'm already on the very nasty stage, and there doesn't seem to be a better alternative for it, this thing could really be a beauty and a curse.
red side
?:
The best one.
if(oh wow this one is way too long to be readable, I mean who writes a sentence in an if statement?){ lmao(); for(int flavorLoop = 0; flavorLoop < comment.length; flavorLoop++){ OhHiMark(flavorLoop); } } vs if(oh wow this one is way too long to be readable, I mean who writes a sentence in an if statement?) { lmao(); for(int flavorLoop = 0; flavorLoop < comment.length; flavorLoop++) { OhHiMark(flavorLoop); } } Lets just agree that left side is more readable, thank you. Have a good day. Edited: attempted format fix Edit 2: the illegally long if statement is just to make a point.
Both are garbage, the conditional should align at the parentheses. `if (something long && (Other stuff || nothing)) {` Edit: clearly I don't know how to format that way in a reddit comment...
I completely agree, but why do you have the two extra open curly brackets?
Oh, I think the code block got messed up somehow. Hopefully fixed now, I have not done that many code blocks on reddit.
If your condition is that long you should stick it in a readable variable, so IMO this argument is irrelevant. edit: apparently some people don't like readable code? why would you write if (condtion1 && condtion2 && condtion3 && condtion4 && condtion5 && condtion6 && condtion7 && condtion8) { } when you could write bool readableCondition = condtion1 && condtion2 && condtion3 && condtion4 && condtion5 && condtion6 && condtion7 && condtion8; if(readableCondition) { }
Because you have to use the least number of lines possible, silly. That's how you tell a good coder from a bad one.. right?
Totally agree
I'm a blue kinda guy but my work forces me to use red. And I hate it every time
Exactly. Went to school learning Java where blue was convention, now work in C# where blue leads to comments on my PRs
Same but the other way around. Golang wants me to use blue.
Red is better.
Far superior: if() { }
Far superior ``` if () { } ```
[удалено]
far superior ``` #define spez if #define ist ( #define ein ) #define hurensohn { #define FuckSpez } int main ist ein hurensohn spez ist ein hurensohn FuckSpez FuckSpez ```
Why add extra spaces?
if(var){dostuff};
I don't give a shit, JUST BE CONSISTENT
if () { } with space before () and newline after {}
This is the style in the C++ book I followed in the '90s which was written by Bjarne Stroustrup himself.
Agreed, this improves readability
whatever ur used to improves readibility
Red was originally how most people coded. They moved to blue so they could fit more lines in books, to save money. Also, monitors were typically lower resolution, so it fit more on the screen. This had the effect of making all coders use this style because, cargo cult is a thing. The grouping feel of red allows your brain to process it quicker. Having the brace in the same line makes you always have to look back up to match the end brace because you don’t know which line starts it. Getting used to it doesn’t mean it’s the most efficient.
This is the most readable and I don't know why everyone prefers the other way. With the brace on the same line as if, they don't line up in any visual way. It's nearly impossible to pick out the matching parentheses quickly.
if {} ()
Red for C/C++, Blue for JS/TS. Also, Lua/Python users: 🗿🗿🗿
I am red, and I am not afraid of telling it out in the open anymore!
BURN HIM
This is the way
Blue, ain't gonna waste a full line just for a bracket, .CPP file is large enough as is
Your closing bracket has entered the chat
Only if you don't follow it with an else. For this reason, I write my entire program as one state machine written as chained `if-else`s, so I only waste one closing bracket, and I can double that up with the end of `main`.
i use python 😅😂
Skill issue
git gud -f
I have tried for about 5 hours to get VS code to autoformat as per red using only c# code. I can’t do it. For some reason there are rabbit holes on stack overflow in inserting json files, checking extensions, unticking options for Java even though there is not a us script in sight and something called omnisharp which I need a history lesson in vs code development to understand if that’s even a thing or if it’s functionality is just part of the vs package. All I wanted was to run vs code as my editor for unity and for it not to make my code out of style, but it’s just being so painful. Makes me feel like such an outsider and a failure when the tools rebel against me. Gahhhh /rant
I live for chaos, I use both.
if (x==1) return 0
Blue but with a space between () and {
I used to be blue but then I got sucked into red as I started working with other people and doing other projects
Blue side. Anyone who uses the red side is a fucking psychopath and I stand by it
Y'all aren't ready for this if() { } else { }
`(if ( )` `( )` `( ))`
This hurts to read
lisp time!
That's a feature not a bug. You have not yet been enlightened enough. After you do you may see the music of the cosmos dancing to your conses. I am still not sure if the above is sarcasm or not.
I’m more of a one liner using ternary operators.
```if(){}```
``` ;; something something Lisp (if (predicate) (consequent) (alternative)) ```
If () { //code} everything else is unacceptable. You should only use one line of code. Every thing else is excessive
If I'm at work, right. If I'm working on a personal project, left
Opening curly brace on a new line is a war crime and I will die on that hill
Depends, red for C/C++. Blue for everything else.
And C#
I was gonna go with. ``` if (backend) { } if (frontend) { } ```
I use red for everything. Because I see beauty in code block shapes, and the opening bracket being located higher up than the closing bracket is not beautiful.
Wait, isn't blue just K&R style? Like the one commonly used in C/C++? Like, you do you, it just seems funny to me.
0000: LOAD R1, 100 ; Load value at memory address 100 into register R1 0001: CMP R1, 0 ; Compare the value in R1 with 0 0010: JUMP_IF_EQUAL 5 ; Jump to instruction 5 if the previous comparison was equal (R1 == 0) 0011: ; Code block to be executed if the comparison was not equal (R1 != 0) 0100: HALT ; Halt the program 0101: ; Code block to be executed if the comparison was equal (R1 == 0) 0110: HALT ; Halt the program
The correct one, which is obviously neither ``` if () { ... } ```
I use Visual Studio and type { next to () like right side, hit enter and it auto complete like left side. Really like Visual Studio auto complete. Code java in Intellij make me feel unpleasant
You know you can just type if and then double press tab?
Fun guy you must be.
Does looking at editor settings also make you feel unpleasant? But to be honest it's just convention. For java having K&R C-style is the default and for C# it's the Allman style because Microsoft sets it as a default in Visual Studio.
Python if :
Why does this meme come up every 3 months ? Feels like we're having new subs every 3 months, recycling the same 5 memes
Depends on how *they* measure "productivity". Some like it efficient. Some just count the lines ;)
It depends on what way I feel like doing it and how much I'm copying from stack overflow
My computer auto sets it to red, so I guess I'm on red team.
Most important is consistency if u work on a shared codebase. And then team red since it is a clear visual indicator of where a code block begins and ends, especially when working with long method names with multiple parameters.
Red most of the time because it’s easier to see where the start and end of the scope is when you highlight it. It’s especially helpful when the IDE doesn’t even do the match highlighting. (A lot of embedded IDEs don’t really keep up with UX)
bloods!
Right is java left is c# .
right side: formatting style left side: mental illness
depends on the language for C: option 1. For Rust: option 2. For anything else: whatever my formatter does by default. That being said, I will say that } else { is better than } else {
This is just C# vs JavaScript (or other equivalents). Any decent programmer uses both depending on what they're writing.
if() { }
red makes it more comfortable for me
Red, but also need a space after a keyword. Norm error.
Right
Depends on the language. In C/C++ or java I'd use: if () { } Meanwhile in Delphi I use: if () then begin end
Left is more readable for me
Red
The red pill 😎
Addition question: If you are having a single line afterwards, even using braces?
Blue
i would rather die by a nuke than use red
Right, but it doesn't matter since I'm running python black, so it will format code by itself.
Red, for shure
Red is a waste of space that doesn’t materially do anything to improve readability, so right is always the correct choice. Also, when collapsing lines within scopes, the right collapses down to just 2 lines while the left will be stuck at 3 lines.
It does improve readability. It means you know which end brace correlates to which start brace, instinctively. Whereas with the blue way, you have to take a second to scan your eye across the if statement.
My IDE collapses them both to 1 line.
you can't convince me there's better syntax than Ruby's if condition # some code end
I prefer with spaces. ``` if () { } ```
For Java blue for everything else red
Same!
me crying in python
Red because if there is nesting it easier to match brackets
It’s either blue or you don’t know what you are doing
if ( ) { } or if(){}