<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Benjamin Mahr</title>
    <description>The latest articles on DEV Community by Benjamin Mahr (@ben1980).</description>
    <link>https://dev.to/ben1980</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F164250%2F63b289fc-f30e-411c-808c-c0aea64b45a7.png</url>
      <title>DEV Community: Benjamin Mahr</title>
      <link>https://dev.to/ben1980</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ben1980"/>
    <language>en</language>
    <item>
      <title>Introduction of myself and my blog thoughts-on-cpp.com</title>
      <dc:creator>Benjamin Mahr</dc:creator>
      <pubDate>Sat, 11 May 2019 19:29:44 +0000</pubDate>
      <link>https://dev.to/ben1980/introduction-of-myself-and-my-blog-thoughts-on-cpp-com-2e0p</link>
      <guid>https://dev.to/ben1980/introduction-of-myself-and-my-blog-thoughts-on-cpp-com-2e0p</guid>
      <description>&lt;p&gt;Hello everyone,&lt;br&gt;
I was told it would be nice to introduce myself..... hmmm well how shall I do that.&lt;br&gt;
OK, I'm a C++/Qt software developer (with a background in mechanical engineering) and head of software development at &lt;a href="https://www.kisssoft.ch/english/home/index.php"&gt;KISSsoft AG&lt;/a&gt; in Switzerland. We are producing a leading calculation and design software for mechanical engineering, especially transmission gearboxes. I'm mainly focusing on the development of numerical calculations for contact pattern analysis of gearboxes, but also responsible for the development infrastructure and leading the development team.&lt;/p&gt;

&lt;p&gt;In my spare time, I'm writing on my blog &lt;a href="https://thoughts-on-cpp.com"&gt;thoughts-on-cpp.com&lt;/a&gt; about programming and software development in general. I'm mostly focusing on topics such as implementations of numerical methods. I would be happy if you sign up and follow my blog.&lt;/p&gt;

&lt;p&gt;You can also reach me via:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; &lt;a href="https://github.com/ben1980"&gt;GitHub&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt; &lt;a href="https://twitter.com/@benmahr"&gt;Twitter&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt; &lt;a href="https://www.facebook.com/benmahr1980/"&gt;Facebook&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt; &lt;a href="https://www.linkedin.com/in/benjamin-mahr-728a1639/"&gt;LinkedIn&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Best regards,&lt;br&gt;
Ben&lt;/p&gt;

</description>
      <category>introduction</category>
    </item>
    <item>
      <title>Introduction into C++ Builds with Gradle</title>
      <dc:creator>Benjamin Mahr</dc:creator>
      <pubDate>Wed, 10 Apr 2019 06:00:39 +0000</pubDate>
      <link>https://dev.to/ben1980/introduction-into-c-builds-with-gradle-52f6</link>
      <guid>https://dev.to/ben1980/introduction-into-c-builds-with-gradle-52f6</guid>
      <description>&lt;p&gt;Posted on &lt;a href="https://thoughts-on-cpp.com" rel="noopener noreferrer"&gt;thoughts-on-cpp.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Welcome back to a new post on thoughts-on-cpp.com. In today’s post, I would like to give an introduction to the build system &lt;a href="https://gradle.org" rel="noopener noreferrer"&gt;Gradle&lt;/a&gt; and how we can use it to build native applications and libraries. Gradle is originally coming from the Java world, but it’s also supporting native build toolchains for quite a while. Gradle is becoming more and more popular in the Java world and is on a good way to rule out the old bull &lt;a href="https://maven.apache.org/" rel="noopener noreferrer"&gt;Maven&lt;/a&gt;. This is because of two features which we can also benefit from in the native (C/C++, Objective-C/C++, Assembly, and Windows resources) build world. These features are Gradle’s easy to maintain and very expressive Groovy (or Kotlin if preferred) based &lt;a href="https://en.wikipedia.org/wiki/Domain-specific_language" rel="noopener noreferrer"&gt;DSL&lt;/a&gt;, and it’s capabilities of dependency resolving via online and on-premise library providers (such as maven-central, Artifactory, Bintray, etc.) or local repositories.&lt;/p&gt;

&lt;p&gt;Let’s start with a &lt;a href="https://github.com/Ben1980/gradleNativ" rel="noopener noreferrer"&gt;multi-project example&lt;/a&gt; we already know from my post &lt;a href="https://dev.to/ben1980/introduction-into-an-automated-c-build-setup-with-jenkins-and-cmake-do-temp-slug-5798207"&gt;Introduction into an Automated C++ Build Setup with Jenkins and CMake&lt;/a&gt;. I have just slightly changed the example hello world application. This time the main function is printing out “Hello World!” onto console using a shared library, called greeter. The Greeter class itself is utilizing the external library &lt;a href="http://fmtlib.net/latest/index.html" rel="noopener noreferrer"&gt;{fmt}&lt;/a&gt; to print “Hello World” onto the screen. If you’ve wondered about the Gradle directory and files, those are provided by the Gradle wrapper which facilitates us to build the project without even installing Gradle upfront.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;The Gradle native build plugin is quite straight forward to configure. Every Gradle project needs a build.gradle file at its root directory as an entry point and one at each subproject. In most cases, we will do general configurations in a build.gradle file located at the root directory. But there is no need, it can also be empty. By default, Gradle is looking for sources in the directory &lt;code&gt;src/main/cpp&lt;/code&gt;. For libraries, public headers are defined in &lt;code&gt;src/main/public&lt;/code&gt; and in case they should be used only library internal (private) the default directory is &lt;code&gt;src/main/headers&lt;/code&gt;. In case we define the headers also in &lt;code&gt;src/main/cpp&lt;/code&gt;, the headers are treated as private as well. If we like to overwrite the default source directories we just need to define them according to this &lt;a href="https://github.com/gradle/native-samples/blob/master/cpp/swift-package-manager/build.gradle#L9-L17" rel="noopener noreferrer"&gt;example&lt;/a&gt;. To be able to resolve dependencies between subprojects, we need to define a settings.gradle file which is including our subprojects &lt;code&gt;include 'app', 'greeter', 'testLib'&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;components.withType(ProductionCppComponent) { 
//By convention, source files are located in the root directory/Sources/
source.from rootProject.file("Sources/${subproject.name.capitalize()}") 
privateHeaders.from rootProject.file("Sources/${subproject.name.capitalize()}/include") 
} 
components.withType(CppLibrary) { 
//By convention, public header files are located in the root directory/Sources//include 
publicHeaders.from rootProject.file("Sources/${subproject.name.capitalize()}/include") 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;As build definition of our root directory we just simply define IDE support for each subproject. &lt;a href="https://www.jetbrains.com/clion/" rel="noopener noreferrer"&gt;CLion&lt;/a&gt;, for example, has native Gradle support, so importing Gradle projects works smooth as silk. Therefore our root build.gradle file looks like the following.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;allprojects { 
apply plugin: 'xcode' 
apply plugin: 'visual-studio' 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The application build configuration is defined at the app directory starting with calling the &lt;a href="https://docs.gradle.org/current/javadoc/org/gradle/language/cpp/CppApplication.html" rel="noopener noreferrer"&gt;&lt;code&gt;cpp-application&lt;/code&gt;&lt;/a&gt; plugin which is generating an executable file which can be found and executed at &lt;code&gt;app/build/install/main/{buildType}/{machine}&lt;/code&gt;. Project internal dependencies can be defined by the &lt;code&gt;dependencies&lt;/code&gt; clause with the implementation of the dependency defined as a project and the given name of the dependency. By default, Gradle is assuming the current host as target machine. If we want to consider other target machines we have to declare them as we do in our example with the &lt;a href="https://docs.gradle.org/current/javadoc/org/gradle/language/ComponentWithTargetMachines.html#getTargetMachines--" rel="noopener noreferrer"&gt;&lt;code&gt;targetMachines&lt;/code&gt;&lt;/a&gt; statement.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;The library build configuration is defined at the greeter directory starting with calling the &lt;a href="https://docs.gradle.org/current/javadoc/org/gradle/language/cpp/CppLibrary.html" rel="noopener noreferrer"&gt;&lt;code&gt;cpp-library&lt;/code&gt;&lt;/a&gt; plugin and the type of &lt;a href="https://docs.gradle.org/current/javadoc/org/gradle/nativeplatform/Linkage.html" rel="noopener noreferrer"&gt;linkage&lt;/a&gt;, which can be STATIC and SHARED. Gradle is assuming we want SHARED libraries as default. A bit special is the way of how we have to resolve the dependency to the header only library {fmt}. Unfortunately, Gradle is not supporting header only libraries out of the box, but we can accomplish a workaround by adding the include path to the &lt;code&gt;includePathConfiguration&lt;/code&gt; of the resulting binary. All other dependencies can be defined as &lt;code&gt;api&lt;/code&gt;, in case we want to share the external dependency api with all consumers of our own defined library, or &lt;code&gt;implementation&lt;/code&gt; in case we only want to use the dependency api private with our own library. A good example can be found in Gradle’s &lt;a href="https://github.com/gradle/native-samples" rel="noopener noreferrer"&gt;example repository&lt;/a&gt;.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;With Gradle, we can not only build applications and libraries, but we can also execute tests to check the resulting artifacts. A test can be defined by the &lt;code&gt;cpp-unit-test&lt;/code&gt; plugin which is generating a test executable. In principle, we could use any of the existing big test libraries, such as &lt;a href="https://github.com/google/googletest" rel="noopener noreferrer"&gt;googletest&lt;/a&gt;, but in my opinion, the out of the box solution is pretty neat and lightweight and can be extended quite easily with external libraries.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;With this project setup, we can build all artifacts by the command &lt;code&gt;./gradlew assemble&lt;/code&gt; and run tests by &lt;code&gt;./gradlew check&lt;/code&gt;. If we want to build and run all tests together we can invoke &lt;code&gt;./gradlew build&lt;/code&gt;. In case we need a list of all available tasks provided by Gradle and its plugins we can simply list them including their description by the command &lt;code&gt;./gradlew tasks&lt;/code&gt;. At &lt;a href="https://github.com/Ben1980/gradleNativ" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; you can find the resulting repository.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthoughtsoncpp.files.wordpress.com%2F2019%2F04%2Fgradlebuild.gif%3Fw%3D800" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthoughtsoncpp.files.wordpress.com%2F2019%2F04%2Fgradlebuild.gif%3Fw%3D800" alt="gradlebuild"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;UPDATE: Thanks to &lt;a href="https://twitter.com/lacasseio" rel="noopener noreferrer"&gt;D. Lacase&lt;/a&gt; I updated the source set configuration section to customize the folder structure of a project.&lt;/p&gt;

&lt;p&gt;Did you like the post?&lt;/p&gt;

&lt;p&gt;What are your thoughts?&lt;/p&gt;

&lt;p&gt;Feel free to comment and share this post.&lt;/p&gt;

</description>
      <category>codeproject</category>
      <category>programming</category>
      <category>buildautomation</category>
      <category>cpp</category>
    </item>
    <item>
      <title>Introduction into an Automated C++ Build Setup with Jenkins and CMake</title>
      <dc:creator>Benjamin Mahr</dc:creator>
      <pubDate>Wed, 27 Mar 2019 07:00:12 +0000</pubDate>
      <link>https://dev.to/ben1980/introduction-into-an-automated-c-build-setup-with-jenkins-and-cmake-4ob2</link>
      <guid>https://dev.to/ben1980/introduction-into-an-automated-c-build-setup-with-jenkins-and-cmake-4ob2</guid>
      <description>&lt;p&gt;Postet on &lt;a href="https://thoughts-on-cpp.com" rel="noopener noreferrer"&gt;thoughts-on-cpp.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Welcome back to a new post on thoughts-on-cpp.com. This time I would like to give an introduction into an automated build setup which, based upon &lt;a href="https://jenkins.io/" rel="noopener noreferrer"&gt;Jenkins&lt;/a&gt; and &lt;a href="https://cmake.org/" rel="noopener noreferrer"&gt;CMake&lt;/a&gt;, fulfills the following needs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Building a ready to deploy release on every commit&lt;/li&gt;
&lt;li&gt;Execution of all tests&lt;/li&gt;
&lt;li&gt;Running static code analysis to track code quality&lt;/li&gt;
&lt;li&gt;And easy to extend with automated deployment (CD)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For all the necessary sources, I prepared a &lt;a href="https://github.com/Ben1980/jenkinsexample" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; repository. We are focusing here only on a technical part of an automated build process which is a prerequisite of a CI/CD (Continues Integration/Continues Deployment) process. It is quite a bit more necessary than just tools for a company to fully embrace the ideas behind a CI/CD process but with an automated build and test setup your on a good way.&lt;/p&gt;

&lt;p&gt;The build, of a Qt and C++ based example desktop application, will be orchestrated by &lt;a href="https://jenkins.io/doc/book/pipeline/syntax/" rel="noopener noreferrer"&gt;Jenkins declarative pipeline&lt;/a&gt;. The example application is based on a simple CMake project generated with &lt;a href="https://www.jetbrains.com/clion/" rel="noopener noreferrer"&gt;CLion&lt;/a&gt;. As static code analysis tool, we are using &lt;a href="http://cppcheck.sourceforge.net" rel="noopener noreferrer"&gt;cppcheck&lt;/a&gt;. Testing is done with my favorite testing framework &lt;a href="https://github.com/catchorg/Catch2" rel="noopener noreferrer"&gt;Catch2&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In this post, I presume your already familiar with a basic Jenkins setup. If you’re not familiar with Jenkins, &lt;a href="https://jenkins.io" rel="noopener noreferrer"&gt;jenkins.io&lt;/a&gt; is a good source of information.&lt;/p&gt;

&lt;p&gt;Jenkins consists of a declarative pipeline defined in a file called Jenkinsfile. This file has to be located in the projects root folder. The declarative pipeline of Jenkins is based upon &lt;a href="http://groovy-lang.org/" rel="noopener noreferrer"&gt;Groovy&lt;/a&gt; as a &lt;a href="https://en.wikipedia.org/wiki/Domain-specific_language" rel="noopener noreferrer"&gt;DSL&lt;/a&gt; and provides a very expressive way to define a build process. Even though the DSL is very mighty because it is based on Groovy you can actually write little scripts, its documentation is, unfortunately, a bit mixed up with its predecessor, the scripting-based pipeline. For our example setup, it’s looking the following way.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;The syntax is pretty straight forward. A Jenkinsfile starts always with the declaration of a pipeline block, followed by the declaration of an &lt;a href="https://jenkins.io/doc/book/pipeline/syntax/#agent" rel="noopener noreferrer"&gt;agent&lt;/a&gt;. An agent describes on environment our build should be executed. In our case, we want it on any environment setup, but it could be also a labeled or a &lt;a href="https://www.docker.com/" rel="noopener noreferrer"&gt;docker&lt;/a&gt; environment.&lt;/p&gt;

&lt;p&gt;With the &lt;a href="https://jenkins.io/doc/book/pipeline/syntax/#options" rel="noopener noreferrer"&gt;options&lt;/a&gt; directive, we define that we want to keep the last 10 build artifacts and code analysis results. With options we could also define a general build timeout, the number of retries we allow in case of a build failure, or the timestamp for console output while running the build.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://jenkins.io/doc/book/pipeline/syntax/#parameters" rel="noopener noreferrer"&gt;parameters&lt;/a&gt; directive provides us the possibility to define arbitrary build parameters of the types &lt;strong&gt;string&lt;/strong&gt; , &lt;strong&gt;text&lt;/strong&gt; , &lt;strong&gt;booleanParam&lt;/strong&gt; , &lt;strong&gt;choice&lt;/strong&gt; , &lt;strong&gt;file, ** and **password&lt;/strong&gt;. In our case, we use &lt;strong&gt;booleanParam&lt;/strong&gt; to provide the user with an option to define which additional stages the user wants to execute in case of a manual execution of the project.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthoughtsoncpp.files.wordpress.com%2F2019%2F03%2Fjenkinsparameters.png%3Fw%3D800" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthoughtsoncpp.files.wordpress.com%2F2019%2F03%2Fjenkinsparameters.png%3Fw%3D800" alt="jenkinsParameters"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But even if those configuration possibilities of Jenkins are vast and very interesting, the really important part of the build declaration file is defined by the &lt;a href="https://jenkins.io/doc/book/pipeline/syntax/#stages" rel="noopener noreferrer"&gt;stages&lt;/a&gt; section with its &lt;a href="https://jenkins.io/doc/book/pipeline/syntax/#stage" rel="noopener noreferrer"&gt;stage&lt;/a&gt; directives. With an arbitrary number of possible stages, we have all the freedom to define our build process as we need to. Even &lt;a href="https://jenkins.io/doc/book/pipeline/syntax/#parallel" rel="noopener noreferrer"&gt;parallel&lt;/a&gt; stages, for example, concurrent execution of testing and static code analysis, are possible.&lt;/p&gt;

&lt;p&gt;With the first stage, “Build”, we are instructing Jenkins to invoke its CMake-Plugin to generate our build setup and resolving all necessary dependencies via a &lt;a href="https://github.com/Microsoft/vcpkg" rel="noopener noreferrer"&gt;Vcpkg&lt;/a&gt; CMake file. Afterward, the build is executed with &lt;code&gt;cmake --build .&lt;/code&gt; through the &lt;code&gt;withCmake: true&lt;/code&gt; setting. User-defined toolchains are also no problem so we could have also defined several build setups with GCC, Clang and Visual Studio Compiler.&lt;/p&gt;

&lt;p&gt;The other stages, Test, Analyse and Deploy, are again pretty straight forward. All of them have one notable thing in common which is the &lt;a href="https://jenkins.io/doc/book/pipeline/syntax/#when" rel="noopener noreferrer"&gt;when&lt;/a&gt; directive. With this directive, we can control if a stage gets executed if the condition inside the curly braces returns true. In our case, we use the when directive to evaluate the build parameters we introduced at the beginning of this post. The syntax might be a bit irritating at first glance but after all, it does its job.&lt;/p&gt;

&lt;p&gt;To get Jenkins executing our nice pipeline we just need to tell it from which repository to pull. This can be done via the project configuration. Here you just need to choose the option ‘Pipeline script from SCM’. If everything is set up correctly you end up with a smooth running automated build process. Even better, if you have configured Jenkins correctly and it has a static connection to the internet, you can connect Jenkins to GitHub over a &lt;a href="https://developer.github.com/webhooks/" rel="noopener noreferrer"&gt;Webhook&lt;/a&gt;. This means that GitHub will invoke a build every time someone pushed a commit to the repository.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthoughtsoncpp.files.wordpress.com%2F2019%2F03%2Fjenkinssourcecontrolconnection.png%3Fw%3D800" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthoughtsoncpp.files.wordpress.com%2F2019%2F03%2Fjenkinssourcecontrolconnection.png%3Fw%3D800" alt="jenkinsSourceControlConnection"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To conclude this post I would like to point out that this isn’t &lt;strong&gt;THE BEST WAY&lt;/strong&gt; to configure automated builds. It is one way of millions possible. And it’s the way which worked out pretty well for me in my daily work. I introduced an adapted version of this several years ago in our company and Jenkins is serving us great since then. One important fact of Jenkins declarative pipeline is the point that it’s versioned over the SCM as the rest of the code is, and that’s a very important feature.&lt;/p&gt;

&lt;p&gt;Did you like the post?&lt;/p&gt;

&lt;p&gt;What are your thoughts?&lt;/p&gt;

&lt;p&gt;Feel free to comment and share the post.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>tools</category>
      <category>buildautomation</category>
      <category>cpp</category>
    </item>
    <item>
      <title>Weekly Knowledge Candy</title>
      <dc:creator>Benjamin Mahr</dc:creator>
      <pubDate>Thu, 21 Mar 2019 13:58:24 +0000</pubDate>
      <link>https://dev.to/ben1980/weekly-knowledge-candy-2hla</link>
      <guid>https://dev.to/ben1980/weekly-knowledge-candy-2hla</guid>
      <description>&lt;p&gt;Postet on &lt;a href="https://thoughts-on-cpp.com"&gt;thoughts-on-cpp.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Welcome back to a new post at thoughts-on-cpp. This time I will write about something different, not quite technical and C++ related. Well, not exactly. It’s a post about team education, about how to evolve the C++ knowledge of a team which is, in my case, not build up with computer science experts, but purely with domain experts (in my development team we are all mechanical engineers or mathematicians). You may ask, why the hell are they doing software engineering only with domain experts? This will be for sure another blog post, I promise, to talk about this.&lt;/p&gt;

&lt;p&gt;I’m working in this company for quite a while, basically since I finished my studies of mechanical engineering. But have I’ve been prepared for the professional development of desktop applications? Well…… not really. Back in university, we had C++ seminars for about a year, and the fact that we have been taught C++ was quite new in 2008. If you have studied mechanical engineering before, you would have been probably taught how to code in &lt;a href="https://en.wikipedia.org/wiki/Fortran"&gt;Fortran&lt;/a&gt; 77, or if you’re lucky in Fortran 95. And basically, the level of programming in C++ was the same as it was in the good old Fortran days. No classes, no encapsulation, no C++ idioms, just pure procedural programming. They just exchanged the syntax and the compiler, that’s it. Clearly, the intention was not to fully educate us in the domain of programming, but I think it’s also a bad idea, if not a dangerous one, to give students such a primitive bunch of half knowledge. And that’s in principle what you get as programming background in classical engineering areas (electrical engineers might be on a higher level). You end up with a team in which C++ knowledge is very heterogeneous. From pure procedural programming with bare knowledge about the STL, to very experienced/self-educated people who are firm with advanced metaprogramming and memory management topics. So somehow there has to be a way to raise the level of programming knowledge for everyone. Not only the most proactive developers, but also the ones which are simply not able, for so many reasons, to raise their programming skills.&lt;/p&gt;

&lt;h3&gt;
  
  
  How Weekly Knowledge Candy Originated
&lt;/h3&gt;

&lt;p&gt;One day I stumbled upon Jonathan Boccara’s blog &lt;a href="https://www.fluentcpp.com/"&gt;Fluent {C++}&lt;/a&gt;. And there was one small page on the side, called &lt;a href="https://www.fluentcpp.com/dailycpp/"&gt;Daily C++&lt;/a&gt;. Johnathan states that you learn the best while your teaching, and I totally agree with my own experience of teaching in seminars. So I thought it would be a good idea to somehow adapt his concept of Daily C++ to our needs and introducing it into the company. Many of his ideas work nicely for us. For example the short 10 to 20 minute presentations and fine granular topics which fit into the time frame. We just felt that having daily presentations, even such short ones would be too exaggerating for us. Once a week would be fine because, with only 17 developers, everyone would have at least a week to prepare him-/herself. To start we carried a list of topics together we wanted to introduce or deepen our knowledge. Not only C++, but also topics about patterns, established architectures, frameworks, tools, but well… mostly C++. We ended up with a list of around 20 presentations topics, such as RAII, Rule of zero/three/five, operator overloading, memory management, observer and factory pattern, and much more. We encourage the developers to pick a topic and prepare it to present in any way they like. That can be on a whiteboard, PowerPoint, purely code, or most often a mixture of several forms. The only requirement is that the topic is documented and self-explanatory. That way developers who haven’t been able to attend can read it whenever they like. The second and last requirement is that everyone should try to pick the topic he’s/she’s the most unfamiliar with. Picking the topic they have the weakest knowledge gives the developers the opportunity to learn and earn the most out of the weekly’s because it’s not just a simple repetition for them. Contrarily to Jonathan’s approach we always gather in a dedicated and equipped meeting room. We experienced an increase in attention and broader discussions afterward. Additional I think a dedicated room is not only helping to focus but also it’s much quieter. Noise can really be a big problem in large open-plan offices.&lt;/p&gt;

&lt;p&gt;Let’s summarize the benefits of the Weekly Knowledge Candy:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Little easy digestible topics&lt;/li&gt;
&lt;li&gt;Developers train their ability to give presentations and speeches&lt;/li&gt;
&lt;li&gt;10 to 20 minutes focus helps to understand a topic&lt;/li&gt;
&lt;li&gt;Every developer is focusing on his weakest topics. This way the whole team is gaining the most benefits.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Did you like the post?&lt;/p&gt;

&lt;p&gt;What are your thoughts?&lt;/p&gt;

&lt;p&gt;Feel free to comment and share the post.&lt;/p&gt;

</description>
      <category>nonprogramming</category>
      <category>bestpractice</category>
      <category>cpp</category>
    </item>
    <item>
      <title>Introduction into Logging with Loguru</title>
      <dc:creator>Benjamin Mahr</dc:creator>
      <pubDate>Tue, 12 Mar 2019 06:00:11 +0000</pubDate>
      <link>https://dev.to/ben1980/introduction-into-logging-with-loguru-2bak</link>
      <guid>https://dev.to/ben1980/introduction-into-logging-with-loguru-2bak</guid>
      <description>&lt;p&gt;Postet on &lt;a href="https://thoughts-on-cpp.com"&gt;thoughts-on-cpp.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This time I would like to give a short introduction into a nice little library I just encountered. It’s called &lt;a href="https://github.com/emilk/loguru/blob/master/README.md"&gt;loguru&lt;/a&gt; and it’s a lightweight, Thread-Safe, logging library with an impressive good written &lt;a href="https://emilk.github.io/loguru/index.html"&gt;documentation&lt;/a&gt; and human-readable output.&lt;/p&gt;

&lt;p&gt;To use it all you need to do is to add a single header and source file to compile with. Unfortunately, that’s, in my opinion, also a drawback. Yes, it’s easier to install and usable in training, but it can’t be exchanged by whoever is operating the system after deployment. In such cases, where the operator wants to define how and what to use for logging, a generic logging interface (facade pattern), such as &lt;a href="https://archive.codeplex.com/?p=slf4cxx"&gt;slf4cxx&lt;/a&gt; which is similar to its java pendant &lt;a href="https://www.slf4j.org"&gt;slf4j&lt;/a&gt;, would be preferable.&lt;/p&gt;

&lt;p&gt;Loguru is supporting a various number of features, such as callbacks for logging and fatal errors, verbosity levels, assertions and aborts, and stack traces in case of aborts. It even supports &lt;a href="https://github.com/fmtlib/fmt"&gt;{fmt}&lt;/a&gt;. Everyone who ever was used to java/spring log outputs will recognize its similarities.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;As you can see it’s pretty straight forward to use. We are not only logging several messages on INFO verbosity level, but also a message in a named thread called “complex lambda”. If we wouldn’t have defined the thread name with loguru::set_thread_name(“complex lambda”), loguru would state the name of a thread with a hex id. The main thread gets its name by calling loguru::init(…). Because our small tool is crashing, loguru is printing us a stack trace which in my opinion is not as helpful as expected, but with ERROR_CONTEXT we get a little better output.&lt;/p&gt;

&lt;p&gt;That’s it for now with this post. We have now a short introduction into a, until now, rather unknown, but promising, logging library. Loguru is not only capable of producing Thread-Safe and human readable logging messages but also provides a very simple and handy interface to use.&lt;/p&gt;

&lt;p&gt;Did you like the post?&lt;/p&gt;

&lt;p&gt;What are your thoughts?&lt;/p&gt;

&lt;p&gt;Feel free to comment and share the post.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>cpp</category>
      <category>introduction</category>
    </item>
    <item>
      <title>Using Pointer to Members on STL Algorithms</title>
      <dc:creator>Benjamin Mahr</dc:creator>
      <pubDate>Fri, 22 Feb 2019 05:00:12 +0000</pubDate>
      <link>https://dev.to/ben1980/using-pointer-to-members-on-stl-algorithms-29o1</link>
      <guid>https://dev.to/ben1980/using-pointer-to-members-on-stl-algorithms-29o1</guid>
      <description>&lt;p&gt;Postet on &lt;a href="https://thoughts-on-cpp.com"&gt;thoughts-on-cpp.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sometimes I need to execute an operation, like std::sort or std::transform, on a container of structs or objects using a lambda or function pointers which should take type defined criteria. Another scenario might be a global minima search of an arbitrary brane which could be described by a vector of 3-dimensional vectors. In such cases, we often use &lt;a href="https://stackoverflow.com/questions/670734/pointer-to-class-data-member"&gt;pointer to members&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This topic might be a piece of cake for every experienced C++ veteran. But I remember back in the days when I was a novice, I was really irritated by a piece of code which was using pointer to members, to do a special operation. I didn’t get what that piece of sh*t was doing and why it was written that wired. And even worse, it was neither easy to find documentation of that code, nor information of such “magic” it was doing on the internet.&lt;/p&gt;

&lt;p&gt;So how might something like this look like? Let’s say we have a vector of complex numbers which we want to sort by either the real or the imaginary number. This is our complex type:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;For sorting vectors, we would use &lt;a href="https://en.cppreference.com/w/cpp/algorithm/sort"&gt;std::sort&lt;/a&gt; of course and for vectors of primitive types, it’s rather simple to use. And indeed, it’s easy to use with complex types as well. Because std::sort is offering an interface which is taking a compare function object that has to fulfill the requirements of &lt;a href="https://en.cppreference.com/w/cpp/named_req/Compare"&gt;Compare&lt;/a&gt;:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Using std::sort for sorting according to real or imaginary numbers might then look like this:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;The interesting point in the code above is the declaration of double Complex::*var (pointer to member of Complex of type double), in line 6, which is passed to the lambda over the captures clause. The lambda function is using the pointer by dereferencing it to a comparable type (in our case a double) in line 7. It’s then used by assigning it a concrete pointer in line 9 and 12 to steer the std::sort algorithm.&lt;/p&gt;

&lt;p&gt;For me, such indirections are sometimes quite useful but not always. The biggest problem might be the readability for programming beginners. Also, there might be a better way to have the same functionality without pointers to members. I would be glad to hear any suggestions or feedback.&lt;/p&gt;

&lt;p&gt;Did you like this post?&lt;/p&gt;

&lt;p&gt;What are your thoughts on this post?&lt;/p&gt;

&lt;p&gt;Feel free to comment and share the post.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>algorithms</category>
      <category>cpp</category>
    </item>
  </channel>
</rss>
