Bash Script to Review Local Subversion Modifications

Daily task when you work with a source control system is to review your changes before check in, in order to avoid accidentally committing temporary (debugging) or incomplete changes.
Reviewing the changes from the command line (terminal) is a tedious task. (more…)

Using Autotools

There are many Linux distributions, shipping different libraries and tools to different locations. Developing software that is portable across several Posix-compatible operating systems is hard. Luckily, there are several build suites, designed to make the build process portable. One of them is Autotools. Autotools is a set of tools:

  • Autoconf – generates configuration script from a template (configure.ac) file. Generates Makefiles from Makefile.in files.
  • Automake – takes Makefile.am files as an input and generates Makefile.in files
  • Libtool – handles all the requirements for building shared libraries

(more…)

“It’s not my code” Syndrome

Multiple times in my career I stumbled upon a phenomenon. It always goes on in exactly the same way:

I am working on some legacy code and I find an issue with performance, lack of comments, bad practices, etc. Then I discuss the issue with my colleagues. Usually the people I talk to just shrug their shoulders, saying “It’s not my code”. They use this phrase to dismiss the conversation and leave the things as is. I call this “It’s not my code” syndrome.

(more…)

Binary Search Algorithm

Description

The binary search algorithm is a divide and conquer algorithm, that takes a sorted array as an input. It works by comparing the searched value (key) to the middle element of the array. If they match, then its index is returned. If the key is less than the middle element, the algorithm is invoked on the left sub-array, otherwise it is invoked on right sub-array. This continues until the key is found or the input array is reduced to zero.

Recursion tree

Recursion tree

(more…)

C++ Observer Implementation

The Observer design pattern is used for state change notifications. An object called subject (or publisher) has a list of dependents, called observers (or subscribers). When the subject changes state, all its dependents are notified by calling a method. The Observer pattern is useful for the implementation of event handling.

UML diagram


The observer interface has an abstract method used for notifications and the subject has methods for attachment and detachment of observers.
(more…)

C++ Singleton Implementation

Singleton is the simplest and probably the most widely used of all design patterns. It’s so popular that some IDEs (like SlickEdit) have templates for its generation. The purpose of this design pattern is to ensure that only one instance of a class is created.
So, why discuss Singleton?
(more…)

Using CxxTest

Unit Testing 2 of 3

Having compared the two most popular C++ unit testing frameworks, let’s move on to the next step – the actual usage. Personally I prefer CxxTest, that’s why the samples bellow demonstrate its use. The test target will be the sample implementation of a read-only memory mapping.
(more…)

Installing Library Header Files with QMake

The problem

Since most of my projects are platform independent I like to organise them like Unix libraries. Unix libraries typically have the following directory structure:

./        Makefile(s)
./src     Source files and private header files
./include Public header files (that are to be installed)
./lib     Library build directory

The header files of the library should be installed into their own subdirectory of the common include directory. The code that uses the library can include the headers this way:

#include <mylibrary/myheader.h>

Copying the header files can be achieved in Visual Studio by adding a custom build step. The custom build steps allow the developer to customize the build process. But what about QT?
(more…)

Tracing Memory Issues

I wasted two weeks of my life, hunting for a bug that is corrupting the heap of a server application. The application runs on Unix-like OSs and is fairly complex. It’s multithreaded and consists of a front-end and several back-ends. The server is written in C++ and it has in-house developed garbage collector. It exposes CORBA interface and several clients, developed in different languages (Java, C#, Perl), connect to it. (more…)

C++ Unit Testing Frameworks

Unit testing is focused on the smallest testable part of an application. A unit test exercises an individual portion of code, to determine if it functions properly.

Unit testing:

  • reduces the cost of software – defects are discovered during the development stage and can be fixed prior to the release to the test team;
  • promotes interface-based approach of implementing components. The interfaces are adding abstraction, that makes the code flexible;
  • ensures that the software functions as specified by the requirements.

(more…)