All Posts
Welcome to my blog.
-
C++11 and override
The new
Read More »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. -
C++11 and final
One of the lesser known - but still very useful - enhancements to C++11 is the addition of the
Read More »final
keyword. This essentially mirrors thefinal
feature in Java, which has existed since its inception. -
C++11 Range-based for loops
The humble
Read More »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 allowfor
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. -
C++11 Futures
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.
Read More » -
C++11 Smart Pointers: Shared Pointer
In the last article on smart pointers, we looked at
Read More »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 Smart Pointers: Unique Pointer
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
Read More »unique_ptr
makes managing dynamically allocated memory safe and simple. -
Modern C++11 Memory Management
Memory management in low level code has changed slowly over the years. In traditional C code, you would allocate memory with
Read More »malloc()
and release it withfree()
. -
What is Rust?
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.
Read More » -
Threading with Boost - Part IV: Mutex Examples
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.
Read More » -
Threading with Boost - Part V: Condition Variables
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?
Read More » -
Threading with Boost - Part III: Mutexes
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.
Read More » -
Bug of the Year - 2011
My favourite bug of all time was uncovered because I was just too impatient.
Read More » -
Good Code Gardening
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:
Read More » -
25 Tips for Intermediate Mercurial Users
I recently read an interesting article by Andy Jeffries entitled 25 Tips for Intermediate Git Users (linked to via proggit) . It had lots of useful information condensed into bite-sized task-oriented chunks.
Read More » -
Threading with Boost - Part II: Threading Challenges
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.
Read More » -
STL: filtering
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.
Read More » -
Threading with Boost - Part I: Creating Threads
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.
Read More » -
The first user
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?
Read More » -
Improve your C++: const-correctness
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
Read More »const
allows you to safely call anyconst
method on such a reference. It is part of good type-safe practice and good code hygiene. So how do we do it? -
STL Iterators and Performance
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
Read More »std::list<T>
. -
Debugging NSBezierPath drawing
I was working on some Cocoa programming, making heavy use of
Read More »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. -
STL warts - when removing isn't
Pop quiz: what does the
Read More »remove
function provided in the C++ STL algorithm package do? -
A subtle bug involving C++ temporaries
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.
Read More » -
Gloves off: Mercurial vs Subversion
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.
Read More » -
NSOpenGLView and text
The Cocoa view class
Read More »NSOpenGLView
, which automates all the initialisation required to provide an OpenGL context for drawing, is very useful indeed. It would also seem thataglUseFont
is a nice simple way to load up a font to draw some text in your view. So long as it isn’t the aforementionedNSOpenGLView
, that is. -
The Happy Coder's Toolkit Part II: Profiling and R
Need to do some performance analysis on the cheap?
Read More » -
The Happy Coder's Toolkit Part I: mtrace
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
Read More »printf
around the place to see what’s going on. Hell, I’ve even fired upgdb
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). -
Autoantonyms
What is the antonym (word of opposite meaning) to the word “resign”? One correct answer is “resign”. What about the opposite of “dust”? Yup, 10 points for “dust”.
Read More » -
What went wrong?
Writing good diagnostic error messages is hard. But it’s worth the effort. And there’s also some side benefits if you take the time, and it’s not just avoiding hate-mail from your users.
Read More » -
Unexpected side-effect
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:
Read More » -
Dropping Privileges in Python
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
Read More »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 (usuallynobody/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. -
Who really cares about usability?
Users, that’s who. They just don’t realise it until the computer gets in the way of them doing what they want.
Read More » -
Bug of the Year
I discovered the weirdest bug the other day…
Read More » -
Optimize this...
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…
Read More » -
A real Python logging example
For some reason, all the examples of the configuration files for the Python logging framework are artificial ones, with names like
Read More »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 Pythonlogging
module in a non-trivial application (ie. with multiple hierarchical modules) with an associated configuration file. -
Pyrex and sharing extension modules
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.
Read More » -
How not to give a talk
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.
Read More » -
VeriSign vs The Rest of the World
On the 15th of September, the top-level Domain Name Service (DNS) for
Read More ».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… -
C++ STL extras - random_sample_n
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.
Read More » -
Emacs Myths
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.
Read More »
subscribe via RSS