G
Guest
Hello,
In vb.net there is a with statement, Is there are similar constructor in c#?
In vb.net there is a with statement, Is there are similar constructor in c#?
In vb.net there is a with statement, Is there are similar constructor in c#?
In vb.net there is a with statement, Is there are similar constructor in
c#?
Andy said:No, there is not.
Michael A. Covington said:But there ought to be.
As well as a genuine "case" statement (allowing operands of any type) to
replace the current "switch" statement, which is a deformed relic of the
influence of Fortran upon C in 1972 or so.
I suspect we'll have to agree to disagree on that front.
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.
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.
Peter Bromberg said:I've seen this particular question come up at least 4 or 5 times in the
last
year or so, and I have to agree. "With xyz ".... is simplyunnecessary in a
concise and elegant language like C#. Hard core classic VB programmers who
are resistant to change are usually the ones who harp on this (among other
silly issues).
Peter
Michael A. Covington said:What I'd much rather have is a concise notation for mathematics.
Programming as we know it originated with Fortran (Formula Translation),
which allowed you to write such things as:
Y = SIN(X)**2 + COS(Z)**2
In C#, if I'm not mistaken, we're now stuck with
y = Math.Pow(Math.Sin(x),2) + Math.Pow(Math.Sin(z),2)
which is a great deal farther from normal mathematical notation. I know
it's nice and object-oriented, but something valuable has been lost.
It could have been worse. They could have given us:
Object.Assign(ref y,
Math.Add(Math.Pow(Math.Sin(x),2),Math.Pow(Math.Sin(z),2)));
If + has special status as a math operator, then why not ** and the Math
functions?
There's an easy solution to the problem of nested "with"es - "don't do
that".
I think a stronger objection is that you shouldn't be making a lot of calls
one after another to a single object (in general).
///ark
DeveloperX said:I completely agree with this. One of my bug bears is coming across
code that looks like:
Kitten.MoveFrontPaw(Left);
Kitten.MoveBackPaw(Right);
Kitten.MoveFrontPaw(Right);
Kitten.MoveBackPaw(Left);
instead of:
Kitten.Walk();
and then the above travesty is needlessly repeated in about 30
locations normally with comic variations of Paw ordering.
Peter Duniho said: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.
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.
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
I like a small language, personally. I don't think most people use the
power operator often enough to make it worth including in the language,
myself.
But there ought to be.
As well as a genuine "case" statement (allowing operands of any type) to
replace the current "switch" statement, which is a deformed relic of the
influence of Fortran upon C in 1972 or so.
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.
Your example is multiple methods being called. I agree with you for
methods. However, try this:
Kitten.Color = "Black"
Kitten.Eyes = "Green"
Kitten.Fur = "Long"
These are properties of a Kitten. In general, they cannot be incorporated
into a single property.
But when we use it, it really helps correctness if our formulas can *look*
like formulas!
[...] 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.
There is no ambiguity with the VB with statement.
Ambiguity is, IMHO, a poor argument against a "with" statement. [...]
Actually I find it a good argument. It makes the language (and hence
the compiler) more complex. Adding a bunch of complexity for no real
gain isn't a great idea in my opinion.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.