Jon Skeet said:
How long do you really think it takes to get used to the syntax that
doesn't include redundant text?
It doesn't take long, but the code is still not as self-documenting and
self-explanatory as the VB.NET code is.
Have a look at the casting syntax in C#
compared with VB.NET - do you really think that the CType syntax is
more elegant than the casting syntax?
Yes, I actually think that VB.NET's casting syntax is better because it
doesn't suffer from the "lots of brackets" problem:
\\\
((SampleForm)foo.MdiParent).Bla();
///
versus
\\\
DirectCast(foo.MdiParent, SampleForm).Bla()
///
However, I don't think that VB.NET's solution is the best possible solution.
(Admittedly I wish that the
unboxing and conversion syntax in C# were distinct from casting, but
that's another issue. There are various things I'd like to see done
differently in C#...)
I'd like to see something like shown below as casting syntax:
\\\
(e-mail address removed)()
Dim x As IFooBar = goo.Bar.@IFooBar
///
In terms of a language itself, of course, it's significantly smaller
than VB.NET - what there is may be slightly harder to learn, but there
are far fewer keywords - 78 in C# compared with 151 in VB.NET.
There are many specialized keywords a beginner doesn't need to be aware of
('Declare', 'Auto', 'Unicode', 'Ansi', 'Alias', etc.). Some other keywords
increase readability of the code and are thus worth learning ('Overloads',
'AddressOf', 'RaiseEvent', 'Implements', 'Inherits', 'MyBase', ...). Other
keywords listed for VB.NET are not keywords at all ('Variant', 'Wend',
'GoSub', 'Let', 'EndIf', ...). Keywords like 'REM' and 'Stop' are rarely
used. The list of C# keywords doesn't include operators, but VB operators
are listed as keywords ('Or', 'And', 'OrElse', 'AndAlso', 'Xor', 'Not',
'Mod', ...). Another class of keywords are keywords for features only
supported by one of the programming languages ('Like', 'With', 'My',
'WithEvents', 'Handles', 'Where', 'On', 'Error', 'Resume', ...).
That's also not including all the VB built
in functions, many of which have been carried over from previous
versions of VB despite perfectly reasonable versions of many (most? I
don't have enough experience in VB to know) being available in the
framework.
Use of these functions is optional, it's not crucial to know how these
functions work.
In short, being a new language, C# doesn't have nearly as much baggage
as VB.NET does. (There are one or two places where C syntax has
unnecessarily been carried over, and that's a shame, but it's far from
the same situation as in VB.NET.)
I think that both languages, C# and VB.NET, carry over a lot of legacy
syntax. I believe that the ability to reuse knowledge is very important for
the success of a new programming language. Additionally I prefer
code-compatibility to a language's predecessor over revolutionary change.
Only where you're comparing two boolean values directly, which I find
to be pretty rare. I'll certainly accept that there's potential for a
bug there though. How often have you actually seen that bug, out of
interest?
I have seen it several times when working together with C++ beginners who
come from various backgrounds, and the bug made them ask "Why doesn't the
code work as expected?"...
Consider the following then, where "thread" is a variable of type
Thread:
thread.Sleep(5000);
If you were a beginner, what would you think that would do? In C# it's
not valid because Thread.Sleep is a static method. In VB.NET (2003) it
compiles without a warning, even in Option Strict mode. In 2005 it's an
optional warning/error, fortuantely.
It's a matter of semantics. The 'Shared' keyword in VB.NET means that the
member is shared between all instances of a class, which is different from
the semantic of 'static' in C#.
Another example - C# doesn't let you use a local variable unless it's
been definitely initialised. VB.NET (2003) does - again, a new
warning/error in 2005.
VB.NET automatically initializes variables, which is IMO a good thing in
addition to the warning.
Another example - VB.NET lets you pass properties by reference, even
though the semantics are significantly different in terms of timing and
what happens if an exception is thrown. I wonder what proportion of
VB.NET developers really know what happens when a property is passed by
reference?
I don't see a big problem here...
And as I say, you don't need to in C# if you write readable code to
start with.
Yeah, you could still scan the code for the blocks' heads with your eyes,
but this is a costly process.