57
Comments
  • 2
    I do the second when I'm making the function, when I'm happy with it and it's working I change it to the first.
  • 11
    I usually use whichever one is standard for that language.
  • 2
    @LucaScorpion Both are standards in C and C++. You do what's already in the code base.
  • 3
    Incidentally, third type like the GNU people:

    if (condition)
    {
    function(blah);
    }

    Indent 2 for curlies, 4 for body.
  • 7
    Then there's
    If (condition) {statement}
  • 1
    I do the latter but that's because that's how "C For Dummies" taught me.
  • 3
    Java guy here, and I do the first one.
  • 1
    by nature 1 by code convention 2
  • 0
    Former ✋
  • 1
    Used to do the second one but after working on way too much Java is think I'm now the first
  • 1
    did the second, now I do the first. for some reason when I switched I felt like a wizard.
  • 3
    I use the first one... I just hate using a whole line for a single curly bracket. No need. Also it looks more clean, optimized and sensible.
  • 0
    @tisaconundrum yup that's my fave, but not aloud to do it at work.
  • 0
  • 1
    Former.

    However, for the sanity of my staff, I have recently started training myself to do the latter.

    All this conforming to standards and best practices bullshit.
  • 0
    Latter.

    I find it makes matching up the braces easier if I'm looking for them at the same indentation.
  • 1
    Visual Studio refactors to the latter one automatically when coding in C#/.NET mvc.

    But when I'm not coding for work I'm the former.
  • 1
    @Wabby How does this apply to best practices? It has absolutely no impact. It's a first world programmer bugbear.
  • 0
    @JavaRules PSR PHP.

    More guidelines to ensure all our code reads the same tbh.
  • 1
    Also I do

    } else {
    }
  • 1
    @donkeyScript Else and catch are the exception for me too?
  • 0
    @CharByte That's actually a very good way of structuring your thoughts. I generally write documentation when I think the function is final
  • 0
    Former here.
  • 0
    Depends on which language I'm using, but if given he choice - latter because it's easier to see whether the if has a block in curly braces or just a one liner.
    Imagine:
    if (expression)
    statement1;
    statement2;
    }
    statement3;

    in some bigger chunk of code (with the opening curly)... The indentation can easily fool you into thinking both 1 and 2 are gonna execute only if the expression is true... So I think the one line for the opening brace is worth it, otherwise I'd say go for:
    if (expression) {
    statement1; }
    statement2;

    to save the extra line for the closing curly, too.
  • 1
    (ha (ha (ha)))
  • 0
    Then the second one will hate Golang :-)
  • 1
    @emperorcezar you seem to functioning correctly today
  • 1
    @Bikonja Welcome to Devrant :D
Add Comment