cpptempl: A string templating library for C++

cpptempl is a simple string templating language (or templating engine) for C++. It has loops, conditionals, and variable interpolation. cpptempl relies on the boost libraries (shared_ptr, string_algo, and lexical_cast). I originally wrote this engine because I was generating HTML files in C++, and generating the HTML right in the C++ quickly got very hairy, besides […]

Implementing IDocHostUIHandler in a C++ WTL/ATL project

I recently implemented IDocHostUIHandler in one of my WTL projects hosting the web browser. You need to implement this interface if you want to do things like control the context menu of the web browser. I had to go spelunking in various forums and documentation to piece together how to do this, and I never […]

Coming from C++/Java to Python should bend your mind

Coming from C++ or Java to Python should bend your mind. If it doesn't, then you haven't learned Python yet — you're just writing C++ or Java in Python. If you only knew a statically typed and compiled language like C++ or Java before, and learning Python hasn't changed the way you think about programming, […]

Google’s Chrome browser uses the WTL for Windows

As pointed out in this post, Google's new Chrome browser uses the Windows Template Library (WTL) in its Windows version. I've long been a fan of the WTL — I've written several programs in it, including Felix, Doc2Html, and Tag Assist — and it's great to see it getting some love. In my opinion, the […]

Mocking file output for unit testing

Having a unit test harness makes modifying code a lot easier, because it lets you quickly spot anything you've broken as you're coding. But when you've got legacy code that doesn't have unit tests, getting the code into a test harness can be a lot of work. You've got code connecting to databases, touching the […]

Aim high

Alex Martelli has a great quote on optimization in Python in a Nutshell: Start by designing, coding, and testing your application in Python, using available extension modules if they save you work. This takes much less time than it would with a classic compiled language. Then benchmark the application to find out if the resulting […]

The past, present, and future of optimization

I have a relative ("Dan") who used to earn a living optimizing code in the late 70s and early 80s. Around then, a new-fangled high-level language named "C" was starting to catch on, but companies didn't like all the wasted cycles in C programs due to the under-optimized assembly code that their C compilers were […]

Three reasons to avoid private class members

I recently read an interesting post about the need for access control via the private keyword (or an equivalent mechanism) on the CodeThinked blog. The post raises some valid points, but I still think enforced private/protected access is something to be used sparingly at most. Here are three reasons why. Private members are a pain […]

How learning Python made me a better C++ programmer

This post on the Raganwald blog spurred me to write about something I've been thinking about for a while: how learning Python has made me a better C++ programmer. The short answer is, it convinced me to start using the boost libraries (and the Loki library). I'd seen these libraries before, and thought that they […]

Classes considered overused

We all love classes. When I write a class, I get a warm and fuzzy feeling, because I know I'm doing OOP. A class represents a bundle of data and behavior. A classic example is a BankAccount class, which maintains a "balance" state and various methods for manipulating and querying the balance. This is a […]