Re: 'with' statement

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




"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.


.



Relevant Pages

  • Re: with statement
    ... I suspect we'll have to agree to disagree on that front. ... 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. ... I don't really see ambiguity as a significant or unresolvable problem, with respect to having a "with" statement. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: FIND
    ... without clearly specifying what that difference implies. ... ambiguity, SEARCH-WORDLIST does *not* say that different xt's can be ... this still leaves the question open what it returnes for words ... you disagree that adding this word provides still more ambiguity, ...
    (comp.lang.forth)
  • Re: Astigmatism vs. distance
    ... optometrists and ophthalmologists tend to disagree on how the convention ... prescribe cylinder. ... and remove that ambiguity. ...
    (sci.med.vision)
  • Re: 48 Hours Saturday
    ... I have to disagree. ... some doubt, some ambiguity. ... It always looks like innocence thru the first 2/3 of the ... Prev by Date: ...
    (alt.true-crime)
  • Re: All languages are equally fit
    ... Both mathematical notation and programming languages may have ... A *well-defined* formal notation system has no ambiguity. ... That's not ambiguity in the computer language; ...
    (sci.lang)