See inline below...
Secondly, VB.NET 1.0 and 1.1 can use overloaded operators. The syntax
isn't
the most lovely but it works. From your example you would use: gamma =
foo.op_Addition(bar)
I wish people would get in the habit of assuming that someone else will use
their code. Technically, yes VB can use operator overloads. However, that
assumes that the VB developer knows they exist. The odds are much higher
that the VB developer will not know they are there and try to wire up their
own special function that does the same thing as the overload. Of course,
later down the line it will be far from obvious why a change in the overload
logic doesn't affect the VB developer's code.
Lastly, I don't think the fact that VB.NET has a not-so-elegant way of
handling operator overloading means that it's only good for "Hello World"
apps.
IMHO, the statement "isn't the most lovely but it works" is the same as "a
not-so-elegant way" is the same as "insane vbonics solution that will cause
nasty hard-to-detect bugs when people use my code".
Think of the scenario: you want to build 1.x components that will be used by
other developers in an enterprise. If you use C#, your developers can easily
utilize a greater percentage of the CLR. In addition, you make operator
overloads such that your GUI developers do not even need to know they exist.
If you have some developers using VB in your company, then you have to code
everything to the CLS and you lose the ability to create *seemless* operator
overloads.
There are things that are nicer to do in C# and there are things that
are nicer to do in VB.NET (interop with Office apps being the classic
example), but there are *very* few things that one language can do that
the
other can't.
I completely agree that there are somethings that are easier to do in
VB.NET. However, assuming that your VB people will use your C# operator
overloads is a bug waiting to happen.
With all that said, I still can't fathom why VB.NET cannot *use* operator
overloads seemlessly. I can understand why VB developers might not want
them, but I fail to understand why VB.NET can't use them if they are in a
compiled C# dll. Doesn't it read the MSIL and see that C# has overloaded the
"+" operator?
Thomas
--
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada
Thomas said:
I fully disagree with people that say that VB.NET 2002/2003 is equivalent to
C#.NET 2002/2003. I was originally a high level VB6 developer. When I first
look at the original betas of .NET, I chose C# for a couple of reasons.
Firstly, Microsoft might as well have called VB.NET, "Fred". Only simple
syntatic similarities exist between VB6 and VB.NET. Other than that, they
are very different products. Secondly, VB.NET, for some idiotic reason, was
limited compared to C#. Silly things like unsigned integers were not
included. Lastly, as I began developing with C#, I discovered that VB.NET
had/has a HUGE limitation. VB.NET 2002/2003 cannot use operator nor
conversion overloads built in C#. That means if you build classes that
are
to be used by other developers, those other developers cannot use VB.NET
either because they have to hack their code to death to utilize
conversion
and operator overloads. For example:
Suppose someone in C# builds a couple of classes and overloads the "+"
operator. You could write the following:
MyClass foo = new MyClass();
MyClass bar = new MyClass();
MyClass gamma = foo + bar;
In VB.NET, they would have to write something like (not sure the exact
syntax):
Dim foo as MyClass = new MyClass();
Dim bar as MyClass = new MyClass();
Dim gamma as MyClass;
gamma = foo operator+ bar;
Insanity that VB.NET 2002/2003 cannot even *use* overloads built and
compiled in C#. So, prior to Whidbey, I would say that if you want to build
nothing but "Hello World" apps, you could use VB.NET, otherwise use C#. Note
that this opinion has absolutely nothing to do with performance which is the
same between VB.NET and C#.
Whidbey changes all that. Microsoft has added most of the new goodies to
VB.NET as well as C#. In addition, VB.NET 2005 includes operator
overloads
so, theoretically, VB.NET developers can use components with operator
overloads built in C#. I'm not yet sure if VB.NET can use conversion
overloads written in C#.
Thomas