Compiled Code—Not a Panacea

P-code is good. Native code is good. Visual Basic has them both. That doesn’t mean you can mix and match at will (although Chapter 5 will suggest a strategy for doing just that). Sometimes you have to make trade-offs. So let’s take a closer look at some of the basic facts of life for program size and speed.

First, program speed is important—it’s just not equally important everywhere. To listen to certain marketing material for previous versions of Visual Basic, you might think speed didn’t really matter. In fact, I could paraphrase what has been said by certain people at Microsoft (who will remain nameless) who thought of a compiler as more of a marketing bullet than a real feature: “Visual Basic programmers (in their ignorance) think they want a compiler, so we’ll give it to them. But they’re going to be disappointed when their forms don’t load any faster with native code than with p-code.”

Well, that’s true. If forms load faster in version 5 (and I’m told that they do), it’s not because of the compiler. The Form Show method isn’t now, and never was, written in p-code. Neither are the Data Access Objects (DAOs) or the Remote Data Objects (RDOs). What’s different about the speed of native code is not that it makes what you used to do faster. The difference is that it makes new things possible. For example, nobody in their right mind tried to write action video games with Visual Basic version 4. I’m not saying it would be easy now, but you could at least consider it.

Between writing the first and second editions of this book, I planned to write a book on C++ for Visual Basic. I ran out of time before I could finish it, but part of that book is available as a series of articles on Microsoft Developer Network (MSDN) and on the companion CD for this book. When I told readers of the first edition of Hardcore Visual Basic that I was working on a C++ book, a frequent reaction was surprise and even anger—as if I were betraying Visual Basic by writing about C++. A typical comment: “The next version of Visual Basic is going to have a compiler, so why would you ever want to use C++ for anything?” Good question. This book will attempt to answer it, but I’m sorry to say that there are still some important and useful tasks that require C++ or some other low-level language.

Some of them include:

I have been a tireless proponent (some Visual Basic developers and designers will say an obnoxious pest) of fixing these limitations so that Visual Basic really could do anything any other language could do (and I think it could be done without pointers). But alas, not this time. The compiler opens a lot of new doors, but I’m afraid that when Visual Basic programmers pass through those doors, they’ll find some language limits that never bothered them before.

According to my friend Joe Hacker, it takes at least one version after a major new feature is added before anybody (language user or language designer) fully understands the implications. So that means the next version of Visual Basic had better be a full-featured compiled language with no compromises (or at least not major ones). Unfortunately, that’s what I said last time.