I was looking at Lisa’s latest blog entries, and the second last screen shot made me sit back and say “what”:
In that example of Lisa’s, the local variable surfaceArea is actually the one that VB creates for you by default, allowing you to assign to the function name. If you don’t explicitly return a value the value of that auto generated local variable is returned for you. But should it be in intellisense following a Return statement ? Like in this example, you could see Lisa could easily select the first variable shown. The code would compile without warning, but it would return 0. And due to the similarity in the local variable she used and the function name, it’s one of those bugs you can stare at all day and just not see.
Personally, I would like tot see that auto-generated variable become a project wide option to raise either a warning or an exception. I don’t see the need for it other than those who want some sort of backward compatibility. Secondly, and more importantly, this should raise a warning about using a variable before it is assigned to. Sure it’s a value type note a reference type, but if a value isn’t assigned, then what is it returning.