Am I immoral for using a variable name that differs from its type only by case?
For instance, take this piece of code:
var person = new Person();
or for you Pythonistas:
person = Person()
I'm told constantly how bad this is, but have yet to see an example of the immorality of these two lines of code. To me, person is a Person and trying to give it another name is a waste of time. I suppose in the days before syntax highlighting, this would have been a big deal. But these days, it's pretty easy to tell a type name apart from a variable name. Heck, it's even easy to see the difference here on SO.
Or is there something I'm missing? If so, it would be helpful if you could provide an example of code that causes problems.
What is the reasoning of those telling you this is bad? I do this all the time. It is the simplest, expressive way to name a single variable of a type. If you needed two Person
objects then you could prefix person
with meaningful adjectives like
fastPerson
slowPerson
otherwise just
person
is fine with me.
I use this pattern a lot in method signatures. If I'm unable to provide an alternate descriptive name then IMHO, there is nothing wrong with this.
What is wrong would be if you have two types Person and person then that is very very wrong.
I use it all the time for temporary object references. I would avoid it like the plague for primitive data types.
Person person = new Person(); // okay
int Int = 42; // pure evil