I’m interested in what goes through your mind, even before the declaration code is written. The moment you decided you need a variable, what do you think of? Let me give an example comparing C# and VB.NET code.
Note: This is not another language war incitement. This is an article on self-discovery and self-understanding.
Dim iNumberOfApples As Int32
Personally, the moment I decided I need a variable to keep track of the number of apples, I think “I need an integer”. Sometimes, before I’ve even thought through the whole thing, this appears in my code editor:
Then I decide on what name to give. When I play RPGs, one of the hardest parts was to give my hero a name. I’ve been known to falter for 10 whole minutes before giving that scrawny protagonist something to call himself. This quaint custom of mine carries over into my variable namings, though I’ve had much success in culling the time spent to seconds instead of minutes now.
VB.NET on the other hand makes me write this first
Then I have to think of a name.
By this time, I can’t even remember what I wanted to use the variable for… oh yeah, it’s an integer.
I haven’t had much contact with other languages (note to self: go read some). For example, I don’t know how Ruby looks like… oh wait, here it is. It’s one of those languages where you can use a variable immediately without declaring it, right?
So what do you think about at the moment you decide a variable is needed?