I can do garbage me
Every day I learn more and yet I sometimes get the feeling that the more I learn, the larger the projects, the more bugs slip in because of assumptions. Right now I'm on such a project. It simply doesn't get of the ground because of assumptions. Nothing more than assumptions!
You can read it in books - and not only the books about managing software projects, but the books about management in general -, in blogpost, articles, MOC material. Don't make assumptions! And still I - and a lot of people with me for that matter - get fooled by them over and over again.
This BI project I'm working on right now for example should have been finished in two weeks, but we made a few assumptions. So it's keeping me busy for almost two months. I'll list the assumptions here and leave it up to your fantasy what went wrong.
The assumptions
We / I assumed:
- that a certain set of records in our source would not change ever;
- that if a certain record changed, the update_date field would be updated;
- that our datawarehouse would not be used by others to store some userdata that has nothing to do with it at all:
- that the data would be used for production only when the data was verified and agreed upon by our customer.
What have I learned
- Don't trust anybody: check;
- Communicate;
- Don't give somebody administrator rights on your datawarehouse because he owns the system and paid for the datawarehouse;
- Don't assume anything:
- Don't assume anything ever.
We'll probably release this project tomorrow and it will go in my books as the project where I learned the most. Because when I look back at it, it's all my own fault...
Redmond...
Yesterday I was invited by Microsoft for a TTT(Train the Trainer) covering Sql Server 2008. It will be my first stay ever in the USA. I Hope to see some cool stuff and meet some interesting people at the Microsoft facility and to come back with tons of information to blog about.
For now I'm feeling just proud to be invited by Microsoft.
[note: This is a repost from my previous blogspace. My previous blogspace has been out of air for a while because of technical issues and a lot of developers were never able to read the articles.]
Extension Methods
If you don't know extension methods yet, please have a look at this blogpost of our Mr. Guthrie which tells you all about what they are.
As soon as VS2008 RTM was out I've started to play with some of the nice new features of Framework 3.5 and one feature I particularly like is Extension Methods. They give you the power to extend any class you like to your willing. One of the first classes I decided to extend is the StateBag class.
ViewState
As a web developer I just cannot count the times I wrote these sort of lines anymore:
public int MyIntProperty
{
get
{
object o = ViewState["MyIntProperty"];
return (o == null) ? 0 : (int)o;
}
set
{
ViewState["MyIntProperty"] = value;
}
}
public bool MyBoolProperty
{
get
{
object o = ViewState["MyBoolProperty"];
return (o == null) ? false : (bool)o;
}
set
{
ViewState["MyBoolProperty"] = value;
}
}
I've built dozens of custom controls and thus dozens multiplied by a lot wrote these default pattern lines.
Extension Methods to the rescue
Nowadays we can extend the StateBag. Just have a simple look at the following code:
public static class ControlUtility
{
public static T GetValue<T>(this StateBag viewState, string key, T defaultValue)
{
if (string.IsNullOrEmpty(key))
throw new ArgumentNullException("key");
T returnValue = defaultValue;
object viewStateValue = viewState[key];
if (viewStateValue != null)
returnValue = (T)Convert.ChangeType(viewStateValue, typeof(T));
return returnValue;
}
public static void SetValue(this StateBag viewState, string key, object value)
{
if (string.IsNullOrEmpty(key))
throw new ArgumentNullException("key");
if (value != null)
viewState[key] = value;
}
}
The best value of course is in the GetValue method. The SetValue method is purely there because I think it's good practice to create symetric code. Developers expect to have a SetValue method when there is a GetValue method.
How to use it
With these very few simple lines of code I can now change my properties to this:
public int MyIntProperty
{
get
{
return ViewState.GetValue<int>("MyIntProperty", 0);
}
set
{
ViewState.SetValue("MyIntProperty", value);
}
}
public bool MyBoolProperty
{
get
{
return ViewState.GetValue<bool>("MyBoolProperty", false);
}
set
{
ViewState.SetValue("MyBoolProperty", value);
}
}
Framework 2.0
The big fun part of this, is that we can actually use these extension methods in our Framework 2.0 projects as well! That's because extension methods are a compiler feature. So with VS2008 we can simply add a reference to our Framework 3.5 extension methods library in our Framework 2.0 projects and all of a sudden we have this great new feature in our Framework 2.0 projects at our fingertips!
And that's why I think generic extension methods are way to cool!