All Posts

The new override modifier can be applied to a virtual method in C++11, and
instructs the compiler that the method is intended to override a virtual
method defined in the parent class. The primary advantage is that typos and
mismatched method signatures that would have resulted in subtle bugs and
unintended runtime bheaviour before can now be detected at build time and
easily corrected.

The humble for loop is one of the oldest control flow control constructs
in the Algol family of languages. Yet while other languages have extended
their syntax to allow for loops to do all sorts of crazy and useful things
beyond iterate over a range of numbers, C and C++ have remained steadfast -
until now.

Concurrency is one of the most significant challenges facing software
development today. As the gains in processor performance diminish year over
year, additional cores have become the norm. For some years now, multicore
processors have become the norm.

In the last article on smart pointers, we looked at std::unique_ptr, which
provides a simple and safe smart pointer to wrap heap allocations. As the name
implies, this smart pointer type cannot be shared between multiple threads.

C++11 introduces many significant improvements to the language and runtime. One
of the most important is to do with memory management - specifically, smart
pointers. The unique_ptr makes managing dynamically allocated memory safe and
simple.

Rust is a compiled, hybrid imperative/object-
oriented/functional language. It appeals directly to any C++ developer who has
battled with memory management, and Python developers who long for faster code.
So why might you be interested in learning Rust?
It’s compiled, so it’s fast. Rust uses LLVM as the
compilation engine, and benefits from all its optimisation and native code
generation support that targets ARM and Intel processors.

This article continues the series on threading with Boost, by looking in
depth at several sample programs which illustrate different aspects of
mutexes. We look at the code, and discuss how it is implemented, including
how to avoid common problems.

In multithreaded programs, mutexes are used as a lock to protect shared
resources and enforce atomic operations. This is useful to manage
concurrent access, but what about when one thread needs to asynchronously
signal to another thread that an event has occured or a condition is true?

In Part I of this series on Boost threading, we looked at the basics of how to create and run threads using the Boost libraries. Then we reviewed the main issues encountered with multithreading code in Part II: Threading Challenges. One of the biggest challenges is safely managing concurrent access to a resource. A Mutex provides a way to serialise access to a shared resource, such that only one thread is accessing the data at any given time, to ensure your data is consistent. In this article, we look at how to create and use Boost mutexes.

During a code review at work recently, we had an interesting discussion about code maintenance. You could say that coding is a bit like gardening: while you are planting new seedlings, do you weed nearby areas as you go, or save up all the weeding for the next sunny weekend? Should code maintenance be a continual, gradual process, or does it warrant being scheduled as a task in its own right?
First, let us define “code maintenance” as editing source code to make non-functional changes, such as:

In Part I of this series on Boost, we looked at the basics of how to create and run threads using the Boost libraries. But once you have more than one thread running in a process, you have to deal with the problems and challenges that threads can introduce. So, before delving into the mechanics of how to use mutexes and other threading constructs, we look at what can go wrong - and how to avoid it.

The STL makes it easy to create lists, iterate over lists, and apply a function to each member of a list. So how do you filter a vector according to some criteria? It’s not hard, but the obvious solution isn’t quite enough. Here’s how.

Boost is an incredibly powerful collection of portable class libraries for C++. There are classes for such tasks as date/time manipulation, filesystem interfaces, networking, numerical programming, interprocess communication and much more.

When you are developing a new piece of software, you typically first spend quite some time setting up your development environment. As you progress, your application becomes a very cozy inhabitant of this environment, a safe happy cocoon that has evolved as you make lots of small changes to the application or your system. What could possibly go wrong?

Writing “const-correct” code will improve the quality and maintainability of your code. It is especially important and useful when writing Object-Oriented code, as objects are often passed around as constant references. Properly declaring non-mutating methods as const allows you to safely call any const method on such a reference. It is part of good type-safe practice and good code hygiene. So how do we do it?

The Standard Template Library (STL) for C++ provides a set of powerful and flexible templated container classes. Never again will you have to hand-craft a doubly-linked list (and get your pointer arithmetic mixed up) – just use std::list<T>.

I was working on some Cocoa programming, making heavy use of NSBezierPath. I wished there was an easy way to see just where my control points were ending up, and how the curves were being constructed. So I wrote a category method to add such a thing to the NSBezierPath class. It is here for all to share.

I tracked down a subtle little bug the other day. My code was crashing on a line that should never crash (and we’ve all heard that one before!). It arose from doing two quite innocuous things, but when combined - disaster! I decided to write it up as an example to my 3 readers and Google.

I use Subversion on a daily basis, and Mercurial a few days a week. I have noticed that Mercurial seems to be faster with a lot of common operations, but I figured it wasn’t a fair comparison as Mercurial was always operating locally, while Subversion has to hit the network for many (but certainly not all) operations.

The Cocoa view class NSOpenGLView, which automates all the initialisation required to provide an OpenGL context for drawing, is very useful indeed. It would also seem that aglUseFont is a nice simple way to load up a font to draw some text in your view. So long as it isn’t the aforementioned NSOpenGLView, that is.

I have been doing some serious hacking, fixing and refactoring on a codebase for genetics analysis. And I’ve needed tools to go beyond just sprinkling the usual calls to printf around the place to see what’s going on. Hell, I’ve even fired up gdb once - but just to get a stack trace! This is the first of a sporadically released series on tools I’ve found useful. Hopefully they will distill the essential steps of using these tools, as well as expose some extremely useful but lesser known tricks to a wider audience (like the huge number of readers of this blog).

I discovered a strange bug in my Python code recently. It took me a few minutes worth of digging to uncover something somewhat surprising, a side-effect to do with default parameters that is not obvious at first blush.
Consider the following code:

When writing a small Python web application using the lightweight CherryPy framework, I needed the server to run on port 80. Of course running a server as root is enough to scare even the hardest sysadmin, so I obviously wanted it to drop privs immediately upon startup, once it had opened the default http port. I wrote the function below to drop privs and switch to a new user and group (usually nobody/nogroup). It is self-contained, should work with anything - there is nothing specific to any system. If you find it useful of have any suggestions to improve it, please leave a comment.

I’m working on an industrial image processing system, and it’s coming together pretty well. I hadn’t tried optimising anything up until now, as I wanted to get all the features implemented and do some profiling. “Premature optimisation is the root of all evil”, as they say…

For some reason, all the examples of the configuration files for the Python logging framework are artificial ones, with names like handler01, handler02 and so on. This makes it a little difficult to figure out how to apply it to a real world example. So after a bit of fiddling around, here is a real example of using the Python logging module in a non-trivial application (ie. with multiple hierarchical modules) with an associated configuration file.

I’m using Python and C in one of the rather large projects I’m working on, and I’m using Pyrex to provide the bridging code. Once I got over some of the tricks involved in sharing types between extension modules, it was cooking with gas.

I just got back from the Artificial Intelligence ‘04 conference in Cairns. It was a great conference, met lots of people, went to some interesting talks, saw some fantastic keynote talks, and generally had a good time. I even got to go for a swim and soak up some sun on the last day.

On the 15th of September, the top-level Domain Name Service (DNS) for .net and .com, fundamental to the entire Internet, was hijacked - by the very custodian entrusted with its upkeep.
Some time ago, VeriSign (better known for their rather pricey digital certificates) purchased Network Solutions, and now acts not only as a domain name registrar, but operates some of the top-level DNS services worldwide. They have done a fairly good job up until now… when they decided to cash in on their DNS operation, and redirect typos to an ad-driven web site. And effectively undermine part of the fabric of the net in the process…

Working on some code for my research tonight, I wasted a lot of time looking for some information on a particlar STL function. Since I couldn’t find the answers elsewhere, I am posting a quick explanation/solution here, to hopefully save someone else the trouble.

A recent article on NewsForge brought up
one of the oldest rwars on the planet (almost as old as the operating system
rwars), asking which editor is best: vi or Emacs? I was inspired to write my
own thoughts, findings and opinions after reading this article. Especially
since most of the arguments I read were trolls sprouting opinions and
regurgitating fallacies, rather than any informed sort of debate. So here I am,
with my own 2 cents.