Rich Herrick liked his ranged types in Ada, and missed them when developing in C++. So he rolled his own, and now he has some protection from out-of-range and overflow conditions in his code. Sure, there's some overhead, as there always is when trading execution or compile time for safety, but Rich's implementation does a pretty good job of limiting the cost, and maximizing the benefit. Check out Ada-style Ranged Types in C++.
Herb Sutter kicks off a new column in DDJ this month talking about concurrency—but not in the way you might expect. Before you can even begin any work on concurrency, he argues, you need to figure out which mental space you occupy: which "pillar" of concurrency is defined by your requirements and techniques. Concurrency is one of those areas of programming about which two knowledgeable developers can have a conversation, and not understand a word the other person is saying. Part of the problem is vocabulary; but vocabulary is just surface layer of what can be deeper divisions between philosophies. Knowing the distinctions between the various approaches is a critical first step into concurrency. Check out Herb's "The Pillars of Concurrency."
If you're tired of tracking down null pointer dereferences and invalid pointer dereferences, then you might be ready to try out the Object Registration and Validation (ORV) pattern. With it, you can perform consistent sanity checks to guarantee you don't use an object that no longer exists. Eric Gufford shows you how.
C++/CLI provides a way to describe your code to the runtime, or to specify certain behaviors at run time: They're called attributes. Rex Jaeschke describes some of these attributes provided by the .NET Framework in his latest article, "C++/CLI: Attributes."
The flexibility of a rule-based system is one reason it has been such a popular choice in the AI field for so long. You don't need to perfectly understand the system you are modeling ahead of time. You can write your program, but later change the knowledge on which the rules operate without redesigning the whole system. There are some very specialized expert systems designed for writing just these kinds of programs, but sometimes, you just want some good 'ol, plain-vanilla C-style capabilities built in to your rule-based program. In this case, an approach like that presented by Lynwood Wilson in "Rule-Based Programming in C" might be just the ticket.
Object cleanup is one place where C++/CLI requires considering a bit more than is necessary with standard C++. Standard C++ achieves object cleanup with a destructor, but CLI uses a finalizer. In the C++/CLI world, it pays to know how both of these facilites work, and when to use them. Rex Jaeschke continues a long-running series of articles on C++/CLI with his latest, this time on Destructors and Finalizers.
Vladimir Kliatchko found recently that there wasn't a universal solution for the thread-safe initialization and destruction of Singletons. A C++ file-scope variable for initialization wouldn't work, and the pattern he turned to, the Meyers Singleton (in which the Singleton is intialized upon first use) didn't really solve the thread safety issue. Here's what Vladimir came up with as a solution.
How can you get the most out of your C++ experience when programming for Vista? One way is to attend "Bringing C++ to Vista: Leveraging Your C++ Code-Base to Create Native Windows Vista Applications," a one-hour Netseminar presented June 20 by Dr. Dobb's Journal and MSDN Magazine. You'll learn how to incorporate multithreading into your Vista apps, as well as how to leverage one codebase to target additional operating systems. Attendees who fill out a feedback form will be automatically entered in a drawing to win a free Slim Devices Squeezebox.
Sometimes even well-understood problems can grow significantly thornier when the variables involved scale up dramatically. Take the problem of joining up the ends of line segments—the algorithm for finding the nearest point on a set of lines to a given point is a common one in modern graphical computing. But when the data sets you're working with become huge, that simple algorithm can take days to execute. Stefan Wörthmüller presents an optimized approach in "Accelerated Search For the Nearest Line."
Choosing the right data structure up front can buy you dramatic performance gains, saving you long hours of optimization later on. But nothing is a silver bullet. Thomas Johnson examines STL hash containers like hash_map, hash_set, hash_multimap, and hash_multiset, which are to be included in TR1 in the form of unordered_map, unordered_multimap, unordered_set, and unordered_multiset, in his article "C++ STL Hash Containers and Performance."
If you're looking for a way to leverage your C knowledge and experience to write for the S60 smartphone, Open C might be just the ticket. Open C is a set of C libraries built on POSIX that can enable you to write much more portable code, and can help you get around a lack of Symbian Experience. Eero Penttinen and Antti Saukko introduce this new C variant in "Open C: Paving the Way for Porting."
Might trading on the stock market one day be entirely run by algorithms? Conventional wisdom has been that a human will always do better than an algorithm in the long run. But the latest trading algorithms, and more importantly, the latest methods of creating trading algorithms, are making an entirely automated stock trader seem less like science fiction and more like technology that's just a breakthrough away. John Bates gives us a glimpse of the state of the art in "Algorithmic Trading."
If you really want to understand error handling in C++, it's a good idea to understand how it came about—as a response to the problems of error handling techniques in C. The common C techniques are to report the error via a return value, bail with an abort() or exit() command, return an error indicator, or jump to an error handler. Dan Saks lays out the problems with each of these techniques.
Every year, Dr. Dobb's gives out the Excellence in Programming award to someone who has profoundly influenced the world of software development. It's hard to actually imagine programming today if Grady Booch, the recipient of this year's award, hadn't invented many of the concepts we take for granted now. Check out Jon Erickson's tribute to a programming legend.
Typically, querying an array to determine how many elements it contains involves using the sizeof operator, often wrapped in COUNTOF macro. But what happens when COUNTOF gets something it wasn't expecting? The results may surprise you. There is, however, a way to make COUNTOF type-safe. Ivan Johnson shows the way in "Counting Array Elements at Compile Time."