Jon,
Jon Skeet said:
It's a less object-oriented way of doing things. If you want to do
something to a string, surely it makes more sense to call a method on
that string than to call a static method in a class in a totally
different assembly.
I believe that's a matter of personal preference. Take mathematical
functions for example. They are still shared methods although they could
alternatively have been implemented as methods of numeric data types.
Operators are not really object-oriented too. IMO it's legitimate to treat
strings differently from other types as it is done with types like 'Int32',
'Int64', etc. which have alias names defined and specialized support
provided as part of the language. VB.NET has built-in support for dealing
with strings ('Like' operator).
But they could easily have kept the VB syntax without keeping a lot of
the extra functions.
As the functions are not part of the language, that's not really relevant.
Maybe somebody else would have implemented an equivalent to the VB6 function
library if Microsoft hasn't done that.
Most of the functions have *similar* equivalents
in the .NET framework, as far as I've seen - the differences aren't
usually why someone would use the function rather than the more OO
method call.
OO has its advantages, but I do not see the huge benefits of OO when dealing
with numbers and strings. I remember discussions in which people were
asking why 'r.Replace("b", "c")' didn't manipulate the contents of 'r'. On
the other hand I have /never/ seen such a question about 'Replace(r, "b",
"c")'. Consequently I would not say that 'String''s methods are more
intuitive and preferrable over VB's strings-related functions. Another
example is 'Substring' vs. 'Left', 'Right', and 'Mid', which I have
mentioned in previous discussions about this topic. In this case I like the
power of 'Mid' on the one hand and the existance of specialized functions
over one generic method. VB's 'Split' functions is more powerful than
'String.Split', and thus I do not see any benefits in using 'String.Split'
instead of VB.NET's 'Split' function.
The reason for using the function would normally be
because that's what their old code did, IMO.
As shown above, that's not the reason why I prefer the VB string handling
functions over the methods of the 'String' class.
Hmm. It's unfortunate that with VB, the line between language and
library is somewhat hazy IMO. Is VB6 the language or the language plus
the libraries? Does "CDate" fall into the category of a language
element or a library call?
In VB6, the 'C*' conversion functions were members of 'VB.Conversion',
although they were compiled inline. In VB.NET, the conversion functions (or
operators...) are not part of a module included with
"Microsoft.VisualBasic.dll". In VB6 the line 'n = Conversion.CLng(12)'
compiled, while it cannot be compiled in VB.NET.
They're things that the compiler itself needs to be aware of (as far as
I know), whereas a compiler doesn't usually need to worry about what
libraries are available, so long as it can find out in a standard way
when you try to call them.
Yes, in VB6 the compiler was aware of the existance of the functions in the
library. In VB.NET the 'C*' functions are directly built into the language.
However, it's not uncommon that a compiler emits calls to functions in
external libraries for syntax features. In VB.NET and C#, for example, the
compiler will emit method calls and error handling code for the 'Using'
statement.
Either way, I hope you *do* take the point that saying that "nobody is
forced to use these functions" doesn't help you if you're trying to
understand someone else's VB.NET code when they *have* used them. It's
extra stuff to learn, and I don't believe most of it would be there if
it weren't for earlier versions of VB.
I really wonder how all those huge applications are being written if people
have problems with learning how a dozen of function work. It's pretty clear
understanding code which is implemented in another programming language
requires one to get familiar with the language.
There are very few of those in C# compared with the number of VB
functions, however - and they're part of C# that all C# developers (and
anyone reading C#) really *should* know.
For me it's important to make a clear distinction between language features
and library functions/classes. As you know, it's possible to use
"Microsoft.VisualBasic.dll" in C# projects too. "Cscompmgd.dll" has a
"Microsoft.CSharp' namespace, but this doesn't mean that the classes
contained in this library are part of the C# programming language. I agree
with you that someone claiming to be familiar with C# should know the
meaning of the 'using' statement, but I don't think that somebody using
COBOL.NET, which (I am not sure about this) doesn't have an equivalent
statement, needs to know that.
They certainly copied the syntax of Java to a large extent. I don't
think anyone outside Microsoft would argue against that. I don't see
why that's a legacy issue though. They fixed some of the issues at the
same time though, because they weren't trying to let people run their
Java code in C#.
The same has been done for VB.NET. They took certain features of other
programming languages, mainly VB6, fixed them and added other features.
A good example is calling static methods. I really like the fact that
C# doesn't let you call a static method via an instance variable. For
instance, this won't compile:
Thread t = new Thread (...);
t.Sleep (1000);
The equivalent in VB.NET *does* compile though - and I believe they
chose to keep it that way because it would have worked in VB classic.
VB6 didn't have static methods at all, so I cannot draw the line between
this design decision for VB.NET and VB6. The VB.NET team has chosen to use
the keyword 'Shared' instead of 'static' and refer to these members as
"shared" members opposed to C# where they are called "static" members.
"Shared" implies that those members are shared between all (0, 1, 2, ...)
instances of a class. So the decision to allow access to shared members via
an instance variable is in compliance with VB.NET's semantics of shared
members.
Practice has shown that this decision has drawbacks too, and thus this issue
has been fixed by adding a compiler switch which disallows access to shared
members via instance variables.
There are various quirks in VB like that - the handling of null strings
being another example. Do you really think they would have made the
string handling that way if they didn't care about backward
compatibility to some extent?
I am not sure what you are talking about. It would be great if you could
provide some more details.