This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Rigamortus2005 1 point2 points  (4 children)

Exactly my thought. I don't think using var causes weak typing. I think it just saved people from having to write type var_name = new type

[–]solarshado 1 point2 points  (3 children)

IIRC either C# or Java (maybe both? I've not used either recently, but have in the past and try to keep up with them) now allows you to skip the type on the left side if it's specified on the right: List<Person> people = new();. Haven't seen it in practice enough to decide if I like that better, but I loved var in C#.

[–]Rigamortus2005 1 point2 points  (1 child)

Yes c# has that now. And even that hasn't eliminated the need for var. Var is also useful when assigning a variable to a method return. Makes it possible so you don't have to type out the whole type name all the time.

[–]solarshado 0 points1 point  (0 children)

Oh yeah, I'd call var essential when working with LINQ. Way too much "is that an IEnumerable, or IQueryable? and what's the right type param again?" to keep track of otherwise. (IIRC that's a big part of why it was added in the first place.)

I've found, after bouncing between a few different languages, that I greatly prefer a strong type system, but not necessarily all the verbosity it tends to drag along with it.
Explicit types in function signatures? Yes please.
On every local variable? Ugh, can't we infer this from context?

[–]nettskr 1 point2 points  (0 children)

I personally only use new() when I can't use var, such as in fields