11 Oct 2005 Update: The answers are now posted. Select the area after C#: or VB.Net: to see the answers. Originally posted 12 Mar 2005.
A friend and I have had numerous discussions on the merits of VB.net and C#. One of the points I've attempted to make during these discussions is that because VB.net uses more natural language keywords, you have to remember less things. He seems to believe that the keywords that C# uses are the ones that come natural to him anyway so my point isn't really valid. In poking around the net I came across a few examples that I think may help me in making my point. Maybe it will work, maybe it won't.
Classes:
Let's say you are creating a class. You don't want other programmers to be able to create an instance of this class. You only want other programmers to be able to inherit from your class. What keyword would you use in C#? How about VB.net? Which one seems more natural?
C#: abstract VB.Net: MustInherit
Now you want to create a class but want to make sure that it is only used by other programmers by creating an instance of the class. Other programmers are not allowed to inherit from your class. What keyword would you use in C#? How about VB.net? Which one seems more natural?
C#: sealed VB.Net: NotInheritable
Now that we've created our class, lets move on to...
Methods:
You've created a method as a shell that you want other programmers to implement in their class. They've inherited from your class and you want to make sure they override the functionality of this shell method. What keyword would you use in the method declaration in C#? How about VB.net? Which one seems more natural?
C#: abstract VB.Net: MustOverride
You're now creating a method that you want to make sure works the way you coded it and doesn't get overriden by a programmer inheriting from your class. What keyword would you use to keep them from overriding your method in C#? How about VB.net? Which one seems more natural?
C#: sealed VB.Net: NotOverridable
Misc. oddities:
Now lets move in to an area that is just weird. Lets say you have a variable that you want to be shared between all instances of a class. What keyword would you use in C#? How about VB.net?
C#: static VB.Net: Shared
Now lets say you have a variable that you want preserved between calls to a particular method, but don't want it shared between instances of the class. This one deserves a bit more explanation. Lets say you have a class called Count that has a method called Add (yes, this is kind of a weak example and you probably would never do something this way, but bear with me). Add has the variable in it that you want preserved called Total. Add increments the Total variable and returns it's value. You create an instance of Count called Hits and another instance of Count called Views. You call Hits.Add 2 times, then call Views.Add 2 times then call Hits.Add 3 more times and call Views.Add 1 more time. The last time Hits.Add is called, it returns 5. The last time Views.Add is called, it returns 3. What keyword do you use when declaring the Total variable in C#? How about VB.net? Which one seems more natural?
C#: Don't think you can do it VB.Net: Static
Conclusion:
The answer to which of the above keywords is more natural is subjective. One person may think one way is more natural while another thinks the other is more natural. If you've been programming in one language long enough, the keywords are going to be so ingrained in your head that they're second nature to you. What I'm trying to point out here though, is if you didn't know what the keyword was to do one of the above tasks, could you type in three or four guesses in to the VS.IDE and stumble upon the right keyword?
On the other hand, if you are looking at the code someone else wrote in one of these languages and you see the keyword used in one of the above examples, will you be able to tell what it means or will you have to look it up? Again, if you have the keywords already memorized, then you're not judging whether they are more natural or whether you can tell what they mean when first exposed to them. I learned some keywords in C, C++, Perl, etc.. that I knew by heart at the time. I've since forgotten a good bit of them. If I went back and looked at code that used those keywords, I MIGHT be able to remember what they meant but I would probably need to look it up. I believe that if I didn't code in VB.net for the same period of time and then went back and looked at old code, I would have to look up a lot less keywords than I would in C# or the other languages listed above. That, to me, says that VB.net's use of keywords is more natural.
You may have noticed that I didn't give any of the answers to the questions of what keyword you would use for the above scenarios. I'm going to let this post sit here for a while before I add that in. When I do add them in I'll add them in a way that hides them until you want to see them. If you don't know what keyword to use in some of the above examples, make 4 guesses for each language. When I post the answers, see how many of each language you got right.
Enjoy,
Check
No Comments for this post yet...
Comments are closed for this post.
| Mon | Tue | Wed | Thu | Fri | Sat | Sun |
|---|---|---|---|---|---|---|
| << < | > >> | |||||
| 1 | 2 | 3 | 4 | 5 | ||
| 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| 13 | 14 | 15 | 16 | 17 | 18 | 19 |
| 20 | 21 | 22 | 23 | 24 | 25 | 26 |
| 27 | 28 | 29 | 30 | |||