<style type="text/css">a[data-mtli~="mtli_filesize22809kB"]:after {content:" (228.09 kB)"}a[data-mtli~="mtli_filesize22209kB"]:after {content:" (222.09 kB)"}</style>{"id":2496,"date":"2017-05-22T14:41:30","date_gmt":"2017-05-22T12:41:30","guid":{"rendered":"http:\/\/monodes.com\/predaelli\/?p=2496"},"modified":"2017-05-25T23:39:29","modified_gmt":"2017-05-25T21:39:29","slug":"six-programming-paradigms-that-will-change-how-you-think-about-coding","status":"publish","type":"post","link":"https:\/\/monodes.com\/predaelli\/2017\/05\/22\/six-programming-paradigms-that-will-change-how-you-think-about-coding\/","title":{"rendered":"Six programming paradigms that will change how you think about coding"},"content":{"rendered":"<p><em><a href=\"http:\/\/www.ybrikman.com\/writing\/2014\/04\/09\/six-programming-paradigms-that-will\/\">Six programming paradigms that will change how you think about coding<\/a><\/em><\/p>\n<p><!--more--><!--nextpage--><\/p>\n<blockquote>\n<nav class=\"clearfix border-bottom border-light-gray\">\n<div class=\"left\"><a class=\"button py2 button-transparent nav-button caps\" href=\"http:\/\/www.ybrikman.com\/\">Yevgeniy Brikman<\/a><\/div>\n<ul class=\"right list-reset m0 nav-collapse nav-collapse nav-collapse-0 closed\">\n<li class=\"inline-block m0\"><a class=\"button button-transparent py2 h6 nav-button caps\" href=\"http:\/\/www.ybrikman.com\/writing\">writing<\/a><\/li>\n<li class=\"inline-block m0\"><a class=\"button button-transparent py2 h6 nav-button caps\" href=\"http:\/\/www.ybrikman.com\/speaking\">speaking<\/a><\/li>\n<li class=\"inline-block m0\"><a class=\"button button-transparent py2 h6 nav-button caps\" href=\"http:\/\/www.ybrikman.com\/projects\">projects<\/a><\/li>\n<li class=\"inline-block m0\"><a class=\"button button-transparent py2 h6 nav-button caps\" href=\"http:\/\/www.ybrikman.com\/photos\">photos<\/a><\/li>\n<\/ul>\n<\/nav>\n<header class=\"bg-splash-gray px3 py3 border-bottom border-light-gray\">\n<div class=\"container\">\n<div class=\"clearfix\">\n<h1 class=\"mt0 mb1\">Six programming paradigms that will change how you think about coding<\/h1>\n<\/div>\n<div>\n<div class=\"gray h6\"><span class=\"mr1 nowrap\"> <i class=\"fa fa-calendar\"><\/i> <time datetime=\"2014-04-09\">Apr 09, 2014<\/time> <\/span> <span class=\"mr1 nowrap\"> <i class=\"fa fa-tags\"><\/i> <a href=\"http:\/\/www.ybrikman.com\/writing\/tags\/#Software%20Engineering\">Software Engineering<\/a> <\/span> <span class=\"mr1 nowrap\"> <i class=\"fa fa-comments\"><\/i> <a class=\"disqus-comment-count\" href=\"http:\/\/www.ybrikman.com\/writing\/2014\/04\/09\/six-programming-paradigms-that-will\/?imm_mid=0f16b7&amp;cmp=em-prog-na-na-newsltr_20170506#comments\" data-disqus-identifier=\"\/writing\/2014\/04\/09\/six-programming-paradigms-that-will\">29 Comments<\/a> <\/span> <span class=\"nowrap\"> <i class=\"fa fa-clock-o\"><\/i> 16 min read <\/span><\/div>\n<\/div>\n<\/div>\n<\/header>\n<article class=\"post\">\n<div class=\"post-content\">\n<p>Every now and then, I stumble across a programming language that does something so different that it changes how I think about coding. In this post, I want to share some of my favorite finds.<\/p>\n<p>This is not your grandma\u2019s \u201cfunctional programming will change the world!\u201d blog post: this list is much more esoteric. I\u2019d wager most readers haven\u2019t heard of the majority of the languages and paradigms below, so I hope you have as much fun learning about these new concepts as I did.<\/p>\n<p>Note: I have only minimal experience with most of the languages below: I find the ideas behind them fascinating, but claim no expertise in them, so please point out any corrections and errors. Also, if you\u2019ve found any new paradigms and ideas not covered here, please share them!<\/p>\n<p><em>Update: this post hit the front page of <a href=\"http:\/\/www.reddit.com\/r\/programming\/comments\/22nhb2\/six_programming_paradigms_that_will_change_how\/\">r\/programming<\/a> and <a href=\"https:\/\/news.ycombinator.com\/item?id=7565153\">HN<\/a>. Thank you for the great feedback! I\u2019ve added some corrections below.<\/em><\/p>\n<h2 id=\"concurrent-by-default\">Concurrent by default<\/h2>\n<figure><a href=\"https:\/\/code.google.com\/p\/anic\/\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" class=\"  lazyloaded\" src=\"https:\/\/i0.wp.com\/monodes.com\/predaelli\/wp-content\/uploads\/sites\/4\/2017\/05\/anic.jpg?w=910\" alt=\"Anic\" data-src=\"\/assets\/img\/blog\/programming-paradigms\/anic.jpg\" \/> <\/a><figcaption> <a href=\"https:\/\/code.google.com\/p\/anic\/\" target=\"_blank\">Anic<\/a> <\/figcaption><\/figure>\n<p>Example languages: <a href=\"https:\/\/code.google.com\/p\/anic\/\">ANI<\/a>, <a href=\"http:\/\/www.cs.cmu.edu\/%7Ealdrich\/plaid\/\">Plaid<\/a><\/p>\n<p>Let\u2019s kick things off with a real mind bender: there are programming languages out there that are concurrent by default. That is, every line of code is executed in parallel!<\/p>\n<p>For example, imagine you wrote three lines of code, A, B, and C:<\/p>\n<figure class=\"highlight\">\n<pre><code class=\"\" data-line=\"\">A;\nB;\nC;<\/code><\/pre>\n<\/figure>\n<p>In most programming languages, A would execute first, then B, and then C. In a language like <a href=\"https:\/\/code.google.com\/p\/anic\/\">ANI<\/a>, A, B, and C would all execute at the same time!<\/p>\n<p>Control flow or ordering between lines of code in <a href=\"https:\/\/code.google.com\/p\/anic\/\">ANI<\/a> is merely a side effect of explicit dependencies between lines of code. For example, if B had a reference to a variable defined in A, then A and C would execute at the same time, and B would execute only after A finished.<\/p>\n<p>Let\u2019s look at an example in ANI. As described in the <a href=\"https:\/\/code.google.com\/p\/anic\/wiki\/Tutorial\">tutorial<\/a>, ANI programs consists of \u201cpipes\u201d and \u201clatches\u201d that are used to manipulate streams and data flows. The unusual syntax is tough to parse, and the language seems dead, but the concepts are pretty interesting.<\/p>\n<p>Here\u2019s a \u201cHello World\u201d example in ANI:<\/p>\n<figure class=\"highlight\">\n<pre><code class=\"\" data-line=\"\">&quot;Hello, World!&quot; -&gt;std.out<\/code><\/pre>\n<\/figure>\n<p>In ANI terminology, we are sending the <code class=\"\" data-line=\"\">&quot;Hello, World!&quot;<\/code> object (a string) to the <code class=\"\" data-line=\"\">std.out<\/code> stream. What happens if we send another string to <code class=\"\" data-line=\"\">std.out<\/code>?<\/p>\n<figure class=\"highlight\">\n<pre><code class=\"\" data-line=\"\">&quot;Hello, World!&quot; -&gt;std.out\n&quot;Goodbye, World!&quot; -&gt;std.out<\/code><\/pre>\n<\/figure>\n<p>Both of these lines of code execute in parallel, so they could end up in any order in the console. Now, look what happens when we introduce a variable on one line and reference it later:<\/p>\n<figure class=\"highlight\">\n<pre><code class=\"\" data-line=\"\">s = [string\\];\n&quot;Hello, World!&quot; -&gt;s;\n\\s -&gt;std.out;<\/code><\/pre>\n<\/figure>\n<p>The first line declares a \u201clatch\u201d (latches are a bit like variables) called <code class=\"\" data-line=\"\">s<\/code> that contains a string; the second line sends the text <code class=\"\" data-line=\"\">&quot;Hello, World!&quot;<\/code> to <code class=\"\" data-line=\"\">s<\/code>; the third line \u201cunlatches\u201d <code class=\"\" data-line=\"\">s<\/code> and sends the contents to <code class=\"\" data-line=\"\">std.out<\/code>. Here, you can see ANI\u2019s implicit program sequencing: since each line depends on the previous one, this code will execute in the order it is written.<\/p>\n<p>The <a href=\"http:\/\/www.cs.cmu.edu\/%7Ealdrich\/plaid\/\">Plaid language<\/a> also claims to support concurrency by default, but uses a permissions model, as described in <a href=\"http:\/\/www.cs.cmu.edu\/%7Ealdrich\/papers\/onward2009-concurrency.pdf\" data-mtli=\"mtli_filesize22809kB\">this paper<\/a>, to setup control flow. Plaid also explores other interesting concepts, such as <a href=\"http:\/\/www.cs.cmu.edu\/%7Ealdrich\/papers\/onward2009-state.pdf\" data-mtli=\"mtli_filesize22209kB\">Typestate-Oriented Programming<\/a>, where state changes become a first class citizen of the language: you define objects not as classes, but as a series of states and transitions that can be checked by the compiler. This seems like an interesting take on exposing <em>time<\/em> as a first class language construct as discussed in Rich Hickey\u2019s <a href=\"http:\/\/www.infoq.com\/presentations\/Are-We-There-Yet-Rich-Hickey\">Are we there yet<\/a> talk.<\/p>\n<p>Multicore is on the rise and concurrency is still harder than it should be in most languages. ANI and Plaid offer a fresh a fresh take on this problem that could lead to amazing performance gains; the question is whether \u201cparallel by default\u201d makes concurrency easier or harder to manage.<\/p>\n<p><em>Update: the description above captures the basic essence of ANI and Plaid, but I used the terms \u201cconcurrent\u201d and \u201cparallel\u201d interchangeably, even though they have different meanings. See <a href=\"http:\/\/vimeo.com\/49718712\">Concurrency Is Not Parallelism<\/a> for more info.<\/em><\/p>\n<h2 id=\"dependent-types\">Dependent types<\/h2>\n<figure><a href=\"http:\/\/www.idris-lang.org\/\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" class=\"  lazyloaded\" src=\"https:\/\/i0.wp.com\/monodes.com\/predaelli\/wp-content\/uploads\/sites\/4\/2017\/05\/idris.png?w=910\" alt=\"Idris\" data-src=\"\/assets\/img\/blog\/programming-paradigms\/idris.png\" \/> <\/a><figcaption> <a href=\"http:\/\/www.idris-lang.org\/\" target=\"_blank\">Idris<\/a> <\/figcaption><\/figure>\n<p>Example languages: <a href=\"http:\/\/www.idris-lang.org\/\">Idris<\/a>, <a href=\"http:\/\/wiki.portal.chalmers.se\/agda\/pmwiki.php\">Agda<\/a>, <a href=\"http:\/\/en.wikipedia.org\/wiki\/Coq\">Coq<\/a><\/p>\n<p>You\u2019re probably used to type systems in languages like C and Java, where the compiler can check that a variable is an integer, list, or string. But what if your compiler could check that a variable is \u201ca positive integer\u201d, \u201ca list of length 2\u201d, or \u201ca string that is a palindrome\u201d?<\/p>\n<p>This is the idea behind languages that support <a href=\"http:\/\/en.wikipedia.org\/wiki\/Dependent_type\">dependent types<\/a>: you can specify <em>types<\/em> that can check the <em>value<\/em> of your variables at <em>compile time<\/em>. The <a href=\"https:\/\/github.com\/milessabin\/shapeless\">shapeless library<\/a> for Scala adds partial, experimental support (read: probably not ready for primetime) for dependent types to Scala and offers an easy way to see some examples.<\/p>\n<p>Here is how you can declare a <code class=\"\" data-line=\"\">Vector<\/code> that contains the values 1, 2, 3 with the shapeless library:<\/p>\n<figure class=\"highlight\">\n<pre><code class=\"\" data-line=\"\">&lt;span class=&quot;k&quot;&gt;val&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;l1&lt;\/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;\/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;:#:&lt;\/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;:#:&lt;\/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;:#:&lt;\/span&gt; &lt;span class=&quot;nc&quot;&gt;VNil&lt;\/span&gt;<\/code><\/pre>\n<\/figure>\n<p>This creates a variable <code class=\"\" data-line=\"\">l1<\/code> who\u2019s type signature specifies not only that it\u2019s a <code class=\"\" data-line=\"\">Vector<\/code> that contains <code class=\"\" data-line=\"\">Ints<\/code>, but also that it is a <code class=\"\" data-line=\"\">Vector<\/code> of length 3. The compiler can use this information to catch errors. Let\u2019s use the <code class=\"\" data-line=\"\">vAdd<\/code> method in <code class=\"\" data-line=\"\">Vector<\/code> to perform a pairwise addition between two <code class=\"\" data-line=\"\">Vectors<\/code>:<\/p>\n<figure class=\"highlight\">\n<pre><code class=\"language-scala\" data-line=\"\">&lt;span class=&quot;k&quot;&gt;val&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;l1&lt;\/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;\/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;:#:&lt;\/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;:#:&lt;\/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;:#:&lt;\/span&gt; &lt;span class=&quot;nc&quot;&gt;VNil&lt;\/span&gt;\n&lt;span class=&quot;k&quot;&gt;val&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;l2&lt;\/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;\/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;:#:&lt;\/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;:#:&lt;\/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;:#:&lt;\/span&gt; &lt;span class=&quot;nc&quot;&gt;VNil&lt;\/span&gt;\n \n&lt;span class=&quot;k&quot;&gt;val&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;l3&lt;\/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;l1&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;vAdd&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;l2&lt;\/span&gt;\n \n&lt;span class=&quot;o&quot;&gt;\/\/&lt;\/span&gt; &lt;span class=&quot;nc&quot;&gt;Result&lt;\/span&gt;&lt;span class=&quot;k&quot;&gt;:&lt;\/span&gt; &lt;span class=&quot;kt&quot;&gt;l3&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;\/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;:#:&lt;\/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;:#:&lt;\/span&gt; &lt;span class=&quot;mi&quot;&gt;6&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;:#:&lt;\/span&gt; &lt;span class=&quot;nc&quot;&gt;VNil&lt;\/span&gt;<\/code><\/pre>\n<\/figure>\n<p>The example above works fine because the type system knows both <code class=\"\" data-line=\"\">Vectors<\/code> have length 3. However, if we tried to <code class=\"\" data-line=\"\">vAdd<\/code> two <code class=\"\" data-line=\"\">Vectors<\/code> of different lengths, we\u2019d get an error at <em>compile time<\/em> instead of having to wait until run time!<\/p>\n<figure class=\"highlight\">\n<pre><code class=\"language-scala\" data-line=\"\">&lt;span class=&quot;k&quot;&gt;val&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;l1&lt;\/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;\/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;:#:&lt;\/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;:#:&lt;\/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;:#:&lt;\/span&gt; &lt;span class=&quot;nc&quot;&gt;VNil&lt;\/span&gt;\n&lt;span class=&quot;k&quot;&gt;val&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;l2&lt;\/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;\/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;:#:&lt;\/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;:#:&lt;\/span&gt; &lt;span class=&quot;nc&quot;&gt;VNil&lt;\/span&gt;\n \n&lt;span class=&quot;k&quot;&gt;val&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;l3&lt;\/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;l1&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;vAdd&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;l2&lt;\/span&gt;\n \n&lt;span class=&quot;c1&quot;&gt;\/\/ Result: a *compile* error because you can&#039;t pairwise add vectors \n&lt;\/span&gt;&lt;span class=&quot;o&quot;&gt;\/\/&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;of&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;different&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;lengths&lt;\/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;\/span&gt;<\/code><\/pre>\n<\/figure>\n<p>Shapeless is an amazing library, but from what I\u2019ve seen, it\u2019s still a bit rough, only supports a subset of dependent typing, and leads to fairly verbose code and type signatures. <a href=\"http:\/\/www.idris-lang.org\/\">Idris<\/a>, on the other hand, makes types a first class member of the programming language, so the dependent type system seems much more powerful and clean. For a comparison, check out the <a href=\"http:\/\/www.infoq.com\/presentations\/scala-idris\">Scala vs Idris: Dependent Types, Now and in the Future<\/a> talk.<\/p>\n<p><a href=\"http:\/\/en.wikipedia.org\/wiki\/Formal_verification\">Formal verification methods<\/a> have been around for a long type, but were often too cumbersome to be usable for general purpose programming. Dependent types in languages like Idris, and perhaps even Scala in the future, may offer lighter-weight and more practical alternatives that still dramatically increase the power of the type system in catching errors. Of course, no dependent type system can catch all errors due to to ineherent limitations from the halting problem, but if done well, dependent types may be the next big leap for static type systems.<\/p>\n<h2 id=\"concatenative-languages\">Concatenative languages<\/h2>\n<figure><a href=\"http:\/\/www.cat-language.com\/index.html\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" class=\"  lazyloaded\" src=\"https:\/\/i0.wp.com\/monodes.com\/predaelli\/wp-content\/uploads\/sites\/4\/2017\/05\/cat.jpg?w=910\" alt=\"Cat\" data-src=\"\/assets\/img\/blog\/programming-paradigms\/cat.jpg\" \/> <\/a><figcaption> <a href=\"http:\/\/www.cat-language.com\/index.html\" target=\"_blank\">Cat<\/a> <\/figcaption><\/figure>\n<p>Example languages: <a href=\"http:\/\/www.forth.com\/forth\/\">Forth<\/a>, <a href=\"http:\/\/www.cat-language.com\/\">cat<\/a>, <a href=\"http:\/\/c2.com\/cgi\/wiki?JoyLanguage\">joy<\/a><\/p>\n<p>Ever wonder what it would be like to program without variables and function application? No? Me neither. But apparently some folks did, and they came up with <a href=\"http:\/\/en.wikipedia.org\/wiki\/Concatenative_programming_language\">concatenative programming<\/a>. The idea is that everything in the language is a function that pushes data onto a stack or pops data off the stack; programs are built up almost exclusively through functional composition (<a href=\"http:\/\/concatenative.org\/wiki\/view\/Concatenative%20language\/Concatenation%20is%20composition\">concatenation is composition<\/a>).<\/p>\n<p>This sounds pretty abstract, so let\u2019s look at a simple example in <a href=\"http:\/\/www.cat-language.com\/\">cat<\/a>:<\/p>\n<figure class=\"highlight\">\n<pre><code class=\"\" data-line=\"\">2 3 +<\/code><\/pre>\n<\/figure>\n<p>Here, we push two numbers onto the stack and then call the <code class=\"\" data-line=\"\">+<\/code> function, which pops both numbers off the stack and pushes the result of adding them back onto the stack: the output of the code is 5. Here\u2019s a slightly more interesting example:<\/p>\n<figure class=\"highlight\">\n<pre><code class=\"\" data-line=\"\">def foo {\n  10 &lt;\n  [ 0 ]\n  [ 42 ]\n  if\n}\n \n20\nfoo<\/code><\/pre>\n<\/figure>\n<p>Let\u2019s walk through this line by line:<\/p>\n<ol>\n<li>First, we declare a function <code class=\"\" data-line=\"\">foo<\/code>. Note that functions in cat specify no input parameters: all parameters are implicitly read from the stack.<\/li>\n<li><code class=\"\" data-line=\"\">foo<\/code> calls the <code class=\"\" data-line=\"\">&lt;<\/code> function, which pops the first item on the stack, compares it to 10, and pushes either <code class=\"\" data-line=\"\">True<\/code> or <code class=\"\" data-line=\"\">False<\/code> back onto the stack.<\/li>\n<li>Next, we push the values 0 and 42 onto the stack: we wrap them in brackets to ensure they get pushed onto the stack unevaluated. This is because they will be used as the \u201cthen\u201d and \u201celse\u201d branches (respectively) for the call to the <code class=\"\" data-line=\"\">if<\/code> function on the next line.<\/li>\n<li>The <code class=\"\" data-line=\"\">if<\/code> function pops 3 items off the stack: the boolean condition, the \u201cthen\u201d branch, and the \u201celse\u201d branch. Depending on the value of the boolean condition, it\u2019ll push the result of either the \u201cthen\u201d or \u201celse\u201d branch back onto the stack.<\/li>\n<li>Finally, we push 20 onto the stack and call the <code class=\"\" data-line=\"\">foo<\/code> function.<\/li>\n<li>When all is said and done, we\u2019ll end up with the number 42.<\/li>\n<\/ol>\n<p>For a much more detailed introduction, check out <a href=\"http:\/\/www.codecommit.com\/blog\/cat\/the-joy-of-concatenative-languages-part-1\">The Joy of Concatenative Languages<\/a>.<\/p>\n<p>This style of programming has some interesting properties: programs can be split and concatenated in countless ways to create new programs; remarkably minimal syntax (even more minimal than LISP) that leads to very concise programs; strong meta programming support. I found concatenative programming to be an eye opening thought experiment, but I\u2019m not sold on its practicality. It seems like you have to remember or imagine the current state of the stack instead of being able to read it from the variable names in the code, which can make it hard to reason about the code.<\/p>\n<h2 id=\"declarative-programming\">Declarative programming<\/h2>\n<figure><a href=\"http:\/\/gprolog.univ-paris1.fr\/\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" class=\"  lazyloaded\" src=\"https:\/\/i0.wp.com\/monodes.com\/predaelli\/wp-content\/uploads\/sites\/4\/2017\/05\/prolog.png?w=910\" alt=\"GNU Prolog\" data-src=\"\/assets\/img\/blog\/programming-paradigms\/prolog.png\" \/> <\/a><figcaption> <a href=\"http:\/\/gprolog.univ-paris1.fr\/\" target=\"_blank\">GNU Prolog<\/a> <\/figcaption><\/figure>\n<p>Example languages: <a href=\"http:\/\/en.wikipedia.org\/wiki\/Prolog\">Prolog<\/a>, <a href=\"http:\/\/en.wikipedia.org\/wiki\/SQL\">SQL<\/a><\/p>\n<p><a href=\"http:\/\/en.wikipedia.org\/wiki\/Declarative_programming\">Declarative programming<\/a> has been around for many years, but most programmers are still unaware of it as a concept. Here\u2019s the gist: in most mainstream languages, you describe <em>how<\/em> to solve a particular problem; in declarative languages, you merely describe <em>the result you want<\/em>, and the language itself figures out how to get there.<\/p>\n<p>For example, if you\u2019re writing a sorting algorithm from scratch in C, you might write the instructions for merge sort, which describes, step by step, how to recursively split the data set in half and merge it back together in sorted order: <a href=\"http:\/\/www.cs.cityu.edu.hk\/%7Elwang\/ccs4335\/mergesort.c\">here\u2019s an example<\/a>. If you were sorting numbers in a declarative language like <a href=\"http:\/\/en.wikipedia.org\/wiki\/Prolog\">Prolog<\/a>, you\u2019d instead describe the output you want: \u201cI want the same list of values, but each item at index <code class=\"\" data-line=\"\">i<\/code> should be less than or equal to the item at index <code class=\"\" data-line=\"\">i + 1<\/code>\u201d. Compare the previous C solution to this Prolog code:<\/p>\n<figure class=\"highlight\">\n<pre><code class=\"\" data-line=\"\">&lt;span class=&quot;ss&quot;&gt;sort_list&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;\/span&gt;&lt;span class=&quot;nv&quot;&gt;Input&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;Output&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;\/span&gt; &lt;span class=&quot;p&quot;&gt;:-&lt;\/span&gt;\n  &lt;span class=&quot;ss&quot;&gt;permutation&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;\/span&gt;&lt;span class=&quot;nv&quot;&gt;Input&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;Output&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;\/span&gt;\n  &lt;span class=&quot;ss&quot;&gt;check_order&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;\/span&gt;&lt;span class=&quot;nv&quot;&gt;Output&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;\/span&gt;\n  \n&lt;span class=&quot;ss&quot;&gt;check_order&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;([]).&lt;\/span&gt;\n&lt;span class=&quot;ss&quot;&gt;check_order&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;\/span&gt;&lt;span class=&quot;nv&quot;&gt;Head&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;]).&lt;\/span&gt;\n&lt;span class=&quot;ss&quot;&gt;check_order&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;\/span&gt;&lt;span class=&quot;nv&quot;&gt;First&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;Second&lt;\/span&gt; &lt;span class=&quot;p&quot;&gt;|&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;Tail&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;\/span&gt; &lt;span class=&quot;p&quot;&gt;:-&lt;\/span&gt;\n  &lt;span class=&quot;nv&quot;&gt;First&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;Second&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt;\n  &lt;span class=&quot;ss&quot;&gt;check_order&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;\/span&gt;&lt;span class=&quot;nv&quot;&gt;Second&lt;\/span&gt; &lt;span class=&quot;p&quot;&gt;|&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;Tail&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;]).&lt;\/span&gt;<\/code><\/pre>\n<\/figure>\n<p>If you\u2019ve used SQL, you\u2019ve done a form of declarative programming and may not have realized it: when you issue a query like <code class=\"\" data-line=\"\">select X from Y where Z<\/code>, you are describing the data set you\u2019d like to get back; it\u2019s the database engine that actually figures out <em>how<\/em> to execute the query. You can use the explain command in most databases to see the execution plan and figure out what happened under the hood.<\/p>\n<p>The beauty of declarative languages is that they allow you to work at a much higher level of abstraction: your job is just to describe the specification for the output you want. For example, the code for a simple <a href=\"http:\/\/www.ybrikman.com\/writing\/2012\/02\/16\/seven-languages-in-seven-weeks-prolog_16\/\">sudoku solver in prolog<\/a> just lists out what each row, column, and diagonal of a solved sudoku puzzle should look like:<\/p>\n<figure class=\"highlight\">\n<pre><code class=\"\" data-line=\"\">&lt;span class=&quot;ss&quot;&gt;sudoku&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;\/span&gt;&lt;span class=&quot;nv&quot;&gt;Puzzle&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;Solution&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;\/span&gt; &lt;span class=&quot;p&quot;&gt;:-&lt;\/span&gt;\n  &lt;span class=&quot;nv&quot;&gt;Solution&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;Puzzle&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt;\n  \n  &lt;span class=&quot;nv&quot;&gt;Puzzle&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;\/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;\/span&gt;&lt;span class=&quot;nv&quot;&gt;S11&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S12&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S13&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S14&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt;\n            &lt;span class=&quot;nv&quot;&gt;S21&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S22&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S23&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S24&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt;\n            &lt;span class=&quot;nv&quot;&gt;S31&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S32&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S33&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S34&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt;\n            &lt;span class=&quot;nv&quot;&gt;S41&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S42&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S43&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S44&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;\/span&gt;\n  \n  &lt;span class=&quot;ss&quot;&gt;fd_domain&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;\/span&gt;&lt;span class=&quot;nv&quot;&gt;Solution&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;m&quot;&gt;1&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;m&quot;&gt;4&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;\/span&gt;\n  \n  &lt;span class=&quot;nv&quot;&gt;Row1&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;\/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;\/span&gt;&lt;span class=&quot;nv&quot;&gt;S11&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S12&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S13&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S14&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;\/span&gt;\n  &lt;span class=&quot;nv&quot;&gt;Row2&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;\/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;\/span&gt;&lt;span class=&quot;nv&quot;&gt;S21&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S22&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S23&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S24&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;\/span&gt;\n  &lt;span class=&quot;nv&quot;&gt;Row3&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;\/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;\/span&gt;&lt;span class=&quot;nv&quot;&gt;S31&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S32&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S33&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S34&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;\/span&gt;\n  &lt;span class=&quot;nv&quot;&gt;Row4&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;\/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;\/span&gt;&lt;span class=&quot;nv&quot;&gt;S41&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S42&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S43&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S44&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;\/span&gt;      \n  \n  &lt;span class=&quot;nv&quot;&gt;Col1&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;\/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;\/span&gt;&lt;span class=&quot;nv&quot;&gt;S11&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S21&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S31&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S41&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;\/span&gt;\n  &lt;span class=&quot;nv&quot;&gt;Col2&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;\/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;\/span&gt;&lt;span class=&quot;nv&quot;&gt;S12&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S22&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S32&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S42&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;\/span&gt;\n  &lt;span class=&quot;nv&quot;&gt;Col3&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;\/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;\/span&gt;&lt;span class=&quot;nv&quot;&gt;S13&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S23&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S33&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S43&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;\/span&gt;\n  &lt;span class=&quot;nv&quot;&gt;Col4&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;\/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;\/span&gt;&lt;span class=&quot;nv&quot;&gt;S14&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S24&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S34&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S44&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;\/span&gt;      \n  \n  &lt;span class=&quot;nv&quot;&gt;Square1&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;\/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;\/span&gt;&lt;span class=&quot;nv&quot;&gt;S11&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S12&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S21&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S22&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;\/span&gt;\n  &lt;span class=&quot;nv&quot;&gt;Square2&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;\/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;\/span&gt;&lt;span class=&quot;nv&quot;&gt;S13&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S14&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S23&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S24&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;\/span&gt;\n  &lt;span class=&quot;nv&quot;&gt;Square3&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;\/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;\/span&gt;&lt;span class=&quot;nv&quot;&gt;S31&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S32&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S41&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S42&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;\/span&gt;\n  &lt;span class=&quot;nv&quot;&gt;Square4&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;\/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;\/span&gt;&lt;span class=&quot;nv&quot;&gt;S33&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S34&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S43&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;S44&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;\/span&gt;      \n  \n  &lt;span class=&quot;ss&quot;&gt;valid&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;\/span&gt;&lt;span class=&quot;nv&quot;&gt;Row1&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;Row2&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;Row3&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;Row4&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt;\n         &lt;span class=&quot;nv&quot;&gt;Col1&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;Col2&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;Col3&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;Col4&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt;\n         &lt;span class=&quot;nv&quot;&gt;Square1&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;Square2&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;Square3&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;Square4&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;]).&lt;\/span&gt;\n \n&lt;span class=&quot;ss&quot;&gt;valid&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;([]).&lt;\/span&gt;\n&lt;span class=&quot;ss&quot;&gt;valid&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;\/span&gt;&lt;span class=&quot;nv&quot;&gt;Head&lt;\/span&gt; &lt;span class=&quot;p&quot;&gt;|&lt;\/span&gt; &lt;span class=&quot;nv&quot;&gt;Tail&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;\/span&gt; &lt;span class=&quot;p&quot;&gt;:-&lt;\/span&gt; &lt;span class=&quot;ss&quot;&gt;fd_all_different&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;\/span&gt;&lt;span class=&quot;nv&quot;&gt;Head&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;\/span&gt; &lt;span class=&quot;ss&quot;&gt;valid&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;\/span&gt;&lt;span class=&quot;nv&quot;&gt;Tail&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;\/span&gt;<\/code><\/pre>\n<\/figure>\n<p>Here is how you would run the sudoku solver above:<\/p>\n<figure class=\"highlight\">\n<pre><code class=\"\" data-line=\"\">| ?- sudoku([_, _, 2, 3,\n             _, _, _, _,\n             _, _, _, _,\n             3, 4, _, _],\n             Solution).\n \n \nS = [4,1,2,3,2,3,4,1,1,2,3,4,3,4,1,2]<\/code><\/pre>\n<\/figure>\n<p>The downside, unfortunately, is that declarative programming languages can easily hit performance bottlenecks. The naive sorting algorithm above is likely <code class=\"\" data-line=\"\">O(n!)<\/code>; the sudoku solver above does a brute force search; and most developers have had to provide database hints and extra indices to avoid expensive and inefficient plans when executing SQL queries.<\/p>\n<h2 id=\"symbolic-programming\">Symbolic programming<\/h2>\n<figure><a href=\"https:\/\/www.youtube.com\/watch?v=L6iUm_Cqx2s\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" class=\"  lazyloaded\" src=\"https:\/\/i0.wp.com\/monodes.com\/predaelli\/wp-content\/uploads\/sites\/4\/2017\/05\/aurora.png?w=910\" alt=\"Aurora\" data-src=\"\/assets\/img\/blog\/programming-paradigms\/aurora.png\" \/> <\/a><figcaption> <a href=\"https:\/\/www.youtube.com\/watch?v=L6iUm_Cqx2s\" target=\"_blank\">Aurora<\/a> <\/figcaption><\/figure>\n<p>Example languages: <a href=\"https:\/\/www.youtube.com\/watch?v=L6iUm_Cqx2s\">Aurora<\/a><\/p>\n<p>The <a href=\"https:\/\/www.youtube.com\/watch?v=L6iUm_Cqx2s\">Aurora<\/a> language is an example of <a href=\"http:\/\/en.wikipedia.org\/wiki\/Symbolic_programming\">symbolic programming<\/a>: the \u201ccode\u201d you write in these languages can include not only plain text, but also images, math equations, graphs, charts, and more. This allows you to manipulate and describe a large variety of data in the format native to that data, instead of describing it all in text. Aurora is also completely interactive, showing you the results from each line of code instantly, like a REPL on steroids.<\/p>\n<div class=\"iframe-wrapper\"><iframe class=\"  lazyloaded\" width=\"300\" height=\"150\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\" data-src=\"\/\/www.youtube.com\/embed\/L6iUm_Cqx2s\"><\/iframe><\/div>\n<p>The Aurora language was created by <a href=\"http:\/\/www.chris-granger.com\/\">Chris Granger<\/a>, who also built the <a href=\"http:\/\/www.lighttable.com\/\">Light Table IDE<\/a>. Chris outlines the motivation for Aurora in his post <a href=\"http:\/\/www.chris-granger.com\/2014\/03\/27\/toward-a-better-programming\/\">Toward a better programming<\/a>: some of the goals are to make programming more observable, direct, and reduce incidental complexity. For more info, be sure to see <a href=\"http:\/\/worrydream.com\/\">Bret Victor\u2019s<\/a> incredible talks: <a href=\"http:\/\/vimeo.com\/36579366\">Inventing on Principle<\/a>, <a href=\"http:\/\/vimeo.com\/67076984\">Media for Thinking the Unthinkable<\/a>, and <a href=\"http:\/\/worrydream.com\/#%21\/LearnableProgramming\">Learnable Programming<\/a>.<\/p>\n<p><em>Update: \u201csymbolic programming\u201d is probably not the right term to use for Aurora. See the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Symbolic_programming\">Symbolic programming<\/a> wiki for more info.<\/em><\/p>\n<h2 id=\"knowledge-based-programming\">Knowledge-based programming<\/h2>\n<figure><a href=\"https:\/\/www.wolfram.com\/language\/\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" class=\"  lazyloaded\" src=\"https:\/\/i0.wp.com\/monodes.com\/predaelli\/wp-content\/uploads\/sites\/4\/2017\/05\/wolfram.png?w=910\" alt=\"Wolfram Language\" data-src=\"\/assets\/img\/blog\/programming-paradigms\/wolfram.png\" \/> <\/a><figcaption> <a href=\"https:\/\/www.wolfram.com\/language\/\" target=\"_blank\">Wolfram Language<\/a> <\/figcaption><\/figure>\n<p>Examples: <a href=\"https:\/\/www.wolfram.com\/language\/\">Wolfram Language<\/a><\/p>\n<p>Much like the Aurora language mentioned above, The <a href=\"https:\/\/www.wolfram.com\/language\/\">Wolfram Language<\/a> is also based on symbolic programming. However, the symbolic layer is merely a way to provide a consistent interface to the core of the Wolfram Language, which is knowledge-based programming: built into the language is a <em>vast<\/em> array of libraries, algorithms, and data. This makes it easy to do everything from graphing your Facebook connections, to manipulating images, to looking up the weather, processing natural language queries, plotting directions on a map, solving mathematical equations, and much more.<\/p>\n<div class=\"iframe-wrapper\"><iframe class=\"  lazyloaded\" width=\"300\" height=\"150\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\" data-src=\"\/\/www.youtube.com\/embed\/_P9HqHVPeik\"><\/iframe><\/div>\n<p>I suspect the Wolfram Languages has the largest \u201cstandard library\u201d and data set of any language in existence. I\u2019m also excited by the idea that Internet connectivity is an inherent part of <em>writing<\/em> the code: it\u2019s almost like an IDE where the auto-complete function does a google search. It\u2019ll be very interesting to see if the symbolic programming model is as flexible as Wolfram claims and can truly take advantage of all of this data.<\/p>\n<p><em>Update: although Wolfram claims the Wolfram Language supports \u201csymbolic programming\u201d and \u201cknowledge programming\u201d, these terms have slightly different definitions. See the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Knowledge_level\">Knowledge level<\/a> and <a href=\"http:\/\/en.wikipedia.org\/wiki\/Symbolic_programming\">Symbolic Programming<\/a> wikis for more info.<\/em><\/p>\n<\/div>\n<\/article>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p class=\"excerpt\">Six programming paradigms that will change how you think about coding<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"https:\/\/monodes.com\/predaelli\/2017\/05\/22\/six-programming-paradigms-that-will-change-how-you-think-about-coding\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":4,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-2496","post","type-post","status-publish","format-standard","hentry","category-senza-categoria"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p6daft-Eg","jetpack-related-posts":[{"id":4877,"url":"https:\/\/monodes.com\/predaelli\/2018\/11\/06\/the-forgotten-history-of-oop\/","url_meta":{"origin":2496,"position":0},"title":"The Forgotten History of OOP","author":"Paolo Redaelli","date":"2018-11-06","format":false,"excerpt":"The Forgotten History of OOP \u2013 JavaScript Scene \u2013 Medium Eric Elliott Make some magic. #JavaScript Nov 1 The Forgotten History of\u00a0OOP Smoke Art Cubes to Smoke\u200a\u2014\u200aMattysFlicks\u200a\u2014\u200a(CC BY\u00a02.0) Note: This is part of the \u201cComposing Software\u201d series on learning functional programming and compositional software techniques in JavaScript ES6+ from the\u2026","rel":"","context":"In &quot;Documentations&quot;","block_context":{"text":"Documentations","link":"https:\/\/monodes.com\/predaelli\/category\/documentations\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":6659,"url":"https:\/\/monodes.com\/predaelli\/2020\/02\/07\/why-most-code-sucks-better-programming-medium\/","url_meta":{"origin":2496,"position":1},"title":"Why Most Code Sucks &#8211; Better Programming &#8211; Medium","author":"Paolo Redaelli","date":"2020-02-07","format":"link","excerpt":"Why Most Code Sucks - Better Programming - Medium And what you can do to improve yours","rel":"","context":"In &quot;Documentations&quot;","block_context":{"text":"Documentations","link":"https:\/\/monodes.com\/predaelli\/category\/documentations\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":9876,"url":"https:\/\/monodes.com\/predaelli\/2022\/11\/24\/how-to-learn-programming-the-guide-i-wish-i-had-when-i-started-learning-to-code\/","url_meta":{"origin":2496,"position":2},"title":"How to Learn Programming \u2013 The Guide I Wish I Had When I Started Learning to Code","author":"Paolo Redaelli","date":"2022-11-24","format":false,"excerpt":"How to Learn Programming \u2013 The Guide I Wish I Had When I Started Learning to Code","rel":"","context":"In &quot;Senza categoria&quot;","block_context":{"text":"Senza categoria","link":"https:\/\/monodes.com\/predaelli\/category\/senza-categoria\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1229,"url":"https:\/\/monodes.com\/predaelli\/2016\/04\/01\/minimal-programming\/","url_meta":{"origin":2496,"position":3},"title":"Minimal Programming","author":"Paolo Redaelli","date":"2016-04-01","format":false,"excerpt":"Such an interesting site this Minimal Programming. Feels old school, written by proficient people! Therefore, minimal programming means minimal code: no code duplication maximal expressiveness: readable code that directly reflects the underlying task minimal overlap: every piece of information can be found in exactly one place maximal orthogonality: clear separation\u2026","rel":"","context":"In &quot;Documentations&quot;","block_context":{"text":"Documentations","link":"https:\/\/monodes.com\/predaelli\/category\/documentations\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3904,"url":"https:\/\/monodes.com\/predaelli\/2018\/03\/23\/the-mistakes-i-made-as-a-beginner-programmer-samer-buna-medium\/","url_meta":{"origin":2496,"position":4},"title":"The Mistakes I Made As a Beginner Programmer \u2013 Samer Buna \u2013 Medium","author":"Paolo Redaelli","date":"2018-03-23","format":"link","excerpt":"Good reading: The Mistakes I Made As a Beginner Programmer by\u00a0 Samer Buna The Mistakes I Made As a Beginner Programmer Learn to identify them, make habits to avoid\u00a0them Let me make one thing clear first. If you are a beginner programmer, this article is not meant to make you\u2026","rel":"","context":"In &quot;Documentations&quot;","block_context":{"text":"Documentations","link":"https:\/\/monodes.com\/predaelli\/category\/documentations\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2251,"url":"https:\/\/monodes.com\/predaelli\/2017\/03\/06\/main-weaknesses-of-c-as-a-programming-language-disadvantages\/","url_meta":{"origin":2496,"position":5},"title":"Main Weaknesses Of C++ As A Programming Language &#8211; Disadvantages","author":"Paolo Redaelli","date":"2017-03-06","format":"link","excerpt":"Main Weaknesses Of C++ As A Programming Language - Disadvantages Because the lack of different in brackets and parentheses on a regular keyboard, the syntax of modern C++ sometimes gets complex.\u00a0And not only for people, but for code highlighting too, which should tell us something. Let\u2019s see: <>: Template declaration\u2026","rel":"","context":"In &quot;Senza categoria&quot;","block_context":{"text":"Senza categoria","link":"https:\/\/monodes.com\/predaelli\/category\/senza-categoria\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/posts\/2496","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/comments?post=2496"}],"version-history":[{"count":0,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/posts\/2496\/revisions"}],"wp:attachment":[{"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/media?parent=2496"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/categories?post=2496"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/tags?post=2496"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}