'with' statement

J

Jon Skeet [C# MVP]

There is no ambiguity with the VB with statement. It can, however, be less
useful than expected, especially when nested.

I didn't mean in terms of compiler ambiguity. You can make the language
specify that it'll be whatever you like. But for the *reader*, it looks
ambiguous - it's basically a minor disaster on the readability front.

I personally don't see why it's any more useful than using a local
variable yourself, without complicating the language.
 
J

Jon Skeet [C# MVP]

Peter Duniho said:
My point is that "ambiguity" as a debating point is a non-starter. A
"with" statement is only ambiguous if the language designer allows it to
be, and there's no reason for them to.

I should have been a lot more clear, and using the word ambiguous was a
mistake. What I meant was that it's not obvious to the reader of the
code which object is being referred to, unless they know the details of
the language specification. You could specify it any way you like, of
course, to avoid the compiler thinking it was ambiguous - but it would
still provoke a "Huh?" in the reader.

Apologies for causing confusion.
 
M

Michael D. Ober

Jon,

Agreed - nested "with" statements can be very difficult to read.

Mike.
 
A

Andy

Yes, introducing a "with" statement increases complexity, but that's true
of anything you include in a language. If "complexity" in and of itself
were an argument against inclusion, then no computer language would do
anything.

I wasn't arguing that complexity should rule out a feature though, I
was arguing that complexity which adds no value should be ruled out.
And keep in mind, there are plenty of people who would debate whether a
"with" statement offers "no real gain".

I could hardly take them seriously either. Eliminating the need to
type the variable name repeatedly in a block doesn't make things
anymore readable. You'd have to show that repeating the same variable
name in a few lines reduces readablity, and I don't anyone could
honestly do that.
 
P

Peter Duniho

[...] What I meant was that it's not obvious to the reader of the
code which object is being referred to, unless they know the details of
the language specification. You could specify it any way you like, of
course, to avoid the compiler thinking it was ambiguous - but it would
still provoke a "Huh?" in the reader.

Ah. Yes, I agree that even though the language can be made unambiguous,
it's still readability issue.

I think that if you disallow nested "with" statements, that helps a lot.
Not that I really miss having a "with" statement, just that if you didn't
allow them to be nested it wouldn't be all that bad. :)

Pete
 
M

Michael A. Covington

As well as a genuine "case" statement (allowing operands of any type) to
What if said objects don't have comparison operators? Most classes
don't define == or even .Equals, ...

That is true of the "switch" statement already. What concerns me is that
"switch" is so awkward, with "break" at the end of every section, mimicking
the Fortran-like flow-of-control semantics that underlies the original C
switch statement. I prefer the syntax of Pascal, especially since the C#
switch statement does *not* really work like the C switch statement that
it's modeled on; there is no fallthrough.
 
M

Michael A. Covington

I don't think C# is trying to target *every* developer on the planet.
It doesn't need to be all things to all people. It's much better (IMO)
to cater very well for the more common cases, making the rarer
situations a bit harder (but still perfectly doable).

If you think trigonometry is rare, you must not do much graphics.
 
J

Jon Skeet [C# MVP]

Michael A. Covington said:
If you think trigonometry is rare, you must not do much graphics.

Not a lot, no. I don't think a particularly large proportion of
professional developers do - particularly managed developers.
 
D

DeveloperX

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.

Mike.- Hide quoted text -

- Show quoted text -

Oh agree completely, it was a rant at some API's I've been forced to
use/fix in the past.

I'm "With" agnostic. I use it in VB6 and don't really miss it in C#
but I've no issue with its inclusion.
 
M

Mark Wilden

I think a with statement can make code easier to read. It explicitly says
"I'm these setting properties on the same object."

But my earlier caveat still applies.

///ark
 
M

Michael A. Covington

Jon Skeet said:
Not a lot, no. I don't think a particularly large proportion of
professional developers do - particularly managed developers.

The thing is, when you need a concise notation for mathematics, you *really*
need it, or the code becomes massively unreadable. And this happens to be
the first aspect of programming languages that was ever invented. It's a
pity to lose it.
 
J

Jon Skeet [C# MVP]

Michael A. Covington said:
The thing is, when you need a concise notation for mathematics, you *really*
need it, or the code becomes massively unreadable. And this happens to be
the first aspect of programming languages that was ever invented. It's a
pity to lose it.

Well, I quite agree that it would be nice to have the equivalent of
Java's "import static" in C# at some point, but I don't think that
making the maths easier is going to impact *that* many developers
compared with, say, LINQ which is likely to be useful to virtually
everyone.
 
M

Michael A. Covington

The thing is, when you need a concise notation for mathematics, you
Well, I quite agree that it would be nice to have the equivalent of
Java's "import static" in C# at some point, but I don't think that
making the maths easier is going to impact *that* many developers
compared with, say, LINQ which is likely to be useful to virtually
everyone.

What programming language do you recommend for mathematical programming in
..NET, then?
 
J

Jon Skeet [C# MVP]

Michael A. Covington said:
What programming language do you recommend for mathematical programming in
.NET, then?

Well, I haven't tried the Fortran for .NET compilers, but they'd be an
obvious starting point. Here's one:

http://www.silverfrost.com/11/ftn95/overview.asp

It really depends on how maths-heavy the code is going to be - I'd
probably *try* it in C# and see how painful it is to start with.
 

Ask a Question

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.

Ask a Question

Top