The final macro

The problem Cleaning up resources is hard. One has to keep track of all allocated resources and make sure to free each one on each error path. The difficulty is compounded, some say, with exceptions, which can make error paths non-obvious. Traditionally, C++ programmers use RAII wrappers (e.g. unique_ptr and CComPtr) to automatically clean up…

9

Against BOOL parameters

BOOL parameters are evil Boolean parameters are everywhere. In public APIs all the way down to private internal functions, code like this is ubiquitous: SaveData (“Bleg”, TRUE); What does TRUE mean here? What does TRUE mean when dropped in the middle of a larger parameter list? A BOOL parameter is like a semantic bomb: hen…

0

On assuming your customers are innumerate

So I was shopping for a couch this week and saw one I liked. I asked about delivery options. The salesperson replied, “It’s an $80 base fee for delivery plus a $20 per-piece charge.” Considering this price a little high, I asked, “Well, when could I come pick it up my self?” The salesperson cheerfully…

0

Breaking code on purpose

Breaking code is useful. When we run into an impossible situation, it’s better to fail early and predictably, especially in a debug build, where the users of which are likely to notice and kindly sent a bug report. (Most of the time, these bug reports will even lack profanity.) On the other hand, in production…

0

Everyone quotes command line arguments the wrong way

Background At one time or another, we all need to pass arbitrary command line arguments to some program. These arguments could be filenames, debugging flags, hostnames, or any other kind of information: the point is that we are to take a string and make sure some child program receives exactly that string in its argv…

13