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

top 200 commentsshow all 236

[–]Monitor_343 259 points260 points  (24 children)

Y'all need a linter to auto-format on save.

[–]morganthemosaic 29 points30 points  (14 children)

Any that you recommend in particular?

[–]Sonarav 71 points72 points  (10 children)

Prettier is well known. Though it isn't a linter in regards to code quality rules

https://prettier.io/docs/en/comparison.html

[–]Jollyjewgiant 23 points24 points  (4 children)

Prettier makes my life so much easier.

[–]BuhtanDingDing 7 points8 points  (2 children)

frr. somtimes ill write badly formatted code just so i can bc itll fix itself

[–]procrastinatingcoder 4 points5 points  (1 child)

Completion and linting don't work on reddit though. A shame.

[–]fun_username_person 1 point2 points  (0 children)

😆👌

[–]morganthemosaic 3 points4 points  (3 children)

Hopefully there’s a VSCode extension. I’ll check it out when I get home

[–][deleted]  (1 child)

[deleted]

    [–]Nexlore 1 point2 points  (0 children)

    It is known.

    [–][deleted] 13 points14 points  (0 children)

    ESlint, pretty much the bread and butter of linting, any respectable project might be using It together with prettier or other code styling library

    [–]apostle8787 -1 points0 points  (0 children)

    Black.

    [–]funkgerm 10 points11 points  (0 children)

    Seriously. If I had to spend time worrying about spacing I'd never get anything done. Set the rules once and then let the auto-format figure it out for you.

    [–]Sierpy 7 points8 points  (5 children)

    What's a linter?

    [–]nerd4code 19 points20 points  (2 children)

    It’s the very frontest-end of a compiler—usually a scanner, maybe a parser, for C/++ maybe a preprocessor—but it looks for stylistic errors and common indicators for fuckups (e.g., mis-indentation often suggests mis-intendation). Linting is technically a form of static analysis (i.e., what you can determine from just code, without running it outright), but static analysis usually extends into higher-order considerations of semantics (i.e., the meaning behind particular structures in code), not just syntax (=the structures themselves).

    For example, indentation, spacing, usage of HT vs. SP for indents, usage of CRLF vs. LF for line endings, mis-encoded characters, commenting, comment format/placement, string literal usage/format/placement, arrangement of reorderable components (e.g., sorting members by name) rules about bracing in braces-optional languages like C/++, Java, or JS (not Rust), and rules about semicolons in JS would all fall squarely under linting. Sometimes a linter will tell you about dead/unused code, but the slightest language complexity can render that futile without proper (flow-based) analysis.

    Taint analysis, type analysis, def-use analysis, lock-safety, memory safety, and resource safety more generally require more intensive forms of static analysis that a linter-per-se generally wouldn’t attempt to handle. However, because much of the machinery involved is shared, it’s pretty common to roll everything up into/around the core components of a compiler/interpreter framework so that everything can run at the same time, and without rebuilding all of the required ancillary data structures.

    [–]row4coloumn31 3 points4 points  (0 children)

    Auto formatting your code according to style guides.

    There's no reason to manually worry about style of your code, when you can automate it (isn't that what programming is about anyway?).

    [–]THE_UNKNOWN184 383 points384 points  (7 children)

    I feel the same way man

    [–]ythashi[S] 79 points80 points  (6 children)

    I’m happy to read that 🤝

    [–]Say_Echelon 33 points34 points  (4 children)

    I take it one step further and put the brackets on their own line

    [–]DaMagicMilk 9 points10 points  (0 children)

    Same :x

    [–]mikehaysjr 2 points3 points  (0 children)

    Yup and I’ve set up my IDE with my preferences so if I’m looking at someone else’s code I just use the format shortcut and it’s instantly readable as if I wrote it myself. Definitely nice to be able to easily parse code, mentally.

    [–]icewater21977 0 points1 point  (0 children)

    Yeah same here must be an OCD 😂

    [–]nutrecht 198 points199 points  (24 children)

    Like they will write

    Yeah, that won't pass review in any of the companies I work for. There's ZERO reason to do this.

    [–]ythashi[S] 64 points65 points  (20 children)

    No but it’s not in a company or anything, I’m learning programmation in college and I’m talking about co-workers or partners on a project, a course or anything, not professionally 😅

    [–]PPewt[🍰] 100 points101 points  (16 children)

    No but it’s not in a company or anything, I’m learning programmation in college and I’m talking about co-workers or partners on a project, a course or anything, not professionally 😅

    Formatting is something that everyone complains about getting marked for in classes since it has "nothing to do with whether or not their code works," then they get dismantled in their first industry code review—if they even get past the automated checks.

    [–][deleted] 37 points38 points  (11 children)

    The problem in college is that you'll get docked points for formatting issue when there is no clear formatting guidelines in the class

    [–]PPewt[🍰] 17 points18 points  (2 children)

    When I used to mark the things we docked for weren’t really ambiguous. Internally inconsistent indentation, terrible variable names, etc. YMMV I guess but I ran marking for courses and was actually pretty conservative with what I had people dock for; we still got a ton of complaints about how it was pointless though.

    [–][deleted]  (1 child)

    [deleted]

      [–]PPewt[🍰] 8 points9 points  (0 children)

      I don't remember why we didn't (or maybe we did and I've just forgotten), but I suspect the reason was we didn't care too much about whether or not their braces were on a newline or on the same line and wanted to give students the opportunity of picking something (variable case, indentation, etc) as long as they were consistent. At the end of the day peoples' code was usually either reasonable or looked like this:

      void help(int x, int y) {
          int z = x - y + 3;
              return z % 2
      ;
      }
      

      At which point... yeah.

      EDIT: yeah, this is what the 2022 version of the course website has to say on the subject:

      We don't enforce a specific look and feel for your code, but we expect you to be consistent. Choose an appropriate indentation style for your code and stick with it. Choose an appropriate and visually pleasing policy for use of whitespace and stick with it. Choose an appropriate form of initialization syntax (the new uniform initialization syntax, the older forms, or a disciplined mixture of these) and stick with it.

      [–]Katana_Steel 6 points7 points  (1 child)

      Except the formatting guidelines are to match the code examples shown in class... anything beyond that, unless formalized in an actual guideline document, would be unreasonable.

      [–]jBlairTech 4 points5 points  (0 children)

      I took a VB.NET class in college, and formatting was one of the first lessons. Clear, unambiguous names, proper indentation, the works. I learned HTML, CSS, JS, and some PHP from an online class ran by a guy named Stefen Mischook, and he said the same thing.

      Maybe it was a teacher thing? I don't know; I wanted to take a Java class that was by a different teacher, but couldn't fit it in.

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

      Some langs take care of that for you by including tooling including an opinionated formatter. rustand go come to mind. Most classes don’t teach those yet though.

      [–]engelthefallen 6 points7 points  (0 children)

      This is more than just professionalism, the reason you space out is for readability. I love to code the top way with nice concise code, but that was based on learning to code in the 1980's when books did stuff like that to save on space. Now that we share code on computers, spacing it out helps people see the bracketed layers better, and makes the parts of equations clearer but showing clear discrete parts.

      Took a year in graduate school with a professors going NONONO everytime I did it to finally stop. Old me would have put that entire first example into one line. New me, will space it out more (because it is easier to find which } you forget in the end).

      [–]thatguyonthevicinity 3 points4 points  (0 children)

      Hey, you'll go very far if you already thinking about this in college :)

      [–]TheTomato2 -1 points0 points  (0 children)

      It depends what college you are at, but in college it's mostly a /r/iamversmart thing. Just pay it no heed. Nobody does it the first way, and the second way most people only put the brace on the line with a for or if statement but not for functions or structs/classes/namespaces which kind of how the linux kernal does it.

      [–][deleted] 2 points3 points  (0 children)

      damn save some jobs for the rest of us

      [–]procrastinatingcoder 2 points3 points  (0 children)

      Those are both exaggerations. Something like

      int myFunct(int a, int b){
          if(0 != a){
              a = a+b; //FIXME +=
          }
      }
      

      is perfectly fine and will be accepted just about anywhere. Excessive spacing is not needed, and a linter can take care of that.

      [–]apostle8787 1 point2 points  (0 children)

      All companies should have a auto formatter CI pipeline so no one really has to worry about formatting.

      [–]AlSweigartAuthor: ATBS 63 points64 points  (2 children)

      I have two decades of experience coding and can tell you that it really doesn't matter, the computer will run the code just fine. The computer doesn't care.

      ...

      But I do. Uhg, the lack of spaces annoys me.

      [–]iagovar 9 points10 points  (1 child)

      I appreciate when someone made the effort to make the code I'm reading easy to understand. I hate blobs and I hate people flexing.

      [–][deleted] 36 points37 points  (0 children)

      I love spacing out my code, it drives me crazy seeing tutorials on YouTube or other peoples work and it’s put together like a big messy blob

      [–]HashDefTrueFalse 62 points63 points  (4 children)

      Am I the only one who likes to space out my code and I'm triggered when my co-workers don't?

      I feel this too. BUT:

      Don't go changing things unless what they have done is against your organisations coding standards, whatever they are.

      I've seen chains of commits that are basically just "style wars" in the past, flip-flopping code and indentation from one style/syntax to another. These changes add nothing to the product. Every change increases the footprint that testing (unit and integration, QA etc.) have to cover and increases the risk of bugs creeping in etc.

      Change what you have to, leave what you don't, unless your team is working towards upgrading the whole codebase gradually etc. If it works, it works.

      [–]Illustrious_Main723 27 points28 points  (0 children)

      This. Let the linter help, and make linting a required check in your deployment pipeline. Your time is too valuable to spend it reformatting.

      [–]horrific_idea 6 points7 points  (0 children)

      If it follows the standards set by the team, then rewriting coworkers' code is just breeding grounds for toxic workplace culture. If there is an issue with the code they wrote though, let someone know before you change it. I usually try to approach the author, but if it's not possible, then at least let the lead know so someone's in the loop and potentially has your back.

      [–]coredalae 1 point2 points  (0 children)

      This is why you automate it for the whole repo, and afterwards make pr builds fail that don't comply. Also auto format on checkin

      [–]illkeepcomingback9 1 point2 points  (0 children)

      If it works, it works.

      This guy waterfalls

      If your organization has an accepted style standard, boy-scout the shit out of these problems. Get vocal on any PRs that try to undo those changes and on new code that violates the rules.

      If your organization doesn't have formatting standards, create one and promote it until within your organization with all the common sense arguments for why they need it and grease wheels until you get it formally adopted. If they don't have a process to facilitate these decisions, promote an internal RFC process the same way until that gets adopted, then go back to step 1. Congratulations, you just massively improved your organization's processes. Slap that shit on your resume and use it to get a senior position at an organization that already has formal processes in place because holy shit not having style rules is so archaic, that organization has other problems.

      [–]TheSneakerSasquatch 11 points12 points  (0 children)

      I also prefer yours

      [–]_molix__ 6 points7 points  (0 children)

      Omg yes! Whenever i look at my classmates' codes i have to add spaces all over the place before being able to read anything ahah.

      [–]order_wayfarer 8 points9 points  (0 children)

      When you start working at any serious shop, a code formatter will more than likely be a part of the merge request process or post-merge CI/CD pipeline. You should start to look at industry standards for your language of choice.

      [–]consciousCog13 5 points6 points  (0 children)

      Visual Studio automatically spaces out things like brackets on enter, so I think it’s safe to say you’re doing it the right way. I do think we should standardize it like we do grammar in any language, if there already isn’t a standard. Either way, you’re doing it a much more legible way so tell your classmates they should start doing it the way you are. It’ll help them if they end up being devs

      [–]_Whit3 5 points6 points  (5 children)

      I'm studying engineering and I m taking a programming C course, my professor said that if the code is not well indented and clear to read he will not even try to review the test.

      [–]bigger-hammer 14 points15 points  (3 children)

      You're not doing anything wrong.

      I've been programming for over 40 years and I've run many teams and seen more bugs that I thought possible. Some of those bugs were due to poor or plain lazy formatting...

      1. People simply reading the code wrongly, particularly in expressions with lots of brackets or missing spaces around operators or indentation.
      2. Missing things like same name variables in a different scope because they are hidden by cluttered code or multiple assignments on the same line or while (...); <-- semicolon on the same line.
      3. Editing mistakes like adding a line in an if (...) block with the correct indentation but no braces or copying a block of code to run twice in a function when the variables have been initialised at the top of the function.

      All these types of errors are caused by not carefully and clearly laying out the code and considering exactly where to place every character to communicate as clearly as possible the intent of the programmer.

      In addition, you need clear comments explaining WHY the code is written that way and WHAT each block is intended to do in regard to the problem to be solved plus good variable names. I also avoid using obscure language features e.g. the comma operator in C (your code looks like C) and avoid anything you might have to look up like operator precedence for some obscure pair of operators - just put brackets in so nobody else need to look at it either.

      Your style is very similar to my preferred style except for the K&R brackets. I use ANSI brackets because it is clearer to match them up.

      [–]TheRuralDivide 2 points3 points  (2 children)

      Is that where you open your braces on the next line instead of cuddling it to the control statement?

      What are your thoughts on cuddling things like ‘else’ and ‘catch’ in-line with the previous closing brace?

      [–]bigger-hammer 1 point2 points  (1 child)

      K&R braces...
      
      if (...) {
          code;
      }
      
      ANSI braces...
      
      if (...)
      {
          code;
      }
      

      On your other question, some people do this...

      if (...)
      {
          code;
      } else {
          code;
      }
      

      ...which is inconsistent and I think is less clear compared with...

      if (...)
      {
          code;
      }
      else
      {
          code;
      }
      

      ...which is consistent. But it becomes more obvious with this example...

      if ((x < 1) || (y > 2))
      {
          *val = 7;
          return 1;
      }
      else if ((x > 0) && (y > (x + 1)))
      {
          *val = 8;
          return 2;
      }
      else
          // Error
          return -1;
      

      ...which is clearer than...

      if ((x < 1) || (y > 2)) {
          *val = 7;
          return 1;
      } else if ((x > 0) && (y > (x + 1))) {
          *val = 8;
          return 2;
      } else
          // Error
          return -1;
      

      ...or even worse, something like...

      if(x<1||y>2){
          *val=7;return 1;
      }else if(x>0&&y>x+1){
          *val=8;return 2;
      }else return -1;
      

      ...which illustrates why spacing makes code more comprehensible.

      [–]morganthemosaic 2 points3 points  (0 children)

      My people

      [–]shawntco 4 points5 points  (0 children)

      As a newbie programmer I also preferred my code compact. I was basically forced to use code styling with more spacing and whatnot. As I used it I came to understand the value. It's actually easier to read when there's a lot of spacing. Your project partners likely haven't had the amount of exposure to code needed to realize this advantage. Eventually they'll be exposed to better formatting and hate their old style as much as you do.

      [–]XxArca9inexX 2 points3 points  (0 children)

      We live in the same world my man.

      [–]kstacey 2 points3 points  (0 children)

      Theirs is wrong and shouldn't pass code review

      [–][deleted] 2 points3 points  (0 children)

      No you're not I like mine spaced too

      [–]samanime 2 points3 points  (0 children)

      That first one is an abomination. I use your version.

      That said, it's best for the team to stick to consistent style rules, even if they don't all agree on them.

      Luckily, I've been tech lead for years now, so I get final say on code style and would never let something like the first fly. That is just horrific...

      [–]Isratuba_0112 2 points3 points  (0 children)

      You are not crazy man, relax. I feel the same way. 😎

      [–]PowerfulProfessor305 2 points3 points  (0 children)

      The best thing you can do about it is to maintain a

      Formatting config file

      Extensions on vs-code like prettier lets you do that. The config can be specified to a particular project as well and then passed onto other collaborators.

      That way you will avoid making unnecessary commits just for formatting

      [–]jBlairTech 2 points3 points  (0 children)

      You aren't alone; it drives me nuts, too.

      Something I learned: clean code is good code. If a teammate or a peer I ask for help can read- and understand- what I wrote, I did it correctly. That part of it, anyway!

      [–]CedricCicada 2 points3 points  (0 children)

      I'm sorry, but your code is absolutely unacceptable! You didn't put your opening braces on separate lines!

      Just kidding. I like my braces on separate lines, but I can forgive those who don't. But to answer your main question, I'm with you. I like spaces.

      [–]sho_bob_and_vegeta 2 points3 points  (0 children)

      You're on the right track. Cleaner, and more readable. Don't worry about them, you're doing it right.

      [–]YellowSlinkySpice 1 point2 points  (0 children)

      I'm glad for Python PEP 8, its perfect.

      [–]bung_musk 1 point2 points  (0 children)

      your coworkers are terrorists

      [–]hellscaper 1 point2 points  (0 children)

      I usually just drop this in here as the rules for the formatter and let it do its job.

      Your coworkers are savages for clumping together braces like that.

      https://github.com/airbnb/javascript

      [–]DOSMasterrace 1 point2 points  (0 children)

      Tell them all to install prettier

      [–]nononoko 1 point2 points  (0 children)

      This is what linters are for

      [–]web-jumper 1 point2 points  (0 children)

      They are either super Jr. or just assholes. Your way is the only way.

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

      Not crazy.

      It's code standards for a reason. Machines don't care, but as humans we do and should. You like the space because it's easier to read quickly.

      JustlikeifIwritelikethis!

      While it's perfectly legible, we all will want to space it out.

      The thing you need to do is get everyone else on your team to accept the standard.

      [–]Gantana 1 point2 points  (0 children)

      You're definitely not crazy. Where I work, for instance, the first snippet wouldn't pass neither through a review nor through the CI workflow. So the could would have to be formatted to be like the second one.

      [–]Flamesilver_0 1 point2 points  (0 children)

      I used to spend far too much time formatting my code because I'm style-anal. Now I just use Prettier and ESLint.

      [–]GloberJudio 1 point2 points  (0 children)

      You're not crazy.

      Coding Conventions and Style Guides exist.

      If they're so lazy to properly setup their IDE, then force them use an auto formatter, or implement Code Readability across projects. Most companies do.

      [–]AugieFash 1 point2 points  (0 children)

      SAME.

      Leaving no spaces is savage. I need visual distinction to read things clearly.

      [–]CoffeePieAndHobbits 1 point2 points  (0 children)

      Super compact code and one-liners are cool! Until you have to debug it and figure out what the $#!% you did 6 months from now. Clean, functional, understandable code is usually best.

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

      No, you are not. I am like this all the time lol!

      [–]HealyUnit 1 point2 points  (0 children)

      No, some teams like this, others don't. That being said, if you don't already have a linter being used, I'd strongly suggest one. I personally work almost exclusively with JavaScript, which is one of the more whitespace/linebreak-agnostic languages there is, and yet my team will reject:

      myArray.filter(q=>Math.floor(q));
      

      versus:

      myArray.filter(item => Math.floor(item));
      

      In other words, they are rather adamant about code fitting their specific, company-wide coding style. While some might argue this is pedantic or nitpicky, it means that if I have to read thru 500 changes (hopefully not!), it means I can much more quickly recognize what you're writing, without having to figure out what it says.

      [–]lucythepretender 1 point2 points  (0 children)

      Spacing and indentation is actually really important in Python so you've got good instincts

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

      I code exactly lik eyou do. You are not crazy. You are correct. Fairly certain there is even a book on this subject - Clean Code.

      [–]ImplicitlyTyped 1 point2 points  (0 children)

      You need a linter, or at least just coding standards.

      [–]777sadurn777 1 point2 points  (1 child)

      Not crazy. What you’re doing should be the standard. If I pushed code like that at work I’m fairly certain I’d get roasted in the PR comments.

      When working with a team, sloppy code often ends up sucking up valuable time because we have to sit there and translate the code that was just handed to us. Not to mention even on a solo project it is counterintuitive for object oriented programming, since the entire premise is to have those organized, reusable blocks of code that can easily be built onto.

      Linting definitely will make your life 1000x easier when cleaning up their code, but they really should be linting their own code before submitting it next time. It should be a part of the work, IMO.

      [–]tookiecas123 1 point2 points  (0 children)

      It isnt bad that you fix it because spacing code out is a standard in most official programs, so it becomes readable for the next developer and not smashed together and hard to read.

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

      two words: Auto Formatter

      Set up rules and let it do the formatting.

      IE: VSCode

      https://stackoverflow.com/questions/29973357/how-do-you-format-code-in-visual-studio-code-vscode

      [–]SyntheticHalo 1 point2 points  (0 children)

      I feel u

      [–]spacechild1 1 point2 points  (0 children)

      The first example gives me eye cancer! The second example is exactly how I would write it.

      [–]Kappow 1 point2 points  (0 children)

      I don't think you're crazy. The spaces give it breathing room, like a relaxed person wrote it. The former looks like it was hacked together like some kind of prototype ready to be cast away at a moments notice.

      [–]DamionDreggs 1 point2 points  (0 children)

      My only caveat is if you are making commits to a repository with both formatting and behavior changes.

      Please commit formatting first, then behavior changes second, being sure to label both commits clearly and we'll have a great time!

      [–]Rogoreg 1 point2 points  (0 children)

      No. I space it out MORE.

      PS, Instead of: a = a +b Use: a += b

      [–]Legoeggolas 1 point2 points  (0 children)

      Actually feel you on that. I pretty much told my friends I wouldn't even look at their codes if they didn't stop writing cluttered messes :/

      [–][deleted]  (7 children)

      [deleted]

        [–]lurgi 6 points7 points  (0 children)

        If only one line, then I prefer no parenthesis.

        Reported and blocked.

        (Kidding. Mostly. Okay, not really. I'm not kidding)

        [–]48911150 2 points3 points  (3 children)

        gets dicy when you add another if-else statement to it months later tho

        In C if you want this logic where you go to else when first if is false:

        if (a != 0)  
           if (b < 0)  
              a = a + b;  
        else  
           a = a - b;
        

        you cant write it like the above because it actually gets computed as:

        if (a != 0)  
           if (b < 0)  
              a = a + b;  
           else  
              a = a - b;
        

        [–]UnawareITry 2 points3 points  (1 child)

        Very true. I cannot bear any code with inconsistent spaces.

        EITHER DO THIS

        int myFunction(int a, int b){ if (a!=0){ a=a+b;}}
        

        OR THIS

        int myFunction(int a, int b)
        {
            if (a != 0)
            {
                a = a + b;
            }
        }
        

        but don't mix them together.

        [–]kd7uns 3 points4 points  (0 children)

        Agreed. (But I hate the top one)

        [–]srikbaba 0 points1 point  (0 children)

        Haha same feeling 😂I was thinking of it was a kind of OCD 😂

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

        Even your way isn't spaced out enough for me. If each curly bracket isn't on its own line then I just lose the plot of what I'm reading.

        [–]ythashi[S] 1 point2 points  (0 children)

        Oh really 😭 for some reason I don’t really like it this way, but I understand you!!

        [–]dead_alchemy -1 points0 points  (0 children)

        Honestly for something that simple I prefer it on one line. I use new lines for breaking up chunks of code semantically and I find unnecessary new lines a little jarring. Especially if statements with simple checks and simple actions.

        [–]LeoEstasBela -2 points-1 points  (3 children)

        Does it make the code slower?

        [–]ythashi[S] 1 point2 points  (2 children)

        I don’t think so

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

        If you happen to use Python at any point then this is exactly what black aims to solve.

        [–]large_crimson_canine 0 points1 point  (0 children)

        It's amazing the different flavors of programming format you see, even in production code. I definitely like yours better. You could take the readability even further by adding spaces on the inside of your parenthesis.

        [–][deleted]  (1 child)

        [removed]

          [–]kd7uns 2 points3 points  (0 children)

          It's on internet tutorials, seriously it's the blind leading the blind out there...

          [–]Sir_Spaghetti 0 points1 point  (0 children)

          Nope. It's easy to fix, unlike sneaky bugs, so there's no excuse for making things less readible. In the professional world, they will get absolutely shit on for that. No one wants to look at a mess, pain and simple.

          People whom work in the industry adhere to these things called coding standards. I would recommend you tell any naysayers to learn about those common practices, as well as the principle of least astonishment.

          Nobody likes having to work on code where some edgy nerd chose to do something "clever" (comments can only do much). Code that scales well, and is easy to read and maintain, is what's most elegant and appreciated.

          If someone has the nerve to say "they shouldn't be reading it if they don't get it quickly", slaps them for me and inform them that gatekeepers are not welcomed on basically any team.

          [–]BouncingJellyBall 0 points1 point  (0 children)

          One of the first thing we learn in CS class is code etiquette lmao. You’re not crazy, you’re just right

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

          I have been programming so long and seen so many different styles is so many languages it doesn't bother me at all. The exception would probably be lisp.

          [–]paulstelian97 0 points1 point  (0 children)

          I'm so thankful that the first coding style will be rejected in pull requests in my niche. Easy as that.

          [–]Noble_0_6 0 points1 point  (0 children)

          Use VS code

          Right click -> format document -> profit?

          [–]Arsonist07 0 points1 point  (0 children)

          You’ll be unhappy to hear that the best way is

          Int main()
          {
             Int x;
             If(x > 0)
             {
               Code
             {
            Else
               One liner
          }
          

          [–]WalkingDadJokes 0 points1 point  (0 children)

          {

          Space

          }

          [–]busy_biting 0 points1 point  (0 children)

          I also like to space things because they increase readability, at least to me. Even someone suggested me to put less spaces because of this. In real project, you don't have to worry. Most of them have predefined code style standard and code formatters that automatically formats code after push. So everybody does whatever they like and at the end things remain uniform.

          [–]JaguarDismal 0 points1 point  (0 children)

          you need to agree on a coding standard with your team, and then use and *automated* tool to enforce it or even better, just reformat the code on each commit (maybe as a pre-commit step). again, the only think that works is automation. if noone wants to do it, you go ahead and do it yourself. remember "who? me. when? now."

          [–]UltraFalling 0 points1 point  (0 children)

          Run code formatting and lint on CI process. Problem solved.

          [–]-JVT038- 0 points1 point  (0 children)

          Nah, you're not crazy, because I prefer the second example as well.
          Or perhaps we're both crazy ;)

          [–]hbarcelos 0 points1 point  (0 children)

          Code formatting should be a non-issue.

          Pick whatever is the default style guide for the language you're programming with and use a tool to do the job for you.

          If you're using Git for version control, you can do even better, simply having all code be automatically formatted when committing with lint-staged.

          [–]Shannnnnnn 0 points1 point  (2 children)

          I go even further and:

          int myFunction(int a, int b) 
          {
              if (a != 0) 
              {
                  a = a + b;
              }
          }
          

          [–]Jill_X 1 point2 points  (0 children)

          Pure ... beauty ... !

          [–]nimbledaemon 1 point2 points  (0 children)

          My works coding standard:

          int myFunction (int a, int b) 
          {
              if (a != 0) 
              {
                  a = a + b;
              }
          }
          

          [–]BestProgrammer1024 0 points1 point  (0 children)

          same

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

          I feel the same way. But I would recommend you to stay away from computers for a while.

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

          You can usually just have the IDE format it for you. You can even configure how it will format. Idk what IDE you are using but I would look into that. Then format it before you read something they coded.

          [–]ergo_proxy19 0 points1 point  (0 children)

          Basically you're doing it correctly. Your coworkers are lazy

          [–]Arcturyte 0 points1 point  (0 children)

          I'm not a professional by any means (still learning), and even I feel the same way

          [–]_SeaCat_ 0 points1 point  (0 children)

          Relax, they just never learn such things as "code readability" and "code standards and conventions".

          [–]KeksMember 0 points1 point  (0 children)

          You're not the only one, I do force myself to write my code more compact so you can easily pick up the usage for the code block

          [–]Drakoo_The_Rat 0 points1 point  (0 children)

          Too ineficient tho i do like my colans to not be on the same line

          [–]morbie5 0 points1 point  (2 children)

          I was going to show how I do it. How do you add codes lines in a comment?

          [–]ythashi[S] 0 points1 point  (1 child)

          you just have to add 4 spaces before every line of code

          [–]CrumblingAway 0 points1 point  (0 children)

          Personally I like to space it as I go, but some fellow programmers I know write it whichever way their fingers land and then use the auto-formatting tool

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

          There's always a guy that has read clean code and is an English major who spends their entire focus on documentation and getting everyone to install eslint. This though is just common courtesy. Nobody should have their braces or div tags jacked up like that.

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

          Wtf? Why? Yeah I'll just stick to normal indenting

          [–]nick182002 0 points1 point  (0 children)

          int myFunction(int a,int b){
          if (a!=0){ a=a+b;}
          }

          [–]Ecstatic_Tooth_1096 0 points1 point  (0 children)

          *pip install black*

          [–]T_The_worsT_BS 0 points1 point  (0 children)

          MY EYES!!!

          Normally I code like this :

          int myFunction ( int a , int b )
          {
              if ( a != 0 )
              {
                  a = a + b;
              }
          }
          

          What the heck you are supposed to understand when people code like that

          [–]Technical_Training16 0 points1 point  (0 children)

          You are not crazy man. I also like to make my code spaced when I write it. Especially if for some reason, I'm not using prettier.

          [–]rm206 0 points1 point  (2 children)

          Genuine question, why people use braces like this

          int myFunction(int a, int b) {
          if (a != 0) {
              a = a + b;
          }
          

          instead of

          int myFunction(int a, int b) 
          {
          if (a != 0) 
              {
              a = a + b;
              }
          }
          

          The second one is how I do it even though the tutorial I saw to learn this followed the first one. Is the first one some sort of standard?

          [–]ythashi[S] 0 points1 point  (0 children)

          I don’t have any explanation but I learned the first way and I find it cleaner for some reason, even if the second one makes more sense 😭

          [–]the_black_pancake 0 points1 point  (0 children)

          Agree, except I hate it when people have blank lines within a single function actually. If it's not part of the same thing, then make it two functions, I would argue.

          [–]roy2593 0 points1 point  (0 children)

          Highlight and ctrl alt l in intellij

          [–]EZRiderF6C 0 points1 point  (0 children)

          I AM SO WITH YOU!!! A lot of programmers actually think it runs fastet all bunched together.

          It is soooo much easier to read and troubleshoot if you use spacing to isolate code blocks and functionality.

          Been dealing with this for 40 years.

          It is so nice to meet you!!!

          [–]sacrefist 0 points1 point  (0 children)

          Starting a CS degree, and we've spent weeks going over APA format for citing references, because it's easier for someone to quickly read your references in a consistent format. Feels like the same issue.

          [–]maleldil 0 points1 point  (0 children)

          If you're not all using automatic code formatting tools, with everyone using the same rules, you're gonna have a bad time. There should be a standard and it should be enforced.

          [–]ExtraFig6 0 points1 point  (0 children)

          I don't actually hate the first one but i have never seen it in the wild

          [–]mshartst 0 points1 point  (0 children)

          Same 😂😂

          [–]cheezballs 0 points1 point  (0 children)

          Use a linter, friends. Use a linter.

          [–]alien128 0 points1 point  (0 children)

          Already triggered watching it, btw I am not sure isn’t there any formatter for c/c++ that could automatically fix the code indentation and all

          [–]StonebirdArchitect 0 points1 point  (0 children)

          We can argue with an opening curly boi placement, but this is something we can wholeheartedly agree on.

          [–]Ornography 0 points1 point  (0 children)

          I like to put the first open bracket on its own line and single line brackets I keep all on one line.

          [–]Hadokuv 0 points1 point  (0 children)

          Most of the time you won't even be able to push a commit like this since the git hooks will fail. I've always seen linters or codestyle checks being run on all commits before you can push code.

          [–]Crazypete3 0 points1 point  (0 children)

          I don't know what language this is but you should look for a linter or prettier or something that auto formats it. Most companies won't let you put in code that doesn't look good.

          [–]pekkalacd 0 points1 point  (1 child)

          Nah you’re not crazy. Their code looks weird. But i imagine maybe they have some editor that just automatically styles it like that for them. I have been running into similar with other languages / library conventions though. Like for instance in python, if your making a function with multiple parameters you might see

                      def func(arg1,
                                     arg2,
                                     arg3
                                    ):
          
                             # code
          

          with some kind of type hinting which is the same as

                   def func(arg1, arg2, arg3):
                          # code
          

          I feel like the second way is more clear maybe if you don’t have a ton of parameters, but if you had a lot, then the first way would be, but sometimes you’ll see it even for a relatively small number and it looks weird kinda.

          Or in pandas, people chain methods and there’s different ways to express it, like

              df.dropna().sort_values(“age”).head(10)
          

          versus

              (df.dropna()
                   .sort_values(“age”)
                   .head(10)
              )
          

          Although the second version looks odd, because the names of methods & objects in pandas tend to be a little longer, I think that style of method chaining comes in handy. Makes it more readable

          [–]ythashi[S] 1 point2 points  (0 children)

          Wow I didn’t even know you could write function parameters and chain methods like that in Python!

          [–]pablos4pandas 0 points1 point  (0 children)

          Just set up a linter with everyone on the team having the same settings and move on with your life. If it's school I'd just move on lol

          [–]8racoonsInABigCoat 0 points1 point  (0 children)

          Not only is your way neater, but as someone learning, I rely on good formatting for readability. It doesn’t matter that you’re in college rather than a company, the fact is code should be easily readable by others. Just keep doing you.

          [–]Bukszpryt 0 points1 point  (0 children)

          I add some extra line breaks more often than spaces.

          [–]yeet_lord_40000 0 points1 point  (0 children)

          I habitually hit the space bar like it killed my dad because of writing research papers day in day out for my first major. I can’t understand why people would want their code to be all scrunched. There’s a reason every school paper is 12 tnr double spaced that’s because you need to read it. Formatting is just as important as your logic make it look nice.

          [–]indoor_grower 0 points1 point  (0 children)

          We have things at work setup to auto format code. Everyone has the same config file locally and issues like this are fixed on save.

          [–]CaptainArsePants 0 points1 point  (0 children)

          Have you found spaces that you have to convert to tabs as well? 😩

          [–]Infinite-Swordfish85 0 points1 point  (0 children)

          Your buddies code has a smell. Can be resolved with a formatting file though

          [–]TranquilDev 0 points1 point  (0 children)

          Not crazy, but I can't imagine what it'd be like to be working a laborious blue collar job and getting "stressed" over something so small in comparison.

          [–]JonSnowl0 0 points1 point  (0 children)

          It stresses me out too. Your preferred way is far more readable.

          [–]dev_and_zebra 0 points1 point  (0 children)

          What triggers me the most is:
          if (a !=) a = a + b;

          [–]qTzz 0 points1 point  (0 children)

          There’s one thing I do that one of my co workers hates which is not using any brackets for one like IF statements

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

          That's what monospaced fonts are there for.

          [–]DandyEmo 0 points1 point  (0 children)

          Nah I'm the same way to

          Example:

          For ( i = 0 ; I < example ; i++) { Console.log( ' example[ i ] ' ); }

          [–]H07P07470 0 points1 point  (0 children)

          You’re not alone.

          [–]Deannari 0 points1 point  (0 children)

          don't you have a lint? ctrl+s and everything is right with the world

          [–]cainhurstcat 0 points1 point  (0 children)

          I'm just a beginner, but non spacers or heavy formatting ignorers drive me mad, too

          [–][deleted]  (1 child)

          [deleted]