Newer Posts Older Posts

Getting Started with Three.js



I think WebGL is an awesome idea; you can use accelerated 3D graphics within a browser. This is totally game changing and opens the gate to games serves directly to your browser.

Working with OpenGL primitives is somewhat annoying. (One of the reason why I build wrappers for C++.) But for javascript there are already quite usable libraries, one of these is Three.js. Today I will show the relative easy with which you can start to use WebGL. (Easy to learn hard to master.)

I will show you how implement the following:

full screen

read more

Agile Spices for Classical Process



In this day and age every programmer and his dog know that well implemented agile processes are more efficient and create an environment where you actually want to work. Unfortunately many organisations are not ready to implement agile processes. This resistance unfortunately is somewhat well founded, when you need to comply with regulations, it is really hard to explain how traceability is implemented when all you have to document your requirements are index cards. Although it is possible to implement traceability in an agile process, such as Scrum, that even the FDA will approve of, getting the upper rungs of management to agree, can be an impossible task.

But not all hope is lost, there are a few things you can take from the agile play book and seamlessly integrate into a classical model, like waterfall or the V-model.

read more

Compose (Variadic Template Function)



I have used a string composition function for quite some while. It is a reimplemented and simpler version of the String Composition Library.

std::cout << compose("Wrote %0 objects into %1.", objects.size(), filename) << std::endl;

"Wrote 548 objects into level1.jsn."

The problem with C++'s stream library is that is almost impossible to localize strings with the stream insertion operators. The core of the problem is that they chop up the sentence into fragments, such as:

std::cout << "Wrote " << objects.size() << " objects into " << filename << ":" << std::endl;

When you use something like gettext the strings that may be translated are:

"Wrote "
" objects into "

Not only is it really difficult for translators to understand what is meant (they see the strings within hundred others), but it also does not allow them to reorder the sentence, as it may be necessary. For example in German I would reorder to to be:

"%0 Objekte wurden in %1."

So it makes sense to keep the string together. This is one of the reason why the printf family of functions still is so popular when it comes to localisation.

read more

Worker Pool



I have recently been asked to write a worker pool and that is what I did. The goal is to have a thread pool, that you can throw at arbitrary functions and they will be executed as resources allow.

The worker pool has the following interface:

class WorkPool

    WorkPool(unsigned int concurency = std::thread::hardware_concurrency());


    template <typename Res, typename ... Args, typename Fun>
    std::future<Res> enqueue(Fun func, Args... args);  

    // ...

To use the worker pool you would use the following code:

WorkPool pool;

addrinfo* google_com  = nullptr;

std::future<int> fgcom = pool.enqueue<int, PCSTR, PCSTR, const ADDRINFOA*, PADDRINFOA*>(getaddrinfo, "", NULL, NULL, &google_com);

if (fgcom.get() == 0)
    // do something with the result
    // print error message

See the full example code.

But you can enqueue anything function like into the work pool; basically anything that goes into a std::packaged_task. Like with std::async, it is important to capture the future, even if it is void. The problem is that the call will hang at enqueue until the function finishes, which renders the entire concept of a worker pool moot.

read more

User Stories are Half the Story



There are many ways in which you can capture requirements. The current "en vogue" method is to writ down user stories on index cards and stick them on a white board. A structured approach to requirements is key if you want to ever finish your project, unfortunately user stories fail to capture all aspects that define a piece of software.

The first and obvious contender to missed requirements are the non functional requirements. Non functional requirements are the ephemeral requirements that encompass maintainability usability, performance and memory footprint. Many methodologies try to skirt the issue by defining "quality metrics" or "common values". The idea here is, that by creating the cleanest and optimal code you actually implement the non functional requirements because the code is is such an awesome state. The problem is that the optimal solution solution for ten elements is not the optimal solution for one million elements.

read more

Iterative Waterfall



Although agile processes are becoming commonplace in many organisations, many developers and projects are still stuck in some form of waterfall and classical project management, especially in large organisations. (Like me.) But within the constraints of classical project management, some agile practices can be applied. In the case of this post, I will look at iterations.

Iterations are not something new that agile processes brought to the development scene. But they make it a core mechanic of the process. The core idea is to reduce the feedback loop. One thing that the water wall fails to do well.

read more

Revised EventEmitter



I wrote a C++ incarnation of node.js' EventEmitter. But as things are, when you communicate a subject, often you find new insight and flaws in the topic. One of the reasons why rubber ducking is a useful tool, while designing software.

My insight was that the listeners are stored is optimized in the wrong way. I used the standard way when you have handle to things, the handle is the key into a map that holds things. This makes sense when most of the time the outside world calls functions with this handle. But in the case of the EventEmitter, the handle to the listener is only relevant when you want to remove it. But what is done most of the time is emitting events. So it just plainly makes sense to order the map by the event.

read more

EventEmitter in C++



Note: While writing this article I noticed in flaw how the listeners are stored. You can read everything about the Revised EventEmitter.

When it comes to C++ callback / event handling I have for a long time relied on sigc++. But since the release and mainstream adoption of C++11, I have more and more relied on lambda function for event handling. I have mostly just used the pattern where a std::function is stored for each event and you can set them through a on_event function, like so:

class Widget
    void on_something(std::function<void (int)>cb) 
        something_cb = cb;            

    void do_something()
        if (something_cb)

    std::function<void (int)> something_cb;

widget.on_something([&] (int info) {
    // react to event

This takes some queues form node.js and has a high degree of readability. The pattern only has one severe drawbacks. First you can only register one handler at any time.

read more

Overhaul of Page Generation



When migrating from jekyl to gulp.js I was basically following jekyls lead, purely to ease the migration pains.

Some point later Daniel Naab adapted my aproach. Although he build ontop of my ideas, he played the ball out of the park. What really stuck me as ingenious is the integration of The combination of travis-ci and, means that novice users can author the website without knowing what git and a text editor is. The result is something close to a high end CMS with static generated HTML pages.

read more

The ACME Protocol



... is the best thing since sliced bread the invention of SSL/TLS.

The Electronic Frontier Foundation (EFF), Mozilla, Akamai, Cisco and IdenTrus have partnered to create a free Certificate Authority (CA), Let's Encrypt. But the real twist is that they have removed humans form the certificate signing and revocation process. Finally the cherry on the cake is that Bruce Schneier thinks it's an "absolutely fantastic idea".

Enough of appeal to authority, first let us look at what is broken with existing certificate signing process. The way to get a valid SSL certificate is to create a signing request and have that signing request turned into a certificate by the CA. This certificate is then signed against the CA's certificate.

The SSL signing process is quite solid from a technical and cryptographic standpoint, but commonly fails on the human front. The problem is how does the CA know you are who you claim to be and that you that you actually own the domains the certificate is for?

read more

Newer Posts Older Posts