Scott M. said:
I am and I do. But CStr() is not an object method as such. It is a
language element that (as this thread has shown) confuses many who
encounter it. My OPINION and PREFERENCE is to avoid it. I could easily
turn your statements around to say that to not use ToString is being
ignorant of the underlying framework that VB runs on.
As you stated stated, you think StringUtility.CStr() would better conform to
your preferences. Perhaps teaching your students how keywords like CStr
compile inline
or the existence of other functions in Microsoft.VisualBasic and the notion
of scope and how the
Imports statement works and what it's supposed to accomplish. CStr is simply
a utility method (compile time conversion?) that sets VB apart. The
"Framework" can't be all things to
all languages.... as I expand upon below....
The immutable nature of the String class does not break any OO doctrine.
It simply has to do with memory management. There goes nothing.
And CStr simply has to do with encapsulation. If s.ToUpper doesn't break OO
doctrine in your book, then I don't seee how Microsoft.VisualBasic.CStr()
does.
That's your opinion and you are entitled to it. There are many things
that are part of VB.NET because MS hasn't found an appropriate way of
losing it from the language.
You base this opinion on what?
I call CStr(), LCase(), UCase(), Time(), Hour(), Replace(), Split() et all
legacy functions because I believe that's what they are.
You "Believe" based on what? Here's why you're wrong: Using
String.Substring(10) on a string that's only 5 characters long will yield an
exception. Left(s, 10) does not. Sure you can add conditional length
checking code.... but that's why VB's encapsulation methods set it
apart.....
If Not s Is Nothing Then
If s.Length >= 10 Then
s2 = s.Substring(10)
End If
End If
=
s2 = Left(s , 10)
Come on. Isn't this obvious? Do you actually prefer the former? If you do,
there is NO POINT in using VB. Use C#.
I believe they exist as part of the VB language syntax to provide VB 6.0
developers (and the millions of lines of code written by them) a
transition into the .NET programming platform. I do firmly believe that,
over time, they will be phased out of the language and so I steer clear of
them.
C# has a "string" ALIAS for System.String (note the All lowercase). There
weren't "millions of lines" of C# code out there when C# came out so why did
Microsoft provide that alias as part of the language? No, these things
that you say are "legacy" are there because they are what make VB a
BASIC-derived language.
The .NET platform is not the end all and be all. It is simply a foundation
upon which certain languages will provide certain features *in addition* to
the building blocks already in the framework platform. If you get tunnel
vision and zero in on the framework SOLELY, you're missing out.
Then
1) encapsulate CStr in your own StringUtility
2) write your own implementation of CStr if you think you can do a BETTER
job than Microsoft.
But, for heaven's sake don't litter your code with zillions of needless
conditionals. Again, encapsulation is key.
Your opinion. There are those that say that the entire VB language is
verbose. If you don't like verboseness, may I respectfully suggest you
try C# and that maybe VB.NET isn't for you?
You're mixing things up again. VB may be a verbose language in that it uses
longer english-like keywords. It is NOT a verbose language in that the 5
lines of code that are necessary in a C# program are handled by one line or
NO code at all in VB.... such as declaritive event handling using the
Handles clause which C# lacks.... or my Substring() example above!