<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>c &amp;mdash; musicmatzes blog</title>
    <link>https://beyermatthias.de/tag:c</link>
    <description></description>
    <pubDate>Thu, 03 Dec 2026 19:00:38 +0100</pubDate>
    <item>
      <title>Rust is one of the best C replacements we currently have</title>
      <link>https://beyermatthias.de/rust-is-one-of-the-best-c-replacements-we-currently-have</link>
      <description>&lt;![CDATA[This is a reply to the article&#xA;published by Drew DeVault called&#xA;&#34;Rust is not a good C replacement&#34;.&#xA;&#xA;---&#xA;&#xA;First of all, let me say that Drew is one of the people out there on the&#xA;internet whose opinions I highly value. Indeed he is one of the people I try&#xA;to read and listen to regardless of topic, because I think he is one of the&#xA;people that deserve unconditional attention.&#xA;&#xA;Needless to say that I&#39;ve also read his latest piece&#xA;&#34;Rust is not a good C replacement&#34;.&#xA;I have to admit I was shocked at first, but after a bit of cooling down (and&#xA;doing the dishes), I can see where this comes from.&#xA;&#xA;And I have to disagree.&#xA;&#xA;But let me start with my background - because that might be important for you,&#xA;dear reader, to classify this article.&#xA;&#xA;My background is mostly hobbyist programming. I did a few years of C, probably&#xA;a few 100kloc, not more. I also do rust since about&#xA;Rust 1.5.0 (2015-12).&#xA;I started a job where I expect to write C and C++ professionally about 1 month&#xA;ago.&#xA;&#xA;So, I do not have a background like Drew with probably millions of lines of&#xA;C, but I guess that I have a bit more experience with Rust - I wouldn&#39;t say&#xA;that I&#39;m a Rust professional, but I would consider myself a &#34;Advanced Rust&#xA;Hobbyist&#34;.&#xA;&#xA;I&#39;m also not as skilled in writing blog articles or even with the english&#xA;language, so keep that in mind when reading this.&#xA;&#xA;---&#xA;&#xA;I am not a big fan of statement-by-statement replying to an article, but&#xA;I guess for this type of article it is good enough.&#xA;&#xA;First of all, Drews initial statement that Rust was designed by C++&#xA;programmers: Yes, I absolutely see that this is true. Nevertheless I have to&#xA;say that these C++ programmers started developing Rust because C++ was too&#xA;complex and too error-prone in what it did and how it did it.&#xA;Rust is far away from the complexity C++ gives us in terms of language&#xA;features!&#xA;From the top of my head, we have&#xA;&#xA;A full-blown OOP programming paradigm, including&#xA;  Overloading&#xA;  &#34;friends&#34;&#xA;  (multi-)inheritance&#xA;  abstract classes&#xA;  partly and fully virtual functions&#xA;  pointers and references&#xA;  implicit conversions&#xA;  Copy/Move constructors&#xA;  Dynamic and static polymorphism&#xA;Manual memory management&#xA;Template Metaprogramming / Generic programming&#xA;operator overloading&#xA;Lambda expressions&#xA;Exceptions&#xA;&#xA;in C++, whereas in Rust we only get&#xA;&#xA;Dynamic and static polymorphism&#xA;operator overloading&#xA;Lambda expressions&#xA;Generic programming&#xA;&#xA;()&#xA;&#xA;You might consider this list cheated as Rust is not an object oriented&#xA;language like C++, but an imperative one like C. That is very true.&#xA;Nevertheless it is one reason why the cognitive load a C++-Program requires&#xA;one to handle is much higher than an equivalent (as in features of the&#xA;program) Rust program!&#xA;&#xA;Drew claims that the values of C and C++ programmers are incompatible and I&#xA;would agree with that. But that does not (have to) mean that a C-programmer&#xA;and a Rust programmer do not have the same values.&#xA;It is true, though, that Rust can excel at a lot of topics that C++ covers,&#xA;but it also empower programmers that do not feel comfortable writing good C&#xA;code to write their software. And that in a safe and at the same time&#xA;performant language while not being overly blown up.&#xA;&#xA;Further Drew compares C, C++, Go and Rust by their complexity, measured with&#xA;features introduced in the language over the years.&#xA;I am really sorry to say this here, Drew, but we are used to much better from&#xA;you! You say that this approach (bullet points/features listed on wikipedia&#xA;vs. bullet points in articles and release notes) is not very scientific, yes.&#xA;But not even to mention the years these languages were released! For the&#xA;record:&#xA;&#xA;C was released in 1972; 47 years ago)&#xA;C++ was released in 1985; 35 years ago&#xA;Go was released in 2009; 9 years ago)&#xA;Rust was released in 2010; 8 years ago)&#xA;&#xA;I am not saying that this disproves your statement - it even supports it! But&#xA;I do say that comparing based on features per year/release/whatever must&#xA;include a statement about how old these languages are, even if it is just for&#xA;showing the reader about what timeframe we are talking.&#xA;&#xA;So, Rust is a relatively young language and yes, it has added a lot of&#xA;features and therefore can be compared to C++ much better than it can be to C.&#xA;But saying that a 10-year-old C programm might even compile today and&#xA;everything might be okay but not so much with Rust is just ignorant of the&#xA;fact that Rust is not even that old.&#xA;Having a Rust program that is one year old still compiles fine today (assuming&#xA;it didn&#39;t use a compiler bug) and does not &#34;look old&#34; at all!&#xA;Rust has a big infrastructure for doing regression tests and for being&#xA;compatible with older programs.&#xA;&#xA;As you say, out of the way with the philosophical stuff and lets get down to&#xA;the facts.&#xA;&#xA;C is more portable.&#xA;But as mentioned before, C is almost six times as old as Rust. We&#39;ll get there!&#xA;&#xA;C has a spec. Yes, and I completely hear you on this one. Rust does not&#xA;(yet?) have a spec and it really is a pain-point. I want one, too! Maybe we&#39;ll&#xA;get there at some point.&#xA;By the way: Does Go have a spec? It&#xA;seems like it, but that rather looks like a&#xA;language definition and I doubt that this is what Drew meant when talking&#xA;about &#34;a spec&#34;, is it?&#xA;&#xA;C has many implementations. Yes and how much trouble has it been because&#xA;different compilers do different things on undefined behaviour?&#xA;Too many. This is where Rust tries to solve a problem: Get a language where&#xA;undefined behaviour is not allowed or at least as minimal as possible, then we&#xA;can have a spec for that language and then we can have different&#xA;implementations.&#xA;Time will tell whether we can get there.&#xA;&#xA;C has a consistent &amp; stable ABI. Point taken. I do not argue about that.&#xA;&#xA;Cargo is mandatory. Yes, another point taken. I again do not argue.&#xA;&#xA;Concurrency is generally a bad thing.&#xA;This statement gives me the impression that you did not yet try Rust,&#xA;actually. Like in a big (and possibly&#xA;multithreaded/concurrent/parallel/whateveryoucallit) environment.&#xA;You say that most software does not have to be parallel and I fully agree on&#xA;that - but if you need to be parallel, I&#39;d rather chose Rust over Go, C or&#xA;C++. Having the safety guarantees Rust gives me allows normal people (and not&#xA;Rockstar-programmers) to write software that can be massively parallel without&#xA;having to fear about deadlocks and other ugly things you get with other&#xA;languages.&#xA;&#xA;It is still true that bad design decisions are possible and might result in&#xA;bad software - but that is true for every language, isn&#39;t it? And I&#39;d rather&#xA;like to have a bad program that gets the job done because it can be statically&#xA;verified that it does than a program that crashes because I ran into a bug&#xA;that was introduced by bad design decisions.&#xA;&#xA;The next paragraph Drew writes makes me really, really sad. Fullquote:&#xA;&#xA;  Safety. Yes, Rust is more safe. I don’t really care. In light of all of&#xA;  these problems, I’ll take my segfaults and buffer overflows. I especially&#xA;  refuse to “rewrite it in Rust” - because no matter what, rewriting an entire&#xA;  program from scratch is always going to introduce more bugs than maintaining&#xA;  the C program ever would. I don’t care what language you rewrite it in.&#xA;&#xA;This gives me the impression that Drew was hit with &#34;Just rewrite it&#34; too many&#xA;times. And I completely agree with you, Drew, that you should indeed not&#xA;rewrite it in Rust just for the sake. Nobody should ever rewrite anything&#xA;in any other language than what &#34;it&#34; currently is written in.&#xA;I hate these people that actually say things like that (if it isn&#39;t for&#xA;trolling, but I have the uneasy feeling that Drew was hit with real &#34;Just&#xA;rewrite it&#34;ers and not just trolling).&#xA;&#xA;I do not say that the points Drew shows are false.&#xA;&#xA;What I do say is that the initial assumption that Rust is there to replace C&#xA;or C++ is, in my opinion, false.&#xA;It is certainly meant to get things right that C++ got wrong - and it is&#xA;certainly there to replace the C++-Monster that we call Gecko, because Mozilla&#xA;is exactly trying to do that!&#xA;But it is not there to replace all C or C++ code ever written because of&#xA;some stupid &#34;Hey we can do X better than your language&#34; bullshit!&#xA;&#xA;Also, the statement that Rust might end up as Kitchen-Sink like C++ and die&#xA;with feature-bloat is one that concerns me because I do not want Rust to end&#xA;up like C++. It certainly is not as complex as C++ and we (as in &#34;the Rust&#xA;community&#34;) have a lot of work to do to not end up with feature-creep - but&#xA;we are also certainly not there yet.&#xA;But I definitively see where this statement is coming from.&#xA;&#xA;The title of this article is&#xA;&#34;Rust is one of the best C replacements we currently have&#34; - and I stand by&#xA;this. But I also think that it is false to say that anyone has to replace C&#xA;or that Rust is necessarily there to do so.&#xA;&#xA;There are domains where you might want to rewrite C code, if you have the time&#xA;and resources. But I&#39;d rather advice against it.&#xA;Improving existing code is always easier than a rewrite of a program and&#xA;rewriting software does not improve the value of the software or even make&#xA;customers more happy. Rewriting software is IMHO only legit in two cases:&#xA;&#xA;It makes you happy because you&#39;re doing it for fun&#xA;It makes your boss happy because he ordered you to do so (for whatever&#xA;  reasons, may it be speed, resource usage, customer request or whatever)&#xA;&#xA;But just for the sake of it? Nah.&#xA;&#xA;I see where Drews article comes from and I see why he thinks like he does. I&#xA;greatly value his opinion and thoughts, and that&#39;s why I took the time to&#xA;write this article.&#xA;&#xA;I see that we (as in &#34;the Rust community&#34;) have a lot to&#xA;do to make more people happy. Not as in making them Rust programmers, because&#xA;that&#39;s not our goal, but as in showing them that we do not want everything&#xA;to be written in Rust and that it is just trolls that request a &#34;rewrite in&#xA;Rust&#34;.&#xA;&#xA;We do value friendlyness and kindness - let me state explicitely that this&#xA;does also include other programming-language-communities (and all other&#xA;communities as well)!&#xA;&#xA;Trolling does not help with that.&#xA;&#xA;: Yes we have generic programming in Rust. I&#39;m not a professional regarding C++, so I cannot say whether they are comparable in this regard.&#xA;: Some might say that we have manual memory management in Rust as well. That might be true by definition, but not the way I meant it: In C++ we can allocate something on the heap and then forget it. We have to try really hard to do that in Rust, though!&#xA;: In fact I might get into the situation where I have to rewrite an application in my job, but I&#39;d rather rewrite it in the same language than switching languages just for the sake of it!&#xA;&#xA;tags: #open-source #programming #rust #c #c++ #cpp&#xA;]]&gt;</description>
      <content:encoded><![CDATA[<p>This is a reply to the article
published by Drew DeVault called
<a href="https://drewdevault.com/2019/03/25/Rust-is-not-a-good-C-replacement.html">“Rust is not a good C replacement”</a>.</p>

<hr>

<p>First of all, let me say that Drew is one of the people out there on the
internet whose opinions I highly value. Indeed he is one of the people I try
to read and listen to regardless of topic, because I think he is one of the
people that deserve unconditional attention.</p>

<p>Needless to say that I&#39;ve also read his latest piece
<a href="https://drewdevault.com/2019/03/25/Rust-is-not-a-good-C-replacement.html">“Rust is not a good C replacement”</a>.
I have to admit I was shocked at first, but after a bit of cooling down (and
doing the dishes), I can see where this comes from.</p>

<p>And I have to disagree.</p>

<p>But let me start with my background – because that might be important for you,
dear reader, to classify this article.</p>

<p>My background is mostly hobbyist programming. I did a few years of C, probably
a few 100kloc, not more. I also do rust since about
<a href="https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-150-2015-12-10">Rust 1.5.0 (2015-12)</a>.
I started a job where I expect to write C and C++ professionally about 1 month
ago.</p>

<p>So, I do <em>not</em> have a background like Drew with probably millions of lines of
C, but I <em>guess</em> that I have a bit more experience with Rust – I wouldn&#39;t say
that I&#39;m a Rust professional, but I would consider myself a “Advanced Rust
Hobbyist”.</p>

<p>I&#39;m also not as skilled in writing blog articles or even with the english
language, so keep that in mind when reading this.</p>

<hr>

<p>I am not a big fan of statement-by-statement replying to an article, but
I guess for this type of article it is good enough.</p>

<p>First of all, Drews initial statement that Rust was designed by C++
programmers: Yes, I absolutely see that this is true. Nevertheless I have to
say that these C++ programmers started developing Rust <em>because</em> C++ was too
complex and too error-prone in what it did and how it did it.
Rust is <em>far</em> away from the complexity C++ gives us in terms of language
features!
From the top of my head, we have</p>
<ul><li>A full-blown OOP programming paradigm, including
<ul><li>Overloading</li>
<li>“friends”</li>
<li>(multi-)inheritance</li>
<li>abstract classes</li>
<li>partly and fully virtual functions</li>
<li>pointers and references</li>
<li>implicit conversions</li>
<li>Copy/Move constructors</li>
<li>Dynamic and static polymorphism</li></ul></li>
<li>Manual memory management</li>
<li>Template Metaprogramming / Generic programming</li>
<li>operator overloading</li>
<li>Lambda expressions</li>
<li>Exceptions</li></ul>

<p>in C++, whereas in Rust we only get</p>
<ul><li>Dynamic and static polymorphism</li>
<li>operator overloading</li>
<li>Lambda expressions</li>
<li>Generic programming[^1]</li></ul>

<p>([^2])</p>

<p>You might consider this list cheated as Rust is not an object oriented
language like C++, but an imperative one like C. That is very true.
Nevertheless it is one reason why the cognitive load a C++-Program requires
one to handle is <em>much</em> higher than an equivalent (as in features of the
program) Rust program!</p>

<p>Drew claims that the values of C and C++ programmers are incompatible and I
would agree with that. But that does not (have to) mean that a C-programmer
and a Rust programmer do not have the same values.
It <em>is</em> true, though, that Rust can excel at a lot of topics that C++ covers,
but it also empower programmers that do not feel comfortable writing good C
code to write their software. And that in a safe and at the same time
performant language while not being overly blown up.</p>

<p>Further Drew compares C, C++, Go and Rust by their complexity, measured with
features introduced in the language over the years.
I am really sorry to say this here, Drew, but we are used to much better from
you! You say that this approach (bullet points/features listed on wikipedia
vs. bullet points in articles and release notes) is not very scientific, yes.
But not even to mention the years these languages were released! For the
record:</p>
<ul><li>C was released <a href="https://en.wikipedia.org/wiki/C_(programming_language)">in 1972; 47 years ago</a></li>
<li>C++ was released <a href="https://en.wikipedia.org/wiki/C%2B%2B">in 1985; 35 years ago</a></li>
<li>Go was released <a href="https://en.wikipedia.org/wiki/Go_(programming_language)">in 2009; 9 years ago</a></li>
<li>Rust was released <a href="https://en.wikipedia.org/wiki/Rust_(programming_language)">in 2010; 8 years ago</a></li></ul>

<p>I am not saying that this disproves your statement – it even supports it! But
I do say that comparing based on features per year/release/whatever <em>must</em>
include a statement about how old these languages are, even if it is just for
showing the reader about what timeframe we are talking.</p>

<p>So, Rust is a relatively young language and yes, it has added a lot of
features and therefore can be compared to C++ much better than it can be to C.
But saying that a 10-year-old C programm might even compile today and
everything might be okay but not so much with Rust is just ignorant of the
fact that Rust is not even that old.
Having a Rust program that is one year old still compiles fine today (assuming
it didn&#39;t use a compiler bug) and does not “look old” at all!
Rust has a big infrastructure for doing regression tests and for being
compatible with older programs.</p>

<p>As you say, out of the way with the philosophical stuff and lets get down to
the facts.</p>

<p><strong>C is more portable.</strong>
But as mentioned before, C is almost six times as old as Rust. We&#39;ll get there!</p>

<p><strong>C has a spec.</strong> Yes, and I completely hear you on this one. Rust does not
(yet?) have a spec and it really is a pain-point. I want one, too! Maybe we&#39;ll
get there at some point.
By the way: Does Go have a spec? It
<a href="https://golang.org/ref/spec">seems like it</a>, but that rather looks like a
language definition and I doubt that this is what Drew meant when talking
about “a spec”, is it?</p>

<p><strong>C has many implementations.</strong> Yes and how much trouble has it been because
different compilers do different things on undefined behaviour?
Too many. This is where Rust tries to solve a problem: Get a language where
undefined behaviour is not allowed or at least as minimal as possible, then we
can have a spec for that language and then we can have different
implementations.
Time will tell whether we can get there.</p>

<p><strong>C has a consistent &amp; stable ABI.</strong> Point taken. I do not argue about that.</p>

<p><strong>Cargo is mandatory.</strong> Yes, another point taken. I again do not argue.</p>

<p><strong>Concurrency is generally a bad thing.</strong>
This statement gives me the impression that you did not yet try Rust,
actually. Like in a big (and possibly
multithreaded/concurrent/parallel/whateveryoucallit) environment.
You say that most software does not have to be parallel and I fully agree on
that – but <em>if</em> you need to be parallel, I&#39;d rather chose Rust over Go, C or
C++. Having the safety guarantees Rust gives me allows normal people (and not
Rockstar-programmers) to write software that can be massively parallel without
having to fear about deadlocks and other ugly things you get with other
languages.</p>

<p>It is still true that bad design decisions are possible and might result in
bad software – but that is true for every language, isn&#39;t it? And I&#39;d rather
like to have a bad program that gets the job done because it can be statically
verified that it does than a program that crashes because I ran into a bug
that was introduced by bad design decisions.</p>

<p>The next paragraph Drew writes makes me really, really sad. Fullquote:</p>

<blockquote><p>Safety. Yes, Rust is more safe. I don’t really care. In light of all of
these problems, I’ll take my segfaults and buffer overflows. I especially
refuse to “rewrite it in Rust” – because no matter what, rewriting an entire
program from scratch is always going to introduce more bugs than maintaining
the C program ever would. I don’t care what language you rewrite it in.</p></blockquote>

<p>This gives me the impression that Drew was hit with “Just rewrite it” too many
times. And I completely agree with you, Drew, that you should indeed <em>not</em>
rewrite it in Rust just for the sake. Nobody should <em>ever</em> rewrite <em>anything</em>
in <em>any</em> other language than what “it” currently is written in.
I hate these people that actually say things like that (if it isn&#39;t for
trolling, but I have the uneasy feeling that Drew was hit with real “Just
rewrite it”ers and not just trolling).</p>

<p>I do not say that the points Drew shows are false.</p>

<p>What I do say is that the initial assumption that Rust is there to replace C
or C++ is, in my opinion, false.
It is certainly meant to get things right that C++ got wrong – and it is
certainly there to replace the C++-Monster that we call Gecko, because Mozilla
is exactly trying to do that!
But it is not there to replace <em>all</em> C or C++ code ever written because of
some stupid “Hey we can do X better than your language” bullshit!</p>

<p>Also, the statement that Rust might end up as Kitchen-Sink like C++ and die
with feature-bloat is one that concerns me because I do not want Rust to end
up like C++. It certainly is not as complex as C++ and we (as in “the Rust
community”) have a lot of work to do to <em>not</em> end up with feature-creep – but
we are also certainly not there yet.
But I definitively see where this statement is coming from.</p>

<p>The title of this article is
“Rust is one of the best C replacements we currently have” – and I stand by
this. But I also think that it is false to say that anyone <em>has to</em> replace C
or that Rust is necessarily there to do so.</p>

<p>There are domains where you might want to rewrite C code, if you have the time
and resources. But I&#39;d rather advice against it[^3].
Improving existing code is always easier than a rewrite of a program and
rewriting software does not improve the value of the software or even make
customers more happy. Rewriting software is IMHO only legit in two cases:</p>
<ul><li>It makes you happy because you&#39;re doing it for fun</li>
<li>It makes your boss happy because he ordered you to do so (for whatever
reasons, may it be speed, resource usage, customer request or whatever)</li></ul>

<p>But just for the sake of it? Nah.</p>

<p>I see where Drews article comes from and I see why he thinks like he does. I
greatly value his opinion and thoughts, and that&#39;s why I took the time to
write this article.</p>

<p>I see that we (as in “the Rust community”) have a lot to
do to make more people happy. Not as in making them Rust programmers, because
that&#39;s not our goal, but as in showing them that we do <em>not</em> want everything
to be written in Rust and that it is just trolls that request a “rewrite in
Rust”.</p>

<p>We do value friendlyness and kindness – let me state explicitely that this
does <em>also</em> include other programming-language-communities (and all other
communities as well)!</p>

<p>Trolling does not help with that.</p>

<p>[^1]: Yes we have generic programming in Rust. I&#39;m not a professional regarding C++, so I cannot say whether they are comparable in this regard.
[^2]: Some might say that we have manual memory management in Rust as well. That might be true by definition, but not the way I meant it: In C++ we can allocate something on the heap and then forget it. We have to try really hard to do that in Rust, though!
[^3]: In fact I might get into the situation where I have to rewrite an application in my job, but I&#39;d rather rewrite it in the same language than switching languages just for the sake of it!</p>

<p>tags: <a href="https://beyermatthias.de/tag:open" class="hashtag"><span>#</span><span class="p-category">open</span></a>-source <a href="https://beyermatthias.de/tag:programming" class="hashtag"><span>#</span><span class="p-category">programming</span></a> <a href="https://beyermatthias.de/tag:rust" class="hashtag"><span>#</span><span class="p-category">rust</span></a> <a href="https://beyermatthias.de/tag:c" class="hashtag"><span>#</span><span class="p-category">c</span></a> <a href="https://beyermatthias.de/tag:c" class="hashtag"><span>#</span><span class="p-category">c</span></a>++ <a href="https://beyermatthias.de/tag:cpp" class="hashtag"><span>#</span><span class="p-category">cpp</span></a></p>
]]></content:encoded>
      <guid>https://beyermatthias.de/rust-is-one-of-the-best-c-replacements-we-currently-have</guid>
      <pubDate>Tue, 26 Mar 2019 16:40:00 +0100</pubDate>
    </item>
    <item>
      <title>Why can&#39;t we map tuples on arguments in Rust?</title>
      <link>https://beyermatthias.de/why-cant-we-map-tuples-on-arguments-in-rust</link>
      <description>&lt;![CDATA[Why can&#39;t we do&#xA;&#xA;fn foo(i: i32, j: i32) -  i32 {&#xA;    i + j&#xA;}&#xA;&#xA;fn main() {&#xA;    println!(&#34;{}&#34;, foo((1, 2)));&#xA;}&#xA;&#xA;in Rust?&#xA;&#xA;The idea&#xA;&#xA;First of all: I don&#39;t know much about what is going on in rust-compiler-land,&#xA;hence I don&#39;t know whether this is technically possible or even in progress&#xA;already. I&#39;m simply writing down some thoughts here.&#xA;&#xA;The idea, or rather the question, is: Why can&#39;t we map tuples on arguments in&#xA;Rust? The code from above shows exactly what I mean by that: Why is the&#xA;compiler not able to unpack the tuple and pass it as list of arguments to the&#xA;function?&#xA;&#xA;It would be really cool if it could do that. The usecase is something like&#xA;this:&#xA;&#xA;somepossiblyfailingfn() // -  Result, &#xA;  .andthen(|res| (res, someotherfailingfn()?)) // Result(, ), &#xA;  .map(PartialEq::Eq) // Resultbool, &#xA;&#xA;for example.&#xA;If mapping of tuples on arguments would be possible, one could write code like&#xA;this, where failing functions are chained and operators and functions can then&#xA;be called on the results of the failing functions.&#xA;&#xA;Currently, one has to write it like this:&#xA;&#xA;somepossiblyfailingfn() // -  Result, &#xA;  .andthen(|res| (res, someotherfailingfn()?)) // Result(, ), &#xA;  .map(|(a, b)| a == b) // Resultbool, &#xA;&#xA;or, because it is solvable with one line less:&#xA;&#xA;somepossiblyfailingfn() // -  Result, &#xA;  .andthen(|res| Ok(res == someotherfailingfn()?)) // Resultbool, &#xA;&#xA;You might think that the overhead for that convenience is rather low and thus&#xA;it is not really beneficial to have such a functionality in the rust compiler.&#xA;&#xA;That is true. But there are great possibilities of API design if this is&#xA;mapping of tuples on arguments are possible.&#xA;For example, one could write an extension to the Result type which extends&#xA;tuples. Think of something like that:&#xA;&#xA;// assuming:&#xA;//&#xA;// somepossiblyfailingfn() -  ResultT, ;&#xA;// someotherfailingfn()) -  ResultU, ;&#xA;// evenotherfailingfn()) -  ResultW, ;&#xA;// yetanotherfailingf()) -  ResultV, ;&#xA;// checkresults(T, U, W, V) -  Resultbool, Error;&#xA;//&#xA;&#xA;somepossiblyfailingfn() // -  ResultT, &#xA;  .andthenchain(|| someotherfailingfn()) // Result(T, U), &#xA;  .andthenchain(|| evenotherfailingfn()) // Result(T, U, W), &#xA;  .andthenchain(|| yetanotherfailingf()) // Result(T, U, W, V), &#xA;  .andthen(checkresults)&#xA;&#xA;From an API-design standpoint, this is plain awesome.&#xA;&#xA;Lets compare that to what we have to write today to do this:&#xA;&#xA;somepossiblyfailingfn() // -  ResultT, &#xA;  .andthen(|a| Ok((a, someotherfailingfn()?)))&#xA;  .andthenchain(|(a, b)| Ok((a, b, evenotherfailingfn()?)))&#xA;  .andthenchain(|(a, b, c)| Ok((a, b, c, yetanotherfailingf()?)))&#xA;  .andthen(|(a, b, c, d)| checkresults(a, b, c, d))&#xA;&#xA;and that&#39;s really not that readable.&#xA;&#xA;From a technical point of view, the compiler is able to verify the length of&#xA;the tuples and thus is able to check whether the tuple actually matches the&#xA;number of parameters of a function.&#xA;&#xA;As said, I&#39;m not that much into the development of the language, thus I don&#39;t&#xA;know whether there are other things that prevent this, though.&#xA;&#xA;Update&#xA;&#xA;After posting this as a question&#xA;on users.rust-lang.org&#xA;and getting some nice replies with explanations why this cannot be, I&#xA;conclude:&#xA;&#xA;It is not possible to do it in a way that does not_ yield weird edge cases,&#xA;ugly implicit conversions and other weirdness we really do not want in the&#xA;language.&#xA;&#xA;But I learned something, and that was worth it!&#xA;&#xA;tags:  #tools #software #c++&#xA;]]&gt;</description>
      <content:encoded><![CDATA[<p>Why can&#39;t we do</p>

<pre><code>fn foo(i: i32, j: i32) -&gt; i32 {
    i + j
}

fn main() {
    println!(&#34;{}&#34;, foo((1, 2)));
}
</code></pre>

<p>in Rust?</p>

<h1 id="the-idea" id="the-idea">The idea</h1>

<p>First of all: I don&#39;t know much about what is going on in rust-compiler-land,
hence I don&#39;t know whether this is technically possible or even in progress
already. I&#39;m simply writing down some thoughts here.</p>

<p>The idea, or rather the question, is: Why can&#39;t we map tuples on arguments in
Rust? The code from above shows exactly what I mean by that: Why is the
compiler not able to unpack the tuple and pass it as list of arguments to the
function?</p>

<p>It would be really cool if it could do that. The usecase is something like
this:</p>

<pre><code>some_possibly_failing_fn() // -&gt; Result&lt;_, _&gt;
  .and_then(|res| (res, some_other_failing_fn()?)) // Result&lt;(_, _), _&gt;
  .map(PartialEq::Eq) // Result&lt;bool, _&gt;
</code></pre>

<p>for example.
If mapping of tuples on arguments would be possible, one could write code like
this, where failing functions are chained and operators and functions can then
be called on the results of the failing functions.</p>

<p>Currently, one has to write it like this:</p>

<pre><code>some_possibly_failing_fn() // -&gt; Result&lt;_, _&gt;
  .and_then(|res| (res, some_other_failing_fn()?)) // Result&lt;(_, _), _&gt;
  .map(|(a, b)| a == b) // Result&lt;bool, _&gt;
</code></pre>

<p>or, because it is solvable with one line less:</p>

<pre><code>some_possibly_failing_fn() // -&gt; Result&lt;_, _&gt;
  .and_then(|res| Ok(res == some_other_failing_fn()?)) // Result&lt;bool, _&gt;
</code></pre>

<p>You might think that the overhead for that convenience is rather low and thus
it is not really beneficial to have such a functionality in the rust compiler.</p>

<p>That is true. But there are great possibilities of API design if this is
mapping of tuples on arguments are possible.
For example, one could write an extension to the <code>Result</code> type which extends
tuples. Think of something like that:</p>

<pre><code>// assuming:
//
// some_possibly_failing_fn() -&gt; Result&lt;T, _&gt;;
// some_other_failing_fn()) -&gt; Result&lt;U, _&gt;;
// even_other_failing_fn()) -&gt; Result&lt;W, _&gt;;
// yet_another_failing_f()) -&gt; Result&lt;V, _&gt;;
// check_results(T, U, W, V) -&gt; Result&lt;bool, Error&gt;;
//

some_possibly_failing_fn() // -&gt; Result&lt;T, _&gt;
  .and_then_chain(|| some_other_failing_fn()) // Result&lt;(T, U), _&gt;
  .and_then_chain(|| even_other_failing_fn()) // Result&lt;(T, U, W), _&gt;
  .and_then_chain(|| yet_another_failing_f()) // Result&lt;(T, U, W, V), _&gt;
  .and_then(check_results)
</code></pre>

<p>From an API-design standpoint, this is plain awesome.</p>

<p>Lets compare that to what we have to write today to do this:</p>

<pre><code>some_possibly_failing_fn() // -&gt; Result&lt;T, _&gt;
  .and_then(|a| Ok((a, some_other_failing_fn()?)))
  .and_then_chain(|(a, b)| Ok((a, b, even_other_failing_fn()?)))
  .and_then_chain(|(a, b, c)| Ok((a, b, c, yet_another_failing_f()?)))
  .and_then(|(a, b, c, d)| check_results(a, b, c, d))
</code></pre>

<p>and that&#39;s really not that readable.</p>

<p>From a technical point of view, the compiler is able to verify the length of
the tuples and thus is able to check whether the tuple actually matches the
number of parameters of a function.</p>

<p>As said, I&#39;m not that much into the development of the language, thus I don&#39;t
know whether there are other things that prevent this, though.</p>

<h1 id="update" id="update">Update</h1>

<p>After posting this as a question
<a href="https://users.rust-lang.org/t/why-cant-we-map-tuples-on-arguments-in-rust/15628">on users.rust-lang.org</a>
and getting some nice replies with explanations why this cannot be, I
conclude:</p>

<p>It is not possible to do it in a way that does <em>not</em> yield weird edge cases,
ugly implicit conversions and other weirdness we really do not want in the
language.</p>

<p>But I learned something, and that was worth it!</p>

<p>tags:  <a href="https://beyermatthias.de/tag:tools" class="hashtag"><span>#</span><span class="p-category">tools</span></a> <a href="https://beyermatthias.de/tag:software" class="hashtag"><span>#</span><span class="p-category">software</span></a> <a href="https://beyermatthias.de/tag:c" class="hashtag"><span>#</span><span class="p-category">c</span></a>++</p>
]]></content:encoded>
      <guid>https://beyermatthias.de/why-cant-we-map-tuples-on-arguments-in-rust</guid>
      <pubDate>Tue, 13 Feb 2018 16:39:07 +0100</pubDate>
    </item>
    <item>
      <title>TIL: Don&#39;t use C++ for new projects</title>
      <link>https://beyermatthias.de/til-dont-use-c-for-new-projects</link>
      <description>&lt;![CDATA[Today I learned that the new C++ standard (C++17) has std::variant - but no&#xA;pattern matching.&#xA;&#xA;Variants and how they work&#xA;&#xA;Variants or &#34;tagged unions&#34; are a special form of data type.&#xA;They describe an abstract thing which could be one concrete thing or another&#xA;concrete thing.&#xA;Variants are available in a lot of languages, including and not limited to&#xA;ML, Haskell, Algol 68, Pascal, Ada, Rust and even C.&#xA;&#xA;With C++17, the C++ standard was extended to have the std::variant generic&#xA;type, which is basically a &#34;C union on steroids&#34;.&#xA;&#xA;(To the C++ greybeard programmers reading this: I know this is technically&#xA;not right, how it is implemented and how this works is very different from an&#xA;actual C union, but what it is used for is basically the same, so please don&#39;t&#xA;yell at me for this statement.)&#xA;&#xA;A std::variant can be used to express, for example, a return value of a&#xA;function which might have failed.&#xA;Maybe you think &#34;Hey, that&#39;s what exceptions are for&#34; - no, that&#39;s not what&#xA;exceptions are for, though a lot of programmer use them like this.&#xA;Exceptions are for unexpected behaviour of your program. If you&#39;re writing a&#xA;terminal calculator, an invalid input is an expected failure. An unexpected&#xA;failure would be that you cannot read from stdin!&#xA;&#xA;In cases where expected failures happen, a std::variant can be used to&#xA;return a &#34;I failed doing my job&#34;-value.&#xA;&#xA;Why you need pattern matching&#xA;&#xA;Pattern matching can be used to destructure variants efficiently (as in code,&#xA;readability, extendability and thus maintainability) to access their inner&#xA;values.&#xA;&#xA;For example, in Haskell, one can destructure a variant like this:&#xA;&#xA;data Result = Ok | Err&#xA;&#xA;explainresult :: Result -  [Char]&#xA;explainresult Ok  = &#34;All right&#34;&#xA;explainresult Err = &#34;Ouch&#34;&#xA;&#xA;Here, we define the variant Result and a function explainresult which&#xA;destructures the variant and returns a string based on the passed variant.&#xA;Of course, variants can hold data and this data can be accessed then.&#xA;&#xA;As a matter of fact, variants are incredible useful in everyday programming&#xA;and so is pattern matching for destructuring them.&#xA;&#xA;What C++17 offers instead of pattern matching&#xA;&#xA;C++17 does not offer pattern matching. Why? I don&#39;t know. But it really should&#xA;have, because the way this issue is solved in C++17 is painful: std::visit&#xA;is used for imitate pattern matching.&#xA;&#xA;On the first glance, the following code looks rather okayish (well, it is&#xA;still C++, right?):&#xA;&#xA;std::vectorstd::variant&lt;char, long, float, int, double, long long  vec = {5, &#39;2&#39;, 5.4, 100ll, 2011l, 3.5f, 2017};&#xA;&#xA;// display each value&#xA;for (auto&amp; v: vec){&#xA;  std::visit({std::cout &lt;&lt; e &lt;&lt; &#34; &#34;;}, v);&#xA;}&#xA;&#xA;But this is simple. What if we want to actually do something with the element&#xA;based on which type it has?&#xA;&#xA;Well, not so nice: We have to design our own visitor and equip it with the&#xA;functionality:&#xA;&#xA;struct Visitor {&#xA;    void operator()(const string&amp; s) const {&#xA;      // ...&#xA;    }&#xA;&#xA;    void operator()(const int n) const {&#xA;      // ...&#xA;    }&#xA;};&#xA;&#xA;While having a dedicated visitor which can be passed around is rather nice,&#xA;having it as the only option for pattern matching is hell.&#xA;&#xA;Also, the standard library does&#xA;not provide a helper for building a visitor object from a list of lambdas!&#xA;&#xA;All in all: Is the whole thing a step into the right direction? No. It is&#xA;rather a stumble into the rightish direction. Nothing more.&#xA;&#xA;A friendly advice from a non-Cpp programmer&#xA;&#xA;Take a grain of salt. I&#39;m not a (C++) professional, hence this might not&#xA;reflect the opinions of the broader community.&#xA;Also, the following might get some people really angry. But I don&#39;t care.&#xA;&#xA;Don&#39;t use C++ for new projects!&#xA;&#xA;I know C++ is a heavy target and the standard is backwards compatible and a&#xA;lot of people count on the standards committee to get this right and&#xA;yaddayaddayadda.&#xA;From my point of view, C++ tries to catch up. This is, of course, nice. But at&#xA;that speed, other languages will innovate much faster and better and C++ will&#xA;slowly die.&#xA;That&#39;s one reason I would never ever use C++ for a new project.&#xA;&#xA;tags:  #tools #software #c++&#xA;]]&gt;</description>
      <content:encoded><![CDATA[<p>Today I learned that the new C++ standard (C++17) has <code>std::variant</code> – but no
pattern matching.</p>

<h1 id="variants-and-how-they-work" id="variants-and-how-they-work">Variants and how they work</h1>

<p>Variants or “tagged unions” are a special form of data type.
They describe an abstract thing which could be one concrete thing or another
concrete thing.
Variants are available in a lot of languages, including and not limited to
ML, Haskell, Algol 68, Pascal, Ada, Rust and even C.</p>

<p>With C++17, the C++ standard was extended to have the <code>std::variant</code> generic
type, which is basically a “C union on steroids”.</p>

<p>(To the C++ greybeard programmers reading this: I know this is technically
not right, how it is implemented and how this works is very different from an
actual C union, but what it is used for is basically the same, so please don&#39;t
yell at me for this statement.)</p>

<p>A <code>std::variant</code> can be used to express, for example, a return value of a
function which might have failed.
Maybe you think “Hey, that&#39;s what exceptions are for” – no, that&#39;s not what
exceptions are for, though a lot of programmer use them like this.
Exceptions are for unexpected behaviour of your program. If you&#39;re writing a
terminal calculator, an invalid input is an <em>expected</em> failure. An unexpected
failure would be that you cannot read from <code>stdin</code>!</p>

<p>In cases where expected failures happen, a <code>std::variant</code> can be used to
return a “I failed doing my job”-value.</p>

<h1 id="why-you-need-pattern-matching" id="why-you-need-pattern-matching">Why you need pattern matching</h1>

<p>Pattern matching can be used to destructure variants efficiently (as in code,
readability, extendability and thus maintainability) to access their inner
values.</p>

<p>For example, in Haskell, one can destructure a variant like this:</p>

<pre><code>data Result = Ok | Err

explainresult :: Result -&gt; [Char]
explainresult Ok  = &#34;All right&#34;
explainresult Err = &#34;Ouch&#34;
</code></pre>

<p>Here, we define the variant <code>Result</code> and a function <code>explainresult</code> which
destructures the variant and returns a string based on the passed variant.
Of course, variants can hold data and this data can be accessed then.</p>

<p>As a matter of fact, variants are incredible useful in everyday programming
and so is pattern matching for destructuring them.</p>

<h1 id="what-c-17-offers-instead-of-pattern-matching" id="what-c-17-offers-instead-of-pattern-matching">What C++17 offers instead of pattern matching</h1>

<p>C++17 does not offer pattern matching. Why? I don&#39;t know. But it really should
have, because the way this issue is solved in C++17 is painful: <code>std::visit</code>
is used for imitate pattern matching.</p>

<p>On the first glance, the following code looks rather okayish (well, it is
still C++, right?):</p>

<pre><code>std::vector&lt;std::variant&lt;char, long, float, int, double, long long&gt;&gt;
           vec = {5, &#39;2&#39;, 5.4, 100ll, 2011l, 3.5f, 2017};

// display each value
for (auto&amp; v: vec){
  std::visit([](auto&amp;&amp; e){std::cout &lt;&lt; e &lt;&lt; &#34; &#34;;}, v);
}
</code></pre>

<p>But this is simple. What if we want to actually do something with the element
based on which type it has?</p>

<p>Well, not so nice: We have to design our own visitor and equip it with the
functionality:</p>

<pre><code>struct Visitor {
    void operator()(const string&amp; s) const {
      // ...
    }

    void operator()(const int n) const {
      // ...
    }
};
</code></pre>

<p>While having a dedicated visitor which can be passed around is rather nice,
having it as the <em>only</em> option for pattern matching is hell.</p>

<p>Also, the standard library does
<a href="https://bitbashing.io/std-visit.html">not provide a helper for building a visitor object from a list of lambdas</a>!</p>

<p>All in all: Is the whole thing a step into the right direction? No. It is
rather a stumble into the rightish direction. Nothing more.</p>

<h1 id="a-friendly-advice-from-a-non-cpp-programmer" id="a-friendly-advice-from-a-non-cpp-programmer">A friendly advice from a non-Cpp programmer</h1>

<p>Take a grain of salt. I&#39;m not a (C++) professional, hence this might not
reflect the opinions of the broader community.
Also, the following might get some people <strong>really</strong> angry. But I don&#39;t care.</p>

<p><strong>Don&#39;t use C++ for new projects!</strong></p>

<p>I know C++ is a heavy target and the standard is backwards compatible and a
lot of people count on the standards committee to get this right and
yaddayaddayadda.
From my point of view, C++ tries to catch up. This is, of course, nice. But at
that speed, other languages will innovate much faster and better and C++ will
slowly die.
That&#39;s one reason I would never ever use C++ for a new project.</p>

<p>tags:  <a href="https://beyermatthias.de/tag:tools" class="hashtag"><span>#</span><span class="p-category">tools</span></a> <a href="https://beyermatthias.de/tag:software" class="hashtag"><span>#</span><span class="p-category">software</span></a> <a href="https://beyermatthias.de/tag:c" class="hashtag"><span>#</span><span class="p-category">c</span></a>++</p>
]]></content:encoded>
      <guid>https://beyermatthias.de/til-dont-use-c-for-new-projects</guid>
      <pubDate>Fri, 09 Feb 2018 16:39:03 +0100</pubDate>
    </item>
    <item>
      <title>Setup for linux kernel dev using qemu</title>
      <link>https://beyermatthias.de/setup-for-linux-kernel-dev-using-qemu</link>
      <description>&lt;![CDATA[I could not think of a better title, I&#39;m sorry.&#xA;&#xA;These are notes how to create a kernel which can be booted in qemu and pass a&#xA;drive to it which has loadable kernel modules.&#xA;&#xA;!-- more --&#xA;&#xA;The idea&#xA;&#xA;I wanted to play around with the linux kernel and write a minimal filesystem&#xA;inside the kernel tree. I wanted to boot the kernel in a QEMU, as I do not&#xA;want to mess with my running kernel.&#xA;&#xA;Here are the steps I did (on a debian VM I run on my universitys&#xA;infrastructure).&#xA;&#xA;Setup&#xA;&#xA;sudo apt-get install build-essential bc git gcc&#xA;git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git&#xA;cd linux&#xA;make x8664defconfig&#xA;make kvmconfig&#xA;make menuconfig&#xA;&#xA;The last step brings up the kernel configuration interface, which I used to&#xA;enable SATA&#xA;(Device Drivers -  Serial ATA and Parallel ATA drivers (libata) -  Generic ATA support)&#xA;support which is needed to be able to mount a device into the qemu instance,&#xA;where we can put things to play around with in the VM.&#xA;&#xA;I then did a make -j 16 (if you have not 8 cores, use a lower number).&#xA;&#xA;While the kernel compiled, I created a busybox initramfs. I used&#xA;this blog article for how to do it.&#xA;I&#39;ll dump in the commands from the blog article, for detailed information, go&#xA;and read it, it&#39;s a really good article. I didn&#39;t do the speed-optimizing&#xA;things, as the QEMU boots fast enough for me (~3 seconds).&#xA;&#xA;(I used the latest busybox, but I don&#39;t see why it should work with the one&#xA;from the article, which is about two versions old)&#xA;&#xA;curl http://busybox.net/downloads/busybox-1.23.2.tar.bz2 | tar xjf -&#xA;cd busybox-1.23.2&#xA;mkdir -pv /tmp/obj/busybox-x86&#xA;make O=/tmp/obj/busybox-x86 defconfig&#xA;make O=/tmp/obj/busybox-x86 menuconfig # See below why&#xA;cd /tmp/obj/busybox-x86&#xA;make -j 16&#xA;&#xA;it does not install in your system, so you can execute this without fear&#xA;make install&#xA;&#xA;mkdir -p /tmp/initramfs/x86-busybox&#xA;cd /tmp/initramfs/x86-busybox&#xA;mkdir -pv {bin,sbin,etc,proc,sys,usr/{bin,sbin}}&#xA;cp -av /tmp/obj/busybox-x86/install/* .&#xA;&#xA;now edit the init script&#xA;vim init&#xA;&#xA;You have to enable busybox build as static binary (with the menuconfig&#xA;part).&#xA;&#xA;The init script I use:&#xA;&#xA;!/bin/sh&#xA;&#xA;echo &#34;INIT SCRIPT&#34;&#xA;&#xA;mount -t proc none /proc&#xA;mount -t sysfs none /sys&#xA;mount -t debugfs none /sys/kernel/debug&#xA;&#xA;mkdir /tmp&#xA;mount -t tmpfs none /tmp&#xA;&#xA;mdev -s # We need this to find /dev/sda later&#xA;&#xA;echo -e &#34;\nBoot took $(cut -d&#39; &#39; -f1 /proc/uptime) seconds\n&#34;&#xA;&#xA;exec /bin/sh&#xA;&#xA;The init script boots into a /bin/sh. We can now build the initramfs with&#xA;it:&#xA;&#xA;chmod +x init&#xA;find . -print0 \&#xA;    | cpio --null -ov --format=newc \&#xA;    | gzip -9   /tmp/initramfs-busybox-x86.cpio.gz&#xA;&#xA;Try it out (1)&#xA;&#xA;Now we can try it out, whether the kernel boots and we get out shell:&#xA;&#xA;In the kernel tree:&#xA;qemu-system-x8664 \&#xA;    -kernel arch/x8664/boot/bzImage \&#xA;    -initrd /tmp/initramfs-busybox-x86.cpio.gz \&#xA;    -nographic -append &#34;console=ttyS0&#34;&#xA;&#xA;We should see some output like this:&#xA;&#xA;[...]&#xA;[    7.170702] Freeing unused kernel memory: 1200K (ffffffff81f55000 - ffffffff82081000)&#xA;[    7.171539] Write protecting the kernel read-only data: 14336k&#xA;[    7.177328] Freeing unused kernel memory: 816K (ffff880001934000 - ffff880001a00000)&#xA;[    7.219360] Freeing unused kernel memory: 1116K (ffff880001ce9000 - ffff880001e00000)&#xA;INIT SCRIPT&#xA;mount: mounting none on /sys/kernel/config failed: No such file or directory&#xA;mount: mounting none on /tmp failed: No such file or directory&#xA;&#xA;Boot took 7.33 seconds&#xA;&#xA;/bin/sh: can&#39;t access tty; job control turned off&#xA;/ # [    7.630681] input: ImExPS/2 BYD TouchPad as /devices/platform/i8042/serio1/input/input3&#xA;&#xA;/ #&#xA;&#xA;(Yes, the output is slightly messed up... but hey! We just booted a linux&#xA;kernel in a QEMU!&#xA;&#xA;Load the kernel module&#xA;&#xA;We can now create a kernel module in the linux kernel tree:&#xA;&#xA;In the kernel tree&#xA;git checkout -b my-module&#xA;mkdir fs/iamcoolfs/ # because I like filesystems&#xA;cat &lt;EOS  ./fs/iamcoolfs/Kconfig&#xA;config COOLFS&#xA;        tristate &#34;COOLFS support&#34;&#xA;        help&#xA;          Private FS for playing and learning FS programming&#xA;&#xA;          This will definitively eat everything you put into it.&#xA;&#xA;EOS&#xA;cat &lt;EOS  ./fs/iamcoolfs/Makefile&#xA;#&#xA;Makefile for the linux mb-filesystem routines.&#xA;&#xA;obj-$(CONFIGMBFS) += coolfs.o&#xA;EOS&#xA;cat &lt;EOS  ./fs/iamcoolfs/coolfs.c&#xA;include linux/init.h&#xA;include linux/module.h&#xA;&#xA;static int _init coolfsinit(void)&#xA;{&#xA;        prdebug(&#34;cool module loaded\n&#34;);&#xA;        return 0;&#xA;}&#xA;&#xA;static void exit coolfsfini(void)&#xA;{&#xA;        prdebug(&#34;cool module unloaded\n&#34;);&#xA;}&#xA;&#xA;moduleinit(coolfsinit);&#xA;moduleexit(coolfsfini);&#xA;&#xA;MODULELICENSE(&#34;GPL&#34;);&#xA;MODULEAUTHOR(&#34;YOUR NAME GOES HERE&#34;);&#xA;&#xA;EOS&#xA;&#xA;This creates all the files we need for a minimal module. Because I like&#xA;filesystems and I really want to implement a minimal filesystem, I chose to&#xA;create the files in ./fs, but I guess_ it shouldn&#39;t matter.&#xA;&#xA;Make sure you adapt the fs/Kconfig file to find your new module! Put&#xA;&#xA;source &#34;fs/coolfs/Kconfig&#34;&#xA;&#xA;into it.&#xA;&#xA;Now you can execute make menuconfig and find the configuration option for&#xA;your new module.&#xA;We can also simply make M=fs/coolfs to build the module.&#xA;Now we create a (ext2) disk where we can cp the module to, so we can mount&#xA;that disk into our QEMU and use the module there:&#xA;&#xA;dd if=/dev/zero of=/tmp/disk bs=4M count=100&#xA;sudo mkfs.ext2 /tmp/disk # you could also try ext4, for example&#xA;mkdir /tmp/disk-mount&#xA;sudo mount /tmp/disk /tmp/disk-mount&#xA;cp fs/coolfs/coolfs.ko /tmp/disk-mount/&#xA;sudo umount /tmp/disk-mount&#xA;&#xA;Try it out (2)&#xA;&#xA;And when we boot our QEMU now with -hda /tmp/disk, we can find /dev/sda in&#xA;the booted instance and mount that:&#xA;&#xA;In the booted VM&#xA;mkdir sda&#xA;mount /dev/sda ./sda&#xA;ls sda&#xA;&#xA;Happy FS dev!&#xA;&#xA;tags:  #c #linux #open source #programming #software #testing #kernel&#xA;]]&gt;</description>
      <content:encoded><![CDATA[<p>I could not think of a better title, I&#39;m sorry.</p>

<p>These are notes how to create a kernel which can be booted in qemu and pass a
drive to it which has loadable kernel modules.</p>



<h1 id="the-idea" id="the-idea">The idea</h1>

<p>I wanted to play around with the linux kernel and write a minimal filesystem
inside the kernel tree. I wanted to boot the kernel in a QEMU, as I do not
want to mess with my running kernel.</p>

<p>Here are the steps I did (on a debian VM I run on my universitys
infrastructure).</p>

<h1 id="setup" id="setup">Setup</h1>

<pre><code class="language-bash">sudo apt-get install build-essential bc git gcc
git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
cd linux
make x86_64_defconfig
make kvmconfig
make menuconfig
</code></pre>

<p>The last step brings up the kernel configuration interface, which I used to
enable SATA
(<code>Device Drivers -&gt; Serial ATA and Parallel ATA drivers (libata) -&gt; Generic ATA support</code>)
support which is needed to be able to mount a device into the qemu instance,
where we can put things to play around with in the VM.</p>

<p>I then did a <code>make -j 16</code> (if you have not 8 cores, use a lower number).</p>

<p>While the kernel compiled, I created a busybox initramfs. I used
<a href="https://mgalgs.github.io/2015/05/16/how-to-build-a-custom-linux-kernel-for-qemu-2015-edition.html">this blog article for how to do it</a>.
I&#39;ll dump in the commands from the blog article, for detailed information, go
and read it, it&#39;s a really good article. I didn&#39;t do the speed-optimizing
things, as the QEMU boots fast enough for me (~3 seconds).</p>

<p>(I used the latest busybox, but I don&#39;t see why it should work with the one
from the article, which is about two versions old)</p>

<pre><code class="language-bash">curl http://busybox.net/downloads/busybox-1.23.2.tar.bz2 | tar xjf -
cd busybox-1.23.2
mkdir -pv /tmp/obj/busybox-x86
make O=/tmp/obj/busybox-x86 defconfig
make O=/tmp/obj/busybox-x86 menuconfig # See below why
cd /tmp/obj/busybox-x86
make -j 16

# it does not install in your system, so you can execute this without fear
make install

mkdir -p /tmp/initramfs/x86-busybox
cd /tmp/initramfs/x86-busybox
mkdir -pv {bin,sbin,etc,proc,sys,usr/{bin,sbin}}
cp -av /tmp/obj/busybox-x86/_install/* .

# now edit the init script
vim init
</code></pre>

<p>You have to enable busybox build as static binary (with the <code>menuconfig</code>
part).</p>

<p>The <code>init</code> script I use:</p>

<pre><code class="language-bash">#!/bin/sh

echo &#34;INIT SCRIPT&#34;

mount -t proc none /proc
mount -t sysfs none /sys
mount -t debugfs none /sys/kernel/debug

mkdir /tmp
mount -t tmpfs none /tmp

mdev -s # We need this to find /dev/sda later

echo -e &#34;\nBoot took $(cut -d&#39; &#39; -f1 /proc/uptime) seconds\n&#34;

exec /bin/sh
</code></pre>

<p>The <code>init</code> script boots into a <code>/bin/sh</code>. We can now build the initramfs with
it:</p>

<pre><code class="language-bash">chmod +x init
find . -print0 \
    | cpio --null -ov --format=newc \
    | gzip -9 &gt; /tmp/initramfs-busybox-x86.cpio.gz
</code></pre>

<h1 id="try-it-out-1" id="try-it-out-1">Try it out (1)</h1>

<p>Now we can try it out, whether the kernel boots and we get out shell:</p>

<pre><code class="language-bash"># In the kernel tree:
qemu-system-x86_64 \
    -kernel arch/x86_64/boot/bzImage \
    -initrd /tmp/initramfs-busybox-x86.cpio.gz \
    -nographic -append &#34;console=ttyS0&#34;
</code></pre>

<p>We should see some output like this:</p>

<pre><code>[...]
[    7.170702] Freeing unused kernel memory: 1200K (ffffffff81f55000 - ffffffff82081000)
[    7.171539] Write protecting the kernel read-only data: 14336k
[    7.177328] Freeing unused kernel memory: 816K (ffff880001934000 - ffff880001a00000)
[    7.219360] Freeing unused kernel memory: 1116K (ffff880001ce9000 - ffff880001e00000)
INIT SCRIPT
mount: mounting none on /sys/kernel/config failed: No such file or directory
mount: mounting none on /tmp failed: No such file or directory

Boot took 7.33 seconds

/bin/sh: can&#39;t access tty; job control turned off
/ # [    7.630681] input: ImExPS/2 BYD TouchPad as /devices/platform/i8042/serio1/input/input3

/ #
</code></pre>

<p>(Yes, the output is slightly messed up... but hey! We just booted a linux
kernel in a QEMU!</p>

<h1 id="load-the-kernel-module" id="load-the-kernel-module">Load the kernel module</h1>

<p>We can now create a kernel module in the linux kernel tree:</p>

<pre><code class="language-bash"># In the kernel tree
git checkout -b my-module
mkdir fs/iamcoolfs/ # because I like filesystems
cat &lt;&lt;EOS &gt; ./fs/iamcoolfs/Kconfig
config COOL_FS
        tristate &#34;COOLFS support&#34;
        help
          Private FS for playing and learning FS programming

          This will definitively eat everything you put into it.

EOS
cat &lt;&lt;EOS &gt; ./fs/iamcoolfs/Makefile
#
# Makefile for the linux mb-filesystem routines.
#

obj-$(CONFIG_MB_FS) += coolfs.o
EOS
cat &lt;&lt;EOS &gt; ./fs/iamcoolfs/coolfs.c
#include &lt;linux/init.h&gt;
#include &lt;linux/module.h&gt;

static int __init coolfs_init(void)
{
        pr_debug(&#34;cool module loaded\n&#34;);
        return 0;
}

static void __exit coolfs_fini(void)
{
        pr_debug(&#34;cool module unloaded\n&#34;);
}

module_init(coolfs_init);
module_exit(coolfs_fini);

MODULE_LICENSE(&#34;GPL&#34;);
MODULE_AUTHOR(&#34;&lt;YOUR NAME GOES HERE&gt;&#34;);

EOS
</code></pre>

<p>This creates all the files we need for a minimal module. Because I like
filesystems and I really want to implement a minimal filesystem, I chose to
create the files in <code>./fs</code>, but I <em>guess</em> it shouldn&#39;t matter.</p>

<p>Make sure you adapt the <code>fs/Kconfig</code> file to find your new module! Put</p>

<pre><code>source &#34;fs/coolfs/Kconfig&#34;
</code></pre>

<p>into it.</p>

<p>Now you can execute <code>make menuconfig</code> and find the configuration option for
your new module.
We can also simply <code>make M=fs/coolfs</code> to build the module.
Now we create a (ext2) disk where we can <code>cp</code> the module to, so we can mount
that disk into our QEMU and use the module there:</p>

<pre><code class="language-bash">dd if=/dev/zero of=/tmp/disk bs=4M count=100
sudo mkfs.ext2 /tmp/disk # you could also try ext4, for example
mkdir /tmp/disk-mount
sudo mount /tmp/disk /tmp/disk-mount
cp fs/coolfs/coolfs.ko /tmp/disk-mount/
sudo umount /tmp/disk-mount
</code></pre>

<h1 id="try-it-out-2" id="try-it-out-2">Try it out (2)</h1>

<p>And when we boot our QEMU now with <code>-hda /tmp/disk</code>, we can find <code>/dev/sda</code> in
the booted instance and mount that:</p>

<pre><code class="language-bash"># In the booted VM
mkdir sda
mount /dev/sda ./sda
ls sda
</code></pre>

<p>Happy FS dev!</p>

<p>tags:  <a href="https://beyermatthias.de/tag:c" class="hashtag"><span>#</span><span class="p-category">c</span></a> <a href="https://beyermatthias.de/tag:linux" class="hashtag"><span>#</span><span class="p-category">linux</span></a> <a href="https://beyermatthias.de/tag:open" class="hashtag"><span>#</span><span class="p-category">open</span></a> source <a href="https://beyermatthias.de/tag:programming" class="hashtag"><span>#</span><span class="p-category">programming</span></a> <a href="https://beyermatthias.de/tag:software" class="hashtag"><span>#</span><span class="p-category">software</span></a> <a href="https://beyermatthias.de/tag:testing" class="hashtag"><span>#</span><span class="p-category">testing</span></a> <a href="https://beyermatthias.de/tag:kernel" class="hashtag"><span>#</span><span class="p-category">kernel</span></a></p>
]]></content:encoded>
      <guid>https://beyermatthias.de/setup-for-linux-kernel-dev-using-qemu</guid>
      <pubDate>Tue, 01 Nov 2016 16:37:55 +0100</pubDate>
    </item>
    <item>
      <title>The annoyance of programming language tutorials - or: Why learning rust feels amazing</title>
      <link>https://beyermatthias.de/the-annoyance-of-programming-language-tutorials-or-why-learning-rust-feels</link>
      <description>&lt;![CDATA[This article is about the annoyance of programming language tutorials. First, I&#xA;will argue why learning new programming languages always feels a bit like a pain&#xA;to me. And then I will tell you why learning Rust was different.&#xA;&#xA;!-- more --&#xA;&#xA;I know a few programming languages. I&#39;ve done things in C, Ruby, Java, Python,&#xA;PHP, C++, Bash, Lisp (Racket, actually), Haskell, LaTeX, Nix, Make, Lua and&#xA;JavaScript.&#xA;&#xA;small&#xA;    *: Only a bit, but still enough to say &#34;I&#39;ve done things in this language&#34;&#xA;/small&#xA;&#xA;When I started learning programming, I learned Java and shortly after that Ruby.&#xA;Both languages have their oddities, but besides their overall concept&#xA;(imperative programming and object orientated programming) they are both rather&#xA;easy to learn.&#xA;After that I learned C. Learning C was a new world for me back then, as I&#xA;only knew object orientation. I cannot remember which resources I&#39;ve been using&#xA;learning C, though I remember it was a pain. I had a good friend helping me,&#xA;which was awesome, though I struggled a lot with the new concept.&#xA;&#xA;After learning C, I did a fair amount of PHP. Learning PHP was simple (I&#xA;actually did it in one weekend and a few thousand lines), though it again was a&#xA;pain. It was a pain because of the tutorials and resources. And that&#39;s the point&#xA;I want to discuss here.&#xA;&#xA;All other programming languages I&#39;ve been learning so far were painful to learn.&#xA;Not because of their concepts (see Haskell, functional programming at all), but&#xA;because of the resources. Haskell is a really good example here. There is&#xA;exactly one resource I enjoyed while learning Haskell, and that&#39;s&#xA;&#34;Learn you a Haskell for great good&#34;.&#xA;And why? Because it takes your hand and shows you the new world. It is good&#xA;because the concept of functional programming is new for most people reading&#xA;this resource. Learning JavaScript, Bash, Lua or Python sucks because you&#xA;already know what an object is. You know what a function or method is and you&#xA;know that the basic syntax for arithmetic is the very same as in the languages&#xA;you&#39;ve been using by now. But all tutorials expect you start from zero - which&#xA;is fine if you&#39;re actually starting from zero, but most of the time you&#39;re not.&#xA;After learning Java and Ruby I understood what OOP is (actually not after&#xA;learning Java, but after learning Ruby, because Java isn&#39;t a fully object&#xA;oriented language in my opinion).&#xA;&#xA;So, learning Haskell was kinda amazing. Learn you a Haskell is a really great&#xA;book and if you want to learn Haskell, you really should read it. But what was&#xA;even a better experience was learning Rust.&#xA;&#xA;So why is that? It is because Rust is a new concept and the old concept&#xA;(imperative programming). Learning Rust is not like learning Python after&#xA;learning Ruby. It is like Learning Haskell after learning Racket. The concept&#xA;behind the language is kinda the same, though it is different in most details.&#xA;&#xA;Plus, the Rust tutorials and resources are freakin&#39; awesome. Let me repeat that.&#xA;The tutorials and documentation of the tools, libraries and everything, the&#xA;resources on how to do things, are awesome!&#xA;&#xA;Every documentation for each library looks exactly the same, which is a huge&#xA;advantage over other languages library documentations. cargo, the Rust&#xA;build-tool builds the documentation locally for you, if you want that. So&#xA;working offline after you fetched the dependencies or your project (also via&#xA;cargo) is no hassle. Building a new project with cargo is absolutely painless,&#xA;its literally just executing a command, editing a textfile and executing another&#xA;command (setting up the project, writing down dependencies and meta information&#xA;about the project and building the project, which fetches the dependencies).&#xA;&#xA;So really, if you want to learn a new programming language, check out Rust. I&#xA;haven&#39;t even talked about its language features, and I will not, as this is not&#xA;the goal of this article. This article is about resources and tutorials. And my&#xA;conclusion is:&#xA;&#xA;All programming language tutorials suck. Except the Rust language tutorial.&#xA;tags:  #programming #open source #bash #c #c++ #haskell #nix #racket #rust #shell&#xA;]]&gt;</description>
      <content:encoded><![CDATA[<p>This article is about the annoyance of programming language tutorials. First, I
will argue why learning new programming languages always feels a bit like a pain
to me. And then I will tell you why learning Rust was different.</p>



<p>I know a few programming languages. I&#39;ve done things in C, Ruby, Java, Python<em>,
PHP, C++, Bash, Lisp</em> (Racket<em>, actually), Haskell</em>, LaTeX, Nix, Make, Lua* and
JavaScript*.</p>

<p><small>
    *: Only a bit, but still enough to say “I&#39;ve done things in this language”
</small></p>

<p>When I started learning programming, I learned Java and shortly after that Ruby.
Both languages have their oddities, but besides their overall concept
(imperative programming and object orientated programming) they are both rather
easy to learn.
After that I learned C. Learning C was a new world for me back then, as I
only knew object orientation. I cannot remember which resources I&#39;ve been using
learning C, though I remember it was a pain. I had a good friend helping me,
which was awesome, though I struggled a lot with the new concept.</p>

<p>After learning C, I did a fair amount of PHP. Learning PHP was simple (I
actually did it in one weekend and a few thousand lines), though it again was a
pain. It was a pain because of the tutorials and resources. And that&#39;s the point
I want to discuss here.</p>

<p>All other programming languages I&#39;ve been learning so far were painful to learn.
Not because of their concepts (see Haskell, functional programming at all), but
because of the resources. Haskell is a really good example here. There is
exactly <em>one</em> resource I enjoyed while learning Haskell, and that&#39;s
<a href="http://learnyouahaskell.com/">“Learn you a Haskell for great good”</a>.
And why? Because it <em>takes your hand and shows you the <strong>new</strong> world</em>. It is good
because the concept of functional programming is <em>new</em> for most people reading
this resource. Learning JavaScript, Bash, Lua or Python <em>sucks</em> because you
already know what an object is. You know what a function or method is and you
know that the basic syntax for arithmetic is the very same as in the languages
you&#39;ve been using by now. But all tutorials expect you start from zero – which
is fine if you&#39;re actually starting from zero, but most of the time you&#39;re not.
After learning Java and Ruby I understood what OOP is (actually not after
learning Java, but after learning Ruby, because Java isn&#39;t a fully object
oriented language in my opinion).</p>

<p>So, learning Haskell was kinda amazing. Learn you a Haskell is a really great
book and if you want to learn Haskell, you really should read it. But what was
even a better experience was learning Rust.</p>

<p>So why is that? It is because Rust is a new concept <em>and</em> the old concept
(imperative programming). Learning Rust is not like learning Python after
learning Ruby. It is like Learning Haskell after learning Racket. The concept
behind the language is <em>kinda</em> the same, though it is different in most details.</p>

<p>Plus, the Rust tutorials and resources are freakin&#39; awesome. Let me repeat that.
The tutorials and documentation of the tools, libraries and everything, the
resources on how to do things, are <em>awesome</em>!</p>

<p>Every documentation for each library looks exactly the same, which is a <em>huge</em>
advantage over other languages library documentations. <code>cargo</code>, the Rust
build-tool builds the documentation locally for you, if you want that. So
working offline after you fetched the dependencies or your project (also via
cargo) is no hassle. Building a new project with cargo is absolutely painless,
its literally just executing a command, editing a textfile and executing another
command (setting up the project, writing down dependencies and meta information
about the project and building the project, which fetches the dependencies).</p>

<p>So really, if you want to learn a new programming language, check out Rust. I
haven&#39;t even talked about its language features, and I will not, as this is not
the goal of this article. This article is about resources and tutorials. And my
conclusion is:</p>

<p>All programming language tutorials suck. Except the Rust language tutorial.
tags:  <a href="https://beyermatthias.de/tag:programming" class="hashtag"><span>#</span><span class="p-category">programming</span></a> <a href="https://beyermatthias.de/tag:open" class="hashtag"><span>#</span><span class="p-category">open</span></a> source <a href="https://beyermatthias.de/tag:bash" class="hashtag"><span>#</span><span class="p-category">bash</span></a> <a href="https://beyermatthias.de/tag:c" class="hashtag"><span>#</span><span class="p-category">c</span></a> <a href="https://beyermatthias.de/tag:c" class="hashtag"><span>#</span><span class="p-category">c</span></a>++ <a href="https://beyermatthias.de/tag:haskell" class="hashtag"><span>#</span><span class="p-category">haskell</span></a> <a href="https://beyermatthias.de/tag:nix" class="hashtag"><span>#</span><span class="p-category">nix</span></a> <a href="https://beyermatthias.de/tag:racket" class="hashtag"><span>#</span><span class="p-category">racket</span></a> <a href="https://beyermatthias.de/tag:rust" class="hashtag"><span>#</span><span class="p-category">rust</span></a> <a href="https://beyermatthias.de/tag:shell" class="hashtag"><span>#</span><span class="p-category">shell</span></a></p>
]]></content:encoded>
      <guid>https://beyermatthias.de/the-annoyance-of-programming-language-tutorials-or-why-learning-rust-feels</guid>
      <pubDate>Sun, 31 Jan 2016 16:37:43 +0100</pubDate>
    </item>
    <item>
      <title>Stay away from FastCGI++ if you can</title>
      <link>https://beyermatthias.de/stay-away-from-fastcgi-if-you-can</link>
      <description>&lt;![CDATA[So I&#39;m in my praxis semester at the moment, and I have to work with fastcgi++,&#xA;a C++ library for fastcgi. And it is a nightmare! Here comes why...&#xA;&#xA;!-- more --&#xA;&#xA;So first, the codebase of fastcgi++ is a mess. Code snippets like&#xA;&#xA;bool foo = someFunction();&#xA;if (foo) return true;&#xA;else return false;&#xA;&#xA;are everywhere. You really don&#39;t want to read that kind of code. And yes,&#xA;you have to actually read this code because there is no documentation on how&#xA;to use the library! There is a wonderful doxygen-generated API documentation,&#xA;but that does not help you because, yeah, you know the types and the&#xA;interfaces now - lucky you! How to build a fastcgi module with them - figure&#xA;it out by reading through the codebase!&#xA;&#xA;Secondly, you are not allowed to define your custom accept() handler. You&#xA;have to inherit from a Request class template and you have to implement the&#xA;virtual bool response(void) = 0; method. Okay, no problem, I can do this!&#xA;But then, you want to start accepting requests. You do this by creating an&#xA;instance of a class called Manager:&#xA;&#xA;Fastcgipp::ManagerMyRequestInheritedClass man();&#xA;man.handler();&#xA;&#xA;or something like this (this is no real code, I just want to demonstrate how&#xA;it looks like). The manager accepts one connection (through many layers of&#xA;abstraction, actually), creates an instance of your request class and calls&#xA;response() on it.&#xA;&#xA;Well, that&#39;s not a problem, is it? Well, it gets to a big problem if you want&#xA;to be able to handle multiple requests at once, speaking of&#xA;multithreading/concurrency here. It is a huge mess! My codebase exists of&#xA;three classes, actually. A ThreadedRequest class, a BlockingQueue where&#xA;requests get stored thread-safe and a RequestDispatcher which is a singleton&#xA;which runs several worker threads. These worker threads take the requests out&#xA;of the queue and process them if they can.&#xA;&#xA;The ThreadedRequest class puts itself into the queue, which is a member of&#xA;the RequestDispatcher singleton instance. The problem is not that it is&#xA;unnecessarily complicated to build these 1-N multiplexing thing, but that the&#xA;library provides an interface which enforces you to couple your classes&#xA;realy tightly. And this is freaking bullshit. &#xA;&#xA;So, finally: I&#39;m building a wrapper lib around fastcgi++ to be able to handle&#xA;requests in a concurrent way. And it sucks. But it works.&#xA;&#xA;So, my conclusion is: Stay away from this bullshit library. And even from&#xA;fastcgi if you can. Apache for example offers a way to write modules, so you&#xA;can simply write your own module for apache if you need to - which is faster&#xA;anyways!&#xA;&#xA;If you have to use fastcgi, consider writing your own library!&#xA;&#xA;tags:  #c++ #linux #server #open source #programming #software&#xA;]]&gt;</description>
      <content:encoded><![CDATA[<p>So I&#39;m in my praxis semester at the moment, and I have to work with fastcgi++,
a C++ library for fastcgi. And it is a nightmare! Here comes why...</p>



<p>So first, the codebase of fastcgi++ is a mess. Code snippets like</p>

<pre><code class="language-C++">bool foo = someFunction();
if (foo) return true;
else return false;
</code></pre>

<p>are <em>everywhere</em>. You really don&#39;t want to read that kind of code. And yes,
you have to actually read this code because there is no documentation on how
to use the library! There is a wonderful doxygen-generated API documentation,
but that does not help you because, yeah, you know the types and the
interfaces now – lucky you! How to build a fastcgi module with them – figure
it out by reading through the codebase!</p>

<p>Secondly, you are not allowed to define your custom <code>accept()</code> handler. You
have to inherit from a <code>Request</code> class template and you have to implement the
<code>virtual bool response(void) = 0;</code> method. Okay, no problem, I can do this!
But then, you want to start accepting requests. You do this by creating an
instance of a class called <code>Manager</code>:</p>

<pre><code class="language-C++">Fastcgipp::Manager&lt;MyRequestInheritedClass&gt; man();
man.handler();
</code></pre>

<p>or something like this (this is no real code, I just want to demonstrate how
it looks like). The manager accepts one connection (through many layers of
abstraction, actually), creates an instance of your request class and calls
<code>response()</code> on it.</p>

<p>Well, that&#39;s not a problem, is it? Well, it gets to a big problem if you want
to be able to handle multiple requests at once, speaking of
multithreading/concurrency here. It is a <em>huge</em> mess! My codebase exists of
three classes, actually. A <code>ThreadedRequest</code> class, a <code>BlockingQueue</code> where
requests get stored thread-safe and a <code>RequestDispatcher</code> which is a singleton
which runs several worker threads. These worker threads take the requests out
of the queue and process them if they can.</p>

<p>The <code>ThreadedRequest</code> class puts <em>itself</em> into the queue, which is a member of
the <code>RequestDispatcher</code> singleton instance. The problem is not that it is
unnecessarily complicated to build these 1-N multiplexing thing, but that the
library provides an interface which <em>enforces</em> you to couple your classes
realy tightly. And this is <em>freaking bullshit</em>.</p>

<p>So, finally: I&#39;m building a wrapper lib around fastcgi++ to be able to handle
requests in a concurrent way. And it sucks. But it works.</p>

<p>So, my conclusion is: Stay away from this bullshit library. And even from
fastcgi if you can. Apache for example offers a way to write modules, so you
can simply write your own module for apache if you need to – which is faster
anyways!</p>

<p>If you have to use fastcgi, consider writing your own library!</p>

<p>tags:  <a href="https://beyermatthias.de/tag:c" class="hashtag"><span>#</span><span class="p-category">c</span></a>++ <a href="https://beyermatthias.de/tag:linux" class="hashtag"><span>#</span><span class="p-category">linux</span></a> <a href="https://beyermatthias.de/tag:server" class="hashtag"><span>#</span><span class="p-category">server</span></a> <a href="https://beyermatthias.de/tag:open" class="hashtag"><span>#</span><span class="p-category">open</span></a> source <a href="https://beyermatthias.de/tag:programming" class="hashtag"><span>#</span><span class="p-category">programming</span></a> <a href="https://beyermatthias.de/tag:software" class="hashtag"><span>#</span><span class="p-category">software</span></a></p>
]]></content:encoded>
      <guid>https://beyermatthias.de/stay-away-from-fastcgi-if-you-can</guid>
      <pubDate>Thu, 14 May 2015 16:37:36 +0200</pubDate>
    </item>
    <item>
      <title>rate.sh -- Port to C++</title>
      <link>https://beyermatthias.de/rate-sh-port-to-c</link>
      <description>&lt;![CDATA[Some of you might know my little project&#xA;rate. It is a bash script to collect&#xA;a database of things you want to rate.&#xA;&#xA;What this means and why I started to reimplement in C++ - read it here!&#xA;&#xA;!-- more --&#xA;&#xA;So I started to write this application because I wanted to keep track of&#xA;animes I already watched, Bands I like but do not listen to that often and so&#xA;on and so forth. What the application does is really simple: You can enter&#xA;notes about a certain thing (in your favourite text editor, which is vim for&#xA;me) and attach tags to it and put it into a category. Then you can give it a&#xA;rating. The rating can be everything, from simply numbers to text to whatever&#xA;you like. But it is supposed to be a number between 1 and 10, of course.&#xA;That&#39;s also the way I use it.&#xA;&#xA;So how does it work? Well, that&#39;s really simple: The &#34;rate&#34; script creates a&#xA;directory structure in ~/.rate/collections/, whereas a folder is a&#xA;&#34;collection&#34; of things and a file is a rating. So, I have something like&#xA;&#34;movies/animes/&#34; as collections (they are nested, of course) and then a file&#xA;for each anime I watched. The filename is generated from the title I passed&#xA;&#34;rate&#34; when creating the entry. The file also contains a &#34;header&#34;, which&#xA;includes a unique ID (which you really should not change), a list of tags, the&#xA;title (the filename is the title, too, but as on linux you shouldn&#39;t include&#xA;whitespace in file names, it is not the title as you typed it) and a rating of&#xA;course. Custom fields could be added to the header, but this feature is not&#xA;implemented yet. After the header, you can put your description.&#xA;&#xA;That&#39;s basically it. &#34;rate&#34; provides some features to search this database,&#xA;for example you can grep for text in your entries, you can view your&#xA;entries, you can list your entries and you can attach more text to your&#xA;entries or edit them. As everything is git controlled in the ~/.rate&#xA;directory, you can reset if you (or the script,...) messed up somehow.&#xA;&#xA;There&#39;s no release by now, as it lacks of some features by now. For example I&#xA;want to be able to search for entries with a certain rating or within a&#xA;certain range of ratings. I also want to be able to search for entries with aspecial set of tags or within a certain collection (I can do this, though)&#xA;special set of tags or within a certain collection (I can do this, already)!&#xA;After these things are implemented, I will release my first version, which&#xA;would be 1.0 then. And, of course, I will package it for NixOS!&#xA;&#xA;So why C++&#xA;&#xA;Well, I have to learn C++ for my praxis semester. That&#39;s basically it. I&#xA;wanted to learn a new programming language for a relatively long time, and&#xA;that&#39;s my approach on learning C++. I was able to implement some things, but&#xA;not yet to run an application. My first step would be to parse my already&#xA;existing entries. Hope that works. As I stated in the github repos README.md&#xA;file, I do not want to use any frameworks for this. No Boost, no Qt, no other&#xA;libraries. I just want to use plain C++11 (or maybe 14 in future, not sure&#xA;about this, though).&#xA;&#xA;Also, C++ gives me way more posibilities when it comes to features. I can&#xA;refactor things really easy and maybe the C++ implementation will continue to&#xA;live whereas the bash implementation will die at some point. Who knows? The&#xA;point is, the bash implementation implements a file format which is&#xA;&#xA;really simple&#xA;forward compatible&#xA;&#xA;The file actually looks like this:&#xA;&#xA;key = value&#xA;other = value&#xA;another = another&#xA;---&#xA;&#xA;text&#xA;&#xA;and that&#39;s basically it. The three dashes mark the end of the header and&#xA;everything before the header is a key = value list, whereas each line is&#xA;only allowed to contain one key-value-pair. The value can be a list of values,&#xA;for example a list of Tags whereas tags are seperated by a whitespace&#xA;character (space) or a string, such as the title is. The bash implementation&#xA;&#34;knows&#34; which key has to be which value and the C++ implementation has to know&#xA;this, too, of course. But that&#39;s it.&#xA;&#xA;The commandline interface of the application needs some work, though. Maybe it&#xA;will get some REPL-like interface later on, or maybe something more&#xA;interactive. By now, it is simply an interface where you can do one thing per&#xA;call. I have no problem with that and I&#39;m planning to keep backward&#xA;compatibility with the bash implementation even if this one is not even&#xA;released! It is fun to write such a tool and I really like doing it.&#xA;&#xA;---&#xA;&#xA;Also, it is not a that complex thing to implement and that&#39;s a huge point to&#xA;me. I don&#39;t want to spend months and months in implementing a thing which only&#xA;one or two people on this planet actually use. For bigger projects, I&#xA;contribute to open source projects. That&#39;s a better way to produce large-scale&#xA;software, IMHO.&#xA;&#xA;tags:  #bash #programming #c++ #linux #shell #vim&#xA;]]&gt;</description>
      <content:encoded><![CDATA[<p>Some of you might know my little project
<a href="https://github.com/matthiasbeyer/rate">rate</a>. It is a bash script to collect
a database of things you want to rate.</p>

<p>What this means and why I started to reimplement in C++ – read it here!</p>



<p>So I started to write this application because I wanted to keep track of
animes I already watched, Bands I like but do not listen to that often and so
on and so forth. What the application does is really simple: You can enter
notes about a certain thing (in your favourite text editor, which is vim for
me) and attach tags to it and put it into a category. Then you can give it a
rating. The rating can be everything, from simply numbers to text to whatever
you like. But it is supposed to be a number between 1 and 10, of course.
That&#39;s also the way I use it.</p>

<p>So how does it work? Well, that&#39;s really simple: The “rate” script creates a
directory structure in <code>~/.rate/collections/</code>, whereas a folder is a
“collection” of things and a file is a rating. So, I have something like
“movies/animes/” as collections (they are nested, of course) and then a file
for each anime I watched. The filename is generated from the title I passed
“rate” when creating the entry. The file also contains a “header”, which
includes a unique ID (which you really should not change), a list of tags, the
title (the filename is the title, too, but as on linux you shouldn&#39;t include
whitespace in file names, it is not the title as you typed it) and a rating of
course. Custom fields <em>could</em> be added to the header, but this feature is not
implemented yet. After the header, you can put your description.</p>

<p>That&#39;s basically it. “rate” provides some features to search this database,
for example you can <code>grep</code> for text in your entries, you can view your
entries, you can list your entries and you can attach more text to your
entries or edit them. As everything is git controlled in the <code>~/.rate</code>
directory, you can reset if you (or the script,...) messed up somehow.</p>

<p>There&#39;s no release by now, as it lacks of some features by now. For example I
want to be able to search for entries with a certain rating or within a
certain range of ratings. I also want to be able to search for entries with aspecial set of tags or within a certain collection (I can do this, though)
special set of tags or within a certain collection (I can do this, already)!
After these things are implemented, I will release my first version, which
would be <code>1.0</code> then. And, of course, I will package it for NixOS!</p>

<h1 id="so-why-c" id="so-why-c">So why C++</h1>

<p>Well, I have to learn C++ for my praxis semester. That&#39;s basically it. I
wanted to learn a new programming language for a relatively long time, and
that&#39;s my approach on learning C++. I was able to implement some things, but
not yet to run an application. My first step would be to parse my already
existing entries. Hope that works. As I stated in the github repos <code>README.md</code>
file, I do not want to use any frameworks for this. No Boost, no Qt, no other
libraries. I just want to use plain C++11 (or maybe 14 in future, not sure
about this, though).</p>

<p>Also, C++ gives me <em>way</em> more posibilities when it comes to features. I can
refactor things really easy and maybe the C++ implementation will continue to
live whereas the bash implementation will die at some point. Who knows? The
point is, the bash implementation implements a file format which is</p>
<ol><li>really simple</li>
<li>forward compatible</li></ol>

<p>The file actually looks like this:</p>

<pre><code class="language-text">key = value
other = value
another = another
---

&lt;text&gt;
</code></pre>

<p>and that&#39;s basically it. The three dashes mark the end of the header and
everything before the header is a <code>&lt;key&gt; = &lt;value&gt;</code> list, whereas each line is
only allowed to contain one key-value-pair. The value can be a list of values,
for example a list of Tags whereas tags are seperated by a whitespace
character (space) or a string, such as the title is. The bash implementation
“knows” which key has to be which value and the C++ implementation has to know
this, too, of course. But that&#39;s it.</p>

<p>The commandline interface of the application needs some work, though. Maybe it
will get some REPL-like interface later on, or maybe something more
interactive. By now, it is simply an interface where you can do one thing per
call. I have no problem with that and I&#39;m planning to keep backward
compatibility with the bash implementation even if this one is not even
released! It is fun to write such a tool and I really like doing it.</p>

<hr>

<p>Also, it is not a that complex thing to implement and that&#39;s a huge point to
me. I don&#39;t want to spend months and months in implementing a thing which only
one or two people on this planet actually use. For bigger projects, I
contribute to open source projects. That&#39;s a better way to produce large-scale
software, IMHO.</p>

<p>tags:  <a href="https://beyermatthias.de/tag:bash" class="hashtag"><span>#</span><span class="p-category">bash</span></a> <a href="https://beyermatthias.de/tag:programming" class="hashtag"><span>#</span><span class="p-category">programming</span></a> <a href="https://beyermatthias.de/tag:c" class="hashtag"><span>#</span><span class="p-category">c</span></a>++ <a href="https://beyermatthias.de/tag:linux" class="hashtag"><span>#</span><span class="p-category">linux</span></a> <a href="https://beyermatthias.de/tag:shell" class="hashtag"><span>#</span><span class="p-category">shell</span></a> <a href="https://beyermatthias.de/tag:vim" class="hashtag"><span>#</span><span class="p-category">vim</span></a></p>
]]></content:encoded>
      <guid>https://beyermatthias.de/rate-sh-port-to-c</guid>
      <pubDate>Wed, 25 Feb 2015 16:37:30 +0100</pubDate>
    </item>
    <item>
      <title>Too much languages to choose from</title>
      <link>https://beyermatthias.de/too-much-languages-to-choose-from</link>
      <description>&lt;![CDATA[I have a problem. I want to write a small application. It should be a&#xA;commandline application, but maybe I want to extend it later with a GUI or&#xA;even a web interface. But I don&#39;t know what language to write it in.&#xA;&#xA;!-- more --&#xA;&#xA;This article could also be named &#34;Which is the right tool for the job?&#34;&#xA;&#xA;The idea is simple: I want to write a journal-application, where one can take&#xA;notes, tag them, query the journal for entries, optionally provide filters&#xA;before printing them to print only some of them and so on.&#xA;&#xA;I want to be able to encrypt them with gpg and I want to write posts to the&#xA;journal with vim. I want to be able to configure these steps, of course, so I&#xA;can use a certain key for encrypting the journal or maybe another editor (for&#xA;these emacs lovers out there).&#xA;&#xA;It should be designed to be extensible, so I can add a GUI or web interface&#xA;later on. Or maybe a tex output, so I can compile a PDF out of it or&#xA;something. Posts should be written in standard markdown, so this wouldn&#39;t be a&#xA;big deal.&#xA;&#xA;But I don&#39;t know what language to write it in. The languages which I can or&#xA;would choose from are:&#xA;&#xA;C&#xA;C++&#xA;Haskell&#xA;Rust&#xA;Java (not really...)&#xA;Scala (not really either, it&#39;s still JVM)&#xA;Ruby&#xA;Python (by extending jrnl)&#xA;Racket&#xA;Lua&#xA;Bash (I really don&#39;t want to write it in bash, but it&#39;s still a possibility)&#xA;&#xA;As you can see, the first four languages are compiled languages, then Java and&#xA;Scala are (lets call it) Semi-Compiled languages and the others are scripting&#xA;languages. All of these languages have certain advantages over others.&#xA;&#xA;The compiled languages&#xA;&#xA;... have the advantages that they are fast. Haskell and Rust also have the&#xA;advantages that if the compiler does not fail compiling the sources, the&#xA;program just works (tm).&#xA;&#xA;Also, learning C++, Haskell or Rust would be a really great experience and may&#xA;be beneficial later in a job or something.&#xA;&#xA;The semi-compiled languages are also (kind of) fast, but they are&#xA;JVM-languages, so I won&#39;t look into them here...&#xA;&#xA;The scripting languages&#xA;&#xA;Writing the application in a scripting language would have some other&#xA;advantages: They would be much more flexible and I&#39;d be faster writing the&#xA;application (compared to Rust or Haskell, which I would need to learn with the&#xA;application). I don&#39;t need to learn Ruby, I know a fair bit of Racket and I&#xA;guess I can get productive with Python or Lua really fast.&#xA;&#xA;Bash is another option and I&#39;m actually an bash script for an almost similar&#xA;job right now. I could simply extend this script, that would be an option, of&#xA;course.&#xA;&#xA;So which is the right tool for the job?&#xA;&#xA;Can you tell me? I don&#39;t know which tool is the right tool for the job. After&#xA;all, I don&#39;t think I should write such an application from scratch. So, for&#xA;me, there are two options left: Extending&#xA;jrnl, which is an Python script, or&#xA;extending diary (I do not even find a link for this anymore), which is a bash&#xA;script. Extending the bash script would be an easy job, I guess. But it&#xA;wouldn&#39;t be as flexible as the Python tool is already.&#xA;tags:  #bash #c #c++ #haskell #programming #racket #rust #shell #tools&#xA;]]&gt;</description>
      <content:encoded><![CDATA[<p>I have a problem. I want to write a small application. It should be a
commandline application, but maybe I want to extend it later with a GUI or
even a web interface. But I don&#39;t know what language to write it in.</p>



<p>This article could also be named “Which is the right tool for the job?”</p>

<p>The idea is simple: I want to write a journal-application, where one can take
notes, tag them, query the journal for entries, optionally provide filters
before printing them to print only some of them and so on.</p>

<p>I want to be able to encrypt them with gpg and I want to write posts to the
journal with vim. I want to be able to configure these steps, of course, so I
can use a certain key for encrypting the journal or maybe another editor (for
these emacs lovers out there).</p>

<p>It should be designed to be extensible, so I can add a GUI or web interface
later on. Or maybe a tex output, so I can compile a PDF out of it or
something. Posts should be written in standard markdown, so this wouldn&#39;t be a
big deal.</p>

<p>But I don&#39;t know what language to write it in. The languages which I can or
would choose from are:</p>
<ul><li>C</li>
<li>C++</li>
<li>Haskell</li>
<li>Rust</li>
<li>Java (not really...)</li>
<li>Scala (not really either, it&#39;s still JVM)</li>
<li>Ruby</li>
<li>Python (by extending <a href="https://maebert.github.io/jrnl/">jrnl</a>)</li>
<li>Racket</li>
<li>Lua</li>
<li>Bash (I really don&#39;t want to write it in bash, but it&#39;s still a possibility)</li></ul>

<p>As you can see, the first four languages are compiled languages, then Java and
Scala are (lets call it) Semi-Compiled languages and the others are scripting
languages. All of these languages have certain advantages over others.</p>

<h1 id="the-compiled-languages" id="the-compiled-languages">The compiled languages</h1>

<p>... have the advantages that they are <em>fast</em>. Haskell and Rust also have the
advantages that if the compiler does not fail compiling the sources, the
program just works ™.</p>

<p>Also, learning C++, Haskell or Rust would be a really great experience and may
be beneficial later in a job or something.</p>

<p>The semi-compiled languages are also (kind of) fast, but they are
JVM-languages, so I won&#39;t look into them here...</p>

<h1 id="the-scripting-languages" id="the-scripting-languages">The scripting languages</h1>

<p>Writing the application in a scripting language would have some other
advantages: They would be much more flexible and I&#39;d be faster writing the
application (compared to Rust or Haskell, which I would need to learn with the
application). I don&#39;t need to learn Ruby, I know a fair bit of Racket and I
guess I can get productive with Python or Lua really fast.</p>

<p>Bash is another option and I&#39;m actually an bash script for an almost similar
job right now. I could simply extend this script, that would be an option, of
course.</p>

<h1 id="so-which-is-the-right-tool-for-the-job" id="so-which-is-the-right-tool-for-the-job">So which is the right tool for the job?</h1>

<p>Can you tell me? I don&#39;t know which tool is the right tool for the job. After
all, I don&#39;t think I should write such an application from scratch. So, for
me, there are two options left: Extending
<a href="https://maebert.github.io/jrnl">jrnl</a>, which is an Python script, or
extending diary (I do not even find a link for this anymore), which is a bash
script. Extending the bash script would be an easy job, I guess. But it
wouldn&#39;t be as flexible as the Python tool is already.
tags:  <a href="https://beyermatthias.de/tag:bash" class="hashtag"><span>#</span><span class="p-category">bash</span></a> <a href="https://beyermatthias.de/tag:c" class="hashtag"><span>#</span><span class="p-category">c</span></a> <a href="https://beyermatthias.de/tag:c" class="hashtag"><span>#</span><span class="p-category">c</span></a>++ <a href="https://beyermatthias.de/tag:haskell" class="hashtag"><span>#</span><span class="p-category">haskell</span></a> <a href="https://beyermatthias.de/tag:programming" class="hashtag"><span>#</span><span class="p-category">programming</span></a> <a href="https://beyermatthias.de/tag:racket" class="hashtag"><span>#</span><span class="p-category">racket</span></a> <a href="https://beyermatthias.de/tag:rust" class="hashtag"><span>#</span><span class="p-category">rust</span></a> <a href="https://beyermatthias.de/tag:shell" class="hashtag"><span>#</span><span class="p-category">shell</span></a> <a href="https://beyermatthias.de/tag:tools" class="hashtag"><span>#</span><span class="p-category">tools</span></a></p>
]]></content:encoded>
      <guid>https://beyermatthias.de/too-much-languages-to-choose-from</guid>
      <pubDate>Mon, 26 Jan 2015 16:37:29 +0100</pubDate>
    </item>
    <item>
      <title>Switch or no switch, that&#39;s the question!</title>
      <link>https://beyermatthias.de/switch-or-no-switch-thats-the-question</link>
      <description>&lt;![CDATA[I already wrote about the project me and&#xA;some friends at my university are currently doing. One of my team mates came&#xA;up with the idea of porting the codebase from C to C++, yesterday&#xA;the appropriate issue&#xA;was opened Yesterday, to discuss it. I&#39;m not sure what to think.&#xA;&#xA;!-- more --&#xA;&#xA;The idea is to port the codebase as soon as possible to C++. I do not like&#xA;this idea entirely, as I think the port should be done after the project&#xA;phase, but not within. I consider myself at a newbie-like level when it comes&#xA;to C++ and I think other project members feel almost the same, maybe better,&#xA;but not on an expert level or whatsoever. Given the fact that we&#39;re already&#xA;running out of time, I think a port of the (30K LOC) codebase would quite take&#xA;some time and would cause the project to be delayed even more.&#xA;&#xA;So I&#39;m trying to push back on that part. A port after the project phase&#xA;would be another question, which I want to talk about here.&#xA;&#xA;First of all: I don&#39;t think a port to another language is required, as I&#xA;consider the codebase as very clean and carefully designed. The architecture&#xA;is good, the code is well documented, the abstractions are clearly defined. A&#xA;port to another programming language would have a certain level of impact on&#xA;this, but I think we are able to handle that. I see the improvements which&#xA;could be made by a port to a OOP(-like) language, though.&#xA;&#xA;Having inheritance build into the language, having a template-like system in&#xA;the language and having methods, virtual functions and the like would cause&#xA;some redesign but also some improvements.&#xA;&#xA;My project mate suggested C++ as language. Now, the careful reader knows that&#xA;I don&#39;t like C++ that much. Some of my points are maybe valid, some not. But&#xA;well, this is a very opinion-based topic, and I won&#39;t go into further detail&#xA;or discussion about that topic here. What I think, though, is that it would be&#xA;nice to port to a language which gives us more power (simplifying to the&#xA;terminus &#34;power&#34; here to refer to possibilities to do abstractions, building&#xA;complexity and the like) and security. I think C++ gives us more power about&#xA;the code, which is very good. I don&#39;t think C++ gives us more security,&#xA;meaning secure code. I think one can very simply do the same mistakes in C++&#xA;as in C, speaking of semantics of the code. For example you can create data&#xA;races, thread related problems or memory corruption in C++ as well as in C.&#xA;&#xA;That given, I consider C++ as an improvement to the code, but not the best&#xA;possibility. My opinion is currently that a port to Rust would be a much&#xA;better option, as Rust gives us memory safety, prevents us from doing nasty&#xA;things with memory, including all the thread stuff. Given the fact that none&#xA;of us is able to write Rust on an expert level by now, the question of doing&#xA;the port within the project phase or after is answered automatically. Also,&#xA;Rust is not stable yet. I would at least wait for version 1.0 of the Rust&#xA;language before doing the port, possibly saving some time of Rust-to-Rust&#xA;porting.&#xA;&#xA;I still don&#39;t think a port is necessary and I really like the code we produce.&#xA;I can see the advantages over staying in C, but for me personally, the&#xA;disadvantages overweight by now. This may change in future, but for now and&#xA;for the rest of the project phase, this is my opinion on the topic.&#xA;&#xA;The discussion on github is not done yet, of course. I will carefully propose&#xA;my opinion there, as this has become a very explosive topic by now. This&#xA;article was just written to be a short overview over the topic and also to be&#xA;a summary of my thoughts.&#xA;&#xA;tags:  #programming #c #rust #c++ #software&#xA;]]&gt;</description>
      <content:encoded><![CDATA[<p>I already wrote about <a href="https://github.com/waysome/waysome">the project</a> me and
some friends at my university are currently doing. One of my team mates came
up with the idea of porting the codebase from C to C++, yesterday
<a href="https://github.com/waysome/waysome/issues/440">the appropriate issue</a>
was opened Yesterday, to discuss it. I&#39;m not sure what to think.</p>



<p>The idea is to port the codebase as soon as possible to C++. I do not like
this idea entirely, as I think the port should be done after the project
phase, but not within. I consider myself at a newbie-like level when it comes
to C++ and I think other project members feel almost the same, maybe better,
but not on an expert level or whatsoever. Given the fact that we&#39;re already
running out of time, I think a port of the (30K LOC) codebase would quite take
some time and would cause the project to be delayed even more.</p>

<p>So I&#39;m trying to push back on that part. A port <em>after</em> the project phase
would be another question, which I want to talk about here.</p>

<p>First of all: I don&#39;t think a port to another language is required, as I
consider the codebase as very clean and carefully designed. The architecture
is good, the code is well documented, the abstractions are clearly defined. A
port to another programming language would have a certain level of impact on
this, but I think we are able to handle that. I see the improvements which
could be made by a port to a OOP(-like) language, though.</p>

<p>Having inheritance build into the language, having a template-like system in
the language and having methods, virtual functions and the like would cause
some redesign but also some improvements.</p>

<p>My project mate suggested C++ as language. Now, the careful reader knows that
I don&#39;t like C++ that much. Some of my points are maybe valid, some not. But
well, this is a very opinion-based topic, and I won&#39;t go into further detail
or discussion about that topic here. What I think, though, is that it would be
nice to port to a language which gives us more power (simplifying to the
terminus “power” here to refer to possibilities to do abstractions, building
complexity and the like) and security. I think C++ gives us more power about
the code, which is very good. I don&#39;t think C++ gives us more security,
meaning secure code. I think one can very simply do the same mistakes in C++
as in C, speaking of semantics of the code. For example you can create data
races, thread related problems or memory corruption in C++ as well as in C.</p>

<p>That given, I consider C++ as an improvement to the code, but not the best
possibility. My opinion is currently that a port to Rust would be a much
better option, as Rust gives us memory safety, prevents us from doing nasty
things with memory, including all the thread stuff. Given the fact that none
of us is able to write Rust on an expert level by now, the question of doing
the port within the project phase or after is answered automatically. Also,
Rust is not stable yet. I would at least wait for version 1.0 of the Rust
language before doing the port, possibly saving some time of Rust-to-Rust
porting.</p>

<p>I still don&#39;t think a port is necessary and I really like the code we produce.
I can see the advantages over staying in C, but for me personally, the
disadvantages overweight by now. This may change in future, but for now and
for the rest of the project phase, this is my opinion on the topic.</p>

<p>The discussion on github is not done yet, of course. I will carefully propose
my opinion there, as this has become a very explosive topic by now. This
article was just written to be a short overview over the topic and also to be
a summary of my thoughts.</p>

<p>tags:  <a href="https://beyermatthias.de/tag:programming" class="hashtag"><span>#</span><span class="p-category">programming</span></a> <a href="https://beyermatthias.de/tag:c" class="hashtag"><span>#</span><span class="p-category">c</span></a> <a href="https://beyermatthias.de/tag:rust" class="hashtag"><span>#</span><span class="p-category">rust</span></a> <a href="https://beyermatthias.de/tag:c" class="hashtag"><span>#</span><span class="p-category">c</span></a>++ <a href="https://beyermatthias.de/tag:software" class="hashtag"><span>#</span><span class="p-category">software</span></a></p>
]]></content:encoded>
      <guid>https://beyermatthias.de/switch-or-no-switch-thats-the-question</guid>
      <pubDate>Sat, 22 Nov 2014 16:42:04 +0100</pubDate>
    </item>
    <item>
      <title>Learning C++ - Less Bullshit (Part 3)</title>
      <link>https://beyermatthias.de/learning-c-less-bullshit-part-3</link>
      <description>&lt;![CDATA[This is the third part of my series about C++.&#xA;&#xA;After some serious discussions with several people, I came to a conclusion.&#xA;Well, not really a conclusion, as it was clear from the beginning of the series&#xA;or even before, when I started to learn C++ at my university, but a point where&#xA;I can say that C++ is not as shitty as I thought before.&#xA;&#xA;Well, even the word &#34;bullshit&#34; isn&#39;t the right terminus.&#xA;&#xA;!-- more --&#xA;&#xA;C++ does some things which seem to be really really weird when you first&#xA;start learning it. After all, I wouldn&#39;t suggest it as first programming&#xA;language to a newbie!&#xA;&#xA;I still consider the syntax of C++ as bloated and not really helpful in&#xA;certain ways, as (for my taste) one can hide too much of the relevant stuff.&#xA;One cannot directly see what&#39;s happening in a piece of code without knowing&#xA;the stuff around the code, the infrastructure or at least the types of the&#xA;variables. Other languages solve this &#34;problem&#34; much better.&#xA;&#xA;I had a discussion with a friend of mine who is really into C++ and he&#xA;explained the benefits, which I fully understand. I also had a discussion&#xA;with a friend who is at most a C++-Critic. Both of them made valid points.&#xA;&#xA;After all, it is a matter of taste whether you like C++ or you don&#39;t. I do not&#xA;like it. I can see its benefits over C, but I consider other languages as&#xA;better. C++ has a historical background, of course. I don&#39;t want to ciritcize&#xA;this, but I think there are other languages which adress the problems C++&#xA;addresses much better today.&#xA;&#xA;I&#39;m speaking of D, Rust, Go and the like, of course. I also consider languages&#xA;like Haskell, Erlang, the whole Lisp Family and the JVM stuff as better&#xA;solutions to most problems. Not only that I consider them as easier to learn,&#xA;but also much easier to maintain and less cluttered with language elements one&#xA;has to understand to work on an existing codebase.&#xA;tags:  #programming #c++&#xA;]]&gt;</description>
      <content:encoded><![CDATA[<p>This is the third part of my series about C++.</p>

<p>After some serious discussions with several people, I came to a conclusion.
Well, not really a conclusion, as it was clear from the beginning of the series
or even before, when I started to learn C++ at my university, but a point where
I can say that C++ is not as shitty as I thought before.</p>

<p>Well, even the word “bullshit” isn&#39;t the right terminus.</p>



<p>C++ does some things which seem to be really really weird when you first
start learning it. After all, I wouldn&#39;t suggest it as first programming
language to a newbie!</p>

<p>I still consider the syntax of C++ as bloated and not really helpful in
certain ways, as (for my taste) one can hide <em>too</em> much of the relevant stuff.
One cannot directly see what&#39;s happening in a piece of code without knowing
the stuff around the code, the infrastructure or at least the types of the
variables. Other languages solve this “problem” much better.</p>

<p>I had a discussion with a friend of mine who is really into C++ and he
explained the benefits, which I fully understand. I also had a discussion
with a friend who is at most a C++-Critic. Both of them made valid points.</p>

<p>After all, it is a matter of taste whether you like C++ or you don&#39;t. I do not
like it. I can see its benefits over C, but I consider other languages as
better. C++ has a historical background, of course. I don&#39;t want to ciritcize
this, but I think there are other languages which adress the problems C++
addresses much better today.</p>

<p>I&#39;m speaking of D, Rust, Go and the like, of course. I also consider languages
like Haskell, Erlang, the whole Lisp Family and the JVM stuff as better
solutions to most problems. Not only that I consider them as easier to learn,
but also much easier to maintain and less cluttered with language elements one
has to understand to work on an existing codebase.
tags:  <a href="https://beyermatthias.de/tag:programming" class="hashtag"><span>#</span><span class="p-category">programming</span></a> <a href="https://beyermatthias.de/tag:c" class="hashtag"><span>#</span><span class="p-category">c</span></a>++</p>
]]></content:encoded>
      <guid>https://beyermatthias.de/learning-c-less-bullshit-part-3</guid>
      <pubDate>Sun, 16 Nov 2014 16:41:56 +0100</pubDate>
    </item>
  </channel>
</rss>