May 2006 - Posts

My Computer

Due to an unfortunate incident involving an operating system setup procedure and a format operation I lost a great deal of data. Anyway, that’s a story for another day. The end result is that I had to rebuild my main development box and this is what it looks like.

This isn’t one of those “here’s my favorite tools” list. Rather these are the commercial software products that go onto any development computer I prepare.

Here are the basic specs for my computer:

Dell Precision Workstation 380
Intel Pentium D 820
2 GB of RAM
2 x 37 GB hard drives
NVIDIA Quadro NVS 285
2 x Dell 1905FP
Microsoft Natural Keyboard 4000
Microsoft IntelliMouse Explorer 3.0

The Dell 380 is a solid desktop. The Pentium D 820 is a great entry-level (read: affordable) dual-core 64-bit processor. Unfortunately it’s not the 920 which supports Intel VT – oh well (read: Ari you ***). The NVIDIA display adapter is not exactly high-end but I love it. It’s a single card supporting dual monitors with a little splitter cable. And those Dell LCD monitors are awesome.

So here’s what gets installed:

Windows Server 2003 x64 Edition
Office 2003
Visual Studio 2005
SQL Server 2005
MSDN Library - May 2006 edition
Windows SDK - Vista beta 2 build
Windows Driver Kit - Vista beta 2 build

I haven’t found working drivers for my video card yet so Windows Server Longhorn will have to wait (I run Vista on a test box). Office 2007 also doesn’t work properly on x64 editions of Windows so that too will have to wait. I’ve also finally ditched Outlook. Unlike Word 2007 which has become considerably faster and simpler, Outlook 2007 remains slow and complex.

How about you? What does your dev box look like?


© 2006 Kenny Kerr

Posted by KennyKerr with 4 comment(s)

Best Practices for Writing Efficient and Reliable Code with C++/CLI

My latest C++/CLI article is now online. Got check it out now:

Best Practices for Writing Efficient and Reliable Code with C++/CLI

Visual C++ 2005 provides a wealth of features that allow you to build sophisticated applications without limits. It can, however, be challenging to write efficient and reliable code, because it can be easier to produce poorly written managed code with C++ than with some of the newer and simple languages. C++/CLI (Common Language Infrastructure) was designed to bring C++ to .NET as a first-class language for developing managed code applications, and specifically to simplify writing managed code with C++. This article walks through a number of best practices for writing efficient and reliable code with C++/CLI.


© 2006 Kenny Kerr

Posted by KennyKerr with 3 comment(s)

Ever wonder...

...what Kenny looks like?


© 2006 Kenny Kerr

Posted by KennyKerr with 1 comment(s)

Kenny in Seattle

I’ll be in Seattle this coming week attending the Windows Hardware Engineering Conference (WinHEC). I’ll be downtown at the convention center for most of the week so if you’re in the area and want to chat then let me know.

I’m not averse to visiting a software campus or two.  ;)


© 2006 Kenny Kerr

Posted by KennyKerr with no comments

The Linq between C# and C++

C# is the hot new language, unless you’re Don Box in which case it’s probably Ruby, but let’s pretend its C# for the purpose of this discussion.

:)

A future version of C# will allow you to write the following:

int[] numbers = { 10, 0, 9, 1, 8, 2, 7, 3, 6, 4, 5 };
 
var query = from n in numbers
            where n < 5
            orderby n
            select n;
 
foreach (var n in query)
{
    Console.WriteLine(n);
}

Running this code results in the following output:

0
1
2
3
4

If you dream in SQL then this code might make you drool. If you dream in C++ or C# then this might make you cringe. Whatever your persuasion, this code is intriguing and has the potential of dramatically simplifying certain types of coding patterns. Think about creating and consuming data in XML documents or relational databases.

Can this work? Is it type-safe? And where does it leave C++? Let’s take a look.

What on earth is ‘var’?

var is the C# rendition of the compromise certain strongly-typed languages are making to appease the onslaught of loosely-typed languages. In a future version of C# you will be able to declare a variable and leave the compiler to infer its type based on its initializer expression. Consider the following example:

Dictionary<int, string> dictionary = new Dictionary<int, string>();
Dictionary<int, string>.KeyCollection.Enumerator enumerator = dictionary.Keys.GetEnumerator();

There is a whole lot of type information that seems redundant to humans yet compilers appear to require it. Well no longer. Making use of the C# var keyword, the code can be simplified considerably (while the resulting IL remains the same):

var dictionary = new Dictionary<int, string>();
var enumerator = dictionary.Keys.GetEnumerator();

The ISO C++ committee has been moving in the same direction and approved a type deduction system for C++ that works in much the same way, with the obligatory syntactic sugar that we C++ developers love to hate. The new (old) auto keyword indicates that the type of the variable be deduced from the initializer expression. Consider the following C++ equivalent to the previous C# example:

Dictionary<int, String^> dictionary;
Dictionary<int, String^>::KeyCollection::Enumerator^ enumerator = dictionary.Keys->GetEnumerator();

Using the proposed auto keyword it can be simplified as follows:

Dictionary<int, String^> dictionary;
auto^ enumerator = dictionary.Keys->GetEnumerator();

So what is LINQ?

LINQ stands for Language-Integrated Query. Which language? Well any language that purports to target the future of the .NET Framework. Much of the attention around LINQ focuses on C#, being the poster child for the .NET Framework, but there is nothing stopping other languages from providing the language bindings necessary to integrate query facilities into the language.
 
To understand what LINQ really is in relation to C# we need to look under the covers. Here is the query declaration again:

var query = from n in numbers
            where n < 5
            orderby n
            select n;

We have already discussed what var is for, but for the sake of this discussion let’s keep things explicit:

IEnumerable<int> query = from n in numbers
                         where n < 5
                         orderby n
                         select n;

C# uses patterns, not unlike the way C++ templates work, to translate query expressions into method calls. Because of this, the query expression is suitably type-safe and is not simply an expression evaluated at runtime as is the case with many loosely-typed languages. The query expression above can be rewritten using method calls and this is essentially what the compiler does on your behalf:

IEnumerable<int> _subset = Sequence.Where<int>(numbers,
                                               n => n < 5);
 
IEnumerable<int> query = Sequence.OrderBy<int, int>(_subset,
                                                    n => n);

This now looks a lot more like C# but there is still the matter of the parameter expressions. These are known as C# lambda expressions, which provide a more concise syntax for writing anonymous methods. This can in turn be rewritten using anonymous methods as follows:

IEnumerable<int> _subset = Sequence.Where<int>(numbers,
                                               delegate(int n) { return n < 5; });
 
IEnumerable<int> query = Sequence.OrderBy<int, int>(_subset,
                                                    delegate(int n) { return n; });

Of course anonymous methods are just shorthand for named methods:

var _subset = Sequence.Where<int>(numbers,
                                  ConstraintFunction);
 
var query = Sequence.OrderBy<int, int>(_subset,
                                       SelectFunction);
 
.
.
.
 
static bool ConstraintFunction(int n)
{
    return n < 5;
}
 
static int SelectFunction(int n)
{
    return n;
}

So as you can see, query expressions are much like “for each” statements where the compiler takes a simpler expression and produces the more verbose imperative code on your behalf. Writing the query expression is just so much simpler and to-the-point:

var query = from n in numbers
            where n < 5
            orderby n
            select n;

Where does this leave C++?

Let’s start with what you can do today. Today you can already use the System.Query assembly, on which LINQ is based, and write the equivalent code as follows:

IEnumerable<int>^ _subset = Sequence::Where<int>(safe_cast<IEnumerable<int>^>(numbers),
                                                 gcnew Func<int, bool>(ConstraintFunction));
 
IEnumerable<int>^ query = Sequence::OrderBy<int, int>(_subset,
                                                      gcnew Func<int, int>(SelectFunction));
 
.
.
.
 
bool ConstraintFunction(int n)
{
    return n < 5;
}

int SelectFunction(int n)
{
    return n;
}

But I know what you’re saying, that syntactic sugar is just sprinkled on way too thick, and I agree. In the future we will hopefully be able to use automatic type inference and lambda expressions (as a language not library feature) to simplify constructs such as these. I hope the Visual C++ team continues the efforts they started with the Visual C++ 2005 release and pioneer modern language features in the Visual C++ compiler.


© 2006 Kenny Kerr

 

Posted by KennyKerr with 9 comment(s)

Window Clippings 1.1

Update: A new version is available here: Window Clippings

 

Since the release of Window Clippings 1.0 in September last year, I have been working on an update in my spare time to address some minor annoyances and bugs as well as to add some of the most commonly requested features. Needless to say I haven’t had much time to work on this, but I finally managed to squeeze in a few evenings.

Although it’s just at version 1.1, Window Clippings sports a number of improvements that I think you’ll really appreciate. It also has one "big" feature. Here’s a quick rundown:

Hot Key Support

You can now capture the Print Screen key to initiate a window clipping.

TIFF Image Support

I have added support for the TIFF image format.

Option to Prompt for Storage Location

You now have the option of having a “Save As” dialog box appear after creating a clipping to control the location, file name and image format for each window clipping that you create.

Windows Vista!

The big feature in this release is the (experimental) support for Windows Vista.

Window Clippings takes advantage of window region information that the window manager tags onto themed windows as well as region information that particular windows may define explicitly. This worked great for creating window clippings of windows using the Windows XP class of themes but it doesn’t work for Windows Vista since windows are composited off-screen by the new desktop window manager using DirectX to create the effect of rounded corners, glass, etc.

Anyway, Window Clippings 1.1 provides support for creating window clippings on Windows Vista and accurately captures the logical window regions that are rendered on-screen.

Firstly, it correctly draws the background for the corners (either transparently or using the background color). Secondly, it provides the option of clearing the window background to avoid the effect of “dirty glass”.

Let me illustrate what I mean by “dirty glass”. Consider the following clipping with the option turned off.

Sure it might look great in the context of your desktop to see that part of the background image and other stuff you have floating on your desktop are partially visible through your Windows Media Player but as a screen shot it merely serves to distract from the window (unless of course you’re actually trying to illustrate the glass effect).

Turning on the option to clear the window background results in a clean window clipping with none of the window background showing through.

Window Clippings supports build 5365 (the latest CTP as of this writing). The Windows Vista desktop window manager has changed from build to build which is why I need to be so specific. Previous builds of Windows Vista are not supported. I will try to ensure that Window Clippings supports Windows Vista beta 2 when it becomes available.


© 2006 Kenny Kerr

Posted by KennyKerr with 10 comment(s)

Another C++/CLI Article

I see MSDN has also published another of the C++/CLI articles I wrote early in 2005. This one is more practical (depending on whether you consider MSIL practical).

Visual C++ 2005 Under the Hood

Understanding the relationship between the C++ you write and the CIL the compiler generates goes a long way towards helping you write faster and more accurate code. In this article we explore some commonly used C++ language constructs and how the compiler translates them into instructions for consumption by the CLR.


© 2006 Kenny Kerr

Posted by KennyKerr with 2 comment(s)

New (Old) C++ Article

I just noticed that MSDN has published another one of my articles. The operations of the MSDN group at Microsoft is a mystery to me (this does not include MSDN Magazine). I wrote this article around February 2005. That’s well over a year ago now. You have to wonder why it takes so long for them to publish something online. Some other authors have noticed the same efficiency. I suspect it’s a conspiracy by Robert Scoble to undermine traditional forms of publishing.

:)

Understanding Member Functions in Visual C++ 2005

Microsoft Visual C++ 2005 introduces new features in the C++ language related to member functions. This article explores these new features, as well as the mechanics behind them, as they relate to the CLI metadata that the compiler produces and, ultimately, how the Common Language Runtime (CLR) implements the behavior defined by the CLI specification. 

Keep in mind that I wrote this article back when I was teaching myself about how the CLR encodes function metadata and semantics within PE files and specifically how the Visual C++ compiler (then in beta) transforms C++ language constructs into CLI metadata. It’s a bit academic but you will hopefully gain some insight into how the code you write is seen by the CLR.


© 2006 Kenny Kerr

Posted by KennyKerr with 1 comment(s)
More Posts