jump to navigation

C++ Isn’t Cool II August 13, 2006

Posted by gordonwatts in computers.
trackback

Microsoft’s latest release of its development environment and libraries contains some very cool new features for C++. One that I really like is a self-checking version of the standard library. This code will watch your code and if you do something illegal it will attempt to flag it right away. The effort grew out of, I think, the whole secure computing drive that Microsoft and the rest of the field has been going through.

When you have to deal with very complex code that makes heavy use of the standard library this sort of thing can be a huge help in tracking down bugs. Heck, why waste time tracking down a bug when the computer can track it down for you, right!?

I discovered a nasty side-effect, however. In order to implement these checks Microsoft altered some basic things in the library. This is fine… except they turn off these alterations for optimized code. This makes sense: once you have debugged your code you don’t want to slow it down making all these cross checks. But this also means you can’t mix optimized an unoptimized code any longer. I found this out the hard way (thanks Axel).

It is times like this that I wish we’d moved towards one of the common garbage collected & interpreted languages – like Java or C# or similar – rather than C++. These languages have ways of adding attributes and other features to objects that will allow you to accomplish the same sort of checking without modifying the underlying object layout: the objects are extensible on the fly.

I was one of the people pushing for C++ when the field converted, but watching new people join our ranks I can’t help but wonder if that was a mistake – though back then I suspect it was the right choice.

Comments»

1. Sean D - August 13, 2006

That’s one of the reasons I’m not a big fan of adding “features” like that – at least if they stick to the standard, you know it will work (having hunted down enough obscure bugs in my short life).

I’m interested in the growing popularity of Python among certain circles. I think that a mix of Python and C++ could give enough flexibility in development (since Python has all those nice features like object reflection and all) that it could be an acceptable standard. (Rather than, say, rewriting ROOT in Java).

2. gordonwatts - August 14, 2006

Good points Sean. However, I really like the additions that MS added — the program does the debugging for you. So I’m in favor of those sorts of things. I just wish C++ had built in support for it.

ROOT already has a python interface to it, and writing and scripting ROOT using pyroot is so much nicer than using the C++ interface they provide with CINT (which is being re-written, as we speak, I think).

If you dig into ROOT you’ll find that it has a lot of the features that already exist in many script languages like java and .NET. The biggest two are the C++ interpreter (compile a line of code on the fly is easy in an interpreted language) and the whole meta-data system that allows you to discover what methods and instance variables are assoicated with an object at run-time. So you’d never do a direct port of ROOT — you’d (I hope) leave a good portion of it out if you were doing the port.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: