Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

For me, it's the other way around.. the second instance is easier to spot because the visual cue of associating the block with the statement is more obvious if you assume beforehand that each statement has to end with the brace.

As for closing braces, I associate them with the start of the statement itself (the if and for) and not the opening brace, assuming the indentation is consistent.

I'm not arguing one is necessarily more right than the other - just that I prefer the way considered less right by consensus.



I get the impression that the { on the end of the line is the one that most people prefer, so I think you're more with consensus than me.

The argument about taking up less space, I get - although given the massive monitors that we all have these days, that seems far less of a consideration than when I used to work on 20-line terminals.

What I just genuinely struggle to understand is how it's clearer (and if I managed to understand, it might help me parse other peoples' code).

Let me turn my code into something that actually has a matching amount of braces

    while (readLine){
        if (isOK)
            loadSomething();
            for(thing in list){
                doSomething(thing);
        }
    }

versus

    while(readLine)
    {
        if (isOK)
            loadSomething();
            for(thing in list)
            {
                doSomething(thing);
        }
    }
If I was quickly parsing the first code, I'd assume everything was fine and that the first } was closing the if(ok). To spot the defect, I have to scroll up, find the matching control statement and check to the end of its line to see whether it had a {.

With second one, even the most rudamentary scan tells me that there's an opening and a closing brace that don't match up. All I have to do is scroll up and see whether there's a matching { at the same indentation.

I'm not saying you're wrong - if you are, most people who write coding articles, or code that I have to look at, are also wrong. But I would love to know what it is that other people can see easier/quicker in the first code than they can in the second in.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: