To 'var' or not to 'var'?

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

33 Replies - 9464 Views - Last Post: 14 November 2012 - 06:46 PM

#31 marty617  Icon User is offline

  • New D.I.C Head

Reputation: 7
  • View blog
  • Posts: 33
  • Joined: 14-October 12

Re: To 'var' or not to 'var'?

Posted 27 October 2012 - 07:38 AM

My OCD opinion is to always be as explicit as possible while understanding that sometimes you cannot be. HOWEVER, keep in mind that using var because you "have to" might be 'code smell' because you do not follow the advice in the first sentence elsewhere.
Was This Post Helpful? 0
  • +
  • -

#32 Curtis Rutland  Icon User is online

  • (╯°□°)╯︵ (~ .o.)~
  • member icon


Reputation: 3798
  • View blog
  • Posts: 6,405
  • Joined: 08-June 10

Re: To 'var' or not to 'var'?

Posted 29 October 2012 - 06:41 AM

Again, I don't think this fetish for the explicit is necessary. If we all were working with older tools, maybe. But with all the capability VS gives us to inspect static code, I believe we should spend our time writing efficient, clean, easily-refactorable, and non-redundant code. Var is a good option in that direction.
Was This Post Helpful? 1
  • +
  • -

#33 lordofduct  Icon User is online

  • I'm a cheeseburger
  • member icon


Reputation: 2059
  • View blog
  • Posts: 4,054
  • Joined: 24-September 10

Re: To 'var' or not to 'var'?

Posted 05 November 2012 - 01:50 PM

var when it doesn't break readability.

That's how I work.

I can see Curtis's expectation of an IDE, but I personally consider readability to be readable with out the IDE.

But see, that's just preference... and really, are we going to pull out the swords over that?
Was This Post Helpful? 0
  • +
  • -

#34 pokiaka  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 8
  • View blog
  • Posts: 76
  • Joined: 05-August 11

Re: To 'var' or not to 'var'?

Posted 14 November 2012 - 06:46 PM

I'm not sure if this is ideal, but I'm using var a lot in-order to write less (and so I'm much more productive.. it has nothing to do with me being lazy.. uhh.. nope.. not at all), and also (and that's justified!) to repeat as less as possible. It's easier to change when you've got to change only once at the declaration, not to mention it's much more readable.

I won't use it in cases where I'm not explicitly allocating a new:

var i = 23m;

(Notice that the variable i is actually a decimal.

I also won't use it in cases where I never explicitly write the type I want. Random is a wonderful example:

Random r = new Random();
var x = r.Next();

This post has been edited by pokiaka: 14 November 2012 - 06:48 PM

Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3