tag:blogger.com,1999:blog-32091858293785465152024-02-22T09:58:18.295+01:00We Press ButtonsMy journey into software engineeringsambahttp://www.blogger.com/profile/11777176850583075015noreply@blogger.comBlogger62125tag:blogger.com,1999:blog-3209185829378546515.post-90961980001510340372017-02-26T23:48:00.000+01:002017-02-26T23:48:45.431+01:00Poor Man's Microservice Configuration Using Environment Variablestl;dr: This post shows a simple and tech stack neutral way to provide a configuration file for a microservice.<br />
<br />
These days a common approach to microservice deployment is to ship them as a standalone binary package. The Uber Jars in the Java world are a prominent example. This simplifies operations - particularly when you are in a pre-Docker environment.<br />
All it needs to run a microservice is a single Linux command line. As an old Linux guy I am delighted with this "back to the basics" approach.<br />
<br />
A must-have feature for those kind of processes is the ability to configure the service via an external configuration file. Here, you often find the usual suspects like YAML, JSON or even INI.<br />
<br />
<a href="https://12factor.net/config">This advice of the 12 factor manifesto</a> made along existing config option more prominent again: good old environment variables.<br />
<br />
This post shows a demo microservice which consists of three files:<br />
<br />
<script src="https://gist.github.com/samba2/d8290f63716777421bb4c76a09677301.js"></script>
<ul>
<li><i>demoservice-starter.sh</i> - starts demoservice.py and provides it with its configuration</li>
<li><i>demoservice.cfg</i> - the configuration file for this service consisting of shell variable definitions</li>
<li><i>demoservice.py</i> - the actual microservice (just a modified <a href="http://flask.pocoo.org/">Flask </a>"Hello World")</li>
</ul>
<br />
The service is started like this:<br />
<pre class="brush: bash">$ ./demoservice-starter.sh demoservice.cfg &</pre>
<br />
Outside to inside explaination:<br />
<i><br /></i>
<br />
<h4>
demoservice-starter.sh </h4>
<br />
Line 6 reads in the config file provided as command line argument. Technically the content of <i>demoservice.cfg </i>is parsed and executed.<br />
<br />
<u>Remarkable </u>here is that the environment variables created in line 6 are just visible for <i>demoservice-starter.sh</i> and its children but not for the rest of the Linux system. In contrast to a user or system "profile" file containing global environment variables this is <u>a decentral, scoped approach to provide environment variables</u>.<br />
<br />
Line 7 then starts the microservice. In this case I use <a href="http://gunicorn.org/">Gunicorn </a>as server for my little Flask application. I use "&" to send the gunicorn process to the background and continue the script execution.<br />
<br />
Line 8 stores the process id of my just started process. This PID variable is needed two times. On line 9 we enter a "wait" state until the gunicorn process exits. This is basically a more sophisticated version of an endless sleep loop. The latter one works as well but it requires more code ;)<br />
<br />
To stop the microservice we just kill <i>demoservice-starter.sh</i>. However, the shell does not kill our gunicorn child process automatically.<br />
<br />
To retrofit this behaviour we have to quickly discuss what <i>kill</i> actually does. This is what the man page says:<br />
<br />
<i>kill - send a signal to a process. </i><i>The default signal for kill is TERM.</i><br />
<br />
So when we kill <i>demoservice-starter.sh</i> we actually just send the TERM signal to the script. What we need to do now is to forward this signal to our child gunicorn process.<br />
<br />
This is what line 4 does: When the script receives a TERM signal it kills the gunicorn process which then lets our "wait" command continue to the end of the script.<br />
<br />
A quick note on line 2: Here we enable two features of the bash shell. "-a" automatically makes variables defined in the script available for child processes. Without "-a" we would need to prepend each variable in <i>demoservice.cfg </i>with a "export" statement.<br />
<br />
The other feature is "stop script on error" by using "-e". This is very useful also for build scripts to safe yourself from each time manually checking exit codes.<br />
<h4>
<br /></h4>
<h4>
demoservice.py</h4>
There is not much to say here. When the route path "/" of our demo service is accessed via HTTP GET we use Pythons "os.getenv" function to read the content of the environment variables and echo their content. <u>Remarkable </u>here is the usage of Pythons <a href="https://www.python.org/dev/peps/pep-0498/">Literal String Interpolation</a> on line 10 which was introduced in version 3.6.sambahttp://www.blogger.com/profile/11777176850583075015noreply@blogger.com2tag:blogger.com,1999:blog-3209185829378546515.post-70445764848767337372016-11-09T23:40:00.003+01:002016-11-09T23:40:23.135+01:00More active on twitter recentlyJust a quick one: I started using Twitter more often. You can find me here: <a href="https://twitter.com/@maik_toepfer">https://twitter.com/@maik_toepfer</a><br />
<br />sambahttp://www.blogger.com/profile/11777176850583075015noreply@blogger.com1tag:blogger.com,1999:blog-3209185829378546515.post-90067239657315451292016-11-09T23:38:00.000+01:002016-11-09T23:46:00.592+01:00Finished Haskell CourseI've finished the Haskell into course and stored <a href="https://github.com/samba2/my_courses/blob/master/haskell_course_notes.md">my notes on github</a>. I wouldn't say that I am a professional Haskell programmer but I gained the insides I was looking for. Also I used the course to read more about monads and in which context they are applied. In my notes I added the links to two sites I found especially useful.<br />
<br />
The future learn platform works similar to openSAP. Also here content is released weekly, I had the feeling that the discussion forums are used even more intensively which was a good thing.<br />
<br />
Here is the link to the certificate earned: <a href="http://www.futurelearn.com/certificates/r7udb4x">Link</a><br />
<br />
And again, while the course was running I found out about the next course: <a href="https://www.futurelearn.com/courses/internet-of-things">The Internet Of Things</a> provided by the <a href="http://www.kcl.ac.uk/index.aspx">King's college of London</a>. MOOC fever apparently never stops.<br />
<br />sambahttp://www.blogger.com/profile/11777176850583075015noreply@blogger.com0tag:blogger.com,1999:blog-3209185829378546515.post-52493769718867410012016-09-19T21:35:00.000+02:002016-09-19T21:35:00.647+02:00Haskell Course Has StartedJust received the mail that the Haskell course is taking off:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXIjNcwYfj0eTtqP6lKcr2cYRFK1uAnBBVOltu9nRbEKykWeWasTP_cRrse47u2-vQnZEMeooZCssKhb6lhyphenhyphenowjLQbhDCegtvZ0WrvhLrghShk5VRMz9vuKXrMYTBPwFdaaS6RK-zESquX/s1600/haskell_course_start.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="186" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXIjNcwYfj0eTtqP6lKcr2cYRFK1uAnBBVOltu9nRbEKykWeWasTP_cRrse47u2-vQnZEMeooZCssKhb6lhyphenhyphenowjLQbhDCegtvZ0WrvhLrghShk5VRMz9vuKXrMYTBPwFdaaS6RK-zESquX/s320/haskell_course_start.PNG" width="320" /></a></div>
I am really looking forward to de-mystify the mondads - now and forever.sambahttp://www.blogger.com/profile/11777176850583075015noreply@blogger.com0tag:blogger.com,1999:blog-3209185829378546515.post-36203758024125742392016-08-30T19:05:00.000+02:002016-08-30T19:05:00.162+02:00Socrates Conference 2016 - My notesLast weekend I attended <a href="https://www.socrates-conference.de/">the Socrates conference </a>in Soltau/ Germany again. Here are my notes of the two days.<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_d2_DmpeonWmr5DRL6616xPkOEt7O-w4s3ScfOUZjsEhzrUe5yuOEGbtKEujOa6rS_DdEEL-LfW7ZaOYxBZi-JbkQvcHGoPoz5WZPSpaEYXEm66pr3CalNyjoSd9VW0qP_9aqTJ4xchN7/s1600/socra_1.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="226" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_d2_DmpeonWmr5DRL6616xPkOEt7O-w4s3ScfOUZjsEhzrUe5yuOEGbtKEujOa6rS_DdEEL-LfW7ZaOYxBZi-JbkQvcHGoPoz5WZPSpaEYXEm66pr3CalNyjoSd9VW0qP_9aqTJ4xchN7/s320/socra_1.png" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Day 1</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLK5qTJhkpMesKjH-IA_fYGBCFZsOf3OY0-E2LZ93SMJzWZ6Np9-u_SzGZrio_OrEgl8MZrlUrGVhp-0i2jBnm2udmBfAfip0BIQ94ii59ngV5CLXG8WR-2tFlh6CK5C_yJH9Ner4_qcmY/s1600/socra_2.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="226" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLK5qTJhkpMesKjH-IA_fYGBCFZsOf3OY0-E2LZ93SMJzWZ6Np9-u_SzGZrio_OrEgl8MZrlUrGVhp-0i2jBnm2udmBfAfip0BIQ94ii59ngV5CLXG8WR-2tFlh6CK5C_yJH9Ner4_qcmY/s320/socra_2.png" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Day 2</td></tr>
</tbody></table>
<br />sambahttp://www.blogger.com/profile/11777176850583075015noreply@blogger.com0tag:blogger.com,1999:blog-3209185829378546515.post-3441838057506709062016-08-29T21:44:00.001+02:002016-08-29T21:44:35.831+02:00In MOOC Fever - Haskell @ Future LearnI just enrolled on the online Haskell class which starts at September, the 21th.<br />
<br />
Here is the link: <a href="https://www.futurelearn.com/courses/functional-programming-haskell">https://www.futurelearn.com/courses/functional-programming-haskell</a><br />
<br />
I eventually want to understand what does "monads" are all about.<br />
<br />sambahttp://www.blogger.com/profile/11777176850583075015noreply@blogger.com0tag:blogger.com,1999:blog-3209185829378546515.post-1656932181846370032016-07-23T16:30:00.000+02:002016-08-01T22:10:21.793+02:00Finished "Design For Non Designers" MOOC - My Second openSAP CourseWhile I was in the middle of <a href="https://we-press-buttons.blogspot.de/2016/07/finished-openui5-course.html" target="_blank">the OpenUI5 course </a>SAPs learning platform <a href="https://open.sap.com/" target="_blank">openSAP</a> announced a new course: "<a href="https://open.sap.com/courses/dfnd1-2/" target="_blank">Design for Non-Designers</a>". That sounded interesting then lets face it - the majority of the posts here are about really techie stuff - and not about typography and the likes.<br />
<br />
The course was a mix of an introduction into "Design Thinking" and basic design concepts. I learned about personas, storyboards and that prototyping on different level is both, important and fun at the same time. I found that the time was a good investment.<br />
<br />
I was glad that I could eventually get some grips on "Design Thinking". I already did a one day workshop at a conference last year but this was a bit pointless.<br />
<br />
<a href="https://github.com/samba2/my_courses/tree/master/design_for_non_designers" target="_blank">My course notes</a> are on github so if you are interest feel free to have a look. And yes of course, there is also a <a href="https://open.sap.com/verify/xonaf-citon-fipol-ravih-ciniv" target="_blank">record of achievement.</a><br />
<br />
<br />sambahttp://www.blogger.com/profile/11777176850583075015noreply@blogger.com0tag:blogger.com,1999:blog-3209185829378546515.post-51811352215914298382016-07-02T21:50:00.000+02:002016-08-01T22:26:13.125+02:00Finished OpenUI5 courseIn the last month <a href="http://openui5.org/" target="_blank">OpenUI5</a>, the open source version of SAPs own HTML5 framework got more and more popular in the enterprise world. Although compared to AngularJS it is still a niche product.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://openui5.org/resources/OpenUI5_text_below.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="" border="0" src="http://openui5.org/resources/OpenUI5_text_below.png" height="302" title="" width="320" /></a></div>
However, if your common task is to build "boring business web apps" than OpenUI5 might be something for you. It's a one stop shop. It supports coding following the MVC pattern, i18n internationalization, hundreds of controls (widgets), lots of high quality icons and so on.<br />
<br />
Their idea is that the main dependency of your business app is OpenUI5 and nothing else.<br />
<br />
I spend the last weeks with a massive open online course (MOOC) named <a href="https://open.sap.com/courses/ui51/" target="_blank">"Developing Web Apps with SAPUI5"</a>. Here 30k people from around the world learned how to program OpenUI5.<br />
<br />
I am glad to announce that I have finished the course and due to the extra task I did I belong to the best 5% - yes.<br />
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
You can find<a href="https://github.com/samba2/openui5_course" target="_blank"> my course notes on github.</a> The record of achievement is here: <a href="https://open.sap.com/verify/xesev-vuzec-hetyf-lebim-vovog">https://open.sap.com/verify/xesev-vuzec-hetyf-lebim-vovog</a></div>
<br />sambahttp://www.blogger.com/profile/11777176850583075015noreply@blogger.com0tag:blogger.com,1999:blog-3209185829378546515.post-85858520659086911982016-04-12T23:40:00.000+02:002016-04-12T23:40:02.616+02:00Avoiding Temporal Coupling - Part 2/2In <a href="http://we-press-buttons.blogspot.de/2016/04/avoiding-temporal-coupling-part-12.html" target="_blank">part one of this post</a> I briefly introduced the problems which come with <i>temporal coupling </i>and "passing a block"<i> </i>as a technique to overcome those problems. In this last part of the post I want to demonstrate "passing a block" in pure C.<br />
<br />
Lets start with a basic implementation:<br />
<pre class="brush: c">#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
typedef void (*FileCommandFunc)(FILE*);
int withFile(const char* fileName, const char* fileAccessMode,
FileCommandFunc func) {
FILE *myFile = fopen(fileName, fileAccessMode);
if (NULL == myFile) {
fprintf(stderr, "Error opening file '%s': %s\n",
fileName, strerror(errno));
return EXIT_FAILURE;
}
func(myFile);
fclose(myFile);
return EXIT_SUCCESS;
}
void printFirstLine(FILE* file) {
char buffer[1000] = {0};
if (fgets(buffer, sizeof(buffer), file)!=NULL) {
printf("%s", buffer);
}
}
void printWholeFile(FILE* file) {
char buffer[1000] = {0};
while (fgets(buffer, sizeof(buffer), file)!=NULL) {
printf("%s", buffer);
}
}
int main() {
withFile("demo.txt", "r", printFirstLine);
withFile("demo.txt", "r", printWholeFile);
}
</pre>
Function <i>withFile</i> takes three arguments: the name of the file to be opened, the access mode (read, write, append...) and a file command. The latter is a pointer to a function which accepts a file object as only argument.<br />
<br />
<i>printFirstLine </i>and <i>printWholeFile</i> are two example commands. Both employ <i>fgets</i> to traverse the file line by line.<br />
<br />
In <i>main</i> we see "passing a block" in action. File "demo.txt" is opened in read mode and the actions implemented in the command functions are executed against the file. Error handling and closing of the file handle takes place inside <i>withFile</i> - the user of the function doesn't have to bother with that.<br />
<br />
When coding this first draft I realized that my solution is quite limited. Inside the command you can only work with the file passed in and global variables. Other variables aren't simply accessible.<br />
<br />
With the GNU Compiler Collection <i>gcc </i>there is the <a href="https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html" target="_blank">nested functions </a> feature which nicely works around this limitation:<br />
<pre class="brush: c">int main() {
const char* header = "Content of demo.txt";
void printWholeFile(FILE* file) {
puts(header);
char buffer[1000] = {0};
while (fgets(buffer, sizeof(buffer), file)!=NULL) {
printf("%s", buffer);
}
}
withFile("demo.txt", "r", printWholeFile);
}
</pre>
I admit the example is a little bit constructed since you could easily print the header before the call of <i>withFile</i> but there you go. The idea is simple: Since <i>printWholeFile</i> is now defined inside <i>main,</i> <i>printWholeFile</i> has access to all global variables <u>and</u> the local variables of <i>main </i>as well.<br />
<br />
The downside of this is that it only works in <i>gcc</i>. Here is a more general implementation which uses a technique you find for example in the <a href="http://www.gnu.org/software/libc/manual/html_node/Comparison-Functions.html#Comparison-Functions" target="_blank">glibc comparision functions</a>. <br />
The command function accepts a second argument which is a void pointer. This allows us to pass anything into the command. We only have to cast it to the right type before using it. This is basically an accepted disabling of C's type checking.<br />
<br />
Here is the code:<br />
<pre class="brush: c">#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
// withFile.h
typedef void (*FileCommandFunc)(FILE*, void*);
typedef struct {
const char* name;
const char* accessMode;
FileCommandFunc func;
void* commandArgs;
} withFileArgs;
// withFile.c
int withFile(withFileArgs args) {
FILE *myFile = fopen(args.name, args.accessMode);
if (NULL == myFile) {
fprintf(stderr, "Error opening file '%s': %s\n",
args.name, strerror(errno));
return EXIT_FAILURE;
}
args.func(myFile, args.commandArgs);
fclose(myFile);
return EXIT_SUCCESS;
}
// production code
// the commands
void printFirstLine(FILE* file, void* commandArgs) {
const char* header = commandArgs;
puts(header);
char buffer[1000] = {0};
if (fgets(buffer, sizeof(buffer), file)!=NULL) {
printf("%s", buffer);
}
}
void printWholeFile(FILE* file, void* notUsed) {
char buffer[1000] = {0};
while (fgets(buffer, sizeof(buffer), file)!=NULL) {
printf("%s", buffer);
}
}
// using the commands
int main() {
withFile((withFileArgs){.name="demo.txt",
.accessMode="r",
.func=printFirstLine,
.commandArgs="Content of demo.txt"});
withFile((withFileArgs){.name="demo.txt",
.accessMode="r",
.func=printWholeFile});
}
</pre>
For convinces I've also replaced the growing number of arguments of <i>withFile</i> with something you call <i>configuration object</i> in Javascript, in C it is the beautiful marriage of <i>designated initializers</i> and <i>compound literals</i>, both introduced in C99.<br />
<br />
Also note that in function <i>printFirstLine</i> the cast from the void pointer <i>commandArgs </i>to the const char pointer <i>header</i> is implicit - no extra cast operation needed on the right hand side of the equals operator.sambahttp://www.blogger.com/profile/11777176850583075015noreply@blogger.com1tag:blogger.com,1999:blog-3209185829378546515.post-73585128683025042512016-04-11T22:20:00.000+02:002016-04-11T22:54:50.893+02:00We Love Code! - Eine popkulturelle Ode an das ProgrammierenIch wohne schon wirklich gern in dieser Stadt Leipzig. Alles da was man so von einer Großstadt erwartet und trotzdem übersichtlich wie früher auf dem Dorf. Und so kam es auch, dass mir "We Love Code! - Das kleine 101 des Programmierens" in die Hände fiel. "Da hat Natalie mit geschrieben - du weißt schon, meine ehemalige Mitbewohnerin" sagte unser Schlafgast.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://www.henschel-verlag.de/Files/Artikelbilder/978373380406.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://www.henschel-verlag.de/Files/Artikelbilder/978373380406.jpg" height="400" width="253" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Macht Spaß zu Lesen (<a href="http://www.henschel-verlag.de/Files/Artikelbilder/978373380406.jpg">Bildquelle</a>)</td></tr>
</tbody></table>
<br />
Ja, ich konnte mich erinnern. Social Media, HTML, CSS, später Ruby und viel Neugier auf den Rest. Drei Jahre später legen die <a href="http://codegirls.de/" target="_blank">Code Girls</a> Natalie Sontopski und Julia Hoffmann einen angenehm leichtgewichtigen Einstieg in die Welt der Programmierung vor.<br />
<br />
Die beiden Autorinnen nehmen den Leser bei der Hand und erklären mit Verve dass man (wie auch ich) eine Mathe-Niete sein kann und trotzdem ein passabler Programmierer, dass Programmiersprachen ähnlich viele Geschmacksfacetten haben wie die irdischen Variationen von Spagetti mit Tomatensoße und dass <i>C</i> Programmierer harte Kerle sind. Da sich mindestens 50% dieses Blogs mit mehr oder weniger obskuren C Programmiertechniken beschäftigt, fühlte ich mich zugegebener Maßen bei letztem Punkt gebauchpinselt.<br />
<br />
Außerdem leistet das Buch einen wichtigen Beitrag zur Idolbildung in der Geschichte bedeutender Programmier-Veteranen. Ada Lovelace, Grace Hopper (<i>It's easier to ask forgiveness than it is to get permission</i>) und andere bekommen extra Seiten gewidmet. Bravo. Im Pop wird fleißig zitiert und referenziert. Die dritte Generation von <a href="https://de.wikipedia.org/wiki/Joy_Division" target="_blank">Joy Division </a>T-Shirt Trägern bevölkert nun die Indie-Clubs. Höchste Zeit dass auch wir Nerds unsere Helden auf der Brust tragen, Beispiel gefällig?<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://d13z1xw8270sfc.cloudfront.net/origin/303242/1416242398645_alan-turing-man-machine-t-shirt.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://d13z1xw8270sfc.cloudfront.net/origin/303242/1416242398645_alan-turing-man-machine-t-shirt.jpg" height="320" width="239" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><a href="http://d13z1xw8270sfc.cloudfront.net/origin/303242/1416242398645_alan-turing-man-machine-t-shirt.jpg">Bildquelle</a></td></tr>
</tbody></table>
<br />
Und zu guter Letzt: Es handelt sich um ein schönes, aufwendig gedrucktes Buch. Wer will seinen Liebsten auch schon einen USB-Stick mit einer epub-Datei schenken? Vielleicht noch mit einem animierten GIF als Glückwunschkarte.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://femgeeks.de/wp-content/uploads/highlights.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="228" src="https://femgeeks.de/wp-content/uploads/highlights.jpg" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Es gibt Dinge die kann man nicht digitalisieren. Ein schönes Buch gehört dazu. (<a href="https://femgeeks.de/wp-content/uploads/highlights.jpg">Bildquelle</a>)</td></tr>
</tbody></table>
<br />
Fazit: Falls ihr Partner, Freunde oder Verwandte habt die die Welt in der ihr lebt faszinierend finden aber eigentlich nix davon verstehen: <i>We Love Code!</i> ist ein empfehlenswerter Einstieg, <a href="http://www.henschel-verlag.de/Buch/9783733804046-We-Love-Code" target="_blank">am Besten direkt vom Verlag gekauft</a>.<br />
<br />sambahttp://www.blogger.com/profile/11777176850583075015noreply@blogger.com0tag:blogger.com,1999:blog-3209185829378546515.post-45142576609410613272016-04-04T22:33:00.000+02:002016-04-04T22:33:50.980+02:00Avoiding Temporal Coupling - Part 1/2Every now and then we try to watch Uncle Bobs <a href="https://cleancoders.com/" target="_blank">cleancoders videos</a>. In episode 4, <a href="https://cleancoders.com/episode/clean-code-episode-4/show" target="_blank">"Function Structure"</a> the issue of <i>temporal coupling </i>is discussed. <i>Temporal coupling </i>is something we encounter quite often: to work with a database you first need to connect to the database. Next you do your work with the database and as the last step you disconnect. The same applies to working with a file: first you open it, then you perform your actions on the file handle/ object and when your done you close it.<br />
<br />
The order of this actions is important - you can't call the database disconnect method before you call the connect method. Also, those temporal couplings are often hidden in the background. Quite often some global init method created this database connection your are using for you, at least this is what you believe. When shutting down the application you are hoping that there is another magic method which closes the connection.<br />
<br />
In order to deal better with temporal coupling Uncle Bob suggests a technique called "passing a block". The idea is to allocate and to release resources at the point where you need it. The following pseudo code illustrates this approach:<br />
<pre class="brush: plain">withRessource(ressource, command):
allocate(ressource)
command(ressource)
release(ressource)</pre>
Python supports this pattern out of the box with its <a href="http://preshing.com/20110920/the-python-with-statement-by-example/" target="_blank">context manager </a>. Also Java 7 and following has <a href="https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html" target="_blank">a similar construct</a>.<br />
<br />
When looking at the pattern I immediately thought that implementing "passing a block" in plain C isn't too hard. Function pointers are your friend here. Wait for the second part of this post to see the implementation of <i>withFile</i>, a function which first opens a file, executes your desired actions and then closes this file.sambahttp://www.blogger.com/profile/11777176850583075015noreply@blogger.com0tag:blogger.com,1999:blog-3209185829378546515.post-31838279886497563222016-03-08T20:17:00.000+01:002016-03-09T21:36:10.107+01:00Professional Online WhiteboardingMy job involves explaining and discussing all sorts of things to people who are almost always situated remotely. Particularly, I like sketching and drawing - that's what we software people do at the end of the day: planing, discussing and implementing boxes and arrows between them.<br />
<br />
<b>Shortcomings Of Builtin Tools</b><br />
For a while I tried to use the builtin whiteboard tools together with the mouse as drawing device. This was inconvenient for a couple of reasons:<br />
<ul>
<li>drawn lines where usually quite edgy and appeared not natural</li>
<li>Microsoft Lync (nowedays <i>Skype for Business</i>) had some lag when I tried the whiteboard there</li>
<li>I never managed to freehand draw nicely with the mouse</li>
</ul>
<div>
<br />
<b>Inspired By A Worldwide Math Trainer</b><br />
At the end, I never used the builtin drawing facilities because I felt so limited. To overcome this I had a look what other people where doing. I ended up with <a href="https://khanacademy.zendesk.com/hc/en-us/articles/202483430-What-software-program-equipment-is-used-to-make-Khan-Academy-videos-" target="_blank">a similar setup like the Khan Academy</a>:</div>
<div>
<ul>
<li>Wacom Bamboo Tablet</li>
<li><a href="http://www.smoothdraw.com/" target="_blank">SmoothDraw </a>(Freeware for Windows) or as a better alternative</li>
<li><a href="https://www.sketchbook.com/?" target="_blank">Autodesk Sketchbook</a> (Free version is enough)</li>
</ul>
<div>
Note: The Wacom Bamboo series of tablet is discontinued and is succeeded by the <a href="http://www.wacom.com/en-us/products/pen-tablets/intuos" target="_blank">Intuos</a> series.<br />
<br />
Since I wasn't sure if this whole tablet drawing thing works out for me I went for a cheap used Wacom Bamboo One tablet which I bought for 15 € off ebay.</div>
</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijtAc8emH04C222_w5VkR3COxXRL3QPx4DbeAV7AmxUoGOFUZ_Ik-rPCiWBlTi13_LptLPrAf514qfv74MpUObcTnRn1YSh5MMq53h9LShXmpPqnnVjT35n2vnV1MQPTbbmvjk4rbTEsLn/s1600/wacom_bamboo_one.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijtAc8emH04C222_w5VkR3COxXRL3QPx4DbeAV7AmxUoGOFUZ_Ik-rPCiWBlTi13_LptLPrAf514qfv74MpUObcTnRn1YSh5MMq53h9LShXmpPqnnVjT35n2vnV1MQPTbbmvjk4rbTEsLn/s1600/wacom_bamboo_one.png" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">A Cheap Wacom Bamboo Tablet Is All To Get You Started</td></tr>
</tbody></table>
<b>Using The Drawing Tools</b><br />
Software wise I kicked off with <i>SmoothDraw </i>which is not a bad choice since it is free and it doesn't require admin rights for its installation. <br />
<br />
These days I use the free edition of <i>Autodesk Sketchbook</i> more often. Compared to SmoothDraw the same (limited) drawings of mine look much nicer here. Also the editing tools are way better with Sketchbook. For example, they have a Lasso selection which lets you draw the selected area and than easily move, turn or resize it.<br />
<br />
Pressing TAB toogles between the blank canvas and the tool bars. This is nice when presenting: To get the audiences full attention I usually present inside the blank canvas. Only when I need to change a tool or setting plus I can't remember the hotkey I quickly press TAB to get all the menus and then TAB again to return to the blank canvas.<br />
<br />
Talking about hotkeys or keyboard shortcuts: To become a fluent presenter it is advisable to know how to change between tools and colors by only using the keyboard. When I present, I draw with my right hand and use the left hand for pressing the hotkeys.<br />
<br />
<b>Airbrush For Visual Quick Wins</b><br />
Beside the pressure sensitive pen tip I really do love the airbrush tool. Once I am done with my boxes and arrows I highlight the important parts with a subtle colored airbrush. These makes to end result much more appealing and it is so simple to do.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijc9I0PugcmJ21YolS5bjPCrPdwskma01UC7JP1NgAgG5H8Lz6p95iR6o5rnOF2rlEBuL-KCPfW_41xO1O_P4KM2u2Jvz0bwmakbrDOurQG5TIc4VAk5POg3cmxh7-jRyFI2lKHL7YyXTh/s1600/tablet_drawing_example.png" imageanchor="1"><img border="0" height="225" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijc9I0PugcmJ21YolS5bjPCrPdwskma01UC7JP1NgAgG5H8Lz6p95iR6o5rnOF2rlEBuL-KCPfW_41xO1O_P4KM2u2Jvz0bwmakbrDOurQG5TIc4VAk5POg3cmxh7-jRyFI2lKHL7YyXTh/s400/tablet_drawing_example.png" width="400" /></a></div>
<br />
<b>Post Production With Gimp</b><br />
No matter what drawing tool I am using, I never use the full size of the canvas. Actually, I like to get started with a large canvas just to be sure I don't need to limit myself later on.<br />
<br />
When I want to share the results of a drawing session I usually export the images to <i>png</i> and then import it into <a href="https://www.gimp.org/" target="_blank">Gimp</a>. There I cut the canvas to the actual size of the image. Also I downscale the image to a size usable for online purposes.<br />
<br />
For this I zoom the image to a satisfying size (in percent). I then go to "Image > Scale Image". There I change the size unit from <i>px </i>to <i>percent. </i>I then enter the desired percentage I previously found out by zooming into the image.<br />
<br />
When I am done I usually use the "Export to original image" option (can't remember the right name) to overwrite my <i>png</i> with a version of the right size.<br />
<br />
<b>Conclusion</b><br />
I started my drawing experiment over a year ago. When I got the tablet I spend some evenings at home listening to good music and drawing (not only) boxes and arrows. This is also an advice for you: drawing with a tablet needs some time to get used to it. For enough self confidence for your free drawing presentation you better spend some time training which by the way is good fun anyway.<br />
<br />
For me these 15 € together with the evenings of good music and drawing training have paid off more than once. In a world of over designed Powerpoint presentations it makes a difference when you build up a topic just with the power of a pen.</div>
sambahttp://www.blogger.com/profile/11777176850583075015noreply@blogger.com0tag:blogger.com,1999:blog-3209185829378546515.post-33918680799090007692016-02-20T22:09:00.000+01:002016-02-20T22:10:41.878+01:00Software Craftmenship In Leipzig Is Picking Up PaceLast September <a href="http://we-press-buttons.blogspot.de/2015/09/software-craftsmanship-in-leipzig.html">I wrote about my attempt to host a local meetup</a> for the software craftsmen in my home town of Leipzig/ Germany. After a slow start things are recently going well.<br />
<br />
This week we had Alex of <a href="https://grossweber.com/">Grossweber</a> over how gave a very compact but at the same time well structured introduction to <i>git</i> and its advanced topics like <i>interactive rebase</i>. Up to this point my git knowledge was very basic but after this evening my understanding of this topic is much clearer. Good work Alex.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7Mpi3eW6exzrI31254Suy4cYb5HUVloWrBrcGckoFHnNUa5HnLaWlOvHGHuMeRx5dZTNCSMkZn6RnQhlBtyYgKbxpD1F-YtiI7mv3RzxXkHsaKD-26EuVCUodqwIFJF74yIfeqe4pib-S/s1600/2016-02-17+20.07.19.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="225" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7Mpi3eW6exzrI31254Suy4cYb5HUVloWrBrcGckoFHnNUa5HnLaWlOvHGHuMeRx5dZTNCSMkZn6RnQhlBtyYgKbxpD1F-YtiI7mv3RzxXkHsaKD-26EuVCUodqwIFJF74yIfeqe4pib-S/s400/2016-02-17+20.07.19.jpg" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="font-size: 12.8px;">git Session with Alex @ Makerspace Leipzig, 2016/02/17</td></tr>
</tbody></table>
We started to publish our events on two platform. Beside <a href="https://www.softwerkskammer.org/groups/sachsen">our native Softwerkskammmer page</a> we started using<a href="http://www.meetup.com/de-DE/Softwerkskammer-Leipzig/"> meetup.com </a>as well. I suppose being a meetup.com event helped use to constantly increase our attendees. Last week we where almost 30 people and I had to limit the subscription to the event. A couple of month back we where always below 10 people - how quickly things change...<br />
<br />
<br />sambahttp://www.blogger.com/profile/11777176850583075015noreply@blogger.com0tag:blogger.com,1999:blog-3209185829378546515.post-25382247173270120842016-02-18T21:45:00.000+01:002016-02-18T21:46:01.943+01:00"pragma once" as a better alternative for guard clausesAn include guard is a very popular and incredibly useful hack:<br />
<br />
<i>... an #include guard, sometimes called a macro guard, is a particular construct used to avoid the problem of double inclusion when dealing with the include directive. (<a href="https://en.wikipedia.org/wiki/Include_guard">Link</a>)</i><br />
<br />
Example:<br />
<pre class="brush: c">// person.h
#ifndef PERSON_H
#define PERSON_H
typedef struct {
char* first_name;
char* last_name;
int age;
} person;
#endif /* PERSON_H*/
</pre>
The idea is to let the C preprocessor only evaluate the guarded code if the global symbol <i>PERSON_H</i> is not defined. Since line 3 defines <i>PERSON_H</i> as the very first step the person struct is guaranteed to be seen only once at compilation time.<br />
<br />
It is simple macro programming but so popular that an IDE like Eclipse CDT auto-generates the include guard for you. You can even choose different naming schemes.<br />
<br />
But this technique also has some downsides:<br />
<ul>
<li>three lines of extra code</li>
<li>potential name clashes if there is another <i>person.h</i> in an included project</li>
</ul>
<div>
The latter one can be worked around with improved naming schemes like adding the path to the symbol name (<i>#define MY_PROJECT_SRC_PERSON_H) </i>or using a simple random number (<i>#define DF454FSKWDLD) </i>but stop - this hack is getting worse and worse.</div>
<br />
Luckily there is a solution for quite some time now called <i>#pragma once</i>. The above example looks rewritten like this:<br />
<pre class="brush: c">// person.h
#pragma once
typedef struct {
char* first_name;
char* last_name;
int age;
} person;
</pre>
<i>The ‘<samp>#pragma</samp>’ directive is the method specified by the C standard for providing additional information to the compiler, beyond what is conveyed in the language itself. [<a href="https://gcc.gnu.org/onlinedocs/cpp/Pragmas.html">Link</a>].</i><br />
<br />
And this is what <i>#pragma once </i>does:<br />
<i>#pragma once is a non-standard but widely supported preprocessor directive designed to cause the current source file to be included only once in a single compilation. [<a href="https://en.wikipedia.org/wiki/Pragma_once">Link</a>]</i><br />
<i><br /></i>
The Wikipedia page which provides this quote gives also a list of compilers which provide this feature. If you're not forced to compile under Solaris studio you're fine.sambahttp://www.blogger.com/profile/11777176850583075015noreply@blogger.com0tag:blogger.com,1999:blog-3209185829378546515.post-32516929335765372802016-01-24T07:55:00.000+01:002016-02-18T21:08:37.602+01:00Printing boolean values in CSince the <i>bool</i> type in C is nothing else than an integer, a naive printout of the number will also just produce a number. This little trick gives you a text representation of the boolean value:<br />
<pre class="brush: c">bool status = true;
printf("The status is %s", status ? "TRUE" : "FALSE");
</pre>
<br />
The ternary operator is evaluated first. Since the value of <i>status</i> is <i>true</i> the string <i>TRUE</i> is the second argument of our printf.<br />
<br />
So the output is:<br />
<pre class="brush: plain">This status is TRUE
</pre>
sambahttp://www.blogger.com/profile/11777176850583075015noreply@blogger.com0tag:blogger.com,1999:blog-3209185829378546515.post-18004575695292043422016-01-21T07:47:00.000+01:002016-01-21T07:47:40.384+01:00Infrastructure As Code - Some Lessons LearnedI used the last days of 2015 to automate the installation of our C development environment. Here are some of the ingredients:<br />
<ul>
<li><a href="https://eclipse.org/cdt/">Eclipse CDT</a></li>
<li><a href="https://github.com/buntatsu/cdt-proc">Eclipse ProC - Extensions</a>. Required to let Eclipse CDT understand ancient *.pc files</li>
<li><a href="https://code.google.com/a/eclipselabs.org/p/workspacemechanic/">Google Workspace mechanics plugin</a> to offer team wide default settings in Eclipse</li>
<li>some other Eclipse plugins like <i>subclipse</i>, <i>Vrapper </i>(vi keyboad layout or Eclipse)...</li>
<li>Oracle Client including header files and pre-compiler</li>
<li>...</li>
</ul>
<div>
Due to this long list of required tools and plugins setting up our development environment is quite complex. After <a href="http://stackoverflow.com/questions/33731512/provision-developer-workspace-ide-inside-virtual-machine">asking for some clarification on the right too</a>l for the job I went for Vagrant.</div>
<div>
<br /></div>
<div>
10 days later the result was as expected. I am now able to say <i>vagrant up</i> and (if running for the first time) a basebox from an internal repository is downloaded and Vagrant is then running all the shell scripts I've written to install the above. This is called to <i>provisioning</i> step and takes place only once.</div>
<div>
<br /></div>
<div>
Coding the infrastructures I found my self dealing with some of the issues I only knew from ordinary coding so far.<br />
<br /></div>
<div>
<h3>
External Dependencies</h3>
</div>
<div>
<br /></div>
<div>
When installing software which was not provided in a nice repository (Oracle client and Eclipse ProC extension for example) I had to decide if the install scripts download some version of the software from the internet or if I should add a specific version to my Vagrant project and keep it.</div>
<div>
<br /></div>
<div>
I went for the latter. To reduce external dependencies (=download links at the Internet) I have the required archives and binaries locally under version control. If I want to update the software, I manually need to download the newer version and let it replace the older version.</div>
<div>
<br /></div>
<div>
Inside my scripts I always tried to use wildcards when it came down to file names. The goal was that a version update does not require an update of the provisioning shell scripts. A simple overwrite of the old version with the new version should do.<br />
<br />
<pre class="brush: plain">ECLIPSE_PURE_SDK="/vagrant/files/eclipse-SDK-*-linux-*_64.tar.gz"
...
tar xvzf ${ECLIPSE_PURE_SDK}
</pre>
<h3>
<br /></h3>
<h3>
Feedback Loop</h3>
</div>
<div>
<br />
The general approach to codify my infrastructure setup was very similar to the way I usually go forward:<br />
<ol>
<li>write new code or correct existing code</li>
<li>let it compile (optional, only required for compiled languages of course)</li>
<li>execute</li>
<li>find the error</li>
<li>start from beginning</li>
</ol>
<div>
Translated into the world of Vagrant this is:</div>
<div>
<ol>
<li>write a new installation task or correct an erroneous existing one</li>
<li>let Vagrant provision (=execute) the installation tasks</li>
<li> find the error in the installation tasks</li>
<li>start from beginning</li>
</ol>
<div>
Particularly the second step, provisioning the Vagrant box was painfully slow. It took about 5-7 minutes to finish this step. Going forward in small incremental steps this means a lot of 5-7 minutes forced breaks.</div>
</div>
<div>
<br /></div>
<div>
This time I accepted these waiting times. For the next bigger infrastructure coding job I will definitely try out one of the configuration management tools (Ansible, Puppet, Chef...). All of them give me something really helpful I was lacking this time - idempotence:</div>
<div>
<br /></div>
<i>... operations [...], that can be applied multiple times without changing the result beyond the initial application. (<a href="https://en.wikipedia.org/wiki/Idempotence">Wikipedia</a>)</i><br />
<div>
<br /></div>
My imaginary updated Vagrant cycle would then look like this:<br />
<div>
</div>
<ol>
<li>write a new installation task or correct an erroneous existing one</li>
<li>execute all installation tasks, only the new or updated once run</li>
<li>find the error in the installation tasks</li>
<li>start from beginning</li>
</ol>
<div>
This should save me a lot of time since here only the differences of the configuration tasks are executed.</div>
<div>
</div>
</div>
<div>
<br /></div>
sambahttp://www.blogger.com/profile/11777176850583075015noreply@blogger.com0tag:blogger.com,1999:blog-3209185829378546515.post-46724705615892344742015-11-27T21:44:00.000+01:002015-11-30T10:07:20.847+01:00Thoughts On "SE-Radio Episode 242: Dave Thomas on Innovating Legacy Systems"In <a href="http://www.se-radio.net/2015/11/se-radio-episode-242-dave-thomas-on-innovating-legacy-systems/" target="_blank">episode 242</a> Software Engineering Radio interviewed <a href="http://www.davethomas.net/" target="_blank">Dave Thomas </a>about how to deal with legacy systems. I liked the show so much that I had to do a sketchnote:<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><span style="margin-left: auto; margin-right: auto;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhI6DJx7wjqK8iIANjyG5J0Ju4rGq0mBRS7RfiGMFcuJTTjdYM67UaOhccjBRQbzqF9PUF2BTtChyPr-tNxtuOYDyzB8yreHW4d62amt86kjJhyphenhyphendOCMxfpAFwnJ0JGijd76ADS6GKVcEe0F/s1600/242_sketchnote_low_res.png" target="_blank">
<img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhI6DJx7wjqK8iIANjyG5J0Ju4rGq0mBRS7RfiGMFcuJTTjdYM67UaOhccjBRQbzqF9PUF2BTtChyPr-tNxtuOYDyzB8yreHW4d62amt86kjJhyphenhyphendOCMxfpAFwnJ0JGijd76ADS6GKVcEe0F/s500/242_sketchnote_low_res.png" /></a>
</span></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Controversial And Very Inspiring At The Same Time - SE Radio 242 with Dave Thomas<br />
<br /></td></tr>
</tbody></table>
Actually I am a faithful follower of <a href="http://www.amazon.com/Working-Effectively-Legacy-Michael-Feathers/dp/0131177052" target="_blank">Working Effectively With Legacy Code</a> : isolate the piece of code you want to change (dependency breaking), write tests for it and then modify the code using TDD. Over time I got quite good at it - even in C. However, it's a lot of effort - even when you're trained.<br />
<div>
<br /></div>
<div>
Dave sayed "Unit tests are a waste of time, focus on acceptance test" (end-to-end tests). The problem with end-to-end tests is that they are even harder to setup. Instead of mocking the objects around you, you have to provide all the external dependencies or at least good replacements: test databases, test middleware, test clients...</div>
<div>
</div>
<div>
Anyway, once you've managed all that and wrote your first end-to-end test, things are getting easier a lot. Covering "unhappy paths" with tests is now actually quite simple - drop a central database table, switch of the middleware, send faulty messages to your application and check what's going on.</div>
<div>
<br />
With all this virtualization (docker as latest hype) and infrastructure as code (Puppet, Chef, ...) we now have got good tools to write end-to-end tests which are repeatable, automated and maintainable.<br />
Surely this was not as simple in 2004 when "Working Effectively With Legacy Code" came out.<br />
<br />
Dave's statements reminded of <a href="http://blog.adrianbolboaca.ro/2014/05/golden-master/" target="_blank">the Golden Master approach</a> which is quite similar. However, the initial end-to-end tests there is only meant to provide the basic safety net towards a unit test coverage. The latter one is the actual goal of "Golden Master" testing.<br />
<br />
So yes, maybe going from outside to inside is nowadays a better way of creating a safety net. I am still not convinced to ditch unit testing of old code completely but this is as always something you have to try out.</div>
<div>
<br /></div>
sambahttp://www.blogger.com/profile/11777176850583075015noreply@blogger.com0tag:blogger.com,1999:blog-3209185829378546515.post-76685845566147558772015-11-25T22:25:00.000+01:002015-11-27T21:07:44.508+01:00Something For The Toolshelf - Code Analysis Tools Used For Security Analysis Of TruecryptRecently the <i>Bundesamt für Sicherheit in der Informationstechnik (</i>BSI), an authority of the German government released a <a href="https://www.bsi.bund.de/DE/Presse/Pressemitteilungen/Presse2015/Sicherheitsanalyse_TrueCrypt_19112015.html" target="_blank">security analysis of Truecrypt</a>. This analysis was carried out by the <i>Fraunhofer-Institut für Sichere Informationstechnologie </i>(SIT) in Darmstadt /Germany. This institute is part of the<a href="https://en.wikipedia.org/wiki/Fraunhofer_Society" target="_blank"> Frauenhofer society </a>- a research organization spread across Germany.<br />
<br />
From a software engineering perspective I was curious what approach the researches took to evaluate the code code base.<br />
<h4>
</h4>
<h4>
</h4>
<h4>
GOTO</h4>
Apparently also the Truecrypt authors liked their goto. The study on goto (my translation):<br />
<br />
<i>To implement exception handling the usage of goto is generally accepted since the language C does not offer an own feature for that. New research concludes that meanwhile programmers are predominantly using goto in a sensible way.</i><br />
<br />
<i>Die Verwendung von goto wird jedoch im Allgemeinen zur Umsetzung einer Ausnahmebehandlung akzeptiert, da die Sprache C kein eigenes Konstrukt hierfür kennt. Neuere Untersuchungen haben ergeben, dass Programmierer mittlerweile die goto-Anweisung überwiegend nur noch in sinnvoller Weise verwenden. </i>(original)<br />
<div>
<br /></div>
<div>
On that topic the study quotes <i><a href="https://peerj.com/preprints/826v1/" target="_blank">An empirical study of goto in C</a>, </i>a paper which was pre-released in February 2015 and which was subject of my previous post.</div>
<h4>
</h4>
<h4>
</h4>
<h4>
Complexity Of The Source Code</h4>
To measure complexity the authors of the study employed a tool called <i><a href="https://github.com/terryyin/lizard" target="_blank">Lizard</a> </i>which can deal with a bunch of languages including C, C++, Java, Python and Javascript<i>. </i><br />
<i><br /></i>
Here is the feature list taken from the Github page of <i>Lizard</i>:<br />
<ul>
<li>the nloc (lines of code without comments),</li>
<li>CCN (cyclomatic complexity number),</li>
<li>token count of functions.</li>
<li>parameter count of functions.</li>
</ul>
<br />
<div>
As their measure of complexity the study uses the cyclomatic complexity:</div>
<div>
<br /></div>
<div>
<i>As a measure for the complexity of the flow of control especially the cyclomatic complexity is being used. Values higher than 15 are an indicator for potential refactoring. Values above 30 are usually accompanied by flawed code. </i>(my translation)</div>
<div>
<br /></div>
<div>
<i>Als Maß für die Kontrollflusskomplexität wird insbesondere die zyklomatische Komplexität verwendet. Werte größer 15 sind ein Indiz dafür, dass Refaktorierung sinnvoll ist. Werte über 30 gehen oft mit fehlerhaftem Code einher. </i>(original)</div>
<br />
<h4>
Code Duplicates</h4>
<div>
To find identical pieces of source code the autors of the study use <a href="http://duplo.sourceforge.net/" style="font-style: italic;" target="_blank">Duplo</a>, a duplicate finder for C and C++. With its default settings the tools consideres three and more identical lines of code as duplicates. </div>
<h4>
</h4>
<h4>
</h4>
<h4>
Static Code Analysis</h4>
<div>
For this kind of analysis three tools where used: <i>Coverity</i>, <i>Cppcheck </i>and the <i>Clang Static Analyzer</i>. The interesting point here is that there where almost no overlaps in the errors found by the three tools. Which brings me to the conclusion that it is a sensible investment to integrate more than one static analyzer in the Continuous Integration chain.</div>
<div>
<br /></div>
sambahttp://www.blogger.com/profile/11777176850583075015noreply@blogger.com0tag:blogger.com,1999:blog-3209185829378546515.post-26229595897248099312015-11-23T21:06:00.000+01:002015-11-23T21:06:00.055+01:00Rehabilitating C's gotoI admit - I regularly write goto's. Actually almost all non-<a href="https://en.wikipedia.org/wiki/Pure_function" target="_blank">pure functions</a> see at least one goto. For always the same reason: Handling errors and cleaning up resources. <a href="http://we-press-buttons.blogspot.com/2014/01/poor-mans-error-handling-with-goto.html">I already wrote about the technique</a> 1 1/2 year ago.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDl-PYI5xvpUNo_BQ0QyS3dSS9Uve4p8sK1WVAjPiKB6BTtnYQaOo6nkGnN-subP2uQAJzKB9IUE5FhtSXHefjTSP_TgoFkkjvBIlqHu5KpqhnYj3kwK30F4F0XVIxinhyMSercBg6Ugtu/s1600/goto_example_paper.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDl-PYI5xvpUNo_BQ0QyS3dSS9Uve4p8sK1WVAjPiKB6BTtnYQaOo6nkGnN-subP2uQAJzKB9IUE5FhtSXHefjTSP_TgoFkkjvBIlqHu5KpqhnYj3kwK30F4F0XVIxinhyMSercBg6Ugtu/s1600/goto_example_paper.PNG" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<i>Example For Error Handling And Cleanup using goto <a href="https://peerj.com/preprints/826v1/" target="_blank">[1]</a></i></div>
<div>
<br /></div>
In my eyes the usage of goto for cleanup and error handling is a good thing. The flow of application logic is not unnecessarily cluttered with local error handling. Instead the function is divided into two parts: The upper part which contains the application logic and the lower part which contains the error handling and the cleanup of resources.<br />
<br />
However, using these goto's always left me feel like doing something in the gray zone: There is an old ban from the 60ies (<i>Letters to the Editor: Go To Statement Considered Harmful</i>, Dijkstra, 1968) but without talking to much about it in public C programmers still carry on writing goto.<br />
<div>
<br /></div>
The paper <a href="https://peerj.com/preprints/826v1/" style="font-style: italic;" target="_blank">An Empirical Study of goto in C Code</a> releases as a pre-print in February 2015 now takes an interesting second look at this old ban.<br />
<br />
The international group of researches who was involved in the paper analyzed 2 million lines of C code collected from 11K Github repositories. I leave the reading of the entire paper up to you and jump directly to the important part of the conclusion:<br />
<br />
<i>...far from being maintenance nightmares, most usages </i><i>of goto follow disciplined, well-designed usage patterns, </i><i>that are handled by specific constructs in more modern </i><i>languages. </i><br />
<i>The most common pattern are error-handling and </i><i>cleanup, for which exception handling constructs exist in </i><i>most modern languages, but not in C. Even properties such </i><i>as several goto statements jumping to the same label have </i><i>benefits, such as reducing code duplication, in spite of the </i><i>coordinate problem described by Dijkstra.</i><br />
<br />
That sounds like good news to me - I eventually can exit the gray zone.sambahttp://www.blogger.com/profile/11777176850583075015noreply@blogger.com0tag:blogger.com,1999:blog-3209185829378546515.post-44152227221591024622015-10-25T23:01:00.000+01:002015-10-25T23:08:33.830+01:00Slides For "Not Your Fathers C - C Application Development in 2015"Before going on a too short vacation I attended the <a href="https://devopenspace.de/" target="_blank">Developer Open Space</a> conference in my home town Leipzig. As the conference name suggests this was an <a href="https://en.wikipedia.org/wiki/Open_Space_Technology" target="_blank">Open Space conference</a> where the participants them self create the agenda for the day.<br />
<br />
I held a session on modern C development which was a high level summary of my past posts here. The slides are now online:<br />
<br>
<iframe src="//de.slideshare.net/slideshow/embed_code/key/AiwYj6uzge44rl" width="510" height="420" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" style="border:1px solid #CCC; border-width:1px; margin-bottom:5px; max-width: 100%;" allowfullscreen> </iframe> <div style="margin-bottom:5px"> <strong> <a href="//de.slideshare.net/maiktoepfer/not-your-fathers-c-c-application-development-in-2015" title="Not Your Fathers C - C Application Development In 2015" target="_blank">Not Your Fathers C - C Application Development In 2015</a> </strong> from <strong><a href="//www.slideshare.net/maiktoepfer" target="_blank">maiktoepfer</a></strong> </div>sambahttp://www.blogger.com/profile/11777176850583075015noreply@blogger.com0tag:blogger.com,1999:blog-3209185829378546515.post-21362400890366811672015-09-30T21:38:00.000+02:002015-09-30T21:38:00.170+02:00Software Craftsmanship in LeipzigI started <a href="https://www.softwerkskammer.org/groups/sachsen" target="_blank">hosting the meeting of the Leipzig branch</a> of the German software craftsmanship community <i><a href="https://www.softwerkskammer.org/" target="_blank">Softwerkskammer</a></i>. This is also a reason why I am short on blog posts here. Anyway, it's good fun. We try to team with the hardware nerd at <a href="http://makerspace-leipzig.de/" target="_blank">Makerspace Leipzig</a> by meeting us at there premises. We think this is a better fit than meeting in some companies (clean) office environment.<br />
<br />sambahttp://www.blogger.com/profile/11777176850583075015noreply@blogger.com0tag:blogger.com,1999:blog-3209185829378546515.post-36210846435030804092015-09-29T21:30:00.000+02:002015-09-29T21:30:00.078+02:00Markdown PresentationsI plan to do offer a session on modern C development called <i>Not Your Fathers C</i> at the <a href="https://devopenspace.de/" target="_blank"><i>Developer Open Space </i>conference</a> in Leipzig/ Germany. For that purpose I was looking for a way to prepare slides not in some proprietary format like Powerpoint but in pure text which is rendered to something nice.<br />
<br />
After one evenings search engine investigation for me the way to go forward is <a href="https://github.com/gnab/remark" target="_blank">remark</a> which lets you create Markdown based presentations which can also be run offline. Very neat.<br />
<br />sambahttp://www.blogger.com/profile/11777176850583075015noreply@blogger.com0tag:blogger.com,1999:blog-3209185829378546515.post-23839921403841298272015-09-26T21:23:00.003+02:002015-09-26T21:49:09.357+02:00Socrates 2015 - What the f**kI'm a IT professional for over a decade now - but I've never attended something like this before:<br />
<br />
A colleague and me took part at the <a href="https://www.socrates-conference.de/" target="_blank">Socrates 2015 conference</a>. It's an Open Space conference which mean there is no agenda at the beginning. Just an empty flipchart which if filled with self-proposed topics of the participants at the beginning of each conference day.<br />
No pop star like speakers but people like you and me how admit "I am not the expert but I've done something in that field and I want to share this knowledge with you." For me this is all you need - for everything more involved there are books.<br />
<br />
While thinking about the conference I was astonished how much I've either learned or was pushed towards something. Here is my top 5:<br />
<br />
<ol>
<li><a href="http://www.thegraphicrecorder.com/wp-content/uploads/2013/02/Sketchnotes-of-Maria-Popova-Interview-on-Design-Matters-with-Debbie-Millman.jpg" target="_blank">Sketchnotes</a>. This is for me "Doing something more with the whiteboard than the usual stuff without needing to be an artist." I believe in the area of Powerpoint spoilt organisations it makes a huge difference to develop a topic just with a flipchart and a pen. It's amazing how much you can do. I love it.</li>
<li><a href="http://blog.codeclimate.com/blog/2014/03/20/kickstart-your-next-project-with-a-walking-skeleton/" target="_blank">Walking Skeleton</a>. I never heard of this topic before. It's basically an approach to build up a system not from inside out but from outside to the inside, guided by so called end-to-end tests as well as unit tests. The book to read on that topic is <i><a href="http://www.amazon.de/Growing-Object-Oriented-Software-Guided-Signature/dp/0321503627" target="_blank">Growing Object Oriented Software Guided By Tests</a></i>. <a href="https://www.softwerkskammer.org/activities/24._Treffen_der_Softwerkskammer_Muenchen" target="_blank">People </a>refer to the approach as "London School Of TDD" (the authors of that book are based in London) in contrast to the "Chicago School Of TDD" which is TDD as we know it (Kent Beck, Uncle Bob). Really interesting.</li>
<li><a href="https://nothingisoutofreach.files.wordpress.com/2011/05/5458592375_6b1415aafd_o.jpg" target="_blank">Personal Kanban</a>. I was once again pushed to think about my time management method. I attended a session about <i>Knowledge Management</i> but we soon found out the the key is actually <i>Time Management</i>. So one of the attendees offered a session about time management the next day. It all was about the guys <i>Getting Things Done</i> interpretation. Anyway, during the discussion I was reminded on the existence of <i>Personal Kanban, </i>and this is what I am trying out at the moment, all analog!. There will be a post with a nice picture somewhen later.</li>
<li><a href="http://blog.adrianbolboaca.ro/2014/04/legacy-coderetreat/" target="_blank">Legacy Code Retreat</a>. I spent quite some time wadding into muddy legacy C code. I thought I am quite good at this topic but <a href="http://blog.adrianbolboaca.ro/" target="_blank">this guy</a> who hosted a 2 hour session an how to attack lagacy code was somewhere else. Really impressive. I've done some handson training for a<a href="http://blog.adrianbolboaca.ro/2014/05/golden-master/" target="_blank"> Golden Master Test</a>. Also, training people to deal with legacy code can be simplified by using <a href="http://blog.adrianbolboaca.ro/2014/04/legacy-coderetreat/" target="_blank">Adrians work</a>.</li>
<li>I had a chat with somebody at dinner how was working for a software consultancy run as a cooperative. Basically, they have no boss and decide all together how they want the company to proceed. This was really thrilling, I was just about to hand in my CV but they are based in the wrong city ;-).</li>
</ol>
<div>
Overall the conference was much more than I expected. In my hometown Leipzig/ Germany there will be the <a href="https://devopenspace.de/" target="_blank">Developer Open Space</a> conference in some weeks, run also as an Open Space event - this time I plan to prepare something my self. Working title "<i>Not Your Father's C</i>".<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvS3m5_V5N7-965y6R6J1GrRa1q0-qQQTOm4elel1e8bEkgWX3ReAhDy2nPS5IJ6q61uM-qMhBmdcNwRIb6hgrP-Tq8d-cI9c24gadpcRC77278waxF-T_DJ4utcH84omPDn8xkBwvpoEF/s1600/make_lovee.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvS3m5_V5N7-965y6R6J1GrRa1q0-qQQTOm4elel1e8bEkgWX3ReAhDy2nPS5IJ6q61uM-qMhBmdcNwRIb6hgrP-Tq8d-cI9c24gadpcRC77278waxF-T_DJ4utcH84omPDn8xkBwvpoEF/s1600/make_lovee.jpg" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Yes - there were also some hippies ;-)</td></tr>
</tbody></table>
<br /></div>
<div>
<br /></div>
sambahttp://www.blogger.com/profile/11777176850583075015noreply@blogger.com0tag:blogger.com,1999:blog-3209185829378546515.post-10243443162105317802015-08-04T10:37:00.000+02:002015-08-04T10:37:00.087+02:00Uncle Bob On VideosFor those of you who are even later than me: <a href="https://en.wikipedia.org/wiki/Robert_Cecil_Martin" target="_blank">Uncle Bob</a>, famous for his <a href="https://books.google.de/books/about/Clean_Code.html?id=dwSfGQAACAAJ" target="_blank">Clean Code</a> book has produced a series of one hour videos which cover the topics of the book - but in a very funny and at the same time educational way: <a href="https://cleancoders.com/category/clean-code" target="_blank">Clean Code Videos</a>sambahttp://www.blogger.com/profile/11777176850583075015noreply@blogger.com0tag:blogger.com,1999:blog-3209185829378546515.post-45511017618094739002015-08-02T10:27:00.000+02:002015-08-02T10:27:00.106+02:00Bash syntax checkWhen automating your administrative tasks also shell scripts are checked in to a version control system. The built-in command line argument <i>-n </i>allows a syntax check of the shell script without executing it:<br />
<br />
<pre class="brush: plain">$ bash -n myScript.sh
$ echo $?
0
</pre>
If the syntax check is successful nothing is displayed and the exit code is <i>0</i>.
However, if there is an error (like in the following case a missing parenthesis) an error message is printed and the exit code is <i>2</i>:<br />
<pre class="brush: plain">$ bash -n myScript.sh
./myScript.sh: line 23: syntax error: unexpected end of file
$ echo $?
2
</pre>
When checking your scripts in that way inside your continuous delivery pipeline it is easy to spot simple type errors.sambahttp://www.blogger.com/profile/11777176850583075015noreply@blogger.com0