Re: use of var
- From: "Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Mon, 02 Mar 2009 12:24:44 -0800
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
.
- Follow-Ups:
- Re: use of var
- From: Pavel Minaev
- Re: use of var
- From: Ajay
- Re: use of var
- References:
- use of var
- From: Peter
- Re: use of var
- From: Jeff Johnson
- Re: use of var
- From: Ajay
- Re: use of var
- From: Peter Duniho
- Re: use of var
- From: Ajay
- use of var
- Prev by Date: Re: use of var
- Next by Date: Re: use of var
- Previous by thread: Re: use of var
- Next by thread: Re: use of var
- Index(es):
Relevant Pages
|