A
abc my vclass
C# has VB's "with" command?
I like VB's with command, why don't know C# has it or not?
I like VB's with command, why don't know C# has it or not?
Nicholas Paldino said:I disagree with the statement that it would be a nice addition to the
language. Check out the following "ask a designer" section on the MS
website for more information on why it was left out:
http://msdn.microsoft.com/vcsharp/programming/language/ask/withstatement/default.aspx
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Pohihihi said:'With' is a statement in VB. It would have been a nice addition to C# but
it is not so for now. You have to fully qualify Object.Proporties in C#
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vaorikeywordsptozvba.asp
http://msdn.microsoft.com/library/d...y/en-us/csref/html/vclrfcsharpkeywords_pg.asp
Reasons given on the link are actually no better than "I want it cause it is
easy for me to work like that". MS was never worried about making things
complex. Only thing that might have some logic IMHO is of C++ relation. C#
is more in the class of C/C++. But yes that is right that having With is not
a big typing and readability benefit but still sometimes when setting tons
of properties it might have been easy, but ctrl + v works just fine.
Nicholas Paldino said:I disagree with the statement that it would be a nice addition to the
language. Check out the following "ask a designer" section on the MS
website for more information on why it was left out:
http://msdn.microsoft.com/vcsharp/programming/language/ask/withstatement/default.aspx
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Pohihihi said:'With' is a statement in VB. It would have been a nice addition to C# but
it is not so for now. You have to fully qualify Object.Proporties in C#
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vaorikeywordsptozvba.asp
http://msdn.microsoft.com/library/d...y/en-us/csref/html/vclrfcsharpkeywords_pg.asp
C# has VB's "with" command?
I like VB's with command, why don't know C# has it or not?
"A critic is a legless man who teaches running."
Just where, exactly, do you think that C# is unnecessarily complex?
I've been programming for 20 years and I find it one of the best
languages I've used.
There you go, one sneering quotation each.
Bruce said:"A critic is a legless man who teaches running."
Just where, exactly, do you think that C# is unnecessarily complex?
I've been programming for 20 years and I find it one of the best
languages I've used.
Nicholas Paldino said:I disagree with the statement that it would be a nice addition to the
language. Check out the following "ask a designer" section on the MS
website for more information on why it was left out:
http://msdn.microsoft.com/vcsharp/programming/language/ask/withstatement/default.aspx
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Pohihihi said:'With' is a statement in VB. It would have been a nice addition to C# but
it is not so for now. You have to fully qualify Object.Proporties in C#
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vaorikeywordsptozvba.asp
http://msdn.microsoft.com/library/d...y/en-us/csref/html/vclrfcsharpkeywords_pg.asp
I haven't been programming for 20 years (just 10), however, the C#
syntax to create an event is ridiculous. This is one area where vb wins
hands down. Consider this:
public class Client
public event FireThis()
public sub Stuff()
raiseevent FireThis()
end sub
end class
Now compare this approach to having to setup delegates, linking them to
events, etc...
I didn't say that it was elegant. I took issue with the statement that
it wasn't simple.
I've used plenty of arguably simpler languages, but with that
"simplicity" and "elegance" came the unfortunate requirement that
programmers take care of all the picky details. C++, for example, was
pretty bad in this regard. I'm not knocking the language: Stroustrup
did an excellent job and, I think, achieved his goals. It's also the
language I would recommend for certain types of high-performance and
real-time work. However, I've watched time and time again as average
programmers struggle to create reasonable complex software that's not
problem-ridden.
C#, for its supposed lack of simplicity, seems to me to strike an
excellent balance between being a workhorse like C / C++, taking care
of the messy details like Java, and being usable by average mortals. I
suppose that one could argue that VB.NET is more accessible than C#,
but IMHO VB encourages a sort of sloppiness that causes more problems
than it solves.
I'm a practical guy and I like working solutions to real problems. C#,
for my money, delivers, and no, I don't find it overly complex. VB.NET
is overly complex in that it does too much stuff behind your back. C++
is complex in anther way in that it requires you to take care of too
many picky housekeeping details.
I think that C# gets the balance right, that's all.
Sorry about the critic quote. It was intended to be light-hearted. I
guess I should have added a smiley afterward.![]()
Jon said:Well, the code you've shown hasn't actually shown the wiring of the
events in the VB.
You need to separate three different elements:
1) Declaring the event
2) Subscribing/unsubscribing to the event
3) Firing the event
Let's look at each in turn:
1) Declaring the event
VB.NET allows you to create an event without explicitly declaring a
delegate. However, I can't see how that's a good idea really - clients
in other languages will need to know what type of delegate to use,
preferably with documentation. In other words, VB.NET is encouraging
what I consider to be sloppy programming.
Both C# and VB.NET allow you to provide your own add/remove semantics.
VB.NET also allows you to provide your own event raising semantics - it
would be nice if C# allowed this. I had to look pretty hard to find
this in the VB.NET docs though (most pages just showed the "simple"
event declaration syntax).
2) Subscribing/unsubscribing to the event
VB.NET has the "Handles" keyword, which autowires an event to a field,
by turning that field into a property internally. Personally, I have no
problem with wiring the event manually, and think it shows what's going
on more clearly - *without* implicitly changing fields into properties.
3) Firing the event
Here, VB.NET has RaiseEvent which appears not to be thread-safe (given
a brief look at it). It could raise a NullReferenceException if the
last subscriber unsubscribed between the nullity test and the
You can also call the event handler directly, using the event name
followed by "Event" (is that documented?) which means you can write
your own event firing code to make it thread-safe. I doubt that many
people bother though
In C# you have to do the nullity check yourself. This is a bit of a
pain I'll admit, but it does make it more straightforward to make the
code thread-safe.
If I understand you correctly, you prefer:
1) The fact that you don't need to specify the delegate in VB.NET. This
makes for code which is less clear for other languages IMO, as well as
for places where you need to explicitly add and remove handlers (you
have to use the implicitly created FooEventHandler delegate - and if
you've got lots of events using the same parameters, you'll end up with
multiple delegates for no good reason).
2) Wiring up the events using "Handles". I don't like fields becoming
properties implicitly. I may be in the minority on this one though.
Frank Rizzo said:No, it can't.
I'd like to see you reproduce this.
Secondly, don't use events as a way to marshal between threads. This
ain't delphi.
I am not understanding what you mean by fields becoming properties. You
use Handles on a method, not a field.
The language has 70-odd keywords, currently 2 different syntaxes (main
code and attribute definition; you can't use keyword assignment, except in
attribute definition - where you can - any *logic* to that?)
soon to be 3
with the inclusion of generics. And 4 if you include lambda expressions
(in 3.0 IIRC). What a dog's dinner.
Clumsy syntax and declarations; MyObjectType myObject = new MyObjectType()
- yechh - pointless. Simplified in 2.0 (or is it 3.0?), but why did this
abomination exist in the first place?
The argument I usually get from supporters is that there's a framework
method that will allow them to get the job done in 4 or 5 lines, and this
is pointed to as evidence that you can arrive at a "simple" solution. It's
finding them that's the trouble, and I find that for non-trivial
applications, they look like real bitches written down, practically
obfuscated. Admittedly, you get code completion, integrated help etc., but
this hardly points to simplicity.
This is a greenfield language, no legacy compatibility issues. It's far
less impressive when viewed in that light. It's strikes me as a series of
improvements on the somewhat shaky bedrock of typical "curly brace"
languages. Disappointing.
I'm with you on VB/VBScript/VB.NET; bloody awful IMHO.
Now compare this approach to having to setup delegates, linking them to
events, etc...
Clumsy syntax and declarations; MyObjectType myObject = new MyObjectType()
- yechh - pointless. Simplified in 2.0 (or is it 3.0?), but why did this
abomination exist in the first place?