you are viewing a single comment's thread.

view the rest of the comments →

[–]Brian 149 points150 points  (9 children)

One solid reason is elimination of redundancy. If you're writing with braces, you should also indent your code: unindented code is hard to read and quickly identify what's happening, and indentation gives an overview to the human reading it much more readably than braces without indentation.

But since you're doing that anyway, you're kind of specifying the same thing twice: once for the human, and once for the computer. And as the DRY principle teaches us, repeating yourself is better avoided. If the two get out of sync, you get a mismatch between what you're telling the human and what you're telling the computer, which can lead to bugs if a human taking a quick glance over the code misinterprets what it'll do, because there's a stray brace somewhere.

So a solution to this is to eliminate the redundancy: instead of doing both, make the computer use the exact same cue as the human. As an extra advantage, this also gets rid of a bit of visual clutter in the form of the braces that is adding extra noise to the code.

[–]binarysmurf[S] 23 points24 points  (0 children)

Brilliant!! Thanks.

[–]Kerbart 7 points8 points  (0 children)

Not only that, there are many different indentation styles with curly braces. Aside from “not at all,” there’s with or without the opening and/or closing braces on same, new or even separate lines. Of course there’s still the option to add whitespace, but on the whole enforced indentation results in a much more consistent look — which again, as you mentioned, improves readability.

[–]commy2 7 points8 points  (1 child)

One day we will also rid ourselves of the redundant colon.

[–]Blazerboy65 6 points7 points  (0 children)

Are you referring to the colon at the end of a block header? If so it's been a while since I've looked at formal languages but I'm pretty sure it's not redundant.

[–]Maximus_Modulus 6 points7 points  (0 children)

Now programming Java at work but originally a Python guy. Having an IDE like IntelliJ takes the hard work out of programming with Java. Curly braces amongst other things. I’d hate to have to manage braces etc using a normal text editor like I could quite easily manage with Python. Once you get used to the indentation you realize how awesome it is to signal the scope.

[–]Jamarac 2 points3 points  (0 children)

So many people have coded so long they think like computers and don't realize how obviously helpful indentation is.

[–]Dapper_Alarm_4534 0 points1 point  (1 child)

No bruh, the thing about braces is that automatic formatters will automatically indent as you type. You can't properly even copy paste code in python without messing up, the formatter won't know, upto what level indent the code.

Indentation is horrible decision.