Wednesday, September 30, 2009

Assignment Progress and Bloody Braces

Well, I've finally started seriously working on Assignment 1 for OOP344, and I have noticed a few things about myself. First off, I am a much sloppier coder when I am working with someone else's code, I go through and figure out what the code does, then I proceed to roughly patch each individual problem piece by piece, and I find that by the time I have completely fixed the problem, it looks ridiculous, for example, by the time I was done fixing one of the parts in Assignment 1, I realized I had three consecutive if statements that could have easily been packed into one. There are often other redundancies as well, but since I am satisfied that it finally works, I just write a comment in caps the clean up the code, which I hopefully won't miss when I finally submit it.
Which brings me to my next problem... Braces, more accurately, brace styles. The standard, or at least what I often see from other programmers looks like this:

Function(arg, arg){
code;
if(arg){
code;
code;
}
code;
}


I HATE this style, it makes it so damn easy to misplace a brace, put the a line of code in the wrong block, and in general is a pain in the ass to read. I much prefer this method:

Function(arg, arg)
{
code;
if(arg)
{
code;
code;
}
code;
}

This looks so much better, easier to read, if you misplace a brace, it will glare out at you, you can easily see what code belongs to what function or what code belongs to what conditional or loop statement. I realize it takes up an extra line every time, but I'd easily be willing to pay that for code that isn't so infuriating to look at.

1 comment:

  1. Well, style is always a matter of opinion and the way you are used to program.
    Many experienced programmers do it in different ways, and they are happy with their own way.
    I believe as long as you are not sloppy, follow your own style and stick to it, you are Ok!, But if you are programming in a team, then what you like is irrelevant and then, it is team's decision to which style and standards to use.

    So I am just letting you know that the "Bloody" braces that you happen to dislike has been my way of programming for many years and I am very happy with it :)

    ReplyDelete