Moved Notice
Wednesday, July 26, 2006
Wednesday, July 12, 2006
VB.NET and Block-Scoped Variables
When I was first introduced to .NET, I learned C#. I came from a C++ and Java background, and so C# seemed like the most natural language for me to choose for development. My entire development team worked in C#, and everything was beautiful.
Then, my company won a contract to perform a major system rewrite and integration project, and the developers that we are working with here came from VB. So naturally, we chose to use VB.NET for this integration. I've been coding in VB.NET for about two years now, and I've actually come to like it somewhat. Optional parameters are nice (if you just use VB), instead of needing to create a bunch of single-line overloads. But, I've been smacked back into reality. Check out the following two code snippets, one in C# and one in VB.
[C#]
for (int i = 1; i < 10; i++)
{
object o;
// Any variable condition will work here.
if (i % 2 == 0)
o = new object();
if (o == null)
o = "
MessageBox.Show(String.Format("Loop execution {0}: o is {1}", i, o.ToString()));
}
[VB.NET]
For i As Integer = 1 To 10
Dim o As Object
' Any variable condition will work here.
If (i Mod 2 = 0) Then
o = New Object
End If
If o Is Nothing Then
o = "
End If
MessageBox.Show(String.Format("Loop execution {0}: o is {1}", i, o.ToString()))
Next i
The C# version of this code doesn't even compile. It complains, "Use of unassigned local variable 'o'", which is correct. The VB version, on the other hand, not only compiles, but IT NEVER SETS o TO NULL!!! That's just pure evil if you ask me. After doing some reading, I found that VB.NET doesn't support block-scoped variables. When you declare a local variable just inside a block, it's exactly the same as declaring it just outside a block. Developers *of* VB.NET should at least warn you that your variable is scoped at the procedure level, not at the block level. Developers *using* VB.NET should always, always, always initialize their variables to null values, to avoid errors that can rise from this wickedness.
Posted by
John B.
at
10:47 AM
3
comments
Links to this post
Labels: .NET
Friday, July 07, 2006
Cross-Browser Implementation of DOM Range & Selection
I'm very glad to find somebody writing quality code to ease the pain of creating cross-browser JavaScript. I've been working on an application that has DOM selections and ranges at its center, and was very pleased to find Jorgen Horstink's implementation of the DOM Range and Selection objects for IE and other non-standards compliant browsers. Per Jorgen's own comments, the implementation of selection is still a work in progress, but I am eager to see it once he completes it. If necessary, I may spend a bit of my own time working to move this piece of code along.
You can view Jorgen's original post here, and as far as I can tell from his blog, you are free to use the code in any way you see fit.
Posted by
John B.
at
9:29 AM
0
comments
Links to this post
Labels: HTML


I just got an email from Kevin Downs, chief of the NDoc .NET code documentation project, saying that he is no longer supporting development of the 2.0 version of the software. His primary reasons for quitting are (1) a lack of community support (read: $$$) for the project, and (2) a mail-bomb attack directed at him personally, apparently related to the fact that he's not working as fast as someone would like him to.
I love NDoc, I consider it to be the standard for documenting Microsoft .NET class libraries, and I'm sad to see it go. I really hope that someone is willing to pick up the project, since it really is (at least so far) the best thing out there to cleanly document custom assemblies. But I cannot fault Kevin for his choice, since I have a family to feed and relate with as well, and I can't spend all of my spare time working on massive software projects for free.
Here's the text of the email that Kevin distributed to his alpha tester group: