Fun Infused Games  |   Smooth Operator  |   Evil Scale  |   Starcraft Live  |   Wellplayed.net RSS Feed Available RSS 

  Home   |    Archive   |    Subscribe   |    Search   |    About

Posts prior to 8/2/2010 may be missing data. If you need one of those posts, please contact kriswd40@yahoo.com and I will try and recover/find it.

11 Things that Annoy Me in .Net Programming
Date 12/22/2008    Tags Development, C#    (9)

Here are eleven things that annoy me that I have run into while doing .Net programming. Some are legitimate gripes that should be fixed poste haste and others are simply personal preferences that you very well may disagree with (you have the right to be wrong).
  1. If statements without the curly braces
    You don't need curly braces to write an if statement but for the love of God, use them! Leaving the braces out will cause the line following the if statement condition to be treated as if it were the code inside the curly braces (but only that one line of code). Using this technique makes code less readable and can also lead to subtle bugs as illustrated in the code below:
    if (myValue > 10)
        x = 5;
        y = 7;
    It's easy to look at this and expect that if myValue > 10, x will be set to 5 and y will be set to 7. And if not, nothing will happen. I reality though, only the "x = 5;" line is part of the if statement. "y = 7;" is a statement outside of the if and will always be ran. If you wrote this same statement out with the braces, it would read as below, which is much easier to understand and spot the error.
    if (myValue > 10)
    {
        x = 5;
    }
    
    y = 7;
  2. After Merge, Check-In is Canceled
    In Visual Studio 2005 and 2008 (using the default merge tool at least), after you run through the merge process, you get a message saying that nothing was checked in. You subsequently have to run the check-in process again, which often involves reselecting numerous files that you need to check in. I understand that you should test your merged code out if there are any non-trivial changes, but often times the changes that I merge in might be something as simple as another developer having changed a comment or updated the page formatting or just a one line fix they made. In these cases, I know for sure that the code will still work but I still have to walk through the check-in process from the beginning. It would be nice if there was some option to check-in after a merge or cancel the check-in to do some testing.

  3. ASP.net ID Mangling
    There often is a need to update control IDs so that you don't end up with two controls using the same ID (especially when dealing with dynamically created controls in something like a gridview). But when I simply have a button on my page for submitting with an ID of "btnSubmit", it would be nice to be able to refer to this button in clientside scripting as btnSubmit instead of ctl00$cphMainContent$btnSubmit (normally you get this name by doing something like <%=btnSubmit.ClientID %>, which is another step I'd like to avoid). ID Mangling does need to happen in some instances, but not in all thus there should be an easy way to turn this off, like setting a property "idMangling=false" on each control.

  4. Inserting a value into a string
    When you are creating a string with a variable value inside of it, there are a couple ways to do it. The first method is:

    nameString = String.Format("My name is {0}", Mud);
    For some reason, I just never liked when people do it this way. It's really just personal preference and cannot explain it anymore than I can explain why I find the color blue more appealing than the color green. I much more prefer doing this sort of string operation this way instead:

    nameString = "My name is " + Mud;
  5. Regions
    Some people really like these for organizing code. I'm not one of them. I like to be able to easily scroll through my code and hate the extra click involved to see the contents of each region. Rarely when I work on<

    Wellplayed.net
    This article has been view 38 times.

Advertisement:

Comments

Aranda

Avatar

12/22/2008 7:37:56 PM

With Expert's Exchange, I too thought that it had gone to payed members only... but next time you see it in the google list, check it and scroll way down the page - the actual comments and solutions are still there. I was happy to discover this as it's a really comprehensive site.

Also, for you #1 annoyance, we'll have to agree to disagree. I find it annoying to have to use 4 lines (and two have only one character!) for what should really be only 2 lines. If it's just a simple statement, I'll often just put both on a single line."0" style=
Kris

Avatar

12/23/2008 6:43:26 AM

Did they just start doing that w/ ExpertsExchange? I never noticed that before, but it certainly will make the page actually useful.

Just want to mention too that these items aren't in any specific order, they're just in the order I thought of them.?sid=1
Bart Czernicki

Avatar

12/23/2008 1:02:58 PM

Out of all of them...I agree with #1, but for my developers I made sure that they use curly brackets everywhere :) This same problem also occurs in t-sql BTW (if you don't use begin/end). So..its not just a .net problem.


nameString = String.Format("My name is {0}", Mud);

This one I completely don't agree with...this uses a StringBuilder behind the scenes and it very nicely allows you to build complex strings without having the penalty of immutability (object gets re-created each time rather than being changed). I actually prefer this syntax as the format gives me a quick "template" of what I am looking for.

Out of all of them i think #3 is the biggest one.
Kennard Consulting

Avatar

12/23/2008 8:23:29 PM

"I wish Google had a feature where I could enter the URL for ExpertsExchange and have it never ever appear in my search results again"

Can't SearchWiki (http://googleblog.blogspot.com/2008/11/searchwiki-make-search-your-own.html) do this?
h="
Kris

Avatar

12/30/2008 1:10:55 PM

I haven't worked extensively w/ SearchWiki, so maybe there is some way to perform that functionality, but it doesn't appear there is a sweaping, across the board way to remove one specific domain from my search results.

For instance, it appears that I could do a search for "C# for loops" and then knock down ExpertsExchange, but if I did a second search for "C# while loop" i would have to knock them down againone"></
Fratm

Avatar

1/9/2009 10:02:28 AM

About #1

Not using curly brackets is just lazy, why would anyone code like that? Have people forgotten how to write readable code?

-Fratm
?sid=1"
just_saying

Avatar

1/16/2009 3:07:36 PM

Disagree on #1

The statement after the "if" will be executed, if this statement fits in one line the brackets are redundant.

The example shown will not happen if the programmer indents his code correctly (actually even if he doesn't VS will do it be itself).
just_saying

Avatar

1/16/2009 3:12:34 PM

Meant "VS will do it by itself" above.i
Imdsm

Avatar

1/18/2009 4:31:03 AM

Disagree on #1 and at the people who also disagree.

Readable code depends who is reading it, a programmer or a non-programmer.

Programmers should be able to understand this without a problem:
if (x == y) doFunctionZ();

The only place I will use brackets for single statement code blocks is when the if statement spans multiple lines, such as:
if ((Game.Client.WindowBounds.Width > valueX) ||
(Game.Client.WindowBounds.Height > valueY))
{
DoSomething();
}

As for the string formatting, that's meant more for formatting a string than for concatenating two or more strings.

Example would be having pre-formatted text on a screen, and needing x number of trailing zeros or displaying a hex value.

Please read up some more on coding practises :)


Add Comments

Current disabled. Check back soon!
top
top


top
Tags
ASP.net (17)  Annoyances (4)  Video Games (6)  Sage-Like Advice (12)  Domain Name (1)  Internet (5)  NFL (2)  Writing (1)  Visual Studio (1)  Hypership (12)  Site News (2)  Xbox (1)  C# (15)  Sage-Like Advise (1)  Education (1)  Tech Support (1)  MSSQL (1)  Absurd (1)  Abduction Action! (27)  Nasty (36)  Economy (1)  Cool (2)  Sports (11)  .Net (1)  Web Tools (2)  Abduction! (1)  Rant (40)  XBLIG (20)  Tutorial (2)  Nastier (1)  Books (1)  Realty (1)  Programming (3)  Weird (1)  Vista (1)  Development (14)  Design (3)  XNA (35)  Links (1)  Security (2)  JavaScript (7)  CSS (1)  Video (2)  Web Development (1)  Computing (1)  Abudction Action! (1)  Popularity (1)  Game Design (4)  Google (1)  AJAX (4)  Game Development (8)  
top

top
top


Twitter

    Follow me on Twitter



    Buy My Games:
    Abduction Action!
    Nasty

    I'm with Coco.