The reason for using lowercase for the first word in a local variable (eg, employeeCount, firstName)

methodsnaming-standardsvariables

I take a good deal of criticism from other programmers due to my use of full proper casing for all my variables. For example, your typical programmer will use employeeCount for a variable name, but I use EmployeeCount. I use full proper casing for everything, be it a void method, return method, variable, property, or constant. I even follow this convention in Javascript. That last one really rustles people's jimmies.

The typical reason given as to why I shouldn't follow this "non-standard" casing convention is because full proper case should be reserved for properties and void methods. Local variable and methods that return a value should have the first word in lowercase like int employeeCount = getEmployeeCount().

However, I don't understand why.

When I question this, it seems that I just get an arbitrary answer of that's the standard. Whatever the answer is, it usually always boils down to That's just the way it is and I don't question it. I just follow it.. Arbitrary answers are never good enough for me.

Ever since my early days of programming Excel 97 macros with the Office IDE, I've never needed a casing convention to tell me whether or not something is a local variable or property. This is because I've always used a very intuitive naming convention. For example, GetNuggetCount() clearly suggests a method that goes somewhere an gets a count of all the nuggets. SetNuggetCount(x) suggests that you are assigning a new value to the count of nuggets. NuggetCount all by itself suggests a property or local variable that is simply holding a value. To that last one, one may be tempted to say, "Ah ha! That is the question. Property or variable? WHICH IS IT?" To that, I'd reply with, "Does it really matter?"

So here's the tl;dr;: What are the objective, logical, non-arbitrary reasons to use lowercase for the first word in your variable or return method?

Edit: For MainMa

Replace this code with the first code sample in your answer and see how well your argument holds up:

public void ComputeMetrics()
{
    const int MaxSnapshots = 20;

    var Snapshots = this.LiveMeasurements.IsEnabled ?
        this.GrabSnapshots(MaxSnapshots, this.cache) :
        this.LoadFromMemoryStorage();

    if (!Snapshots.Any())
    {
        this.Report(LogMessage.SnapshotsAreEmpty);
        return;
    }

    var MeasurementCount = Measurements.Count();
    this.Chart.Initialize((count + 1) * 2);

    foreach (var s in Snapshots)
    {
        this.Chart.AppendSnapshot(s);
    }
}

Best Answer

That naming convention is often used when people want to be able to give a variable the same name as its type. For example:

Employee employee;

Some languages even enforce that capitalization. This prevents having to use annoying variable names like MyEmployee, CurrentEmployee, EmployeeVar, etc. You can always tell if something is a type or a variable, just from the capitalization. That prevents confusion in situations like:

employee.function(); // instance method
Employee.function(); // static method

Also, in English, nouns are not generally capitalized, so you can't really claim your capitalization is "proper."

So what does that have to do with your situation? You obviously have no trouble reading your own code, but by keeping things as consistent as possible, you reduce the mental workload of anyone else needing to read your code. In coding as in writing, you adjust your style to match the readers.

Related Topic