84

when your teacher says he prefers this:
class A
{
// code
};

over this:
class A {
// code
};

me: can u not

Comments
  • 11
    That's fine for classes. Methods/loops/if-statements/etc on the other hand...

    #OneTrueBraceStyle
  • 9
    @Christine well it's fine but i prefer the 2nd style. i guess in the end it's just a matter of style taste :)
  • 17
    I agree with your teacher on this one tbh...
  • 6
    @linuxxx Seriously, so much easier to read through code. Now I will say if statements with a single line of indented code w/o braces are the shyt

    If(true)
    ++Vote;
  • 6
    ++teacher
  • 14
    Are you trying to start a war?

    Let's just go with "whatever the coding standards for your team says" and try not to take the discussion too far.
  • 6
    What's wrong with war?

    Everyone will emerge more close to nirvana and increase in knowledge.

    Best way to learn tbh.

    So bring your points sonny.

    ps: this is dev community, so don't let me tell you to be logical and not emotional hissy cat.

    BEGIN.
  • 4
    I tend to use the second for js and the first for C#/backend languages. I only backed down on js as a lot of the linters/formatters tend to go for the same line braces style. I do agree with your teacher though that the first is more readable as a code block and gives you good spacing and you can turn on indentation lines which visually links opening and closing brackets and makes it look even neater and easier to see what belongs to what.
  • 2
    Im always using the first option cuz thats what visual studio does by default (programming C#). I prefer the second though but whatever i guess
  • 4
    Don't trigger me. Your teacher is right, that's more common in C++
  • 0
    Sorry but i really hate people that say can you not.
  • 1
    I prefer the first style as it is easier to see the blocks when you're browsing through the code.

    Ultimately though I like how python does it.
  • 1
    @querellaMMXII that's exactly what my teacher said... well, i've never even tried to use that style because i don't work and haven't been restricted by team coding standards, i just code for myself and classes, where they don't care about the coding style.
  • 3
    I hate the first one so much. It's ugly.
  • 0
    Class a {//code} ;

    'uck you and your bloated code ;-)
  • 0
    One of several advantages of programming in F#, Haskell etc is that you get to say "Curly braces and semicolons are sooo 80's".
  • 1
    @brahn Honestly yeah. I too have strong opinions on how I prefer code to be formatted, but honestly, I stopped giving much of a shit once IDEs started taking care of formatting for me.
  • 0
    For some time I used the second one exclusively and find the first very ugly. But I had to change because the work standards, than I got used to that. Today i have no problem with either. 😀
  • 0
    @Christine lol no it's not though
  • 1
    @RYPTAR I hate those because you see them in huge files and people squeeze them on one line. I think adding the curly braces even just for one line is way more readable
  • 3
    The worst is when people put it all on one line curly braces and all

    function foo() { console.log('bar') }

    No it doesn't make you a better programmer to put things on one line that shouldn't be
  • 3
    It's a style that you should have the choice to choose I use brace per line but worked with a friend who had first brace on the first line, he tried to justify the choice and honestly I didn't care lol, I chose to use one way, like I choose to use m_variableName with globals, though that is more to do with a lecturer I thought was awesome uses the same concept.

    Just do what you want really as long as it's readable and not on one line should be fine.
  • 1
    I like the first one more because it's more readable. I still use the second but only in JS for events.
  • 1
    I prefer the first style, since with code folding I don't get hanging open curly braces every line
  • 0
    yes, a year later i came here to say that i'm writing the first style now and i like THAT now. sorry not sorry ¯\_(ツ)_/¯
  • 0
    Thanks true ;)
Add Comment