What you need to know about the .NET Framework Jeffrey Richter specializes in programming/designing for .NET and Win32 and is an expert on Metadata. As a preview of his VCDC session "Metadata and Building Applications" read his VSLive! speaker interview below!
Can you give a brief overview of the .NET Framework?
I know a lot of developers that want to learn C#, Visual Basic .NET, or some other language; however, a programming language should not be the focus of a developer's attention. Programmers should learn how the CLR works and should learn the types contained in the FCL. This is where the learning curve is. Programming languages are just about the syntax required for a programmer to express their intentions. A programming language is about semicolons and braces. This kind of stuff is easy to learn and pick up. The CLR and the FCL is the heat of the .NET Framework and a solid understanding of these 2 technologies will help developers go far regardless of the programming language they use.
What are some of the more important features offered by the .NET Framework's CLR?
Second, the CLR also offers Code Access Security which allows for fine-granularity of protection. For example it's possible to write access to a specific disk subdirectory while allowing unrestricted read access. Third, the CLR proves rich threading capabilities to all applications written in any programming language allowing developers to write high-performance, scalable applications. Fourth, the CLR imposes a garbage collection environment on all languages. Via garbage collection, an application cannot corrupt memory and the responsibility for knowing when to free an object is the job of the garbage collection. This frees developers from having to worry about memory management and allows them to focus on their applications logic. Fifth, the CLR uses exception handing throughout. Exception handling allows developers to separate their method's cleanup and error recovery code from the method's main logic. This makes it easier to write, read, and maintain code. In addition, the developer cannot simply ignore an error returned by a method allowing the application to continue to run unpredictably. The developer must catch the exception and recover from the problem. These are just some of the highlights offered by the CLR; there are many more features available. What is the role of Metadata in the .NET Framework?
Metadata is used to enable lots of technologies. For example, the FCL's serialization engines use metadata to know how to serialize a type's fields into a binary or XML stream. Visual Studio's IntelliSense uses metadata to offer the developer suggestions when editing their code. The garbage collector uses metadata to know when fields within an object refer to other objects so that the GC can know what objects can and can't have their memory reclaimed. Metadata also allows compilers to reference types defined in another programming language without any auxiliary information such as header files. And certainly, ASP.NET XML Web services use metadata to determine how to how to expose a type's method as a web service method with little effort by the programmer. ASP.NET also uses the metadata to automatically construct the Web Service Description Language (WSDL) for a web service's methods. What are custom attributes and what role do they play?
Let's look at an example. Microsoft's ASP.NET team has created a WebMethod attribute. When this method is applied to a method, ASP.NET knows to make the method "publicly accessible via the Internet". Custom attributes are a pretty innovating thing. Microsoft's FCL defines several custom attributes for various purposes such as security, interoperating with unmanaged code, working with XML, and so on. All .NET Framework developers should become very familiar with custom attributes since Microsoft uses them quite frequently. But, don't' forget, any developer can define their own custom attributes and use them as they see fit this is a very powerful technology indeed. How concerned should developers be with the .NET Framework's Performance?
Also, if the CLR sees that the machine is a single processor machine, it can remove any code that is only necessary for multi-processor machines. Likewise, if the CLR sees that a certain 'if' statement will never be true on the host machine, the CLR can remove the 'if' test and its code entirely when compiling to CPU instructions. Also, the CLR ensures that a type's fields are aligned correctly on proper byte boundaries which can improve performance enormously on some CPU architecture. Theoretically, the CLR could analyze a method's code path at execution time and could re-arrange or recompile the code as the application runs fine tuning the code for the way the application is actually running. For example, if the CLR sees that a test is always false, it could rearrange the code to improve branch predictions. Jeffrey Richter |