The Lounge is rated PG. If you're about to post something you wouldn't want your
kid sister to read then don't post it. No flame wars, no abusive conduct, no programming
questions and please don't post ads.
So I'm not here to start a holy wvar, but this must be the worst use of var I've ever come across.
var dossier = GetDossier(id);
Three guesses what type dossier has?
Trick question, three guesses isn't enough.
It's actually dynamic and going into GetDossier tells me it can be four different types (or null)!
There's actually a switch with some magic number that returns a different model on 1, 2, 3 and 4...
Come to think of it, not only the var is very misleading, it's a bad case of dynamic as well
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
I have a strong dislike for var. Makes me guessing the data type while reviewing someone's code. It's a true irritant. May be I'm very old school, but this is how I feel. I cannot look at a variable name without it's data type explicitly specified.
Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy Falcon.
dynamic is part of the Dynamic Language Runtime, which allows interoperability with loosely typed languages such as Ruby (or so I'm told).
It also comes in handy when using late binding with COM objects.
And I've used it once or twice with some Type<T> where T isn't really important, but can't be deduced, for example List<T>.Count.