VB does in fact support pointers. References to objects and ByRef parameters
are addresses. However, what you are looking for is direct manipulation of
addresses or the contents of a specific address. VB does support this, but
not in a way that is embedded in the language. The IntPtr type (which is
accessable from VB) represents a platform-specific integer value, used for
(among other things) holding addresses. You can use several utilities in the
System.Runtime.Interop namespace to retrieve the address and modify the
contents located at an address contained in an IntPtr.
However, to counter some of the arguments made about VB's roots in BASIC
being the reason for a lack of direct pointer support, let's remember that
BASIC did indeed have PEEK and POKE. I for one would like to see unsafe code
blocks in VB. I've only written two production C# programs since 2001 that
use unsafe code, but they really did help. The percentage of times a feature
is used doesn't seem like a good criteria - i'd rather measure the
usefullness, even if it's only required in a small percentage of situations.
After all, VB is getting (for example) operator overloads in the next
version (and VERY good support for them too!). You can make the same
arguments about operator overloads only being necessary in a small number of
cases, but when you need them, it's not easy to "work around" the lack of
support for them. What I like most about VB.NET over VB6 is that unlike VB6,
most of my VB.NET code is "hack-free" - I didn't have to do something
unintuitive or unsupported to "get around" some limitation. I would like to
see the last of that "hack" stuff go away by having real unsafe code blocks
supported by the language - after all, if I use the Marshal class, I can
already write the very same unsafe code with the same risks and side-effects
(but not get 100% of the performance benefit). It's also incredibly useful
when dealing with unmanaged code (which isn't going away anytime soon).
As for the RAD-vs. Framework argument... I always thought there was a
certain amount of ... well, BS in that argument. C# was an attempt to make a
RAD C language (as stated directly by MS in 2000-2001). However, now that
there are two primary languages in .NET, there are a lot of programmers that
are grasping for the answer to "which one should i use? what makes them
different?". Seems like some people have taken a stab at trying to "invent"
a reason for chosing one vs the other by artificially creating this RAD vs.
Framework argument. The truth is much simpler - people who love Java and
C(++) want to continue using a familiar curly-bracket consise language.
People who love VB tend to hate the syntax structure of C, and prefer to use
something familiar as well. That is the WHOLE POINT of having a CLI in the
first place - a common language infrastructre that supports the same
operations for multiple syntax sets. Unlike Java, MS set out to create an
environment where the programmer wasn't forced into one new language in
order to use the massive .NET framework and runtime features. The programmer
could use a language he/she was familiar with and be productive from the
very start without a massive learning curve. The real differenciating
principle should be "a matter of choice". In whidbey (the next version of
VS), the differences between the two languages gets extremely small. C#
still doesn't support non-indexer properties with parameters, and VB.NET
still doesn't support unsafe code blocks - but minutia aside, that's about
it. In addition, most of VB.NET's RAD features aren't all exactly syntax
(language) related - they are mostly support from an extremely large and
useful runtime library and IDE tools. C# could get a similarly-huge runtime
and better IDE tools and that would make it more RAD - and this has nothing
to do with the language itself. I can't tell you how many times people go to
the various C# groups and say "there's this function in VB, what's the C#
equivalent?" and the answer is "go build it yourself" or "reference the VB
runtime library". That is a matter of runtime library support, not language.
With Option Strict On, this argument makes very little sense, as the
structure, strict type-safety, and need for good design are about identical.
-Rob Teixeira [MVP]
Lance said:
VB.NET (v2003) does not support pointers, right? Assuming that this is
true, are there any plans to support pointers in the future? Forgive my
ignorance, but if C# supports pointers and C# and VB.NET get compiled into
the same code, then I don't understand why VB.NET can't support pointers.