> This is what made me ask:
>
[quoted text clipped - 6 lines]
> var mockViewEngine = new MockViewEngine();
> var controller = new MainController(repository, mockViewEngine);
All of those seem reasonable to me. It's immediately clear what the
type is, because it's on the right hand side - and because the variable
names are clear. (The variable names don't have to explicitly specify
the type, of course, so long as they're clear in intent.)
> Unlike using "var" in LINQ queries I see no benefit here. In fact I see it
> resembling my old BASIC days back in the 1980's
[quoted text clipped - 4 lines]
>
> var c = a + b;
I might use var for b, but not a or c.
a) Integer literals get trickier, because the type changes depending on
the size of the number.
b) String literals are obviously strings. No ambiguity there. A better
variable name would probably be more help than an explicitly typed
variable here.
c) In this case it's not immediately obvious what the type *or the
behaviour of the expression* is. Again, I'd say this is more due to the
names of the variables than anything else.
> The answer is "12", not 3 or 12. I'll stick with strongly typed variables
> unless using LINQ I think :-)
You're still using strongly typed variables with var. You're just not
using *explicitly* typed variables. There's a massive difference. I
suspect you may know this, but others may not - I think it's important
to spread the word that "var != Variant" :)

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Peter Morris - 10 Mar 2008 14:01 GMT
> You're still using strongly typed variables with var. You're just not
> using *explicitly* typed variables. There's a massive difference. I
> suspect you may know this, but others may not - I think it's important
> to spread the word that "var != Variant" :)
I know, but I just don't see a *benefit* to using "var" here except that it
is quicker to type, and seeing as I haven't used less than two fingers to
type since I was about 15 it doesn't really benefit me. How I hated typing
lessons at the time!
Pete
Jon Skeet [C# MVP] - 10 Mar 2008 14:11 GMT
> > You're still using strongly typed variables with var. You're just not
> > using *explicitly* typed variables. There's a massive difference. I
[quoted text clipped - 5 lines]
> type since I was about 15 it doesn't really benefit me. How I hated typing
> lessons at the time!
Typing isn't the issue. Information redundancy is the issue.
Does having the type name twice actually make the code clearer? I
wouldn't say it does. The same information is available mere
centimetres away, so including it again is redundant. Where's the
benefit?
Redundancy is the enemy of information density (to steal Eric's
phrase). You want to get as much information across to the reader with
the least about of fluff - which is one argument in favour of
object/collection initializers too, on a somewhat separate note.
Getting the same amount of information just as clearly across without
repeating yourself is a good thing.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk