Re: VB.NET advantages

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Michael D. Ober (obermd._at_.alum.mit.edu.nospam)
Date: 01/14/05


Date: Fri, 14 Jan 2005 05:04:42 GMT

OK, I had to write a simple program to convert a flat file from a print job
into a CSV file. I could have done this in VB 6 in about an hour. It took
2 hours in VB 2005 Express Beta 1. Here's what I learned.

1 - The core Basic Language is almost, but not quite the same. The specific
area that I ran into that was different was the "open <filename> for input
as #1" is no longer there by default. The IDE will tell you this and even
tell you what code you need to insert to put it there. Instead, I chose to
use the System.IO.StreamReader class in the .Net 2.0 runtime.

2 - Object classes are a hell of a lot easier to implement in VB 2005. You
don't need a seperate .CLS file, although I would still use one for a more
complex development task than this one. I created an Object class that
inherited from the StreamReader and was able to use all the underlying
StreamReader methods that I needed, without writing a single bit of code
other than "inherit StreamReader" as the first non-comment line of the
class.

3 - Properties (Property Let/Set/Get) are syntactically much easier to
handle and code. In VB 6, it is possible for the Property Let and the
Property Get method code to get separated from each other in the source.
Not so in VB 2005. The overall syntax for this is

Property Foo() as type
   Get
       ' Your code that returns "type"
   End Get
   Let (t as Type)
       ' Your code to set the internal variables
   End Let
End Property

Note that there is no "SET" as objects no longer have a default method or
property - this has the benefit of making the code somewhat clearer at the
expense of more code. Also, read only properties are explicit with the
keyword "ReadOnly" being placed before the keyword "Property." In this
case, the IDE would only put in the blocking structures for the Get portion
(see item 10 for more). In VB 6, because the Let/Get parts of a property
can be split in the code, it's possible to make a read/write property appear
to be a read only property because the Let portion is elsewhere.

4 - The IDE is actually superior in some ways to that of VB 6 (I can't say
this about the IDE in VB 2002 and VB 2003.). The compiler doesn't stop on
the first error and it will even compile in background, putting the compile
errors in a window. You can click on an error and the IDE will immediately
take you to the offending line of code. As you fix the code, the error is
removed from the window.

5 - Edit and Continue is back and fully functional. I fixed coding errors
on the fly without restarting the debug runs. I copied and pasted in and
out of the immediate window. Changed the value of variables in the
immediate window. Reexecuted lines of code by copying from the source and
pasting into the immediate window.

6 - The locals window is a little harder to use as objects have a lot of
additional overhead that is displayed, especially collection objects.
However, collection objects will show both the value of an item and its key,
so more useful information is available, but a lot of not so useful
information is also displayed.

7 - The watch window has the same features as the VB 6 watch window, but it
also shows the same excessive amount of information as the locals window.

8 - Intellisense - Way too many options, but the most common ones are first
and as you enter function arguments, the intellisense options are trimmed.
Property drop downs are more like VB 6, with the exception that you can
select from the most "common" properties or from the complete list all the
way back to the root of the object heirarchy. The most common ones appear
to be well thought out.

9 - IDE support for coding - As you close quotes and parenthesis, the IDE
highlights the corresponding open mark. I found this really useful when
coding lines such as

    if left$(s, len("foo")) = "foo" then

10 - IDE support for blocked structures (if then ... end if) When you key
in the start of a block the IDE automatically fills in the keyword(s) that
end the block. It also automatically pretty prints your source for you. If
the automated pretty printer gets confused, there is a menu option to pretty
print the whole file. I discovered that the automatic pretty printer worked
about 90% of the time - the rest of the time, failing only when using
cut/paste to copy code from one location to another.

11 - Structured exception handling. You still have the option of "On Error
Goto ...", but VB 2005 also has Try ... Catch ex As Exception ... End Catch
blocks. Try blocks are far more flexible that On Error Goto. The one On
Error option that is tough to emulate with a Try block is "On Error Resume
Next".

12 - Console Applications. These are a royal pain in VB 6 as you must use
the Windows Console API to do this. VB 2005 natively supports them as well
as more traditional form based applications. This program was a console app
as it didn't have any fancy user IO other than status updating, which a
console window is ideally suited for.

13 - A real line/column counter in the editor. I was having to extract data
from fixed format, undelimited lines using the Mid$ function. I opened my
source data file in another window and used the line/column information on
the status bar to assist in the mid$(...) statements. What it's missing is
a column start/length feature; this could be added to the IDE and I would
add it if I were to find myself having to parse a lot of print files. In VB
6, I would either have had to manually count my columns or more likely open
the file in the VC++ 6 editor were I could use that editors line/column
status information.

14 - IDE Code window support for finding errors. Errors are underlined and
putting the mouse over the underline will pop up a tooltip explaining the
error.

15 - Debugging unhandled exceptions is a lot easier with the unhandled
exception debug window popping up and telling you exactly what the exception
is - in English. I had my output file open in Excel when I restarted a
debug session. The exception window told me that the output file was open
and locked - I couldn't create a new one. When I closed Excel, and pressed
F10 to step to the next line of code, the line with the exception reexecuted
for me.

16 - The "My" classes. For example get the current desktop, simply code

    My.Computer.FileSystem.SpecialFolders.Desktop()

17 - Sub and Function calls all include a () in the call. If you don't put
it there, the IDE will. Non Control-Array property usage is identical to VB
6. Control Arrays aren't supported in VB 2005; there is a runtime mechanism
to emulate them however. I can't say how easy it is to emulate them as I
haven't done it yet.

18 - The IDE is noticably slower than that of VB 6. Part of this is simply
because as a Beta product, there is still a lot of debugging code in the
IDE. However, I have also attempted to use the VB 2002 IDE (.NET 1.0) and
found it to be so slow as to be nearly unusable, so I can't take a guess as
to the final release version speed.

19 - Running a program within the IDE is slower, but the compiled program
ran at about the same speed I would have expected from a compiled VB 6
program.

20 - The compiler generates an intermediate language that can be decompiled.
In VB 6, you have an option to generate "native code", but the VB 6 pCode
option can also be decompiled. The primary difference is that the .NET
intermediate language is documented.

As for why it took twice as long in VB 2005, I had to learn how to use the
IDE, and parts of the .NET runtime classes, especially the StreamReader and
StreamWriter classes - actually they're very similar to the
FileSystemObject's TextStream class. The .NET libraries are huge, but they
also encapsulate the entire windows API, including such auxilaiary APIs as
WinSock, WinINet and CDOSYS (used for SMTP mail). You no longer need the
much maligned (and rightfully so) FileSystemObject to manipulate directories
and network files. I did spend considerable time in the MSDN help reading
how to do the inheritance and how to use the classes I used. This time
would have been spent if I had written this program in another language that
I didn't already know, such as Delphi (I know C++, so that wouldn't have
been a fair comparison.)

I have documented in the recent thread "OOP" in this NG the improvements in
the .NET garbage collector - it's a true mark/sweep/compact GC vs the VB 6
Reference Count/Compact GC. Basically, the VB 6 GC can be fooled by looped
object references. You cannot fool the .NET GC at all, and it handles low
memory situations far better than VB 6.

My recommendation, if you haven't already done so, is to download and
install the VB 2005 Express Beta (it's free, even for non MSDN customers) or
the current VB 2005 Beta (free for MSDN customers) and write some simple
programs in it. VB 2005 coexists with VB 6 on the same system. Just be
aware that when you deinstall the VB 2005 beta, you may lose the
intellisense in VB 6 and have to deinstall/reinstall VB 6 to restore it -
been there, have the t-shirt. Also, the VB 2005 Express Beta expires on
March 31, 2005 and this is documented at the top of the license agreement
dialog at the beginning of the install. I would not attempt to port
existing VB 6 code unless you determine it will require a major rewrite
anyway.

Mike.



Relevant Pages

  • Re: BDS 2006
    ... i can minimize or maximize window but i can't save nor tap any code. ... First chance exceptions are reported before any exception handling. ... WinDbg the IDE hanging. ... personality it is the effect that the IDE hanging. ...
    (borland.public.delphi.non-technical)
  • Re: VB.NET advantages
    ... > StreamReader methods that I needed, without writing a single bit of code ... the IDE would only put in the blocking structures for the Get ... > removed from the window. ... > Property drop downs are more like VB 6, with the exception that you can ...
    (microsoft.public.vb.general.discussion)
  • Re: VB.NET advantages
    ... the compile will assemble it for you - I'm not sure how useful this would ... > That's stuff you'd never notice if you were using 'Single Procedure View' ... VB 2005 IDE is missing the single procedure view. ... >> out of the immediate window. ...
    (microsoft.public.vb.general.discussion)
  • Re: Writeln alternative for GUI applications?
    ... window when running in the IDE. ... Maybe Delphi has an equivalent? ... running the program under the Delphi IDE, the lines show up in the Events ... serial interface application, which had to send strings or characters to ...
    (comp.lang.pascal.delphi.misc)
  • Re: Collapsing Code in VB6
    ... I used to use VB6 in single-procedure mode, but since using the VS.NET IDE I ... Window menu all the time. ... CodeSMART has 'Regions' but they're not collapable. ...
    (microsoft.public.vb.general.discussion)