79

A teacher who came to see if I'm programming correctly asked me to start my curly braces on a new line like
F()
{
}

because where the fuck did you learn the other version

F() {

}

" that's just wrong"

Comments
  • 18
    Yeah, not having lines that only contain 1 char is wrong.
  • 23
    Curly braces on a new line? Blasphemy!
  • 25
    @runfrodorun real devs only read minified code!
  • 16
    @scroach actually, real devs don't care. As long as it runs with minimal errors. That's why there's so much spaghetti code out there.
  • 18
    Surely it depends on the language you're using? If I'm doing c# they go one a new line, if I'm doing JavaScript they don't.
  • 9
    Personally I like to have my curly braces on new lines, but that's just my preference.

    A teacher should not push their preferences into their students.
  • 1
    I guess, buuutt I can't be bothered to change it ;-)

    Nice catch btw.
  • 8
    @runfrodorun

    Oh yeah? Real programmers use butterflies! https://www.xkcd.com/378/
  • 7
    This is where religions start guys. For the love of none existence of God let it go...
  • 4
    Braces are for weak.

    Hiss intensifies 🐍
  • 1
    I use both, depends on the situation. But I don't get the people (mostly teachers) who are trying to force something into their students i.e. code formatting.
    That proves that those teachers are just a bunch of incompetent idiots unable and unwilling to learn a single thing.
  • 3
    Let's break convention and used a mixed-form.
    Whenever we need braces, we shall randomly choose where to put the opening brace.
  • 2
    There is an xSR for each language (first letter of the language being the x). When I read PHP code that is not PSR compliant it's often not very easy to understand nor fast to read. There is also a JSR (Java) etc and surprisingly many developers haven't come across these. At the risk of sounding like an old pessimist, the good old "braces is a personal taste" is just not a thing anymore.
  • 3
    @shdw PSR2 states "Code MUST use 4 spaces for indenting, not tabs" - no sir, i will not accept that!
  • 0
    @Lahsen2016 guess I've been to focused on reading/writing and forgot about it :-)
  • 0
    @scroach that is because the tab renderings looks different across several systems (and the PSR goal is to make everything a standard). You can set your tab to be made out of four spaces in your IDE/text editor.
  • 1
    @shdw so how does it look different and on what system? every ide since like decades supports a preference where you can set "how many spaces wide" a tab should be displayed. and i just always found it annoying to navigate through code with spaces cause e.g. you got to hit the arrow key 4 times instead of once
  • 2
    @scroach there has been quite a lot debate on this matter. The fact that you are able to adjust your tab width in each IDE/system is the exact reason for using standard spaces instead. Some people argue that they prefer to be in charge of their own layout which is fully understandable. The PSR reflects the majority of developers opinion on matters like tabs, braces etc and the agreement of the majority is to use four spaces (hence the standard: what most people prefer). When I navigate a code base I rarely use the arrow keys alone when jumping between blocks or sentences. I usually use ctrl+arrow or ctrl+e/a. Don't know if that is any better for you to handle the "four-spaces-annoyance"?
  • 1
    I bet they also use spaces instead of tabs...
  • 4
    I think every language has its own style for braces. You should follow this convention and not trying to apply a style to other languages. For example Java has braces on the same line while C# not.
  • 2
    @runfrodorun I must respectfully disagree. I find readability much higher when the curly brace is on the same line. Otherwise they look like two separate bits of code.
  • 3
    I did this once in my practicals

    function name(){
    ...
    }

    During verification she asked me to change it and commented that I was trying to save space. Was so annoying as fuck. She even decreased my score because of it.
  • 0
    I might get shit for this but i always use

    Foo () {
    }

    Unless i have a long function or a function with nested loops etc

    Foo ()
    {
    For () {

    .}
    }

    Because with nesting sometimes finding which brace corresponds to which block is a bit obfuscated
  • 4
    Rule #1 - Consistency is King...
    Be consistent throughout your project no matter which coding style/indentation style you choose to use.

    Rule #2 - When in Rome...
    When you join someone else's project, adopt their style for any work done for said project.

    Rule #4 - Deception...
    There is no rule #3

    That said, I prefer Allman style indentation, though with different use of spaces:

    void DoSomething( int x, int y )
    {
    if( x > y )
    {
    Console.WriteLine( "X wins!" );
    }
    }
  • 1
    @wizzzard I actually like that look a lot. Very uncluttered looking imo
  • 0
    If you think it's OK to put { on a new line, try this JS code:

    return {
    foo: "bar"
    };

    And this code:

    return
    {
    foo: "bar"
    };

    Once you catch that bad habit, you'll lose hours trying to figure out why a function is returning undefined.

    Again, I'm not saying anything about the function, I'm saying that writing it that way (with } on a new line) creates a habit.
  • 1
    Yeah, it hardly counts in a formatting discussion. 😁
  • 0
    love how people come up with the "having one character in a line is bad" ... it's not like you're paying 100$ for that char... and you can minify your code if it's not compiled after you're done
Add Comment