Technorati Tags:
C#,
Standards,
Rants There are two major annoyances when it comes to good code and readable code. Here are 2 things that really every team should ensure happens (at least in my opinion
).
1) Any method should not be more than 50 lines but preferably < 25 if possible. I cannot stand huge methods. The point of OOP is to abstract logic out into manageable pieces. Methods are meant to mainly do one unit of work. Not 5 units to make up 1 unit. Put your logic in reusable methods so that they are not only reusable, but READABLE! I’d much rather see a bunch of case statements in a method but in between calls to other methods to make the entire thing readable.
2) Put the damn curly on the next line:
1: if(something){
2: //do something
3: }
that is the most irritating thing to read. Every time I see that curly on the right, it just irritates me and I move it back down for readability when I see this.
Why doesn’t the person just put it on the next line to make it much more readable:
1: if(something)
2: {
3: // do something
4: }
I mean are we that lazy? Do you REALLY think that the first one is actually more readable? If so I think you were born cross eyed and must see that way. You get an entire page of if statements throughout and nested, you start to see how that becomes very unreadable. If you are fine with it, more power to you but I think it looks like a pile.
I wish programmers would pay more attention to formatting, because it makes code so much more readable and saves so much time overall for anyone who has to read it.
I am kinda open ended on the one-statement after the if decision on whether to include a {}. You are not required in C# to include {} if there is only one statement after the next line in a single if statement without an else. If you are going to make the decision to include the {} then for readability, make sure the first is on a next line and keep it consistent like the last }.
Thank goodness I’m not coding in VB, I’d hang myself with the Subs, End Sub, and all the other extra verbose crap that I’d have to type.
This may seem like something not worth mentioning to some, but really, it makes a big difference and I just don’t get the lazy #2. You can’t debate #1 though and I wish though people would stop making 50+ line methods.
My rant for today.
Print | posted on Monday, December 08, 2008 8:53 PM