<?xml version="1.0" encoding="UTF-8" ?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-us">

  <title type="text">Sean Cribbs</title>

  <link rel="self" href="http://seancribbs.com/atom.xml" />
  <link rel="alternate" type="text/html" href="http://seancribbs.com/" />

  <id>http://seancribbs.com/</id>

  <generator uri="http://nanoc.stoneship.org/" 
    version="3.3.1">Nanoc3</generator>

  <author>
    <name>Sean Cribbs</name>
    <uri>http://seancribbs.com/</uri>
  </author>
  
  <updated>2012-10-08T14:32:18-07:00</updated>

  
    <entry>
      <author><name>Sean Cribbs</name></author>
      <published>2012-10-08T14:32:18-07:00</published>
      <title>Property-Driven Grammar Development</title>
      <link rel="alternate" type="text/html" 
        href="http://seancribbs.com/tech/2012/10/08/property-driven-grammar-development/" />
      <id>http://seancribbs.com/tech/2012/10/08/property-driven-grammar-development/</id>
      <content type="html">&lt;p&gt;Back when I first learned about parsing expression grammars (PEGs), I was impressed by the test-driven grammar development demo that the author of Treetop had created. TDD, BDD, and friends are a given in the Ruby community, but are not as popular in the Erlang world. On the other hand, QuickCheck is the most powerful tool for testing Erlang, given that it can generate random test cases and quickly reduce found errors to the minimal failing case (the most important part!).&lt;/p&gt;

&lt;p&gt;A few weeks ago Rich Hickey released an informal specification &lt;code&gt;edn&lt;/code&gt;, a subset of Clojure syntax for expressing data, and the on-the-wire format for Datomic. Since I have a &lt;a href='https://github.com/seancribbs/neotoma'&gt;PEG/Packrat tool&lt;/a&gt; and QuickCheck, it seemed like a perfect weekend project to attempt property-driven development on. (With minimal modification, one could use PropEr or Triq to do this, too.) I&amp;#8217;m not going to go into detail about how to use QuickCheck, but I&amp;#8217;ll try to cover the relevant bits as I go.&lt;/p&gt;

&lt;p&gt;Now, the interesting part about testing a parser with QuickCheck is that you have to do the work twice! That is, you must define a generator for a subset of the language at the same time that you develop the rule that parses it; the challenge will be avoiding the &amp;#8220;ugly mirror&amp;#8221; problem. With some more formal methods than I take here, one might be able to use the grammar as both generator and parser, an exercise I leave to you, kind reader.&lt;/p&gt;

&lt;p&gt;Usually I try to attack developing a grammar by selecting the simplest construct &amp;#8211; usually a terminal deep in the syntax tree &amp;#8211; and implementing that, then build up the language as I go with more terminals and simple non-terminals until I reach the top level. Since the simplest and most prolific terminal in &lt;code&gt;edn&lt;/code&gt; is whitespace, we&amp;#8217;ll start there. In my first pass at this, I started by writing my properties in the grammar file, but that quickly became unmanageable, so my examples below will keep them separate. Whitespace in &lt;code&gt;edn&lt;/code&gt; is defined as any tab character, carriage return, linefeed, horizontal space, or comma, so let&amp;#8217;s create a QuickCheck generator for that.&lt;/p&gt;
&lt;pre&gt;
&lt;code class='erlang'&gt;%% edn_eqc.erl
-module(edn_eqc).
-ifdef(EQC).
-compile([export_all]).
-include_lib(&quot;eqc/include/eqc.hrl&quot;).

gen_ws() -&gt; oneof([9, 10, 11, 12, 13, 32, $,]).

-endif.
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;I use the &lt;code&gt;oneof&lt;/code&gt; generator because each of the whitespace types is independent and none are preferred over another, meaning that they don&amp;#8217;t need to shrink to a specific value. Since we need binaries and not just bytes as parser input, and all streams in &lt;code&gt;edn&lt;/code&gt; are UTF-8 encoded, let&amp;#8217;s modify the generator a little bit and add a convenience macro for converting to UTF-8.&lt;/p&gt;
&lt;pre&gt;
&lt;code class='erlang'&gt;%% [snip]
-define(to_utf8(X), unicode:characters_to_binary(lists:flatten(X), utf8, utf8)).

gen_ws() -&gt;
    ?LET(X,
         list(oneof([9, 10, 11, 12, 13, 32, $,])),
         ?to_utf8(X)).
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;?LET&lt;/code&gt; macro allows you to wrap a non-abstract operation around a generator so that you can modify the concrete value after it is generated, while still returning a generator that QuickCheck can understand. Now we can sample that generator and see if it makes sense. (Note that I&amp;#8217;ve skipped over some setup stuff you&amp;#8217;ll need to do with rebar to make it a proper app. I put &lt;code&gt;edn_eqc.erl&lt;/code&gt; in &lt;code&gt;test/&lt;/code&gt;.)&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ rebar get-deps compile eunit compile_only=true
$ erl -pa .eunit
 
1&amp;gt; eqc_gen:sample(edn_eqc:gen_ws()).
&amp;lt;&amp;lt;&amp;quot;\t \n&amp;quot;&amp;gt;&amp;gt;
&amp;lt;&amp;lt;&amp;gt;&amp;gt;
&amp;lt;&amp;lt;&amp;quot;\f &amp;quot;&amp;gt;&amp;gt;
&amp;lt;&amp;lt;&amp;gt;&amp;gt;
&amp;lt;&amp;lt;&amp;quot;\f\r,\f,&amp;quot;&amp;gt;&amp;gt;
&amp;lt;&amp;lt;&amp;gt;&amp;gt;
&amp;lt;&amp;lt;&amp;quot; \v\r\n&amp;quot;&amp;gt;&amp;gt;
&amp;lt;&amp;lt;&amp;quot;,\f\n&amp;quot;&amp;gt;&amp;gt;
&amp;lt;&amp;lt;&amp;quot;\n, \n\v\n&amp;quot;&amp;gt;&amp;gt;
&amp;lt;&amp;lt;&amp;gt;&amp;gt;
&amp;lt;&amp;lt;&amp;gt;&amp;gt;
ok&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Great, now we should define what the property of parsing whitespace should be, namely, that it is ignored. However, given that &lt;code&gt;edn&lt;/code&gt; can be used to stream data, and has a native list type, returning an empty list when the stream has only whitespace would not make sense. Returning a tagged &lt;code&gt;error&lt;/code&gt; tuple, which is Erlang&amp;#8217;s convention, would also be presumptious, given that &lt;code&gt;edn&lt;/code&gt; has a tuple type. Therefore, I&amp;#8217;m going to choose to return a sentinel value of &lt;code&gt;&amp;#39;$space&amp;#39;&lt;/code&gt; for now, and I&amp;#8217;ll later insert a throw at the top level so we can detect empty streams. Luckily, it will be simple to change this later.&lt;/p&gt;
&lt;pre&gt;
&lt;code class='erlang'&gt;%% Must be after the EQC include, since it will try to define similar
%% macros.
-include_lib(&quot;eunit/include/eunit.hrl&quot;). 

%% [snip]

prop_whitespace() -&gt;
    ?FORALL(Spaces, gen_ws(),
           '$space' == edn:parse(Spaces)).
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;Now let&amp;#8217;s run it!&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ rebar qc
==&amp;gt; edn (qc)
NOTICE: Using experimental &amp;#39;qc&amp;#39; command
Compiled test/edn_eqc.erl
prop_whitespace: Starting Quviq QuickCheck version 1.25.1
   (compiled at {{2011,10,1},{13,42,22}})
Licence for Basho reserved until {{2012,10,11},{11,19,8}}
Failed! Reason: 
{&amp;#39;EXIT&amp;#39;,{undef,[{edn,parse,[&amp;lt;&amp;lt;&amp;gt;&amp;gt;],[]},
                {edn_eqc,&amp;#39;-prop_whitespace/0-fun-0-&amp;#39;,1,
                         [{file,&amp;quot;test/edn_eqc.erl&amp;quot;},{line,16}]},
                {eqc,&amp;#39;-f777_0/2-fun-4-&amp;#39;,3,[]},
                {eqc_gen,&amp;#39;-f321_0/2-fun-0-&amp;#39;,5,[]},
                {eqc_gen,f186_0,2,[]},
                {eqc_gen,&amp;#39;-f321_0/2-fun-0-&amp;#39;,5,[]},
                {eqc_gen,f186_0,2,[]},
                {eqc_gen,gen,3,[]}]}}
After 1 tests.
&amp;lt;&amp;lt;&amp;gt;&amp;gt;
ERROR: One or more QC properties didn&amp;#39;t hold true:
[prop_whitespace]&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Woops, we got &lt;code&gt;undef&lt;/code&gt; because we didn&amp;#8217;t define our grammar module yet! Let&amp;#8217;s open up &lt;code&gt;edn.peg&lt;/code&gt; and add the grammar rule.&lt;/p&gt;
&lt;pre&gt;
&lt;code class='erlang'&gt;whitespace &amp;lt;- [,\s\v\f\r\n\t]+ `'$space'`;
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;Briefly, we&amp;#8217;ve defined the &lt;code&gt;whitespace&lt;/code&gt; non-terminal as parsing from one-or-more characters in the class of visible whitespaces plus the comma character, and returning the Erlang atom &lt;code&gt;&amp;#39;$space&amp;#39;&lt;/code&gt;. Now let&amp;#8217;s compile the grammar and try it again.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ rebar compile qc skip_deps=true
==&amp;gt; edn (compile)
Compiled src/edn.peg
src/edn.erl:109: Warning: function p_all/4 is unused
Compiled src/edn.erl
==&amp;gt; edn (qc)
NOTICE: Using experimental &amp;#39;qc&amp;#39; command
src/edn.erl:109: Warning: function p_all/4 is unused
Compiled src/edn.erl
Compiled test/edn_eqc.erl
prop_whitespace: Starting Quviq QuickCheck version 1.25.1
   (compiled at {{2011,10,1},{13,42,22}})
Licence for Basho reserved until {{2012,10,11},{11,19,8}}
Failed! After 1 tests.
&amp;lt;&amp;lt;&amp;gt;&amp;gt;
ERROR: One or more QC properties didn&amp;#39;t hold true:
[prop_whitespace]
ERROR: qc failed while processing /Users/sean/Development/edn: rebar_abort&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Hmm, an empty content is a valid input, but shouldn&amp;#8217;t be recognized as a space. Let&amp;#8217;s make that generator predicated as non-empty on the property.&lt;/p&gt;
&lt;pre&gt;
&lt;code class='erlang'&gt;%% QuickCheck property for whitespace
prop_whitespace() -&gt;
    ?FORALL(Spaces, non_empty(gen_ws()),
           '$space' == edn:parse(Spaces)).
&lt;/code&gt;
&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;$ rebar compile qc skip_deps=true
==&amp;gt; edn (qc)
NOTICE: Using experimental &amp;#39;qc&amp;#39; command
src/edn.erl:109: Warning: function p_all/4 is unused
Compiled src/edn.erl
Compiled test/edn_eqc.erl
prop_whitespace: Starting Quviq QuickCheck version 1.25.1
   (compiled at {{2011,10,1},{13,42,22}})
Licence for Basho reserved until {{2012,10,11},{11,19,8}}
....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
OK, passed 500 tests&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Alright, we can parse whitespace! &lt;em&gt;*facepalm*&lt;/em&gt; Let&amp;#8217;s quickly add a few more simple language constructs, namely &lt;code&gt;nil&lt;/code&gt; and booleans so we can see how to start building up the structure around these terminals. Again we start with the generators:&lt;/p&gt;
&lt;pre&gt;
&lt;code class='erlang'&gt;gen_nil() -&gt; &amp;lt;&amp;lt;&quot;nil&quot;&gt;&gt;.

gen_bool() -&gt; oneof([&amp;lt;&amp;lt;&quot;true&quot;&gt;&gt;, &amp;lt;&amp;lt;&quot;false&quot;&gt;&gt;]).
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;Native Erlang values generate themselves in QuickCheck, so simply returning the &lt;code&gt;&amp;lt;&amp;lt;&amp;quot;nil&amp;quot;&amp;gt;&amp;gt;&lt;/code&gt; value means that that will always be generated from the &lt;code&gt;gen_nil()&lt;/code&gt; function. We can sample those generators again if we like, but they will be unsurprising. Instead, let&amp;#8217;s define a property for &lt;code&gt;nil&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;
&lt;code class='erlang'&gt;prop_nil() -&gt;
    ?FORALL(Nil, ws_wrap(gen_nil()),
            nil == edn:parse(Nil)).
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;Notice I haven&amp;#8217;t defined that &lt;code&gt;ws_wrap&lt;/code&gt; function yet. Remember that our goal here was to treat whitespace simply as a separator, so the property we want to define is that a real terminal surrounded by whitespace parses into that terminal. Let&amp;#8217;s teach QuickCheck how to wrap things in whitespace by making another generator, using our handy &lt;code&gt;?LET&lt;/code&gt; macro again:&lt;/p&gt;
&lt;pre&gt;
&lt;code class='erlang'&gt;%% Wrap another generator in whitespace
ws_wrap(Gen) -&gt;
    ?LET({LWS, V, TWS}, 
         {gen_ws(), Gen, gen_ws()},
         ?to_utf8([LWS, V, TWS])).
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;Thanks to &lt;code&gt;?LET&lt;/code&gt;, &lt;code&gt;ws_wrap&lt;/code&gt; defines a generator that will create some amount of leading whitespace (maybe none), evaluate the passed generator, and then some trailing whitespace (maybe none) and flatten it into a UTF-8 binary. Perfect, check that property!&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ rebar qc skip_deps=true
==&amp;gt; edn (qc)
NOTICE: Using experimental &amp;#39;qc&amp;#39; command
Compiled test/edn_eqc.erl
prop_nil: Starting Quviq QuickCheck version 1.25.1
   (compiled at {{2011,10,1},{13,42,22}})
Licence for Basho reserved until {{2012,10,11},{11,19,8}}
Failed! After 1 tests.
&amp;lt;&amp;lt;&amp;quot;nil&amp;quot;&amp;gt;&amp;gt;
prop_whitespace: ....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
OK, passed 500 tests
ERROR: One or more QC properties didn&amp;#39;t hold true:
[prop_nil]
ERROR: qc failed while processing /Users/sean/Development/edn: rebar_abort&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;We&amp;#8217;ve got a failing property again, and look how it shrunk! It&amp;#8217;s easy to see what broke, namely that, &lt;em&gt;DUH&lt;/em&gt;, we didn&amp;#8217;t define how to parse nil. That&amp;#8217;s easy to fix:&lt;/p&gt;
&lt;pre&gt;
&lt;code class='erlang'&gt;nil &amp;lt;- &quot;nil&quot; `nil`;
whitespace &amp;lt;- [,\s\v\f\r\n\t]+ `'$space'`;
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;Now, I could run the property again, but I&amp;#8217;ll save you the pain; simply adding that rule isn&amp;#8217;t going to cut it because nil must be surroundable by whitespace. Also, &lt;code&gt;neotoma&lt;/code&gt; won&amp;#8217;t compile that grammar because it contains nonterminals that are not referred anywhere else &amp;#8211; its convention is that the first rule is the entry point to the grammar. Let&amp;#8217;s add some rules that allow us to describe the syntactic form of whitespace, and the semantic behavior of empty streams at the same time.&lt;/p&gt;
&lt;pre&gt;
&lt;code class='erlang'&gt;edn &amp;lt;- whitespace? (term:term whitespace?)* `
case Node of
  %% Nothing but whitespace
  [ _, []] -&amp;gt;
        throw({edn,empty});
  %% Just one datum
  [ _, [[{term,Term}, _]]] -&amp;gt;
       Term;
  %% Lots of terms
  [ _, Terms ] -&amp;gt;
        [ T || [{term, T}, _WS] &amp;lt;- Terms ]
end
`;
 
term &amp;lt;- nil ~;
nil &amp;lt;- &quot;nil&quot; `nil`;
whitespace &amp;lt;- [,\s\v\f\r\n\t]+ `'$space'`;
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;This is the first time we&amp;#8217;ve seen significant code in the grammar, so I&amp;#8217;ll try to describe what&amp;#8217;s going on. In &lt;code&gt;neotoma&lt;/code&gt; grammars, you can include inline code between backticks or comment-braces (&lt;code&gt;%{&lt;/code&gt;, &lt;code&gt;%}&lt;/code&gt;) that will be run when a rule is successfully parsed. Within that code block, the variable &lt;code&gt;Node&lt;/code&gt; is sequence of terms that was parsed, so you can manipulate that to build the data structures you want to result from the parse. In the previous two rules, we&amp;#8217;ve been ignoring the parse result and simply returning static values. In our new &lt;code&gt;term&lt;/code&gt; rule, we are using the special-form of &lt;code&gt;~&lt;/code&gt; to skip doing any transformation, which is the equivalent of writing &lt;code&gt;%{ Node %}&lt;/code&gt;, but much less noisy.&lt;/p&gt;

&lt;p&gt;Now let&amp;#8217;s focus our attention on the top-level rule, &lt;code&gt;edn&lt;/code&gt;, which encapsulates our whitespace and stream behavior. It says that leading whitespace is optional, followed by zero-or-more terms separated by whitespace. We tag the terms as they are parsed so they are easier to pattern-match on and extract. Now in the code block, we can do something with parse. If the parenthesized portion parses zero times, the result will be an empty list, so we handle that case by throwing a special term like I mentioned above. In the case of parsing only a single term, we want to return &lt;strong&gt;only&lt;/strong&gt; that term, and it not wrapped in a list, so we special-case that parse as well. Finally, if there is a stream of terms, for now we will just extract them and return them in a list.&lt;/p&gt;

&lt;p&gt;Let&amp;#8217;s recompile the grammar and try our properties again.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ rebar compile qc skip_deps=true
==&amp;gt; edn (compile)
Compiled src/edn.peg
Compiled src/edn.erl
==&amp;gt; edn (qc)
NOTICE: Using experimental &amp;#39;qc&amp;#39; command
Compiled src/edn.erl
prop_nil: Starting Quviq QuickCheck version 1.25.1
   (compiled at {{2011,10,1},{13,42,22}})
Licence for Basho reserved until {{2012,10,11},{11,19,8}}
....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
OK, passed 500 tests
prop_whitespace: Failed! Reason: 
{&amp;#39;EXIT&amp;#39;,{{case_clause,{edn,empty}},
         [{eqc,&amp;#39;-f777_0/2-fun-4-&amp;#39;,3,[]},
          {eqc_gen,&amp;#39;-f321_0/2-fun-0-&amp;#39;,5,[]},
          {eqc_gen,f186_0,2,[]},
          {eqc_gen,&amp;#39;-f321_0/2-fun-0-&amp;#39;,5,[]},
          {eqc_gen,f186_0,2,[]},
          {eqc_gen,gen,3,[]},
          {eqc,&amp;#39;-f758_0/1-fun-2-&amp;#39;,3,[]},
          {eqc_gen,&amp;#39;-f321_0/2-fun-1-&amp;#39;,4,[]}]}}
After 1 tests.
ERROR: One or more QC properties didn&amp;#39;t hold true:
[prop_whitespace]
ERROR: qc failed while processing /Users/sean/Development/edn: rebar_abort&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Woops, we broke the whitespace property because we didn&amp;#8217;t expect the throw! (One might call this letting your code get ahead of your tests.) Let&amp;#8217;s change that to use an assertion provided by &lt;code&gt;eunit&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;
&lt;code class='erlang'&gt;%% You must put this AFTER the EQC header file.
-include_lib(&quot;eunit/include/eunit.hrl&quot;).

%% [snip]

prop_whitespace() -&gt;
    ?FORALL(Spaces, gen_ws(),
            ok == ?assertThrow({edn, empty}, edn:parse(Spaces))).
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;Run that one more time.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ rebar qc skip_deps=true
==&amp;gt; edn (qc)
NOTICE: Using experimental &amp;#39;qc&amp;#39; command
Compiled test/edn_eqc.erl
prop_nil: Starting Quviq QuickCheck version 1.25.1
   (compiled at {{2011,10,1},{13,42,22}})
Licence for Basho reserved until {{2012,10,11},{11,19,8}}
....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
OK, passed 500 tests
prop_whitespace: ....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
OK, passed 500 tests&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Cool, now we can integrate that boolean generator and write a property for it.&lt;/p&gt;
&lt;pre&gt;
&lt;code class='erlang'&gt;prop_bool() -&gt;
    ?FORALL(Boolean, ws_wrap(gen_bool()),
            lists:member(edn:parse(Boolean), [true, false])).
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;I think you get the drill now, let&amp;#8217;s assume you ran that, you would get the &lt;code&gt;{edn, empty}&lt;/code&gt; thrown because it will stop parsing at the first valid tree before an unknown character. Let&amp;#8217;s add the rule to the grammar:&lt;/p&gt;
&lt;pre&gt;
&lt;code class='erlang'&gt;edn &amp;lt;- whitespace? (term:term whitespace?)* `
case Node of
  %% Nothing but whitespace
  [ _, []] -&gt;
        throw({edn,empty});
  %% Just one datum
  [ _, [[{term,Term}, _]]] -&gt;
       Term;
  %% Lots of terms
  [ _, Terms ] -&gt;
        [ T || [{term, T}, _WS] &amp;lt;- Terms ]
end
`;

term &amp;lt;- boolean / nil ~;
boolean &amp;lt;- &quot;true&quot; / &quot;false&quot; `binary_to_existing_atom(Node, utf8)`;
nil &amp;lt;- &quot;nil&quot; `nil`;
whitespace &amp;lt;- [,\s\v\f\r\n\t]+ `'$space'`;
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;On the &lt;code&gt;term&lt;/code&gt; rule, we just added &lt;code&gt;boolean&lt;/code&gt; to one of the possible terms, using ordered choice, and use the &lt;code&gt;binary_to_existing_atom/2&lt;/code&gt; BIF in the &lt;code&gt;boolean&lt;/code&gt; rule to create the proper Erlang term. One last time, let&amp;#8217;s compile the grammar and run the properties:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ rebar compile qc skip_deps=true
==&amp;gt; edn (compile)
Compiled src/edn.peg
Compiled src/edn.erl
==&amp;gt; edn (qc)
NOTICE: Using experimental &amp;#39;qc&amp;#39; command
Compiled src/edn.erl
prop_nil: Starting Quviq QuickCheck version 1.25.1
   (compiled at {{2011,10,1},{13,42,22}})
Licence for Basho reserved until {{2012,10,11},{11,19,8}}
....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
OK, passed 500 tests
prop_whitespace: ....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
OK, passed 500 tests
prop_bool: ....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
OK, passed 500 tests&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id='puzzler'&gt;Puzzler&lt;/h2&gt;

&lt;p&gt;So far I&amp;#8217;ve lead you through it by hand, including most of the missteps along the way. I&amp;#8217;ve gone way past this point in the &lt;a href='https://github.com/seancribbs/edn-erlang'&gt;actual project&lt;/a&gt;, including doing more complicated-to-parse types like numbers. Given the grammar and properties in the project on Github, can you figure out why &lt;code&gt;prop_symbol()&lt;/code&gt; fails? The answer is subtle.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ rebar qc skip_deps=true
==&amp;gt; edn (qc)
NOTICE: Using experimental &amp;#39;qc&amp;#39; command
Compiled test/edn_eqc.erl
Compiled src/edn.erl
prop_whitespace: Starting Quviq QuickCheck version 1.25.1
   (compiled at {{2011,10,1},{13,42,22}})
Licence for Basho reserved until {{2012,9,30},{14,35,1}}
....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
OK, passed 500 tests
prop_bool: ....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
OK, passed 500 tests
prop_nil: ....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
OK, passed 500 tests
prop_unescape: ....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
OK, passed 500 tests
prop_string: ....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
OK, passed 500 tests
prop_symbol: ............................................................................................................................................................................................................................................................................Failed! After 269 tests.
&amp;lt;&amp;lt;&amp;quot;\v\v\n\r  ,, ,\r\t-3fAloF0oZXp8 ,&amp;quot;&amp;gt;&amp;gt;
Shrinking...(3 times)
&amp;lt;&amp;lt;&amp;quot;-3&amp;quot;&amp;gt;&amp;gt;
prop_character: ....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
OK, passed 500 tests
prop_integer: ....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
OK, passed 500 tests
prop_float: ....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
OK, passed 500 tests
ERROR: One or more QC properties didn&amp;#39;t hold true:
[prop_symbol]
ERROR: qc failed while processing /Users/sean/Development/edn:
rebar_abort&lt;/code&gt;&lt;/pre&gt;</content>
    </entry>
  
    <entry>
      <author><name>Sean Cribbs</name></author>
      <published>2012-02-23T22:15:40Z</published>
      <title>Screencast: Riak Client Multi-node Connections</title>
      <link rel="alternate" type="text/html" 
        href="http://seancribbs.com/tech/2012/02/23/riak-client-multinode/" />
      <id>http://seancribbs.com/tech/2012/02/23/riak-client-multinode/</id>
      <content type="html">&lt;p&gt;The Riak client for Ruby (&lt;code&gt;riak-client&lt;/code&gt;) was released a few weeks ago and it includes some really useful features for working with Riak from your Ruby applications.&lt;/p&gt;

&lt;p&gt;This second screencast demonstrates the multi-node or &amp;#8220;cluster&amp;#8221; connection feature in the client, and the effect that has on performance and reliability. Co-starring in this video is &lt;a href='http://basho.com/blog/technical/2012/02/22/Riak-Control/'&gt;Riak Control&lt;/a&gt;, Riak 1.1&amp;#8217;s new web-based administration tool.&lt;/p&gt;
&lt;iframe allowFullScreen='true' frameborder='0' height='360' mozallowfullscreen='true' src='http://player.vimeo.com/video/37340458?byline=0&amp;amp;portrait=0' webkitAllowFullScreen='true' width='640'&gt;
&lt;/iframe&gt;
&lt;p&gt;&lt;a href='http://vimeo.com/37340458'&gt;Riak Ruby Client 1.0: Multi-node connections&lt;/a&gt; from &lt;a href='http://vimeo.com/seancribbs'&gt;Sean Cribbs&lt;/a&gt; on &lt;a href='http://vimeo.com'&gt;Vimeo&lt;/a&gt;.&lt;/p&gt;</content>
    </entry>
  
    <entry>
      <author><name>Sean Cribbs</name></author>
      <published>2012-02-09T19:50:40Z</published>
      <title>Screencast: Riak Client Serializers</title>
      <link rel="alternate" type="text/html" 
        href="http://seancribbs.com/tech/2012/02/09/riak-client-serializers/" />
      <id>http://seancribbs.com/tech/2012/02/09/riak-client-serializers/</id>
      <content type="html">&lt;p&gt;The Riak client for Ruby (&lt;code&gt;riak-client&lt;/code&gt;) was released a few weeks ago and it includes some really useful features for working with Riak from your Ruby applications. Here&amp;#8217;s my first screencast about those features, which describes how to use custom serializers. Enjoy! (Watch on Vimeo for the best experience.)&lt;/p&gt;
&lt;iframe allowFullScreen='true' frameborder='0' height='360' mozallowfullscreen='true' src='http://player.vimeo.com/video/36516075?byline=0&amp;amp;portrait=0' webkitAllowFullScreen='true' width='640'&gt;
&lt;/iframe&gt;
&lt;p&gt;&lt;a href='http://vimeo.com/36516075'&gt;Riak Ruby Client 1.0: Serializers&lt;/a&gt; from &lt;a href='http://vimeo.com/seancribbs'&gt;Sean Cribbs&lt;/a&gt; on &lt;a href='http://vimeo.com'&gt;Vimeo&lt;/a&gt;.&lt;/p&gt;</content>
    </entry>
  
    <entry>
      <author><name>Sean Cribbs</name></author>
      <published>2012-01-16T15:00:00Z</published>
      <title>Webmachine vs. Grape</title>
      <link rel="alternate" type="text/html" 
        href="http://seancribbs.com/tech/2012/01/16/webmachine-vs-grape/" />
      <id>http://seancribbs.com/tech/2012/01/16/webmachine-vs-grape/</id>
      <content type="html">&lt;p&gt;Back in December, I gave my &lt;a href='http://rubyconf-webmachine.heroku.com/'&gt;&lt;em&gt;Resources, For Real This Time&lt;/em&gt;&lt;/a&gt; talk for the third time, this time at NYC.rb. After the talk, I got into a very emphatic discussion with &lt;a href='http://code.dblock.org'&gt;Daniel Doubrovkine&lt;/a&gt; and &lt;a href='http://twitter.com/johnjoseph'&gt;John &amp;#8220;JJB&amp;#8221; Bachir&lt;/a&gt; about the differences between &lt;a href='https://github.com/seancribbs/webmachine-ruby'&gt;Webmachine&lt;/a&gt;&amp;#8217;s approach and &lt;a href='https://github.com/intridea/grape'&gt;Grape&lt;/a&gt;&amp;#8217;s approach and their relative strengths. Daniel followed it up with an interesting blog post titled &lt;a href='http://code.dblock.org/grape-vs-webmachine'&gt;Grape vs. Webmachine&lt;/a&gt;. I&amp;#8217;ve had some time to think it all over and so I figured it was about time I wrote a response.&lt;/p&gt;

&lt;p&gt;Daniel poses the question &amp;#8220;Should you build your next RESTful API with Grape or Webmachine?&amp;#8221; Before I address his question (and the inherent assumptions therein), I want to tell you a bit more about Webmachine and why it is fundamentally different from the prevailing approaches.&lt;/p&gt;

&lt;h3 id='protocols_are_contracts'&gt;Protocols are contracts&lt;/h3&gt;

&lt;p&gt;If you Google &amp;#8221;&lt;a href='http://www.google.com/search?q=define%3A+protocol'&gt;define: protocol&lt;/a&gt;&amp;#8221;, two definitions appear:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The official procedure governing affairs of state or diplomatic occasions.&lt;/li&gt;

&lt;li&gt;The established code of procedure or behavior in any group, organization, or situation.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href='http://www.merriam-webster.com/dictionary/protocol'&gt;Merriam-Webster&lt;/a&gt; gives some additionally detailed definitions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;a code prescribing strict adherence to correct etiquette and precedence (as in diplomatic exchange and in the military services) &amp;#60;a breach of &lt;em&gt;protocol&lt;/em&gt;&amp;#62;&lt;/li&gt;

&lt;li&gt;a set of conventions governing the treatment and especially the formatting of data in an electronic communications system &amp;#60;network &lt;em&gt;protocols&lt;/em&gt;&amp;#62;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Another way of saying this is that &lt;em&gt;protocols are contracts&lt;/em&gt; or &lt;em&gt;conventional manners of speech and behavior&lt;/em&gt;. To violate that contract is to be misunderstood, worse, to offend or to cause unintended actions. Granted, computer protocols may have lesser social consequences than social protocols, but if we don&amp;#8217;t speak them properly, our programs won&amp;#8217;t work.&lt;/p&gt;

&lt;h3 id='protocols_are_fsms'&gt;Protocols are FSMs&lt;/h3&gt;

&lt;p&gt;The classical way to implement a protocol participant (that is, a client, server or peer) is a &lt;a href='http://en.wikipedia.org/wiki/Finite-state_machine'&gt;finite state machine&lt;/a&gt; (FSM). Why? Protocols are usually defined in terms of &amp;#8220;in this situation, do that&amp;#8221; or &amp;#8220;react to this condition by doing that&amp;#8221;. Many of those assertions are dependent on one another, meaning that they are not even relevant if other assertions have not been made previously. To illustrate this better, imagine the protocol of two heads of state meeting. Their meeting might go through these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Arrive at the same location.&lt;/li&gt;

&lt;li&gt;Shake hands and introduce other participants.&lt;/li&gt;

&lt;li&gt;Enter the meeting space.&lt;/li&gt;

&lt;li&gt;Negotiate an issue.&lt;/li&gt;

&lt;li&gt;Leave the meeting space.&lt;/li&gt;

&lt;li&gt;Arrive and speak at the press conference.&lt;/li&gt;

&lt;li&gt;Shake hands again.&lt;/li&gt;

&lt;li&gt;Depart the press conference.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;First, this is a discrete set of steps that must be followed in the order given. It wouldn&amp;#8217;t make much sense to negotiate the issue (which might have its own internal protocol) before you shake hands and enter the meeting space, or to discuss the negotiations at the press conference before you&amp;#8217;ve done any negotiation. Second, if one part of the protocol fails, other steps in the protocol may never occur! Imagine that upon arrival, the other head of state refuses to shake your hand or even look at you; you might abort the meeting altogether.&lt;/p&gt;

&lt;p&gt;Like protocols, in finite state machines, there are also discrete steps (states), and conditions that allow transition from one state to another. A transition may lead to another internal state, or an end state in which processing is terminated. Finite state machines are the essential way to implement protocols.&lt;/p&gt;

&lt;p&gt;And interesting side-effect of this coherence between protocol and FSM is that they are duals of each other. The FSM is an implementation of the protocol, and the protocol&amp;#8217;s states and assertions can be derived from the FSM. It&amp;#8217;s the kind of thing that researchers interested in provability and mathematical formulations of software get really excited about.&lt;/p&gt;

&lt;h3 id='so_what_does_this_have_to_do_with_webmachine_and_grape'&gt;So what does this have to do with Webmachine and Grape?&lt;/h3&gt;

&lt;p&gt;HTTP happens to be a protocol with a simple syntax but very rich semantic possibilities. If your application &amp;#8220;misspeaks&amp;#8221; HTTP, it might still be partially understood (the syntax may still be grasped), but the other party might miss out on some crucial subtlety your application wants to convey or might take an unexpected or undesirable action as a result.&lt;/p&gt;

&lt;p&gt;Despite HTTP&amp;#8217;s flexibility (laxness?), it&amp;#8217;s still important to speak the protocol as fluently as possible. Building a better Web is just as much about the brick and mortar (the HTTP protocol) as the paint and trim (&amp;#8220;Web Standards&amp;#8221; in the browser).&lt;/p&gt;

&lt;p&gt;Webmachine tries to do just that. Its core is an FSM of the server side of HTTP. The end states are response status codes (e.g. 200 OK or 404 Not Found). The transition conditions come from the &amp;#8220;MAY&amp;#8221;, &amp;#8220;MUST&amp;#8221;, &amp;#8220;SHOULD&amp;#8221; language in the &lt;a href='tools.ietf.org/html/rfc2616'&gt;HTTP/1.1 RFC 2616&lt;/a&gt; as well as the less formal aspects of the specification. The FSM determines which transitions to take based on facts about the request and facts about the resource being requested. Because the FSM is a dual of the HTTP protocol, we at Basho have taken to calling Webmachine &amp;#8220;an executable model of HTTP.&amp;#8221;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This is where Webmachine fundamentally differs from Grape and other existing frameworks:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It implements an FSM that is a dual of the protocol, not an ever-varying stack of middleware.&lt;/li&gt;

&lt;li&gt;It focuses on determining facts about the resource, not performing actions.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is what I mean when I say that Webmachine is declarative (functional?) rather than imperative. By being declarative and focusing on the facts about your resource rather than &amp;#8220;what do I do when I get a request&amp;#8221;, a whole lot of complex and error-prone aspects of the protocol are hidden from the developer, and more importantly, done in a deterministic way every time.&lt;/p&gt;

&lt;p&gt;In contrast, Grape and most other Rack-based frameworks encourage you to (perhaps unwittingly) redefine HTTP semantics for every application. In my opinion, this is not just error-prone, it is wasteful. Why should you have to define what GET means everytime? You want to focus on the resources your application exposes, not implementing the protocol all over again. This is why Webmachine encapsulates those decisions (FSM!) and includes sensible defaults so that you only have to focus on the decisions and behaviors (transitions!) that your resources need to modify. You focus on what your resources &lt;em&gt;are&lt;/em&gt;, rather than what they &lt;em&gt;do&lt;/em&gt;.&lt;/p&gt;

&lt;h3 id='rest_for_real_this_time'&gt;REST, For Real This Time&lt;/h3&gt;

&lt;p&gt;Daniel is by no means the only or greatest offender, but I take strong objection to his use of &amp;#8220;REST&amp;#8221;. He says,&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Grape is a DSL for RESTful APIs.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Simply exposing your service over HTTP and not treating it like RPC is not sufficient to be called &amp;#8220;RESTful&amp;#8221;, you must satisfy the &amp;#8220;Hypermedia Constraint&amp;#8221;. Daniel admits&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&amp;#8230;you have to be disciplined about those API methods - they should represent resources, not RPC service endpoints.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&amp;#8230;but does not address Hypermedia. I could go into great detail about why the typical HTTP-based API is not REST, but that has been done by some really great people who have said it much better, &lt;a href='http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven'&gt;Roy Fielding&lt;/a&gt;, &lt;a href='http://oredev.org/2010/sessions/hypermedia-apis'&gt;Jon Moore&lt;/a&gt; and &lt;a href='http://nicksda.apotomo.de/'&gt;Nick Sutterer&lt;/a&gt;. Do check out their presentations and blogs.&lt;/p&gt;

&lt;h3 id='a_note_on_dsls'&gt;A note on &amp;#8220;DSLs&amp;#8221;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Rubyists, we have a fetish for so-called &amp;#8220;DSLs&amp;#8221;.&lt;/strong&gt; It&amp;#8217;s time for an intervention.&lt;/p&gt;

&lt;p&gt;In reality, what we call DSLs in Ruby tend to be thin wrappers around the fluent-builder pattern with a dash of &lt;code&gt;instance_eval&lt;/code&gt; and &lt;code&gt;class_eval&lt;/code&gt; to remove block arguments and necessary uses of &lt;code&gt;self&lt;/code&gt;. (One lightning talk at RubyConf humorously called gratuitous use of the pattern &amp;#8220;Playskool MyFirstDSL&amp;#8221;.) Grape, and its elder cousin Sinatra, follow this pattern. On the surface, it seems to promote clean, concise, readable code. But at what cost? What complexity is hidden? Does it actually help you write better code, faster and more reliably, or are you in the end working around the DSL to do what you want?&lt;/p&gt;

&lt;p&gt;So this is where I take big issue with Daniel&amp;#8217;s argument:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I would grant Grape an advantage over favoring the API consumer, since it focuses on the expressiveness of the API.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That warm fuzzy the developer gets when writing an application with Grape is not correlated to the experience of the consumer of the API. It is indeed a strength that Grape can generate API consumer documentation from the code, but as Moore and Sutterer demonstrate, a truly RESTful service is mostly self-documenting.&lt;/p&gt;

&lt;p&gt;Maybe it&amp;#8217;s the fact that Webmachine(-Ruby) is a fairly faithful port of the original Erlang version, but when authoring it I felt disillusioned with metaprogramming magic. Instead of including a module and executing some class methods to decorate your Resource class, you use simple inheritance and override methods. Internally, modules only exist as namespaces and to separate functional concerns of the same class (see &lt;code&gt;Webmachine::Decision::Conneg&lt;/code&gt; or &lt;code&gt;Webmachine::Resource::Callbacks&lt;/code&gt;), they are never used to decorate or modify the behavior of the class they are included in. &lt;code&gt;Webmachine::Decision::FSM&lt;/code&gt; uses a loop to walk the decision graph, where individual state methods either return a &lt;code&gt;Symbol&lt;/code&gt; for the next state or a &lt;code&gt;Fixnum&lt;/code&gt; that is the response status code.&lt;/p&gt;

&lt;p&gt;That said, others have been working on higher level abstractions on top of Webmachine, ones that include &amp;#8220;DSLs&amp;#8221;. Whether they will provide more value or simplicity over the existing abstractions Webmachine provides has yet to shake out.&lt;/p&gt;

&lt;h3 id='so_which_should_you_use'&gt;So which should you use?&lt;/h3&gt;

&lt;p&gt;I think if I were still doing web APIs via Rails or Sinatra, Grape would be an extremely attractive alternative to those, having a lower barrier to entry than Webmachine. It&amp;#8217;s a great library and very well written. For an application that exposes very simple semantics, the amount of code you need to write in Grape is small, and you don&amp;#8217;t need to have any awareness or understanding of Webmachine&amp;#8217;s decision flow, and you can get consumer documentation nearly for free.&lt;/p&gt;

&lt;p&gt;On the other hand, I have been just as productive in Webmachine (both Ruby and Erlang) and now that I think more in terms of resources instead of actions, it feels more natural. I want to be able to add those extra semantics just by declaring a few methods, without worrying as much about whether I did it right. I want to avoid the cross-cutting, double-blind mentality of the middleware pattern promoted by Rack.&lt;/p&gt;

&lt;h3 id='what_next'&gt;What next?&lt;/h3&gt;

&lt;p&gt;Like Webmachine has done for the server side, I think we can also do for the client side and for intermediaries (which act as both clients and servers). We can encapsulate the client side of HTTP into an FSM and expose its decisions in a clean way to applications. We can build client and server-side libraries that make working with Hypermedia APIs simpler (Nick&amp;#8217;s &lt;a href='https://github.com/apotonick/roar'&gt;Roar&lt;/a&gt; project is a good start).&lt;/p&gt;</content>
    </entry>
  
    <entry>
      <author><name>Sean Cribbs</name></author>
      <published>2011-11-07T18:41:35Z</published>
      <title>MongoDB and Riak, In Context (and an apology)</title>
      <link rel="alternate" type="text/html" 
        href="http://seancribbs.com/tech/2011/11/07/mongodb-and-riak-in-context-and-an-apology/" />
      <id>http://seancribbs.com/tech/2011/11/07/mongodb-and-riak-in-context-and-an-apology/</id>
      <content type="html">&lt;p&gt;There has been quite a bit of &lt;a href='http://news.ycombinator.com/item?id=3207203'&gt;furor&lt;/a&gt; and &lt;a href='http://blog.schmichael.com/2011/11/05/failing-with-mongodb/'&gt;excitement&lt;/a&gt; on the Internet this week regarding some very public criticisms (and defenses) of MongoDB and its creators, &lt;a href='http://10gen.com'&gt;10gen&lt;/a&gt;. Unfortunately, a &lt;a href='http://luigimontanez.com/2011/mongodb-2.0-should-have-been-1.0/'&gt;ghost from my recent past also resurfaced&lt;/a&gt; as a result. Let me begin by apologizing to 10gen and its engineers for &lt;a href='https://twitter.com/#!/sintaxi/status/65550206825005057'&gt;what I said at JSConf&lt;/a&gt;, and then I will reframe my comments in a more constructive form.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Mea culpa&lt;/em&gt;. It&amp;#8217;s way too easy in our industry to set up and knock down strawmen, as I did, than to convey messages of objective and constructive criticism. It&amp;#8217;s also too easy, when you are passionate about what you believe in, to ignore the feelings and efforts of others, which I did. I have great respect for the engineers I have met from 10gen, Mathias Stern and Kyle Banker. They are friendly, approachable, helpful and fun to socialize with at conferences. Thanks for being stand-up guys.&lt;/p&gt;

&lt;p&gt;Also, whether we like it or not, these kinds of public embarrassments have rippling effects across the whole NoSQL ecosystem. While Basho has tried to distance itself from other players in the NoSQL field, we cannot deny our origins, and the ecosystem as a &amp;#8220;thing&amp;#8221; is only about 3 years old. Are developers, technical managers and CTOs more wary of new database technologies as a result of these embarrassments? Probably. Should we continue to work hard to develop and promote alternative data-storage solutions? Absolutely.&lt;/p&gt;

&lt;h2 id='making_it_constructive'&gt;Making it constructive&lt;/h2&gt;

&lt;p&gt;For better or worse, many people consider MongoDB and Riak to be competitors. In reality, there are very few similarities between the products. &lt;em&gt;Then why are they in competition?&lt;/em&gt; I personally believe this is because we have largely targeted our products at the same group of developers, those who work on web applications. So let&amp;#8217;s take a moment and clarify the primary differences &amp;#8212; both for understanding the technologies themselves and for unmuddying the current hoopla.&lt;/p&gt;

&lt;p&gt;If I were asked why someone would use MongoDB, there are two clear reasons in my mind:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;MongoDB is &lt;em&gt;fast&lt;/em&gt;. Say what you will about its durability (the context of my comment from JSConf) and the global write-lock (a consequence of its design, unfortunately), both writes and reads tend to be of low latency. Why? They are mostly in memory (via mmap).&lt;/li&gt;

&lt;li&gt;MongoDB has very friendly APIs for developers. This is its biggest strength in my mind. Despite other things you would want to address before going to production, developers love to think of their data as lightly-structured documents. &lt;em&gt;It just makes sense&lt;/em&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In contrast, Riak&amp;#8217;s strengths appeal more to operations folk, and developers who are cognizant or experienced in production operations:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Riak is distributed and replicated &lt;em&gt;at its core&lt;/em&gt;. There are no special nodes or services to run to scale out, every node you start and join acts equally among the cluster.&lt;/li&gt;

&lt;li&gt;Riak has a strong focus on availability and durability in the face of failure. It will gladly sacrifice raw speed and consistency for the sake of staying available to your write load and making sure your writes get to disk.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These differences are fundamental design decisions and have associated trade-offs. Because MongoDB&amp;#8217;s design focus is to be a fast single-system database, other elements of its scale-out story are necessarily more complex &amp;#8212; sharding, replica sets, etc. Because Riak&amp;#8217;s focus is on distributed fault-tolerance and reliability, it necessarily sacrifices raw single-system performance. That&amp;#8217;s not to say that MongoDB can&amp;#8217;t scale out to large clusters well, or that Riak performs poorly in production, it is simply a recognition of the sacrifices necessary when designing a database system that addresses specific needs.&lt;/p&gt;

&lt;p&gt;Could Urban Airship have used Riak instead of MongoDB for their bounded, in-memory dataset? Maybe. Would it have worked better for them than MongoDB? That is really difficult to tell.&lt;/p&gt;

&lt;h1 id='bringing_it_back_around'&gt;Bringing it back around&lt;/h1&gt;

&lt;p&gt;Now, if I&amp;#8217;m so buddy-buddy with the 10gen guys, why did I say such an inflammatory thing in the first place? At Basho, we spend a decent amount of time evaluating and comparing other technologies so that we can understand where we stand in the market, to learn from others&amp;#8217; perspectives, and to address the concerns and demands of potential customers. Naturally, this means we have examined MongoDB closely. MongoDB&amp;#8217;s visibility, popularity, and developer-friendliness are things to be respected, even if we criticize the engineering decisions made by 10gen.&lt;/p&gt;

&lt;p&gt;Shortly before JSConf, I had personally spent some time finding out ways to demonstrate that MongoDB will lose writes in the face of failure, to be used in a competitive comparison. Let&amp;#8217;s just say that I was successful in doing so, despite recent improvements that 10gen has made. Unfortunately, I am not at liberty to share the results, nor do I think it would be constructive to this discussion. I&amp;#8217;m sure 10gen has its own collection of competitive comparisons that are designed to shed a positive light on their product in contrast to Riak, it&amp;#8217;s just how business works.&lt;/p&gt;

&lt;p&gt;We also both know our system&amp;#8217;s weaknesses and are working hard to fix them. 10gen&amp;#8217;s most recent releases have demonstrated this fact, as I believe Basho&amp;#8217;s recent releases have as well. (Have you tried out Riak 1.0? It&amp;#8217;s awesome.)&lt;/p&gt;

&lt;h1 id='so_what_now'&gt;So what now?&lt;/h1&gt;

&lt;p&gt;The honeymoon phase of NoSQL is over. Will 10gen make the hard decisions it needs to make MongoDB is easier to scale out and have greater durability, while maintain its reputation for snappy performance? I believe they will. Will Basho improve Riak&amp;#8217;s developer-friendliness and raw performance, while maintaining its reputation for simplicity and reliability in operations? I have no doubt.&lt;/p&gt;

&lt;p&gt;So instead of gloating over each others&amp;#8217; failures, let&amp;#8217;s toast to the challenges and all become stronger, more proficient, and more successful as a result.&lt;/p&gt;</content>
    </entry>
  
</feed>
