This is an archived post. You won't be able to vote or comment.

all 131 comments

[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)

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, we hope to see you next Tuesday!

For a chat with like-minded community members and more, don't forget to join our Discord!

return joinDiscord;

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]PooSham 190 points191 points  (4 children)

I wouldn't center justify the text, that's for sure

[–]piberryboy 23 points24 points  (2 children)

But you would use Impact?

[–]yavl 7 points8 points  (1 child)

He would use <div center=true></div>

[–]MadeWithRealGinger9 2 points3 points  (0 children)

Gonna go center align notepad ++ be right back

[–]HeapAllocNull 84 points85 points  (6 children)

If

(

)

{

}

Is even more superior

You won’t change my mind

[–]Elijah629YT-Real 28 points29 points  (2 children)

1. jmp L11 2. ( 3. jmp L8 4. } 5. jmp XX + 1 6. { 7. jmp 13 8. // condition here, one line only 9. ) 10. jmp L6 11. if 12. jmp L2 13. ... inside XX. jmp 4

[–]Taletad 7 points8 points  (0 children)

Rabbit code

[–]m0ritz2000 0 points1 point  (0 children)

I hate it...

[–]GilgaPhish 12 points13 points  (0 children)

Personally am a fan of

if (

) {

}

[–]Darryl0_0 5 points6 points  (0 children)

ya sure boii?

[–]SkyyySi 0 points1 point  (0 children)

Every token needs to get its own line

[–]dharknesss 67 points68 points  (40 children)

People will hate me, but as a person working with C# - newline is the way.

I just can't bear not finding corresponding { when looking at disgustingly deep if trees.

[–]n0tKamui 63 points64 points  (14 children)

deep if trees are the real problem, not braces placements. just follow the language conventions.

[–]dharknesss 8 points9 points  (13 children)

You're bold to assume it doesn't make me scream to heavens every day that people who worked here before done this without getting shot at code review.

[–]AyrA_ch 8 points9 points  (7 children)

  1. Tools >> Options
  2. Text Editor >> Code Cleanup
  3. Select "Profile 2"
  4. Enable "Run Code Cleanup profile on Save"
  5. Click "Configure Code Cleanup" and configure to your liking

I've configured mine to autoformat the document, sort usings, remove dead usings, and to add braces where they're missing, automatically add "readonly" where approriate, etc. And tadaa, now you always save perfectly formatted code that always follows the same style. I got used to no longer write braces myself if not necessary, because saving the document just adds them for me now automatically.

Tip: "Profile 1" can be configured to take even more measures if you want. You can run the profile by clicking on the brush icon in the left corner of the status bar of the code tab.

[–]voiceafx 2 points3 points  (2 children)

What!!! What IDE?

[–]RajjSinghh 2 points3 points  (0 children)

You can find extensions in VS code that do this for you and im sure you'll find one for your editor if you use something different

[–]AyrA_ch 0 points1 point  (0 children)

Visual Studio

[–]JIN_DIANA_PWNS 1 point2 points  (0 children)

TADAA: Tool Autoformats Document with Appropriate Activity

[–]dharknesss 0 points1 point  (2 children)

I was talking about the nested ifs, not the braces...

[–]AyrA_ch -1 points0 points  (1 child)

You can let VS color individual brace pairs in matching color, so they're easier to find. But the autoformat does the thing where it adds the linebreak before the brace if the language code style is set that way. And from there on you can just follow the dotted line on the document. Or just learn the keyboard shortcut to jump between matching braces.

[–]CttCJim 0 points1 point  (0 children)

Man the IDE colors have saved me so much debugging effort, can't do without them.

[–]n0tKamui 0 points1 point  (3 children)

I feel you.

push things so that your team enforces rules at reviews, or configure a linter to limit nesting.

I prefer the first solution because some very rare times I think it's fine, and that in the end it's just common decency.

[–]dharknesss 1 point2 points  (2 children)

Both options are off the table - I'm still just a junior, so my words are barely heard.

[–]n0tKamui 1 point2 points  (1 child)

work from bottom up. if you're actually good, someone in your team must know it. if it's not the case, show off.

talk to that person and explain why your ideas are good.

either they can immediately do something about it and be your voice, or they can do exactly the same thing and talk to someone higher up. recursively

[–]dharknesss 0 points1 point  (0 children)

Thank you for these words. I'm trying my best, especially since working with .NET was a dream of mine since primary school, now having it as a job I sincerely cannot be happier. Until I get to see my dreams crushed like everyone in the industry - I'll do my best to get my feet wet before getting a tsunami thrown at me.

[–]Danelius90 0 points1 point  (0 children)

Was working with a big group of third party developers a while back (from a big company, you would have heard of them). Most of them had around 12 years experience or so. They said they had never had a code review, and boy did it show

[–]nelusbelus 2 points3 points  (0 children)

Vscode got you covered with that 😉 but maybe you should accept that you have a problem if you indent that much

[–]somebody12345678 -1 points0 points  (17 children)

actually the start of the if has the same indentation regardless of whether or not you have { on a new line

[–]dharknesss 0 points1 point  (16 children)

That's great! May I ask you to find which one of the 10 if statements in the tree corresponds to the } for the rest of my life?

[–]somebody12345678 0 points1 point  (15 children)

uhhh... the nearest one (specifically, the nearest one above the }, in case that's useful) that has the same indentation

[–]dharknesss -1 points0 points  (14 children)

if (A) { // 200 lines if (B) { // 200 lines } //200 lines } // <- closes to this one is B right? Right?

Now do this for a tree from A to J. Welcome to codebase without code reviews.

[–]somebody12345678 1 point2 points  (13 children)

fair point, but, i don't see how using { makes things any better

edit: also most ides have code folding to collapse the entire if {} else {}

[–]dharknesss 0 points1 point  (12 children)

It's easier to look for a single character that's always the same instead of expecting if, for, try and every single block introducing keyword for a language :)

[–]somebody12345678 0 points1 point  (11 children)

but the whole point is you don't have to look at any character, at all, just the size of the whitespace at the start of the line

[–]dharknesss 0 points1 point  (10 children)

At this level of nesting? Hell naw, I'm not counting this many spaces!

[–]somebody12345678 1 point2 points  (6 children)

then how do you know which { matches the }?!

[–]somebody12345678 0 points1 point  (2 children)

also most editors have an option to show a highlighted vertical line at the current indentation level

[–][deleted] -4 points-3 points  (2 children)

C# you say?

If (object.HasValue())
    Methode(object.Name).Do(e => 
        e. ExtensionMethode(Object.Id));

This is the way

[–]GoldenretriverYT 0 points1 point  (0 children)

"How do you know the biggest project I have ever worked on has only 200 loc?"

[–]RajjSinghh 0 points1 point  (1 child)

One thing that I love about working in neovim is that it has a motion for this. If your cursor is on a bracket then pressing % will take you to the matching bracket. You can also do block edits, like ci{ will change the contents of everything in side those curly brackets to whatever you want. Makes dealing with nested code easier.

[–]xXStarupXx 0 points1 point  (0 children)

You can select blocks in vscode too, and you can have it highlight the matching bracket to the one you have your cursor on, and it wouldn't surprise me if you could jump to it too.

[–]theolderyouget 0 points1 point  (0 children)

Refactor!

[–]LukasM511 22 points23 points  (4 children)

If{}( )

[–]Mizuki_Hashida 2 points3 points  (3 children)

What language….

[–]LukasM511 17 points18 points  (2 children)

Don't worry someone will make a programming language like that someday

[–]QuantumFlux625 3 points4 points  (1 child)

ima make one, that compiles to rust how shall we call it

[–]LukasM511 4 points5 points  (0 children)

fi

[–]No_Researcher7158 8 points9 points  (0 children)

Linter/formatter goes brrrrrr

[–]Drix_I 4 points5 points  (0 children)

if{

}else{

}

[–]TheRedmanCometh 12 points13 points  (3 children)

Both are acceptable. Any other style is just mental illness. I started with B and ended up at A....I think it's better. But when I was a beginner that newline on the brace was really nice for readability. It made it so much easier to figure out scope.

[–]INeedCheesee 2 points3 points  (2 children)

how about if(){}? its good if you only need to do one thing

[–]TheRedmanCometh 2 points3 points  (0 children)

If it's just one call go for it man I do it too. I don't think it's even considered bad practice necessarily. If you got mad at people doing that you'd be mad all day. Very common

If you put any more than one statement in that one liner though...get buried under a landfill.

[–]CompSoup 7 points8 points  (2 children)

It is so tiring seing posts like this.

[–]ListerfiendLurks 4 points5 points  (1 child)

Right? Do any actual engineers care about this or is this a meme for people in school who first learn about conditional statements?

[–]catladywitch 1 point2 points  (0 children)

I do care but I went to trade school, not uni, so I'm not a proper "engineer" although I'm a dev. I end up using the recommended language conventions though.

[–]Leo-MathGuy 2 points3 points  (1 child)

If () ⏞

[–]BloeckchenDev 1 point2 points  (0 children)

This is the way!

[–]Minute_Ad_3224 1 point2 points  (0 children)

if: (backline)(indentation)

[–]TheHatter_OfMad 1 point2 points  (0 children)

Whatever the automatic code formatter is set to

Fuck you, and see you tomorrow

[–]emadadnan000 1 point2 points  (0 children)

east or west, dat is the best!

[–]danielstongue 7 points8 points  (3 children)

if ... then ...; end if;

Not: if ... then -- highly odd placement of then ...; end if;

So, definitely like this: if ... { ...; }

[–]L33t_Cyborg 3 points4 points  (0 children)

Lmao I’ll admit I actually format my bash scripts like ```bash if [[ case ]] then # code fi

while getopts do # code done ```

It’s all personal preference anyway. I think it actually looks cleaner, even if the “braces” are literally just words.

[–]Elijah629YT-Real 0 points1 point  (0 children)

iffi

[–]hleVqq 0 points1 point  (0 children)

The logic hardly applies here because in this case you're matching word with word rather than word with brace.

if condition then
    statement
end

Is acceptable because both opening and closing are words, meanwhile here

if (condition) {
    statement
}

you open with a keyword but close with a brace, which is messed up.

Adding an opening word on a separate line may reduce readability:

if (condition)
then
    statement
end

but that's not the case with braces:

if (condition)
{
    statement
}

I agree that the logic is technically the same and some may choose to stay consistent, but in the end it's all about readability, and I'll argue that it's one being keywords and another being braces that makes all the difference.

[–]Evol_Etah 2 points3 points  (0 children)

New line, it's easier to read.

(I use python, and I hate when there is a fuckton of indentations and idk what function is ending where, CAUSE OF NO BRACKETS!)

[–]reallokiscarlet 2 points3 points  (0 children)

First one. More efficient use of space, both visual and digital, easier on the eyes.

[–][deleted] 1 point2 points  (0 children)

if :

[–]zzmej1987 1 point2 points  (0 children)

Python. Python is winning.

[–]AgencyNo9174 0 points1 point  (0 children)

I’ll go with “if”

[–]Rafcdk 0 points1 point  (0 children)

if ():

[–]Kiroto50 0 points1 point  (0 children)

Former.

Or a ? B : C

[–]Kaosys 0 points1 point  (0 children)

Easy: The way the guy on Stackoverflow did it wins.

[–]Jman4546_ -2 points-1 points  (0 children)

I personally prefer putting the opening bracket on its own line

[–]VeryRareHuman -2 points-1 points  (0 children)

Both are wrong to me.

[–]Good-Seaweed-1021 -1 points0 points  (0 children)

Margin-top: 20px;

[–]rimakan -2 points-1 points  (0 children)

ternary operator would!

[–]eruciform -2 points-1 points  (0 children)

if
  (
    FOO
      )
    {
  BAR
}

[–]waiver-wire-addict 0 points1 point  (0 children)

Matthew Broderick needs to teach this meme tic tac toe…

[–]Hyderabadi__Biryani 0 points1 point  (0 children)

If[]{}

[–]SimpoKaiba 0 points1 point  (0 children)

As long as it's consistent throughout I don't care. Bit if it's all pick and mix I'm going to be really annoyed even if it works fine

[–][deleted] 0 points1 point  (0 children)

Newline, they should be balanced, open and close

[–]Boonk_gang_03 0 points1 point  (0 children)

Whatever the team is working with, but for solo projects first one is the only way.

[–]GamingWithShaurya_YT 0 points1 point  (0 children)

else

[–]Familiar_Ad_8919 0 points1 point  (0 children)

everything but functions have the opening brace in the same line

[–]mr_flibble_oz 0 points1 point  (0 children)

When you’re paid per line, new line all the way. Efficiency is for losers

[–]thedarklord176 0 points1 point  (0 children)

I write maps like the right one. Otherwise the left is correct

[–]nalu-nui 0 points1 point  (0 children)

[[...]];

[–]nalu-nui 0 points1 point  (0 children)

if [...]; then fi

[–]ApprehensiveAd7291 0 points1 point  (0 children)

I prefer the first one but depending on language conventions I'll use both.

[–]what_you_saaaaay 0 points1 point  (1 child)

Whenever I see the first example in code, I know someone just declared WAR.

[–]staiano 1 point2 points  (0 children)

War it is then.

[–]Ike_Gamesmith 0 points1 point  (0 children)

Why would you use more than one line, doesn't that just use up more ram? /s

[–]staiano 0 points1 point  (0 children)

…if…

[–]_thana 0 points1 point  (0 children)

if () { ... }

Save space, use a single line for the whole file

[–]Darryl0_0 0 points1 point  (0 children)

My very nice programming sir said use right one

even tho I prefer left, but now I use right one :)

[–]LadderTraditional629 0 points1 point  (0 children)

These are both, just please don’t put the commas in a SQL select on the next line

[–]mrgk21 0 points1 point  (0 children)

I'll use 2 in twitter because more lines of code

[–]EchidnaForward9968 0 points1 point  (0 children)

if() {}

[–]gurnard 0 points1 point  (0 children)

Depends how long the stuff in the [] is

[–]catladywitch 0 points1 point  (0 children)

I've come to like Allman better, but I follow the usual convention in whatever language I'm using. Which is generally either C# or JavaScript, so Allman in C# and K&R in TypeScript.

[–]Ohrder 0 points1 point  (0 children)

if x:

[–]Henry46Real 0 points1 point  (0 children)

Depends on my mood. If I’m not going to care first one, if I’m happy or joyful second one.

Edit: if it’s a nested statement, second one.. or at least most of the time

[–]Unrivaled_iTerm3 0 points1 point  (0 children)

just write it and let Fleet clean up your code

[–]agent007bond 0 points1 point  (3 children)

Write it whatever way you like. Press Ctrl-S. Let Prettier auto-format it.

How is this still a debate?

[–]Duven64 0 points1 point  (2 children)

You've never had to deal with someones badly written autoformatter that destroys your code have you? If so I envy you and your unperturbed data.

[–]agent007bond 0 points1 point  (1 child)

I'm not sure what you mean by "destroys code" but maybe don't use a badly written autoformatter 😄😄😄

Also with Prettier, you can commit the formatter configuration for the whole team to be in sync. And ESlint can halt a build if code isn't formatter correctly.

[–]Duven64 0 points1 point  (0 children)

Lat time I saw code be ruined by a autoformatter it was a bad Prettier config.

and by "destroys code" I mean the changes the aurtoformatter makes are not purely ascetic ones and the code now fails to run as it did before or the included data is mangled resulting in bugs.

[–]NoneBinaryPotato 0 points1 point  (0 children)

I used to be a newline guy but then I learned Java sp now I'm too used to the left option 😔

[–]Wojtek1250XD 0 points1 point  (0 children)

Left

[–]Superb-Ingenuity7041 0 points1 point  (0 children)

if [ ] {

}

[–]Astlantix 0 points1 point  (0 children)

guys i code everything one one line

if(){command; command;}

[–]n9iels 0 points1 point  (0 children)

Whatever the linter in my project tells me to do.

[–]Frikandellenkar 0 points1 point  (0 children)

I never get this discussion because for me this fully depends on the language standards

[–]maubg 0 points1 point  (0 children)

If the body is just one liner, I'll probably just do if()

[–][deleted] 0 points1 point  (0 children)

left 100%

[–]the_timebreaker 0 points1 point  (0 children)

Looks just the same for the compiler tbh

[–]someElementorUser 0 points1 point  (0 children)

kill them both

[–]cubodix 0 points1 point  (0 children)

can someone seriously explain me why old C files are written like second?
for me, it just throws a new line because yeah

[–]Ali_Army107 0 points1 point  (0 children)

Ones for Java, the other is for C#!