Sam Gentile's Radio Weblog : Partying with .NET

 

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.

 
 

It's The Runtime Stupid

Just got off the phone with my friend Peter Drayton who"encouraged" me to post more of my original content that I have been holding back. I have been holding back this particular one, because I wanted my radio to stay completly technical and not offer any rants or such things. I have been accused of a rant or two in my past-) This one has some tindings of a rant but can no longer be sat on. It just bothers me constantly. It is not meant to attack anyone but to strongly push them in a new direction-)))

I have spent a lot of time on the site C# Corner Forums . Disclaimer: This is not meant to single out the fine folks at C# Corner and their hard work. This problem is epidemic to most places that discuss .NET.I have answered over 600 queries. However about a week or two ago, I stopped (I can't do it anymore) after 4 of the same question in one week (there's this annoying tendency not to search even the screen in front of them), and the question is invariably some permutation of "If I write this .NET application, do I need to install the .NET Framework Runtime on each machine?" Now, invariably I would tend to call this question "stupid" and my first tendency would be to take the person's VS.NET and C# away from them for a year in punishment-)) but I realized that people just don't get it and they need to get it. By it, I mean the fact that a managed application needs to be managed by something!

This should be an obvious fact to everyone but isn't so somewhere something's breaking down. Is is the fact that I think C# is the VB of 2002? Remember, you heard it here first. We now have a whole lot of people, like the VB days, that have no idea what they're doing. Before you start flaming away, think for a minute. How is it that you are coding in C# and have no idea what the CLR is and how it works, the BCL and such? Do you just write syntax in a language and have no idea of the environment in which it needs to run? And there's the issue and problem.

.NET is certainly not the first language to have a runtime. Those of us who have been around long enough know of the runtimes of LISP, Smalltalk and then UCSD Pascal (No for the 10,000th time Java did not invent them). We understand them and we understand Garbage Collection. I also spent three years as a Java programmer, so I grok them. The problem is that most Windows programmers and particularly the new bunch coming in through the "C# Media Wave" and to some extent, VB.NET *don't*. What's even worse is that they either don't want to or aren't being told.

This is not Windows. This is not COM. To program in .NET is a whole new ballgame folks. Throw out everything you knew in MFC, COM, etc. If you want to program in .NET, you must learn and understand how .NET works. That means understanding the basics of the Common Language Runtime, Garbage Collection, Finalization, the Dispose Pattern, the BCL and what Managed code is. You can't wing it anymore. To ask if you have to install the runtime where you run is like asking "Do I have to plug in the computer to make it run?" Managed code is managed. Managed by what? Managed by the CLR! You need one to run .NET code, ok? A runtime means just that. A runtime is needed at runtime to for programs to function.

So, lets review shall we? In .NET, compilers do not natively emit X86 code or whatever platform specific code. All .NET compilers emit an abstract, intermediate form, independent of the original programming language, target machine and operating system. This has two parts: Metadata and managed code. Metadata is simply data about data. Simple huh? Its job is to structurally describe the items that make up an application i.e. data types. Managed code is the stuff that does the work, encoded in an abstract binary form known as Microsoft Intermediate Language (MSIL) or Common Intermediate Language (CIL). Now why do we think it is called managed? If you said because it is code managed by the runtime, you're with me. So what does this mean? This means that code written to target this runtime, the CLR gains a lot of services. So when Joel rants yet again that "that 20 MB runtime is a real showstopper", he may want to consider what he and you are getting for all that and how much faster development goes because of it. Because the CLR provides neat things like garbage collection, type control, security and exception handling. Garbage collection is huge. For the most part, most programmers can just forget about memory management. The ability to have a robust cross-language Common Type System (CTS) is huge. One could write a whole book about the CLR. Trust me, you get a lot.

Now, here's the drill. Forget about learning C#. Forget about learning VB.NET. Learn about the CLR and the BCL FIRST. That's the real .NET. The languages are just synatatic sugar. If you want 60% more verbosity, choose VB.NET. If you want the current media darling, choose C#. And if you're a real man (or woman) choose Managed C++-)). Only kidding. C# is a  fine langauge. But for gosh sakes, its not whats important. As John Lam in his excellent BLOG on this topic: "Here's some C# resources. The reason why this is a brief list is that I honestly don't read C# books either. There's not enough complexity in this language to warrant reading a book on the language itself. All of your questions can be answered by judicious reading of the C# language spec." Its not that complex a language. Its the System Libraries (the BCL) and the CLR that are important. Learn them, learn how and why .NET is doing the things its doing. Then you won't have to ask those kind of questions and you will really understand what's going on.


 



© Copyright 2002 Sam Gentile.
Last update: 7/1/2002; 9:38:45 PM.

Click here to visit the Radio UserLand website.