Re: use of var

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Mon, 02 Mar 2009 11:22:05 -0800, Ajay <ajaykalra@xxxxxxxxx> wrote:

I was speaking strictly from understanding the code. It makes someone
not familiar with the code to think more than required as you would
need to know the type as its not explicit. As a code writer its not a
big deal at least when you are coding.

I see no difference in understanding between:

Form form = new Form();

and

var form = new Form();

That said, I do see a difference between:

Control control = new TextBox();

and

var control = new TextBox();

But in either case, I think that the fundamental understanding of the code is the same. The latter example demonstrates a marginal improvement when _not_ using "var" in terms of comprehending how the variable will be used, but I feel that difference represents maybe 5% of what there is to be understood, with 95% of the understanding the same either way.

I havent used it at all so far but my first impressions arent very
friendly towards it. However if there are benefits(performance etc)
than it is worth the effort/confusion.

There are zero code execution performance benefits. And I feel that using "var" can only take _away_ understanding of the code, never add to it. So I think that literally speaking, the only objective "benefit" is less text in the code, except in cases where you _have_ to use "var" (because of anonymous types being involved).

But I agree with the others who point out that in lots of cases, "var" doesn't in fact cause any reduction in understanding of the code as compared to the alternative.

Pete
.



Relevant Pages

  • Re: Problem with object instance....
    ... AFAIK, the problem is here, and your understanding of the "this" ... keyword. ... var INSTANCE=this; ... In rough terms, the value of "this" within a function depends on what ...
    (comp.lang.javascript)
  • Re: Questions about new : is this pattern legit?
    ... var me = this; ... a private member a function that calls the prototype method, ... You use the terms without understanding their meaning. ... Prototype.js was written by people who don't know javascript for people ...
    (comp.lang.javascript)
  • Re: create form on same page?
    ... formmail-nms.cgi script so that they can be sent to me via email. ... The code below does this using prototype.js (see function saveIt() ... var slider_value = new Array; ... not be understanding"; ...
    (comp.lang.javascript)
  • JScript bug in return statement?
    ... On my understanding, the following two solutions always should be equivalent: ... var s = node.getNodeIndex; ... The function getNodeIndex comes from treeview.htc (a part of unsupported MS WebControls) ... Any explanations? ...
    (microsoft.public.scripting.jscript)
  • Problem with submitting multiple hidden forms
    ... It's a datepicker javascript and it has a multiple hidden input forms, ... Transform your input text control into a date-picker control. ... in the 'input' tag or a special 'id' attribute format. ... var inputsLength = inputControls.length; ...
    (comp.lang.php)