Good coding conventions

Here are some good conventions that we use on my current project that makes the job for future developers easier and the code more reliable and readable:

Conditional statements:

  • Use == false instead of ! as negation in conditional statements.
    if( !String.IsNullOrEmpty( foo ) ) is harder to read than if( String.IsNullOrEmpty( foo ) == false )
  • Use { and } to open and close conditional statements
    if( foo == true ) doSomething(); is more errorprone than if( foo == true ){ doSomething(); }


  • If you can’t figure out what to name your method, you probably should refactor your method.
  • Methods should do ONE thing.
    Ex: Don’t have a method that reads and writes stuff to some other layer. Create one method for reading and an other for writing.
  • Methods should not extend one screen, i.e. create small methods makes the code more readable.

  1. #1 by The Lazy Dragon on September 29, 2009 - 23:45

    Couldn’t have written it better myself…

    • #2 by Johan Leino on September 30, 2009 - 08:57

      But you did…sorry for the missed out credit to you!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: