Thunderclap, the Newsletter of Rolling Thunder Computing
Volume 3, Number 1 Winter 2001
In this issue:
About Thunderclap
Subscription Information
Feature Article: A Simple .NET Framework Example
New Book: Introducing Microsoft
.NET
Blatant Self-Promotion
The Internet Chuckle: OUCH.MPG
Contest with Prizes: Write a Caption For This Picture
Results of Last Contest: Geeky Greeting Cards
This is the ninth issue of my (more or less) quarterly newsletters, the start of my third year. Each will bring you a technical article on current topics in software development, which I hope you will find useful. Each will also bring you a contest, allowing you to show off your intelligence and creativity to win prizes, which I hope you will find funny (although some readers have reported the reverse.) In between you will find my own blatant self promotional material, telling you about the latest ways I've come up with to separate you from your money. (I could have said "carefully selected products and services that we feel might interest you", or other mealy-mouthed horsepuckey. You want the truth or you want me to waste my time and yours dressing it up?)
I'd like to hear what you think about this newsletter and what types of articles you'd like to see in the future. Send your e-mail comments to newsletter@rollthunder.com.
This newsletter may be freely redistributed, provided that it is sent in its entirety. If you enjoyed it, can I ask you to please forward it to a friend who might also enjoy it? The subscription roll has grown to over 3000 for this issue.
Thunderclap is free, and is distributed via e-mail only. We never rent, sell or give away our mailing list. Subscription and unsubscription are handled by a human operator reading e-mail messages. To subscribe or unsubscribe, jump to the Rolling Thunder Web site and fill in the subscription form.
The computer and non-computer press has carried an enormous amount of hype lately, even for this industry, about Microsoft’s forthcoming .NET product. As usual, the marketing blizzard contains essentially no useful information (see, for example, http://www.microsoft.com/business/vision/netvision.asp, about as enlightening as a Bush-Gore debate on toenail fungus in gerbils). Still, the notion that something large and profitable is about to happen has taken root in the developer community, demonstrated by the fact that the developers' conference explaining it drew 5000 attendees to Orlando’s punishing heat last July. The first beta version of the software just shipped. I'm writing Microsoft's lead book on the topic, so I figured I'd use this newsletter to offer a simple introduction to it.
This month's topic is the .NET Framework's object model and the coding that you have to do to implement objects in it. As I've done in previous articles, I've placed the background discussion in my column on Byte.com, and this newsletter contains the more detailed coding discussion. Go read my Byte column, and come back here. I'll wait while you do that.
As I always do when I'm trying to understand something, I've written the simplest example I could think of to demonstrate the operation of the .NET framework. You can download this code sample by clicking here. To run it, you'll need the .NET SDK. The link keeps moving, but you can probably find it by starting here on Microsoft's .NET home page. I wrote a .NET object server, the .NET replacement for an ActiveX DLL in VB 6, and its accompanying client. The server provides a single object exposing a single method called GetTime, which provides the current system time in the form of a string, either with or without the seconds digits. Even though I wrote the server in the Visual Basic language and the client in the C# language, I didn't have to use Visual Studio. In fact, I wrote both applications in Notepad, and built them with the command line tools provided in the .NET SDK.
The code listing for my sample object server follows this paragraph.. It seems, at least superficially, quite similar to classic VB code with which you are already familiar. However, Microsoft made a number of important changes to the .NET version of Visual Basic to enable it to use .NET's CLR classes and interoperate correctly with the other CLR languages. A full discussion of these changes is far beyond the scope of this newsletter, but as an example, arrays now begin with element(0) instead of element(1). If you declare an array with ten members (Dim x(10) as Integer), they are numbered 0-9 instead of the 1-10 that you are used to. The C++ guys and the VB guys arm-wrestled to see whose array syntax would be used consistently throughout the CLR, and the C++ guys won. Sorry. Sort of. You can find a good article on these changes here. These changes mean that you cannot simply compile your existing VB code in Visual Studio.NET and expect it to work correctly. It will take some effort; not an enormous amount, but more than the zero-level you were hoping for. VS.NET contains an upgrade tool that runs automatically when you open a VB6 project. It flags the changes that it detects and suggests fixes. The language has definitely gotten more powerful. If you want the cool Internet features of .NET, you'll probably think it's worth the effort to switch. If you're just writing single-user desktop form apps, you may well think it isn't.
' Import
the external Visual Basic namespace, allowing me to
' access
the Now function by its short name
Imports
Microsoft.VisualBasic
' Declare
the namespace that clients will use to access
' the
classes in this component
Namespace
TimeComponentNS
' Declare
the class(es) that this DLL will provide to a client.
' This
is the same as VB6
Public
Class TimeComponent
' Declare
the function(s) that this class will provide to a client.
' This,
too, is the same as VB6
Public Function
GetTime(ByVal ShowSeconds
As Boolean)
As String
' The
formatting of dates, and the returning of values of functions,
' changed
somewhat in VB.NET
If (ShowSeconds =
True) Then
Return Now.ToLongTimeString
Else
Return Now.ToShortTimeString
End If
End Function
End
Class
End
Namespace
Looking the code, we first see the “Imports” directive. This new feature of VB tells the compiler to “import the namespaces”. The term "namespace" is a fancy way to refer to the description of a set of prefabricated functionality provided by some class somewhere. It is conceptually identical to a reference in your VB 6 project. The names following "Imports" tell the engine which sets of functionality to include the references for. In this case, "Microsoft.VisualBasic" is the one containing the definition of the Visual Basic function "Now" that I use to fetch the time. If you Visual Studio, this namespace is automatically imported for you without your having to write that line. We next see the directive "Namespace TimeComponentNS". This is the declaration of this component's namespace, the name that its clients will use when they want to access this component's functionality. Again, if you are using Visual Studio, this is done automatically. Next come the class and function declarations, identical to VB 6. Finally I put in the internal logic of fetching the time, formatting it into a string, and returning it to the client. These too have changed slightly. The property Now still fetches the date, but formatting it into a string is now done with a method of the Date class rather than a separate function. Also, a VB function specifies its return value using the new keyword Return instead of the previous syntax.
I next compiled my code into a DLL called "timecomponent.dll", using the command line tools that come with the .NET SDK. Anyone who cares can find the command line batch files in the sample code you downloaded. The result may look like a plain old DLL to you, but it's actually very different inside. The VB.NET compiler didn't convert the VB code to native code, that is, to specific instructions for the microprocessor chip inside your PC. Instead, the DLL contains my object server's logic expressed in Microsoft Intermediate Language (MSIL, or IL for short) the intermediate language that I introduced in the "Solution Architecture" section of this chapter, and discuss further in the section on Just-In-Time compilation. All CLR language compilers produce this IL rather than native processor instructions, that's how the CLR can run seamlessly with so many different ones. You can see this using the IL disassembler ILDASM.exe, which came with the .NET SDK. It looks like this:
The DLL also contains the metadata that I that describes the code to the CLR system. This is data in a CLR-required format that describes the contents of the DLL – what classes and methods it contains, what external objects it requires, what version of the code it represents, and so on. It lives in an area of the DLL called the manifest. Think of it as a type library on steroids. The main difference is that a COM server could sometimes run without a type library, whereas a .NET object server can't even begin to think about running without its metadata. I discuss this metadata further in the section on assemblies in my book. The manifest can be seen using ILDASM, which I will leave as an exercise to the student.
Having written my server, I next needed a client to test it. To demonstrate the fact that .NET works between different languages, I wrote this client in C#. I know that not many of you are familiar with this language; nobody is at this point. But if you look at the code shown, you'll see that it's fairly easy to understand at this level of simplicity. In fact, given VB.NET's enhancement's to support CLR's object oriented features such as inheritance, described later in this chapter, I've heard programmers after a few beers describe C# as "VB with semicolons." That can start a fistfight if you say it too loud in the wrong bar in Redmond.
// Import
the namespaces that this program uses, thereby allowing
// us to use the short names of the functions inside them
using
System ;
using
TimeComponentNS ;
class
MainApp
{
// The static
method "Main" is an application's entry point
public static
void Main()
{
// Declare and create a new component of the class
// provided by the VB server we wrote
TimeComponent tc = new TimeComponent ( )
;
// Call the server's GetTime method. Write its
// resulting string to a console window.
Console.Write (tc.GetTime (true)) ;
}
}
Our client example starts with the importing namespaces, which in C# uses the directive "using". Our sample client imports the System namespace described later in this chapter, which contains the description of the Console.Write function, and our time component's namespace. We have to explicitly tell the compiler in which DLL it will find our namespace, which is done in the compiler batch file. Visual Studio provides an easy user interface for this. Execution of any C# program begins in a static method called Main( ). In that method, we can see that our client program uses the C# new operator to tell the CLR runtime engine to find the DLL containing our TimeComponent class and create an instance of it. The next line calls the object's GetTime method, then uses the system's Console.Write method to output the time string in a command line window. The C# compiler in the case produces an EXE file. Like the server DLL, this .EXE does not contain native instructions, but instead contains intermediate language and metadata.
When I run the C# client .EXE, the system loader notes that it is managed code and loads it into the CRT runtime engine. The engine will note that the .EXE contains IL, so it will invoke the "just-in-time" compiler, or JITter. This is a system tool that converts IL into native code for whichever processor and operating system it runs on. Each different architecture will have its own JITter tailored to that particular system, thereby allowing one set of IL code to run on multiple types of systems. The JITter produces native code, which the runtime engine will begin to execute. When the client invokes the new operator to create an object of the TimeComponent class, the runtime engine will again invoke the JITter to compile the component DLLs IL just in time, then make the call and report the results. The output window is shown below:
Pretty boring, isn't it? I told you this was the simplest example. Look at the next to last line for the time.
This runtime compilation model works well for some classes of applications, say, code downloaded from the Internet for a page you just surfed to, but not for others, say, Visual Studio that you use all day every day and update once or twice a year. Therefore, an application can specify that JIT compilation is to be performed once, when the application is installed on a machine, and the native code stored on the system as it is today. I discuss JIT compilation in more detail later in my book.
When the client used the new operator to create the object, how did the loader know where to find the server DLL? In this case, the loader simply looked in the same directory as the client application. This is known as a private assembly, the simplest type of deployment model. A private assembly can't be referenced from outside its own directory. It supports no version checking nor any security checking. It requires no registry entries, as would a COM server. To uninstall it, all you have to do is delete the files, without performing any cleanup. Obviously, this simple case isn't useful in every situation, for example, when you want to share the same server code among multiple clients. I discuss these more complex scenarios in the section on Assemblies later in my book.
That's all for this issue on .NET. If you'd like to learn more, come to one of my public talks, or bring me to your company to talk at you there. Until next time, as Red Green would say, "Spare the duct tape, spoil the job."
New Book: Introducing Microsoft .NET
(Note: The cover art is preliminary, and the title shown on it will be replaced with the correct title shown above)
by David S. Platt, President of Rolling Thunder Computing
From Microsoft Press
ISBN 0-7356-1377-X
(To be published in Q2 2001)
Like an idiot, I've done it again. I'm so busy teaching that I don't have time to sneeze (OK, I manage to squeeze it in occasionally in the midst of other things), so what do I do? I sign up with Microsoft Press to write another book, this one on their new .NET family of technologies, which they promise will be the greatest thing since beer. The book will be similar in content and style to my Understanding COM+, and aimed at the same readership. It is meant to be accessible to managers, while still providing enough information to be useful to programmers, both lightweight VB types and heavyweight C++ types. The book is meant to be non-threatening, using a lot of pictures and diagrams, a small amount of simple VB code, and no C++ at all, which would scare off 80% of the potential readers. I write each chapter in a pyramidal structure, so managers can read the first three sections (Introduction, Problem Background, Solution Architecture). Ambitious managers and VB programmers can continue through the next section (Simplest Example). Heavier-duty developers can read the ends of the chapters, where I discuss more advanced elements of the topic. Here's the table of contents:
1. Introduction, What the Heck is .NET Anyway? |
5. Windows Forms |
2. .NET Framework Objects |
6. ADO.NET Data Access |
3. ASP.NET and Web Forms |
7. Epilogue and Benediction |
4. Web Services |
|
On thing I did do right. Once I found out the title, I quickly snagged the URL for it. The MS Press web address for Understanding COM+ was hideously complicated. But the new one is as simple as can be -- the same as the title, www.introducingmicrosoft.net. Microsoft will be posting a sample there chapter soon, probably the one on ASP.NET. It may or may not be up by the time you read this. But keep checking that URL, and I'll make sure that it gets a link to the sample
I don't know who the heck the woman on the cover is supposed to represent -- just a random Diverse Empowered Workplace Stakeholder or something stupid like that, and the sine waves are supposed to say "science." I think we'd sell more books if she at least wore a bathing suit. It could have been worse; MS Press could have put my ugly face on the book like WROX press does. Give me an O'Reilly Press animal any day.
In-House Training Class on Microsoft.NET
Wonder what all the fuss is about? Want to get a jump-start on the competition? You can have a one- or two-day class on the latest .NET technology, including the .NET framework, Visual Studio, ASP.NET, Web Forms, Web Services, and Windows Forms (or whatever all these things are called by the time you read this) right at your own company. Get things fermenting, look at your upgrade path. I'll bring you the very latest information that you need to plan your upgrade path. Call or e-mail today..
In-House Training Class on XML
You've probably been hearing an enormous amount of hype these days about XML. It sounds like a great idea, and it is indeed a beautiful solution to certain classes of problems. This four- or five-day training class covers the guts of XML, such as well-formed documents, validating documents with DTDs or schemas, programming XML using DOM and SAX, and transforming XML with XSL stylesheets. Most important, we talk about how to use XML in real-life applications: the advantages and drawbacks, the places where it fits well, and the places where you'd be trying to bang a square peg into a round hole. Get your reservation in quickly, because this one looks hot. You can read all about the new XML class on Rolling Thunder Computing's web site, http://www.rollthunder.com.
In-House Training Class on XML for Insurance Standards
This three-to- five-day class covers the same material as ACORD's public class listed below, and with the same instructor, but tailored to your company's exact needs. We can cover only life, or only P&C, or both if you like. We work with the tools and skill set that your developers currently have. We spend at least half a day, up to as much as you like, looking at your specific design and architecture problems. Counting travel, it costs about as much as sending 7 programmers to the public class. So you not only save money and target your own specific needs, you get to sleep in your own bed. Check the syllabus on my web site, www.rollthunder.com, and then give me a call.
In-House Training Class on COM+
This three or four day training class covers all portions of COM+, including that catalog, security, synchronization and threading, transactions, queued components, and events. You can read all about it on Rolling Thunder Computing's web site, http://www.rollthunder.com.
Public Three-Day Class on XML for Insurance, March 12-14 in Dallas, and others to follow
I'll be presenting this 3-day training course is designed to educate the technical person on XML and the ACORD XML standards for both P&C and Life insurance. It gets beyond the hype and teaches programmers what they need to know about this technology standard. Register with gprescott@acord.org. It's rumored there will be another public class in New York around May 2-4, and another one in Boston around June 4-6. Sponsor inquiries for future classes are invited, addressed either to me (dplatt@rollthunder.com) or Tana Sabatino (tsabatino@acord.org)
Public Talks at the ACORD Technology Conference in Orlando, May 20-22
I'll be giving three talks at this conference, at three different levels of geekery. I'll have a non-technical introduction to the XML standards, a more technical talk on the same topic, and a very geeky explanation of Microsoft.NET and how it pertains to the insurance industry. See www.acord.org to register for the conference.
Internet Chuckle: Ouch.mpeg
I was teaching a class at a client, discussing a particularly dry and unfunny piece of memory management, when one of the students burst into hysterical laughter. I don't necessarily discourage laughing in my classes, but generally I like it to happen when I've told a joke. "Do you have something to share with the class?" I asked him. He did. It was the Internet video you can see by clicking on the video below. I won't be giving too much away if I tell you that ABC ought to use this clip for "the agony of defeat" in its Wide World of Sports intro instead of that klutzy ski jumper (Japanese, competing in the 1968 Olympics in Grenoble, France, in case you care). I don't know where it came from or anything else about it, although I can deduce from the mostly empty seats in the background that this wasn't the Olympic finals or anything like that. I'm sure you'll agree when you view it.
Disclaimer: This section will often refer to commercial vendors of products or services. Rolling Thunder Computing receives no benefit from these vendors in any way, shape, form, or manner; and would decline any if offered. The sole criterion for mention in this section is that I laughed at it, and that I think people as sick as I am would do so as well. If you know a good one, send me the URL at chuckle@rollthunder.com. If I use it, I'll send you a Rolling Thunder Computing coffee mug, which makes an excellent specimen container when your company implements mandatory drug testing.
Contest with Prizes: Picture Caption Contest
Lord, send a man like Robbie Burns to sing the Song o' Steam!
-- Rudyard Kipling, "McAndrew's Hymn", 1894
I'd settle for Dr Seuss, except he's dead.
-- David S. Platt, "Plattski's Rantings", 2000
"What the heck do you mean, Rolling Thunder keeps my frequent flyer miles?"
Here's Annabelle's first airplane ride, with me and Mommy on the way to a gig in Redmond. She's a better traveler than I am. She sleeps better, she screams less, and she's easier to feed. She's obviously telling me something, but I have trouble figuring out what it could be. Your assignment is to write a caption for this picture divulging Annabelle's thoughts, such as the example above.
As always, your entries must be computer-related, or at least business-related, and original. This isn't a family newsletter, so they don't have to be clean or politically correct. Submitting more than one increases your chances of winning. First prize is $100, second prize $50. Winners will be announced in the next issue of Thunderclap, and the judge's decision (mine) is final. In the event of duplicate or similar entries, the earliest wins. All entries become property of Rolling Thunder Computing. All authors will be identified by first and last names, but not by company. Authors names will be withheld if you so request. Submit your entries via e-mail to contest@rollthunder.com.
Results of Last Contest: Geek Greeting Cards
First prize, $100 to Barry Doyle.
(Front) I was very sorry to hear about your loss.
(Inside) Who would have thought the new company firewall would block all your porn
sites...
Second Prize, $50 to Mark Messer
(cover) "Happy 30th Birthday!" at the bottom.
(inside) That's 0x1E in geek years!
And honorable mention to all:
(cover) "Sorry to hear your .com went under."
(inside) "Mind if I scout your web developers?"
(cover) picture of Seagate dog, teeth bared, with bone
(inside) "Runtime license? I ain't got to show you no stinkin' runtime license!"
-- Phil MacArthur
(Front) Wow! You knew those 70 hour weeks and no vacations
would lead to big changes!
(Inside) Sorry to hear about your divorce.
(Front) This is your "Happy Birthday" e-mail.
(Inside) If you would like to unsubscribe to this birthday, send an e-mail with
the subject "UNSUBSCRIBE" to already_too_old@over_the_hill.com and your birthday
will be removed from our records.
(Front) Congratulations on graduating from the Jewish Institute
of Technology!
(Inside) Could you please remove the propeller from your yarmulke?
(Front) I was very sorry to hear about your loss.
(Inside) Who would have thought the new company firewall would block all your porn
sites...
Two sided card:
(Front) Sorry to hear about your infinite loop problem. Turn card over.
(Back) Sorry to hear about your infinite loop problem. Turn card over.
-- Barry Doyle
(cover) Picture of a glum-looking man with
party hat and shirt pocket protector in front of a big birthday cake. "Over the
Hill" at the bottom.
(inside) Happy 32nd Birthday!
This card should be in the blank cards section of Hallmarks.
(cover) Some generic, inspiring, overly sentimental photo -
puppies and flowers or some such.
(inside) "This page intentionally left blank."
(cover) Picture of a big Thanksgiving feast. At the bottom:
"Happy Turkey Day"
(inside) "I am sure that it was chosen as the due date for
your project only by coincidence."
-- Mark Messer
(cover) A picture of some locker-room showers
(inside) SOAP: You don't dare drop it.
(cover) In a singles bar, a picture from the back of a man
tapping the shoulder of a woman with long blonde hair
(inside) Frontal shot, the "woman" is actually a really ugly man. Caption reads:
"TYPE MISMATCH!"
Or a card for network administrators: "The E-Mail of the species is more deadly than the mail"
-- Duncan Millard
(cover) Merry Christmas! Enclosed are your new multi-colored pants...
(inside) in GREEN and RED to match your pocket protector!
-- Marian Elam
Legal Notices
Thunderclap does not accept advertising; nor do we sell, rent, or give away our subscriber list. We will make every effort to keep the names of subscribers private; however, if served with a court order, we will sing like a whole flock of canaries. If this bothers you, don't subscribe.
Source code and binaries supplied via this newsletter are provided "as-is", with no warranty of functionality, reliability or suitability for any purpose.
This newsletter is Copyright © 2001 by Rolling Thunder Computing, Inc., Ipswich MA. It may be freely redistributed provided that it is redistributed in its entirety, and that absolutely no changes are made in any way, including the removal of these legal notices.
Thunderclap is a registered trademark ® of Rolling Thunder Computing, Inc., Ipswich MA. All other trademarks are owned by their respective companies.