Applied Visual C++ 2005
I haven’t been blogging much over the last few months mostly because I’ve been real busy on various projects, the most significant being my new book entitled Applied Visual C++ 2005. Hopefully I will be able to write more about it in the coming weeks. In a nutshell, it introduces Visual C++ 2005 as a language and compiler for developing applications targeting the .NET Framework.
Part 1 sets the foundation by exploring the fundamentals that you need to be familiar with in order to start writing managed as well as mixed mode (containing both native and managed code) applications. I hope to complete part 1 of the book and get it out to reviewers by the end of the month.
I came across a quote from Douglas Adams in the commentary of one of his books that I think all authors must appreciate:
“I love deadlines. I like the whooshing sound they make as they fly by.”
Here is the outline for part 1:
Ch1 – Hello .NET
(How to set up projects and build your first console application)
Ch2 – A New Runtime and Type System
(How the CLR relates to the OS and CRT and how it’s exposed in Visual C++)
Ch3 – Types and Abstractions
(How to define managed types and members)
Ch4 – Member Functions
(Member functions in depth)
Ch5 – From Pointers to Handles
(How different forms of object references work and are applied in different scenarios)
Ch6 – Exceptions and Exception Handling
(How to define and use managed exceptions alongside native C++ exceptions)
Ch7 – Generic Programming
(How CLR generics compare to C++ templates and how to use them both effectively)
Part 1 of the book is relatively short. I don’t attempt to introduce the CLR in detail. Rather it focuses on providing a practical introduction to C++/CLI and explaining enough of how the CLR works for it all to make sense.
Part 2 focuses on the .NET Framework’s extensive class library, exploring some of the most generally useful and powerful libraries. Each chapter in part 2 also includes a realistic sample project that is explored in detail to provide practical and generally applicable sample code for the reader. As this book is geared at providing lots of practical information that can be directly applied to real-world applications, each chapter considers aspects of native as well as managed code and libraries.
You may be saying to yourself: “I know the .NET Framework already. What can this teach me?” As much as the CLR is a “common language runtime”, the language you choose to view it through has a significant impact on your view of managed code. This is witnessed in books like Richter, which although an excellent book providing great insight into the .NET Framework, paints a rather language centric view of the framework. You can also see this in the design of some parts of the .NET Framework. In part 2 of this book my aim is to present a more C++ centric view of managed code design and development, not just a straight port of typical C# code. You will likely be surprised by how your view of managed code changes as you start thinking in C++.
I’m really excited about Visual C++ 2005 for a few reasons:
It allows me to use and build on my investment in C++ while moving to managed code.
It is 100% backward compatible, allowing me to continue using the millions of lines of C and native C++ code that are in existence today along with managed code in a single component.
It provides a far more natural interop story than languages like C# allowing me to use existing header files, to call Windows API functions for example, without having to redefine all the structures and functions which can be error-prone.
It shows that C++ truly is an incredibly flexible language. The Visual C++ team was able to introduce CLR and GC constructs in a way that fits naturally into Standard C++ even if they are non-standard. Some people like to refer to this flexibility as the “complexity” of C++, but I think that this view is naïve. As other newer and “more elegant” languages evolve to introduce new language features and through necessity add new language constructs to solve various usage problems, the languages inevitably get more complex. As an example, avoiding things like declarator operators (such as *, & and ^ in C++) may simplify a language design for common code but does limit your options when greater flexibility is required. Nevertheless I love the fact that different languages are being developed as it provides inspiration for new language ideas for all language designers. VB, Java, C#, along with the countless languages that preceded them have introduced many interesting concepts to make the programmer’s life easier. C++/CLI is a testament to that by introducing (language, not library) features for concepts like garbage collection and useful and familiar constructs like the for each statement that have been around in other languages.
Here’s an excerpt from my evolving preface:
"C++ is a unique language in that it allows you to naturally program at different levels of abstraction. The level of abstraction you program at is up to you. What parts of the language you wish to make use of is also up to you. C++ doesn’t require you to understand every detail of the language and certainly you should not have to in order to be productive. You should always program at the highest level of abstraction that is possible and practical, but when the day comes that you need to go a little deeper to get something done, C++ will not stop you but instead will allow you to naturally extend your programming to a lower level of abstraction as needed."
Scoble has been fielding some questions about Longhorn’s .NET story. The bottom line is that building an operating system is a monumental task. With the amount of engineering gone into Windows it makes no sense to “rewrite” it in managed code. It does however make sense to provide managed wrappers for many of the OS services in the .NET Framework, as Microsoft has been doing, but we cannot expect that every last API will ever be completely wrapped by some managed abstraction. That’s where Visual C++ plays a significant role in allowing you to naturally mix native and managed code. You get the best of both worlds.
I wonder if Scoble would be interested in reading my book if I sent him a copy when it’s done…
That’s it for today. I know I’ve rambled a bit. Does this sound like something useful? I’d love to hear your feedback.
© 2005 Kenny Kerr