Terminally Incoherent

Utterly random, incoherent and disjointed rants and ramblings...

Sunday, September 04, 2005

Indenting Brackets

This is one of my pet peeves. If you have never programmed, or read code you will probably not understand this. Anyways, here it goes.

Why on god's green earth would anyone ever want to write code like this:


some_method() {

    // do stuff here

}


Now in this example the code is clean, but imagine 3 pages of nested statements indented like this. Especially if you fuck up the indenting at some point - which frequently happens when you copy and paste large chunks of code. Am I the only person who thinks that this type of indenting makes code more difficult to read? What is wrong with doing it like this?


some_method()
{

    // do stuff here

}


There. The brackets are aligned. I can visually see which blocks of code belong to each other even if your indentation is screwy. Tracing back to the beginning of method is now as easy as putting my finger on the screen and scrolling up till I hit an open bracket. Try doing that with the other style!

Every time someone gives me code which has the fucked up brackets, I tend to "correct it" as I read it, by hitting enter after every single open bracket I encounter. I know there are different styles and conventions but hell... I think placing open brackets on newline is a good coding practice which improves readability.

How does placing it on the same line improve anything? Seriously people. I'm very tolerant when it comes to coding practices, but come on!

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home