June 9th, 2010
The short answer is Now!
Not now as in ooh-shiny! but as in I-have-to-learn-this-anyday-anyway.
Take this example: Linq.
Linq is a sterling technology for writing code that is easy to read and have fewer bugs. It takes an hour or two to grasp but is payed back when the first bug is avoided. Here is the cherry on top: you will have to learn Linq one day. So why keeping on building your technical debt?
Is it smart? No.
June 9th, 2010
The short answer is Now!
Not now as in update-right-before-delivery but now-since-we-will-update-anyway-someday.
Take this example: You have a web site running on dotnet2. You know that dotnet has updated not one but two steps since then. You also know of goodies like Linq. If you google for dotnet2->4 problems you will not see many.
So what is keeping you?
Every day you don’t update you will build on your technical debt. Since you didn’t upgrade 2->3.5 two years ago 1)the debt is greater and 2)the update is bigger.
Smart move? No.
June 8th, 2010
It is, at least in MSSqlserver, possible to annotate fields. Please do.
There are people coming after you to maintain the code base. One day it might be you who come after someone. Start paying it forward.
The field explanation might be in the Documentation but the Documentation is too often faulty, not accessible and almost always not up to date. The database is closer and probably easer to keep in sync with reality.
Don’t think a field name is self explanatory. The field CustomerID in table Customer might be. But the same field in Region is not. Is it the region master or the primary customer or what? By the time the field was created the meaning of this field was clear but not a year afterwards.
The reason I write this is that I presently work in a project where the habile predecessor has written down the meaning of the fields and saved me lots of time and lots more of confidence of what the figures mean and tons of debugging time.
June 2nd, 2010
Update: I wrote a longer article here.
List<T> is the work horse of list handling in dotnet. But there are several more to choose from; ArrayList, Hashtable, SortedList, DictionaryEntry, ListDictionary, StringCollection, NameValueCollection, StringDictionary, HybridDictionary andOrderedDictionary for instance. Several of these are replaceable by generic lists so don’t memorise them.
Here is a link to a better explanation: http://www.platinumbay.com/blogs/dotneticated/archive/2007/06/08/hashtables-and-stacks-and-linkedlists-oh-my.aspx
*Update*: I wrote some more, and later, info here.
June 2nd, 2010
When working with generics in dotnet (like templates in C++) there is something called “constraint” that limits the type of generic you can use.
Say you have a method
AreEqual bool<T>(T x, T y)
{
return x == y;
}
It will stop in the compiler since T isn’t necessarily comparable. So we have to make sure T is.
AreEqual bool<T>(T x, T y) where T:IComparable
{
return x == y;
}
This example requries T to implement IComparable; i.e. int and string but not necessarily Customer.
Other constraints are “struct” constraining T to value types like int and enums, “class” for contraining to classes or “new()” for requiring a default constructor (constructor without parameter). One can also constrain to inherit from a class and even send this class as a parameter like T.
The constraints are limited and I have often stepped into limitations I cannot recall right now.
More info here: http://msdn.microsoft.com/en-us/library/d5x73970%28VS.90%29.aspx.
May 5th, 2010
If you want to take down an aspnet2 site but still give the user a web page with some other info than 404; just drop a file named App_Offline.html with contents of choice in the direcotry and IIS will gracefully take down the sessions and instead show your message. Remove the file and you are up again.
Honor those who should.
April 24th, 2010
If you get the error above in your web browser it might be due to Visual studio 2010 not updating the web.config file.
—-
Creating an Entity framework 2 multi tier (n-tier/ntier) aspnet mvc 2 solution in Visual studio 2010 wasn’t the next-next-next or just-follow-an-example I first thought.
The first try rendered a “The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.” message in the browser. There were mainly two answers through google:
1) create a Mydatalayer.dll.config and insert the connection string there
2) update the web.config and insert the connection string there
I tried them both to no avail. I knew my connection string was correct because I could use it through a test dll.
Finally I found out that the web.config file in the web project does not get copied to the output. It fooled me since I saw that there were 3 web config files (ordinary+debug+release) in the site.
Now I don’t dare to set the web.config in VS2010 to Copy-if-newer since the web.config already in the site has almost 80 rows already and I don’t want to overwrite it.
Updating the web.config in the site will save me for now. I will figure out how to do it the right way later.
April 16th, 2010
If you for instance create a multi layered application and get the compilation error
The type ‘System.Data.Objects.DataClasses.EntityObject’ is defined in an assembly that is not referenced. You must add a reference to assembly ‘System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’.
when you compile the business layer just add a reference to System.Data.Entity.
April 12th, 2010
If you get
—————————
Microsoft Visual Studio 2010 Ultimate Setup
—————————
Some components must be installed in c:\Program Files\Microsoft Visual Studio 10.0\ directory. Check that you have write permissions and enough space in that directory.
—————————
OK
—————————
when you try to install Visual studio 2010; don’t despair.
There is a big chance you try to install from a mounted virtual disc.
The solution is to copy the files in the mounted disk to real files and run it from there. One could possibly also assign the mounted disk a letter but I haven’t tried this.
I have learned that there is also some problem when installing from a network share. The symptom is something about a .cab file with a faulty digital signature.
March 16th, 2010
I am a long time fan of DPack. Some time ago Coderush stepped up to a must-have.
The other day I noticed that Coderush did camel case selection. It is like this:
Open the Vsnet editor with your favourite project and go to a camelCased or PascalCased word. Select it with ctrl-shift-right/left. This is old news.
Now instead use alt-shift-right/left; only a part of the word is highlighted. Perfect when copy-pasting variables like CustomerName and SerialNumber.
Coderush comes both in gratis and payed versions.