Home > General Development > Operator Overloading in Visual Basic 2005 Operator Overloading in Visual Basic 2005 Eugenia Loli 2004-07-15 General Development 16 Comments Operator Overloading, new to Visual Basic 2005, simplifies the use & development of complex types by allowing you to specify your own implementation for standard operations such as addition & subtraction. About The Author Eugenia Loli Ex-programmer, ex-editor in chief at OSNews.com, now a visual artist/filmmaker. Follow me on Twitter @EugeniaLoli 16 Comments 2004-07-15 8:51 am Anonymous Quite often it makes things harder to understand (and you end up writing an awful lot of code such as == and = and a copy constructor). People say they’re great for pseudo-primitive types, e.g. Strings, complex numbers representations, big number representations and matrices. They’re right (except the Matrix bit, see the C++ FAQ on operator for more), but they should never get used anywhere else. And given that VB comes with a String primitive and people don’t do much complex arithmetic on it, I don’t see why you’d want to use these very often. Personally I prefer the wordy approach of Java where at least you know what’s what. 2004-07-15 9:05 am Anonymous Slowly but surely VB is turning into VC#. I am surprised Microsoft doesn’t rename VB to simply B#. It would fit with the rest of the chud stuff they offer. 2004-07-15 11:27 am Anonymous I’ve noticed this too. And I think it must be because Microsoft’s C# marketing machine didn’t do its job. I think Microsoft is actually surprised by how many exisiting Microsoft shops have clung to VB. Almost every person I talk to who’s moving to .NET is using VB.NET instead of C#. I think that it’s probably due to a misconception (or deception) sprung on managers by the tech guys who have somehow convinced management that moving to VB.NET from VB6 is okay because they have the foundational skillset in-house from their existing VB6 developers. Which, in my opinion, is entirely untrue. It’s like saying that because you have C++ developers that you can easily migrate them all to Java because the syntax is similar. The syntax may be more natural to those developers – but just because you have developers who know VB6 doesn’t mean that there isn’t a steep learning curve to grok concepts needed in a language that supports full object orientation. I think Microsoft was shooting for C# to become the dominant .NET language, but they have recently embraced VB.NET as their more popular brainchild and are taking strides to make it feature-for-feature stack up against C#… which really is a shame because in my opinion VB.NET is has a much more crufty syntax than C# – parenthesis as array indexers which makes them look like method calls, case insensitive code, and verbose language constructs all make for a language that is more difficult to read than C#. 2004-07-15 11:41 am Anonymous ..make for a language that is more difficult to read than C#. At the end it all boils down to the language you’re used to…a VB.Net guy would say C# is harder to read too. So, let’s all move to Ruby or Python 2004-07-15 1:03 pm Anonymous i prefer java way too. Operator overloading in some limited areas (linear algebra calculations) has good use, but the evil behind it does make it too dangerous for careless programmer. VB programmers, at least a big chunk of them are indeed “careless” IMHO. i can imagine people overloading “==” “+” operations all over the software with different purposes… so, good luck. 2004-07-15 1:23 pm Anonymous The operator overloading debate has been raging for years now, and all the arguments for both sides are known. Truthfully, I think that a language that allows the developer to make those choices instead of forcing an ideology on them is the best way. Others may disagree – that the need to prevent poor developers from writing bad code trumps any good uses for a feature like op overloading. It’s a debate no one’s going to win – but I personally believe that it’s better to let a developer have a tool and teach him how to use it rather than deny him that tool out of fear of misuse. I’d rather let my development team dictate programming idology than a language designer. 2004-07-15 1:59 pm Anonymous i do respect your opinion, however, giving too much choice in any given system causes uncontrollable abuses. Plus it makes it more difficult to learn, or letme rephrase “more difficult to understand” the system. in C++ , operator overloading gives great deal of confusion to many developers, and makes learning curve steeper. That is way, i dont think this is a ideology matter, it simply makes you use simpler mechanisms to do things with a little bit more use of characters or symbols preventing the potential abuses. therefore, i prefer simpler systems with less choices than more complicated systems with a lot of choices.. 2004-07-15 2:08 pm Anonymous I’ve had exactly the opposite experience with .NET. Almost everyone I know is using C#, whether they’re starting anew or switching from VB6. I’m in Tampa, so I guess it may be a regional thing. 2004-07-15 2:41 pm Anonymous Operator overloading was one of the main differentiators between C# and VB. What’s left, besides syntactical sugar? 2004-07-15 2:58 pm Anonymous Everybody thinks that operator overloading is evil until they see the absolute bullshit that is BigInteger in Java. I agree with Matt, let the programmer decide his design not Sun. Althought Java is a decent language, some of us coming from a C++ background think they dumbed it down a little too much initially. And that’s my biggest problem with Sun’s stewardship of Java. They’ve always got this “We know what’s best for you, don’t ask so many questions, do it this way” attitude – until C# came out and gave Sun some competition in the managed world. Pathetic. As far as VB.NET and C# is concerned, those two languages are supposed to take quite divergent paths sometime in the future, but who knows. 2004-07-15 3:39 pm Anonymous Quite often it makes things harder to understand (and you end up writing an awful lot of code such as == and = and a copy constructor). Actually, the article says that you can’t overload = in VB, because it’s a statement and not an operator. Eiffel doesn’t allow you to overload assignment, either. People say they’re great for pseudo-primitive types, e.g. Strings, complex numbers representations, big number representations and matrices. They’re right (except the Matrix bit, see the C++ FAQ on operator for more), but they should never get used anywhere else. 2004-07-15 3:41 pm Anonymous BTW, the copy constructor has more to do with the strangeness of how C++ works. You don’t have to do stupid stuff like that in Java or Eiffel; in fact I always forget the copy constructor when I return to C++ & I curse it a little bit before I continue. 🙂 2004-07-15 3:44 pm Anonymous As far as VB.NET and C# is concerned, those two languages are supposed to take quite divergent paths sometime in the future, but who knows. I am not so sure, since both must be compatible to the CLI. 2004-07-15 3:51 pm Anonymous I am not so sure, since both must be compatible to the CLI. There’s BrainF*ck.NET out there. That doesn’t mean that BrainF*ck and C# are the same except for syntatic sugar. Microsoft is getting bold, while Java is doing the conservative thing. Microsoft changed the runtime to incorporate generics, while Sun decided to use Type erasure so that the JVM would stay the same. My point is that given a rich enough IL instruction set and sophisticated enough JIT then there’s no reason that you can’t get completely divergent languages on top of .NET/Mono. 2004-07-15 6:28 pm Anonymous “parenthesis as array indexers which makes them look like method calls, case insensitive code, and verbose language constructs all make for a language that is more difficult to read than C#.” that’s your subjective opinion, I agree with the indexers, insensitive code and paths is one of the features that makes totally sense to Windows and VB users like the opposite makes sense to a Linux/C user, we’re used to things but who is right? Verbose language constructs is also very subjective, I assume that’s the main reason why people like VB, many code editor features like background compilation and auto indention and many other comfortable code editor features require a verbose syntax, many of this features are not possible or only limited possible with a compact syntax. Not everybody needs or likes such features but I’ve never heard a VB programmer complaining except occasionally it’s slow. Obviously some things are clumsy and over the top like ctype for casts (I hope with generics less of them will be needed), now there is “TryCast” (as in C#) but there is still no “Cast” operator which I would have preferred over ctype and all the other legacy things like CStr which do imho much harm to the language. Another good example where VB .NET sucks is AndAlso (|| in C#) which is one of the most used keywords and way to long, there are endless other things I dislike but I still prefer VB syntax over anything else .I dislike C syntax much (same a C programmers dislike VB syntax) especially when a C programmer don’t has a consistent or unconventional coding style and I have to read the code, in VB .NET that’s not much a problem since the code editor formats the code. I think I went over the top again so let’s just talk about VB .NET in this topic and not why it’s better or worse than C#, they both have ups and downs and every programmer has his subjective view about it 2004-07-15 6:42 pm Anonymous The point of a language is to be expressive. If some people find the crazy-go-nuts styling of Number as String to be more expressive and understandable than string Number, then, well, what the hell, right? As long as you’re using something that compiles to IL, you’ve got the ability to pick-and-choose a language according to your styles, and then invoke the same powerful API in whatever manner you see fit.