<?xml version="1.0"?>
<rss version="2.0">
  <channel>
    <title>SoftwarePhilosophy</title>
    <description>SoftwarePhilosophy</description>
    <link>http://softwarephilosophy.ninja</link>
    <pubDate>2019-08-13</pubDate>
    <item>
      <title>Literate programming really works for tutorials</title>
      <link>http://softwarephilosophy.ninja/literate-programming-really-works-for-tutorials</link>
      <pubDate>2016-09-19</pubDate>
      <description>&lt;p&gt;Have you&amp;nbsp;heard about literate programming? It&amp;#39;s a&amp;nbsp;technique that lets you&amp;nbsp;write a&amp;nbsp;computer program
the&amp;nbsp;same way&amp;nbsp;as&amp;nbsp;if&amp;nbsp;you&amp;nbsp;were writing a&amp;nbsp;piece of&amp;nbsp;literature. And&amp;nbsp;while it&amp;nbsp;may&amp;nbsp;seem exotic
and&amp;nbsp;unnecessary, there are&amp;nbsp;some cases when it&amp;#39;s quite useful. I&amp;nbsp;believe I&amp;nbsp;have found
one&amp;nbsp;of&amp;nbsp;them. In&amp;nbsp;this post, I&amp;nbsp;will describe a&amp;nbsp;solution for&amp;nbsp;writing a&amp;nbsp;tutorial in&amp;nbsp;the&amp;nbsp;spirit
of&amp;nbsp;literate programming by&amp;nbsp;using nodejs-based, language-agnostic, literate programming tool.&lt;/p&gt;

&lt;h2 id="toc_0"&gt;Background&lt;/h2&gt;

&lt;p&gt;Literate programming is&amp;nbsp;a&amp;nbsp;technique of&amp;nbsp;writing computer programs in&amp;nbsp;natural (spoken) language.
When using this technique, documentation receives most of&amp;nbsp;programmers attention while code is&amp;nbsp;treated as&amp;nbsp;a&amp;nbsp;formality. Code snippets are&amp;nbsp;typically embedded in&amp;nbsp;the&amp;nbsp;essay and&amp;nbsp;get&amp;nbsp;extracted for&amp;nbsp;compilation during project build.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The&amp;nbsp;main idea is&amp;nbsp;to&amp;nbsp;regard a&amp;nbsp;program as&amp;nbsp;a&amp;nbsp;communication to&amp;nbsp;human beings rather than as&amp;nbsp;a&amp;nbsp;set&amp;nbsp;of&amp;nbsp;instructions to&amp;nbsp;a&amp;nbsp;computer.&lt;/p&gt;

&lt;p&gt;~ &lt;a href="http://www-cs-faculty.stanford.edu/%7Euno/cweb.html"&gt;The&amp;nbsp;CWEB System of&amp;nbsp;Structured Documentation&lt;/a&gt; by&amp;nbsp;Donald E. Knuth and&amp;nbsp;Silvio Levy&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;First literate programming tool, developed by&amp;nbsp;Donald Knuth, was&amp;nbsp;called &lt;a href="https://en.wikipedia.org/wiki/WEB"&gt;WEB&lt;/a&gt; and&amp;nbsp;worked with
&lt;a href="https://en.wikipedia.org/wiki/Pascal_programming_language"&gt;Pascal&lt;/a&gt; only. Short after, Knuth developed CWEB, which is&amp;nbsp;WEB&amp;nbsp;for&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/C_(programming_language)"&gt;C&amp;nbsp;language&lt;/a&gt;.
In&amp;nbsp;response to&amp;nbsp;WEB, Norman Ramsey created &lt;a href="https://en.wikipedia.org/wiki/Noweb"&gt;noweb&lt;/a&gt;&amp;mdash;a&amp;nbsp;literate programming tool
compatible with any&amp;nbsp;programming language. It&amp;nbsp;started a&amp;nbsp;language-agnosticity trend in&amp;nbsp;the&amp;nbsp;field.&lt;/p&gt;

&lt;h2 id="toc_1"&gt;Research&lt;/h2&gt;

&lt;p&gt;So, I&amp;nbsp;was&amp;nbsp;faced with a&amp;nbsp;task of&amp;nbsp;writing a&amp;nbsp;tutorial on&amp;nbsp;using &lt;a href="https://github.com/mchalapuk/hyper-text-slider"&gt;hyper-text-slider&lt;/a&gt; with &lt;a href="https://nodejs.org/en/"&gt;node&lt;/a&gt;
and&amp;nbsp;&lt;a href="https://github.com/substack/node-browserify"&gt;browserify&lt;/a&gt;. Since I&amp;nbsp;have this habit of&amp;nbsp;making my&amp;nbsp;life more exciting, and&amp;nbsp;since
writing a&amp;nbsp;tutorial is&amp;nbsp;an&amp;nbsp;inherently dull task, I&amp;nbsp;started thinking.
From this thinking emerged a&amp;nbsp;question&amp;#8203;&amp;mdash;Is&amp;nbsp;it&amp;nbsp;possible to&amp;nbsp;automatically test
a&amp;nbsp;tutorial?&lt;/p&gt;

&lt;p&gt;After few&amp;nbsp;minutes of&amp;nbsp;Googling around, I&amp;nbsp;had&amp;nbsp;my&amp;nbsp;answer&amp;mdash;literate programming.&lt;/p&gt;

&lt;p&gt;HyperText Slider is&amp;nbsp;a&amp;nbsp;web&amp;nbsp;slideshow component that utilizes CSS3 transitions to&amp;nbsp;control background
and&amp;nbsp;foreground animations of&amp;nbsp;changes between slides. It&amp;nbsp;has&amp;nbsp;declarative (HTML-only) API&amp;nbsp;which is&amp;nbsp;very easy to&amp;nbsp;use, and&amp;nbsp;JavaScript API&amp;nbsp;for&amp;nbsp;fine-grained control.
Using hyper&amp;#8209;text&amp;#8209;slider with node and&amp;nbsp;browserify means using a&amp;nbsp;node-base
build system for&amp;nbsp;front-end technology stack (HTML, CSS&amp;nbsp;and&amp;nbsp;JavaScript).
I&amp;nbsp;needed a&amp;nbsp;literate programming solution that supports front-end stuff and&amp;nbsp;has&amp;nbsp;a&amp;nbsp;plugin
for&amp;nbsp;&lt;a href="https://github.com/gulpjs/gulp"&gt;gulp&lt;/a&gt; (my&amp;nbsp;build utility of&amp;nbsp;choice for&amp;nbsp;node-based projects).&lt;/p&gt;

&lt;p&gt;As&amp;nbsp;it&amp;nbsp;turns out, number of&amp;nbsp;literate programming solutions for&amp;nbsp;JavaScript in&amp;nbsp;suprisingly big&amp;nbsp;(&lt;code&gt;npm&amp;nbsp;search literate&lt;/code&gt; gives 288 results).
I&amp;nbsp;really disliked &lt;a href="https://jashkenas.github.io/docco/"&gt;docco&lt;/a&gt; which seemed to&amp;nbsp;be&amp;nbsp;the&amp;nbsp;most popular one.
It&amp;nbsp;was&amp;nbsp;advertized as&amp;nbsp;quick and&amp;nbsp;dirty yet&amp;nbsp;it&amp;nbsp;was&amp;nbsp;still too&amp;nbsp;complicated for&amp;nbsp;my&amp;nbsp;taste.
After trying a&amp;nbsp;few, I&amp;nbsp;ended up&amp;nbsp;choosing &lt;a href="https://github.com/satchmorun/writ"&gt;writ&lt;/a&gt;.
It&amp;nbsp;does only one&amp;nbsp;thing&amp;mdash;extracts any&amp;nbsp;code from &lt;a href="http://daringfireball.net/projects/markdown/"&gt;Markdown&lt;/a&gt;
(with very basic support for&amp;nbsp;macro-definitions).&lt;/p&gt;

&lt;h2 id="toc_2"&gt;Solution&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Documentation (tutorial), human-written, contains snippets of&amp;nbsp;code needed
for&amp;nbsp;a&amp;nbsp;website to&amp;nbsp;be&amp;nbsp;built.
It&amp;nbsp;is&amp;nbsp;a&amp;nbsp;single source of&amp;nbsp;information (actual sources).
Tutorial is&amp;nbsp;written in&amp;nbsp;markdown and&amp;nbsp;hosted on&amp;nbsp;&lt;a href="https://github.com/"&gt;Github&lt;/a&gt;
which automatically renders markdown files into nice HTML documents.&lt;/li&gt;
&lt;li&gt;Code snippets are&amp;nbsp;extracted from the&amp;nbsp;documentation by&amp;nbsp;invoking &lt;a href="https://github.com/satchmorun/writ"&gt;writ&lt;/a&gt;
from a&amp;nbsp;&lt;a href="https://github.com/gulpjs/gulp"&gt;gulp&lt;/a&gt; script. Writ produces one&amp;nbsp;output file for&amp;nbsp;each markdown file,
so&amp;nbsp;the&amp;nbsp;tutorial must have been divided into multiple pages&amp;mdash;3 source files
(HTML, Sass and&amp;nbsp;JavaScript), a&amp;nbsp;shell script that sets up&amp;nbsp;the&amp;nbsp;project,
and&amp;nbsp;a&amp;nbsp;gulpfile that builds generated sources.
There actually are&amp;nbsp;2 gulpfiles in&amp;nbsp;the&amp;nbsp;project.
First that invokes writ (human-written), second that builds the&amp;nbsp;project (generated).
Extracted JavaScript and&amp;nbsp;Sass code is&amp;nbsp;linted by&amp;nbsp;invoking linter plugins after writ.
All&amp;nbsp;generated sources are&amp;nbsp;checked into the&amp;nbsp;source control so&amp;nbsp;that the&amp;nbsp;project
can&amp;nbsp;be&amp;nbsp;cloned and&amp;nbsp;built.&lt;/li&gt;
&lt;li&gt;Project is&amp;nbsp;built by&amp;nbsp;invoking gulpfile script which was&amp;nbsp;extracted from the&amp;nbsp;documentation.
Building process produces browser-runnable files (HTML, CSS, JavaScript),
which are&amp;nbsp;also checked into the&amp;nbsp;source control. &lt;a href="https://pages.github.com/"&gt;Github Pages&lt;/a&gt; is&amp;nbsp;active
with master branch set&amp;nbsp;as&amp;nbsp;source so&amp;nbsp;that compiled project can&amp;nbsp;be&amp;nbsp;run&amp;nbsp;in&amp;nbsp;the&amp;nbsp;browser.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This way, I&amp;#39;m killing three birds with one&amp;nbsp;stone. The&amp;nbsp;project is:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A&amp;nbsp;tutorial on&amp;nbsp;creating a&amp;nbsp;web&amp;nbsp;slideshow using hyper-text-slider, node and&amp;nbsp;browserify,&lt;/li&gt;
&lt;li&gt;An&amp;nbsp;example project which can&amp;nbsp;be&amp;nbsp;cloned and&amp;nbsp;compiled,&lt;/li&gt;
&lt;li&gt;A&amp;nbsp;website which shows live results of&amp;nbsp;the&amp;nbsp;compilation.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id="toc_3"&gt;Configuring Writ&lt;/h3&gt;

&lt;p&gt;There are&amp;nbsp;two&amp;nbsp;gulpfiles in&amp;nbsp;the&amp;nbsp;project. Generated one&amp;nbsp;has&amp;nbsp;the&amp;nbsp;default name (&lt;code&gt;gulpfile.js&lt;/code&gt;).
Handwritten one&amp;nbsp;must be&amp;nbsp;named differently (&lt;code&gt;.writ.gulpfile.js&lt;/code&gt;).&lt;/p&gt;

&lt;blockquote&gt;
&lt;h5 id="toc_4"&gt;NOTE&lt;/h5&gt;

&lt;p&gt;Below paragraphs require basic understanding of&amp;nbsp;gulp. If&amp;nbsp;you&amp;#39;re not&amp;nbsp;familiar with it,
please read &lt;a href="https://github.com/mchalapuk/hyper-text-slider-node-tutorial/blob/master/doc/2_gulpfile.js.md#2-build-configuration"&gt;Build Configuration chapter from the&amp;nbsp;tutorial&lt;/a&gt;. If&amp;nbsp;you&amp;nbsp;know gulp,
it&amp;nbsp;may&amp;nbsp;still be&amp;nbsp;useful to&amp;nbsp;read it&amp;nbsp;as&amp;nbsp;it&amp;nbsp;contains soure code of&amp;nbsp;generated gulpfile.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We&amp;nbsp;need &lt;code&gt;gulp&lt;/code&gt;, &lt;code&gt;gulp-util&lt;/code&gt;, &lt;code&gt;gulp-writ&lt;/code&gt;, &lt;code&gt;gulp-rename2&lt;/code&gt;, &lt;code&gt;gulp-eslint&lt;/code&gt;, &lt;code&gt;gulp-stylelint&lt;/code&gt;,
&lt;code&gt;merge-stream&lt;/code&gt; and&amp;nbsp;&lt;code&gt;del&lt;/code&gt; modules (they must be&amp;nbsp;installed with &lt;code&gt;npm&amp;nbsp;install&lt;/code&gt; in&amp;nbsp;order to&amp;nbsp;make
this gulpfile work).&lt;/p&gt;

&lt;pre&gt;&lt;code class="js"&gt;&amp;#39;use strict&amp;#39;;

var&amp;nbsp;gulp = require(&amp;#39;gulp&amp;#39;);
var&amp;nbsp;gutil = require(&amp;#39;gulp-util&amp;#39;);
var&amp;nbsp;writ = require(&amp;#39;gulp-writ&amp;#39;);
var&amp;nbsp;rename = require(&amp;#39;gulp-rename2&amp;#39;);
var&amp;nbsp;eslint = require(&amp;#39;gulp-eslint&amp;#39;);
var&amp;nbsp;stylelint = require(&amp;#39;gulp-stylelint&amp;#39;);
var&amp;nbsp;merge = require(&amp;#39;merge-stream&amp;#39;);
var&amp;nbsp;del&amp;nbsp;= require(&amp;#39;del&amp;#39;);
var&amp;nbsp;child = require(&amp;#39;child_process&amp;#39;);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The&amp;nbsp;project contains following folders:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;doc/&lt;/code&gt; containing the&amp;nbsp;tutorial,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;src/&lt;/code&gt; containing generated sources,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;dist/&lt;/code&gt; containing build output files (browser-comsumable).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As&amp;nbsp;it&amp;nbsp;will be&amp;nbsp;used as&amp;nbsp;a&amp;nbsp;dependency of&amp;nbsp;&lt;code&gt;generate&lt;/code&gt;, &lt;code&gt;clean&lt;/code&gt; task must be&amp;nbsp;defined first.
Deleting files with del&amp;nbsp;module requires using gulp in&amp;nbsp;asynchronuous mode
(task function has&amp;nbsp;a&amp;nbsp;callback which is&amp;nbsp;called by&amp;nbsp;del).
We&amp;nbsp;want to&amp;nbsp;delete all&amp;nbsp;files generated in&amp;nbsp;previous run&amp;nbsp;of&amp;nbsp;writ which
are&amp;nbsp;contained in&amp;nbsp;&lt;code&gt;src&lt;/code&gt; folder, but&amp;nbsp;without deleting the&amp;nbsp;folder itself.&lt;/p&gt;

&lt;pre&gt;&lt;code class="js"&gt;gulp.task(&amp;#39;clean&amp;#39;, function(callback) {
  return del([ &amp;#39;src/**/*&amp;#39;, &amp;#39;!src/&amp;#39; ], { force: true }, callback);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The&amp;nbsp;tutorial consists of&amp;nbsp;following files:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;doc/0_introduction.markdown&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;doc/1_setup.sh.md&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;doc/2_gulpfile.js.md&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;doc/3_script.js.md&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;doc/4_index.html.md&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;doc/5_style.scss.md&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;First file (&lt;code&gt;0_introduction.markdown&lt;/code&gt;) does not&amp;nbsp;contain any&amp;nbsp;code snippets
so&amp;nbsp;it&amp;nbsp;has&amp;nbsp;different extension. This way, it&amp;nbsp;is&amp;nbsp;still properly rendered on&amp;nbsp;Github
yet&amp;nbsp;not&amp;nbsp;catched by&amp;nbsp;writ&amp;#39;s glob pattern.&lt;/p&gt;

&lt;p&gt;Each file is&amp;nbsp;prefixed with a&amp;nbsp;number which indicates reading order of&amp;nbsp;the&amp;nbsp;tutorial.
Numbers also keep the&amp;nbsp;files properly ordered when listed on&amp;nbsp;Github.
&lt;code&gt;gulp-writ&lt;/code&gt; plugin removes &lt;code&gt;.md&lt;/code&gt; extension but&amp;nbsp;we&amp;nbsp;need to&amp;nbsp;use&amp;nbsp;&lt;code&gt;rename2&lt;/code&gt; in&amp;nbsp;order
to&amp;nbsp;remove number prefixes. &lt;code&gt;setup.sh&lt;/code&gt; and&amp;nbsp;&lt;code&gt;gulpfile.js&lt;/code&gt; will be&amp;nbsp;placed in&amp;nbsp;project main folder while all&amp;nbsp;generated sources will be&amp;nbsp;placed in&amp;nbsp;&lt;code&gt;/src&lt;/code&gt;.&lt;/p&gt;

&lt;pre&gt;&lt;code class="js"&gt;function removeNumberPrefix(pathObj, filePath) {
  return pathObj.dirname(filePath) +&amp;#39;/&amp;#39;+ pathObj.basename(filePath).replace(/^[0-9]+_/, &amp;#39;&amp;#39;);
}

gulp.task(&amp;#39;generate&amp;#39;, [ &amp;#39;clean&amp;#39; ], function() {
  var&amp;nbsp;sources = gulp.src([ &amp;#39;doc/*.md&amp;#39;, &amp;#39;!doc/*.sh.md&amp;#39;, &amp;#39;!doc/*gulpfile.js.md&amp;#39; ])
    .pipe(writ().on(&amp;#39;error&amp;#39;, gutil.log))
    .pipe(rename(removeNumberPrefix))
    .pipe(gulp.dest(&amp;#39;src/&amp;#39;))
  ;
  var&amp;nbsp;setupAndConfig = gulp.src([ &amp;#39;doc/*.sh.md&amp;#39;, &amp;#39;doc/*gulpfile.js.md&amp;#39; ])
    .pipe(writ().on(&amp;#39;error&amp;#39;, gutil.log))
    .pipe(rename(removeNumberPrefix))
    .pipe(gulp.dest(&amp;#39;.&amp;#39;))
  ;
  return merge(sources, setupAndConfig);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Generated sources are&amp;nbsp;ready to&amp;nbsp;be&amp;nbsp;linted.&lt;/p&gt;

&lt;pre&gt;&lt;code class="js"&gt;gulp.task(&amp;#39;lint:sass&amp;#39;, [ &amp;#39;generate&amp;#39; ], function() {
  return gulp.src([ &amp;#39;src/*.sass&amp;#39; ])
    .pipe(stylelint({
      reporters: [ { formatter: &amp;#39;string&amp;#39;, console: true } ],
    }))
  ;
});

gulp.task(&amp;#39;lint:javascript&amp;#39;, [ &amp;#39;generate&amp;#39; ], function() {
  return gulp.src([ &amp;#39;*.js&amp;#39;, &amp;#39;src/*.js&amp;#39; ])
    .pipe(eslint())
    .pipe(eslint.format())
    .pipe(eslint.failAfterError())
  ;
});

gulp.task(&amp;#39;lint&amp;#39;, [ &amp;#39;lint:sass&amp;#39;, &amp;#39;lint:javascript&amp;#39; ]);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Linted sources are&amp;nbsp;ready to&amp;nbsp;be&amp;nbsp;built. In&amp;nbsp;case of&amp;nbsp;this tutorial, building the&amp;nbsp;project
means invoking another &lt;code&gt;gulp&lt;/code&gt; process with generated gulpfile.&lt;/p&gt;

&lt;pre&gt;&lt;code class="js"&gt;gulp.task(&amp;#39;dist&amp;#39;, [ &amp;#39;lint&amp;#39; ], function() {
  child.execSync(&amp;#39;gulp&amp;#39;);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id="toc_5"&gt;Running Writ&lt;/h3&gt;

&lt;p&gt;Invoking &lt;code&gt;generate&lt;/code&gt; task extracts sources from the&amp;nbsp;tutorial.&lt;/p&gt;

&lt;pre&gt;&lt;code class="sh"&gt;gulp --gulpfile=.writ.gulpfile.js generate
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Invoking &lt;code&gt;dist&lt;/code&gt; task extracts sources, lints them and&amp;nbsp;builds the&amp;nbsp;project.&lt;/p&gt;

&lt;pre&gt;&lt;code class="sh"&gt;gulp --gulpfile=.writ.gulpfile.js dist
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Above command is&amp;nbsp;equal to&amp;nbsp;invoking &lt;code&gt;lint&lt;/code&gt; task and&amp;nbsp;then running gulp with generated gulpfile.&lt;/p&gt;

&lt;pre&gt;&lt;code class="sh"&gt;gulp --gulpfile=.writ.gulpfile.js list
gulp
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Invoking &lt;code&gt;dist&lt;/code&gt; task after changing the&amp;nbsp;documentation will propagate changes
into &lt;code&gt;src/&lt;/code&gt; and&amp;nbsp;&lt;code&gt;dist/&lt;/code&gt; folders. It&amp;nbsp;should be&amp;nbsp;invoked before each commit.&lt;/p&gt;

&lt;h2 id="toc_6"&gt;Wrap Up&lt;/h2&gt;

&lt;p&gt;After setting everything up, all&amp;nbsp;that remains is&amp;nbsp;writing the&amp;nbsp;tutorial.
It&amp;nbsp;will be&amp;nbsp;automatically tested in&amp;nbsp;a&amp;nbsp;sense that contained code snippets will be&amp;nbsp;linted
and&amp;nbsp;checked if&amp;nbsp;they compile successfully. Resulting program must still be&amp;nbsp;run&amp;nbsp;by&amp;nbsp;a&amp;nbsp;human,
but&amp;nbsp;it&amp;#39;s much less work than manually testing each step of&amp;nbsp;the&amp;nbsp;tutorial.&lt;/p&gt;

&lt;p&gt;Implementing a&amp;nbsp;&lt;code&gt;watch&lt;/code&gt; task would add&amp;nbsp;more automation into the&amp;nbsp;process
It&amp;#39;s there &lt;a href="https://github.com/mchalapuk/hyper-text-slider-node-tutorial/blob/master/.writ.gulpfile.js"&gt;in&amp;nbsp;my&amp;nbsp;tutorial&amp;#39;s &lt;code&gt;.writ.gulpfile.js&lt;/code&gt;&lt;/a&gt;,
but&amp;nbsp;as&amp;nbsp;it&amp;#39;s not&amp;nbsp;essential, I&amp;nbsp;haven&amp;#39;t include it&amp;nbsp;this blogpost.&lt;/p&gt;

&lt;p&gt;I&amp;nbsp;must say&amp;nbsp;that writing a&amp;nbsp;tutorial using literate programming was&amp;nbsp;an&amp;nbsp;exciting experience.
Writ is&amp;nbsp;a&amp;nbsp;great, simple tool for&amp;nbsp;literate programing in&amp;nbsp;Markdown. I&amp;nbsp;really recommend using it.
I&amp;#39;m curious of&amp;nbsp;your opinion on&amp;nbsp;literate programming and&amp;nbsp;writ. If&amp;nbsp;you&amp;nbsp;have any&amp;nbsp;thoughts
to&amp;nbsp;share or&amp;nbsp;questions to&amp;nbsp;ask, please do&amp;nbsp;in&amp;nbsp;the&amp;nbsp;comments below.&lt;/p&gt;

&lt;h2 id="toc_7"&gt;References&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="http://www.literateprogramming.com/"&gt;literateprogramming.com&lt;/a&gt; is&amp;nbsp;a&amp;nbsp;website that gathers literate-programming-related white
paper fragments,&lt;/li&gt;
&lt;li&gt;In&amp;nbsp;his&amp;nbsp;&lt;a href="http://www.literateprogramming.com/knuthweb.pdf"&gt;original paper on&amp;nbsp;literate programming&lt;/a&gt;, Donald Knuth describes first attempt
of&amp;nbsp;implementing this concept in&amp;nbsp;a&amp;nbsp;framework called &lt;a href="https://en.wikipedia.org/wiki/WEB"&gt;WEB&lt;/a&gt;,&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www-cs-faculty.stanford.edu/%7Euno/lp.html"&gt;Literate Programming&lt;/a&gt;&amp;mdash;a&amp;nbsp;book by&amp;nbsp;Donald Kunth&amp;mdash;contains a&amp;nbsp;collection of&amp;nbsp;his&amp;nbsp;papers on&amp;nbsp;this technique alongside some new&amp;nbsp;material,&lt;/li&gt;
&lt;li&gt;Cunningham &amp;amp; Cunningham Wiki contains an&amp;nbsp;interesting &lt;a href="http://c2.com/cgi/wiki?LiterateProgramming"&gt;discussion on&amp;nbsp;literate programming&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Haskell Wiki contains information on&amp;nbsp;how&amp;nbsp;to&amp;nbsp;do&amp;nbsp;&lt;a href="https://wiki.haskell.org/Literate_programming"&gt;literate programming by&amp;nbsp;using only Haskell&amp;#39;s
native features&lt;/a&gt;,&lt;/li&gt;
&lt;li&gt;Github Pages Help website contains information on&amp;nbsp;&lt;a href="https://help.github.com/articles/configuring-a-publishing-source-for-github-pages/"&gt;how&amp;nbsp;to&amp;nbsp;set&amp;nbsp;a&amp;nbsp;source branch for&amp;nbsp;Github Pages
in&amp;nbsp;your project&lt;/a&gt;,&lt;/li&gt;
&lt;li&gt;Tutorial described in&amp;nbsp;this blogpost is&amp;nbsp;&lt;a href="https://github.com/mchalapuk/hyper-text-slider-node-tutorial"&gt;hosted on&amp;nbsp;github&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;
</description>
    </item>
    <item>
      <title>Compile-Time Unit Testing</title>
      <link>http://softwarephilosophy.ninja/compile-time-unit-testing</link>
      <pubDate>2016-04-04</pubDate>
      <description>&lt;p&gt;These days, &lt;a href="https://en.wikipedia.org/wiki/Unit_testing"&gt;unit testing&lt;/a&gt; became a&amp;nbsp;major part of&amp;nbsp;software engineer&amp;#39;s work.
We&amp;nbsp;familiarized ourselves with unit testing frameworks based on&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/XUnit"&gt;xUnit&lt;/a&gt; architecture
(e.g. &lt;a href="https://en.wikipedia.org/wiki/JUnit"&gt;JUnit&lt;/a&gt;, &lt;a href="https://en.wikipedia.org/wiki/SUnit"&gt;SUnit&lt;/a&gt;) where tests are&amp;nbsp;executed during &lt;a href="https://en.wikipedia.org/wiki/Run_time_%28program_lifecycle_phase%29"&gt;run&amp;nbsp;time&lt;/a&gt; of&amp;nbsp;the&amp;nbsp;test program.
As&amp;nbsp;of&amp;nbsp;time of&amp;nbsp;this writing, it&amp;#39;s the&amp;nbsp;most popular way&amp;nbsp;of&amp;nbsp;testing in&amp;nbsp;an&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/Object-oriented_programming"&gt;object-oriented&lt;/a&gt;
environment.
Few&amp;nbsp;years ago, I&amp;nbsp;started using &lt;a href="https://en.wikipedia.org/wiki/Compile_time"&gt;compile-time&lt;/a&gt; unit testing in&amp;nbsp;my&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/C%2B%2B"&gt;C++&lt;/a&gt; experiments.
As&amp;nbsp;it&amp;nbsp;turned out&amp;nbsp;quite well, I&amp;nbsp;will try&amp;nbsp;to&amp;nbsp;share my&amp;nbsp;experience in&amp;nbsp;here. This article describes
reasons for&amp;nbsp;using compile-time unit testing, provides examples of&amp;nbsp;code that can&amp;nbsp;be&amp;nbsp;tested this way,
and&amp;nbsp;shows how&amp;nbsp;to&amp;nbsp;debug such tests.&lt;/p&gt;

&lt;blockquote&gt;
&lt;h4 id="toc_0"&gt;NOTE&lt;/h4&gt;

&lt;p&gt;Examples in&amp;nbsp;this article are&amp;nbsp;written in&amp;nbsp;C++, but&amp;nbsp;used terminology and&amp;nbsp;the&amp;nbsp;concept of&amp;nbsp;compile-time
unit testing applies to&amp;nbsp;many other statically-typed languages. All&amp;nbsp;examples should be&amp;nbsp;compilable
with gcc4.9. They can&amp;nbsp;be&amp;nbsp;found on&amp;nbsp;github in&amp;nbsp;&lt;a href="https://github.com/mchalapuk/static-tests"&gt;mchalapuk/static-tests&lt;/a&gt; repo.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id="toc_1"&gt;Static Binding&lt;/h3&gt;

&lt;p&gt;There are&amp;nbsp;two&amp;nbsp;ways of&amp;nbsp;binding values to&amp;nbsp;symbols in&amp;nbsp;C++ language&amp;mdash;&lt;a href="https://en.wikipedia.org/wiki/Name_binding"&gt;static (AKA&amp;nbsp;early)
binding&lt;/a&gt; and&amp;nbsp;dynamic (AKA&amp;nbsp;late) binding. To&amp;nbsp;make a&amp;nbsp;long story short&amp;mdash;a&amp;nbsp;(not&amp;nbsp;only) example
of&amp;nbsp;dynamic binding is&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/Dynamic_dispatch"&gt;method polymorphism&lt;/a&gt;, where pointer to&amp;nbsp;method&amp;#39;s implementation
is&amp;nbsp;resolved during program run&amp;nbsp;time (wich is&amp;nbsp;late). Static binding happens during compilation.
Value is&amp;nbsp;computed by&amp;nbsp;the&amp;nbsp;compiler and&amp;nbsp;inserted into the&amp;nbsp;output code instead of&amp;nbsp;a&amp;nbsp;computation
procedure.&lt;/p&gt;

&lt;p&gt;The&amp;nbsp;simplest example of&amp;nbsp;a&amp;nbsp;value that is&amp;nbsp;bound statically is&amp;nbsp;a&amp;nbsp;literal of&amp;nbsp;any&amp;nbsp;type.&lt;/p&gt;

&lt;pre&gt;&lt;code class="cpp"&gt;auto i&amp;nbsp;= 0; // zero is&amp;nbsp;statically bound (value is&amp;nbsp;known during the&amp;nbsp;compilation)
auto s&amp;nbsp;= &amp;quot;static binding&amp;quot;; // string literal is&amp;nbsp;statically bound
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;But&amp;nbsp;what makes static binding really powerful is&amp;nbsp;a&amp;nbsp;computation performed at&amp;nbsp;compile time.&lt;/p&gt;

&lt;pre&gt;&lt;code class="cpp"&gt;// Mathematical PI&amp;nbsp;constant.
// Literal of&amp;nbsp;type double is&amp;nbsp;bound statically.
const auto PI&amp;nbsp;= 3.141592L;

// Degrees to&amp;nbsp;radians convertion ratio.
// The&amp;nbsp;compiler will compute right-hand side expression and&amp;nbsp;replace it&amp;nbsp;with
// single value, because all&amp;nbsp;values used in&amp;nbsp;the&amp;nbsp;expression are&amp;nbsp;bound statically.
// This means that value of&amp;nbsp;DEG_2_RAD is&amp;nbsp;also bound statically.
const auto DEG_2_RAD = 2 * PI&amp;nbsp;/ 360;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Those examples are&amp;nbsp;just scratching the&amp;nbsp;surface of&amp;nbsp;static binding in&amp;nbsp;C++.&lt;/p&gt;

&lt;h3 id="toc_2"&gt;Constant Expressions&lt;/h3&gt;

&lt;p&gt;Since &lt;a href="http://en.cppreference.com/w/cpp/language/constexpr"&gt;C++11&lt;/a&gt; standard, we&amp;nbsp;have a&amp;nbsp;feature of&amp;nbsp;&lt;a href="http://en.cppreference.com/w/cpp/language/constexpr"&gt;constant expressions&lt;/a&gt; in&amp;nbsp;the&amp;nbsp;language.
It&amp;nbsp;extends the&amp;nbsp;posibilities of&amp;nbsp;static binding from simple expressions to&amp;nbsp;whole blocks of&amp;nbsp;code.&lt;/p&gt;

&lt;pre&gt;&lt;code class="cpp"&gt;// Function converting degrees into radians.
// Declared as&amp;nbsp;constant expression, which means that it&amp;nbsp;can&amp;nbsp;be&amp;nbsp;executed
// during the&amp;nbsp;compilation (the&amp;nbsp;code is&amp;nbsp;statically bound).
constexpr double deg2rad(double deg) {
  return deg&amp;nbsp;* DEG_2_RAD;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;There are&amp;nbsp;many requirements that a&amp;nbsp;function must meet to&amp;nbsp;be&amp;nbsp;a&amp;nbsp;valid constant
expression&lt;sup&gt;&lt;a href="#constexpr-requirements"&gt;1&lt;/a&gt;&lt;/sup&gt;. In&amp;nbsp;essence, blocks of&amp;nbsp;code declared as&amp;nbsp;constant expressions can&amp;nbsp;not&amp;nbsp;have any&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/Side_effect_%28computer_science%29"&gt;side effects&lt;/a&gt;. As&amp;nbsp;its&amp;nbsp;code is&amp;nbsp;statically bound, &lt;code&gt;deg2rad&lt;/code&gt; function can&amp;nbsp;be&amp;nbsp;tested during the&amp;nbsp;compilation.&lt;/p&gt;

&lt;p&gt;Writing compile-time unit tests is&amp;nbsp;quite easy since C++11 brougth &lt;a href="http://en.cppreference.com/w/cpp/language/static_assert"&gt;&lt;code&gt;static_assert&lt;/code&gt;&lt;/a&gt;
into the&amp;nbsp;game.
It&amp;nbsp;works the&amp;nbsp;same way&amp;nbsp;as&amp;nbsp;normal assertion but&amp;nbsp;with one&amp;nbsp;difference&amp;mdash;it&amp;nbsp;is&amp;nbsp;evaluated
during the&amp;nbsp;compilation. This implies that its&amp;nbsp;argument must be&amp;nbsp;a&amp;nbsp;constant expression.
If&amp;nbsp;expression doesn&amp;#39;t convert to&amp;nbsp;&lt;code&gt;true&lt;/code&gt;, compilation fails.&lt;/p&gt;

&lt;pre&gt;&lt;code class="cpp"&gt;#include &amp;lt;cmath&amp;gt;

// A&amp;nbsp;helper function for&amp;nbsp;comparing floating point numbers.
constexpr bool float_equals(double lhs, double rhs) {
  return std::abs(lhs&amp;nbsp;- rhs) &amp;lt; 0.00001L;
}

namespace deg2rad_tests {

static_assert(float_equals(3.141592L, deg2rad(180)), &amp;quot;deg2rad(180) == 3.141592L&amp;quot;);
static_assert(float_equals(0.017453L, deg2rad(1)), &amp;quot;deg2rad(1) == 0.017453L&amp;quot;);
static_assert(float_equals(17.104226L, deg2rad(980)), &amp;quot;deg2rad(980) == 17.104226L&amp;quot;);

} // namespace deg2rad_tests
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Above code contains three compile-time unit tests of&amp;nbsp;&lt;code&gt;deg2rad&lt;/code&gt; function. Compiling this code runs
the&amp;nbsp;tests. Tests in&amp;nbsp;this form are&amp;nbsp;not&amp;nbsp;very maintainable as&amp;nbsp;they contains many duplications. Function
calls contain the&amp;nbsp;same information as&amp;nbsp;assertion messages. This problem can&amp;nbsp;can&amp;nbsp;be&amp;nbsp;resolved by&amp;nbsp;using a&amp;nbsp;macro-definition instead of&amp;nbsp;a&amp;nbsp;helper function.&lt;/p&gt;

&lt;pre&gt;&lt;code class="cpp"&gt;#include &amp;lt;cmath&amp;gt;

#define STATIC_ASSERT_FLOAT_EQUALS(expected, actual) \
  static_assert(std::abs(expected - actual) &amp;lt; 0.00001L, #expected &amp;quot; == &amp;quot; #actual);

namespace deg2rad_tests {

STATIC_ASSERT_FLOAT_EQUALS(3.141592L, deg2rad(180));
STATIC_ASSERT_FLOAT_EQUALS(0.017453L, deg2rad(1));
STATIC_ASSERT_FLOAT_EQUALS(17.104226L, deg2rad(980));

} // namespace deg3rad_tests
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;All&amp;nbsp;further examples of&amp;nbsp;tests will use&amp;nbsp;macro-definitions.&lt;/p&gt;

&lt;p&gt;Object methods, static methods and&amp;nbsp;construtors can&amp;nbsp;also have &lt;code&gt;constexpr&lt;/code&gt; modifier.
The&amp;nbsp;next example contains a&amp;nbsp;simple, statically bound class that represents a&amp;nbsp;vector in&amp;nbsp;&lt;abbr
title="two-dimentional"&gt;2D&lt;/abbr&gt; space. Its&amp;nbsp;constructor, getters and&amp;nbsp;arithmetic
operators are&amp;nbsp;unit-tested during the&amp;nbsp;compilation.&lt;/p&gt;

&lt;pre&gt;&lt;code class="cpp"&gt;// Two-dimentional vector.
// Class is&amp;nbsp;immutable, all&amp;nbsp;operations (including constructor) are&amp;nbsp;constant expressions.
class vec2 {
 public:
  constexpr vec2(int&amp;nbsp;x&amp;nbsp;= 0, int&amp;nbsp;y&amp;nbsp;= 0) : _x(x), _y(y) {
  }

  constexpr int&amp;nbsp;x() const {
    return _x;
  }
  constexpr int&amp;nbsp;y() const {
    return _y;
  }

  constexpr vec2 operator+(vec2 const&amp;amp; rhs) const {
    return vec2(_x + rhs._x, _y + rhs._y);
  }
  constexpr vec2 operator-(vec2 const&amp;amp; rhs) const {
    return vec2(_x - rhs._x, _y - rhs._y);
  }

 private:
  int&amp;nbsp;_x;
  int&amp;nbsp;_y;
}; // class vec2

#define STATIC_ASSERT_EQUALS(expected, actual) \
  static_assert(expected == actual, #expected &amp;quot; != &amp;quot; #actual)

namespace vec2_tests {

STATIC_ASSERT_EQUALS(1, vec2(1, 2).x());
STATIC_ASSERT_EQUALS(2, vec2(1, 2).y());
STATIC_ASSERT_EQUALS(3, (vec2(1, 2) + vec2(2, 3)).x());
STATIC_ASSERT_EQUALS(5, (vec2(1, 2) + vec2(2, 3)).y());
STATIC_ASSERT_EQUALS(-1, (vec2(1, 2) - vec2(2, 3)).x());
STATIC_ASSERT_EQUALS(-1, (vec2(1, 2) - vec2(2, 3)).y());

} // namespace vec2_tests
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Number of&amp;nbsp;unit tests in&amp;nbsp;above example is&amp;nbsp;minimal. Production code will probably contain more than
one&amp;nbsp;test per&amp;nbsp;operation.&lt;/p&gt;

&lt;h3 id="toc_3"&gt;Meta-Functions&lt;/h3&gt;

&lt;p&gt;There is&amp;nbsp;a&amp;nbsp;popular statement that meta-language of&amp;nbsp;C++ is&amp;nbsp;C++ itself. It&amp;#39;s true, but&amp;nbsp;more precicely,
meta-programming in&amp;nbsp;C++ is&amp;nbsp;done using &lt;a href="http://en.cppreference.com/w/cpp/language/templates"&gt;C++ templates&lt;/a&gt;, which are&amp;nbsp;whole another, purely
&lt;a href="https://en.wikipedia.org/wiki/Functional_programming"&gt;functional&lt;/a&gt; programming language, embedded into C++. Templates provide a&amp;nbsp;way&amp;nbsp;to&amp;nbsp;abstract out&amp;nbsp;a&amp;nbsp;common code from a&amp;nbsp;family of&amp;nbsp;classes (or&amp;nbsp;functions) without
use&amp;nbsp;of&amp;nbsp;runtime polymorphism&lt;sup&gt;&lt;a href="#static-polymorphism"&gt;2&lt;/a&gt;&lt;/sup&gt;.
C++ code is&amp;nbsp;generated from template specializations during the&amp;nbsp;compilation.
That&amp;#39;s why&amp;nbsp;templates can&amp;nbsp;be&amp;nbsp;compile-time unit-tested.&lt;/p&gt;

&lt;p&gt;Meta-function is&amp;nbsp;a&amp;nbsp;template structure that takes a&amp;nbsp;type as&amp;nbsp;parameter and&amp;nbsp;returns another type
in&amp;nbsp;a&amp;nbsp;typedef or&amp;nbsp;a&amp;nbsp;value in&amp;nbsp;a&amp;nbsp;static variable (or&amp;nbsp;both).
One&amp;nbsp;of&amp;nbsp;the&amp;nbsp;simplest meta-functions is&amp;nbsp;the&amp;nbsp;one&amp;nbsp;that adds pointer to&amp;nbsp;a&amp;nbsp;type.&lt;/p&gt;

&lt;pre&gt;&lt;code class="cpp"&gt;// Since C++11, there is&amp;nbsp;a&amp;nbsp;one-liner for&amp;nbsp;doing this.
template&amp;lt;class arg_t&amp;gt; using add_pointer_t = arg_t*;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In&amp;nbsp;order to&amp;nbsp;test this meta-function, one&amp;nbsp;of&amp;nbsp;&lt;a href="http://en.cppreference.com/w/cpp/header/type_traits"&gt;type traits&lt;/a&gt; from the&amp;nbsp;standard library
(&lt;a href="http://en.cppreference.com/w/cpp/types/is_same"&gt;&lt;code&gt;std::is_same&lt;/code&gt;&lt;/a&gt;) must be&amp;nbsp;used. It&amp;nbsp;takes two&amp;nbsp;types in&amp;nbsp;template parameters and&amp;nbsp;returns &lt;code&gt;true&lt;/code&gt;
it&amp;nbsp;they are&amp;nbsp;identical.&lt;/p&gt;

&lt;pre&gt;&lt;code class="cpp"&gt;#include &amp;lt;type_traits&amp;gt;

#define STATIC_ASSERT(expr) static_assert(expr, #expr)

namespace add_pointer_t_tests {

STATIC_ASSERT((std::is_same&amp;lt;add_pointer_t&amp;lt;int&amp;gt;, int*&amp;gt;::value));
STATIC_ASSERT((std::is_same&amp;lt;add_pointer_t&amp;lt;long&amp;gt;, long*&amp;gt;::value));
STATIC_ASSERT((std::is_same&amp;lt;add_pointer_t&amp;lt;float&amp;gt;, float*&amp;gt;::value));
STATIC_ASSERT((std::is_same&amp;lt;add_pointer_t&amp;lt;int*&amp;gt;, int**&amp;gt;::value));

} // namespace add_pointer_t_tests
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The&amp;nbsp;next example is&amp;nbsp;less trivial. It&amp;nbsp;contains a&amp;nbsp;meta-function that counts types passed
in&amp;nbsp;its&amp;nbsp;template parameters. Function uses:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://en.cppreference.com/w/cpp/language/parameter_pack"&gt;parameter packs&lt;/a&gt;, a&amp;nbsp;C++11 feature that enables creating &lt;a href="https://en.wikipedia.org/wiki/Variadic_template"&gt;variadic templates&lt;/a&gt;,&lt;/li&gt;
&lt;li&gt;&lt;a href="http://en.cppreference.com/w/cpp/language/partial_specialization"&gt;partial specialization&lt;/a&gt;, which in&amp;nbsp;this example is&amp;nbsp;used to&amp;nbsp;make the&amp;nbsp;template
&lt;a href="https://en.wikipedia.org/wiki/Recursion_%28computer_science%29"&gt;recursive&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;&lt;code class="cpp"&gt;// Meta-function that counts types.
// It&amp;nbsp;takes a&amp;nbsp;parameter pack (which can&amp;nbsp;be&amp;nbsp;empty) in&amp;nbsp;its&amp;nbsp;template argument.
// There is&amp;nbsp;no&amp;nbsp;implementation, because everything will be&amp;nbsp;handled in&amp;nbsp;specializations.
template &amp;lt;class ...args_t&amp;gt;
struct count_types;

// Partial specialization that will be&amp;nbsp;chosen by&amp;nbsp;the&amp;nbsp;compiler
// if&amp;nbsp;there is&amp;nbsp;at&amp;nbsp;least one&amp;nbsp;type (head_t) in&amp;nbsp;parameter pack.
template &amp;lt;class head_t, class ...tail_t&amp;gt;
struct count_types&amp;lt;head_t, tail_t...&amp;gt; {
  // value is&amp;nbsp;computed recursively by&amp;nbsp;calling the&amp;nbsp;same meta-function
  static const size_t value = 1 + count_types&amp;lt;tail_t...&amp;gt;::value;
};

// Partial specialization that will be&amp;nbsp;chosen only if&amp;nbsp;parameter pack is&amp;nbsp;empty.
template &amp;lt;&amp;gt;
struct count_types&amp;lt;&amp;gt; {
  static const size_t value = 0;
};

#define STATIC_ASSERT_EQUALS(expected, actual) \
  static_assert(expected == actual, #expected &amp;quot; == &amp;quot; #actual)

namespace count_types_tests {

STATIC_ASSERT_EQUALS(0, (count_types&amp;lt;&amp;gt;::value));
STATIC_ASSERT_EQUALS(1, (count_types&amp;lt;int&amp;gt;::value));
STATIC_ASSERT_EQUALS(3, (count_types&amp;lt;int,float,double&amp;gt;::value));
STATIC_ASSERT_EQUALS(10, (count_types&amp;lt;int,int,int,int,int,int,int,int,int,int&amp;gt;::value));

} // namespace count_types_tests
&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id="toc_4"&gt;Debugging&lt;/h3&gt;

&lt;p&gt;GCC&amp;nbsp;compiler prints very limited information when static assertion fails. To&amp;nbsp;demonstrate this, let&amp;#39;s
change one&amp;nbsp;of&amp;nbsp;the&amp;nbsp;partial specializations of&amp;nbsp;&lt;code&gt;count_types&lt;/code&gt;, so&amp;nbsp;it&amp;nbsp;will contain a&amp;nbsp;bug.&lt;/p&gt;

&lt;pre&gt;&lt;code class="cpp"&gt;template &amp;lt;class head_t, class ...tail_t&amp;gt;
struct count_types&amp;lt;head_t, tail_t...&amp;gt; {
  // A&amp;nbsp;programmer forgot to&amp;nbsp;pass tail_t... to&amp;nbsp;recursive call
  static const size_t value = 1 + count_types&amp;lt;&amp;gt;::value;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now, when processing following assertion...&lt;/p&gt;

&lt;pre&gt;&lt;code class="cpp"&gt;STATIC_ASSERT_EQUALS(3, (count_types&amp;lt;int, float, double&amp;gt;::value));
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;...the compiler will produce following output.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;error: static assertion failed: 3 == (count_types&amp;lt;int, float, double&amp;gt;::value)
   static_assert(expected == actual, #expected &amp;quot; == &amp;quot; #actual)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The&amp;nbsp;information of&amp;nbsp;wich assertion has&amp;nbsp;failed is&amp;nbsp;present, but&amp;nbsp;it&amp;nbsp;is&amp;nbsp;not&amp;nbsp;known what value was&amp;nbsp;returned from the&amp;nbsp;tested meta-function. A&amp;nbsp;way&amp;nbsp;to&amp;nbsp;print a&amp;nbsp;static value is&amp;nbsp;to&amp;nbsp;put&amp;nbsp;it&amp;nbsp;in&amp;nbsp;a&amp;nbsp;template
parameter that will be&amp;nbsp;visible in&amp;nbsp;the&amp;nbsp;&amp;lsquo;required from&amp;rsquo; stack trace (a&amp;nbsp;part of&amp;nbsp;compilation
error output). Next code snippet contains an&amp;nbsp;utility for&amp;nbsp;printing static values this way.&lt;/p&gt;

&lt;pre&gt;&lt;code class="cpp"&gt;// Compilation error must be&amp;nbsp;generated in&amp;nbsp;order to&amp;nbsp;print anything.
// This function generates this error (static assertion always fails).
// Template parameters of&amp;nbsp;calls containing failed static assertions
// are&amp;nbsp;never printed by&amp;nbsp;gcc&amp;nbsp;compiler (val_t will not&amp;nbsp;be&amp;nbsp;printed).
template &amp;lt;class val_t&amp;gt;
constexpr val_t staticAssertFail(val_t value) {
  // Value must be&amp;nbsp;passed to&amp;nbsp;trick the&amp;nbsp;compiler
  // that it&amp;#39;s needed to&amp;nbsp;evaluate the&amp;nbsp;assertion.
  static_assert(value &amp;amp;&amp;amp; false, &amp;quot;debugging value&amp;quot;);
  return value;
}

// Another function that calls the&amp;nbsp;function above.
// Template parameters of&amp;nbsp;this function will be&amp;nbsp;printed
// in&amp;nbsp;&amp;#39;required from&amp;#39; stack trace.
template &amp;lt;class val_t, val_t value&amp;gt;
constexpr val_t debugStaticValue() {
    return staticAssertFail(value);
}

// Helper macro-definition for&amp;nbsp;usage in&amp;nbsp;debugged code.
// To&amp;nbsp;use&amp;nbsp;it, just wrap a&amp;nbsp;value you&amp;nbsp;wish to&amp;nbsp;debug.
#define DSV(v) \
  debugStaticValue&amp;lt;std::remove_cv&amp;lt;std::remove_reference&amp;lt;decltype(v)&amp;gt;::type&amp;gt;::type, v&amp;gt;()
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;code&gt;DSV&lt;/code&gt; helper macro is&amp;nbsp;reusable. You&amp;nbsp;may&amp;nbsp;copy and&amp;nbsp;paste it&amp;nbsp;into your project if&amp;nbsp;you&amp;nbsp;like
(or&amp;nbsp;download &lt;a href="https://github.com/mchalapuk/static-tests/blob/master/include/debug.hpp"&gt;debug.hpp&lt;/a&gt; file from &lt;a href="https://github.com/mchalapuk/static-tests"&gt;mchalapuk/static-tests&lt;/a&gt; project).&lt;/p&gt;

&lt;pre&gt;&lt;code class="cpp"&gt;// Erroneus value wrapped in&amp;nbsp;DSV&amp;nbsp;macro.
STATIC_ASSERT_EQUALS(3, DSV((count_types&amp;lt;int, float, double&amp;gt;::value)));
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Above code produces following compiler output.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;required from &#x2018;constexpr val_t debugStaticValue() [with val_t = size_t; val_t value = 1ul]&#x2019;
required from here
error: static assertion failed: debugging value
error: static assertion failed: 3 == DSV((count_types&amp;lt;int, float, double&amp;gt;::value))
note: in&amp;nbsp;expansion of&amp;nbsp;macro &#x2018;STATIC_ASSERT_EQUALS&#x2019;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Use&amp;nbsp;of&amp;nbsp;helper macro resulted in&amp;nbsp;three extra lines at&amp;nbsp;the&amp;nbsp;beginning of&amp;nbsp;the&amp;nbsp;output.
First line contains erroneus value (&lt;code&gt;1ul&lt;/code&gt;) and&amp;nbsp;its&amp;nbsp;type (&lt;code&gt;size_t&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;Unfortunately, above method can&amp;nbsp;not&amp;nbsp;be&amp;nbsp;used on&amp;nbsp;all&amp;nbsp;values. There are&amp;nbsp;strict requirements that
a&amp;nbsp;value must meet to&amp;nbsp;be&amp;nbsp;a&amp;nbsp;valid &lt;a href="http://en.cppreference.com/w/cpp/language/template_parameters#Non-type_template_parameter"&gt;non-type template parameter&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id="toc_5"&gt;Rationale&lt;/h3&gt;

&lt;p&gt;There are&amp;nbsp;many reasons for&amp;nbsp;using static unit testing. First of&amp;nbsp;all, having statically bound code
implies statically bound tests. If&amp;nbsp;all&amp;nbsp;code is&amp;nbsp;executed during the&amp;nbsp;compilation, but&amp;nbsp;tests are&amp;nbsp;done
in&amp;nbsp;runtime, resulting program will contain only comparisons between meaningless values.&lt;/p&gt;

&lt;pre&gt;&lt;code class="cpp"&gt;// For&amp;nbsp;example following program.
int&amp;nbsp;main() {
  assert std::numeric_limits&amp;lt;unsigned char&amp;gt;::max == 255;
}

// Will compile to&amp;nbsp;something like this.
int&amp;nbsp;main() {
  assert 255 == 255; // What are&amp;nbsp;the&amp;nbsp;meanings of&amp;nbsp;this values?
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Using static assertions instead of&amp;nbsp;runtime ones will result in&amp;nbsp;everything (code and&amp;nbsp;tests) being
run&amp;nbsp;on&amp;nbsp;the&amp;nbsp;compiler. Resulting test program will be&amp;nbsp;empty, which is&amp;nbsp;much more &lt;a href="https://en.wikipedia.org/wiki/Elegance"&gt;elegant&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Elegance is&amp;nbsp;not&amp;nbsp;a&amp;nbsp;dispensable luxury but&amp;nbsp;a&amp;nbsp;quality that decides between success and&amp;nbsp;failure.&lt;/p&gt;

&lt;p&gt;~ Edsger W. Dijkstra&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Static assertions are&amp;nbsp;also the&amp;nbsp;only way&amp;nbsp;of&amp;nbsp;&lt;strong&gt;checking that code is&amp;nbsp;statically bound&lt;/strong&gt;, as&amp;nbsp;intended.
Skipping this type of&amp;nbsp;test may&amp;nbsp;result in&amp;nbsp;instructions sliping to&amp;nbsp;runtime by&amp;nbsp;accident which can&amp;nbsp;drastically affect program&amp;#39;s &lt;a href="https://en.wikipedia.org/wiki/Computer_performance"&gt;performance&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Compile-time unit testing &lt;strong&gt;reduces turn around time&lt;/strong&gt;, as&amp;nbsp;full project doesn&amp;#39;t have to&amp;nbsp;be&amp;nbsp;built
before running any&amp;nbsp;tests. Static assertions fail during compilation of&amp;nbsp;a&amp;nbsp;single file which
can&amp;nbsp;greatly reduce feedback time and&amp;nbsp;increase &lt;a href="https://en.wikipedia.org/wiki/Maintainability"&gt;maintainability&lt;/a&gt; of&amp;nbsp;a&amp;nbsp;code base.&lt;/p&gt;

&lt;h3 id="toc_6"&gt;Summary&lt;/h3&gt;

&lt;p&gt;Examples from this article include C++ constructs of&amp;nbsp;three types: statically bound functions,
statically bound classes, and&amp;nbsp;meta-functions. These (more or&amp;nbsp;less) cover the&amp;nbsp;full spectrum
of&amp;nbsp;code which can&amp;nbsp;be&amp;nbsp;tested during the&amp;nbsp;compilation. Things to&amp;nbsp;take out&amp;nbsp;from this article are&amp;nbsp;that many features of&amp;nbsp;modern C++ utilize static binding, and&amp;nbsp;that statically bound code requires
compile-time unit tests.&lt;/p&gt;

&lt;p&gt;As&amp;nbsp;of&amp;nbsp;now, compile-time unit-testing in&amp;nbsp;C++ is&amp;nbsp;not&amp;nbsp;ideal.
Besides &lt;code&gt;static_assert&lt;/code&gt;, there aren&amp;#39;t any&amp;nbsp;debugging facilities of&amp;nbsp;compile-time code.
Templates provide a&amp;nbsp;simple way&amp;nbsp;of&amp;nbsp;debugging statically bound values, but&amp;nbsp;this technique works only
with types that are&amp;nbsp;accepted as&amp;nbsp;template parameters, which of&amp;mdash;most notably&amp;mdash;floating
point numbers are&amp;nbsp;not&amp;nbsp;part.
Also, the&amp;nbsp;fact that there are&amp;nbsp;no&amp;nbsp;test reports may&amp;nbsp;be&amp;nbsp;interpreted as&amp;nbsp;a&amp;nbsp;problem. The&amp;nbsp;only way&amp;nbsp;of&amp;nbsp;proving that test is&amp;nbsp;run&amp;nbsp;by&amp;nbsp;the&amp;nbsp;compiler is&amp;nbsp;to&amp;nbsp;make it&amp;nbsp;not&amp;nbsp;pass. On&amp;nbsp;the&amp;nbsp;other hand,
this is&amp;nbsp;consistent with Linux&amp;#39;s &amp;lsquo;empty output means no&amp;nbsp;error&amp;rsquo; convention, so&amp;nbsp;maybe it&amp;#39;s
not&amp;nbsp;such a&amp;nbsp;downside after all.&lt;/p&gt;

&lt;p&gt;Good knowledge of&amp;nbsp;rescent C++ standards and&amp;nbsp;build environments is&amp;nbsp;definitely a&amp;nbsp;requirement for&amp;nbsp;an&amp;nbsp;efficient use&amp;nbsp;of&amp;nbsp;compile-time unit testing. The&amp;nbsp;technique still needs work, but&amp;nbsp;the&amp;nbsp;benefits
most definitely outweight the&amp;nbsp;problems. If&amp;nbsp;you&amp;nbsp;are&amp;nbsp;not&amp;nbsp;up-to-date with current C++, this may&amp;nbsp;be&amp;nbsp;a&amp;nbsp;good reason to&amp;nbsp;brush up&amp;nbsp;your skills.&lt;/p&gt;

&lt;h3 id="toc_7"&gt;References&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;A&amp;nbsp;White paper titled &amp;ldquo;&lt;a href="http://ceur-ws.org/Vol-1375/SQAMIA2015_Paper1.pdf"&gt;Compile-time Unit Testing&lt;/a&gt;&amp;rdquo; written by&amp;nbsp;Aron Barath and&amp;nbsp;Zoltan Porkol (Lorand University) contains many examples written in&amp;nbsp;C++ and&amp;nbsp;in&amp;nbsp;experimental
language created for&amp;nbsp;purposes of&amp;nbsp;testing this concept.&lt;/li&gt;
&lt;li&gt;Peter Dimov&amp;#39;s article titled &amp;ldquo;&lt;a href="http://pdimov.com/cpp2/simple_cxx11_metaprogramming.html"&gt;Simple C++11 metaprogramming&lt;/a&gt;&amp;rdquo; contains many
examples of&amp;nbsp;operations on&amp;nbsp;type lists implemented using parameter packs.&lt;/li&gt;
&lt;li&gt;Eric Niebler wrote a&amp;nbsp;blogpost titled &amp;ldquo;&lt;a href="http://ericniebler.com/2014/11/13/tiny-metaprogramming-library/"&gt;Tiny Metaprogramming Library&lt;/a&gt;&amp;rdquo; where he&amp;nbsp;argues that we&amp;nbsp;don&amp;#39;t need big&amp;nbsp;meta-programming libraries like &lt;a href="http://www.boost.org/doc/libs/1_60_0/libs/mpl/doc/"&gt;Boost.MPL&lt;/a&gt;, as&amp;nbsp;type
lists are&amp;nbsp;now&amp;nbsp;implemented in&amp;nbsp;C++ with just one&amp;nbsp;line of&amp;nbsp;code. He&amp;nbsp;provides many examples.&lt;/li&gt;
&lt;li&gt;An&amp;nbsp;old&amp;nbsp;StackOverflow thread titled &amp;ldquo;&lt;a href="http://stackoverflow.com/questions/846103/runtime-vs-compile-time"&gt;Runtime vs&amp;nbsp;Compile time&lt;/a&gt;&amp;rdquo; in&amp;nbsp;great
detail describes the&amp;nbsp;difference between runtime and&amp;nbsp;compile-time errors.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id="toc_8"&gt;Annotations&lt;/h3&gt;

&lt;p&gt;&lt;a id="constexpr-requirements"&gt;&lt;/a&gt;
&lt;sup&gt;&lt;a href="#constexpr-requirements"&gt;{1}&lt;/a&gt;&lt;/sup&gt; Please consult the&amp;nbsp;documentation of&amp;nbsp;&lt;a href="http://en.cppreference.com/w/cpp/language/constexpr"&gt;constexpr&lt;/a&gt; keyword for&amp;nbsp;full list of&amp;nbsp;requirements.&lt;/p&gt;

&lt;p&gt;&lt;a id="static-polymorphism"&gt;&lt;/a&gt;
&lt;sup&gt;&lt;a href="#static-polymorphism"&gt;{2}&lt;/a&gt;&lt;/sup&gt; There is&amp;nbsp;even a&amp;nbsp;template technique called &lt;a href="https://en.wikipedia.org/wiki/Template_metaprogramming#Static_polymorphism"&gt;static polymorphism&lt;/a&gt;, where
implementations are&amp;nbsp;bound to&amp;nbsp;calls during the&amp;nbsp;compilation.&lt;/p&gt;
</description>
    </item>
    <item>
      <title>Why do we learn next programming languages?</title>
      <link>http://softwarephilosophy.ninja/why-do-we-learn-next-programming-languages</link>
      <pubDate>2016-02-19</pubDate>
      <description>&lt;p&gt;Self-education can&amp;nbsp;be&amp;nbsp;as&amp;nbsp;painful as&amp;nbsp;it&amp;nbsp;can&amp;nbsp;be&amp;nbsp;gratifying. The&amp;nbsp;trick is&amp;nbsp;to&amp;nbsp;know when to&amp;nbsp;expect what.
Contents of&amp;nbsp;this article are&amp;nbsp;aimed at&amp;nbsp;establishing a&amp;nbsp;correct (IMHO) &lt;a href="https://en.wikipedia.org/wiki/Mindset"&gt;mindset&lt;/a&gt; in&amp;nbsp;the&amp;nbsp;topic
of&amp;nbsp;learning programming languages. I&amp;nbsp;will try&amp;nbsp;to&amp;nbsp;convince you&amp;nbsp;that knowing multiple languages
well is&amp;nbsp;the&amp;nbsp;way&amp;nbsp;to&amp;nbsp;excell as&amp;nbsp;a&amp;nbsp;software developer. You&amp;#39;ll get&amp;nbsp;to&amp;nbsp;know the&amp;nbsp;benefits
of&amp;nbsp;polyglot programming, reasons for&amp;nbsp;not&amp;nbsp;liking it, what programming gurus have to&amp;nbsp;say&amp;nbsp;in&amp;nbsp;this matter, and&amp;nbsp;how&amp;nbsp;to&amp;nbsp;choose the&amp;nbsp;next language to&amp;nbsp;learn.&lt;/p&gt;

&lt;h3 id="toc_0"&gt;Mindful Engineering&lt;/h3&gt;

&lt;p&gt;One&amp;nbsp;of&amp;nbsp;the&amp;nbsp;most important skills of&amp;nbsp;any&amp;nbsp;engineer is&amp;nbsp;being able to&amp;nbsp;&lt;strong&gt;choose a&amp;nbsp;tool for&amp;nbsp;the&amp;nbsp;job&lt;/strong&gt;. Programming languages come with unique traits, which often makes them well suited for&amp;nbsp;solving
problems of&amp;nbsp;particular type. Game engines are&amp;nbsp;written in&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/C%2B%2B"&gt;C++&lt;/a&gt;, as&amp;nbsp;it&amp;nbsp;enables precise control
over &lt;a href="https://en.wikipedia.org/wiki/System_resource"&gt;system resources&lt;/a&gt;. &lt;a href="https://en.wikipedia.org/wiki/Java_%28programming_language%29"&gt;Java&lt;/a&gt; has&amp;nbsp;one&amp;nbsp;of&amp;nbsp;the&amp;nbsp;best technology stacks for&amp;nbsp;writing
&lt;a href="https://en.wikipedia.org/wiki/Server_%28computing%29"&gt;server-side&lt;/a&gt; &lt;a href="https://en.wikipedia.org/wiki/Business_logic"&gt;business logic&lt;/a&gt;. It&amp;#39;s good to&amp;nbsp;code &lt;a href="https://en.wikipedia.org/wiki/Big_data"&gt;data processors&lt;/a&gt; in&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/Functional_programming"&gt;functional
languages&lt;/a&gt; such as&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/Scala_%28programming_language%29"&gt;Scala&lt;/a&gt; or&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/Haskell_%28programming_language%29"&gt;Haskell&lt;/a&gt;. The&amp;nbsp;list goes on...
Coding everything in&amp;nbsp;the&amp;nbsp;same language, if&amp;nbsp;it&amp;#39;s even possible, means not&amp;nbsp;using the&amp;nbsp;best
tools out&amp;nbsp;there.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If&amp;nbsp;you&amp;#39;re a&amp;nbsp;hammer, everything looks like a&amp;nbsp;nail.&lt;/p&gt;

&lt;p&gt;~ Abraham Maslow&amp;#39;s The&amp;nbsp;Psychology of&amp;nbsp;Science&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Existence of&amp;nbsp;a&amp;nbsp;better solution than the&amp;nbsp;one&amp;nbsp;just developed&amp;mdash;in&amp;nbsp;another language or&amp;nbsp;not&amp;mdash;is&amp;nbsp;highly probable. Different languages promote &lt;strong&gt;different ways of&amp;nbsp;solving the&amp;nbsp;same problems&lt;/strong&gt;. Techniques learned in&amp;nbsp;one&amp;nbsp;language can&amp;nbsp;be&amp;nbsp;used in&amp;nbsp;many others, which means, that by&amp;nbsp;learning a&amp;nbsp;new&amp;nbsp;language you&amp;nbsp;are&amp;nbsp;getting more skilled at&amp;nbsp;using all&amp;nbsp;the&amp;nbsp;languages you&amp;nbsp;know.
Each programming language you&amp;nbsp;know makes you&amp;nbsp;more capable of&amp;nbsp;making decisions
about technology and&amp;nbsp;a&amp;nbsp;better software engineer overall.&lt;/p&gt;

&lt;p&gt;Another benefit from an&amp;nbsp;engineer&amp;#39;s point of&amp;nbsp;view is&amp;nbsp;doing &lt;a href="https://en.wikipedia.org/wiki/Solution_stack"&gt;full-stack development&lt;/a&gt;,
which is&amp;nbsp;lately getting more in-demand by&amp;nbsp;employers.
Many technology stacks are&amp;nbsp;heterogeneous in&amp;nbsp;terms of&amp;nbsp;programming languages.
Typically, different languages are&amp;nbsp;used on&amp;nbsp;different layers.
Software developers familiar with entire technology stacks are&amp;nbsp;more efficient at&amp;nbsp;finding bugs
and&amp;nbsp;much better at&amp;nbsp;performance and&amp;nbsp;optimization work.&lt;/p&gt;

&lt;h3 id="toc_1"&gt;Efficient Learning&lt;/h3&gt;

&lt;p&gt;Most software developers have read something about &lt;a href="https://en.wikipedia.org/wiki/Functional_programming"&gt;functional programming&lt;/a&gt; and&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/Predicate_logic"&gt;predicate
logic&lt;/a&gt; during their period of&amp;nbsp;formal education, but&amp;nbsp;this knowledge stays very theoretical until
something useful is&amp;nbsp;created using it. As&amp;nbsp;you&amp;nbsp;practically try&amp;nbsp;languages implementing other
paradigms than you&amp;nbsp;already know, you&amp;nbsp;learn new&amp;nbsp;idioms and&amp;nbsp;techniques, while getting to&amp;nbsp;know their
pros and&amp;nbsp;cons in&amp;nbsp;the&amp;nbsp;process.
This is&amp;nbsp;a&amp;nbsp;great way&amp;nbsp;to&amp;nbsp;grow as&amp;nbsp;a&amp;nbsp;programmer.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Once you&amp;nbsp;stop learning, you&amp;nbsp;start dying.&lt;/p&gt;

&lt;p&gt;~ Albert Einstein&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;While learning multiple programming languages, we&amp;nbsp;unconsciously build a&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/Metalanguage"&gt;meta-language&lt;/a&gt;
in&amp;nbsp;our&amp;nbsp;heads, which is&amp;nbsp;then used to&amp;nbsp;translate between programming languages. In&amp;nbsp;time,
this meta-language becomes very handy in&amp;nbsp;learning yet&amp;nbsp;new&amp;nbsp;languages. A&amp;nbsp;master of&amp;nbsp;a&amp;nbsp;dozen
programming languages may&amp;nbsp;start efficiently using a&amp;nbsp;next one&amp;nbsp;just after few-hour scrolling through
its&amp;nbsp;specification. This ability is&amp;nbsp;referred to&amp;nbsp;as&amp;nbsp;a&amp;nbsp;&lt;strong&gt;generalized language learning skill&lt;/strong&gt;.&lt;/p&gt;

&lt;h3 id="toc_2"&gt;More Contribution&lt;/h3&gt;

&lt;p&gt;Trying new&amp;nbsp;languages involves digging through forums and&amp;nbsp;mailing lists. By&amp;nbsp;introducing ourselves
to&amp;nbsp;the&amp;nbsp;new&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/TIOBE_index"&gt;community&lt;/a&gt;, we&amp;nbsp;may&amp;nbsp;learn about new&amp;nbsp;ways of&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/Standardization"&gt;standardization&lt;/a&gt;,
&lt;a href="https://en.wikipedia.org/wiki/Coding_conventions"&gt;coding conventions&lt;/a&gt;, or&amp;nbsp;even social interactions. Active involvement in&amp;nbsp;multiple
programming communities creates a&amp;nbsp;potential for&amp;nbsp;expansion of&amp;nbsp;professional network.&lt;/p&gt;

&lt;p&gt;Programmers, that are&amp;nbsp;highly skilled in&amp;nbsp;using many languages, are&amp;nbsp;often the&amp;nbsp;ones writing new&amp;nbsp;libraries, frameworks and&amp;nbsp;tools. If&amp;nbsp;you&amp;nbsp;are&amp;nbsp;able to&amp;nbsp;identify the&amp;nbsp;need for&amp;nbsp;a&amp;nbsp;library that is&amp;nbsp;already
available in&amp;nbsp;another language, you&amp;nbsp;may&amp;nbsp;also try&amp;nbsp;to&amp;nbsp;reimplement it&amp;nbsp;in&amp;nbsp;the&amp;nbsp;language you&amp;#39;re
currently using. Examples of&amp;nbsp;such successful reimplementations include (but&amp;nbsp;are&amp;nbsp;not&amp;nbsp;limited to):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/Jasmine_%28JavaScript_testing_framework%29"&gt;Jasmine&lt;/a&gt;(&lt;a href="https://en.wikipedia.org/wiki/JavaScript"&gt;JavaScript&lt;/a&gt;) and&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/Mocha_%28JavaScript_framework%29"&gt;Mocha&lt;/a&gt;(JavaScript) based on&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/RSpec"&gt;RSpec&lt;/a&gt;, a&amp;nbsp;&lt;abbr title="Behavior Driven Development"&gt;BDD&lt;/abbr&gt; framework for&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/Ruby_%28programming_language%29"&gt;Ruby&lt;/a&gt;&lt;sup&gt;&lt;a href="#origins-of-bdd"&gt;1&lt;/a&gt;&lt;/sup&gt;,&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.npmjs.com/package/offensive"&gt;offensive.js&lt;/a&gt;(JavaScript) and&amp;nbsp;&lt;a href="https://github.com/mchalapuk/prego"&gt;prego&lt;/a&gt;(&lt;a href="https://en.wikipedia.org/wiki/Golang"&gt;Go&lt;/a&gt;) based on&amp;nbsp;&lt;a href="https://github.com/google/guava/wiki/PreconditionsExplained"&gt;Preconditions&lt;/a&gt;(&lt;a href="https://github.com/google/guava"&gt;Guava&lt;/a&gt;, Java)&lt;sup&gt;&lt;a href="#origins-of-preconditions"&gt;2&lt;/a&gt;&lt;/sup&gt;,&lt;/li&gt;
&lt;li&gt;&lt;a href="http://en.cppreference.com/w/cpp/thread/future"&gt;std::future&lt;/a&gt; class from &lt;a href="https://en.wikipedia.org/wiki/C%2B%2B11"&gt;C++11&lt;/a&gt; standard based on&amp;nbsp;quite old&amp;nbsp;&lt;a href="http://docs.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/Future.html"&gt;Future&lt;/a&gt; from Java,&lt;/li&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/Play_Framework"&gt;Play&lt;/a&gt; framework for&amp;nbsp;Java and&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/Grails_%28framework%29"&gt;Grails&lt;/a&gt; for&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/Bjarne_Stroustrup"&gt;Groovy&lt;/a&gt;, both based on&amp;nbsp;concepts from
&lt;a href="https://en.wikipedia.org/wiki/Ruby_on_Rails"&gt;Ruby on&amp;nbsp;Rails&lt;/a&gt;,&lt;/li&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/Clojure"&gt;Clojure&lt;/a&gt; language, which is&amp;nbsp;essentially a&amp;nbsp;copy of&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/Lisp_%28programming_language%29"&gt;Lisp&lt;/a&gt; that works on&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/Java_virtual_machine"&gt;JVM&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One&amp;nbsp;of&amp;nbsp;the&amp;nbsp;highest forms of&amp;nbsp;contribution is&amp;nbsp;language design. After mastering multiple languages
from various programming paradigms, you&amp;nbsp;can&amp;nbsp;improve some of&amp;nbsp;them by&amp;nbsp;adding your 2 cents
to&amp;nbsp;the&amp;nbsp;work of&amp;nbsp;standard communities. People that see&amp;nbsp;the&amp;nbsp;need, have proper theoretical
knowledge and&amp;nbsp;feel up&amp;nbsp;for&amp;nbsp;it, may&amp;nbsp;even want to&amp;nbsp;start a&amp;nbsp;project of&amp;nbsp;a&amp;nbsp;totally new&amp;nbsp;programming
language on&amp;nbsp;their own.&lt;/p&gt;

&lt;h3 id="toc_3"&gt;Better Career&lt;/h3&gt;

&lt;p&gt;As&amp;nbsp;you&amp;nbsp;learn more and&amp;nbsp;more languages, the&amp;nbsp;number of&amp;nbsp;job&amp;nbsp;opportunities that matches your profile
raises. What&amp;#39;s more, being a&amp;nbsp;polyglot programmer gives you&amp;nbsp;an&amp;nbsp;advantage over other candidates
for&amp;nbsp;a&amp;nbsp;position you&amp;nbsp;may&amp;nbsp;be&amp;nbsp;interested in.
With higher probability of&amp;nbsp;recruitment resulting in&amp;nbsp;hire, you&amp;nbsp;can&amp;nbsp;be&amp;nbsp;more precise in&amp;nbsp;selecting
positions for&amp;nbsp;which you&amp;nbsp;would like to&amp;nbsp;apply. This ultimately leads to&amp;nbsp;being happier with your
job.&lt;/p&gt;

&lt;p&gt;Freelancers can&amp;nbsp;utilize the&amp;nbsp;benefits of&amp;nbsp;knowing multiple languages even more. As&amp;nbsp;freelancing
jobs are&amp;nbsp;project-based, there will be&amp;nbsp;more occasions to&amp;nbsp;change daily-used languages.
The&amp;nbsp;purpose of&amp;nbsp;learning new&amp;nbsp;languages will be&amp;nbsp;to&amp;nbsp;use&amp;nbsp;them in&amp;nbsp;the&amp;nbsp;next project, instead
of&amp;nbsp;just getting better at&amp;nbsp;programming. As&amp;nbsp;in&amp;nbsp;the&amp;nbsp;case of&amp;nbsp;permanent-job programmers, more
languages means more job&amp;nbsp;offers, more expertise and&amp;nbsp;better work efficiency, but&amp;nbsp;for&amp;nbsp;freelancers
better efficiency is&amp;nbsp;also directly connected with more money.&lt;/p&gt;

&lt;h3 id="toc_4"&gt;Following Gurus&lt;/h3&gt;

&lt;p&gt;Many succesful book authors and&amp;nbsp;designers of&amp;nbsp;popular programming languages have something to&amp;nbsp;say&amp;nbsp;about the&amp;nbsp;&lt;strong&gt;importance of&amp;nbsp;continuous learning&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Robert_Cecil_Martin"&gt;Robert C. &amp;lsquo;Uncle Bob&amp;rsquo; Martin&lt;/a&gt; writes in&amp;nbsp;his&amp;nbsp;second best-selling  book titled
&lt;a href="http://www.amazon.com/The-Clean-Coder-Professional-Programmers/dp/0137081073"&gt;The&amp;nbsp;Clean Coder&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The&amp;nbsp;frenetic rate of&amp;nbsp;change in&amp;nbsp;our&amp;nbsp;industry means that software developers must continue to&amp;nbsp;learn
copious quantities just to&amp;nbsp;keep up. Woe&amp;nbsp;to&amp;nbsp;the&amp;nbsp;architects who&amp;nbsp;stop coding&#x2014;they will rapidly find
themselves irrelevant. Woe&amp;nbsp;to&amp;nbsp;the&amp;nbsp;programmers who&amp;nbsp;stop learning new&amp;nbsp;languages&#x2014;they will watch as&amp;nbsp;the&amp;nbsp;industry passes them by. Woe&amp;nbsp;to&amp;nbsp;the&amp;nbsp;developers who&amp;nbsp;fail to&amp;nbsp;learn new&amp;nbsp;disciplines and&amp;nbsp;techniques &amp;mdash; their peers will excel as&amp;nbsp;they decline.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In&amp;nbsp;this statement he&amp;nbsp;touches another problem (high-flying architects), but&amp;nbsp;the&amp;nbsp;essence is&amp;nbsp;about
learning. This guy&amp;nbsp;has&amp;nbsp;40+ years of&amp;nbsp;experience in&amp;nbsp;computer programming. He&amp;#39;s witness how&amp;nbsp;many
languages and&amp;nbsp;technologies got&amp;nbsp;obsolete.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://pragprog.com/the-pragmatic-programmer/extracts/tips"&gt;The&amp;nbsp;Pragmatic Programmer&lt;/a&gt;&amp;mdash;a&amp;nbsp;popular book by&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/Andy_Hunt_%28author%29"&gt;Andy Hunt&lt;/a&gt; and&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/Dave_Thomas_%28programmer%29"&gt;Dave
Thomas&lt;/a&gt;&amp;mdash;contains a&amp;nbsp;list of&amp;nbsp;very useful programming tips. Tip&amp;nbsp;#8 &amp;ldquo;Invest
Regularly in&amp;nbsp;Your Knowledge Portfolio&amp;rdquo; states:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Learn at&amp;nbsp;least one&amp;nbsp;new&amp;nbsp;language every year. Different languages solve the&amp;nbsp;same problems
in&amp;nbsp;different ways. By&amp;nbsp;learning several different approaches, you&amp;nbsp;can&amp;nbsp;help broaden
your thinking and&amp;nbsp;avoid getting stuck in&amp;nbsp;a&amp;nbsp;rut. Additionally, learning many languages
is&amp;nbsp;far&amp;nbsp;easier now, thanks to&amp;nbsp;the&amp;nbsp;wealth of&amp;nbsp;freely available software on&amp;nbsp;the&amp;nbsp;Internet.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Authors of&amp;nbsp;this book took a&amp;nbsp;huge part in&amp;nbsp;creating the&amp;nbsp;&lt;a href="http://www.agilemanifesto.org/"&gt;Agile Manifesto&lt;/a&gt;. Some Agile values were
based on&amp;nbsp;the&amp;nbsp;tips from The&amp;nbsp;Pragmatic Programmer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Larry_Wall"&gt;Larry Wall&lt;/a&gt;&amp;mdash;the&amp;nbsp;author of&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/Perl"&gt;Perl&lt;/a&gt; scripting language&amp;mdash;lists following five
languages as&amp;nbsp;must-haves in&amp;nbsp;the&amp;nbsp;world of&amp;nbsp;modern programming:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;JavaScript, to&amp;nbsp;know the&amp;nbsp;consequence of&amp;nbsp;enabling scripts in&amp;nbsp;a&amp;nbsp;web&amp;nbsp;browser,&lt;/li&gt;
&lt;li&gt;Java, because managers like it&amp;nbsp;due&amp;nbsp;to&amp;nbsp;the&amp;nbsp;fact that programmers are&amp;nbsp;easily interchangeable,&lt;/li&gt;
&lt;li&gt;Haskell&amp;mdash;a&amp;nbsp;language for&amp;nbsp;geniuses by&amp;nbsp;geniuses&amp;mdash;even just for&amp;nbsp;the&amp;nbsp;sake of&amp;nbsp;knowing
how&amp;nbsp;smart one&amp;nbsp;must be&amp;nbsp;in&amp;nbsp;order to&amp;nbsp;program in&amp;nbsp;it,&lt;/li&gt;
&lt;li&gt;C, because most of&amp;nbsp;the&amp;nbsp;compilers, VM&amp;#39;s and&amp;nbsp;kernels are&amp;nbsp;implemented in&amp;nbsp;this language,&lt;/li&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/Python_%28programming_language%29"&gt;Python&lt;/a&gt;, &lt;a href="https://en.wikipedia.org/wiki/Ruby_%28programming_language%29"&gt;Ruby&lt;/a&gt; or&amp;nbsp;Perl&amp;mdash;one&amp;nbsp;of&amp;nbsp;the&amp;nbsp;scripting languages&amp;mdash;to&amp;nbsp;have a&amp;nbsp;tool for&amp;nbsp;everyday use.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id="toc_5"&gt;Having Doubts&lt;/h3&gt;

&lt;p&gt;The&amp;nbsp;most common reason for&amp;nbsp;not&amp;nbsp;learning another language is&amp;nbsp;the&amp;nbsp;lack of&amp;nbsp;time. These days,
not&amp;nbsp;every software developer is&amp;nbsp;a&amp;nbsp;total &lt;a href="https://en.wikipedia.org/wiki/Nerd"&gt;nerd&lt;/a&gt; that do&amp;nbsp;coding and&amp;nbsp;sleep on&amp;nbsp;the&amp;nbsp;same chair.
Some of&amp;nbsp;us&amp;nbsp;would like to&amp;nbsp;have a&amp;nbsp;life besides work. Sure, there&amp;#39;s nothing wrong with that,
yet&amp;nbsp;we&amp;nbsp;have to&amp;nbsp;remember that the&amp;nbsp;further in&amp;nbsp;the&amp;nbsp;process of&amp;nbsp;self-education,
the&amp;nbsp;less time it&amp;nbsp;takes to&amp;nbsp;learn new&amp;nbsp;stuff. An&amp;nbsp;expert polyglot programmer should be&amp;nbsp;able to&amp;nbsp;educate
himself, do&amp;nbsp;active menthoring and&amp;nbsp;write good-quality code, all&amp;nbsp;during a&amp;nbsp;highly productive
8-hour workday.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;One&amp;nbsp;must specialize in&amp;nbsp;order to&amp;nbsp;be&amp;nbsp;good&lt;/strong&gt; at&amp;nbsp;something. This statement is&amp;nbsp;quite often used
as&amp;nbsp;an&amp;nbsp;argument against polyglot programming. And&amp;nbsp;while the&amp;nbsp;statement in&amp;nbsp;itself is&amp;nbsp;very
true, there is&amp;nbsp;an&amp;nbsp;open question of&amp;nbsp;how&amp;nbsp;narrow a&amp;nbsp;succesful specialization should be.
Nobody is&amp;nbsp;a&amp;nbsp;master at&amp;nbsp;every language he&amp;nbsp;knows. That is&amp;nbsp;not&amp;nbsp;the&amp;nbsp;point.
We&amp;nbsp;learn more languages because we&amp;nbsp;want to&amp;nbsp;be&amp;nbsp;better software developers. We&amp;nbsp;want to&amp;nbsp;have broader
views, know strengths and&amp;nbsp;weeknesses of&amp;nbsp;the&amp;nbsp;languages we&amp;nbsp;know by&amp;nbsp;comparing them to&amp;nbsp;new&amp;nbsp;ones.
Besides that, keeping up-to-date knowledge in&amp;nbsp;more than five languages is&amp;nbsp;virtually impossible.&lt;/p&gt;

&lt;p&gt;At&amp;nbsp;some point, after mastering several languages, a&amp;nbsp;programmer may&amp;nbsp;already know most
of&amp;nbsp;the&amp;nbsp;features a&amp;nbsp;language can&amp;nbsp;have. What&amp;#39;s the&amp;nbsp;point of&amp;nbsp;learning another language
by&amp;nbsp;then...?
Well, it&amp;#39;s not&amp;nbsp;about language features. We&amp;nbsp;learn new&amp;nbsp;stuff to&amp;nbsp;have more and&amp;nbsp;more tools in&amp;nbsp;our&amp;nbsp;toolboxes. Knowledge of&amp;nbsp;many language features is&amp;nbsp;helpful when learning next languages, but&amp;nbsp;this
doesn&amp;#39;t mean another language isn&amp;#39;t worth learning. A&amp;nbsp;language may&amp;nbsp;have similar features to&amp;nbsp;the&amp;nbsp;one&amp;nbsp;you&amp;nbsp;already know, but&amp;nbsp;it&amp;nbsp;may&amp;nbsp;have a&amp;nbsp;better syntax, a&amp;nbsp;different target platform or&amp;nbsp;some detail, which
makes it&amp;nbsp;more suitable for&amp;nbsp;a&amp;nbsp;particular use&amp;nbsp;case.&lt;/p&gt;

&lt;p&gt;Another reason for&amp;nbsp;not&amp;nbsp;learning another language could be&amp;nbsp;that languages are&amp;nbsp;easy to&amp;nbsp;learn
in&amp;nbsp;comparison with &lt;a href="https://en.wikipedia.org/wiki/Software_framework"&gt;frameworks&lt;/a&gt;. In&amp;nbsp;other words&amp;mdash;&lt;strong&gt;learning a&amp;nbsp;framework takes more
time&lt;/strong&gt; than learning a&amp;nbsp;language.
This is&amp;nbsp;true for&amp;nbsp;commercially standardized frameworks with very long specifications
(e.g. &lt;a href="https://en.wikipedia.org/wiki/Enterprise_JavaBeans"&gt;EJB&lt;/a&gt;), yet&amp;nbsp;there are&amp;nbsp;many frameworks, which require very little learning and&amp;nbsp;almost
no&amp;nbsp;configuration. All&amp;nbsp;thanks to&amp;nbsp;the&amp;nbsp;concept called &lt;a href="https://en.wikipedia.org/wiki/Convention_over_configuration"&gt;Convention over Configuration&lt;/a&gt; (CoC),
popularized by&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/Ruby_on_Rails"&gt;Ruby on&amp;nbsp;Rails&lt;/a&gt; (RoR) framework.
Today&amp;#39;s frameworks learn from each other and&amp;nbsp;adopt the&amp;nbsp;same good solutions.
Generalized learning skill is&amp;nbsp;also applicable in&amp;nbsp;here.&lt;/p&gt;

&lt;h3 id="toc_6"&gt;Choosing The&amp;nbsp;Next Language&lt;/h3&gt;

&lt;p&gt;So, you&amp;#39;re a&amp;nbsp;programmer with experience of&amp;nbsp;a&amp;nbsp;year or&amp;nbsp;two&amp;nbsp;and&amp;nbsp;you&amp;nbsp;use&amp;nbsp;one&amp;nbsp;programming language. What
should you&amp;nbsp;do&amp;nbsp;next? There are&amp;nbsp;so&amp;nbsp;many options out&amp;nbsp;there...&lt;/p&gt;

&lt;p&gt;My&amp;nbsp;advice is&amp;nbsp;to&amp;nbsp;take a&amp;nbsp;look at&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/Programming_paradigm"&gt;programming paradigms&lt;/a&gt; on&amp;nbsp;Wikipedia and&amp;nbsp;choose something
that is&amp;nbsp;&lt;strong&gt;totally different from what you&amp;nbsp;already know&lt;/strong&gt;. If&amp;nbsp;you&amp;nbsp;know an&amp;nbsp;imperative
language, pick a&amp;nbsp;declarative one. If&amp;nbsp;you&amp;nbsp;know meta-programming with reflection, try&amp;nbsp;a&amp;nbsp;language
with template meta-programming. Choose a&amp;nbsp;language with different model of&amp;nbsp;concurrency, different
features of&amp;nbsp;the&amp;nbsp;type system, different overall complexity, and&amp;nbsp;even different target platform.&lt;/p&gt;

&lt;p&gt;It&amp;nbsp;is&amp;nbsp;probably a&amp;nbsp;good idea to&amp;nbsp;check out&amp;nbsp;which languages are&amp;nbsp;in&amp;nbsp;demand before choosing the&amp;nbsp;next
step in&amp;nbsp;your learning process. &lt;a href="http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html"&gt;Tiobe Index&lt;/a&gt; and&amp;nbsp;&lt;a href="http://spectrum.ieee.org/computing/software/the-2015-top-ten-programming-languages"&gt;IEEE Spectrum&lt;/a&gt; are&amp;nbsp;good sources
of&amp;nbsp;information about trends in&amp;nbsp;programming language popularity.&lt;/p&gt;

&lt;h3 id="toc_7"&gt;Making a&amp;nbsp;Decision&lt;/h3&gt;

&lt;p&gt;When still in&amp;nbsp;doubt about starting to&amp;nbsp;learn another programming language, you&amp;nbsp;may&amp;nbsp;ask&amp;nbsp;yourself some
of&amp;nbsp;the&amp;nbsp;following questions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Is&amp;nbsp;programming my&amp;nbsp;passion?&lt;/li&gt;
&lt;li&gt;How&amp;nbsp;much of&amp;nbsp;a&amp;nbsp;salary would I&amp;nbsp;like to&amp;nbsp;receive?&lt;/li&gt;
&lt;li&gt;What are&amp;nbsp;my&amp;nbsp;priorities is&amp;nbsp;life?&lt;/li&gt;
&lt;li&gt;Will I&amp;nbsp;move to&amp;nbsp;management at&amp;nbsp;some point?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Not&amp;nbsp;everyone is&amp;nbsp;ought to&amp;nbsp;be&amp;nbsp;the&amp;nbsp;best, but&amp;nbsp;there is&amp;nbsp;a&amp;nbsp;great, &lt;strong&gt;forever unsatisfied need for&amp;nbsp;more
experts&lt;/strong&gt; in&amp;nbsp;the&amp;nbsp;field of&amp;nbsp;software development. Experience of&amp;nbsp;an&amp;nbsp;average programmer is&amp;nbsp;slowly
declining as&amp;nbsp;beginners are&amp;nbsp;produced by&amp;nbsp;universities in&amp;nbsp;greater quantities every year. I&amp;nbsp;encourage
you&amp;nbsp;to&amp;nbsp;become an&amp;nbsp;expert and&amp;nbsp;make things just slightly better for&amp;nbsp;everyone.&lt;/p&gt;

&lt;p&gt;I&amp;nbsp;hope that this article provides information helpful in&amp;nbsp;making a&amp;nbsp;decision about a&amp;nbsp;career.
Which path did&amp;nbsp;I&amp;nbsp;take? I&amp;nbsp;think that&amp;#39;s obvious.
But&amp;nbsp;what do&amp;nbsp;you&amp;nbsp;think? Are&amp;nbsp;you&amp;nbsp;willing to&amp;nbsp;become a&amp;nbsp;polyglot programmer?&lt;/p&gt;

&lt;h3 id="toc_8"&gt;References&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Detailed information about &lt;a href="https://www.facebook.com/notes/facebook-engineering/the-full-stack-part-i/461505383919/?_fb_noscript=1"&gt;how&amp;nbsp;full-stack developers are&amp;nbsp;good at&amp;nbsp;performance and&amp;nbsp;optimization
work&lt;/a&gt; can&amp;nbsp;be&amp;nbsp;found in&amp;nbsp;Carlos Bueno&amp;#39;s article on&amp;nbsp;Facebook&amp;#39;s technical blog.&lt;/li&gt;
&lt;li&gt;Good &lt;a href="http://www.wikihow.com/Become-Skilled-at-Learning-Programming-Languages"&gt;tutorial on&amp;nbsp;how&amp;nbsp;to&amp;nbsp;learn multiple programming languages&lt;/a&gt; can&amp;nbsp;be&amp;nbsp;found on&amp;nbsp;WikiHow.&lt;/li&gt;
&lt;li&gt;Robert C. Martin argues that &lt;a href="http://thecleancoder.blogspot.com/2010/08/why-clojure.html"&gt;Clojure is&amp;nbsp;the&amp;nbsp;best pick for&amp;nbsp;a&amp;nbsp;functional
language&lt;/a&gt; on&amp;nbsp;his&amp;nbsp;blog.&lt;/li&gt;
&lt;li&gt;Question on&amp;nbsp;&lt;a href="http://programmers.stackexchange.com/questions/43729/learning-multiple-languages-simultaneously"&gt;Learning Multiple Languages Simultaneously&lt;/a&gt; at&amp;nbsp;programmers.stackexchange
forum contains information on&amp;nbsp;pros and&amp;nbsp;cons of&amp;nbsp;learning multiple languages at&amp;nbsp;once.&lt;/li&gt;
&lt;li&gt;Lauren Orsini describes the&amp;nbsp;story behind Facebook&amp;#39;s Hack language in&amp;nbsp;article titled &lt;a href="http://readwrite.com/2014/06/17/apple-swift-facebook-hack-google-dart"&gt;How&amp;nbsp;Many
Languages Do&amp;nbsp;Developers Need To&amp;nbsp;Know?&lt;/a&gt; posted on&amp;nbsp;ReadWrite tech news website.&lt;/li&gt;
&lt;li&gt;Coding Dojo offers some &lt;a href="http://www.codingdojo.com/blog/how-many-programming-languages-should-i-learn/"&gt;good advice on&amp;nbsp;what to&amp;nbsp;focus on&amp;nbsp;when learning new&amp;nbsp;languages&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Comprehensive discussion and&amp;nbsp;suggestions of&amp;nbsp;languages to&amp;nbsp;learn can&amp;nbsp;be&amp;nbsp;found in&amp;nbsp;thread
on&amp;nbsp;programmers.stackexchange titled &lt;a href="http://programmers.stackexchange.com/questions/136133/why-should-i-learn-a-new-programming-language"&gt;(Why) Should I&amp;nbsp;learn a&amp;nbsp;new&amp;nbsp;programming language?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Big&amp;nbsp;Think interviewed &lt;a href="https://www.youtube.com/watch?v=NvWTnIoQZj4"&gt;Bjarne Stroustrup&lt;/a&gt; and&amp;nbsp;&lt;a href="https://www.youtube.com/watch?v=LR8fQiskYII"&gt;Larry Wall&lt;/a&gt; about five programming
languages everyone should know. Both interviews are&amp;nbsp;available on&amp;nbsp;Youtube.&lt;/li&gt;
&lt;li&gt;Kira M. Newman lists &lt;a href="http://tech.co/3-reasons-learn-multiple-programming-languages-2015-09"&gt;her&amp;nbsp;reasons for&amp;nbsp;learning many programming languages&lt;/a&gt; on&amp;nbsp;tech.co.&lt;/li&gt;
&lt;li&gt;Mary Branscombe describes her&amp;nbsp;concept of&amp;nbsp;&lt;a href="http://blog.pluralsight.com/more-programming-languages-more-money"&gt;causality between more programming languages and&amp;nbsp;more
money&lt;/a&gt; on&amp;nbsp;pluralsight.com blog.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id="toc_9"&gt;Annotations&lt;/h3&gt;

&lt;p&gt;&lt;a id="origins-of-bdd"&gt;&lt;/a&gt;
&lt;sup class="annot"&gt;&lt;a href="#origins-of-bdd"&gt; [ 1 ] &lt;/a&gt;&lt;/sup&gt; Ultimate precursor of&amp;nbsp;this style of&amp;nbsp;testing is&amp;nbsp;&lt;a href="http://jbehave.org/"&gt;JBehave&lt;/a&gt;
framework for&amp;nbsp;Java.&lt;/p&gt;

&lt;p&gt;&lt;a id="origins-of-preconditions"&gt;&lt;/a&gt;
&lt;sup class="annot"&gt;&lt;a href="#origins-of-preconditions"&gt; [ 2 ] &lt;/a&gt;&lt;/sup&gt; Preconditions class from Java is&amp;nbsp;itself based on&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/Eiffel_%28programming_language%29"&gt;Eifel&lt;/a&gt;&amp;#39;s
&lt;a href="https://archive.eiffel.com/doc/online/eiffel50/intro/language/invitation-07.html"&gt;require&lt;/a&gt; keyword, which was&amp;nbsp;part of&amp;nbsp;one&amp;nbsp;of&amp;nbsp;the&amp;nbsp;early &lt;a href="https://en.wikipedia.org/wiki/Design_by_contract"&gt;Design by&amp;nbsp;Contract&lt;/a&gt;
utility implementations.&lt;/p&gt;
</description>
    </item>
    <item>
      <title>Distributed Transactions</title>
      <link>http://softwarephilosophy.ninja/distributed-transactions</link>
      <pubDate>2015-11-24</pubDate>
      <description>&lt;p&gt;Recently, I&amp;nbsp;had&amp;nbsp;few&amp;nbsp;email conversations with past job&amp;nbsp;coleague of&amp;nbsp;mine. The&amp;nbsp;most challenging one&amp;nbsp;was&amp;nbsp;on&amp;nbsp;the&amp;nbsp;topic of&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/Distributed_transaction"&gt;distributed transactions&lt;/a&gt;. It&amp;nbsp;turns out&amp;nbsp;we&amp;nbsp;both had&amp;nbsp;some experience with them,
but&amp;nbsp;our&amp;nbsp;opinions were rather different. As&amp;nbsp;this topic is&amp;nbsp;pretty hot&amp;nbsp;these days, I&amp;nbsp;decided
to&amp;nbsp;write down our&amp;nbsp;insights in&amp;nbsp;this article. The&amp;nbsp;goal is&amp;nbsp;to&amp;nbsp;list disadvantages of&amp;nbsp;distributed
transactions, show how&amp;nbsp;they are&amp;nbsp;overused, provide an&amp;nbsp;alternative approach, and&amp;nbsp;specify conditions
under which each technique may&amp;nbsp;be&amp;nbsp;applied.&lt;/p&gt;

&lt;h2 id="toc_0"&gt;Why&amp;nbsp;Not?&lt;/h2&gt;

&lt;p&gt;Software developers are&amp;nbsp;attracted to&amp;nbsp;distributed transactions because they provide
all&amp;#8209;or&amp;#8209;nothing
solution across multiple database resources. Standardized interfaces of&amp;nbsp;a&amp;nbsp;distributed resource
(&lt;a href="https://en.wikipedia.org/wiki/X/Open_XA"&gt;XA&lt;/a&gt;) and&amp;nbsp;standardized transactional &lt;abbr title="Application Programming Interface"&gt;API&lt;/abbr&gt;s&amp;nbsp;(&lt;a href="https://en.wikipedia.org/wiki/Java_Transaction_API"&gt;JTA&lt;/a&gt;, &lt;a href="https://github.com/repoze"&gt;repoze&lt;/a&gt;) greatly reduce the&amp;nbsp;time-cost of&amp;nbsp;applying this technique. It&amp;nbsp;results in&amp;nbsp;less code written, because domain logic is&amp;nbsp;free of&amp;nbsp;transaction-related code. On&amp;nbsp;the&amp;nbsp;other hand,
there are&amp;nbsp;many downsides to&amp;nbsp;distributed transactions.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href="https://en.wikipedia.org/wiki/Two-phase_commit_protocol"&gt;Two&amp;nbsp;Phase Commit&lt;/a&gt;&lt;sup&gt;&lt;a href="#advanced-commitment-protocols"&gt;1&lt;/a&gt;&lt;/sup&gt; lowers maximum &lt;a href="https://en.wikipedia.org/wiki/Throughput"&gt;throughput&lt;/a&gt; of&amp;nbsp;the&amp;nbsp;system&lt;/strong&gt;.
The&amp;nbsp;more nodes are&amp;nbsp;involved in&amp;nbsp;the&amp;nbsp;transaction, the&amp;nbsp;lower throughput is&amp;nbsp;achievable. Cost of&amp;nbsp;needed hardware is&amp;nbsp;increased.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Risk of&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/Resource_contention"&gt;contention&lt;/a&gt; grows with number of&amp;nbsp;users&lt;/strong&gt;. More contention affects
&lt;a href="https://en.wikipedia.org/wiki/Computer_performance"&gt;performance&lt;/a&gt; and&amp;nbsp;limits &lt;a href="https://en.wikipedia.org/wiki/Scalability"&gt;scalability&lt;/a&gt; to&amp;nbsp;a&amp;nbsp;point where performance becomes
unacceptably low. Performance problems can&amp;nbsp;be&amp;nbsp;resolved (in&amp;nbsp;retrospective) by&amp;nbsp;optimizing the&amp;nbsp;data
model and&amp;nbsp;re-designing the&amp;nbsp;transactions, but&amp;nbsp;it&amp;nbsp;means that a&amp;nbsp;system built using
distributed transactions will never be&amp;nbsp;scale-agnostic&lt;sup&gt;&lt;a href="#shared-nothing"&gt;2&lt;/a&gt;&lt;/sup&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;All-or-nothing &lt;a href="https://en.wikipedia.org/wiki/Availability"&gt;availability&lt;/a&gt;&lt;/strong&gt;. If&amp;nbsp;one&amp;nbsp;resource inside a&amp;nbsp;transaction is&amp;nbsp;unavailable,
whole operation must fail. Partial availability of&amp;nbsp;the&amp;nbsp;system is&amp;nbsp;not&amp;nbsp;possible. What&amp;#39;s more,
availability of&amp;nbsp;a&amp;nbsp;single operation is&amp;nbsp;inversely proportional to&amp;nbsp;number of&amp;nbsp;resources at&amp;nbsp;use&amp;nbsp;in&amp;nbsp;the&amp;nbsp;transaction. A&amp;nbsp;system containing 5 resources, each 99.999 % available, will be&amp;nbsp;availabile
&lt;code&gt;pow(99.999, 5) ~= 99.995&lt;/code&gt; % of&amp;nbsp;the&amp;nbsp;time.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;All&amp;nbsp;resources must implement the&amp;nbsp;same transactional &lt;abbr title="Application Programming
Interface"&gt;API&lt;/abbr&gt;&lt;/strong&gt;. If&amp;nbsp;a&amp;nbsp;resource don&amp;#39;t natively implement required interface, an&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/Adapter_pattern"&gt;adapter&lt;/a&gt;, which implements it, must be&amp;nbsp;added to&amp;nbsp;the&amp;nbsp;system. This increases overall system
complexity because of&amp;nbsp;additional dependency added.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Distributed transaction is&amp;nbsp;just a&amp;nbsp;technical candy&lt;/strong&gt;. The&amp;nbsp;concept is&amp;nbsp;based on&amp;nbsp;the&amp;nbsp;assumption
that transactions&lt;sup&gt;&lt;a href="#define-transaction"&gt;4&lt;/a&gt;&lt;/sup&gt; between subsystems are&amp;nbsp;a&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/Cross-cutting_concern"&gt;cross-cutting concern&lt;/a&gt;
(like logging or&amp;nbsp;concurrency), while in&amp;nbsp;true they should be&amp;nbsp;treated as&amp;nbsp;parts of&amp;nbsp;program&amp;#39;s
&lt;a href="https://en.wikipedia.org/wiki/Business_logic"&gt;domain logic&lt;/a&gt;. Generic implementation of&amp;nbsp;a&amp;nbsp;distributed transaction is&amp;nbsp;strictly technical
and&amp;nbsp;very complicated. Thinking about errors in&amp;nbsp;the&amp;nbsp;second phase of&amp;nbsp;&lt;abbr title="Two
Phase Commit"&gt;2PC&lt;/abbr&gt; is&amp;nbsp;hard and&amp;nbsp;requires detailed knowledge of&amp;nbsp;the&amp;nbsp;commit
protocol&lt;sup&gt;&lt;a href="#2pc-fail-probability"&gt;5&lt;/a&gt;&lt;/sup&gt;, while transaction implemented as&amp;nbsp;part of&amp;nbsp;entity&amp;#39;s interface is&amp;nbsp;always
&lt;a href="https://en.wikipedia.org/wiki/Simplicity"&gt;simple&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id="toc_1"&gt;Transaction&lt;sup&gt;&lt;a href="#define-transaction"&gt;4&lt;/a&gt;&lt;/sup&gt; Inside Contract&lt;/h2&gt;

&lt;p&gt;Let&amp;#39;s say&amp;nbsp;&lt;strong&gt;we&amp;nbsp;have to&amp;nbsp;model a&amp;nbsp;newsletter subscription system&lt;/strong&gt; with prizes for&amp;nbsp;first
10 subscribers. Messages must be&amp;nbsp;sent to&amp;nbsp;winners during successful subscription. We&amp;nbsp;have two&amp;nbsp;resources to&amp;nbsp;be&amp;nbsp;used inside a&amp;nbsp;distributed transaction&amp;mdash;a&amp;nbsp;database for&amp;nbsp;storing subscriber
entities and&amp;nbsp;a&amp;nbsp;mail server for&amp;nbsp;sending emails to&amp;nbsp;subscribers. Each time a&amp;nbsp;subscriber is&amp;nbsp;added
to&amp;nbsp;the&amp;nbsp;database, distributed transaction must be&amp;nbsp;set&amp;nbsp;up. After adding subscriber, we&amp;nbsp;have
to&amp;nbsp;count all&amp;nbsp;subscribers added so&amp;nbsp;far. If&amp;nbsp;there is&amp;nbsp;less than or&amp;nbsp;equal 10, add&amp;nbsp;an&amp;nbsp;email to&amp;nbsp;send
in&amp;nbsp;the&amp;nbsp;transaction. If&amp;nbsp;all&amp;nbsp;is&amp;nbsp;well, commit.&lt;/p&gt;

&lt;p&gt;The&amp;nbsp;relationship between subscriber entities and&amp;nbsp;sent emails, which is&amp;nbsp;an&amp;nbsp;essential part
of&amp;nbsp;the&amp;nbsp;model, gets marginalized when using distributed transactions (hidden inside
a&amp;nbsp;technical solution).
All&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/ACID"&gt;&lt;abbr title="Atomicity, Consistency, Isolation, Durability"&gt;ACID&lt;/abbr&gt;&lt;/a&gt;
properties are&amp;nbsp;kept, yet&amp;nbsp;not&amp;nbsp;all&amp;nbsp;of&amp;nbsp;them are&amp;nbsp;required across all&amp;nbsp;resources. Next
paragraph describe alternative model, wich doesn&amp;#39;t use&amp;nbsp;distributed transactions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;After checking the&amp;nbsp;database for&amp;nbsp;a&amp;nbsp;winner, we&amp;nbsp;can&amp;nbsp;store another entity that represents
an&amp;nbsp;email. Then write a&amp;nbsp;simple &lt;a href="https://en.wikipedia.org/wiki/Daemon_%28computing%29"&gt;daemon&lt;/a&gt; that periodically checks the&amp;nbsp;database for&amp;nbsp;unsent emails, send them and&amp;nbsp;mark them in&amp;nbsp;database as&amp;nbsp;sent.&lt;/strong&gt; Done.
Operations are&amp;nbsp;now&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/Asynchronous_system"&gt;asynchronous&lt;/a&gt;, transactions are&amp;nbsp;explicitly reflected in&amp;nbsp;the&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/Design_by_contract"&gt;contracts&lt;/a&gt; between subsystems.
In&amp;nbsp;case of&amp;nbsp;an&amp;nbsp;error occuring between sending and&amp;nbsp;marking, message will be&amp;nbsp;sent second time
(in&amp;nbsp;the&amp;nbsp;next &lt;a href="https://en.wikipedia.org/wiki/Batch_processing"&gt;batch&lt;/a&gt;), which is&amp;nbsp;acceptable. No&amp;nbsp;distributed transactions needed.&lt;/p&gt;

&lt;p&gt;&lt;img alt="A drawing of&amp;nbsp;envelope and&amp;nbsp;a&amp;nbsp;database field list. Fields listen in&amp;nbsp;white: id, subscriber_id, subject, message. Green color and&amp;nbsp;plus sign suggests that another field is&amp;nbsp;being added: is_sent." src="/assets/media/email-contract.png"&gt;&lt;/p&gt;

&lt;h2 id="toc_2"&gt;Tradeoffs&lt;/h2&gt;

&lt;p&gt;Starting a&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/Greenfield_project"&gt;green-field project&lt;/a&gt; is&amp;nbsp;the&amp;nbsp;best time to&amp;nbsp;consider abandoning distributed
transactions technique. Situation is&amp;nbsp;less obvious when reality imposes many constrains.
Following questions may&amp;nbsp;be&amp;nbsp;helpful in&amp;nbsp;making a&amp;nbsp;decision in&amp;nbsp;this matter.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Are&amp;nbsp;all&amp;nbsp;&lt;abbr title="Atomicity, Consistency, Isolation, Durability"&gt;ACID&lt;/abbr&gt; properties
needed accross distributed resources?&lt;/li&gt;
&lt;li&gt;What is&amp;nbsp;the&amp;nbsp;probability of&amp;nbsp;an&amp;nbsp;error in&amp;nbsp;the&amp;nbsp;second phase of&amp;nbsp;&lt;abbr title="Two Phase Commit"&gt;2PC&lt;/abbr&gt;?&lt;/li&gt;
&lt;li&gt;Is&amp;nbsp;an&amp;nbsp;inconsistency after an&amp;nbsp;error in&amp;nbsp;&lt;abbr title="Two Phase Commit"&gt;2PC&lt;/abbr&gt; acceptable?&lt;/li&gt;
&lt;li&gt;What is&amp;nbsp;the&amp;nbsp;cost of&amp;nbsp;manually removing such an&amp;nbsp;inconsistency?&lt;/li&gt;
&lt;li&gt;What is&amp;nbsp;the&amp;nbsp;cost of&amp;nbsp;automatically removing such an&amp;nbsp;inconsistency?&lt;/li&gt;
&lt;li&gt;What are&amp;nbsp;the&amp;nbsp;requirements for&amp;nbsp;availability?&lt;/li&gt;
&lt;li&gt;What are&amp;nbsp;the&amp;nbsp;requirements for&amp;nbsp;scalability?&lt;/li&gt;
&lt;li&gt;How&amp;nbsp;much of&amp;nbsp;operations consist of&amp;nbsp;communication with legacy systems?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Very often &lt;strong&gt;the&amp;nbsp;most significant factor will be&amp;nbsp;the&amp;nbsp;time-cost comparison&lt;/strong&gt; between
distributed-transaction-based solution (containing cost of&amp;nbsp;hardware) and&amp;nbsp;solution with transactions
inside contracts.&lt;/p&gt;

&lt;p&gt;Dedicated solutions are&amp;nbsp;often better than general ones, but&amp;nbsp;since they are&amp;nbsp;dedicated, they may&amp;nbsp;be&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/Software_incompatibility"&gt;not&amp;nbsp;compatible&lt;/a&gt; with legacy systems. Much may&amp;nbsp;depend on&amp;nbsp;company profile and&amp;nbsp;policies.
Start-ups must be&amp;nbsp;innovative and&amp;nbsp;will tend towards dedicated solutions. Corporations seek
to&amp;nbsp;standardize things, so&amp;nbsp;they prefer vastly used and&amp;nbsp;generally accepted technology.&lt;/p&gt;

&lt;h2 id="toc_3"&gt;References&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&amp;quot;&lt;a href="http://c2.com/cgi/wiki?DistributedTransactionsAreEvil"&gt;Distributed Transactions are&amp;nbsp;Evil&lt;/a&gt;&amp;quot; and&amp;nbsp;&amp;quot;&lt;a href="http://c2.com/cgi/wiki?AvoidingDistributedTransactions"&gt;Avoiding Distributed Transactions&lt;/a&gt;&amp;quot; pages
on&amp;nbsp;Cunningham &amp;amp; Cunningham wiki touch many problems connected with the&amp;nbsp;topic.&lt;/li&gt;
&lt;li&gt;Gregor Hohpe (ToughWorks) wrote a&amp;nbsp;paper titled &amp;quot;&lt;a href="http://www.enterpriseintegrationpatterns.com/docs/IEEE_Software_Design_2PC.pdf"&gt;Your Coffee Shop Doesn&#x2019;t Use&amp;nbsp;Two-Phase
Commit&lt;/a&gt;&amp;quot;, in&amp;nbsp;which he&amp;nbsp;states that real-world workflows are&amp;nbsp;often asynchronuous, concurrent
and&amp;nbsp;simple. He&amp;nbsp;suggests that information systems should be&amp;nbsp;modeled the&amp;nbsp;same way.&lt;/li&gt;
&lt;li&gt;In&amp;nbsp;white paper titled &amp;quot;&lt;a href="http://www.ics.uci.edu/%7Ecs223/papers/cidr07p15.pdf"&gt;Life beyond Distributed Transactions&lt;/a&gt;&amp;quot; Pat&amp;nbsp;Helland (Amazon)
describes the&amp;nbsp;impact that distributed transactions have on&amp;nbsp;scalability.&lt;/li&gt;
&lt;li&gt;Kevin Hoffman, in&amp;nbsp;his&amp;nbsp;article on&amp;nbsp;&lt;a href="https://medium.com/@KevinHoffman/distributed-transactions-in-a-cloud-native-microservice-world-7528f8baa8da#.3iik7z52h"&gt;distributed transactions in&amp;nbsp;microservice environment&lt;/a&gt;,
suggests that the&amp;nbsp;need of&amp;nbsp;distributed transactions may&amp;nbsp;indicate an&amp;nbsp;violation of&amp;nbsp;&lt;abbr title="Single Responsibility Principle"&gt;SRP&lt;/abbr&gt;.&lt;/li&gt;
&lt;li&gt;In&amp;nbsp;his&amp;nbsp;&lt;a href="http://www.addsimplicity.com/adding_simplicity_an_engi/2006/12/2pc_or_not_2pc_.html"&gt;article on&amp;nbsp;2PC&lt;/a&gt;, Dan&amp;nbsp;Pritchett writes about how&amp;nbsp;distributed transactions affect
performance and&amp;nbsp;availability. He&amp;nbsp;also provides a&amp;nbsp;simple alternative.&lt;/li&gt;
&lt;li&gt;On&amp;nbsp;his&amp;nbsp;personal website, Martin Fowler (ToughWorks) wrote a&amp;nbsp;short essay about
&lt;a href="http://martinfowler.com/bliki/Transactionless.html"&gt;transactionlessness in&amp;nbsp;eBay&amp;#39;s architecture&lt;/a&gt;. References are&amp;nbsp;worth checking out.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id="toc_4"&gt;Annotations&lt;/h2&gt;

&lt;p&gt;&lt;a id="advanced-commitment-protocols" href="#advanced-commitment-protocols"&gt;&lt;sup&gt;{1}&lt;/sup&gt;&lt;/a&gt;
More &lt;a href="https://en.wikipedia.org/wiki/Atomic_commit"&gt;advanced commitment protocols&lt;/a&gt; are&amp;nbsp;out&amp;nbsp;of&amp;nbsp;scope of&amp;nbsp;this document. They share many
of&amp;nbsp;the&amp;nbsp;disadvantages listed in&amp;nbsp;here.&lt;/p&gt;

&lt;p&gt;&lt;a id="shared-nothing" href="#shared-nothing"&gt;&lt;sup&gt;{2}&lt;/sup&gt;&lt;/a&gt;
With exception of&amp;nbsp;data models designed for&amp;nbsp;no&amp;nbsp;contention. &lt;a href="https://en.wikipedia.org/wiki/Shared_nothing_architecture"&gt;Shared Nothing&lt;/a&gt; architectural
pattern satisfies non-functional requirement of&amp;nbsp;no&amp;nbsp;contention.&lt;/p&gt;

&lt;p&gt;&lt;a id="define-transaction" href="#define-transaction"&gt;&lt;sup&gt;{4}&lt;/sup&gt;&lt;/a&gt;
Term &amp;lsquo;transaction&amp;rsquo; (not&amp;nbsp;distributed transaction) is&amp;nbsp;used throughout this article
in&amp;nbsp;traditional (non-technical) meaning &amp;mdash; an&amp;nbsp;execution of&amp;nbsp;a&amp;nbsp;deal.&lt;/p&gt;

&lt;p&gt;&lt;a id="2pc-fail-probability" href="#2pc-fail-probability"&gt;&lt;sup&gt;{5}&lt;/sup&gt;&lt;/a&gt;
Probability of&amp;nbsp;error during second phase is&amp;nbsp;extremely low&amp;nbsp;(years may&amp;nbsp;pass before one&amp;nbsp;happens).
Commit errors are&amp;nbsp;often ignored by&amp;nbsp;software developers (data integrity must be&amp;nbsp;fixed manually
or&amp;nbsp;restored from backup after the&amp;nbsp;incident).&lt;/p&gt;
</description>
    </item>
    <item>
      <title>Go to SPA or Just REST?</title>
      <link>http://softwarephilosophy.ninja/go-to-spa-or-just-rest</link>
      <pubDate>2015-11-08</pubDate>
      <description>&lt;p&gt;Single Page Application (&lt;a href="https://en.wikipedia.org/wiki/Single-page_application"&gt;SPA&lt;/a&gt;) is&amp;nbsp;an&amp;nbsp;old, yet&amp;nbsp;only lately popular way&amp;nbsp;of&amp;nbsp;creating programs
for&amp;nbsp;the&amp;nbsp;web. The&amp;nbsp;idea is&amp;nbsp;to&amp;nbsp;fetch most of&amp;nbsp;the&amp;nbsp;resources from the&amp;nbsp;server when user loads
a&amp;nbsp;website and&amp;nbsp;then, as&amp;nbsp;the&amp;nbsp;user interacts with the&amp;nbsp;site, fetch and&amp;nbsp;store data via&amp;nbsp;calls to&amp;nbsp;an&amp;nbsp;&lt;abbr title="Application Programming Interface"&gt;API&lt;/abbr&gt; endpoint
(typically &lt;a href="https://en.wikipedia.org/wiki/Representational_State_Transfer"&gt;REST&lt;/a&gt;).
In&amp;nbsp;effect, page is&amp;nbsp;never reloaded, wich makes the&amp;nbsp;expecience more smooth than with traditional
webpage. This article highlights main characteristics of&amp;nbsp;SPA&amp;nbsp;and&amp;nbsp;specifies conditions under
which the&amp;nbsp;concept is&amp;nbsp;preferably applicable.&lt;/p&gt;

&lt;p&gt;With recent advent of&amp;nbsp;client-side frameworks (&lt;a href="https://angularjs.org/"&gt;AngularJS&lt;/a&gt;, &lt;a href="http://emberjs.com/"&gt;EmberJS&lt;/a&gt;, &lt;a href="https://www.meteor.com/"&gt;MeteorJS&lt;/a&gt;,
&lt;a href="https://facebook.github.io/react/"&gt;ReactJS&lt;/a&gt;), SPA&amp;nbsp;gained much more attention in&amp;nbsp;the&amp;nbsp;community. New&amp;nbsp;frameworks provide new&amp;nbsp;abstractions that force good client-side programming techniques. Creating rich web&amp;nbsp;clients is&amp;nbsp;now&amp;nbsp;much easier and&amp;nbsp;faster. Despite the&amp;nbsp;benefits that come with new&amp;nbsp;frameworks, SPA&amp;nbsp;isn&amp;#39;t
always considered the&amp;nbsp;right way&amp;nbsp;to&amp;nbsp;write software for&amp;nbsp;the&amp;nbsp;web&amp;nbsp;and&amp;nbsp;not&amp;nbsp;all&amp;nbsp;new&amp;nbsp;web&amp;nbsp;projects
end&amp;nbsp;up&amp;nbsp;being SPA.&lt;/p&gt;

&lt;h2 id="toc_0"&gt;Pros&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Application can&amp;nbsp;be&amp;nbsp;usable when offline&lt;/strong&gt;. An&amp;nbsp;example of&amp;nbsp;popular SPA, that is&amp;nbsp;connection-aware,
is&amp;nbsp;GMail. When user goes offline, functionality is&amp;nbsp;very limited, but&amp;nbsp;the&amp;nbsp;app&amp;nbsp;is&amp;nbsp;still
usable. This makes the&amp;nbsp;client &lt;a href="https://en.wikipedia.org/wiki/Fault_tolerance"&gt;fault-tolerant&lt;/a&gt;. Things can&amp;nbsp;be&amp;nbsp;taken one&amp;nbsp;step further. Since
HTML5 brings multiple client-side storage technology to&amp;nbsp;the&amp;nbsp;table, server-side storage
may&amp;nbsp;be&amp;nbsp;used only as&amp;nbsp;backup and&amp;nbsp;synchronization medium&lt;sup&gt;&lt;a href="#ria"&gt;1&lt;/a&gt;&lt;/sup&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Application can&amp;nbsp;respond very fast after each click&lt;/strong&gt;. According to&amp;nbsp;research done at&amp;nbsp;Google,
user feels that application is&amp;nbsp;fast and&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/Responsiveness"&gt;responsive&lt;/a&gt; only if&amp;nbsp;it&amp;nbsp;gives him&amp;nbsp;a&amp;nbsp;feedback after less
than 200 ms. If&amp;nbsp;operation lasts longer (potentially), an&amp;nbsp;indication of&amp;nbsp;operation
in&amp;nbsp;progress should appear (e.g. spinner or&amp;nbsp;progress bar). These requirements may&amp;nbsp;be&amp;nbsp;hard
to&amp;nbsp;achieve with traditional server-side HTML rendering. SPA&amp;nbsp;makes it&amp;nbsp;much easier.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;API&amp;nbsp;is&amp;nbsp;a&amp;nbsp;well defined boundary that slows down software entropy&lt;/strong&gt;. Sole fact that there
is&amp;nbsp;an&amp;nbsp;API&amp;nbsp;to&amp;nbsp;be&amp;nbsp;designed forces a&amp;nbsp;very good practice of&amp;nbsp;actually designing the&amp;nbsp;software.
Lack of&amp;nbsp;well defined boundaries may&amp;nbsp;(in&amp;nbsp;time) lower &lt;a href="https://en.wikipedia.org/wiki/Maintainability"&gt;maintainability&lt;/a&gt; of&amp;nbsp;a&amp;nbsp;system, because
of&amp;nbsp;accidental inter-dependencies being added.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Moving presentation logic to&amp;nbsp;the&amp;nbsp;client reduces the&amp;nbsp;need for&amp;nbsp;server resources&lt;/strong&gt;. Total cost
of&amp;nbsp;the&amp;nbsp;system may&amp;nbsp;be&amp;nbsp;reduced significantly, depending on&amp;nbsp;the&amp;nbsp;technology at&amp;nbsp;use&amp;nbsp;and&amp;nbsp;size
of&amp;nbsp;the&amp;nbsp;part that handles &lt;a href="https://en.wikipedia.org/wiki/Presentation_logic"&gt;presentation&lt;/a&gt;&lt;sup&gt;&lt;a href="#jsf-resource-hogging"&gt;3&lt;/a&gt;&lt;/sup&gt;. This point gains weight
with rescent popularization of&amp;nbsp;many &lt;a href="https://en.wikipedia.org/wiki/Cloud_computing#Infrastructure_as_a_service_.28IaaS.29"&gt;&lt;abbr title="Infrastructure as&amp;nbsp;a&amp;nbsp;Service"&gt;IaaS&lt;/abbr&gt;&lt;/a&gt; solutions, where payments are&amp;nbsp;directly dependent on&amp;nbsp;resources at&amp;nbsp;use.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Modern ways of&amp;nbsp;creating sofware increase morale&lt;/strong&gt;. New&amp;nbsp;things are&amp;nbsp;more exciting and&amp;nbsp;give people
a&amp;nbsp;space to&amp;nbsp;grow. This can&amp;nbsp;be&amp;nbsp;a&amp;nbsp;big&amp;nbsp;factor affecting team&amp;#39;s productivity.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id="toc_1"&gt;Cons&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Multiple programming languages used in&amp;nbsp;one&amp;nbsp;project&lt;/strong&gt;. Either people of&amp;nbsp;two&amp;nbsp;skillsets (client
and&amp;nbsp;server) or&amp;nbsp;more experienced (full-stack) developers are&amp;nbsp;needed&lt;sup&gt;&lt;a href="#pick-the-right-tool-for-the-job"&gt;4&lt;/a&gt;&lt;/sup&gt; when
building SPA. To&amp;nbsp;alleciate this problem, single-language technology stacks are&amp;nbsp;being
developed. We&amp;nbsp;see&amp;nbsp;successful expansions of&amp;nbsp;client-side languages to&amp;nbsp;the&amp;nbsp;server (&lt;a href="https://nodejs.org/en/"&gt;Node&lt;/a&gt; for&amp;nbsp;JavaScript) and&amp;nbsp;vice-versa (&lt;a href="http://www.gwtproject.org/"&gt;GWT&lt;/a&gt; for&amp;nbsp;Java, &lt;a href="http://opalrb.org/"&gt;Opal&lt;/a&gt; for&amp;nbsp;Ruby, &lt;a href="http://pyjs.org/"&gt;pyJS&lt;/a&gt; for&amp;nbsp;Python,
&lt;a href="https://github.com/gopherjs/gopherjs"&gt;GopherJS&lt;/a&gt; for&amp;nbsp;Go).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Indexer robots do&amp;nbsp;not&amp;nbsp;run&amp;nbsp;JavaScript.&lt;/strong&gt; As&amp;nbsp;of&amp;nbsp;4&lt;sup&gt;th&lt;/sup&gt; quarter of&amp;nbsp;2015 Google crawler is&amp;nbsp;able to&amp;nbsp;interpret JavaScript and&amp;nbsp;&lt;abbr title="Cascading Style Sheets"&gt;CSS&lt;/abbr&gt; just like
modern web&amp;nbsp;browsers, but&amp;nbsp;if&amp;nbsp;some pages from SPA&amp;nbsp;website are&amp;nbsp;to&amp;nbsp;be&amp;nbsp;posted on&amp;nbsp;Facebook, authors must
implement mechanisms that provide the&amp;nbsp;same content in&amp;nbsp;another form, which can&amp;nbsp;be&amp;nbsp;read by&amp;nbsp;Facebook&amp;#39;s robot&lt;sup&gt;&lt;a href="#prerender"&gt;5&lt;/a&gt;&lt;/sup&gt; &lt;sup&gt;&lt;a href="#js-test"&gt;6&lt;/a&gt;&lt;/sup&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Extensive use&amp;nbsp;of&amp;nbsp;JavaScript can&amp;nbsp;lead to&amp;nbsp;memory leaks&lt;/strong&gt;. It&amp;nbsp;is&amp;nbsp;especially apparent in&amp;nbsp;older
versions of&amp;nbsp;Internet Explorer, where there are&amp;nbsp;two&amp;nbsp;memory managers (one&amp;nbsp;for&amp;nbsp;&lt;abbr title="Document
Object Model"&gt;DOM&lt;/abbr&gt; elements and&amp;nbsp;one&amp;nbsp;for&amp;nbsp;JavaScript objects). Many of&amp;nbsp;moders JavaScript
libraries contain &lt;abbr title="Internet Explorer"&gt;IE&lt;/abbr&gt; leak-protection code, but&amp;nbsp;expert
knowledge of&amp;nbsp;the&amp;nbsp;matter may&amp;nbsp;also be&amp;nbsp;required in&amp;nbsp;the&amp;nbsp;team. Page reload frees all&amp;nbsp;memory associated
with it, thus problem is&amp;nbsp;circumvented in&amp;nbsp;non-SPA websites.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Coding in&amp;nbsp;JavaScript requires much discipline&lt;/strong&gt;, as&amp;nbsp;the&amp;nbsp;language contain many features that
are&amp;nbsp;considered bad&amp;nbsp;programming practices&lt;sup&gt;&lt;a href="#strict-mode"&gt;7&lt;/a&gt;&lt;/sup&gt; &lt;sup&gt;&lt;a href="#es6"&gt;8&lt;/a&gt;&lt;/sup&gt;. What&amp;#39;s more,
JavaScript is&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/Programming_language#Type_system"&gt;untyped&lt;/a&gt;&lt;sup&gt;&lt;a href="#type-script"&gt;9&lt;/a&gt;&lt;/sup&gt;, which makes it&amp;nbsp;more prone to&amp;nbsp;mistakes made by&amp;nbsp;the&amp;nbsp;programmer. Multiple linting solutions (&lt;a href="http://www.jslint.com/"&gt;jslint&lt;/a&gt;, &lt;a href="http://jshint.com/"&gt;jshint&lt;/a&gt;, &lt;a href="http://eslint.org/"&gt;eslint&lt;/a&gt;) are&amp;nbsp;being
developed by&amp;nbsp;the&amp;nbsp;community in&amp;nbsp;order to&amp;nbsp;mitigate these problems.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id="toc_2"&gt;When to&amp;nbsp;use&amp;nbsp;SPA?&lt;/h2&gt;

&lt;p&gt;Following conditions can&amp;nbsp;be&amp;nbsp;considered as&amp;nbsp;favorable for&amp;nbsp;SPA:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Required high responsiveness,&lt;/li&gt;
&lt;li&gt;Required connection awareness of&amp;nbsp;the&amp;nbsp;client,&lt;/li&gt;
&lt;li&gt;Heterogenous client applications,&lt;/li&gt;
&lt;li&gt;Code base estimated to&amp;nbsp;be&amp;nbsp;large (&amp;gt; 100kLOC),&lt;/li&gt;
&lt;li&gt;Experienced development team.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Under following conditions SPA&amp;nbsp;may&amp;nbsp;be&amp;nbsp;not&amp;nbsp;advisable:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Limited knowledge of&amp;nbsp;JavaScript language and&amp;nbsp;browser technology,&lt;/li&gt;
&lt;li&gt;Web-app without additional client applications,&lt;/li&gt;
&lt;li&gt;Required compatibility with very old&amp;nbsp;browsers.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id="toc_3"&gt;References&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Jose Maria Arranz Santamaria (ItsNat Java Web&amp;nbsp;Framework) wrote a&amp;nbsp;document titled &lt;a href="http://itsnat.sourceforge.net/php/spim/spi_manifesto_en.php"&gt;The&amp;nbsp;Single
Page Interface Manifesto&lt;/a&gt;, where he&amp;nbsp;advises on&amp;nbsp;how&amp;nbsp;to&amp;nbsp;transition from server-side thinking to&amp;nbsp;modern SPA.&lt;/li&gt;
&lt;li&gt;Personal website of&amp;nbsp;Douglas Crockford (member of&amp;nbsp;&lt;abbr title=EcmaScript&gt;ES&lt;/abbr&gt; standards
committee) contains article on&amp;nbsp;&lt;a href="http://javascript.crockford.com/memory/leak.html"&gt;causes of&amp;nbsp;memory leaks in&amp;nbsp;&lt;abbr title="Internet
Explorer"&gt;IE&lt;/abbr&gt; and&amp;nbsp;how&amp;nbsp;to&amp;nbsp;avoid them&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Report on&amp;nbsp;&lt;a href="https://engineering.linkedin.com/frontend/client-side-templating-throwdown-mustache-handlebars-dustjs-and-more"&gt;research of&amp;nbsp;client-side template engines&lt;/a&gt; written by&amp;nbsp;Veena Basavaraj can&amp;nbsp;be&amp;nbsp;found
on&amp;nbsp;LinkedIn&amp;#39;s engineering blog.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id="toc_4"&gt;Annotations&lt;/h2&gt;

&lt;p&gt;&lt;sup&gt;&lt;a id="ria" href="#ria"&gt;{1}&lt;/a&gt;&lt;/sup&gt;
The&amp;nbsp;concept of&amp;nbsp;client-side web&amp;nbsp;application that provide functionality on&amp;nbsp;its&amp;nbsp;own&amp;nbsp;(without
the&amp;nbsp;assistance of&amp;nbsp;a&amp;nbsp;server) is&amp;nbsp;often called &lt;a href="https://en.wikipedia.org/wiki/Rich_Internet_application"&gt;Rich Internet Application&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;sup&gt;&lt;a id="jsf-resource-hogging" href="#jsf-resource-hogging"&gt;{3}&lt;/a&gt;&lt;/sup&gt;
I&amp;nbsp;participated in&amp;nbsp;a&amp;nbsp;project in&amp;nbsp;which half of&amp;nbsp;server-side resources were consumed by&amp;nbsp;presentation
logic and&amp;nbsp;session storage (&lt;a href="https://en.wikipedia.org/wiki/JavaServer_Faces"&gt;&lt;abbr title="Java Server Faces"&gt;JSF&lt;/a&gt;&lt;/a&gt; was&amp;nbsp;used extensively).&lt;/p&gt;

&lt;p&gt;&lt;sup&gt;&lt;a id="pick-the-right-tool-for-the-job" href="#pick-the-right-tool-for-the-job"&gt;{4}&lt;/a&gt;&lt;/sup&gt;
Multiple programming languages in&amp;nbsp;one&amp;nbsp;project can&amp;nbsp;be&amp;nbsp;considered the&amp;nbsp;right approach. Experienced
programmers often seek to&amp;nbsp;&lt;a href="http://c2.com/cgi/wiki?PickTheRightToolForTheJob"&gt;use&amp;nbsp;the&amp;nbsp;right tool for&amp;nbsp;the&amp;nbsp;job&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;sup&gt;&lt;a id="prerender" href="#prerender"&gt;{5}&lt;/a&gt;&lt;/sup&gt;
&lt;a href="https://prerender.io/"&gt;Prerender.io&lt;/a&gt; provides serverside components that prerenders HTML pages in&amp;nbsp;headless browser.
Rendered HTML can&amp;nbsp;be&amp;nbsp;sent to&amp;nbsp;robots visiting the&amp;nbsp;website.&lt;/p&gt;

&lt;p&gt;&lt;sup&gt;&lt;a id="js-test" href="#js-test"&gt;{6}&lt;/a&gt;&lt;/sup&gt;
Facebook&amp;#39;s robot fetches the&amp;nbsp;content of&amp;nbsp;first &lt;abbr title="Uniform Resource Locator"&gt;URL&lt;/abbr&gt;
written in&amp;nbsp;a&amp;nbsp;post. To&amp;nbsp;test if&amp;nbsp;Facebook&amp;#39;s robot runs JavaScript paste
&lt;a href="/js-test"&gt;http://softwarephilosophy.ninja/js-test&lt;/a&gt; in&amp;nbsp;the&amp;nbsp;post.&lt;/p&gt;

&lt;p&gt;&lt;sup&gt;&lt;a id="strict-mode" href="#strict-mode"&gt;{7}&lt;/a&gt;&lt;/sup&gt;
EcmaScript standard version 5 instroduced &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode"&gt;Strict Mode&lt;/a&gt;, which changes the&amp;nbsp;semantics
of&amp;nbsp;JavaScript by&amp;nbsp;removing many unwanted behaviours.&lt;/p&gt;

&lt;p&gt;&lt;sup&gt;&lt;a id="es6" href="#es6"&gt;{8}&lt;/a&gt;&lt;/sup&gt;
&lt;a href="http://www.ecma-international.org/ecma-262/6.0/index.html"&gt;EcmaScript standard version 6&lt;/a&gt; resolves many semantical problems that were present
in&amp;nbsp;previous versions of&amp;nbsp;the&amp;nbsp;language.&lt;/p&gt;

&lt;p&gt;&lt;sup&gt;&lt;a id="type-script" href="#type-script"&gt;{9}&lt;/a&gt;&lt;/sup&gt;
A&amp;nbsp;super-set of&amp;nbsp;JavaScript called &lt;a href="http://www.typescriptlang.org/"&gt;TypeScript&lt;/a&gt; (created by&amp;nbsp;Microsoft) adds type declarations
to&amp;nbsp;the&amp;nbsp;syntax and&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/Type_inference"&gt;type inference&lt;/a&gt; to&amp;nbsp;the&amp;nbsp;semantics of&amp;nbsp;the&amp;nbsp;language.&lt;/p&gt;
</description>
    </item>
  </channel>
</rss>
