Every programming language has its benefits and its drawbacks. Python, for example, provides a dynamic and clean environment for the developer, which boosts productivity by hiding much of the “dirty work”: memory management, type inference (duck typing, in this case), and more. Such benefits usually come at the cost of efficiency, which is something that other programming languages (such as C++) excel in.
The next logical step would then be a way to combine the benefits of such different programming languages in a single system. For instance, we could use C++ solely for the cpu-intensive parts, while the rest of the software could very well be written entirely in Python. The missing piece would then be a way to integrate the two. The common way of doing so is through SWIG, which is a tool that is able to wrap C++ to many different programming languages, Python included. Using SWIG right out of the box, we will be able to invoke C++ code directly from a Python interpreter. But what if we wanted to extend C++ classes in Python, making native C++ seamlessly call Python code?
Continue reading Python directing C++
A few months ago I have been to the states. Naturally, one big outcome of that trip was a handful of photographs documenting it – 1.6GB of these, to be precise. The bad part is that I have forgotten to reset the camera settings beforehand, which made all the pictures date a few years back.
The images I made with my Cannon camera (sx110) use JPEG for compression, and Exif for the metadata – including the date and time the picture was taken, which is what we’re interested in. Being as perfectionist as I am, and having some familiarity with Python, I set out to modify the metadata on the pictures to contain the right dates for the trip.
Continue reading Fixing incorrect photo data
Using the initialization list is very much encouraged in C++, and rightfully so – it has many benefits. But what happens if one of your members fails at initialization and actually throws an exception? Even worse: what happens if that member’s constructor throws an exception not in your exception specification list?
Continue reading Exceptional initialization list
I know I’m a little late, but I’ve only recently discovered the interesting site of projecteuler.net. For anybody not familiar with it, Project Euler is a site offering a vast collection of programming puzzles of mathematical nature for anybody to solve. It has a ranking system for its members, allowing every member to see others’ statistics with solving the offered puzzles. Most of the puzzles are pretty hard, even for the gifted mathematicians among us, and the majority of them can not be solved using brute force methods (it would just take far too long), so usually an efficient algorithm is required. Once you solve a problem you gain access to a forum thread which discusses the problem, its solution, and the various techniques and algorithms other users came up with.
Continue reading Project Euler