<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>open &amp;mdash; musicmatzes blog</title>
    <link>https://beyermatthias.de/tag:open</link>
    <description></description>
    <pubDate>Thu, 03 Dec 2026 19:00:37 +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>How to improve your open source code (9) - Types</title>
      <link>https://beyermatthias.de/how-to-improve-your-open-source-code-9-types</link>
      <description>&lt;![CDATA[small&#xA;  This post was written during my trip through Iceland and published much&#xA;  later than it was written.&#xA;/small&#xA;&#xA;This is a really important topic in programming and I really hope to get&#xA;this article right. Not only for technical correctness, but also for&#xA;ease to understand, as explaining types is not that simple if one has&#xA;never heard of them.&#xA;&#xA;Let&#39;s give it a try...&#xA;&#xA;What are types&#xA;&#xA;Well, that&#39;s a question which is, in my opinion, not easy to answer. In&#xA;fact, I thought several days about this question before writing this&#xA;down, in hope it will become a sufficient answer. Hence, you might find&#xA;other answers which are easier to understand and maybe more correct as&#xA;mine, but I&#39;ll give it a try nonetheless.&#xA;&#xA;From what I think&#xA;&#xA;  Types are a combination of abilities and properties that are combined&#xA;  to express and limit a certain scope of a thing.&#xA;&#xA;For example, A type Car may have four wheels, two doors and a horn&#xA;(its properties) and can drive slow, drive fast and park (its&#xA;abilities). That is certainly not a real representation of a car (also&#xA;because only a car is a real representation of a car) but because of the&#xA;domain this is used in, it is sufficient in the scenario at hand.  The&#xA;type Car cannot be multiplied, but another type Number may have this&#xA;ability. Thus, the scope and abilities are also limited in a certain&#xA;way.&#xA;&#xA;I hope this description is a good one for you to understand.&#xA;&#xA;Now that we know what types are, we should also learn some other terms&#xA;around the subject of types. The first thing I want to talk about here&#xA;is &#34;strong typing&#34; and &#34;weak typing&#34;. The reason for this is: These&#xA;things do not exist. Yes, you&#39;ve read this correctly: There is no such&#xA;thing as &#34;strong typing&#34;. There is only stronger and weaker&#xA;typing. The Java programming language is not strongly typed, neither&#xA;is it weakly typed (but it is, of course badly typed... forgive me&#xA;that joke, pity java programmer).&#xA;&#xA;But what is a stronger typing? That is rather simple to explain,&#xA;actually. We discussed that types are limitations of things to be able&#xA;to only do some specific operations and such. These things are enforced&#xA;by the compiler or interpreter of the programming language, of course.&#xA;And stronger typing only says that the compiler has more information&#xA;(implicitly via the definition of the programming language) to enforce&#xA;these rules, the rules of &#34;the function A is defined for type T, so you&#xA;cannot call it on U&#34;. Of course there is more to that because of generic&#xA;typing and so on, but that&#39;s basically it.&#xA;&#xA;The next term is &#34;type inference&#34;. Type inference is nothing a&#xA;programmer experiences explicitely, because it happens implicitly. Type&#xA;inference is a feature of the compiler and interpreter of the language&#xA;to guess the type of a variable without the programmer stating the&#xA;actual type. It&#39;s nothing more to that actually.&#xA;&#xA;I mentioned the term &#34;generic types&#34; in one of the former paragraphs&#xA;already, so we should have a look there, too. Generic types, or shorter&#xA;Generics, are types which are partial, in a way. So for example, one&#xA;can define a Bag of things, whatever things is. This is often (at&#xA;least in typed languages - languages where types actually matter for the&#xA;compiler or interpreter) specified in the code via &#34;type parameters&#34;&#xA;(though this term differs from language to language).&#xA;&#xA;Why more types are better then few&#xA;&#xA;The more types you introduce in your programs (internally or even for&#xA;the public API), the more safety you get (speaking in the context of a&#xA;stronger typed programming language, but also if you do a lot of&#xA;runtime-type-checking in a weaker typed language).  That does not mean&#xA;that you should introduce a BlueCar, a BlackCar and a GreenCar as&#xA;types in your program, but rather a type Color and a type Car&#xA;whereas each Car has a Color - even if your domain is cars and not&#xA;colors.&#xA;&#xA;Maybe that example lacks a certain expressiveness, so consider this:&#xA;Your Car has wheels. You can set the number of wheels when&#xA;constructing the Car object. But instead of passing an integer here,&#xA;which would yield an API where one can pass 17 as valid number for the&#xA;number of wheels - or 1337 or possibly even -1. But if you introduce a&#xA;type which represents the number of wheels, you get some safety into the&#xA;construction of the Car object - safety checks in your code are not&#xA;necessary anymore and thus your code will be shorter, better focused on&#xA;what the actual problem is instead of fighting for valid values and of&#xA;course, the compiler or interpreter can do the work for you.&#xA;&#xA;Sounds nice, doesn&#39;t it? You can get this all with (almost) no cost&#xA;attached, you just have to write down some more types. If your&#xA;programming language contains feature like enumerations, you do not even&#xA;have to make validity checks anymore, as the compiler can execute them.&#xA;&#xA;Next&#xA;&#xA;In the next post we will focus on the coding environment.&#xA;&#xA;tags: #open-source #programming #software #tools #rust&#xA;]]&gt;</description>
      <content:encoded><![CDATA[<p><small>
  This post was written during my trip through Iceland and published much
  later than it was written.
</small></p>

<p>This is a really important topic in programming and I really hope to get
this article right. Not only for technical correctness, but also for
ease to understand, as explaining types is not that simple if one has
never heard of them.</p>

<p>Let&#39;s give it a try...</p>

<h1 id="what-are-types" id="what-are-types">What are types</h1>

<p>Well, that&#39;s a question which is, in my opinion, not easy to answer. In
fact, I thought several days about this question before writing this
down, in hope it will become a sufficient answer. Hence, you might find
other answers which are easier to understand and maybe more correct as
mine, but I&#39;ll give it a try nonetheless.</p>

<p>From what I think</p>

<blockquote><p>Types are a combination of abilities and properties that are combined
to express and limit a certain scope of a thing.</p></blockquote>

<p>For example, A type <code>Car</code> may have four wheels, two doors and a horn
(its properties) and can drive slow, drive fast and park (its
abilities). That is certainly not a real representation of a car (also
because only a car is a real representation of a car) but because of the
domain this is used in, it is sufficient in the scenario at hand.  The
type <code>Car</code> cannot be multiplied, but another type <code>Number</code> may have this
ability. Thus, the scope and abilities are also limited in a certain
way.</p>

<p>I hope this description is a good one for you to understand.</p>

<p>Now that we know what types are, we should also learn some other terms
around the subject of types. The first thing I want to talk about here
is “strong typing” and “weak typing”. The reason for this is: These
things do not exist. Yes, you&#39;ve read this correctly: There is no such
thing as “strong typing”. There is only strong<strong>er</strong> and weak<strong>er</strong>
typing. The Java programming language is not <em>strongly typed</em>, neither
is it <em>weakly typed</em> (but it is, of course <em>badly typed</em>... forgive me
that joke, pity java programmer).</p>

<p>But what is a stronger typing? That is rather simple to explain,
actually. We discussed that types are limitations of things to be able
to only do some specific operations and such. These things are enforced
by the compiler or interpreter of the programming language, of course.
And stronger typing only says that the compiler has more information
(implicitly via the definition of the programming language) to enforce
these rules, the rules of “the function A is defined for type T, so you
cannot call it on U”. Of course there is more to that because of generic
typing and so on, but that&#39;s basically it.</p>

<p>The next term is “type inference”. Type inference is nothing a
programmer experiences explicitely, because it happens implicitly. Type
inference is a feature of the compiler and interpreter of the language
to <em>guess</em> the type of a variable without the programmer stating the
actual type. It&#39;s nothing more to that actually.</p>

<p>I mentioned the term “generic types” in one of the former paragraphs
already, so we should have a look there, too. Generic types, or shorter
<em>Generics</em>, are types which are partial, in a way. So for example, one
can define a <code>Bag</code> of <em>things</em>, whatever <em>things</em> is. This is often (at
least in typed languages – languages where types actually matter for the
compiler or interpreter) specified in the code via “type parameters”
(though this term differs from language to language).</p>

<h1 id="why-more-types-are-better-then-few" id="why-more-types-are-better-then-few">Why more types are better then few</h1>

<p>The more types you introduce in your programs (internally or even for
the public API), the more safety you get (speaking in the context of a
stronger typed programming language, but also if you do a lot of
runtime-type-checking in a weaker typed language).  That does not mean
that you should introduce a <code>BlueCar</code>, a <code>BlackCar</code> and a <code>GreenCar</code> as
types in your program, but rather a type <code>Color</code> and a type <code>Car</code>
whereas each <code>Car</code> has a <code>Color</code> – even if your domain is cars and not
colors.</p>

<p>Maybe that example lacks a certain expressiveness, so consider this:
Your <code>Car</code> has wheels. You can set the number of wheels when
constructing the <code>Car</code> object. But instead of passing an integer here,
which would yield an API where one can pass 17 as valid number for the
number of wheels – or 1337 or possibly even -1. But if you introduce a
type which represents the number of wheels, you get some safety into the
construction of the <code>Car</code> object – safety checks in your code are not
necessary anymore and thus your code will be shorter, better focused on
what the actual problem is instead of fighting for valid values and of
course, the compiler or interpreter can do the work for you.</p>

<p>Sounds nice, doesn&#39;t it? You can get this all with (almost) no cost
attached, you just have to write down some more types. If your
programming language contains feature like enumerations, you do not even
have to make validity checks anymore, as the compiler can execute them.</p>

<h1 id="next" id="next">Next</h1>

<p>In the next post we will focus on the coding environment.</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:software" class="hashtag"><span>#</span><span class="p-category">software</span></a> <a href="https://beyermatthias.de/tag:tools" class="hashtag"><span>#</span><span class="p-category">tools</span></a> <a href="https://beyermatthias.de/tag:rust" class="hashtag"><span>#</span><span class="p-category">rust</span></a></p>
]]></content:encoded>
      <guid>https://beyermatthias.de/how-to-improve-your-open-source-code-9-types</guid>
      <pubDate>Sun, 22 Apr 2018 16:39:30 +0200</pubDate>
    </item>
    <item>
      <title>How to improve your open source code (8) - Code verbosity</title>
      <link>https://beyermatthias.de/how-to-improve-your-open-source-code-8-code-verbosity</link>
      <description>&lt;![CDATA[small&#xA;  This post was written during my trip through Iceland and published much&#xA;  latern than it was written.&#xA;/small&#xA;&#xA;While we heavily focused on the code-surrounding things in the last&#xA;parts, we will return to focus on code-related things from here on.&#xA;&#xA;This article discusses code verbosity and how it can improve your open&#xA;source code and also your contributors experience a lot.&#xA;&#xA;What is code verbosity&#xA;&#xA;Code verbosity is mainly explicitness of code. For example, in Java you&#xA;have to be more explicit when declaring a variable than in (recent) C++&#xA;or even Ruby:&#xA;&#xA;String s = someFunctionCall(param); // Java&#xA;&#xA;auto s = someFunctionCall(param); // C++&#xA;&#xA;s = someFunctionCall param # Ruby&#xA;&#xA;So code verbosity is how explicit you have to state certain things&#xA;so that the compiler or interpreter understands your intention.&#xA;&#xA;Because we do not always tell the compiler or interpreter what we want&#xA;to do exactly and because we want to re-use functionality, we&#xA;introduced abstractions. So abstractions are a way to make code less&#xA;verbose, in some ways.&#xA;&#xA;How to make code less verbose&#xA;&#xA;Abstraction. It is as simple as this. You introduce abstraction to&#xA;minimize repetition which leads to less verbose code. Of course, you&#xA;cannot always make the code less verbose if the language does not allow&#xA;it: in the above example we used the auto keyword for specifying the&#xA;type in C++, which is nice, but not possible in Java. So in the borders&#xA;of your languages abilities, you can make code less verbose.&#xA;&#xA;If you do that right and the abstractions results in nice code, you&#xA;know that you&#39;ve done fine.&#xA;&#xA;How much is too much&#xA;&#xA;But there can also be too much abstraction which then yields unreadable&#xA;code. Not unreadable as in clustered with stuff but just too abstract to&#xA;grasp at first sight.&#xA;&#xA;Abstraction can get too much. So make sure you introduce sensible&#xA;abstractions, abstractions that can be combined nicely and of course one&#xA;can step around the abstractions and use the core functionality, the&#xA;not-abstracted things beneath.&#xA;&#xA;As a sidenote: sometimes it makes sense to hide certain things&#xA;completely or even introducing several layers of abstractions.&#xA;&#xA;Next&#xA;&#xA;This was a rather short one, I guess. The next article will be longer I&#xA;hope, as it will be about typing.&#xA;&#xA;tags: #open-source #programming #software #tools #rust&#xA;]]&gt;</description>
      <content:encoded><![CDATA[<p><small>
  This post was written during my trip through Iceland and published much
  latern than it was written.
</small></p>

<p>While we heavily focused on the code-surrounding things in the last
parts, we will return to focus on code-related things from here on.</p>

<p>This article discusses code verbosity and how it can improve your open
source code and also your contributors experience a lot.</p>

<h1 id="what-is-code-verbosity" id="what-is-code-verbosity">What is code verbosity</h1>

<p>Code verbosity is mainly explicitness of code. For example, in Java you
have to be more explicit when declaring a variable than in (recent) C++
or even Ruby:</p>

<pre><code>String s = someFunctionCall(param); // Java

auto s = someFunctionCall(param); // C++

s = someFunctionCall param # Ruby
</code></pre>

<p>So code verbosity is how <em>explicit</em> you have to <em>state</em> certain things
so that the compiler or interpreter understands your intention.</p>

<p>Because we do not always tell the compiler or interpreter what we want
to do <em>exactly</em> and because we want to re-use functionality, we
introduced <em>abstractions</em>. So abstractions are a way to make code less
verbose, in some ways.</p>

<h1 id="how-to-make-code-less-verbose" id="how-to-make-code-less-verbose">How to make code less verbose</h1>

<p>Abstraction. It is as simple as this. You introduce abstraction to
minimize repetition which leads to less verbose code. Of course, you
cannot always make the code less verbose if the language does not allow
it: in the above example we used the <code>auto</code> keyword for specifying the
type in C++, which is nice, but not possible in Java. So in the borders
of your languages abilities, you can make code less verbose.</p>

<p>If you do that right and the abstractions results in nice code, you
know that you&#39;ve done fine.</p>

<h1 id="how-much-is-too-much" id="how-much-is-too-much">How much is too much</h1>

<p>But there can also be too much abstraction which then yields unreadable
code. Not unreadable as in clustered with stuff but just too abstract to
grasp at first sight.</p>

<p>Abstraction can get too much. So make sure you introduce sensible
abstractions, abstractions that can be combined nicely and of course one
can step around the abstractions and use the core functionality, the
not-abstracted things beneath.</p>

<p>As a sidenote: sometimes it makes sense to hide certain things
completely or even introducing several layers of abstractions.</p>

<h1 id="next" id="next">Next</h1>

<p>This was a rather short one, I guess. The next article will be longer I
hope, as it will be about typing.</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:software" class="hashtag"><span>#</span><span class="p-category">software</span></a> <a href="https://beyermatthias.de/tag:tools" class="hashtag"><span>#</span><span class="p-category">tools</span></a> <a href="https://beyermatthias.de/tag:rust" class="hashtag"><span>#</span><span class="p-category">rust</span></a></p>
]]></content:encoded>
      <guid>https://beyermatthias.de/how-to-improve-your-open-source-code-8-code-verbosity</guid>
      <pubDate>Wed, 04 Apr 2018 16:39:28 +0200</pubDate>
    </item>
    <item>
      <title>How to improve your open source code (7) - Contributor experience</title>
      <link>https://beyermatthias.de/how-to-improve-your-open-source-code-7-contributor-experience</link>
      <description>&lt;![CDATA[small&#xA;  This post was written during my trip through Iceland and published much&#xA;  latern than it was written.&#xA;/small&#xA;&#xA;This is the last post which does not deal with code directly, I promise.&#xA;&#xA;When it comes to open source hobby projects, contributions from others&#xA;are often happily taken. But making the contribution process smooth for&#xA;everyone does involve some precautions.&#xA;&#xA;In this article I want to summarize how to make a contribution to a&#xA;project as smooth as possible for all persons involved.&#xA;&#xA;Public code and contributions&#xA;&#xA;I wrote about this before and I want to shortly reiterate on it. &#34;Open&#34;&#xA;as in open source (or even better: open contributions) is not&#xA;black-white at all but there are several levels of grey in between, in my&#xA;opinion.&#xA;&#xA;The more open your code is, the better a contributor is able to&#xA;contribute. Whether it be discussion, requests, bug reports, bug fixes&#xA;or even feature implementation or general enhancement.  On the other&#xA;side, though, the more open your code is the less your contributors are&#xA;&#34;bound&#34; (in a mentally way) to your project. It can happen (and it&#xA;happened to me) that a contributor stops by for one pull request or&#xA;issue and then you&#39;ll never hear of them. The better the contribution&#xA;process is for them, the more likely they come back - and how relevant&#xA;the project is to them, of course.&#xA;&#xA;The contribution process in the rust community (for the Rust compiler&#xA;itself) is awesome, from what I&#39;ve heard. This, of course, enhances the&#xA;&#34;I will come back and give another issue a try&#34; a lot.&#xA;The&#xA;contribution process of the nixpkgs project is slightly worse (but still&#xA;rather good). Sometimes, nobody answers questions you might have for&#xA;your pull request for several days or even weeks.&#xA;This does not really make one eager to file another request.&#xA;&#xA;Platforms&#xA;&#xA;From what I think, github is the &#34;most open&#34; in the sense of&#xA;&#34;open contributions&#34;.&#xA;That&#39;s not only because of how github works, as other platforms&#xA;work equally well (gitlab, gitea, gogs, bitbucket) but also because&#xA;everyone is on github.&#xA;&#xA;If you want to close down contributions a bit, you could host your own&#xA;instances of gitea or gitlab - contributors can easily open an account&#xA;for their contribution, though that slight hurdle will make the &#34;casual&#xA;code dumper&#34; likely go away.&#xA;&#xA;Even &#34;more closed&#34; would be a email-patch-workflow, git supports (and&#xA;the kernel community uses successfully for years now). In this case, the&#xA;code is often made available via a web interface like cgit or&#xA;klaus.&#xA;&#xA;Readme&#xA;&#xA;A project should always contain a readme file in its root folder. The&#xA;readme file is often the first thing a contributor will look at, not&#xA;only but also because github renders and displays them.&#xA;&#xA;Therefore, keeping your readme file up to date and filled with current&#xA;information can be a good way to show your contributors (and users) what&#xA;is going on in the projects code base. It should contain a short&#xA;description what the project/code does and how it works (only from a&#xA;users view - implementation details or why you implemented this in&#xA;Haskell instead of JavaScript do not necessarily belong here). It should&#xA;contain a few examples how to use the code or, if it is a library, how&#xA;to call it. It also should contain build instructions (if necessary) or&#xA;a pointer to a &#34;BUILDING&#34; file if the build process is long or&#xA;complicated. At the end of the Readme file, a license statement (how the&#xA;project is licensed) should be pasted. Not the entire license, but only&#xA;a short note and a copyright note as well. It happens to be kind to do&#xA;so.&#xA;&#xA;Contributing File&#xA;&#xA;Often, projects contain a Contributing file where guidelines (or even&#xA;rules) are written down on how to contribute. It does not only contain&#xA;statements on how code is submitted but also how issues are filed or&#xA;requests should be made.&#xA;&#xA;I think it is extremely important to have such an file available,&#xA;especially if not hosting the code on a site like github, where it is&#xA;obvious that code is submitted through pull requests and issues are&#xA;submitted via the issue tracker.&#xA;&#xA;The length of such an file should respect the size of the project&#xA;itself. If the project contains 10KLOC, one should be able to read the&#xA;contribution file in less than two minutes, preferably in less than one&#xA;minute. It should state not only how code should be submitted, but also&#xA;whether it should conform to some style guide (which itself can be&#xA;outsourced to yet another file), how to behave in&#xA;the community, how to write bug reports and also how to file issues&#xA;(what information must be included).&#xA;&#xA;Issue handling&#xA;&#xA;Handling issues is clearly a way to improve the contributors experience.&#xA;As soon as a contributor files an issue, she or he should be greeted&#xA;and thanked for the issue. Take it this way: Someone just invested time&#xA;to look at your project and cared enough to have a question, try it out&#xA;or even found a bug. This is truly a cool thing and therefore they&#xA;should be thanked for this, as soon as you have the time to do so. The&#xA;Rust community even automated this, but I don&#39;t think this would be&#xA;necessary for a small or medium sized project/community.&#xA;&#xA;So be nice to every one. Nothing is worse than a maintainer that babbles&#xA;about bad things or insults the contributor because of his or her ideas&#xA;or ways an issue was proposed to be resolved. Don&#39;t ever do this. I&#39;ve&#xA;seen issues where the maintainer of the project started rambling about&#xA;how bad things were (not the project itself but rather its dependencies&#xA;or even things that had nothing to do with the project itself). I&#xA;cannot believe that such projects will last long, let alone survive at&#xA;all. These projects will die.&#xA;&#xA;Also, your ramblings have nothing to do with the issue at hand and even&#xA;if they do: be kind and humble will most likely be better in every way,&#xA;right?&#xA;&#xA;Next&#xA;&#xA;In the next part we will finally go back and actually talk code.&#xA;&#xA;What I want to discuss in the next article of this series is code&#xA;verbosity. I want to make sure how DRY a code actually needs to be and&#xA;how much abstraction is enough for the sake of understandability and&#xA;cleanness of code.&#xA;&#xA;tags: #open-source #programming #software #tools #rust&#xA;]]&gt;</description>
      <content:encoded><![CDATA[<p><small>
  This post was written during my trip through Iceland and published much
  latern than it was written.
</small></p>

<p>This is the last post which does not deal with code directly, I promise.</p>

<p>When it comes to open source hobby projects, contributions from others
are often happily taken. But making the contribution process smooth for
everyone does involve some precautions.</p>

<p>In this article I want to summarize how to make a contribution to a
project as smooth as possible for all persons involved.</p>

<h1 id="public-code-and-contributions" id="public-code-and-contributions">Public code and contributions</h1>

<p>I wrote about this before and I want to shortly reiterate on it. “Open”
as in open source (or even better: open contributions) is not
black-white at all but there are several levels of grey in between, in my
opinion.</p>

<p>The more open your code is, the better a contributor is able to
contribute. Whether it be discussion, requests, bug reports, bug fixes
or even feature implementation or general enhancement.  On the other
side, though, the more open your code is the less your contributors are
“bound” (in a mentally way) to your project. It can happen (and it
happened to me) that a contributor stops by for one pull request or
issue and then you&#39;ll never hear of them. The better the contribution
process is for them, the more likely they come back – and how relevant
the project is to them, of course.</p>

<p>The contribution process in the rust community (for the Rust compiler
itself) is awesome, from what I&#39;ve heard. This, of course, enhances the
“I will come back and give another issue a try” a lot.
The
contribution process of the nixpkgs project is slightly worse (but still
rather good). Sometimes, nobody answers questions you might have for
your pull request for several days or even weeks.
This does not really make one eager to file another request.</p>

<h1 id="platforms" id="platforms">Platforms</h1>

<p>From what I think, github is the “most open” in the sense of
“open contributions”.
That&#39;s not only because of how github works, as other platforms
work equally well (gitlab, gitea, gogs, bitbucket) but also because
<em>everyone is on github</em>.</p>

<p>If you want to close down contributions a bit, you could host your own
instances of gitea or gitlab – contributors can easily open an account
for their contribution, though that slight hurdle will make the “casual
code dumper” likely go away.</p>

<p>Even “more closed” would be a email-patch-workflow, git supports (and
the kernel community uses successfully for years now). In this case, the
code is often made available via a web interface like cgit or
<a href="https://github.com/jonashaag/klaus">klaus</a>.</p>

<h1 id="readme" id="readme">Readme</h1>

<p>A project should always contain a readme file in its root folder. The
readme file is often the first thing a contributor will look at, not
only but also because github renders and displays them.</p>

<p>Therefore, keeping your readme file up to date and filled with current
information can be a good way to show your contributors (and users) what
is going on in the projects code base. It should contain a short
description what the project/code does and how it works (only from a
users view – implementation details or why you implemented this in
Haskell instead of JavaScript do not necessarily belong here). It should
contain a few examples how to use the code or, if it is a library, how
to call it. It also should contain build instructions (if necessary) or
a pointer to a “BUILDING” file if the build process is long or
complicated. At the end of the Readme file, a license statement (how the
project is licensed) should be pasted. Not the entire license, but only
a short note and a copyright note as well. It happens to be kind to do
so.</p>

<h1 id="contributing-file" id="contributing-file">Contributing File</h1>

<p>Often, projects contain a <code>Contributing</code> file where guidelines (or even
rules) are written down on how to contribute. It does not only contain
statements on how code is submitted but also how issues are filed or
requests should be made.</p>

<p>I think it is extremely important to have such an file available,
<em>especially</em> if not hosting the code on a site like github, where it is
obvious that code is submitted through pull requests and issues are
submitted via the issue tracker.</p>

<p>The length of such an file should respect the size of the project
itself. If the project contains 10KLOC, one should be able to read the
contribution file in less than two minutes, preferably in less than one
minute. It should state not only how code should be submitted, but also
whether it should conform to some style guide (which itself can be
outsourced to yet another file), how to behave in
the community, how to write bug reports and also how to file issues
(what information must be included).</p>

<h1 id="issue-handling" id="issue-handling">Issue handling</h1>

<p>Handling issues is clearly a way to improve the contributors experience.
As soon as a contributor files an issue, she or he should be greeted
and thanked for the issue. Take it this way: Someone just invested time
to look at your project and cared enough to have a question, try it out
or even found a bug. This is truly a cool thing and therefore they
should be thanked for this, as soon as you have the time to do so. The
Rust community even automated this, but I don&#39;t think this would be
necessary for a small or medium sized project/community.</p>

<p>So be nice to every one. Nothing is worse than a maintainer that babbles
about bad things or insults the contributor because of his or her ideas
or ways an issue was proposed to be resolved. Don&#39;t ever do this. I&#39;ve
seen issues where the maintainer of the project started rambling about
how bad things were (not the project itself but rather its dependencies
or <em>even things that had nothing to do with the project itself</em>). I
cannot believe that such projects will last long, let alone survive at
all. These projects will die.</p>

<p>Also, your ramblings have nothing to do with the issue at hand and even
if they do: be kind and humble will most likely be better in every way,
right?</p>

<h1 id="next" id="next">Next</h1>

<p>In the next part we will finally go back and actually talk code.</p>

<p>What I want to discuss in the next article of this series is <em>code
verbosity</em>. I want to make sure how DRY a code actually needs to be and
how much abstraction is enough for the sake of understandability and
cleanness of code.</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:software" class="hashtag"><span>#</span><span class="p-category">software</span></a> <a href="https://beyermatthias.de/tag:tools" class="hashtag"><span>#</span><span class="p-category">tools</span></a> <a href="https://beyermatthias.de/tag:rust" class="hashtag"><span>#</span><span class="p-category">rust</span></a></p>
]]></content:encoded>
      <guid>https://beyermatthias.de/how-to-improve-your-open-source-code-7-contributor-experience</guid>
      <pubDate>Tue, 20 Mar 2018 16:39:16 +0100</pubDate>
    </item>
    <item>
      <title>Writing a git-dit web frontend with gotham, libgitdit and love</title>
      <link>https://beyermatthias.de/writing-a-git-dit-web-frontend-with-gotham-libgitdit-and-love</link>
      <description>&lt;![CDATA[I love the Rust language. And I love the library ecosystem the Rust community&#xA;provides.&#xA;&#xA;But let me start at the beginning.&#xA;&#xA;libgitdit&#xA;&#xA;In 2016, I and a friend of mine developed a library for distributed issue&#xA;tracking with git and a commandline frontend for that library.&#xA;The project, git-dit got a rather&#xA;good portion of attention on hackernews, reddit and of course on github.&#xA;Ranking at about 350 stars on github, this is the most successfull piece of&#xA;software I (co-)authored so far.&#xA;&#xA;Development sleeps right now, which is really unfortunate.&#xA;There is a number of unresolved issues, despite the software is usable today.&#xA;&#xA;A failed thesis&#xA;&#xA;My friend and I proposed a bachelors thesis at our university for writing a&#xA;web-viewer for git-dit.&#xA;Because we&#39;re both master students, we also offered to supervise this thesis.&#xA;&#xA;In the last semester, the thesis was assigned and I was happy when it started.&#xA;Today (or rather a few days ago) I was not that happy anymore, because I got&#xA;the end-result. I was able to compile it (yay), but after starting it, I was&#xA;not even able to open the web page because I did not know which port to use.&#xA;&#xA;After looking at the source, I was able to figure that part out.&#xA;Unfortunately, everything I tried to do via the web frontend failed (as in&#xA;nothing happened). I was not able to see any issues or anything else. Only&#xA;viewing the git configuration was possible - but that&#39;s the least thing I&#xA;cared about.&#xA;&#xA;So I figured: How hard can it be? If a bachelor student has half a year&#xA;time,... it must be hard? No, I guess not.&#xA;&#xA;Lets do that!&#xA;&#xA;So I started my own git-dit-web viewer. And I tracked the time it took to&#xA;implement it.&#xA;&#xA;I mean, how hard can it be? I am not a web-dev at all, I have zero experience&#xA;with Rust web frameworks, I never touched one.&#xA;I have no experience with CSS (only that view bits I used for this blog) and&#xA;of course I also have no experience with JS.&#xA;&#xA;But how hard can it be?&#xA;&#xA;Turns out: It is not hard at all.&#xA;I&#39;m proud to present the first prototype, after 11 hours of implementation&#xA;time:&#xA;&#xA;$ time sum :week git-dit-wui&#xA;&#xA;Wk  Date       Day Tags           Start      End    Time    Total&#xA;--- ---------- --- ----------- -------- -------- ------- --------&#xA;W11 2018-03-15 Thu git-dit-wui 14:00:00 16:43:35 2:43:35&#xA;                   git-dit-wui 20:31:00 23:52:04 3:21:04  6:04:39&#xA;W11 2018-03-16 Fri git-dit-wui 11:23:39 14:12:56 2:49:17&#xA;                   git-dit-wui 15:45:16 17:58:47 2:13:31  5:02:48&#xA;&#xA;                                                         11:07:27&#xA;&#xA;What does not work yet&#xA;&#xA;Of course, this is only the first prototype. The following things do not&#xA;work yet:&#xA;&#xA;Filtering issues for open/closed or other metadata&#xA;Showing issues which were opened by one specific author&#xA;Show messages as tree (currently linear by timestamp)&#xA;Graph for issues-per-date (nice-to-have)&#xA;Showing commits&#xA;Automatically detecting git hashes in messages and linking to the&#xA;  appropriate issue/commit&#xA;Abbreviating git hashes in messages and everywhere else&#xA;Configuration&#xA;    Port&#xA;    Repository path&#xA;    Readonly/RW&#xA;Error handling: if things go wrong, we should show an error page rather than&#xA;  nothing&#xA;&#xA;What does work&#xA;&#xA;But some things also work, of course:&#xA;&#xA;Messages are rendered as markdown&#xA;Listing all issues (with some metadata)&#xA;Showing an issue (including replies)&#xA;Showing single messages&#xA;Landing page with statistics about issues&#xA;&#xA;And it looks rather good (thanks to the bulma CSS framework) despite me beeing&#xA;a CLI-only guy without web-dev experience.&#xA;&#xA;Screenshots&#xA;&#xA;Some screenshots showing the issues in the git-dit repository.&#xA;&#xA;The landing page&#xA;The issue listing page&#xA;Showing a single issue&#xA;&#xA;Conclusion&#xA;&#xA;Of course I open-sourced the code [on&#xA;github](https://github.com/matthiasbeyer/git-dit-wui) and licensed it as&#xA;AGPL-3.0.&#xA;&#xA;So it can be done. I&#39;m not quite sure what the student did in 6 months&#xA;time he had for implementing this.&#xA;&#xA;tags:  #network #open-source #software #git&#xA;]]&gt;</description>
      <content:encoded><![CDATA[<p>I love the Rust language. And I love the library ecosystem the Rust community
provides.</p>

<p>But let me start at the beginning.</p>

<h1 id="libgitdit" id="libgitdit">libgitdit</h1>

<p>In 2016, I and a friend of mine developed a library for distributed issue
tracking with git and a commandline frontend for that library.
The project, <a href="https://github.com/neithernut/git-dit">git-dit</a> got a rather
good portion of attention on hackernews, reddit and of course on github.
Ranking at about 350 stars on github, this is the most successfull piece of
software I (co-)authored so far.</p>

<p>Development sleeps right now, which is really unfortunate.
There is a number of unresolved issues, despite the software is usable today.</p>

<h1 id="a-failed-thesis" id="a-failed-thesis">A failed thesis</h1>

<p>My friend and I proposed a bachelors thesis at our university for writing a
web-viewer for git-dit.
Because we&#39;re both master students, we also offered to supervise this thesis.</p>

<p>In the last semester, the thesis was assigned and I was happy when it started.
Today (or rather a few days ago) I was not that happy anymore, because I got
the end-result. I was able to compile it (yay), but after starting it, I was
not even able to open the web page because I did not know which port to use.</p>

<p>After looking at the source, I was able to figure that part out.
Unfortunately, everything I tried to do via the web frontend failed (as in
nothing happened). I was not able to see any issues or anything else. Only
viewing the git configuration was possible – but that&#39;s the least thing I
cared about.</p>

<p>So I figured: How hard can it be? If a bachelor student has half a year
time,... it must be hard? No, I guess not.</p>

<h1 id="lets-do-that" id="lets-do-that">Lets do that!</h1>

<p>So I started my own git-dit-web viewer. And I tracked the time it took to
implement it.</p>

<p>I mean, how hard can it be? I am not a web-dev at all, I have zero experience
with Rust web frameworks, I never touched one.
I have no experience with CSS (only that view bits I used for this blog) and
of course I also have no experience with JS.</p>

<p>But how hard can it be?</p>

<p>Turns out: It is <em>not hard at all</em>.
I&#39;m proud to present the first prototype, after 11 hours of implementation
time:</p>

<pre><code>$ time sum :week git-dit-wui

Wk  Date       Day Tags           Start      End    Time    Total
--- ---------- --- ----------- -------- -------- ------- --------
W11 2018-03-15 Thu git-dit-wui 14:00:00 16:43:35 2:43:35
                   git-dit-wui 20:31:00 23:52:04 3:21:04  6:04:39
W11 2018-03-16 Fri git-dit-wui 11:23:39 14:12:56 2:49:17
                   git-dit-wui 15:45:16 17:58:47 2:13:31  5:02:48

                                                         11:07:27
</code></pre>

<h2 id="what-does-not-work-yet" id="what-does-not-work-yet">What does not work yet</h2>

<p>Of course, this is only the first prototype. The following things do <em>not</em>
work yet:</p>
<ul><li>Filtering issues for open/closed or other metadata</li>
<li>Showing issues which were opened by one specific author</li>
<li>Show messages as tree (currently linear by timestamp)</li>
<li>Graph for issues-per-date (nice-to-have)</li>
<li>Showing commits</li>
<li>Automatically detecting git hashes in messages and linking to the
appropriate issue/commit</li>
<li>Abbreviating git hashes in messages and everywhere else</li>
<li>Configuration
<ul><li>Port</li>
<li>Repository path</li>
<li>Readonly/RW</li></ul></li>
<li>Error handling: if things go wrong, we should show an error page rather than
nothing</li></ul>

<h2 id="what-does-work" id="what-does-work">What does work</h2>

<p>But some things also work, of course:</p>
<ul><li>Messages are rendered as markdown</li>
<li>Listing all issues (with some metadata)</li>
<li>Showing an issue (including replies)</li>
<li>Showing single messages</li>
<li>Landing page with statistics about issues</li></ul>

<p>And it looks rather good (thanks to the bulma CSS framework) despite me beeing
a CLI-only guy without web-dev experience.</p>

<h2 id="screenshots" id="screenshots">Screenshots</h2>

<p>Some screenshots showing the issues in the <code>git-dit</code> repository.</p>

<p><img src="/2018-03-16-git-dit-wui-1.png" alt="The landing page">
<img src="/2018-03-16-git-dit-wui-2.png" alt="The issue listing page">
<img src="/2018-03-16-git-dit-wui-3.png" alt="Showing a single issue"></p>

<h2 id="conclusion" id="conclusion">Conclusion</h2>

<p>Of course I open-sourced the code <a href="https://github.com/matthiasbeyer/git-dit-wui">on
github</a> and licensed it as
AGPL-3.0.</p>

<p>So it can be done. I&#39;m not quite sure what the student did in 6 months
time he had for implementing this.</p>

<p>tags:  <a href="https://beyermatthias.de/tag:network" class="hashtag"><span>#</span><span class="p-category">network</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:software" class="hashtag"><span>#</span><span class="p-category">software</span></a> <a href="https://beyermatthias.de/tag:git" class="hashtag"><span>#</span><span class="p-category">git</span></a></p>
]]></content:encoded>
      <guid>https://beyermatthias.de/writing-a-git-dit-web-frontend-with-gotham-libgitdit-and-love</guid>
      <pubDate>Fri, 16 Mar 2018 16:39:13 +0100</pubDate>
    </item>
    <item>
      <title>Blueprint of a distributed social network on IPFS - and its problems (2)</title>
      <link>https://beyermatthias.de/blueprint-of-a-distributed-social-network-on-ipfs-and-its-problems-2</link>
      <description>&lt;![CDATA[After thinking a while about the points I layed out&#xA;in my previous post&#xA;I&#39;d like to update my ideas here.&#xA;&#xA;It is not necessary to read the first post to understand what I am talking&#xA;about in this second one, but it also does not do any harm.&#xA;&#xA;  Matrix and Mastodon are nice - but federation is only the first step - we&#xA;  have to go towards fully distributed applications!&#xA;&#xA;(me, at the 34. Chaos Communication Congress 2017)&#xA;&#xA;The idea&#xA;&#xA;With the rise of protocols like the matrix protocol, activitypub and others,&#xA;decentralized social community platforms like matrix, mastodon and others gained&#xA;power and were made real.&#xA;I consider these platforms, especially mastodon and matrix, to be great steps&#xA;into the future and am using both enthusiastically.&#xA;But I think we can do better. Federation is the first step out of&#xA;centralization and definitively a good one. But we have to push further -&#xA;towards full distributed environments!&#xA;&#xA;(For a &#34;Why?&#34; have a look at the end of the article!)&#xA;&#xA;How would it work?&#xA;&#xA;The foundations how a social network on IPFS would work are rather simple.&#xA;I am very tempted to use the un-word &#34;blockchain&#34; in this article, but because&#xA;of the hype around that word and because nobody really understands what a&#xA;&#34;blockchain&#34; actually is, I refrain from using it.&#xA;&#xA;I use a better one instead: &#34;DAG&#34; - &#34;Directed Acyclic Graph&#34;. Also &#34;Merkle-Tree&#34;&#xA;is a term which could be used, but when using this term, a notion of&#xA;implementation-details comes to mind and I want to avoid that. One instantly&#xA;thinks of crypto, hash values and blobs when talking about hash trees or&#xA;merkle trees. A DAG though is a bit more abstract concept which fits my ideas&#xA;better.&#xA;&#xA;What we would need to develop a social network (its core functionality) on IPFS&#xA;is a DAG and some standard data formats we agree upon.&#xA;We also need a private-public-key infrastructure, which IPFS already has.&#xA;&#xA;There are two &#34;kinds&#34; of data which must be considered: meta-data (which&#xA;should be replicated by as many nodes as possible) and actual user data&#xA;(posts, messages, images, videos, files).&#xA;I&#39;m not talking about the second one here very much, because the meta-data is&#xA;where the problems are.&#xA;&#xA;Consider the following metadata blob:&#xA;&#xA;{&#xA;  &#34;version&#34;: 1,&#xA;  &#34;previous&#34;: [ &#34;Qm...1234567890&#34; ],&#xA;&#xA;  &#34;profile&#34;: [ &#34;Qm...098765&#34;, &#34;Qm...54312&#34; ],&#xA;&#xA;  &#34;post&#34;: {&#xA;    &#34;mimetype&#34;: &#34;text/plain&#34;,&#xA;    &#34;nodes&#34;: [&#34;Qm...abc&#34;],&#xA;    &#34;date&#34;: &#34;2018-01-02T03:04:05+0200&#34;,&#xA;    &#34;reply&#34;: [],&#xA;  },&#xA;&#xA;  &#34;publicfollow&#34;: [ &#34;Qm...efg&#34;, &#34;Qm...hij&#34; ]&#xA;}&#xA;&#xA;The version key describes the version of the protocol, of course.&#xA;&#xA;Here, the previous array points to the previous metadata blob(s).&#xA;  We need multiple entries here (an array) because we want to create a DAG.&#xA;&#xA;The profile key holds a list of IPNS names which are associated with the&#xA;  profile.&#xA;&#xA;The version, previous and profile keys are the only ones required in&#xA;such a metadata blob.&#xA;All other keys shown above are optional, though one metadata-blob should&#xA;only contain one at a time (or none).&#xA;&#xA;The post table describes the actual userdata. Some meta-information is&#xA;  added, for example the mimetype (&#34;text/plain&#34; in this case) and the date it&#xA;  was created. More can be thought of.&#xA;  The nodes key points to a list of actual content (again via IPFS hashes).&#xA;  I&#39;m not yet convinced whether this shall be a list or a single value.&#xA;  Details!&#xA;  I&#39;d say that these three keys are required in a post table.&#xA;  The reply key notes that this post is a reply to another post. This is, of&#xA;  course, optional.&#xA;&#xA;The publicfollow is a list of IPNS hashes to other profiles which the user&#xA;  follows publicly.&#xA;  Whether such a thing is desireable is to be discussed.&#xA;  I show it here to give a hint on the possibilities.&#xA;&#xA;More such data could be considered, though the meta-data blobs should be&#xA;  held small: If one thinks of 4kb per meta-data blob (which is a lot) and&#xA;  10 million blobs (which I do not consider that much, because every&#xA;  interaction which is a input into the network in one form or another results&#xA;  in a new meta-data blob), we have roughly 38 GB of meta-data content, which is&#xA;  really too much.&#xA;  If we have 250 bytes per metadata-blob (which sounds like a reasonable size)&#xA;  we get 2.3 GB of meta-data for 10 million blobs. That sounds much better.&#xA;&#xA;The profile DAG&#xA;&#xA;The idea of linking the previous version of a profile from each new version of&#xA;the profile is of course one of the key points.&#xA;With this approach, nobody has to fetch the whole list of profile versions.&#xA;Traversing the whole chain backwards is only required if a user wants to see&#xA;old content from the profile she&#39;s browsing.&#xA;&#xA;Because of IPFS and its caching, content automatically gets replicated over&#xA;nodes as users browse profiles.&#xA;Nodes can cache either only meta-data blobs (not so much data) or user content&#xA;as well (more data). This can happen automatically or user-driven - several&#xA;possibilities here!&#xA;It is even possible that users &#34;pin&#34; content if they think its important to&#xA;keep it.&#xA;&#xA;Profile updates can even be &#34;announced&#34; using PubSub so other nodes can then&#xA;fetch the new profile versions and cache them. The latest profile&#xA;metadata-blob (or &#34;version&#34;) can be published via a IPNS name.&#xA;The IPNS name should be published per-device and not per-account.&#xA;(This is also why there is a devices array in the metadata JSON blob!)&#xA;&#xA;Why should we publish IPNS names per-device and why do we actually need a DAG&#xA;here? That&#39;s actually because of we want multi-device support!&#xA;&#xA;Multi-device support&#xA;&#xA;I already mentioned that the profile-chain would be a DAG.&#xA;I also mentioned that there would be a profile key in the meta-data blob.&#xA;&#xA;This is because of the multi-device support.&#xA;If two, three or even more devices need to post to one account, we need to be&#xA;able to merge different versions of an account: Consider Alice and Bob sharing&#xA;one account (which would be possible!). Now, Bob loses connection to the&#xA;internet. But because we are on IPFS and work offline, this is not a problem.&#xA;Alice and Bob could continue creating content and thus new profile versions:&#xA;&#xA;A &lt;--- B &lt;--- C &lt;--- D &lt;--- E&#xA;        \&#xA;         C&#39; &lt;--- D&#39; &lt;--- E&#39;&#xA;&#xA;In the shown DAG, Alice posts C, D and E, each referring to the former.&#xA;Bob creates C&#39;, D&#39; and E&#39; - each refering to the former.&#xA;Of course both C and C&#39; would refer to B.&#xA;&#xA;As soon as Bob comes back online, Alice notices that there is another chain of&#xA;posts to the profile and can now merge the chains be publishing a new&#xA;version F which points to both E and E&#39;:&#xA;&#xA;A &lt;--- B &lt;--- C &lt;--- D &lt;--- E &lt;--- F&#xA;        \                         /&#xA;         C&#39; &lt;--- D&#39; &lt;--- E&#39; &lt;-----&#xA;&#xA;Because Bob would also see another chain, his client would also provide a new&#xA;version of the profile (F&#39;) where E and E&#39; are merged - one of the&#xA;problem which must be sorted out. But a rather trivial one in my opinion, as&#xA;the clients need only to do some sort of leader-election. And this election is&#xA;temporary until a new node is published - so not really a complicated form&#xA;of concensus-finding!&#xA;&#xA;What has to be sorted out, though, is that the devices/nodes which share an&#xA;account and now need to agree upon which one merges the chains need some form&#xA;of communication between them. I have not yet thought about how this should be&#xA;done. Maybe IPFS PubSub is a viable option for this. Cryptographic signatures&#xA;play a important role here.&#xA;&#xA;This gets a bit more complicated if there are more than two devices posting to&#xA;one account and also if some of them are not available yet - though it is&#xA;still in a problem space near &#34;we have to think hard about this&#34; ... and&#xA;nowhere in the space of &#34;seems impossible&#34;!&#xA;&#xA;The profile key is provided in the account data so the client knows which&#xA;other chains should be checked and merged. Thus, only nodes which are already&#xA;allowed to publish new profile versions are actually allowed to add new nodes&#xA;to that list.&#xA;&#xA;Deleting content in the DAG&#xA;&#xA;Deleting old versions of the profile - or old content - is possible, too.&#xA;Because the previous key is an array, we can refer to multiple old&#xA;versions of a profile.&#xA;&#xA;Consider the following chain of profile versions:&#xA;&#xA;A&lt;---B&lt;---C&lt;---D&lt;---E&#xA;&#xA;Now, the user wants to drop profile version C. This is possible by creating&#xA;a new profile version which refers to E and B in the previous field and&#xA;then dropping C. The following chain (DAG) is the result:&#xA;&#xA;A&lt;---B     &lt;---D&lt;---E&lt;---F&#xA;      \                 /&#xA;       -----------------&#xA;&#xA;Of course, D would now point to a node which does not exist. But that is not&#xA;a problem. Indeed, its a fundamental key point of the idea - that content may be&#xA;unavailable.&#xA;&#xA;F should not contain new content.&#xA;If F would contain new content, dropping this content would become harder as&#xA;the previous key would be copied over, creating even more links to previous&#xA;versions in the new profile version.&#xA;&#xA;&#34;Forgetting&#34; content&#xA;&#xA;Because clients won&#39;t traverse the whole chain of a profile, but only the&#xA;newest 10, 100 or 1,000 entries, older content gets &#34;forgotten&#34; slowly.&#xA;Of course it is still there and the device hosting it still has it (and other&#xA;devices which post to the same account, eventually also caching servers).&#xA;Either way, content gets forgotten slowly. If the user who published the&#xA;content deletes it, the network may be unable to fetch it at some point.&#xA;&#xA;Is that bad? I don&#39;t think so! Important content gets replicated by others, so&#xA;if I post a comment on an article, I could (automatically or manually) pin the&#xA;article itself in my IPFS instance to preserve it.&#xA;If I do not and the author of the article thinks that it might not be that&#xA;interesting, the article may be deleted and gets unavailable to the network.&#xA;&#xA;And I think that is fine. Replicate important content, delete unimportant&#xA;content. The user has the power to decide here!&#xA;&#xA;Comments on posts (and comments)&#xA;&#xA;Consider you want to comment on a post. Of course you create new content,&#xA;which links to the post you just commented.&#xA;But the person who wrote the original post does not automatically link to your&#xA;comment, so nobody is able to find your comment.&#xA;&#xA;The approach for solving this is to provide updates to content.&#xA;An update is simply a new meta-data blob in the profile.&#xA;The blob would contain a link to the original post and the comment on it:&#xA;&#xA;{&#xA;  &#34;version:&#34; 1,&#xA;  &#34;previous&#34;: [ &#34;Qm...1234567890&#34; ],&#xA;&#xA;  &#34;profile&#34;: [ &#34;Qm...098765&#34;, &#34;Qm...54312&#34; ],&#xA;&#xA;  &#34;post&#34;: {&#xA;    &#34;update&#34;: &#34;Qm...abc&#34;,&#xA;    &#34;new-reply&#34;: &#34;Qm...ghjjk&#34;,&#xA;  },&#xA;}&#xA;&#xA;The  post.update and post.new-reply would link to meta-data blobs: The&#xA;update one to the original post or the latest update on the post - the&#xA;new-reply one on the post from the other user which provides a comment on the&#xA;post.&#xA;Maybe it would also be an option to list all direct replies to the post here. Details!&#xA;&#xA;Because this works on both &#34;posts&#34; and &#34;reply&#34; kind of data, comments on&#xA;comments are possible.&#xA;&#xA;Comments deep down the chain of comments would have to slowly propagate to the&#xA;top - to the actual post.&#xA;&#xA;Here, several configurations are possible:&#xA;&#xA;Automatically include comments and publish new profile versions for them&#xA;Publishing/propagating comments until some mark is hit (original post is&#xA;  more than 1 month old, more than 100 comments are propagated)&#xA;User can select other users where comments are automatically propagated and others have to be moderated&#xA;User has to confirm propagation (moderated comments).&#xA;&#xA;The key difference to known approaches here is that not the author of the original post permits&#xA;comments, but always the author of the post or comment the reply was filed&#xA;for.&#xA;I don&#39;t know whether this is a nice thing or a problem.&#xA;&#xA;Unavailable content&#xA;&#xA;The implementation of the social network has to be error-resistant, of course.&#xA;IPFS hashes might not be there, fetching content might not be possible&#xA;(temporarily or at all). But that&#39;s an implementation-detail to me and I&#xA;will not lose any more words about it.&#xA;&#xA;Federated component&#xA;&#xA;One might think &#34;If I go offline with my node, my posts are not accessible if&#xA;nobody else is online having them&#34;. And that&#39;s true.&#xA;&#xA;That&#39;s why I would introduce a federated component, which would run a&#xA;stripped-down version of the application.&#xA;&#xA;As soon as another instance connects and a new post is announced,&#xA;the instance automatically pins or caches it.&#xA;Of course, this would mean that all of these federated instances would pin all&#xA;content, which is surely not nice.&#xA;Posts which are pinned for a certain amount of time are most likely&#xA;distributed well enough so the federated component nodes can drop them...&#xA;maybe after 90 days, maybe after 10... Details!&#xA;&#xA;Subscribing (privately) and other private information&#xA;&#xA;Another issue with multi-device support would be subscribing privately to&#xA;another account. For example, if a user (lets call her Amy) subscribes to&#xA;another user (lets call him Sheldon) on her Notebook, this information needs&#xA;to be stored somehow.&#xA;And because Amys machines do not necessarily sync with each other, her mobile&#xA;phone may never know that following Sheldon is a thing now!&#xA;&#xA;This problem could by solved by storing the &#34;follow&#34;-information in her public&#xA;profile. Although, some users might not like everyone to know who to follow.&#xA;Cryptographic things could be considered to fix visibility.&#xA;&#xA;But then, users may want to &#34;categorize&#34; their friends, store them in groups&#xA;or whatever. This information would be stored in the public profile as well,&#xA;which would create even more noise on the network.&#xA;Also, because cryptography is hard and information would be stored forever,&#xA;this might not be an option as some day, the crypto might be broken and reveal&#xA;all the things that were stored privately before.&#xA;&#xA;Another solution for this would be that Amys devices would have to somehow&#xA;sync directly, without others beeing able to read any of that data.&#xA;Something like a&#xA;CRDT&#xA;which holds a configuration file which is then shared&#xA;between the devices directly (think of a git-repository which is pushed&#xA;between the devices directly without accessing a server on the internet).&#xA;This would, of course, only work if the devices are on the same network.&#xA;&#xA;As you see, I have not thought about this particular problem very much yet.&#xA;&#xA;Discovering content&#xA;&#xA;What I did not spend much time thinking about as well was how clients discover&#xA;new content.&#xA;When a user installs a client, this client does not know any IPFS peers - or&#xA;rather any &#34;social network nodes&#34; where it can fetch user profiles/data from -&#xA;yet.&#xA;Even if it knows some bootstrap nodes to connect to, it might not get content&#xA;from them if they do not serve any social network data and if the user does&#xA;not know any hashes of user profiles.&#xA;To be able to find new social network IPFS nodes, a client has to know their&#xA;IPNS hashes - But how to discover them?&#xA;&#xA;This is a hard problem. My first idea would be a PubSub channel where each&#xA;client periodically announces their IPNS hashes.  I&#39;m not sure whether PubSub&#xA;nodes must be connected directly. If this is the case, the problem just got&#xA;harder.  There&#39;s also the problem that this channel would be rather&#xA;high-volume as soon as the network grows. If each client announces their IPNS&#xA;hash every 15 minutes, for example, we get 4 messages per client each hour.&#xA;That&#39;s already a lot of bandwidth if we speak about 1,000, 10,000 or even&#xA;100,000 clients!&#xA;It is also an attack-vector how the system can be flooded. Not nice!&#xA;&#xA;One way to think about this is that if only nodes which are subscribed to a&#xA;topic do also forward the topics messages&#xA;(like this comment suggests),&#xA;we could reduce the time between &#34;publishing&#34; messages in the topic.&#xA;Such a message would contain all IPNS hashes a node knows about, thus the&#xA;amount of data would be rather much. As soon as the network grows, a node would&#xA;need to send this message less and less often, to reduce the number of&#xA;messages and bytes send. Still, if each node knows 10,000 nodes and sends this&#xA;list once an hour, we get&#xA;&#xA;bytesperhash = 46&#xA;numberofnodes = 10000&#xA;messagesize = bytesperhash  numberofnodes&#xA;bytesperhour = numberofnodes  messagesize&#xA;&#xA;4,28 GiB of &#34;I know these nodes&#34; messages per hour. That does&#xA;obviousely not scale!&#xA;&#xA;Maybe each client should offer an API where other clients can ask them about&#xA;which IPNS hashes they know. That would be a &#34;pull&#34; approach rather than a&#xA;&#34;push&#34; approach then, which would limit bandwidth a bit.  This could even be&#xA;done via PubSub as well, where the channel name is generared from the IPFS&#xA;instance hash, for example.&#xA;I don&#39;t know whether this would be a nice idea.&#xA;Still, this would need some &#34;internet-facing&#34; software where clients need to&#xA;be able to talk directly to eachother. I don&#39;t know whether IPFS offers&#xA;functionality to do this in a simple way.&#xA;&#xA;Either way, I have no solution for this problem yet.&#xA;&#xA;Why IPFS?&#xA;&#xA;Platforms like scuttlebutt or movim also implement distributed social&#xA;networks, why not use those? Also, why IPFS and not the dat protocol or&#xA;something else?&#xA;&#xA;That question is rather simple to answer: IPFS provides functionality and&#xA;semantics other tools/frameworks do not provide. Most importantly the notion&#xA;that content is immutable, but also full decentralization (not federation like&#xA;with services like movim or mastodon, for example).&#xA;&#xA;Having immutable content is a key point. The dat protocol, for example,&#xA;features mutable content as it is roughly based on bittorrent (if I understood&#xA;everything correctly, feel free to point out mistakes).&#xA;That might be nice in some cases, though I think immutability is the way to go.&#xA;Distributed applications or frameworks for distributed content with immutability&#xA;as core concept are better suited for netsplit, slow connections and&#xA;peer-to-peer applications.&#xA;From what I saw from the last weeks and months of looking at frameworks for&#xA;distributed content storage is that IPFS is way more mature than these other&#xA;frameworks. IPFS is build to replace existing contents and to stay, and that&#39;s a&#xA;nice thing to build applications on.&#xA;&#xA;Remaining Questions&#xA;&#xA;Some questions are remaining:&#xA;&#xA;Is it possible to talk to a specific node directly in IPFS? This would be&#xA;  helpful for discovering content by asking nodes what profiles they know.&#xA;  It would also be a nice way for finding consensus when multiple devices have&#xA;  to agree on which node publishes a merge.&#xA;How fast is IPFS with small files? If I need to traverse a long chain of&#xA;  profile updates, I constantly request a small file, parse it and continue&#xA;  requesting the previous node in the chain. That should be fast.&#xA;  If it is not, we might need to introduce some &#34;pack files&#34; where a list of&#xA;  metadata-nodes is provided and traversing becomes unnecessary with. But that&#xA;  makes deleting content rather complicated, TBH.&#xA;&#xA;That&#39;s all I can think of right now, but there might be more questions which&#xA;are not yet answered.&#xA;&#xA;Problems are hard in distributed environments&#xA;&#xA;Distributed systems involve a lot of new complexity where we have to carefully&#xA;think about details and how to design our system.&#xA;New ways to design systems can be discovered by the &#34;distributed approach&#34; and&#xA;new paradigms emerge.&#xA;&#xA;Moving away from a central authority which holds the truth, the global state and&#xA;also the data results in a&#xA;paradigm shift&#xA;we really have to be careful about.&#xA;&#xA;I think we can do it and design new, powerful and fully distributed systems&#xA;with user freedom, usability, user-convenience and state-of-the-art in mind.&#xA;Users want to have a system which is reliable, failure proof, convenient and&#xA;easy to use.&#xA;They want to &#34;always be connected&#34;.&#xA;I think we can provide such software.&#xA;Developers want nice abstractions to build upon, data integrity, failure-proof&#xA;software with simplicity designed into the system and reusable data structures&#xA;and be able to scale.&#xA;I think IPFS is the way to for this.&#xA;In addition, I think we can provide free software with free data.&#xA;&#xA;I do not claim to know the final solution to any of the problems layed out in&#xA;this article.&#xA;Its just that I think of them and would love to get an open conversation started&#xA;on the whole subject of distributed social networks and problems that come with&#xA;them.&#xA;&#xA;And maybe we can come up with a prototype for this?&#xA;&#xA;tags:  #distributed #network #open-source #social #software&#xA;]]&gt;</description>
      <content:encoded><![CDATA[<p>After thinking a while about the points I layed out
<a href="/blog/2017/10/31/blueprint-of-a-distributed-social-network-on-ipfs---and-its-problems/">in my previous post</a>
I&#39;d like to update my ideas here.</p>

<p>It is not necessary to read the first post to understand what I am talking
about in this second one, but it also does not do any harm.</p>

<blockquote><p>Matrix and Mastodon are nice – but federation is only the first step – we
have to go towards fully distributed applications!</p></blockquote>

<p>(me, at the 34. Chaos Communication Congress 2017)</p>

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

<p>With the rise of protocols like the matrix protocol, activitypub and others,
decentralized social community platforms like matrix, mastodon and others gained
power and were made real.
I consider these platforms, especially mastodon and matrix, to be great steps
into the future and am using both enthusiastically.
But I think we can do better. Federation is the first step out of
centralization and definitively a good one. But we have to push further -
towards full distributed environments!</p>

<p>(For a “Why?” have a look at the end of the article!)</p>

<h1 id="how-would-it-work" id="how-would-it-work">How would it work?</h1>

<p>The foundations how a social network on IPFS would work are rather simple.
I am very tempted to use the un-word “blockchain” in this article, but because
of the hype around that word and because nobody really understands what a
“blockchain” actually is, I refrain from using it.</p>

<p>I use a better one instead: “DAG” – “Directed Acyclic Graph”. Also “Merkle-Tree”
is a term which could be used, but when using this term, a notion of
implementation-details comes to mind and I want to avoid that. One instantly
thinks of crypto, hash values and blobs when talking about hash trees or
merkle trees. A DAG though is a bit more abstract concept which fits my ideas
better.</p>

<p>What we would need to develop a social network (its core functionality) on IPFS
is a DAG and some standard data formats we agree upon.
We also need a private-public-key infrastructure, which IPFS already has.</p>

<p>There are two “kinds” of data which must be considered: meta-data (which
should be replicated by as many nodes as possible) and actual user data
(posts, messages, images, videos, files).
I&#39;m not talking about the second one here very much, because the meta-data is
where the problems are.</p>

<p>Consider the following metadata blob:</p>

<pre><code class="language-json">{
  &#34;version&#34;: 1,
  &#34;previous&#34;: [ &#34;Qm...1234567890&#34; ],

  &#34;profile&#34;: [ &#34;Qm...098765&#34;, &#34;Qm...54312&#34; ],

  &#34;post&#34;: {
    &#34;mimetype&#34;: &#34;text/plain&#34;,
    &#34;nodes&#34;: [&#34;Qm...abc&#34;],
    &#34;date&#34;: &#34;2018-01-02T03:04:05+0200&#34;,
    &#34;reply&#34;: [],
  },

  &#34;publicfollow&#34;: [ &#34;Qm...efg&#34;, &#34;Qm...hij&#34; ]
}
</code></pre>
<ul><li><p>The <code>version</code> key describes the version of the protocol, of course.</p></li>

<li><p>Here, the <code>previous</code> array points to the previous metadata blob(s).
We need <em>multiple</em> entries here (an array) because we want to create a <em>DAG</em>.</p></li>

<li><p>The <code>profile</code> key holds a list of <code>IPNS</code> names which are associated with the
profile.</p></li></ul>

<p>The <code>version</code>, <code>previous</code> and <code>profile</code> keys are the only ones required in
such a metadata blob.
All other keys shown above are <em>optional</em>, though one metadata-blob should
only contain one at a time (or none).</p>
<ul><li><p>The <code>post</code> table describes the actual userdata. Some meta-information is
added, for example the mimetype (<code>&#34;text/plain&#34;</code> in this case) and the date it
was created. More can be thought of.
The <code>nodes</code> key points to a list of actual content (again via IPFS hashes).
I&#39;m not yet convinced whether this shall be a <em>list</em> or a single value.
Details!
I&#39;d say that these three keys are required in a <code>post</code> table.
The <code>reply</code> key notes that this post is a reply to another post. This is, of
course, optional.</p></li>

<li><p>The <code>publicfollow</code> is a list of IPNS hashes to other profiles which the user
follows <em>publicly</em>.
Whether such a thing is desireable is to be discussed.
I show it here to give a hint on the possibilities.</p></li>

<li><p>More such data could be considered, though the meta-data blobs should be
held <em>small</em>: If one thinks of 4kb per meta-data blob (which is a lot) and
10 million blobs (which I do not consider that much, because every
interaction which is a input into the network in one form or another results
in a new meta-data blob), we have roughly 38 GB of meta-data content, which is
really too much.
If we have 250 bytes per metadata-blob (which sounds like a reasonable size)
we get 2.3 GB of meta-data for 10 million blobs. That sounds much better.</p></li></ul>

<h2 id="the-profile-dag" id="the-profile-dag">The profile DAG</h2>

<p>The idea of linking the previous version of a profile from each new version of
the profile is of course one of the key points.
With this approach, nobody has to fetch the whole list of profile versions.
Traversing the whole chain backwards is only required if a user wants to see
old content from the profile she&#39;s browsing.</p>

<p>Because of IPFS and its caching, content automatically gets replicated over
nodes as users browse profiles.
Nodes can cache either only meta-data blobs (not so much data) or user content
as well (more data). This can happen automatically or user-driven – several
possibilities here!
It is even possible that users “pin” content if they think its important to
keep it.</p>

<p>Profile updates can even be “announced” using PubSub so other nodes can then
fetch the new profile versions and cache them. The latest profile
metadata-blob (or “version”) can be published via a IPNS name.
The IPNS name should be published per-device and not per-account.
(This is also why there is a <code>devices</code> <em>array</em> in the metadata JSON blob!)</p>

<p>Why should we publish IPNS names per-device and why do we actually need a DAG
here? That&#39;s actually because of we want multi-device support!</p>

<h2 id="multi-device-support" id="multi-device-support">Multi-device support</h2>

<p>I already mentioned that the profile-chain would be a DAG.
I also mentioned that there would be a <code>profile</code> key in the meta-data blob.</p>

<p>This is because of the multi-device support.
If two, three or even more devices need to post to one account, we need to be
able to merge different versions of an account: Consider Alice and Bob sharing
one account (which would be possible!). Now, Bob loses connection to the
internet. But because we are on IPFS and work offline, this is not a problem.
Alice and Bob could continue creating content and thus new profile versions:</p>

<pre><code>A &lt;--- B &lt;--- C &lt;--- D &lt;--- E
        \
         C&#39; &lt;--- D&#39; &lt;--- E&#39;
</code></pre>

<p>In the shown DAG, Alice posts <code>C</code>, <code>D</code> and <code>E</code>, each referring to the former.
Bob creates <code>C&#39;</code>, <code>D&#39;</code> and <code>E&#39;</code> – each refering to the former.
Of course both <code>C</code> and <code>C&#39;</code> would refer to <code>B</code>.</p>

<p>As soon as Bob comes back online, Alice notices that there is another chain of
posts to the profile and can now <em>merge</em> the chains be publishing a new
version <code>F</code> which points to both <code>E</code> and <code>E&#39;</code>:</p>

<pre><code>A &lt;--- B &lt;--- C &lt;--- D &lt;--- E &lt;--- F
        \                         /
         C&#39; &lt;--- D&#39; &lt;--- E&#39; &lt;-----
</code></pre>

<p>Because Bob would also see another chain, his client would also provide a new
version of the profile (<code>F&#39;</code>) where <code>E</code> and <code>E&#39;</code> are merged – one of the
problem which must be sorted out. But a rather trivial one in my opinion, as
the clients need only to do some sort of leader-election. And this election is
<em>temporary</em> until a new node is published – so not really a complicated form
of concensus-finding!</p>

<p>What has to be sorted out, though, is that the devices/nodes which share an
account and now need to agree upon which one merges the chains need some form
of communication between them. I have not yet thought about how this should be
done. Maybe IPFS PubSub is a viable option for this. Cryptographic signatures
play a important role here.</p>

<p>This gets a bit more complicated if there are more than two devices posting to
one account and also if some of them are not available yet – though it is
still in a problem space near “we have to think hard about this” ... and
nowhere in the space of “seems impossible”!</p>

<p>The <code>profile</code> key is provided in the account data so the client knows which
other chains should be checked and merged. Thus, only nodes which are already
allowed to publish new profile versions are actually allowed to add new nodes
to that list.</p>

<h2 id="deleting-content-in-the-dag" id="deleting-content-in-the-dag">Deleting content in the DAG</h2>

<p>Deleting old versions of the profile – or old content – is possible, too.
Because the <code>previous</code> key is an <em>array</em>, we can refer to multiple old
versions of a profile.</p>

<p>Consider the following chain of profile versions:</p>

<pre><code>A&lt;---B&lt;---C&lt;---D&lt;---E
</code></pre>

<p>Now, the user wants to drop profile version <code>C</code>. This is possible by creating
a new profile version which refers to <code>E</code> and <code>B</code> in the <code>previous</code> field and
then dropping <code>C</code>. The following chain (DAG) is the result:</p>

<pre><code>A&lt;---B     &lt;---D&lt;---E&lt;---F
      \                 /
       -----------------
</code></pre>

<p>Of course, <code>D</code> would now point to a node which does not exist. But that is not
a problem. Indeed, its a fundamental key point of the idea – that content may be
unavailable.</p>

<p><code>F</code> should not contain new content.
If <code>F</code> would contain new content, dropping this content would become harder as
the <code>previous</code> key would be copied over, creating even more links to previous
versions in the new profile version.</p>

<h2 id="forgetting-content" id="forgetting-content">“Forgetting” content</h2>

<p>Because clients won&#39;t traverse the whole chain of a profile, but only the
newest 10, 100 or 1,000 entries, older content gets “forgotten” slowly.
Of course it is still there and the device hosting it still has it (and other
devices which post to the same account, eventually also caching servers).
Either way, content gets forgotten slowly. If the user who published the
content deletes it, the network may be unable to fetch it at some point.</p>

<p>Is that bad? I don&#39;t think so! Important content gets replicated by others, so
if I post a comment on an article, I could (automatically or manually) pin the
article itself in my IPFS instance to preserve it.
If I do not and the author of the article thinks that it might not be that
interesting, the article may be deleted and gets unavailable to the network.</p>

<p>And I think that is fine. Replicate important content, delete unimportant
content. The user has the power to decide here!</p>

<h2 id="comments-on-posts-and-comments" id="comments-on-posts-and-comments">Comments on posts (and comments)</h2>

<p>Consider you want to comment on a post. Of course you create new content,
which links to the post you just commented.
But the person who wrote the original post does not automatically link to your
comment, so nobody is able to find your comment.</p>

<p>The approach for solving this is to provide updates to content.
An update is simply a new meta-data blob in the profile.
The blob would contain a link to the original post and the comment on it:</p>

<pre><code class="language-json">{
  &#34;version:&#34; 1,
  &#34;previous&#34;: [ &#34;Qm...1234567890&#34; ],

  &#34;profile&#34;: [ &#34;Qm...098765&#34;, &#34;Qm...54312&#34; ],

  &#34;post&#34;: {
    &#34;update&#34;: &#34;Qm...abc&#34;,
    &#34;new-reply&#34;: &#34;Qm...ghjjk&#34;,
  },
}
</code></pre>

<p>The  <code>post.update</code> and <code>post.new-reply</code> would link to meta-data blobs: The
<code>update</code> one to the original post or the latest update on the post – the
<code>new-reply</code> one on the post from the other user which provides a comment on the
post.
Maybe it would also be an option to list all direct replies to the post here. Details!</p>

<p>Because this works on both “posts” and “reply” kind of data, comments on
comments are possible.</p>

<p>Comments deep down the chain of comments would have to slowly propagate to the
top – to the actual post.</p>

<p>Here, several configurations are possible:</p>
<ul><li>Automatically include comments and publish new profile versions for them</li>
<li>Publishing/propagating comments until some mark is hit (original post is
more than 1 month old, more than 100 comments are propagated)</li>
<li>User can select other users where comments are automatically propagated and others have to be moderated</li>
<li>User has to confirm propagation (moderated comments).</li></ul>

<p>The key difference to known approaches here is that not the author of the original post permits
comments, but always the author of the post or comment the reply was filed
for.
I don&#39;t know whether this is a nice thing or a problem.</p>

<h2 id="unavailable-content" id="unavailable-content">Unavailable content</h2>

<p>The implementation of the social network has to be error-resistant, of course.
IPFS hashes might not be there, fetching content might not be possible
(temporarily or at all). But that&#39;s an implementation-detail to me and I
will not lose any more words about it.</p>

<h1 id="federated-component" id="federated-component">Federated component</h1>

<p>One might think “If I go offline with my node, my posts are not accessible if
nobody else is online having them”. And that&#39;s true.</p>

<p>That&#39;s why I would introduce a federated component, which would run a
stripped-down version of the application.</p>

<p>As soon as another instance connects and a new post is announced,
the instance automatically pins or caches it.
Of course, this would mean that all of these federated instances would pin all
content, which is surely not nice.
Posts which are pinned for a certain amount of time are most likely
distributed well enough so the federated component nodes can drop them...
maybe after 90 days, maybe after 10... Details!</p>

<h1 id="subscribing-privately-and-other-private-information" id="subscribing-privately-and-other-private-information">Subscribing (privately) and other private information</h1>

<p>Another issue with multi-device support would be subscribing privately to
another account. For example, if a user (lets call her Amy) subscribes to
another user (lets call him Sheldon) on her Notebook, this information needs
to be stored somehow.
And because Amys machines do not necessarily sync with each other, her mobile
phone may never know that following Sheldon is a thing now!</p>

<p>This problem could by solved by storing the “follow”-information in her public
profile. Although, some users might not like everyone to know who to follow.
Cryptographic things could be considered to fix visibility.</p>

<p>But then, users may want to “categorize” their friends, store them in groups
or whatever. This information would be stored in the public profile as well,
which would create even <em>more</em> noise on the network.
Also, because cryptography is hard and information would be stored forever,
this might not be an option as some day, the crypto might be broken and reveal
all the things that were stored privately before.</p>

<p>Another solution for this would be that Amys devices would have to somehow
sync directly, without others beeing able to read any of that data.
Something like a
<a href="https://en.wikipedia.org/wiki/Conflict-free_replicated_data_type">CRDT</a>
which holds a configuration file which is then shared
between the devices directly (think of a git-repository which is pushed
between the devices directly without accessing a server on the internet).
This would, of course, only work if the devices are on the same network.</p>

<p>As you see, I have not thought about this particular problem very much yet.</p>

<h1 id="discovering-content" id="discovering-content">Discovering content</h1>

<p>What I did not spend much time thinking about as well was how clients discover
new content.
When a user installs a client, this client does not know any IPFS peers – or
rather any “social network nodes” where it can fetch user profiles/data from -
yet.
Even if it knows some bootstrap nodes to connect to, it might not get content
from them if they do not serve any social network data and if the user does
not know any hashes of user profiles.
To be able to find new social network IPFS nodes, a client has to know their
IPNS hashes – But how to discover them?</p>

<p>This is a hard problem. My first idea would be a PubSub channel where each
client periodically announces their IPNS hashes.  I&#39;m not sure whether PubSub
nodes must be connected directly. If this is the case, the problem just got
harder.  There&#39;s also the problem that this channel would be rather
high-volume as soon as the network grows. If each client announces their IPNS
hash every 15 minutes, for example, we get 4 messages per client each hour.
That&#39;s already a lot of bandwidth if we speak about 1,000, 10,000 or even
100,000 clients!
It is also an attack-vector how the system can be flooded. Not nice!</p>

<p>One way to think about this is that if only nodes which are subscribed to a
topic do also forward the topics messages
(like <a href="https://discuss.ipfs.io/t/when-will-ipfs-pubsub-be-scaleable/1923/2?u=musicmatze">this comment suggests</a>),
we <em>could</em> reduce the time between “publishing” messages in the topic.
Such a message would contain all IPNS hashes a node knows about, thus the
amount of data would be rather much. As soon as the network grows, a node would
need to send this message less and less often, to reduce the number of
messages and bytes send. Still, if each node knows 10,000 nodes and sends this
list once an hour, we get</p>

<pre><code>bytes_per_hash = 46
number_of_nodes = 10_000
message_size = bytes_per_hash * number_of_nodes
bytes_per_hour = number_of_nodes * message_size
</code></pre>

<p>4,28 GiB of “I know these nodes” messages per hour. That does
obviousely not scale!</p>

<p>Maybe each client should offer an API where other clients can ask them about
which IPNS hashes they know. That would be a “pull” approach rather than a
“push” approach then, which would limit bandwidth a bit.  This could even be
done via PubSub as well, where the channel name is generared from the IPFS
instance hash, for example.
I don&#39;t know whether this would be a nice idea.
Still, this would need some “internet-facing” software where clients need to
be able to <em>talk directly to eachother</em>. I don&#39;t know whether IPFS offers
functionality to do this in a simple way.</p>

<p>Either way, I have no solution for this problem yet.</p>

<h1 id="why-ipfs" id="why-ipfs">Why IPFS?</h1>

<p>Platforms like scuttlebutt or movim also implement distributed social
networks, why not use those? Also, why IPFS and not the dat protocol or
something else?</p>

<p>That question is rather simple to answer: IPFS provides functionality and
semantics other tools/frameworks do not provide. Most importantly the notion
that content is immutable, but also full decentralization (not federation like
with services like movim or mastodon, for example).</p>

<p>Having immutable content is a key point. The dat protocol, for example,
features mutable content as it is roughly based on bittorrent (if I understood
everything correctly, feel free to point out mistakes).
That might be nice in some cases, though I think immutability is the way to go.
Distributed applications or frameworks for distributed content with immutability
as core concept are better suited for netsplit, slow connections and
peer-to-peer applications.
From what I saw from the last weeks and months of looking at frameworks for
distributed content storage is that IPFS is way more mature than these other
frameworks. IPFS is build to replace existing contents and to stay, and that&#39;s a
nice thing to build applications on.</p>

<h1 id="remaining-questions" id="remaining-questions">Remaining Questions</h1>

<p>Some questions are remaining:</p>
<ul><li>Is it possible to talk to a specific node directly in IPFS? This would be
helpful for discovering content by asking nodes what profiles they know.
It would also be a nice way for finding consensus when multiple devices have
to agree on which node publishes a merge.</li>
<li>How fast is IPFS with small files? If I need to traverse a long chain of
profile updates, I constantly request a small file, parse it and continue
requesting the previous node in the chain. That should be fast.
If it is not, we might need to introduce some “pack files” where a list of
metadata-nodes is provided and traversing becomes unnecessary with. But that
makes deleting content rather complicated, TBH.</li></ul>

<p>That&#39;s all I can think of right now, but there might be more questions which
are not yet answered.</p>

<h1 id="problems-are-hard-in-distributed-environments" id="problems-are-hard-in-distributed-environments">Problems are hard in distributed environments</h1>

<p>Distributed systems involve a lot of new complexity where we have to carefully
think about details and how to design our system.
New ways to design systems can be discovered by the “distributed approach” and
new paradigms emerge.</p>

<p>Moving away from a central authority which holds the truth, the global state and
also the data results in a
<a href="https://ruben.verborgh.org/blog/2017/12/20/paradigm-shifts-for-the-decentralized-web/">paradigm shift</a>
we really have to be careful about.</p>

<p>I think we can do it and design new, powerful and fully distributed systems
with user freedom, usability, user-convenience and state-of-the-art in mind.
Users want to have a system which is reliable, failure proof, convenient and
easy to use.
They want to “always be connected”.
I think we can provide such software.
Developers want nice abstractions to build upon, data integrity, failure-proof
software with simplicity designed into the system and reusable data structures
and be able to scale.
I think IPFS is the way to for this.
In addition, I think we can provide free software with free data.</p>

<p>I do not claim to know the final solution to any of the problems layed out in
this article.
Its just that I think of them and would love to get an open conversation started
on the whole subject of distributed social networks and problems that come with
them.</p>

<p>And maybe we can come up with a prototype for this?</p>

<p>tags:  <a href="https://beyermatthias.de/tag:distributed" class="hashtag"><span>#</span><span class="p-category">distributed</span></a> <a href="https://beyermatthias.de/tag:network" class="hashtag"><span>#</span><span class="p-category">network</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:social" class="hashtag"><span>#</span><span class="p-category">social</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/blueprint-of-a-distributed-social-network-on-ipfs-and-its-problems-2</guid>
      <pubDate>Sun, 25 Feb 2018 16:39:10 +0100</pubDate>
    </item>
    <item>
      <title>Developing a Query-API for toml-query</title>
      <link>https://beyermatthias.de/developing-a-query-api-for-toml-query</link>
      <description>&lt;![CDATA[For one of my other projects (yes, imag), I developed a query library for TOML.&#xA;I currently am planning a new feature for it: A query API which can be used&#xA;to execute prepared queries on a given TOML document.&#xA;&#xA;But let me start with the basics!&#xA;&#xA;What is TOML?&#xA;&#xA;&#34;TOML&#34; stands for &#34;Tom&#39;s Obvious, Minimal Language&#34; and is somewhat similar to&#xA;JSON, though is highly readable and easy to understand.&#xA;It is mainly used for configuration files in the Rust community, I use it as&#xA;header format for imag store entries and as configuration file format for&#xA;imag, for example.&#xA;&#xA;A mini TOML file looks like this:&#xA;&#xA;[table]&#xA;key = &#34;value&#34;&#xA;[table.subtable]&#xA;key = [&#34;another value in an array&#34;]&#xA;&#xA;What does &#39;toml-query&#39; do?&#xA;&#xA;toml-query, the library I developed, is actually an extension.&#xA;It extends the toml-rs library, which is a serde based library for the&#xA;TOML data format. Serde is the serialization/deserialization framework in&#xA;the rust ecosystem. Thus, toml-rs is a frontend to that framework to work&#xA;with the file format.&#xA;&#xA;Because serde is such an amazing tool, one can write code like this:&#xA;&#xA;[derive(Serialize, Deserialize)]&#xA;struct Foo {&#xA;  integer: i32,&#xA;  string: String&#xA;}&#xA;&#xA;to get a struct which can be serialized to and deserialized from TOML&#xA;with minimal effort in Rust:&#xA;&#xA;extern crate serde;&#xA;[macrouse] extern crate serdederive;&#xA;extern crate toml;&#xA;&#xA;[derive(Serialize, Deserialize)]&#xA;struct Foo {&#xA;    integer: i32,&#xA;    string: String,&#xA;}&#xA;&#xA;fn main() {&#xA;    let foo = Foo {&#xA;        integer: 15,&#xA;        string: String::from(&#34;Hello world!&#34;),&#xA;    };&#xA;&#xA;    let serialized = toml::tostring(&amp;foo).unwrap(); // here is magic!&#xA;    let text = r#&#34;integer = 15&#xA;string = &#34;Hello world!&#34;&#xA;&#34;#;&#xA;    asserteq!(text, serialized);&#xA;}&#xA;&#xA;(this piece of code can be executed with&#xA;the playground).&#xA;&#xA;The resulting TOML can, of course, be deserialized back to an instance of&#xA;Foo.&#xA;That&#39;s really neat if you want to read your configuration file, because you&#xA;simply have to write a struct which describes the variables your&#xA;configuration file should have and let toml-rs and serde do the magic of&#xA;failure-free deserialization.&#xA;If an error happens, for example a key is not there, the deserialization fails&#xA;and you can forward the error to your user, for example.&#xA;&#xA;But what happens if you have a really complex configuration file? What if you&#xA;don&#39;t know, at build time of your program, what your configuration file looks&#xA;like? What if you have things that are allowed to go wrong and you have to&#xA;very precisely catch errors and handle them individually?&#xA;Then, this awesomeness becomes complicated.&#xA;&#xA;That&#39;s why I wrote toml-query. It helps you maintain a real CRUD&#xA;(Create-Read-Update-Delete) workflow on TOML documents.&#xA;For example, when reading your toml document into memory and into toml-rs&#xA;structures, you can then read and write specific values by their path:&#xA;&#xA;extern crate serde;&#xA;extern crate toml;&#xA;extern crate tomlquery;&#xA;&#xA;fn main() {&#xA;    let text = r#&#34;integer = 15&#xA;string = &#34;Hello world!&#34;&#xA;&#34;#;&#xA;    let toml : toml::Value = toml::de::fromstr(text).unwrap();&#xA;    let int = toml.read(&#34;integer&#34;) {&#xA;        Ok(Some(&amp;Value::Integer(i))) =  i,&#xA;        Ok(Some()) =  panic!(&#34;Type error: Not an integer!&#34;),&#xA;        Ok(None)    =  panic!(&#34;Key &#39;integer&#39; missing&#34;),&#xA;        Err(e)      =  panic!(&#34;Error reading TOML document: {:?}&#34;, e);&#xA;    }&#xA;}&#xA;&#xA;The upper code example reads the TOML document into a Value (which is a&#xA;datatype provided by toml-rs) and then read()s the value at &#34;integer&#34;.&#xA;This read operation is done via the &#34;path&#34; to the value, and of course this&#xA;path is not only a string. Things like &#34;table.subtable.value&#34; are possible.&#xA;Array indexes are possible. This works with several CRUD operations: Reading&#xA;values, writing values and creating intermediate &#34;tables&#34; or &#34;arrays&#34; if they&#xA;are not already created, updating values and of course also deleting values.&#xA;&#xA;Why a Query-API?&#xA;&#xA;The things I explained above are entirely CRUD functionality things. There is&#xA;no &#34;query&#34; thing here.&#xA;&#xA;The next step I am currently thinking about is an API which can be used to&#xA;build complex queries, chaining them and (not in the first version of the API,&#xA;but maybe later), also rolling them back.&#xA;&#xA;The idea would be an API like this:&#xA;&#xA;let query = Read::new(&#34;foo&#34;)&#xA;  .andthen(SetTo::new(|x| x + 1))&#xA;  .andthen(DeleteAt::new(&#34;bar&#34;));&#xA;&#xA;let queryresult = document.execute(query);&#xA;&#xA;Here, we build a query which reads a value at &#34;foo&#34;, then increments that&#xA;value and after that deletes the value at &#34;bar&#34;.&#xA;If one of these steps fails, the others are never executed.&#xA;&#xA;The equivalent in CRUD calls would look like this:&#xA;&#xA;let value = document.read(&#34;foo&#34;).unwrap().unwrap();&#xA;let value = value + 1;&#xA;document.set(&#34;foo&#34;, value).unwrap();&#xA;document.delete(&#34;bar&#34;).unwrap();&#xA;&#xA;The calls to unwrap() are here to show where errors can happen. All this&#xA;would be hidden in the query functionality and the queryresult would then&#xA;hold an error which can be used to tell the user what exactly went wrong and&#xA;where.&#xA;&#xA;The exact shape and semantics of the API are not as shown in the example&#xA;above. The example is solely used for visualizing how the API would look like.&#xA;&#xA;How does the Query-API work?&#xA;&#xA;The basic idea here is to encapsulate CRUD calls into objects which then can&#xA;be chained in some way.&#xA;That&#39;s the whole thing, actually.&#xA;&#xA;The important thing is that the user is able to define own &#34;Query types&#34;:&#xA;Types which can be put into the chain of queries and which are composed of&#xA;other query types.&#xA;This way, a user can basically define structures and procedures to write code&#xA;like this:&#xA;&#xA;let result = document.execute(TransformConfigFileFormat::new());&#xA;&#xA;and the TransformConfigFileFormat type then transforms an old config file&#xA;format to a new one (for example).&#xA;&#xA;This requirement makes the whole thing complicated. To list the full&#xA;requirements:&#xA;&#xA;A query may return data which may be used by the next query in the chain&#xA;A user of the library should be able to compose new query objects from&#xA;  existing ones&#xA;The CRUD functionalities shall be provided as &#34;query types&#34;&#xA;The API should be easy to use with both &#34;query types&#34; and closures (think:&#xA;  query = otherquery.andthen(|val| val + 1);&#xA;&#xA;Reversible queries / Transactions&#xA;&#xA;A really nice thing would be reversible queries.&#xA;&#xA;In this scenario, one would be able to call a chain of queries and if one of&#xA;the queries fails, the document is left untouched.&#xA;This could be done by either copying the whole document before executing the&#xA;query-chain and replacing the modified version with the unmodified if&#xA;something failed, or by making the queries actually role-back-able (thus, an&#xA;insert would reverse to a delete and the other way round, for example).&#xA;&#xA;The first idea is more memory-intensive and the latter more runtime/CPU intensive.&#xA;Maybe both would be an idea and the user is then able to decide.&#xA;&#xA;Other things&#xA;&#xA;One other thing which would be really_ great is to generalize the&#xA;functionality of toml-query over all data-formats serde provides&#xA;serialization and deserialization functionality for.&#xA;&#xA;This would be the ultimate end-game and I&#39;m sure I&#39;m not able to do this&#xA;without help (because toml-query is already really complex right now and&#xA;such a thing would increase complexity even more).&#xA;&#xA;If someone wants to step up and do this, I&#39;d love to help!&#xA;&#xA;tags:  #software #rust #open-source&#xA;]]&gt;</description>
      <content:encoded><![CDATA[<p>For one of my other projects (yes, imag), I developed a query library for TOML.
I currently am planning a new feature for it: A query API which can be used
to execute prepared queries on a given TOML document.</p>

<p>But let me start with the basics!</p>

<h1 id="what-is-toml" id="what-is-toml">What is TOML?</h1>

<p>“TOML” stands for “Tom&#39;s Obvious, Minimal Language” and is somewhat similar to
JSON, though is highly readable and easy to understand.
It is mainly used for configuration files in the Rust community, I use it as
header format for imag store entries and as configuration file format for
imag, for example.</p>

<p>A mini TOML file looks like this:</p>

<pre><code>[table]
key = &#34;value&#34;
[table.subtable]
key = [&#34;another value in an array&#34;]
</code></pre>

<h1 id="what-does-toml-query-do" id="what-does-toml-query-do">What does &#39;toml-query&#39; do?</h1>

<p><code>toml-query</code>, the library I developed, is actually an <em>extension</em>.
It extends the <code>toml-rs</code> library, which is a <code>serde</code> based library for the
TOML data format. <code>Serde</code> is the serialization/deserialization framework in
the rust ecosystem. Thus, <code>toml-rs</code> is a <em>frontend</em> to that framework to work
with the file format.</p>

<p>Because <code>serde</code> is such an amazing tool, one can write code like this:</p>

<pre><code>[derive(Serialize, Deserialize)]
struct Foo {
  integer: i32,
  string: String
}
</code></pre>

<p>to get a <code>struct</code> which can be serialized to and deserialized from TOML
<em>with minimal effort</em> in Rust:</p>

<pre><code>extern crate serde;
#[macro_use] extern crate serde_derive;
extern crate toml;

#[derive(Serialize, Deserialize)]
struct Foo {
    integer: i32,
    string: String,
}

fn main() {
    let foo = Foo {
        integer: 15,
        string: String::from(&#34;Hello world!&#34;),
    };

    let serialized = toml::to_string(&amp;foo).unwrap(); // here is magic!
    let text = r#&#34;integer = 15
string = &#34;Hello world!&#34;
&#34;#;
    assert_eq!(text, serialized);
}
</code></pre>

<p>(this piece of code can be executed with
<a href="https://play.rust-lang.org/">the playground</a>).</p>

<p>The resulting TOML can, of course, be deserialized back to an instance of
<code>Foo</code>.
That&#39;s really neat if you want to read your configuration file, because you
simply have to write a <code>struct</code> which describes the variables your
configuration file should have and let <code>toml-rs</code> and <code>serde</code> do the magic of
failure-free deserialization.
If an error happens, for example a key is not there, the deserialization fails
and you can forward the error to your user, for example.</p>

<p>But what happens if you have a really complex configuration file? What if you
don&#39;t know, at build time of your program, what your configuration file looks
like? What if you have things that are allowed to go wrong and you have to
very precisely catch errors and handle them individually?
Then, this awesomeness becomes complicated.</p>

<p>That&#39;s why I wrote <code>toml-query</code>. It helps you maintain a real CRUD
(Create-Read-Update-Delete) workflow on TOML documents.
For example, when reading your toml document into memory and into <code>toml-rs</code>
structures, you can then read and write specific values by their <em>path</em>:</p>

<pre><code>extern crate serde;
extern crate toml;
extern crate toml_query;

fn main() {
    let text = r#&#34;integer = 15
string = &#34;Hello world!&#34;
&#34;#;
    let toml : toml::Value = toml::de::from_str(text).unwrap();
    let int = toml.read(&#34;integer&#34;) {
        Ok(Some(&amp;Value::Integer(i))) =&gt; i,
        Ok(Some(_)) =&gt; panic!(&#34;Type error: Not an integer!&#34;),
        Ok(None)    =&gt; panic!(&#34;Key &#39;integer&#39; missing&#34;),
        Err(e)      =&gt; panic!(&#34;Error reading TOML document: {:?}&#34;, e);
    }
}
</code></pre>

<p>The upper code example reads the TOML document into a <code>Value</code> (which is a
datatype provided by <code>toml-rs</code>) and then <code>read()</code>s the value at <code>&#34;integer&#34;</code>.
This read operation is done via the “path” to the value, and of course this
path is not only a string. Things like <code>&#34;table.subtable.value&#34;</code> are possible.
Array indexes are possible. This works with several CRUD operations: Reading
values, writing values and creating intermediate “tables” or “arrays” if they
are not already created, updating values and of course also deleting values.</p>

<h1 id="why-a-query-api" id="why-a-query-api">Why a Query-API?</h1>

<p>The things I explained above are entirely CRUD functionality things. There is
no “query” thing here.</p>

<p>The next step I am currently thinking about is an API which can be used to
build complex queries, chaining them and (not in the first version of the API,
but maybe later), also rolling them back.</p>

<p>The idea would be an API like this:</p>

<pre><code>let query = Read::new(&#34;foo&#34;)
  .and_then(SetTo::new(|x| x + 1))
  .and_then(DeleteAt::new(&#34;bar&#34;));

let query_result = document.execute(query);
</code></pre>

<p>Here, we build a query which <em>reads</em> a value at “foo”, then increments that
value and after that deletes the value at “bar”.
If one of these steps fails, the others are never executed.</p>

<p>The equivalent in CRUD calls would look like this:</p>

<pre><code>let value = document.read(&#34;foo&#34;).unwrap().unwrap();
let value = value + 1;
document.set(&#34;foo&#34;, value).unwrap();
document.delete(&#34;bar&#34;).unwrap();
</code></pre>

<p>The calls to <code>unwrap()</code> are here to show where errors can happen. All this
would be hidden in the query functionality and the <code>query_result</code> would then
hold an error which can be used to tell the user what exactly went wrong and
where.</p>

<p>The exact shape and semantics of the API are not as shown in the example
above. The example is solely used for visualizing how the API would look like.</p>

<h1 id="how-does-the-query-api-work" id="how-does-the-query-api-work">How does the Query-API work?</h1>

<p>The basic idea here is to encapsulate CRUD calls into objects which then can
be chained in some way.
That&#39;s the whole thing, actually.</p>

<p>The important thing is that the user is able to define own “Query types”:
Types which can be put into the chain of queries and which are composed of
other query types.
This way, a user can basically define structures and procedures to write code
like this:</p>

<pre><code>let result = document.execute(TransformConfigFileFormat::new());
</code></pre>

<p>and the <code>TransformConfigFileFormat</code> type then transforms an old config file
format to a new one (for example).</p>

<p>This requirement makes the whole thing complicated. To list the full
requirements:</p>
<ul><li>A query may return data which may be used by the next query in the chain</li>
<li>A user of the library should be able to compose new query objects from
existing ones</li>
<li>The CRUD functionalities shall be provided as “query types”</li>
<li>The API should be easy to use with both “query types” and closures (think:
<code>query = other_query.and_then(|val| val + 1);</code></li></ul>

<h1 id="reversible-queries-transactions" id="reversible-queries-transactions">Reversible queries / Transactions</h1>

<p>A really nice thing would be reversible queries.</p>

<p>In this scenario, one would be able to call a chain of queries and if one of
the queries fails, the document is left untouched.
This could be done by either copying the whole document before executing the
query-chain and replacing the modified version with the unmodified if
something failed, or by making the queries actually role-back-able (thus, an
insert would reverse to a delete and the other way round, for example).</p>

<p>The first idea is more memory-intensive and the latter more runtime/CPU intensive.
Maybe both would be an idea and the user is then able to decide.</p>

<h1 id="other-things" id="other-things">Other things</h1>

<p>One other thing which would be <em>really</em> great is to generalize the
functionality of <code>toml-query</code> over all data-formats <code>serde</code> provides
serialization and deserialization functionality for.</p>

<p>This would be the ultimate end-game and I&#39;m sure I&#39;m not able to do this
without help (because <code>toml-query</code> is already really complex right now and
such a thing would increase complexity even more).</p>

<p>If someone wants to step up and do this, I&#39;d love to help!</p>

<p>tags:  <a href="https://beyermatthias.de/tag:software" class="hashtag"><span>#</span><span class="p-category">software</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:open" class="hashtag"><span>#</span><span class="p-category">open</span></a>-source</p>
]]></content:encoded>
      <guid>https://beyermatthias.de/developing-a-query-api-for-toml-query</guid>
      <pubDate>Sun, 04 Feb 2018 16:39:00 +0100</pubDate>
    </item>
    <item>
      <title>How to improve your open source code (6) - Version control</title>
      <link>https://beyermatthias.de/how-to-improve-your-open-source-code-6-version-control</link>
      <description>&lt;![CDATA[small&#xA;  This post was written during my trip through Iceland and published much&#xA;  later than it was written.&#xA;/small&#xA;&#xA;Version Control is one important aspect when developing software as a&#xA;whole, and especially when developing open source software.&#xA;&#xA;Here are some thoughts about it.&#xA;&#xA;Technology&#xA;&#xA;First of all, technology wise it doesn&#39;t matter which version control&#xA;system one uses. For the sake I&#39;m using git here as an example VCS,&#xA;though others might do as well.&#xA;&#xA;One important thing, at least in my opinion, is that the VCS has some&#xA;basic functionality. This is mainly that it can be used distributed and&#xA;has a branching functionality (which are two things I like to believe&#xA;go hand in hand).&#xA;&#xA;So I do not care whether one uses git, mecurial, or anything else. Most&#xA;important is that a (D)VCS is actually used.&#xA;&#xA;Branching model&#xA;&#xA;Branching is a method that came up before git was created, as bitkeeper&#xA;had such functionality (as far as I can tell) before Linus Torvalds&#xA;wrote git. It is only that git has revolutionised the way we do version&#xA;control and brought branching to wider knowledge and use.&#xA;&#xA;In my opinion it is really important how branching is done. There is not&#xA;simply &#34;the branching&#34; but there are many ways to do branching and one&#xA;might be better for certain use case than another. There are known&#xA;models such as feature branching, the gitflow branching model and a&#xA;rebase-merge workflow. I don&#39;t want to explain each of them because&#xA;others have done so way better than I ever could.&#xA;&#xA;What I want to tell is that branching is not only important, but as&#xA;flexible as you might not even guess. This is not necessarily a good&#xA;thing - I&#39;ll show you in a minute. In my opinion, branching and&#xA;developing a branching model for a project is like developing an API.&#xA;Once it is set up properly, it may serve as a communication rule for a&#xA;project, putting developers on the same page about how certain things&#xA;have to be handled. Having a protocol on how to work on things is a good&#xA;thing. If implemented properly, branching can improve the work of&#xA;everyone as it is one point less to think about.&#xA;&#xA;The bad thing about flexibility of branching functionality is that it&#xA;can be done wrong. It&#39;s as simply as that, but merging one branch into&#xA;another when one is not supposed to do that, creates overhead which&#xA;might not be reversible. This has happened to the best communities (for&#xA;example the kernel community) but also happens in small communities,&#xA;often due to too few knowledge of the tools at hand.&#xA;&#xA;To summarize: If an open source project gets to a certain size (both&#xA;code-wise and contributor/community-wise) a branching model should be&#xA;implemented. If there are rules that contributors agree upon, it can&#xA;improve working speed and therefore overall happiness in the community.&#xA;Because developers like to bikeshed, it could also worsen happiness, of&#xA;course. Though, it is better than no plan and chaos instead.&#xA;&#xA;Hosting&#xA;&#xA;I will not go into thoughts about hosting platforms in this article but&#xA;rather on the how and why.&#xA;&#xA;First of all, hosting the code somewhere with a way to show it in a web&#xA;browser is a good way to improve the &#34;open&#34; part of open source code. Of&#xA;course, tarball downloads and such suffice, but we are in the 21st&#xA;century, so having a nice web interface is something one can expect.&#xA;&#xA;Making the code browsable is often done via a VCS-specific web frontend,&#xA;for example cgit for code version controlled with git. Therefore this&#xA;web interfaces often also feature functionality to go back in time&#xA;and view the history of one file. Maybe this is not needed&#xA;often, but nevertheless helpful if needed.&#xA;&#xA;I personally do not care about comments on code in my web interfaces&#xA;or even ways to register users on the site, but of course some people like&#xA;that. There are web interfaces that feature such things, for example for&#xA;the git VCS there is gitea, gogs, gitlab, ... and many more. And of&#xA;course there are the closed providers github, bitbucket and others...&#xA;&#xA;Making code public and contributions easy&#xA;&#xA;Hosting helps a lot with enabling contributions from strangers. No&#xA;doubt, github makes contributions ridiculously easy.&#xA;&#xA;I don&#39;t want to reiterate what others have said better and most people&#xA;already know. What I want to point out here is that open source does not&#xA;mean &#34;open contributions&#34;. One is completely free to reject all&#xA;contributions one ones code base.&#xA;&#xA;I really want to stress this. Open source does indeed mean that everyone&#xA;is able to view the code, which also enables them to copy it (though&#xA;redistribution might be limited or forbidden, as only free software&#xA;allows you - by definition - to redistribute and alter code) but not&#xA;necessarily that one is allowed or welcome to send in changes, feature&#xA;requests or the like.&#xA;&#xA;So if you want people to contribute to your code and suggest changes,&#xA;features or report bugs, you should somehow give them the opportunity to&#xA;do so. Depending on how &#34;open&#34; you want to be with your development you&#xA;either should use a hosting platform (like github or bitbucket) or a&#xA;slightly more &#34;closed&#34; variant, for example hosting your code on&#xA;your own gitea instance. One step further you&#39;d host your code on a&#xA;site where people might be able to get it, maybe even with a &#34;git&#xA;clone&#34;, though not send in pull requests, feature requests or open&#xA;issues (for example a hosted git repository with cgit interface).&#xA;Issues and bug reports could still be done via a mailinglist, if&#xA;desired.&#xA;&#xA;In fact, that last bit is what I consider for my own project&#xA;imag.&#xA;&#xA;SemVer, Change Management, Release Management&#xA;&#xA;As soon as your code is out there, you have to think about change and&#xA;release management. In my opinion, these are topics closely related to&#xA;source code version control as VCS often offer functionality to do&#xA;releases in one form or another and are clearly involved in the process&#xA;of change management.&#xA;&#xA;First of all, I&#39;d like to suggest you read the SemVer specification. It&#xA;is not that long but will help you understanding the next few&#xA;paragraphs. So if you haven&#39;t read it already, go ahead and do so. Even&#xA;if you don&#39;t apply SemVer to your projects it might open your eyes in&#xA;one aspect or another.&#xA;&#xA;But before we get into releases, we should first talk about change&#xA;management, or better named for my points: Pull request management.&#xA;&#xA;What I personally do with my PRs is, merge them when they&#39;re ready. This&#xA;approach is easy and works, so far, pretty well. From time to time I&#xA;have changes in my working branches (as stated before, I use feature&#xA;branches) which might conflict with other peoples work. For the sake of&#xA;contributor experience, I pause my PRs and wait until they are done with&#xA;theirs. We will talk a lot about this in the next episode of this&#xA;series, so I won&#39;t go into much detail. For now: This is a simple&#xA;approach that works perfectly well so far for me and my (considerably&#xA;small) open source projects.&#xA;&#xA;But as soon as ones project grews bigger, that approach might not do the&#xA;job anymore. If there are too many changes in a short amount of time&#xA;which have to be agreed on and that have to be merged, it might be time&#xA;to think about an alternative approach.&#xA;&#xA;There are two ways I would tackle this problem. I never experienced it in&#xA;the &#34;real world&#34;/in my projects, so the following is just a write down&#xA;of my thoughts. Take a grain of salt from here on.&#xA;&#xA;The first approach I can think of is to assign certain subsystems to&#xA;certain people. If the amount of changes has become too big, one could&#xA;assume that the codebase has also become tremendous. If that is the&#xA;case, sub-maintainers can handle certain subsystems and the project&#xA;leader can then periodically merge all changes together. This requires,&#xA;of course, at least two people that are interested into the subject and&#xA;willing to contribute maintaining efforts to the project.&#xA;&#xA;If the latter is not the case or there are too few people around for&#xA;this, one could consider a merge-window style approach, like known from&#xA;Linus himself. Changes are pulled in every other week, for example, and&#xA;the rest of the time, only bug fixes are merged into the project.&#xA;&#xA;These two approaches might become handy some day if one is about to&#xA;maintain a large code base alone (as in &#34;as the only project owner&#34;).&#xA;&#xA;Now on to release management. In my opinion, releases should be done as&#xA;soon as something works and from there on periodically. I myself made&#xA;one mistake too often: Pull more things into one release than would have&#xA;been good. For example the imag 0.2.0 release was over one year ago.&#xA;0.3.0 is almost ready, but not yet. I should&#39;ve done more releases in&#xA;between.&#xA;&#xA;In my opinion, more releases with clear-cut edges are better than long&#xA;release-cycles. As soon as there is a new feature for users - release.&#xA;User-facing fixed - release. This might result in high numbers for&#xA;versioning, but who cares?&#xA;&#xA;This is where I want to throw SemVer in, to adjust my statement from the&#xA;last paragraph with a &#34;but&#34;.&#xA;&#xA;SemVer can be used to notify breaking user interfaces. This is a really&#xA;good thing and therefore I think SemVer should be applied everywhere.&#xA;SemVer also states that in the &#34; 0.y.z phase&#34; everything is allowed to&#xA;happen, also API breakage. This is where I want to adjust my statement&#xA;from above. A lot of releases should be done in the 0.y.z phase, but&#xA;also within that scope. As soon as a library or program hits the 1.0.0,&#xA;changes should be applied carefully. One really does not want to end up&#xA;with a program or library in version 127.0.0, right? That&#39;d also&#xA;decrease a users trust into the application as one can expect breakage&#xA;with every new release.&#xA;&#xA;So what I&#39;d do and actually plan doing with my projects is releasing a&#xA;number of zero-releases until I am confident that everything is all&#xA;right and then go from there. For imag specifically I am not thinking&#xA;about 1.0.0 because imag is far from ready, but for my other projects,&#xA;especially toml-query, I think of 1.0.0 already.&#xA;&#xA;Another point which popped into my head weeks after the initial draft of&#xA;this article was: Do not plan the features of the next release with a&#xA;release number! This might sound a bit odd, so let me explain. For&#xA;example, you&#39;re planning three major features for the next release,&#xA;which will be 0.15.0 then. And you&#39;re slowly getting to a point where&#xA;the release becomes ready, you might need three more weeks to get it&#xA;ready. Now, a contributor steps up and opens a pull request with&#xA;another feature, which is already completely implemented, tested and&#xA;also documented in the pull request. The contributor needs this feature&#xA;as soon as possible in your code and you also think that it might be a&#xA;great idea to release this as soon as possible. After you merged the&#xA;request, you release the source - as 0.15.0, despite your three features&#xA;are not yet completed.&#xA;&#xA;Two things come to mind in this scenario: First, if two of your three&#xA;features are already completed, they might show up in 0.15.0 but one&#xA;feature has to be moved to the next release. If these two features are&#xA;ready, but not tested, you might end up with a buggy&#xA;release and have to release 0.15.1 soonish - more effort for you. If you&#xA;do not merge your features into the master branch of your project, but&#xA;you have a 0.15.0-prepare branch or something like that, you end up with&#xA;a rather ugly merge-mess later on, as 0.15.0 is already released and you&#xA;cannot just rename a public branch.&#xA;&#xA;So how to handle this properly? I came to the conclusion that&#xA;release-branches is the way to go here. In the scenario described above,&#xA;you&#39;d branch off of the release before, most certainly 0.14.x and create&#xA;a new branch 0.15.0, where the pull request of the contributor would be&#xA;merged than. As soon as the release is out, 0.15.0 will be tagged and&#xA;merged back to the master branch.&#xA;&#xA;What my point is here: you&#39;d still need to rename your next milestone or&#xA;rewrite your issues for the next release. That&#39;s why I would not plan&#xA;&#34;0.15.0&#34;, but simply &#34;the next release&#34; - because you&#39;ll never know&#xA;whether your planned things will actually be the next release or the&#xA;the release after. So lessen the effort for yourself here!&#xA;&#xA;Next&#xA;&#xA;In the next article in this series I want to elaborate on how to make a&#xA;contribution as pleasing as possible for the contributor. I guess I can&#xA;talk a lot about that because I&#39;ve contributed to a lot of projects&#xA;already, including but not limited to linux,&#xA;nixpkgs and&#xA;nanoc.&#xA;&#xA;tags: #open-source #programming #software #tools #rust&#xA;]]&gt;</description>
      <content:encoded><![CDATA[<p><small>
  This post was written during my trip through Iceland and published much
  later than it was written.
</small></p>

<p>Version Control is one important aspect when developing software as a
whole, and especially when developing open source software.</p>

<p>Here are some thoughts about it.</p>

<h1 id="technology" id="technology">Technology</h1>

<p>First of all, technology wise it doesn&#39;t matter which version control
system one uses. For the sake I&#39;m using git here as an example VCS,
though others might do as well.</p>

<p>One important thing, at least in my opinion, is that the VCS has some
basic functionality. This is mainly that it can be used distributed and
has a branching functionality (which are two things I like to believe
go hand in hand).</p>

<p>So I do not care whether one uses git, mecurial, or anything else. Most
important is that a (D)VCS is actually used.</p>

<h1 id="branching-model" id="branching-model">Branching model</h1>

<p>Branching is a method that came up before git was created, as bitkeeper
had such functionality (as far as I can tell) before Linus Torvalds
wrote git. It is only that git has revolutionised the way we do version
control and brought branching to wider knowledge and use.</p>

<p>In my opinion it is really important how branching is done. There is not
simply “the branching” but there are many ways to do branching and one
might be better for certain use case than another. There are known
models such as feature branching, the gitflow branching model and a
rebase-merge workflow. I don&#39;t want to explain each of them because
others have done so way better than I ever could.</p>

<p>What I want to tell is that branching is not only important, but as
flexible as you might not even guess. This is not necessarily a good
thing – I&#39;ll show you in a minute. In my opinion, branching and
developing a branching model for a project is like developing an API.
Once it is set up properly, it may serve as a communication rule for a
project, putting developers on the same page about how certain things
have to be handled. Having a protocol on how to work on things is a good
thing. If implemented properly, branching can improve the work of
everyone as it is one point less to think about.</p>

<p>The bad thing about flexibility of branching functionality is that it
can be done wrong. It&#39;s as simply as that, but merging one branch into
another when one is not supposed to do that, creates overhead which
might not be reversible. This has happened to the best communities (for
example the kernel community) but also happens in small communities,
often due to too few knowledge of the tools at hand.</p>

<p>To summarize: If an open source project gets to a certain size (both
code-wise and contributor/community-wise) a branching model should be
implemented. If there are rules that contributors agree upon, it can
improve working speed and therefore overall happiness in the community.
Because developers like to bikeshed, it could also worsen happiness, of
course. Though, it is better than no plan and chaos instead.</p>

<h1 id="hosting" id="hosting">Hosting</h1>

<p>I will not go into thoughts about hosting platforms in this article but
rather on the how and why.</p>

<p>First of all, hosting the code somewhere with a way to show it in a web
browser is a good way to improve the “open” part of open source code. Of
course, tarball downloads and such suffice, but we are in the 21st
century, so having a nice web interface is something one can expect.</p>

<p>Making the code browsable is often done via a VCS-specific web frontend,
for example cgit for code version controlled with git. Therefore this
web interfaces often also feature functionality to go back in time
and view the history of one file. Maybe this is not needed
often, but nevertheless helpful if needed.</p>

<p>I personally do not care about comments on code in my web interfaces
or even ways to register users on the site, but of course some people like
that. There are web interfaces that feature such things, for example for
the git VCS there is gitea, gogs, gitlab, ... and many more. And of
course there are the closed providers github, bitbucket and others...</p>

<h1 id="making-code-public-and-contributions-easy" id="making-code-public-and-contributions-easy">Making code public and contributions easy</h1>

<p>Hosting helps a lot with enabling contributions from strangers. No
doubt, github makes contributions ridiculously easy.</p>

<p>I don&#39;t want to reiterate what others have said better and most people
already know. What I want to point out here is that open source does not
mean “open contributions”. One is completely free to reject all
contributions one ones code base.</p>

<p>I really want to stress this. Open source does indeed mean that everyone
is able to view the code, which also enables them to copy it (though
redistribution might be limited or forbidden, as only free software
allows you – by definition – to redistribute and alter code) but not
necessarily that one is allowed or welcome to send in changes, feature
requests or the like.</p>

<p>So if you want people to contribute to your code and suggest changes,
features or report bugs, you should somehow give them the opportunity to
do so. Depending on how “open” you want to be with your development you
either should use a hosting platform (like github or bitbucket) or a
slightly more “closed” variant, for example hosting your code on
your own gitea instance. One step further you&#39;d host your code on a
site where people might be able to get it, maybe even with a “git
clone”, though not send in pull requests, feature requests or open
issues (for example a hosted git repository with cgit interface).
Issues and bug reports could still be done via a mailinglist, if
desired.</p>

<p>In fact, that last bit is what I consider for my own project
<a href="https://imag-pim.org">imag</a>.</p>

<h1 id="semver-change-management-release-management" id="semver-change-management-release-management">SemVer, Change Management, Release Management</h1>

<p>As soon as your code is out there, you have to think about change and
release management. In my opinion, these are topics closely related to
source code version control as VCS often offer functionality to do
releases in one form or another and are clearly involved in the process
of change management.</p>

<p>First of all, I&#39;d like to suggest you read the SemVer specification. It
is not that long but will help you understanding the next few
paragraphs. So if you haven&#39;t read it already, go ahead and do so. Even
if you don&#39;t apply SemVer to your projects it might open your eyes in
one aspect or another.</p>

<p>But before we get into releases, we should first talk about change
management, or better named for my points: Pull request management.</p>

<p>What I personally do with my PRs is, merge them when they&#39;re ready. This
approach is easy and works, so far, pretty well. From time to time I
have changes in my working branches (as stated before, I use feature
branches) which might conflict with other peoples work. For the sake of
contributor experience, I pause my PRs and wait until they are done with
theirs. We will talk a lot about this in the next episode of this
series, so I won&#39;t go into much detail. For now: This is a simple
approach that works perfectly well so far for me and my (considerably
small) open source projects.</p>

<p>But as soon as ones project grews bigger, that approach might not do the
job anymore. If there are too many changes in a short amount of time
which have to be agreed on and that have to be merged, it might be time
to think about an alternative approach.</p>

<p>There are two ways I would tackle this problem. I never experienced it in
the “real world”/in my projects, so the following is just a write down
of my thoughts. Take a grain of salt from here on.</p>

<p>The first approach I can think of is to assign certain subsystems to
certain people. If the amount of changes has become too big, one could
assume that the codebase has also become tremendous. If that is the
case, sub-maintainers can handle certain subsystems and the project
leader can then periodically merge all changes together. This requires,
of course, at least two people that are interested into the subject and
willing to contribute maintaining efforts to the project.</p>

<p>If the latter is not the case or there are too few people around for
this, one could consider a merge-window style approach, like known from
Linus himself. Changes are pulled in every other week, for example, and
the rest of the time, only bug fixes are merged into the project.</p>

<p>These two approaches might become handy some day if one is about to
maintain a large code base alone (as in “as the only project owner”).</p>

<p>Now on to release management. In my opinion, releases should be done as
soon as something works and from there on periodically. I myself made
one mistake too often: Pull more things into one release than would have
been good. For example the imag 0.2.0 release was over one year ago.
0.3.0 is almost ready, but not yet. I should&#39;ve done more releases in
between.</p>

<p>In my opinion, more releases with clear-cut edges are better than long
release-cycles. As soon as there is a new feature for users – release.
User-facing fixed – release. This might result in high numbers for
versioning, but who cares?</p>

<p>This is where I want to throw SemVer in, to adjust my statement from the
last paragraph with a “but”.</p>

<p>SemVer can be used to notify breaking user interfaces. This is a really
good thing and therefore I think SemVer should be applied everywhere.
SemVer also states that in the “ 0.y.z phase” everything is allowed to
happen, also API breakage. This is where I want to adjust my statement
from above. A lot of releases should be done in the 0.y.z phase, but
also within that scope. As soon as a library or program hits the 1.0.0,
changes should be applied carefully. One really does not want to end up
with a program or library in version 127.0.0, right? That&#39;d also
decrease a users trust into the application as one can expect breakage
with every new release.</p>

<p>So what I&#39;d do and actually plan doing with my projects is releasing a
number of zero-releases until I am confident that everything is all
right and then go from there. For imag specifically I am not thinking
about 1.0.0 because imag is far from ready, but for my other projects,
especially toml-query, I think of 1.0.0 already.</p>

<p>Another point which popped into my head weeks after the initial draft of
this article was: Do not plan the features of the next release with a
release number! This might sound a bit odd, so let me explain. For
example, you&#39;re planning three major features for the next release,
which will be 0.15.0 then. And you&#39;re slowly getting to a point where
the release becomes ready, you might need three more weeks to get it
ready. Now, a contributor steps up and opens a pull request with
<em>another</em> feature, which is already completely implemented, tested and
also documented in the pull request. The contributor needs this feature
as soon as possible in your code and you also think that it might be a
great idea to release this as soon as possible. After you merged the
request, you release the source – as 0.15.0, despite your three features
are not yet completed.</p>

<p>Two things come to mind in this scenario: First, if two of your three
features are already completed, they might show up in 0.15.0 but one
feature has to be moved to the next release. If these two features are
ready, but not tested, you might end up with a buggy
release and have to release 0.15.1 soonish – more effort for you. If you
do not merge your features into the master branch of your project, but
you have a 0.15.0-prepare branch or something like that, you end up with
a rather ugly merge-mess later on, as 0.15.0 is already released and you
cannot just rename a public branch.</p>

<p>So how to handle this properly? I came to the conclusion that
release-branches is the way to go here. In the scenario described above,
you&#39;d branch off of the release before, most certainly 0.14.x and create
a new branch 0.15.0, where the pull request of the contributor would be
merged than. As soon as the release is out, 0.15.0 will be tagged and
merged back to the master branch.</p>

<p>What my point is here: you&#39;d still need to rename your next milestone or
rewrite your issues for the next release. That&#39;s why I would not plan
“0.15.0”, but simply “the next release” – because you&#39;ll never know
whether your planned things will actually be the <em>next</em> release or the
<em>the release after</em>. So lessen the effort for yourself here!</p>

<h1 id="next" id="next">Next</h1>

<p>In the next article in this series I want to elaborate on how to make a
contribution as pleasing as possible for the contributor. I guess I can
talk a lot about that because I&#39;ve contributed to a lot of projects
already, including but not limited to <a href="https://kernel.org">linux</a>,
<a href="https://github.com/nixos/nixpkgs">nixpkgs</a> and
<a href="https://nanoc.ws">nanoc</a>.</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:software" class="hashtag"><span>#</span><span class="p-category">software</span></a> <a href="https://beyermatthias.de/tag:tools" class="hashtag"><span>#</span><span class="p-category">tools</span></a> <a href="https://beyermatthias.de/tag:rust" class="hashtag"><span>#</span><span class="p-category">rust</span></a></p>
]]></content:encoded>
      <guid>https://beyermatthias.de/how-to-improve-your-open-source-code-6-version-control</guid>
      <pubDate>Sat, 03 Feb 2018 16:38:57 +0100</pubDate>
    </item>
    <item>
      <title>Extending an Iterator in Rust</title>
      <link>https://beyermatthias.de/extending-an-iterator-in-rust</link>
      <description>&lt;![CDATA[A common thing one has to do in Rust to leverage zero-cost abstractions and&#xA;convenience is to extend types.&#xA;By &#34;extending&#34; them I mean adding functionality (functions) to the type which&#xA;make it more convenient to use and &#34;improve&#34; it for the domain at hand.&#xA;&#xA;From time to time, one needs to extend generic types, which is a difficult&#xA;thing to do. Especially when it comes to iterators, where extending is often&#xA;tricky.&#xA;&#xA;That&#39;s why I want to write some notes on it down.&#xA;&#xA;How do filters work?&#xA;&#xA;I have this crate called &#34;filters&#34; which offers nice functionality for&#xA;building predicates with the builder pattern.&#xA;A predicate is nothing more than a function which takes something by reference&#xA;and returns a boolean for it:&#xA;&#xA;fn(&amp;self, some: &amp;Thing) -  bool;&#xA;&#xA;The function is now allowed to decide whether the Thing shall be used. This&#xA;is useful when working with iterators:&#xA;&#xA;let filter = LowerThan::new(5);&#xA;vec![1,2,3,4,5,6,7,8,9].iter().filter(|e| filter.filter(&amp;e)).collect()&#xA;&#xA;Filters can, as I mentioned, be build with the builder-pattern:&#xA;&#xA;let filter = HigherThan::new(5)&#xA;    .and(LowerThan::new(20))&#xA;    .and(UnequalTo::new(15));&#xA;&#xA;vec![1,2,3,4,5,6,7,8,9].iter().filter(|e| filter.filter(&amp;e)).collect()&#xA;&#xA;One can also define own filters (in fact, the HigherThan, LowerThan and&#xA;UnequalTo types do not ship with the crate) by implementing the Filter&#xA;trait:&#xA;&#xA;struct LowerThan(u64);&#xA;impl Filteru64 for LowerThan {&#xA;  fn filter(&amp;self, elem: &amp;u64) -  bool {&#xA;    elem &lt; self.0&#xA;  }&#xA;}&#xA;&#xA;What are we going to do?&#xA;&#xA;What we&#39;re going to do is rather easy. We want a functionality implemented on&#xA;all iterator types which gives us the possibility to pass an object for&#xA;filtering rather than writing down this nasty closure (as shown above):&#xA;&#xA;iterator.filter(|e| filter.filter(&amp;e))&#xA;&#xA;We want to write:&#xA;&#xA;iterator.filterwith(somefilter)&#xA;&#xA;And we want to get back a nice iterator type.&#xA;&#xA;Step 1: A type&#xA;&#xA;First, we need a type representing a iterator which is filtered. This type, of&#xA;course, has to be abstract over the actual iterator we want to filter (that&#39;s&#xA;also how the rust standard library does this under the hood).&#xA;The type also has to be generic over the filter in use.&#xA;So basically we write down an entirely generic type:&#xA;&#xA;pub struct FilteredIteratorT, F, I(F, I)&#xA;    where F: FilterT,&#xA;          I: IteratorItem = T;&#xA;&#xA;Here F is a filter over T and I is the iterator over T. The&#xA;FilteredIterator holds both F and I.&#xA;&#xA;Step 2: Implement Iterator on this type&#xA;&#xA;The next step is implementing iterator on this new type.&#xA;Because we want to use this iterator in a chain like this, for example:&#xA;&#xA;forest&#xA;    .filteredwith(TreeWithColor::new(Color::Green))&#xA;    .map(|tree| tree.getname())&#xA;    .enumerate()&#xA;    .map(|(i, treename)| {&#xA;      storetreenumber(treename, i)&#xA;    })&#xA;    .fold(Ok(()), |acc, e| {&#xA;      // ...&#xA;    })&#xA;&#xA;we have to implement Iterator on it.&#xA;&#xA;Because the type is generic, so is our iterator implementation.&#xA;&#xA;implT, F, I Iterator for FilteredIteratorT, F, I&#xA;    where F: FilterT,&#xA;          I: IteratorItem = T&#xA;{&#xA;    type Item = T;&#xA;&#xA;    fn next(&amp;mut self) -  OptionSelf::Item {&#xA;        // ...&#xA;    }&#xA;}&#xA;&#xA;The implementation is left out as task for the reader. Hint: The only function&#xA;one needs is Filter::filter() and a while let Some(e).&#xA;&#xA;Step 3: Transforming one iterator into a filtered iterator&#xA;&#xA;Next, we want to be able to transform an existing iterator type into a&#xA;filtered iterator.&#xA;As I wrote above, we do this by providing a new trait for this.&#xA;Because of the generic parameters our FilteredIterator type has, we need&#xA;generic types in our trait as well:&#xA;&#xA;pub trait FilterWithT, F: Filter&lt;T  : IteratorItem = T + Sized {&#xA;    fn filterwith(self, f: F) -  FilteredIteratorT, F, Self;&#xA;}&#xA;&#xA;The trait provides only one function: filterwith(). This function takes&#xA;self owning and a Filter which is used in the FilteredIterator later.&#xA;&#xA;Step 4: Extending all iterators&#xA;&#xA;Last but not least, we implement this trait on all Iterators.&#xA;Even more generics here, of course:&#xA;&#xA;implI, T, F: Filter&lt;T  FilterWithT, F for I&#xA;    where I: IteratorItem = T&#xA;{&#xA;    fn filterwith(self, f: F) -  FilteredIteratorT, F, Self {&#xA;        FilteredIterator(f, self)&#xA;    }&#xA;}&#xA;&#xA;The actual implementation is trivial, sure. But the type signature is not, so&#xA;I&#39;ll explain.&#xA;&#xA;I is the type we implement the FilterWith trait for. Because we want to&#xA;   implement it for all iterators, we have to use a generic type.&#xA;I is, of course, generic itself. We want to be able to filter all&#xA;   iterators over all types. So, T is the Item of the Iterator.&#xA;F is needed because FilterWith is generic over the provided filter: We&#xA;   can filter with any Filter we want. So we have to be generic over that as&#xA;   well.&#xA;&#xA;The output of the filterwith function is a FilteredIterator which is&#xA;generic over T and F - but wait! FilteredIterator is generic over three&#xA;types!&#xA;&#xA;That&#39;s true. But the third generic type is the iterator it encapsulated - the&#xA;iterator it actually filters. Because of that, we return `FilteredIterator&lt;T,&#xA;F, Self  ` here - we don&#39;t need a generic type as third type here because we&#xA;know that the iterator which will be encapsulated has exactly the type which&#xA;the trait gets currently implemented for.&#xA;&#xA;(I hope that explanation is easy to understand.)&#xA;&#xA;Conclusion&#xA;&#xA;Extending types in Rust is incredible easy - if one can grok generics. I know&#xA;that generics are not that easy to grok for a beginner - I had a hard time&#xA;learning how to use them myself. But it is really worth it, as our test shows:&#xA;&#xA;[test]&#xA;fn testfilterwith() {&#xA;    struct Foo;&#xA;    impl Filteru64 for Foo {&#xA;        fn filter(&amp;self, u: &amp;u64) -  bool {&#xA;            u   5&#xA;        }&#xA;    }&#xA;    let foo = Foo;&#xA;&#xA;    let v : Vecu64 = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 0]&#xA;        .intoiter()&#xA;        .filterwith(foo)&#xA;        .collect();&#xA;&#xA;    assert_eq!(v, vec![6, 7, 8, 9]);&#xA;}&#xA;&#xA;tags:  #tools #software #rust #open-source&#xA;]]&gt;</description>
      <content:encoded><![CDATA[<p>A common thing one has to do in Rust to leverage zero-cost abstractions and
convenience is to <em>extend</em> types.
By “extending” them I mean adding functionality (functions) to the type which
make it more convenient to use and “improve” it for the domain at hand.</p>

<p>From time to time, one needs to extend generic types, which is a difficult
thing to do. Especially when it comes to iterators, where extending is often
tricky.</p>

<p>That&#39;s why I want to write some notes on it down.</p>

<h1 id="how-do-filters-work" id="how-do-filters-work">How do filters work?</h1>

<p>I have this crate called “filters” which offers nice functionality for
building predicates with the builder pattern.
A predicate is nothing more than a function which takes something by reference
and returns a boolean for it:</p>

<pre><code>fn(&amp;self, some: &amp;Thing) -&gt; bool;
</code></pre>

<p>The function is now allowed to decide whether the <code>Thing</code> shall be used. This
is useful when working with iterators:</p>

<pre><code>let filter = LowerThan::new(5);
vec![1,2,3,4,5,6,7,8,9].iter().filter(|e| filter.filter(&amp;e)).collect()
</code></pre>

<p>Filters can, as I mentioned, be build with the builder-pattern:</p>

<pre><code>let filter = HigherThan::new(5)
    .and(LowerThan::new(20))
    .and(UnequalTo::new(15));

vec![1,2,3,4,5,6,7,8,9].iter().filter(|e| filter.filter(&amp;e)).collect()
</code></pre>

<p>One can also define own filters (in fact, the <code>HigherThan</code>, <code>LowerThan</code> and
<code>UnequalTo</code> types do not ship with the crate) by implementing the <code>Filter</code>
trait:</p>

<pre><code>struct LowerThan(u64);
impl Filter&lt;u64&gt; for LowerThan {
  fn filter(&amp;self, elem: &amp;u64) -&gt; bool {
    *elem &lt; self.0
  }
}
</code></pre>

<h1 id="what-are-we-going-to-do" id="what-are-we-going-to-do">What are we going to do?</h1>

<p>What we&#39;re going to do is rather easy. We want a functionality implemented on
<em>all</em> iterator types which gives us the possibility to pass an object for
filtering rather than writing down this nasty closure (as shown above):</p>

<pre><code>iterator.filter(|e| filter.filter(&amp;e))
</code></pre>

<p>We want to write:</p>

<pre><code>iterator.filter_with(some_filter)
</code></pre>

<p>And we want to get back a nice iterator type.</p>

<h1 id="step-1-a-type" id="step-1-a-type">Step 1: A type</h1>

<p>First, we need a type representing a iterator which is filtered. This type, of
course, has to be abstract over the actual iterator we want to filter (that&#39;s
also how the rust standard library does this under the hood).
The type also has to be generic over the filter in use.
So basically we write down an entirely generic type:</p>

<pre><code>pub struct FilteredIterator&lt;T, F, I&gt;(F, I)
    where F: Filter&lt;T&gt;,
          I: Iterator&lt;Item = T&gt;;
</code></pre>

<p>Here <code>F</code> is a filter over <code>T</code> and <code>I</code> is the iterator over <code>T</code>. The
<code>FilteredIterator</code> holds both <code>F</code> and <code>I</code>.</p>

<h1 id="step-2-implement-iterator-on-this-type" id="step-2-implement-iterator-on-this-type">Step 2: Implement Iterator on this type</h1>

<p>The next step is implementing iterator on this new type.
Because we want to use this iterator in a chain like this, for example:</p>

<pre><code>forest
    .filtered_with(TreeWithColor::new(Color::Green))
    .map(|tree| tree.get_name())
    .enumerate()
    .map(|(i, tree_name)| {
      store_tree_number(tree_name, i)
    })
    .fold(Ok(()), |acc, e| {
      // ...
    })
</code></pre>

<p>we have to implement <code>Iterator</code> on it.</p>

<p>Because the type is generic, so is our iterator implementation.</p>

<pre><code>impl&lt;T, F, I&gt; Iterator for FilteredIterator&lt;T, F, I&gt;
    where F: Filter&lt;T&gt;,
          I: Iterator&lt;Item = T&gt;
{
    type Item = T;

    fn next(&amp;mut self) -&gt; Option&lt;Self::Item&gt; {
        // ...
    }
}
</code></pre>

<p>The implementation is left out as task for the reader. Hint: The only function
one needs is <code>Filter::filter()</code> and a <code>while let Some(e)</code>.</p>

<h1 id="step-3-transforming-one-iterator-into-a-filtered-iterator" id="step-3-transforming-one-iterator-into-a-filtered-iterator">Step 3: Transforming one iterator into a filtered iterator</h1>

<p>Next, we want to be able to transform an existing iterator type into a
filtered iterator.
As I wrote above, we do this by providing a new trait for this.
Because of the generic parameters our <code>FilteredIterator</code> type has, we need
generic types in our trait as well:</p>

<pre><code>pub trait FilterWith&lt;T, F: Filter&lt;T&gt;&gt; : Iterator&lt;Item = T&gt; + Sized {
    fn filter_with(self, f: F) -&gt; FilteredIterator&lt;T, F, Self&gt;;
}
</code></pre>

<p>The trait provides only one function: <code>filter_with()</code>. This function takes
<code>self</code> owning and a <code>Filter</code> which is used in the <code>FilteredIterator</code> later.</p>

<h1 id="step-4-extending-all-iterators" id="step-4-extending-all-iterators">Step 4: Extending all iterators</h1>

<p>Last but not least, we implement this trait on all <code>Iterator</code>s.
Even more generics here, of course:</p>

<pre><code>impl&lt;I, T, F: Filter&lt;T&gt;&gt; FilterWith&lt;T, F&gt; for I
    where I: Iterator&lt;Item = T&gt;
{
    fn filter_with(self, f: F) -&gt; FilteredIterator&lt;T, F, Self&gt; {
        FilteredIterator(f, self)
    }
}
</code></pre>

<p>The actual implementation is trivial, sure. But the type signature is not, so
I&#39;ll explain.</p>
<ol><li><code>I</code> is the type we implement the <code>FilterWith</code> trait for. Because we want to
implement it for <em>all</em> iterators, we have to use a generic type.</li>
<li><code>I</code> is, of course, generic itself. We want to be able to filter all
iterators over <em>all</em> types. So, <code>T</code> is the <code>Item</code> of the Iterator.</li>
<li><code>F</code> is needed because <code>FilterWith</code> is generic over the provided filter: We
can filter with any Filter we want. So we have to be generic over that as
well.</li></ol>

<p>The output of the <code>filter_with</code> function is a <code>FilteredIterator</code> which is
generic over <code>T</code> and <code>F</code> – but wait! <code>FilteredIterator</code> is generic over three
types!</p>

<p>That&#39;s true. But the third generic type is the iterator it encapsulated – the
iterator it actually filters. Because of that, we return <code>FilteredIterator&lt;T,
F, Self&gt;</code> here – we don&#39;t need a generic type as third type here because we
know that the iterator which will be encapsulated has exactly the type which
the trait gets currently implemented for.</p>

<p>(I hope that explanation is easy to understand.)</p>

<h1 id="conclusion" id="conclusion">Conclusion</h1>

<p>Extending types in Rust is incredible easy – if one can grok generics. I know
that generics are not that easy to grok for a beginner – I had a hard time
learning how to use them myself. But it is really worth it, as our test shows:</p>

<pre><code>#[test]
fn test_filter_with() {
    struct Foo;
    impl Filter&lt;u64&gt; for Foo {
        fn filter(&amp;self, u: &amp;u64) -&gt; bool {
            *u &gt; 5
        }
    }
    let foo = Foo;

    let v : Vec&lt;u64&gt; = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
        .into_iter()
        .filter_with(foo)
        .collect();

    assert_eq!(v, vec![6, 7, 8, 9]);
}
</code></pre>

<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:rust" class="hashtag"><span>#</span><span class="p-category">rust</span></a> <a href="https://beyermatthias.de/tag:open" class="hashtag"><span>#</span><span class="p-category">open</span></a>-source</p>
]]></content:encoded>
      <guid>https://beyermatthias.de/extending-an-iterator-in-rust</guid>
      <pubDate>Fri, 02 Feb 2018 16:38:56 +0100</pubDate>
    </item>
    <item>
      <title>Maybe it&#39;s time for a crates team</title>
      <link>https://beyermatthias.de/maybe-its-time-for-a-crates-team</link>
      <description>&lt;![CDATA[After reading another post in the users.rust-lang.org forum where a crate&#xA;author is looking for a maintainer for his crate, I started thinking.&#xA;Do we need a &#34;crates-team&#34; in the rust community?&#xA;&#xA;Incentive&#xA;&#xA;The Rust community has a lot of great teams.&#xA;Each of these teams has a different goal: The Core team, for example&#xA;&#xA;  is responsible for steering the design and development process, overseeing the&#xA;  introduction of new features, and ultimately making decisions for which there&#xA;  is no consensus [...]&#xA;&#xA;(source)&#xA;&#xA;Because people change, interests of people change and also because the&#xA;life-situations people are in change, a crate author might not be able to&#xA;continue maintaining their crates.&#xA;I, for one, have such a problem: I am about to go on a really long vacation&#xA;from may 2018 until early 2019. Most of that time I will be off the grid, in a&#xA;mobile home in northern America. This is a one-time opportunity for me and I&#xA;am really looking forward to that experience.&#xA;But because of that I will have issues maintaining my crates in that time.&#xA;I have 7 projects where I cannot continue development for about one year:&#xA;&#xA;toml-query&#xA;filters&#xA;kairos&#xA;task-hookrs&#xA;git-dit (and libgitdit)&#xA;is-match&#xA;&#xA;and of course imag, which contains over 40 crates at the time of writing.&#xA;All of the above are ready to be used (imag is not) and are, in fact, used by&#xA;others from what I know.&#xA;&#xA;In my case, this is only temporarily: I will be able (and am willing to)&#xA;continue development on them in 2019. But people change, interests change,&#xA;people get kids, a dog or some new hobby.&#xA;The end result is always: They have less time (or no time anymore) to continue&#xA;developing their crates.&#xA;&#xA;So why not have a team available which takes over maintainership?&#xA;&#xA;What a crates-team would do&#xA;&#xA;The crates-team won&#39;t always be able to continue development of the crate,&#xA;but it might be able to continue maintainership.&#xA;That is: Merge pull requests which add new functionality (or even just discuss&#xA;whether this new functionality would be a nice addition to the crate), update&#xA;the dependencies from time to time, fix and close bugs in the codebase,&#xA;update the documentation and document known bugs.&#xA;&#xA;The team would consist of people from the community (so basically hobbyists)&#xA;which are willing to maintain a few crates in their free time.&#xA;The crates-team would, of course, not take over maintainership for all&#xA;abandoned crates. It would rather discuss whether a crate shall be maintained&#xA;by them and then do so (or not).&#xA;&#xA;Some ideas on basic rules for the team:&#xA;&#xA;Only the following things are in the scope of &#34;maintaining&#34; a crate in the&#xA;  crates-team:&#xA;    Update the dependencies to the newest version if and only if updating&#xA;      to the newest version is as simple as updating the version number in the&#xA;      Cargo.toml file. If it is more complicated, the crates-team is allowed&#xA;      to reject any requests or reply to such requests with a variant of the&#xA;      phrase &#34;You&#39;re welcome to file an PR for this!&#34;&#xA;    Updating the documentation of a crate&#xA;    Publish new versions of the crate, the first newly published version&#xA;      should change the cargo metainformation maintenance = ... to&#xA;      passively-maintained.&#xA;    Discuss and (if consensus is reached) merge pull requests which add new&#xA;      functionality to the crate&#xA;    Merge pull requests which&#xA;        Fix bugs&#xA;        Update dependencies&#xA;        Update documentation&#xA;A crate only gets maintained if at least 2 members of the crates-team are&#xA;  willing to maintain the crate (these two get rights to publish new versions)&#xA;&#xA;More rules are possible, of course.&#xA;&#xA;Discussion&#xA;&#xA;I&#39;d love to discuss the subject on either&#xA;users.rust-lang.org&#xA;or&#xA;reddit!&#xA;&#xA;Also, feel free to reach out via mail (the thing which looks like an &#39;a&#39;)&#xA;(thisdomain) (dot) de.&#xA;&#xA;tags:  #tools #software #rust #open-source&#xA;]]&gt;</description>
      <content:encoded><![CDATA[<p>After reading another post in the users.rust-lang.org forum where a crate
author is looking for a maintainer for his crate, I started thinking.
Do we need a “crates-team” in the rust community?</p>

<h1 id="incentive" id="incentive">Incentive</h1>

<p>The Rust community has a lot of great teams.
Each of these teams has a different goal: The Core team, for example</p>

<blockquote><p>is responsible for steering the design and development process, overseeing the
introduction of new features, and ultimately making decisions for which there
is no consensus [...]</p></blockquote>

<p>(<a href="https://www.rust-lang.org/en-US/community.html">source</a>)</p>

<p>Because people change, interests of people change and also because the
life-situations people are in change, a crate author might not be able to
continue maintaining their crates.
I, for one, have such a problem: I am about to go on a <em>really</em> long vacation
from may 2018 until early 2019. Most of that time I will be off the grid, in a
mobile home in northern America. This is a one-time opportunity for me and I
am really looking forward to that experience.
But because of that I will have issues maintaining my crates in that time.
I have 7 projects where I cannot continue development for about one year:</p>
<ul><li>toml-query</li>
<li>filters</li>
<li>kairos</li>
<li>task-hookrs</li>
<li>git-dit (and libgitdit)</li>
<li>is-match</li></ul>

<p>and of course imag, which contains over 40 crates at the time of writing.
All of the above are ready to be used (imag is not) and are, in fact, used by
others from what I know.</p>

<p>In my case, this is only temporarily: I will be able (and am willing to)
continue development on them in 2019. But people change, interests change,
people get kids, a dog or some new hobby.
The end result is always: They have less time (or no time anymore) to continue
developing their crates.</p>

<p>So why not have a team available which takes over maintainership?</p>

<h1 id="what-a-crates-team-would-do" id="what-a-crates-team-would-do">What a crates-team would do</h1>

<p>The crates-team won&#39;t always be able to continue <em>development</em> of the crate,
but it might be able to continue <em>maintainership</em>.
That is: Merge pull requests which add new functionality (or even just discuss
whether this new functionality would be a nice addition to the crate), update
the dependencies from time to time, fix and close bugs in the codebase,
update the documentation and document known bugs.</p>

<p>The team would consist of people from the community (so basically hobbyists)
which are willing to maintain a few crates in their free time.
The crates-team would, of course, not take over maintainership for all
abandoned crates. It would rather discuss whether a crate shall be maintained
by them and then do so (or not).</p>

<p>Some ideas on basic rules for the team:</p>
<ul><li>Only the following things are in the scope of “maintaining” a crate in the
crates-team:
<ul><li>Update the dependencies to the newest version <strong>if and only if</strong> updating
to the newest version is as simple as updating the version number in the
<code>Cargo.toml</code> file. If it is more complicated, the crates-team is allowed
to reject any requests or reply to such requests with a variant of the
phrase “You&#39;re welcome to file an PR for this!”</li>
<li>Updating the documentation of a crate</li>
<li>Publish new versions of the crate, the first newly published version
should change the cargo metainformation <code>maintenance = ...</code> to
<code>passively-maintained</code>.</li>
<li>Discuss and (if consensus is reached) merge pull requests which add new
functionality to the crate</li>
<li>Merge pull requests which
<ul><li>Fix bugs</li>
<li>Update dependencies</li>
<li>Update documentation</li></ul></li></ul></li>
<li>A crate only gets maintained if at least 2 members of the crates-team are
willing to maintain the crate (these two get rights to publish new versions)</li></ul>

<p>More rules are possible, of course.</p>

<h1 id="discussion" id="discussion">Discussion</h1>

<p>I&#39;d love to discuss the subject on either
<a href="https://users.rust-lang.org/t/maybe-its-time-for-a-crates-team/15291">users.rust-lang.org</a>
or
<a href="https://www.reddit.com/r/rust/comments/7tcux6/maybe_its_time_for_a_crates_team_blogpost/">reddit</a>!</p>

<p>Also, feel free to reach out via mail (the thing which looks like an &#39;a&#39;)
(thisdomain) (dot) de.</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:rust" class="hashtag"><span>#</span><span class="p-category">rust</span></a> <a href="https://beyermatthias.de/tag:open" class="hashtag"><span>#</span><span class="p-category">open</span></a>-source</p>
]]></content:encoded>
      <guid>https://beyermatthias.de/maybe-its-time-for-a-crates-team</guid>
      <pubDate>Sat, 27 Jan 2018 16:38:52 +0100</pubDate>
    </item>
  </channel>
</rss>