Write Event-based programs again sequentially or how to Clean Code in asynchronous programs

Helge Betzinger's picture

Helge Betzinger
pcvisit software ag
Europe Date: 
Wednesday, October 8, 2014 -
11:30am to 12:30pm
Europe Room: 
B5+B6
Europe Track: 

Presenter Bio: 

After his studies at the Technical University of Dresden Helge Betzinger has worked in the automated Chipententwicklung at Systemonic and Philips Semiconductors as CTO and Architect for the pcvisit software ag. The company develops high-performance server-client based, platform-independent products based on C + + since 2004. Helge’s main interests are deemed to the development of maintainable and efficient code. Key points are Domain Driven Design, Clean Code Development and Continuous Delivery.

Abstract: 

For modern applications there are always plenty of reasons to wait. It doesn’t matter whether they are of high or low complexity. They're waiting for network events, waiting for a slow database, waiting for content from the Internet, waiting for computationally intensive tasks. But waiting is not a virtue of programming languages like C + +. Thus, one needs to implement the well known workarounds like using threads, signals, callbacks as well as synchronization mechanisms to cope with this challenge. Using those techniques in general helps to solve the problem but at high costs.
Instead of letting the compiler take care of the control flow the developer needs to explicitly modify it to achieve the required behaviour. Usually parts of the application that actually belong together in terms of functionality are located at separate locations in the source code. As a result the source code at all is difficult to maintain as the application and the explicit control flow are mixed together. Therefore, clean code remains an ambitious vision as in reality one has often still to cope “spaghetti code”.

While in programming languages ​​such as JavaScript, ECMAScript 6 already possible, in C + + a general and simple way to formulate asynchronous code sequentially is still missing. Currently there are visible trends that C++ also moves in this direction. E.g. there are proposals for an extension of C + + with the language standard C + +17. Furthermore, Microsoft already proposes corresponding extensions in its current C + + compiler preview. But one needs to keep in mind: Before all this can be used productively it will take years!

But why wait? With the coasync4cpp library there is already an excellent method to write event-based programs elegant and clean in C + + and Qt using await/async/thunkify. The library also allows easy combination with the elements known from C + +11 such as std::async, std::thread or std::future and it supports further to bring the advantages of async / await to program using callbacks and signals. Who is familar with the concepts and notations of std :: async; std :: thread and std :: future, can take off with this knowledge practically immediately. The library is based on boost 1.55, makes full use of C + +11 and will be freely available under the LGPL.

First, there is the motivation for such a library and a presentation of a few basic elements. Then Qt example application is to be shown by a small, such as event-driven Qt applications now can easily be programmed sequentially.
The application stores and manages images using the Qt cloud services. Step by step it goes through the Hotspots of the application until the entire explicit control flow has been stripped of signals and callbacks, and the actual application code reappears in a highly simplified Qt application.