Introduction to .NETThe .NET framework has been plugged by Microsoft as a new programming model for the Internet age. Personally I prefer to think of it as a new programming model for almost everything that is Windows related.
Seriously, if you are working doing Windows programming, then I believe .NET is going to be well worth learning for future projects, simply because it will make programming so much easier.
So what is .NET?There are lots of ways to think about .NET, but here's the way I prefer:
Over the last 10 years or so, Microsoft have gradually been improving the Windows platform, and the associated APIs and developer tools. So we've seen for example the emergence of COM, then DCOM, then COM+ to enable reuse of software. For Data Access, we had first ODBC, then OLE DB and ADO in various versions. For dynamic web sites we had different versions of ASP. And for programming there were a variety of languages, C++, VB, scripting languages etc.
One problem with this is that as the tools and languages have got more sophisticated they have also got more complex, due to the need to support earlier tools or versions of the tools. So for example, these days, COM is an extremely powerful way to package up code for reuse, but if you want to use COM effectively the learning curve is frightening. I've routinely heard people talk about 6 months as the minimum time for an experienced developer to learn COM. And if you want to master DCOM or COM+, you've got to learn COM first! Add to this the fact that many people have (rightly in my view) complained that many of these APIs and tools are in some ways badly designed, and you can see why Microsoft has had such a poor reputation amongst many developers up until now.
.NET appears to be a serious attempt to change all that. Rather than just updating the existing tools and languages (and so making them even more complex), Microsoft have started from the ground up again, and developed a completely new framework, within which most programming tasks can be easily accomplished. (And they haven't destroyed backwards compatibility. Your old code will work fine, it's just that new code can be written more easily). Not only that, but .NET has had a very favourable reaction on newsgroups - there seems to be a general consensus that .NET is well designed, and Microsoft are seriously listening to the needs of developers as far as .NET is concerned.
What does .NET give you?Quite a lot is the answer. Here's the main points:
- Most things that you might want to do on Windows, including data access, windowing, connecting to the Internet, and much of the functionality of the Win32 API is now accessible through a very simple object model.
- The VB language has been hugely upgraded, so it now includes classes and most of the features previously accessible in C++.
- A new language, C#, has been introduced, which combines the efficiency of C++ with some of the ease of development of VB.
- Memory management for .NET applications is much more sophisticated, meaning that a badly behaved .NET component is extremely unlikely to crash other components running in the same process.
- ASP.NET, the replacement for ASP, offers compiled web pages (making processing of web requests much more efficient) and includes a large number of pre-written components that can generate commonly used HTML form and user-interface items for you (the so-called server controls.
- The main programming languages have been moved far closer together, so code written in VB, C++ and C# can be intermixed: For example you can write a class in VB, derive a class in C# (or C++), and freely step between the languages in the debugger.
- Components are wrapped up in a new unit called an assembly, which is highly self-describing, making installation and use of components very easy.
How does .NET work?The most significant aspect of the .NET architecture is that code in VB, and C# is compiled not to native executable code, but to an Intermediate Language (IL), with the final step of converting to native executable normally happening at runtime. Such code is termed managed code C++ code can optionally be marked as managed code, in which case it gets compiled to IL too. This makes your C++ code interoperable with VB and C# and allows you to take advantage of all the .NET features, but does restrict you to not using some features of C++ (such as multiple inheritance) that are not supported on .NET.
The principle of IL clearly owes something to the ideas of Java, which was also compiled in two stages. (And the resemblence between C# and Java is very strong). However, with Java the emphasis is on cross-platform independence, while .NET is geared to Windows, and has an emphasis on cross-language (rather than cross-platform) independence. Having said that, Microsoft have left open the possibility of .NET being developed on other platforms. Microsoft also appear to be convinced that the existence of IL won't substantially hurt performance of applications, and may even improve it (because at the final stage of compilation, the compiler knows what processor is going to run the code, and so can take advantage of hardware features specific to that processor - this is not the case with direct compilation of source code into executable). Whether that belief will turn out to be correct has yet to be tested.