This post originated from an RSS feed registered with Agile Buzz
by James Robertson.
Original Post: Uninitialized versus auto-initialized variables
Feed Title: David Buck - Blog
Feed URL: http://www.cincomsmalltalk.com/rssBlog/buck-rss.xml
Feed Description: Smalltalk can do that
My blog article Bug rates in a Smalltalk project prompted a discussion on uninitialized variables. I thought I'd bring the discussion into its own thread here.
I said I doubted that compilers can detect uninitialized variables except in trivial cases. Isaac Gouy showed an example from Nice and asked if my doubts were answered.
Actually, they aren't. In the Nice example, it handled the problem by forcing you to initialize the variables. C# auto-initializes the variables. What I was looking for was the ability to leave the variables with a nil value. This way, I can detect the error that they were not assigned a proper value at the time I need to use them.
This is not a limitation of static typing at all. It's a limitation of primitive types which is quite different. Statically typed languages can have variables that can contain nil or a boxed type. They typically can't have a variable that can contain nil or a primitive type.