What do you think of when declaring variables?

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.

In C#:

int iNumberOfApples;


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.

Dim iNumberOfApples

By this time, I can’t even remember what I wanted to use the variable for… oh yeah, it’s an integer.

In this respect, I prefer C# over VB.NET. Other than that, I write the two languages in similar ways. Yes, I am aware that Javascript variables are typeless when declared. My point is that I can write the code for saying “I want a variable” first.

// Javascript
var iNumberOfApples;

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?

  1. mem

    (Longtime RSS subscriber here.) I’m not a huge fan of either language, personally, but it does stop and make you think; this really is kind of a simple distinction, but not a trivial one.

  2. Vincent Tan

    “Longtime RSS subscriber here”
    This sentence means so much to me… You’re fantastic!

    I’m more of the C family, so without going into the details, even Java looks familiar. VB.NET required me to rewire some of my thought circuits…

    And thank you for sharing your thoughts.

Comments are closed.