Let me be frank first. I don’t like Visual Basic much, and never have in the days of Visual Studio 6 and so forth. I don’t find it easy on the eyes when reading it. However, recently I found myself in the situation of having to start a new project using the VB language, for the company I recently started working for in Italy. To me, it seems like in Italy they tend to use Visual Basic much more then where I’m coming from, Holland. I would like to see that explained or maybe if I’m wrong, rejected. Also during a .NET course I have taken, the teacher had a slight preference for VB, and stated that there are some slight productivity advantages to VB. This is when I decided to make a list of all the things I found to be different between the two. Note that both languages are equally compatible with the .NET framework, the differences lie in the syntax, symantics and availability of features inside the code editor of Visual Studio.NET.
Visual Basic lacks
- Tooltip documentation in the code editor.
- "Go to definition" only possibile between symbols in the same assembly. In C# you can navigate freely between assemblies.
- Complete abstract class member function when coding a new derived class.
- The code error resolver is more limited than that of the C# code resolver. For instance, you can not let it add namespaces to the module in order to solve unknown type errors.
- No code refactoring (except for the rename refactoring). This was a major addition to the C# language in .NET 2.0. I use it all the time, for example to extract pieces of code into a new function, in which it does a great job, automatically declaring all parameters needed.
- No intellegent type automation when inserting snippets. For example, C# is capable of inserting all the possible enumeration values when inserting the switch statement snippet.
- Code snippets are not listed in the code completion list (in VB you use the insert snippet command). This is more a difference than a lacking, and subject to personal preference.
- No code completing for overriden methods, in C# you can start typing a overriden method, and it will propose to you all the overridable methods from the baseclasses.
- Cannot automatically insert event handlers. You have to type them out manually. In C#, when you type += after a event property, C# will let you create the event handler including all the right parameters, so you can go right ahead and programming the handler.
- Microsoft uses C# for their programming tasks, they use VB for their scripting tasks. If the company that programmed these languages prefers the one over the other for programming applications, it’s a good bet they will do everything to keep C# as easy as possible to fulfull this task with.
- The VB compiler allows weak typed variables using the following construct Dim person = New PersonClass(). If you declare a var like this, you will be able to write whatever method or property you want behind it. The validity of these members are check during the execution of the code, which means that it is a possible source of errors which, in worst case scenarios, could be detected to late, when an application is in production. I’m against every weaked-type construct, and so should you!
- Class members are initialized after the constructors of the class have been called. This means that you never know if assignments inside your constructors are going to be overwritten by a baseclass. It just against common sense to initialize constants after the constructor, and I don’t know any OOP language which does that.
- No code completion for language keywords.
- No anonymous methods
- In C# all .NET constructs are elegantly build into the language, in VB they are often build on top of the language. For example VB does not allow “is nothing” comparisions on nullable types (confusingly it does support assigning nothing to nullable types). Also in C# is much easier to add an eventhandler to an event using the += operator. In VB you have to use the more elaborate AddHandler / AddressOf construct (AddressOf??? did .NET not get rid of the sense of programming with pointer addresses?).
C# lacks
- The “Me” namespace. The Me namespace contains all kinds of shortcuts to objects throughout the framework. BTW I dont use it, I know where I can find all these objects.
- In VB when deleting an event handler of a control, it is removed automatically from the control event property. I find this very useful, and I can’t see why they didn’t implement this behaviour is C#.
That’s it, I didn’t even elaborate on the fact that I find C# a more modern language which can give your company the image of being in sync with new technology, while VB could be associated with older technologies. Also Microsoft (and other companies) usual publish their sources in C#. Also a lot of blogs and tutorials out there, strictly list C# code.
If you are a VB enthousiast, and think that my list contains some wrong assumptions or other errors, you are welcome to comment on them, so I can correct them and maybe learn how to use VB better myself.
Geen opmerkingen:
Een reactie posten