Thursday, January 15, 2009

[.NET] Stepping to .NET

Who should read this ?
This is a write up targeted for the .NET beginners to understand the basic concepts of .NET to start with. This article contains the information I earned from my little experience in .NET, MSDN and some other books/sites.
.NET What is it ?
The Microsoft .NET Framework is a software technology that includes a large library of pre-coded solutions to common programming problems and a virtual machine that manages the execution of programs written specifically for the framework. We can divide Microsoft .NET to two,
>> Runtime environment to execute .NET application developed by any .NET complaint compiler.
>> SDK( Software Development Kit ) to develop .NET applications.
Why .NET ?
You may wonder why the .NET influenced our world with a much greater pace than any other programming technology/environment after C. Consider some of the existing programming languages and their disadvantages which made Microsoft thinking of .NET world.
>> C/Win32 API Programmer's life is a complex undertaking; Building application using the raw API is a difficult task because C developers are forced to do manual memory management, pointer arithmetic, bad looking syntactical constructs. After all it is not an Object oriented language.
>> Coming to C++/MFC programming it is upgraded to an object oriented programming language but it still has the manual memory management, complex syntatical constructs & pointer arithmetic.
>> Visual Basic 6 was designed to make life easy also it hides the complexity of raw Win32 API but VB6 is not a fully object oriented eventhough it is object aware making it less powerful.
>> Java/J2EE programming have the advantage of running platform independent with Java Virtual Machine. Eventhough it have many advantages the disadvantage is that cross language integration is not possible with Java.
>> Microsoft's COM made it possible to reuse binary code but it is not fully language independent for example deriving a class from existing COM class is not possible. Also COM will force to register and numerous deployment issues may be waiting for the developer.
Above disadvantages are solved with Microsoft.NET. Microsoft's initiative is an approach to make the programmer's life easier. The .NET Framework provides the following advantages (quoting MS):
1. A consistent, object-oriented programming environment.
2. A code-execution environment that: Promotes safe execution of code, Eliminates the performance problems of scripted or interpreted environments, Minimizes software deployment and versioning conflicts.
3. A consistent experience for both developers and users across various types of Windows-based and Web-based applications on multiple devices.
4. Communication built on the industry standards to ensure that code based on the .NET Framework can integrate with any other code.
Also .NET is based on open Internet standards, which include Hypertext Transfer Protocol (HTTP), Extensible Markup Language (XML), and Simple Object Access Protocol (SOAP).
Basic building blocks of .NET
Following are the basic building blocks which makes up .NET.
CLR(Common Language Runtime)
The Common Language Runtime (CLR) is the virtual machine component of the .NET framework. The core of the .NET Framework is the CLR; it manages code at execution time and provides core services such as memory management, thread management, remoting, and strict type safety enforcement. Code that targets the CLR is known as managed code, whereas code that does not target the CLR is known as unmanaged code. The most important part of the CLR is physically represented by a library named mscoree.dll (Common Object Runtime Execution Engine).
.NET Framework Base Class Library
The Microsoft .NET base class library is an object-oriented class library providing an integrated set of classes that expose the underlying functionality of the Win32 API as well as some other additional capabilities. These classes integrate tightly with the CLR. In Microsoft .NET library, all class (types) are grouped in namespaces (grouping of similar classes). Although the entire base class library has been broken into a number of discrete assemblies, the key assembly is mscorlib.dll.
CTS(Common Type System)
CTS is a formal specification that documents how data types must be defined in order to be hosted by the CLR. Only persons who are deeply concerned with the inner workings of the CTS are those building tools and/or compilers that target the .NET platform. The common type system supports two general categories of types,
Value types:
Value types directly contain their data, and instances of value types are either allocated on the stack or allocated inline in a structure. Value types can be built-in (implemented by the runtime), user-defined, or enumerations.
Reference types:
Reference types store a reference to the value's memory address, and are allocated on the heap. Reference types can be self-describing types, pointer types, or interface types.
CLS(Common Language System)
The CLS is a set of rules that describe in vivid detail the minimal and complete set of features a given .NET-aware compiler must support to produce code that can be hosted by the CLR, while at the same time be accessed in a uniform manner by all languages that target the .NET platform. The CLS is ultimately a set of rules that compiler builders must conform to, if they intend their products to function seamlessly within the .NET universe.
A word about Visual Studio 2008
Microsoft started development on the .NET Framework in the late 1990s originally under the name of Next Generation Windows Services (NGWS). By late 2000 the first beta versions of .NET 1.0 were released and latest (at the time this is wrote) .NET Framework available is major version 3.5 (released on Nov 2007). When .NET Framework 3.5 was released Microsoft Visual Studio 2008 from Microsoft was released alongside .NET Framework 3.5 and it is the latest released development environment.
Below figure shows the overall architecture of the .NET Framework components,

CLR in Action !
Regardless of which .NET language you choose to program with, understand the fact that .NET binaries take the file extension *.dll or *.exe. When a *.dll or a *.exe has been created using a .NET-aware compiler, the resulting module is bundled into an assembly. .NET assemblies do not contain platform specific instructions, but platform independent Common intermediate language (CIL) and type metadata. Due to the fact that assemblies contain CIL instructions, rather than platform-specific instructions, CIL code must be compiled to platform specific instructions. One which compiles CIL code into CPU instructions is called as just-in-time (JIT) compiler (called as Jitter). Below figure illustrates the workflow that takes place between source code (which is made using base class library), specific .NET compiler for your source code, and the .NET execution engine.


No comments: