F5 Should Be The Easy Button

Recently I've come to the conclusion that any project you download or pull down from source control or get through email, whatever, should work the first time out when you load the project in Visual Studio or it had better fail in a blaze of glory and indicate exactly why it cannot run.  I'm not Above the Law on this one, I write projects all the time that probably won't run without modification when someone else on a different machine tries to run the same project.  But I'm trying to establish better habits for my personal projects, hence this post. 

Phil Haack has a good post on reading code, Write Readable Code By Making Its Intentions Clear.  Why does code have to be so difficult to read and maintain?  My favorite projects are the ones that are well documented and names of classes, methods, and properties clearly explain what they do and why they are there in the first place.  It sounds simple, but it's surprising how often I run into code that is soooo difficult to understand.  Ever see 3,000 line methods? I see them all the time, and they suck to debug, basically they are dependent on the developer stepping through the debugger to figure out what the method is doing.

Building dependencies on appSettings into class libraries is annoying me more and more.  Especially when use of the appSetting is inside of a try catch block that squishes the exception if the setting does not exist in the config file, then you have no clue why the class is broken.  That scenario looks like this:

try{
  int blah = Convert.ToInt32(
    ConfigurationSettings.AppSetting["blah"]);
}catch{
  //Exception? What exception?
  //No exception here...
}

Other "techniques" that are annoying and make debugging difficult are the codebehind files in asp.net pages.  Lot's of private methods with dependencies on ViewState and/or Session variables or other class level variables.  This makes it almost impossible to test without running the whole web application so you can get Session state or whatever dependency you need from the runtime.  I'm not against using any of those things, I'd just rather not see thousands of lines of code abuse in a sincle codebehind file that has one class in it that does everything.   

 
Author: , 0000-00-00