Geeks With Blogs

Michael Freidgeim's Blog MS .Net Development

We don't have code reviews, but sometimes I have to tell the team quite obvious coding recommendations.

There are a few examples:

1. We should do the check if array element is available before access it:

 E.g. BAD:
            string departureCity = Flight[0].StartPoint;

GOOD:      if (Flight.Rows.Count <= 0)
                WarningMessageEvent.Raise("Flight.Rows.Count <= 0");
            string departureCity = Flight[0].StartPoint;

2. Keep separate functionality in small functions, rather than add morre code to existing functions, that makes them too big.

It is easier to read, test, maintain and investigate errors.

You can use VS Refactor –Extract Method to make functions smaller.

Also highly recommend to install RefactorAsp from

See "Common Refactors" section here about

  • Extract method
  • Replace Method with Method Object
  • Decompose Conditional
  • List of Refactors can be viewed here(or original here).

    3. Do not "eat" exceptions

    Even if you don’t want to report errors in production, Debug.Assert them in development environment to understand, why they happen and avoid them.
    E.g. BAD:
                    //we ignore any errors
                catch(Exception exc)
                    //we ignore any errors in production 
                    Debug.Assert(false, "Investigate why " + exc.ToString());
    4. Use enums, do not hardcode magic values
    Use Enum (C#) instead of magic numbers 
    and (more general) C# Coding Style Guide .
    Aside note: By some reason this particular post is not searchable by Google. I have no idea why it is different from other posts.
    Posted on Thursday, January 22, 2009 8:58 PM .Net Framework , General Tips | Back to top

    Comments on this post: Code reviews and coding recommendations

    # re: Code reviews and coding recommendations
    Requesting Gravatar...
    It might be worth to log somewhere fir
    catch(Exception exc)
    Left by codemeit software developer on Feb 21, 2009 8:05 AM

    Your comment:
     (will show your gravatar)

    Copyright © Michael Freidgeim | Powered by: | Join free