Why is the 'var' keyword bad? Or am I just old school?
Posted
by WaggingSiberian
on Stack Overflow
See other posts from Stack Overflow
or by WaggingSiberian
Published on 2010-05-19T13:44:11Z
Indexed on
2010/05/19
13:50 UTC
Read the original article
Hit count: 169
Recently I overheard junior developer ask "why do you use 'var' so much?". The mid-level developer responded "I use VAR all the time. I love it! I don't have to figure out the type." I didn't have the time or energy to get into a religious war and hey, I'm still the new guy here :-)
I understand var has its place. LINQ comes to mind. But I have also always been told the use of var represents lazy programming and I should just use the correct type to begin with. If it's an int, define it as an int, not a var. When reviewing code, seeing the type makes it easier to follow. My opinion is, it's just lazy but there are exception.
Var also reminds me of the VB/VBA variant type. It also had its place. I recall (from many years ago) its usage being less-than-desirable type and it was rather resource hungry.
Am I just being stuck in my ways? Should we start using var all the time as my co-worker does?
© Stack Overflow or respective owner