« August 2006 | Main | October 2006 »

September 12, 2006

Wow, Check it out!

My blog has moved. Please go to: http://jstawski.com/archive/2006/09/12/Wow_2C00_-Check-it-out_2100_.aspx

Do you remember my previous post: Is Programming Going Away? Well today I was directed to a post that totally shocked me, but saw it coming. Pete Wright, a programmer/author that has been writing books/code since VB 3 has totaly dropped Microsoft technologies. Anyway, read his post here.

I do not agree with him 100%, but I will say I do agree 90%. The other 10%? I think he is blaming Microsoft for everything, when i think part of the blame has to be on the industry in general.

Happy programming!!

03:43 PM | Permalink | Comments (0)

September 08, 2006

Nullable Types ?!?!?!?!?!??!?!?!

My blog has moved. Please go to: http://jstawski.com/archive/2006/09/08/Nullable-Types-_3F0021003F0021003F0021003F0021003F0021003F003F0021003F0021003F002100_.aspx

Today I learned something new. Today I learned this new feature of .net 2.0 and that feature is Nullable Types. What are they? Basically they are a typed object of a primitive/value type that can hold a value or null/nothing.

What's the difference between those types and the primitive ones? The only difference from a usefullness perspective is that you can have primitive values with null rather than a predefined value. Do I think they are usefull? nope, I don't. Do I think they are going to continue on till death do us apart? No, I don't.

What's the difference of setting an integer to a predifined "null" value like -1 rather than null? None, whatsover. The only time I see when it will be usefull is if the integer type can be any of the values from integer.min to integer.max. In that case there is no real value to set as a predefined "null". Is that scenario possible? Yes, it is. Is that scenario a normal ocurrence? Not in my experience.

This thing gets more interesting. What is a boolean? A boolean is a primitive type that can only hold 2 values: True or False. So what is a Nullable Boolean? In simple terms: an oxymoron. If by definition a boolean can have 2 values: true or false, so how can a boolean be null? It can't, because if it is null then it's not a boolean. So what is the conclusion to this? Microsoft used the wrong term for the booleans. Did you ever wonder why SQL Server (just to mention one DB) doesn't have a boolean type? What, MSSQL doesn't have a boolean type?!?!?!?!??!!?!? Nope, it doesn't. It has types that can represent a boolean, but they are not booleans. What are those types? Well any type that can hold at least 2 values: int, bit, varchar(1), char(1), etc, etc. The one that resembles more to the boolean is the bit with 2 possible values: 0, 1; but as any other field in the db, it can contain nulls and therefore it makes it 3 possible values.

Will I ever use this nullable types? probably not, but the nullable int might come in handy.

Too much talk, too little code, so here's how to use nullable types in C# and VB.net:

int? x = null;
bool? flag = null; //Oxymoron :)
//Or
System.Nullable<int> x = null;
System.Nullable<bool> flag = null;

Dim X as Nullable(Of Integer)
Dim flag as Nullable(Of Boolean)

As always, happy programming!!

07:06 PM | Permalink | Comments (5)