Wow, day 4 is done already. Three more subscribers join us today. The band (Felix and the Buzzcats) are gone, but the food is getting better. Yesterday they had Twinkies on the snack table when Russ and I walked by, so I grabbed a couple. After a few steps I realized I better tell Russ that both of them were for me and if he wanted one he oughtta go back and grab one. Lots of sessions today, a couple of them were very good, a couple less so. Let's get right to it.

Introductions to the Managed Extensions To C++

Managed Extensions to C++ are the way you take advantage of .NET and the CLR in Visual C++. This session spelled out how this all works. The session started off with, whadyaknow, a slide listing all the features of the Common Language Specification. I'm starting to hear these features listed in my sleep. If you don't know what they are, go back and review the previous newsletters.

The pre-requisite 10 minutes of marketing out of the way, we got down to business. The whole thing hinges on extensions they have made to the language, notably 14 keywords (all beginning with __), 1 new compile option and 1 new string literal prefix. Doesn't sound like much, but they are going to rock your world. The big one is __gc. You use this when you define a type and it applies to all instances of that type. Once you have sold your soul to the __gc operator to get the garbage collection, you give up a few things-

  • Multiple Inheritance
  • Incrementing pointers
  • The ability to move back and forth between managed objects and pointers and unmanaged objects and pointers.

Starts to look like the restrictions in C#, doesn't it? There were a lot of esoteric rules about casting that flew by kind of fast as well.

Once you include the .NET header file, all the .NET constructs are available to you. In fact, once you start using them, the C++ness of your program kind of goes away. For instance, here is the Hello, World program they wrote for us-

#using <mscorlib.dll>
using namespace System::Console
void main()
{
    // defined in mscorlib.dll
    WriteLine(L"Hello, World");
}

Gosh, this looks very much like the Hello, World program from C#. Note that printf and the stream operators were ignored to use the CLR based WriteLine function.

There was no reference to the STL and how it coexists with all this stuff. Since the CLR provides a lot of this functionality, I think they prefer you stay away from it and use the CLR constructs. A question was asked about STL afterward and they confirmed that templates cannot be managed.

If you need to access unmanaged code that takes a pointer to an object, you can do this with the __pin command. This command will prevent .NET from moving managed pointer around in memory while the pin is in place. For instance-

#using <mscorlib.dll>
__gc struct G { int i; }
// foo from existing, unmanaged DLL
extern void foo( int * );
void main()
{
    G *pG = new G;
    foo( &pG->i ); // error
    G __pin *ppG = pG;
    foo ( &ppG->i ); // ok
    // but foo must not hold onto &i
}

Performance

OK, here's what we've been waiting for. How does the managed code compare in performance to the Native code. To give proper credit, they spent several minutes talking about how the CLR was still being optimized and these numbers should improve before release. They ran about 9 different benchmark tests and displayed the results on the screen - turns out they weren't in the presentation stored on the web, so I cannot quote them verbatim. I did do a little statistical analysis on them as they were going by in the actual session. Of the 9 tests, the affect on performance (positive is good) when moving to managed code ranged from +4% to -37% with an average of -9%. If you throw out the highest and lowest, the average rose to -6%. Not too bad, depending on what your code does.

Visual Studio .NET Automation, Macros, Add-ins and Wizards

I thought this session would be kind of light and fun in the middle of the day when Russ and I went in. Unfortunately it was pretty light on content and not a lot of fun. We left about halfway through. I did learn one or two things about macros in the new IDE before I left. I don't remember if I explicitly stated this before, but all languages use the same IDE in VS .NET, so this information applies to every language.

Macros have not been completely overhauled, but they have been heavily tweaked:

  • If you have a debugging scenario where you have to perform several steps to get the situation you need to be in to observe a certain behavior, you can record a macro to take care of this.
  • While you are recording a macro you can hit pause if you need to perform an operation that you don't want to be part of the macro.
  • All macros are shown in a new Macro explorer.
  • IDE events are exposed, so you can perform activities by hooking up to them
  • Formerly, macros where 'undone' one keyboard function at a time. Now you can wrap them in a couple of lines so that the whole macro (or any part you want) 'undoes' with one step. They call this Atomic Undo.

That's about it. We headed over to George Sheppard's talk on ASP+ Server Side controls, but his half of the presentation was already done, so we just got some ice cream - that part was fun.

Object Oriented Programming in VB .NET

VB developers, before you read this go grab yourself a bag of munchies and a beer because we're gonna have a party. This was the best layout of everything new in VB that we've seen so far and it is really something. The guy encouraged the audience to show what it liked with applause so that he would know what should be protected if shipping dates threatened features. I thought the crowd was gonna start doing the wave every now and then. OK, let's get started.

What they wanted to do with VB .NET was fourfold-

  • Modernize
  • Simplify
  • Reduce Programming Errors
  • Provide Full access to the .NET Framework
Modernize-

VB is now a fully Object Oriented language. It supports implementation inheritance, encapsulation and polymorphism. Let's talk a minute about each.

Inheritance is limited to a Single base class (hmmm...just like C# and Managed C++...sensing a pattern?). One key OO concept this allows is polymorphism. Polymorphism is the ability of an object to decide on its own what it is going to do in response to certain direction. For instance, you create an Animal class with a method named Talk. Then you create a Dog class and Cat class both from the Animal class. You override the Talk method of Dog to go "Bark" and the Talk method of the Cat to go "Meow." You then create a bunch of Cats and Dogs, put them in an array of Animal objects (you're allowed to do that since they are inherited from Animal) and ask each one to Talk. The object then decides right then if it is a Dog or a Cat and barks or meows appropriately. This is polymorphism and VB didn't have it until now...well, won't have had it until then...whatever. The other inheritance feature is the addition of the 'Protected' decorator to the current Public and Private. Whereas Public items are available inside and outside the class and Private only inside the class, Protected items are available inside the class and inside any class derived from the class.

Encapsulation is the hiding of internal workings to the outside world (it's none of your business how I provide this functionality, so step off!). There are two new encapsulation features.

First are shared members (C++ developers, these are static class members, feel free to skip ahead.) Shared members are values that are shared between all instances of the class, but available only within the class. For instance, you may want to know at any given time, how many objects of a certain class exist. You could do this by incrementing the shared member when the instance is created (this is a constructor, you have them now), then decrementing it when the class is destroyed (this is a destructor, I don't know if you have these, but I think you do). So, app starts, shared member is 0. First instance is created, shared member is now 1. Second instance is created, shared member is now 2. First instance is destroyed, shared member is now 1. Second member...aw, heck, you get the idea.

The other new encapsulation feature is nested classes. Suppose you implement a collection of some object as a linked list of nodes. You would define a list class that clients would use and you would create a node class for you to use inside the list class. Since it is nobody's business how you do your list, you would define the node class within the list class, probably private, so nobody could see it and it would be your dirty little secret.

That's it for the strict OO features, now we're just going to talk about some cool stuff. On Error Goto label is dead, kaput, finis! OK, it is still available, but you should never use it again. VB now supports try/catch exception handling, just like C++, Java and C#. Simply stated, when an error occurs, an object called an exception is created and (this is kind of tricky) thrown. Thrown means that control flow leaves the current location and looks for some piece of code that says, "Hey, I know what to do with you." Since the exception was thrown, this piece of code is called a catch. The throw starts out by looking through the rest of the current routine, then raising up to the calling routine, and so on and so on. If it never finds a catch statement, it is called an "Unhandled Exception." These are very bad, never let this happen. Here's a quick code snippet, maybe it will help (this is not official VB .NET

try
Dim i as integer
Dim o as new SomeObject
for i = 1 to 10

    // assume o only holds 9 values, then
    // the final loop will cause
    // an error and "throw an exception"
    o.Values[i] = i

next i
catch Exception
    MessageBox "Too much stuff crammed into SomeObject"
end catch

Besides try and catch, the keywords of interest are throw and finally. Throw allows you to throw your own exceptions and finally (listen up here C++ heads) defines a block of code that is executed every time, regardless of whether an exception was thrown or not. This is where you put clean up code that otherwise would have to go outside the Try/Catch block. C++ doesn't have this and it sure would be nice.

Simplify
  • They eliminated default properties. This will break some existing code, but prevents confusion about what an assignment does.
  • All assignments are the same - no more Set and Let
  • All procedure and function calls must always use parenthesis. Once again, breaks existing code, but for the greater good
  • Dim X, Y as Integer now works like you would expect, 2 integers
  • The new operator now works the same for all objects. The bug caused by new'ing an MTS object that was from your own library can no longer be created.
  • The 'and' and 'or' operators are short-circuited. This means that once one condition of a complex condition statement fails, processing stops (formerly the whole line got checked all the time). This allows code like-

if ((obj is not nothing) and (obj.Count > 3)) then
    DoSomething()
end if

This would have caused an error in previous versions when obj actually was nothing.

Lotta stuff, huh? I'm just getting warmed up!

Overloaded methods are now supported. Overloaded methods are multiple methods with the same name but different arguments. For instance, you may have a collection that you wrote where it makes sense to retrieve values based on index number or name. You can write 2 GetItem routines, one with a string for the argument and the other with an integer for an argument. The compiler will know which one to call based on what you pass as an argument.

Events are now based on the .NET structure, using delegates just as we discussed yesterday in the C# talk.

Multi-threaded applications are now supported. You create a thread object, associate it with the proper code, set any parameters and call Start. Boom, a second thread is running. Synchronization objects are provided to coordinate between threads.

Finally, they showed some demos to demonstrate the faster performance.

  VB6 VB.NET
Create 10,000 objects 2.2 secs .57 secs
Assign 10,000,000 values 2.3 secs .062 secs
Create and sort 10,000 objects .4 secs .016 secs

Wow!

Getting the Most Out of the .NET Platform: .NET Framework Practices and Patterns

(This session went over naming conventions, etc for .NET apps. It will take you 15 minutes to read the whole PPT file off the web when this stuff is finally in production 6 months from now, so I won't bore you with it here. I only bored myself with it for about 20 minute before Russ and I left.)

ASP+

Another first for the newsletter. Today we have a guest columnist, Allen Broadman, who attended the ASP+ Server Controls session and has contributed the following report. C'mon, put your hands together and give it up for...Allen Broadman!

"ASP+ is an evolutionary step forward from ASP. The same basic model exists, but new capabilities will allow a reduction in the total amount of source code and also a better separation of HTML from logic. Everything mentioned in this document will work on any browser and represents only server side technology.

ASP+ Highlights
  • pages use a .ASPX extension
  • will work side by side with ASP using IIS 5 with Windows 2000
  • pages are compiled to native code
  • supports full language implementations, not just scripts (full VB and C#, for example)
  • supports server-side only comments which are not visible in the HTML sent to the client
  • ASP+ is backwards compatible with ASP
  • Server-Side Controls
  • Pagelets
  • Client-side persistence of form control values between HTTP POST calls
Server-Side Controls

Server-Side Controls can be used to encapsulate standard HTML features. For example, to create a table containing dynamic data in normal ASP you would interlace HTML and script code together. This type of code is hard to read, hard to maintain, mixes rendering formats with data access, etc.

In ASP+, you can use a Server-Side table control to accomplish the same thing MUCH more easily. Look at the following ASP+ code and then look at the HTML it generates:

// ASP+ code
<asp:datagrid id=myDataGrid HeaderStyle-BackColor="skyblue"
runat="server" />
Function GetSampleData As DataView
Dim ds As DataSet
Dim MyConnection As SQLConnection
Dim MyCommand As SQLDataSetCommand
MyConnection = New SQLConnection("server=localhost;database=pubs")
MyCommand = New SQLDataSetCommand ("select title from Titles", MyConnection)
ds = new DataSet()
MyCommand.FillDataSet(ds, "Titles")
GetSampleData = ds.Tables("Titles").DefaultView

End Function
Sub Page_Load(s As Object, e As EventArgs)

myDataGrid.DataSource = GetSampleData()
myDataGrid.DataBind

End Sub

which generates-

<!--! Generated HTML -->
<table>
<tr><td>The Psychology of Computer Programming</td></tr>
<tr><td>Software Project Survival Guide</td></tr>
 
<!-- ...lot's of code omitted here for sanity -->
 
</table>

You can also bind multiple columns that you specify. The binding mechanism is one-way, from server to client. This is NOT a technology for providing client editing of SQL-based data. Over 45 controls will come out of the box with ASP+.

[ed note - those of you familiar with the HTML Table control that Tom Abraham wrote for Nasdaq-Online, this functionality is very similar. Sorry to interrupt, Allen, please continue]

Pagelets

A Pagelet is a subset of a page that can be "included" into another page and therefore can be shared among multiple pages. Unlike an ordinary include mechanism, Pagelets have their own namespace and scope which is separate from the page that includes them, so there is no naming conflict between controls and code in the Pagelet and the other page. Great for reuse."

 

Thanks, Allen. One additional note on server side controls - they automatically sense the browser and adjust the creation of the HTML output accordingly. Pretty cool.

One more thing on ASP+ - one of our newest Plurites, George Sheppard, gave a talk on the Server Side controls his previous company, Stingray, has already written. If you have questions on this technology, he is probably a good source of information.

 

Letters, We Get Letters

AB from New York writes-

“…I really enjoy this newsletter (I just can't explain why).”

 

Dear AB,
It’s probably because of the hidden messages I stuck throughout the document in white font. -Ed

____________________

PK from Washington writes-

“What do you have against COBOL? Cockroach of languages?”

and

“With the Common Runtime Language my prediction of the "Microsoft Language" comes closer to fruition. 1 line Basic, next line C, next COBOL, .etc. it is all good.”

Dear PK,
By cockroach of languages, I was not so much being derogatory as I was referring to the oft-quoted factoid that cockroaches will survive a nuclear holocaust.

As for the “Microsoft Language,” this concept has been discussed greatly amongst the Pluralites here at the conference. Each new session reveals another similarity introduced between the big three. Between the OO extensions and performance improvements to VB and the way .NET cripples C++ both functionally and performance-wise, things are definitely moving toward the center. -Ed

That’s it for today,

Biff Gaut
Assistant Editor and Office Supply Monitor, Biff’s PDC Newsletter