Vanguard Coder

Simple Life of a Keen Developer

Variables and Names


I’ve been working with C# for the past few months, and never encountered a “var”. Mark commented seeing var’s all over the code base he is working on here.

It probably happens that once in a while a person encounters ancient code base, or people still using old methods of coding. I remember a few years ago in VB class at university, they were saying that to improve readability, variables should be named as “String strReceipt” and “int intTotal” which was probably the most ridiculous thing I’ve ever heard.

Even worse was the (Q)Basic era where variables were variables were named a, b, c and when there were too many, I was told to keep some sort of documentation for future reference as to which variable is for what for purpose. No matter how primitive, this can never be beautiful as some things I found in my previous blog about Ugly Code turning beautiful.

Written by zkashan

August 15th, 2008 at 2:23 pm

Posted in Coding Practices

Tagged with ,

2 Responses to 'Variables and Names'

Subscribe to comments with RSS or TrackBack to 'Variables and Names'.

  1. var is actualy a new construct in C# it was released with .NET 3.5 and if your using resharper (and why wouldn’t you) you will find that on the most common suggestions it makes is turning the DataType variablename notation into var variablename.


    DateTime nextBirthDay = new DateTime(…)


    var nextBirthDay = new DateTime(…)

    for me the dury is still out for var but jetbrains certainly this we should be using it.

    Floyd Price

    15 Aug 08 at 5:46 pm

  2. Hungarian notation used to make sense before the days of high quality IDEs. It allowed you to quickly see the type of a variable without having to go all the way back to it’s instantiation. Nowadays though with the ability to Ctrl-Q in Resharper to find a variable’s type and auto completion it is rendered pointless.

    The var idea is a C#3.0 introduction along with lambda etc -> it does have its place in code, I just think it needs to be used with a bit more care.


    15 Aug 08 at 11:27 pm

Leave a Reply