Tag Archives: cplusplus

Interfaces in C++

C++ has no such thing as an interface. It’s one of the few Java vs C++ comparisons that I think Java wins. Interfaces are useful. I’d like to talk about how we can get similar functionality into C++. First we need to define our terms. Here’s an abstract base class in C++. class Shape : […]

Posted in FussyLogic | Also tagged , , , , | Leave a comment

Finally, No

Why doesn’t C++ have a finally block? Here’s some Java. void userFunction() { f = new Resource(); f.open(); try { // might throw buffer = f.read(); } finally { f.close(); } useBuffer(buffer); } It’s tempting, after you’ve had a finally for a while to think that it’s necessary for proper resource management in the face […]

Posted in FussyLogic | Also tagged | Leave a comment

Not Everything Is A Reference

I like Java as a language. Kind of. It’s strongly and statically typed, has object oriented syntax, reflection, exceptions, and interfaces (interfaces being one of the few features that I think C++ is missing). Dynamically typed languages encourage sloppiness, and don’t help you avoid sloppiness, and the overriding feature of all good software is that […]

Posted in FussyLogic | Also tagged , , , | Leave a comment

Copy and Swap Idiom

I learned a new trick today, while reading about C++11 (of which more to come). It’s a technique I wish I’d known about a long time ago, as it addresses an issue I’ve always thought C++ had – forcing you to duplicate code. That issue is addressed even more thoroughly with C++11, which has introduced […]

Posted in FussyLogic | Also tagged , | Leave a comment

Valgrind II — helgrind

Last time we looked at valgrind’s memory leak detector, memcheck. This time we’ll be looking at an even more difficult to catch class of bug, thread race conditions. First let’s be clear what a thread race is: a race is when two threads run code that access the same piece of memory. The outcome is […]

Posted in FussyLogic | Also tagged , , , | Leave a comment

Valgrind I — memcheck

In this series I’m going to give you a quick tour of the valgrind tool suite. valgrind is useful for finding those hard-to-find, serious-repercussion bugs that can sneak into your code. Consider this C++ program: // C++ #include <iostream> // C #include <stdlib.h> // OS #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> using namespace […]

Posted in FussyLogic | Also tagged , , , | Leave a comment