Re: 'with' statement
- From: "Michael D. Ober" <obermd.@.alum.mit.edu.nospam>
- Date: Wed, 2 May 2007 07:27:22 -0600
"Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx> wrote in message
news:op.trn7txyi8jd0ej@xxxxxxxxxxxxxxxxxxxxxxx
On Tue, 01 May 2007 15:30:40 -0700, Jon Skeet [C# MVP] <skeet@xxxxxxxxx>
wrote:
Michael A. Covington <look@xxxxxxxxxxxxxxxxxxxxxx> wrote:
But there ought to be.
I suspect we'll have to agree to disagree on that front.
And I'll disagree with you both (but agreeably so, I hope). :)
I disagree that "there ought to be" in C#. As the article Mark referred
to points out, we lived just fine without a "with" statement in C and
C++. It's just not that important a construct to argue that it *ought* to
be in the language, even if having it would make life a little easier.
Intellisense in VS makes the usefulness of "with" even less, since it
usually only takes a handful of keystrokes to type in the longest of names
(exceptions including when you've got a lot of long names that are mostly
the same...a bad idea anyway, IMHO :) ).
I do see utility in the "with" statement. I just don't find it so
compelling as to demand its inclusion in the language.
I'd rather write a descriptive variable name and put that in front of
each statment than have the ambiguous (when there are multiple levels
of "with") dot on its own.
Ambiguity is, IMHO, a poor argument against a "with" statement. The
article Mark referred to brought up the question of ambiguity between a
field and a local variable. Well, as VB does, so too could C# just
require slightly different syntax for a field than a local (so you can
easily tell the difference between ".Text" and "Text"). As far as nested
"with" statements go, there are two easy solutions: either disallow nested
"with" statements altogether, or only allow access to the inner-most
"with" statement in any block of code.
In VB, the with statement is really nothing more than telling the compiler
"Make a temporary, unnamed, local variable for me." As for ambiguity in
nested with statements, only the inner most with statement allows access to
its properties without specifiying the variable name. Is a with statement
useful - definitely. Is it a must have, no.
I'd prefer the former, but if the language did the latter but the compiler
emitted a warning similar to that used when hiding a local variable, that
would be fine with me too.
I don't really see ambiguity as a significant or unresolvable problem,
with respect to having a "with" statement.
Pete
There is no ambiguity with the VB with statement. It can, however, be less
useful than expected, especially when nested.
Mike.
.
- Follow-Ups:
- Re: 'with' statement
- From: Jon Skeet [C# MVP]
- Re: 'with' statement
- From: Peter Duniho
- Re: 'with' statement
- References:
- Re: 'with' statement
- From: Andy
- Re: 'with' statement
- From: Michael A. Covington
- Re: 'with' statement
- From: Jon Skeet [C# MVP]
- Re: 'with' statement
- From: Peter Duniho
- Re: 'with' statement
- Prev by Date: Re: 'with' statement
- Next by Date: Re: 'with' statement
- Previous by thread: Re: 'with' statement
- Next by thread: Re: 'with' statement
- Index(es):
Relevant Pages
|