diff options
Diffstat (limited to 'articles')
29 files changed, 4854 insertions, 4892 deletions
diff --git a/articles/cowboy-2.0.0-pre.4/index.html b/articles/cowboy-2.0.0-pre.4/index.html index 2158aa7a..2a23be43 100644 --- a/articles/cowboy-2.0.0-pre.4/index.html +++ b/articles/cowboy-2.0.0-pre.4/index.html @@ -7,7 +7,7 @@ <meta name="description" content=""> <meta name="author" content="Loïc Hoguin based on a design from (Soft10) Pol Cámara"> - <meta name="generator" content="Hugo 0.17" /> + <meta name="generator" content="Hugo 0.26" /> <title>Nine Nines: Cowboy 2.0 pre-release 4</title> @@ -74,116 +74,116 @@ </p> </header> -<div class="paragraph"><p>Cowboy <code>2.0.0-pre.4</code> has been released!</p></div>
-<div class="paragraph"><p>This is the new recommended version of Cowboy.
-While I would not recommend putting it in production
-just yet, I do recommend you start writing new
-applications with this Cowboy version.</p></div>
-<div class="paragraph"><p>The most significant changes in the pre-release are:</p></div>
-<div class="ulist"><ul>
-<li>
-<p>
-A new architecture: there now is one process per
- connection and one process per request. This was
- done because HTTP/2 allows running requests concurrently.
-</p>
-</li>
-<li>
-<p>
-Stream handlers. Every request, response and data goes
- through stream handlers. They are meant to replace hooks
- and more. They will be documented in a future pre-release.
- Check <code>cowboy_stream</code> and <code>cowboy_stream_h</code> if interested.
-</p>
-</li>
-<li>
-<p>
-Numerous changes to the <code>cowboy_req</code> interface. This
- is very close to final. Check the manual for what changed.
-</p>
-</li>
-<li>
-<p>
-The Req object is no longer passed in Websocket callbacks.
-</p>
-</li>
-<li>
-<p>
-It is now possible to send frames directly from <code>websocket_init/1</code>.
-</p>
-</li>
-<li>
-<p>
-SPDY support was removed, now that we have HTTP/2.
-</p>
-</li>
-<li>
-<p>
-Update Ranch to 1.3. We still depend on Cowlib master
- for the time being.
-</p>
-</li>
-<li>
-<p>
-A much improved manual.
-</p>
-</li>
-</ul></div>
-<div class="paragraph"><p>The manual received a lot of love. It now has one page per
-function with a detailed description, arguments list, return
-value, changelog and examples. It also links to the other
-relevant manual pages: <a href="https://ninenines.eu/docs/en/cowboy/2.0/manual/">https://ninenines.eu/docs/en/cowboy/2.0/manual/</a></p></div>
-<div class="paragraph"><p>I am quite proud of the manual right now. While more
-improvements can be made, what we have now is way better
-than before. Feedback for further improvements is welcome!</p></div>
-<div class="paragraph"><p>This is a significant step toward Cowboy 2.0. Almost all
-the breaking changes are in. A few more pre-releases are
-planned and will be released on a weekly basis (with exceptions).</p></div>
-<div class="paragraph"><p>Cowboy is now tested and supported with Erlang/OTP 18.0 or above
-on Arch Linux, FreeBSD, OSX, Ubuntu and Windows 7. Contact me
-if you can provide permanent access to another platform for the
-purposes of testing.</p></div>
-<div class="paragraph"><p>Cowboy is now available from four locations:</p></div>
-<div class="ulist"><ul>
-<li>
-<p>
-<a href="https://git.ninenines.eu/cowboy.git">https://git.ninenines.eu/cowboy.git</a>
-</p>
-</li>
-<li>
-<p>
-<a href="https://github.com/ninenines/cowboy.git">https://github.com/ninenines/cowboy.git</a>
-</p>
-</li>
-<li>
-<p>
-<a href="https://bitbucket.org/ninenines/cowboy.git">https://bitbucket.org/ninenines/cowboy.git</a>
-</p>
-</li>
-<li>
-<p>
-<a href="https://gitlab.com/ninenines/cowboy.git">https://gitlab.com/ninenines/cowboy.git</a>
-</p>
-</li>
-</ul></div>
-<div class="paragraph"><p>They are updated at the same time so there is no real difference.</p></div>
-<div class="paragraph"><p>Cowboy 2.0 will be released once all the breaking changes
-are completed and the temporarily removed features are
-added back.</p></div>
-<div class="paragraph"><p>Thanks for your patience. I know it took a long time.</p></div>
-<hr/>
-<div class="paragraph"><p>Half-price on all donations because I need a new hat:</p></div>
-<form action="https://www.paypal.com/cgi-bin/webscr" method="post" style="display:inline">
-<input type="hidden" name="cmd" value="_donations">
-<input type="hidden" name="business" value="[email protected]">
-<input type="hidden" name="lc" value="FR">
-<input type="hidden" name="item_name" value="Loic Hoguin">
-<input type="hidden" name="item_number" value="99s">
-<input type="hidden" name="currency_code" value="EUR">
-<input type="hidden" name="bn" value="PP-DonationsBF:btn_donate_LG.gif:NonHosted">
-<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
-<img alt="" border="0" src="https://www.paypalobjects.com/fr_FR/i/scr/pixel.gif" width="1" height="1">
-</form>
+<div class="paragraph"><p>Cowboy <code>2.0.0-pre.4</code> has been released!</p></div> +<div class="paragraph"><p>This is the new recommended version of Cowboy. +While I would not recommend putting it in production +just yet, I do recommend you start writing new +applications with this Cowboy version.</p></div> +<div class="paragraph"><p>The most significant changes in the pre-release are:</p></div> +<div class="ulist"><ul> +<li> +<p> +A new architecture: there now is one process per + connection and one process per request. This was + done because HTTP/2 allows running requests concurrently. +</p> +</li> +<li> +<p> +Stream handlers. Every request, response and data goes + through stream handlers. They are meant to replace hooks + and more. They will be documented in a future pre-release. + Check <code>cowboy_stream</code> and <code>cowboy_stream_h</code> if interested. +</p> +</li> +<li> +<p> +Numerous changes to the <code>cowboy_req</code> interface. This + is very close to final. Check the manual for what changed. +</p> +</li> +<li> +<p> +The Req object is no longer passed in Websocket callbacks. +</p> +</li> +<li> +<p> +It is now possible to send frames directly from <code>websocket_init/1</code>. +</p> +</li> +<li> +<p> +SPDY support was removed, now that we have HTTP/2. +</p> +</li> +<li> +<p> +Update Ranch to 1.3. We still depend on Cowlib master + for the time being. +</p> +</li> +<li> +<p> +A much improved manual. +</p> +</li> +</ul></div> +<div class="paragraph"><p>The manual received a lot of love. It now has one page per +function with a detailed description, arguments list, return +value, changelog and examples. It also links to the other +relevant manual pages: <a href="https://ninenines.eu/docs/en/cowboy/2.0/manual/">https://ninenines.eu/docs/en/cowboy/2.0/manual/</a></p></div> +<div class="paragraph"><p>I am quite proud of the manual right now. While more +improvements can be made, what we have now is way better +than before. Feedback for further improvements is welcome!</p></div> +<div class="paragraph"><p>This is a significant step toward Cowboy 2.0. Almost all +the breaking changes are in. A few more pre-releases are +planned and will be released on a weekly basis (with exceptions).</p></div> +<div class="paragraph"><p>Cowboy is now tested and supported with Erlang/OTP 18.0 or above +on Arch Linux, FreeBSD, OSX, Ubuntu and Windows 7. Contact me +if you can provide permanent access to another platform for the +purposes of testing.</p></div> +<div class="paragraph"><p>Cowboy is now available from four locations:</p></div> +<div class="ulist"><ul> +<li> +<p> +<a href="https://git.ninenines.eu/cowboy.git">https://git.ninenines.eu/cowboy.git</a> +</p> +</li> +<li> +<p> +<a href="https://github.com/ninenines/cowboy.git">https://github.com/ninenines/cowboy.git</a> +</p> +</li> +<li> +<p> +<a href="https://bitbucket.org/ninenines/cowboy.git">https://bitbucket.org/ninenines/cowboy.git</a> +</p> +</li> +<li> +<p> +<a href="https://gitlab.com/ninenines/cowboy.git">https://gitlab.com/ninenines/cowboy.git</a> +</p> +</li> +</ul></div> +<div class="paragraph"><p>They are updated at the same time so there is no real difference.</p></div> +<div class="paragraph"><p>Cowboy 2.0 will be released once all the breaking changes +are completed and the temporarily removed features are +added back.</p></div> +<div class="paragraph"><p>Thanks for your patience. I know it took a long time.</p></div> +<hr/> +<div class="paragraph"><p>Half-price on all donations because I need a new hat:</p></div> +<form action="https://www.paypal.com/cgi-bin/webscr" method="post" style="display:inline"> +<input type="hidden" name="cmd" value="_donations"> +<input type="hidden" name="business" value="[email protected]"> +<input type="hidden" name="lc" value="FR"> +<input type="hidden" name="item_name" value="Loic Hoguin"> +<input type="hidden" name="item_number" value="99s"> +<input type="hidden" name="currency_code" value="EUR"> +<input type="hidden" name="bn" value="PP-DonationsBF:btn_donate_LG.gif:NonHosted"> +<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"> +<img alt="" border="0" src="https://www.paypalobjects.com/fr_FR/i/scr/pixel.gif" width="1" height="1"> +</form> </article> </div> @@ -192,55 +192,107 @@ added back.</p></div> <h3>More articles</h3> <ul id="articles-nav" class="extra_margin"> - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + - <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + + <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + - <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + + <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + - <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + + <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + - <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + + <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + - <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + + <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + - <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + + <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + - <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + + <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + - <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + + <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + - <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + + <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + - <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + + <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + + + </ul> diff --git a/articles/cowboy-2.0.0-rc.1/index.html b/articles/cowboy-2.0.0-rc.1/index.html index 4c06a670..dd1c6584 100644 --- a/articles/cowboy-2.0.0-rc.1/index.html +++ b/articles/cowboy-2.0.0-rc.1/index.html @@ -7,7 +7,7 @@ <meta name="description" content=""> <meta name="author" content="Loïc Hoguin based on a design from (Soft10) Pol Cámara"> - <meta name="generator" content="Hugo 0.17" /> + <meta name="generator" content="Hugo 0.26" /> <title>Nine Nines: Cowboy 2.0 release candidate 1</title> @@ -74,62 +74,62 @@ </p> </header> -<div class="paragraph"><p>Cowboy <code>2.0.0-rc.1</code> has been released!</p></div>
-<div class="paragraph"><p>This is the new recommended version of Cowboy.
-Its API should not change before release. While
-you probably should not use it in production yet,
-many do successfully. Use at your own risk.</p></div>
-<div class="paragraph"><p>The plan is to have a new RC version every couple
-weeks until the summer ends or later if there are
-still blocking issues open. Only issues that can’t
-be fixed without making breaking changes to the
-interface may block the release.</p></div>
-<div class="paragraph"><p>Numerous changes were made since Cowboy 1.0. The
-one most people care about is probably HTTP/2, but
-it’s most likely not the only one worthwhile. The
-full list of changes (excluding types) can be found
-in the user guide chapter
-<a href="https://ninenines.eu/docs/en/cowboy/2.0/guide/migrating_from_1.0/">Migrating from Cowboy 1.0 to 2.0</a>.</p></div>
-<div class="paragraph"><p>As this is not the full release just yet, please pay
-extra attention to details and report anything
-suspicious you find.</p></div>
-<div class="paragraph"><p>There are still some tests failing. Most of those are
-related to standards that are not being followed perfectly
-just yet. Some of those will probably not be fixed before
-Cowboy 2.0 is released. They are edge cases and should not
-prevent interoperability.</p></div>
-<div class="paragraph"><p>The manual received a lot of love. It now has one page per
-function with a detailed description, arguments list, return
-value, changelog and examples. It also links to the other
-relevant manual pages: <a href="https://ninenines.eu/docs/en/cowboy/2.0/manual/">https://ninenines.eu/docs/en/cowboy/2.0/manual/</a></p></div>
-<div class="paragraph"><p>Cowboy is now tested and supported with Erlang/OTP 19.0 or above
-on Arch Linux, FreeBSD, OSX, Ubuntu and Windows 7. Contact me
-if you can provide permanent access to another platform for the
-purposes of testing.</p></div>
-<div class="paragraph"><p>Cowboy is now available from four locations:</p></div>
-<div class="ulist"><ul>
-<li>
-<p>
-<a href="https://git.ninenines.eu/cowboy.git">https://git.ninenines.eu/cowboy.git</a>
-</p>
-</li>
-<li>
-<p>
-<a href="https://github.com/ninenines/cowboy.git">https://github.com/ninenines/cowboy.git</a>
-</p>
-</li>
-<li>
-<p>
-<a href="https://bitbucket.org/ninenines/cowboy.git">https://bitbucket.org/ninenines/cowboy.git</a>
-</p>
-</li>
-<li>
-<p>
-<a href="https://gitlab.com/ninenines/cowboy.git">https://gitlab.com/ninenines/cowboy.git</a>
-</p>
-</li>
-</ul></div>
-<div class="paragraph"><p>They are updated at the same time so there is no real difference.</p></div>
+<div class="paragraph"><p>Cowboy <code>2.0.0-rc.1</code> has been released!</p></div> +<div class="paragraph"><p>This is the new recommended version of Cowboy. +Its API should not change before release. While +you probably should not use it in production yet, +many do successfully. Use at your own risk.</p></div> +<div class="paragraph"><p>The plan is to have a new RC version every couple +weeks until the summer ends or later if there are +still blocking issues open. Only issues that can’t +be fixed without making breaking changes to the +interface may block the release.</p></div> +<div class="paragraph"><p>Numerous changes were made since Cowboy 1.0. The +one most people care about is probably HTTP/2, but +it’s most likely not the only one worthwhile. The +full list of changes (excluding types) can be found +in the user guide chapter +<a href="https://ninenines.eu/docs/en/cowboy/2.0/guide/migrating_from_1.0/">Migrating from Cowboy 1.0 to 2.0</a>.</p></div> +<div class="paragraph"><p>As this is not the full release just yet, please pay +extra attention to details and report anything +suspicious you find.</p></div> +<div class="paragraph"><p>There are still some tests failing. Most of those are +related to standards that are not being followed perfectly +just yet. Some of those will probably not be fixed before +Cowboy 2.0 is released. They are edge cases and should not +prevent interoperability.</p></div> +<div class="paragraph"><p>The manual received a lot of love. It now has one page per +function with a detailed description, arguments list, return +value, changelog and examples. It also links to the other +relevant manual pages: <a href="https://ninenines.eu/docs/en/cowboy/2.0/manual/">https://ninenines.eu/docs/en/cowboy/2.0/manual/</a></p></div> +<div class="paragraph"><p>Cowboy is now tested and supported with Erlang/OTP 19.0 or above +on Arch Linux, FreeBSD, OSX, Ubuntu and Windows 7. Contact me +if you can provide permanent access to another platform for the +purposes of testing.</p></div> +<div class="paragraph"><p>Cowboy is now available from four locations:</p></div> +<div class="ulist"><ul> +<li> +<p> +<a href="https://git.ninenines.eu/cowboy.git">https://git.ninenines.eu/cowboy.git</a> +</p> +</li> +<li> +<p> +<a href="https://github.com/ninenines/cowboy.git">https://github.com/ninenines/cowboy.git</a> +</p> +</li> +<li> +<p> +<a href="https://bitbucket.org/ninenines/cowboy.git">https://bitbucket.org/ninenines/cowboy.git</a> +</p> +</li> +<li> +<p> +<a href="https://gitlab.com/ninenines/cowboy.git">https://gitlab.com/ninenines/cowboy.git</a> +</p> +</li> +</ul></div> +<div class="paragraph"><p>They are updated at the same time so there is no real difference.</p></div> </article> </div> @@ -138,55 +138,107 @@ purposes of testing.</p></div> <h3>More articles</h3> <ul id="articles-nav" class="extra_margin"> - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + - <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + + <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + - <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + + <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + - <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + + <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + - <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + + <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + - <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + + <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + - <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + + <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + - <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + + <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + - <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + + <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + - <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + + <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + - <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + + <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + + + </ul> diff --git a/articles/cowboy-2.0.0-rc.2/index.html b/articles/cowboy-2.0.0-rc.2/index.html index 51401e0f..b268f671 100644 --- a/articles/cowboy-2.0.0-rc.2/index.html +++ b/articles/cowboy-2.0.0-rc.2/index.html @@ -7,7 +7,7 @@ <meta name="description" content=""> <meta name="author" content="Loïc Hoguin based on a design from (Soft10) Pol Cámara"> - <meta name="generator" content="Hugo 0.17" /> + <meta name="generator" content="Hugo 0.26" /> <title>Nine Nines: Cowboy 2.0 release candidate 2</title> @@ -74,41 +74,41 @@ </p> </header> -<div class="paragraph"><p>Cowboy <code>2.0.0-rc.2</code> has been released!</p></div>
-<div class="paragraph"><p>This is the new recommended version of Cowboy.
-Its API should not change before release. While
-you probably should not use it in production yet,
-many do successfully. Use at your own risk.</p></div>
-<div class="paragraph"><p>This new version contains fixes for the following
-issues:</p></div>
-<div class="ulist"><ul>
-<li>
-<p>
-HTTP/2 server push was using the wrong header
- compression context.
-</p>
-</li>
-<li>
-<p>
-HTTP/2 flow control could end up queueing data
- in the wrong order when resuming the sending of
- data.
-</p>
-</li>
-<li>
-<p>
-The <code>shutdown</code> timeout was not implemented
- and request processes could be killed too quickly.
-</p>
-</li>
-</ul></div>
-<div class="paragraph"><p>What else is new in Cowboy 2.0? Check the
-<a href="/articles/cowboy-2.0.0-rc.1">rc.1 announcement</a>.</p></div>
-<div class="paragraph"><p>Please test this new release candidate and provide
-feedback! The best place to provide feedback is via
-tickets. Do not hesitate to open a ticket or bring
-an existing ticket to my attention to get it resolved
-before 2.0.</p></div>
+<div class="paragraph"><p>Cowboy <code>2.0.0-rc.2</code> has been released!</p></div> +<div class="paragraph"><p>This is the new recommended version of Cowboy. +Its API should not change before release. While +you probably should not use it in production yet, +many do successfully. Use at your own risk.</p></div> +<div class="paragraph"><p>This new version contains fixes for the following +issues:</p></div> +<div class="ulist"><ul> +<li> +<p> +HTTP/2 server push was using the wrong header + compression context. +</p> +</li> +<li> +<p> +HTTP/2 flow control could end up queueing data + in the wrong order when resuming the sending of + data. +</p> +</li> +<li> +<p> +The <code>shutdown</code> timeout was not implemented + and request processes could be killed too quickly. +</p> +</li> +</ul></div> +<div class="paragraph"><p>What else is new in Cowboy 2.0? Check the +<a href="/articles/cowboy-2.0.0-rc.1">rc.1 announcement</a>.</p></div> +<div class="paragraph"><p>Please test this new release candidate and provide +feedback! The best place to provide feedback is via +tickets. Do not hesitate to open a ticket or bring +an existing ticket to my attention to get it resolved +before 2.0.</p></div> </article> </div> @@ -117,55 +117,107 @@ before 2.0.</p></div> <h3>More articles</h3> <ul id="articles-nav" class="extra_margin"> - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + - <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + + <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + - <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + + <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + - <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + + <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + - <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + + <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + - <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + + <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + - <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + + <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + - <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + + <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + - <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + + <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + - <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + + <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + - <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + + <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + + + </ul> diff --git a/articles/cowboy2-qs/index.html b/articles/cowboy2-qs/index.html index 5d26a2ee..f8064d1e 100644 --- a/articles/cowboy2-qs/index.html +++ b/articles/cowboy2-qs/index.html @@ -7,7 +7,7 @@ <meta name="description" content=""> <meta name="author" content="Loïc Hoguin based on a design from (Soft10) Pol Cámara"> - <meta name="generator" content="Hugo 0.17" /> + <meta name="generator" content="Hugo 0.26" /> <title>Nine Nines: Cowboy 2.0 and query strings</title> @@ -74,155 +74,155 @@ </p> </header> -<div class="paragraph"><p>Now that Cowboy 1.0 is out, I can spend some of my time thinking
-about Cowboy 2.0 that will be released soon after Erlang/OTP 18.0.
-This entry discusses the proposed changes to query string handling
-in Cowboy.</p></div>
-<div class="paragraph"><p>Cowboy 2.0 will respond to user wishes by simplifying the interface
-of the <code>cowboy_req</code> module. Users want two things: less
-juggling with the Req variable, and more maps. Maps is the only
-dynamic key/value data structure in Erlang that we can match directly
-to extract values, allowing users to greatly simplify their code as
-they don’t need to call functions to do everything anymore.</p></div>
-<div class="paragraph"><p>Query strings are a good candidate for maps. It’s a list of
-key/values, so it’s pretty obvious we can win a lot by using maps.
-However query strings have one difference with maps: they can have
-duplicate keys.</p></div>
-<div class="paragraph"><p>How are we expected to handle duplicate keys? There’s no standard
-behavior. It’s up to applications. And looking at what is done in
-the wild, there’s no de facto standard either. While some ignore
-duplicate keys (keeping the first or the last they find), others
-require duplicate keys to end with <code>[]</code> to automatically
-put the values in a list, or even worse, languages like PHP even
-allow you to do things like <code>key[something][other]</code> and
-create a deep structure for it. Finally some allow any key to have
-duplicates and just gives you lists of key/values.</p></div>
-<div class="paragraph"><p>Cowboy so far had functions to retrieve query string values one
-value at a time, and if there were duplicates it would return the
-first it finds. It also has a function returning the entire list
-with all duplicates, allowing you to filter it to get all of them,
-and another function that returns the raw query string.</p></div>
-<div class="paragraph"><p>What are duplicates used for? Not that many things actually.</p></div>
-<div class="paragraph"><p>One use of duplicate keys is with HTML forms. It is common practice
-to give all related checkboxes the same name so you get a list of
-what’s been checked. When nothing is checked, nothing is sent at all,
-the key is not in the list.</p></div>
-<div class="paragraph"><p>Another use of duplicate keys is when generating forms. A good
-example of that would be a form that allows uploading any number
-of files. When you add a file, client-side code adds another field
-to the form. Repeat up to a certain limit.</p></div>
-<div class="paragraph"><p>And that’s about it. Of note is that HTML radio elements share
-the same name too, but only one key/value is sent, so they are not
-relevant here.</p></div>
-<div class="paragraph"><p>Normally this would be the part where I tell you how we solve
-this elegantly. But I had doubts. Why? Because there’s no good
-solutions to solving only this particular problem.</p></div>
-<div class="paragraph"><p>I then stopped thinking about duplicate keys for a minute and
-started to think about the larger problem.</p></div>
-<div class="paragraph"><p>Query strings are input data. They take a particular form,
-and may be sent as part of the URI or as part of the request
-body. We have other kinds of input data. We have headers and
-cookies and the request body in various forms. We also have
-path segments in URIs.</p></div>
-<div class="paragraph"><p>What do you do with input data? Well you use it to do
-something. But there is one thing that you almost always do
-(and if you don’t, you really should): you validate it and
-you map it into Erlang terms.</p></div>
-<div class="paragraph"><p>Cowboy left the user take care of validation and conversion
-into Erlang terms so far. Rather, it left the user take care
-of it everywhere except one place. Guess where? That’s right,
-bindings.</p></div>
-<div class="paragraph"><p>If you define routes with bindings then you have the option
-to provide constraints. Constraints can be used to do two things:
-validate the data and convert it in a more appropriate term. For
-example if you use the <code>int</code> constraint, Cowboy will
-make sure the binding is an integer, and will replace the value
-with the integer representation so that you can use it directly.
-In this particular case it not only routes the URI, but also
-validates and converts the bindings directly.</p></div>
-<div class="paragraph"><p>This is very relevant in the case of our duplicate keys,
-because if we have a list with duplicates of a key, chances
-are we want to convert that into a list of Erlang terms, and
-also make sure that all the elements in this list are expected.</p></div>
-<div class="paragraph"><p>The answer to this particular problem is simple. We need a
-function that will parse the query string and apply constraints.
-But this is not all, there is one other problem to be solved.</p></div>
-<div class="paragraph"><p>The other problem is that for the user some keys are mandatory
-and some are optional. Optional keys include the ones that
-correspond to HTML checkboxes: if the key for one or more
-checkbox is missing from the query string, we still want to
-have an empty list in our map so we can easily match. Matching
-maps is great, but not so much when values might be missing,
-so we have to normalize this data a little.</p></div>
-<div class="paragraph"><p>This problem is solved by allowing a default value. If the
-key is missing and a default exists, set it. If no default
-exists, then the key was mandatory and we want to crash.</p></div>
-<div class="paragraph"><p>I therefore make a proposal for changing the query string
-interface to three functions.</p></div>
-<div class="paragraph"><p>The first function already exists, it is <code>cowboy_req:qs(Req)</code>
-and it returns only the query string binary. No more Req returned.</p></div>
-<div class="paragraph"><p>The second function is a renaming of <code>cowboy_req:qs_vals(Req)</code>
-to something more explicit: <code>cowboy_req:parse_qs(Req)</code>.
-The new name implies that a parsing operation is done. It was implicit
-and cached before. It will be explicit and not cached anymore now.
-Again, no more Req returned.</p></div>
-<div class="paragraph"><p>The third function is the one I mentioned above. I think
-the interface <code>cowboy_req:match_qs(Req, Fields)</code> is
-most appropriate. It returns a normalized map that is the same
-regardless of optional fields being provided with the request,
-allowing for easy matching. It crashes if something went wrong.
-Still no Req returned.</p></div>
-<div class="paragraph"><p>I feel that this three function interface provides everything
-one would need to comfortably write applications. You can get
-low level and get the query string directly; you can get a list
-of key/value binaries without any additional processing and do it
-on your own; or you can get a processed map that contains Erlang
-terms ready to be used.</p></div>
-<div class="paragraph"><p>I strongly believe that by democratizing the constraints to
-more than just bindings, but also to query string, cookies and
-other key/values in Cowboy, we can allow the developer to quickly
-and easily go from HTTP request to Erlang function calls. The
-constraints are reusable functions that can serve as guards
-against unwanted data, providing convenience in the process.</p></div>
-<div class="paragraph"><p>Your handlers will not look like an endless series of calls
-to get and convert the input data, they will instead be just
-one call at the beginning followed by the actual application
-logic, thanks to constraints and maps.</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="font-weight: bold"><span style="color: #000000">handle</span></span>(<span style="color: #009900">Req</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-></span>
- #{<span style="color: #FF6600">name</span><span style="color: #990000">:=</span><span style="color: #009900">Name</span>, <span style="color: #FF6600">email</span><span style="color: #990000">:=</span><span style="color: #009900">Email</span>, <span style="color: #FF6600">choices</span><span style="color: #990000">:=</span><span style="color: #009900">ChoicesList</span>, <span style="color: #FF6600">remember_me</span><span style="color: #990000">:=</span><span style="color: #009900">RememberMe</span>} <span style="color: #990000">=</span>
- <span style="font-weight: bold"><span style="color: #000000">cowboy_req:match_qs</span></span>(<span style="color: #009900">Req</span>, [
- <span style="font-weight: bold"><span style="color: #000080">name</span></span>, {<span style="color: #FF6600">email</span>, <span style="color: #FF6600">email</span>},
- {<span style="color: #FF6600">choices</span>, <span style="font-weight: bold"><span style="color: #0000FF">fun</span></span> <span style="font-weight: bold"><span style="color: #000000">check_choices</span></span><span style="color: #990000">/</span><span style="color: #993399">1</span>, []},
- {<span style="color: #FF6600">remember_me</span>, <span style="color: #FF6600">boolean</span>, <span style="color: #000080">false</span>}]),
- <span style="font-weight: bold"><span style="color: #000000">save_choices</span></span>(<span style="color: #009900">Name</span>, <span style="color: #009900">Email</span>, <span style="color: #009900">ChoicesList</span>),
- <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #009900">RememberMe</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">create_account</span></span>(<span style="color: #009900">Name</span>, <span style="color: #009900">Email</span>); <span style="color: #000080">true</span> <span style="color: #990000">-></span> <span style="color: #FF6600">ok</span> <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>,
- {<span style="color: #FF6600">ok</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>}<span style="color: #990000">.</span>
-
-<span style="font-weight: bold"><span style="color: #000000">check_choices</span></span>(<span style="color: #990000"><<</span><span style="color: #FF0000">"blue"</span><span style="color: #990000">>></span>) <span style="color: #990000">-></span> {<span style="color: #000080">true</span>, <span style="color: #FF6600">blue</span>};
-<span style="font-weight: bold"><span style="color: #000000">check_choices</span></span>(<span style="color: #990000"><<</span><span style="color: #FF0000">"red"</span><span style="color: #990000">>></span>) <span style="color: #990000">-></span> {<span style="color: #000080">true</span>, <span style="color: #FF6600">red</span>};
-<span style="font-weight: bold"><span style="color: #000000">check_choices</span></span>(<span style="color: #990000">_</span>) <span style="color: #990000">-></span> <span style="color: #000080">false</span>;</tt></pre></div></div>
-<div class="paragraph"><p>(Don’t look too closely at the structure yet.)</p></div>
-<div class="paragraph"><p>As you can see in the above snippet, it becomes really easy
-to go from query string to values. You can also use the map
-directly as it is guaranteed to only contain the keys you
-specified, any extra key is not returned.</p></div>
-<div class="paragraph"><p>This would I believe be a huge step up as we can now
-focus on writing applications instead of translating HTTP
-calls. Cowboy can now take care of it.</p></div>
-<div class="paragraph"><p>And to conclude, this also solves our duplicate keys
-dilemma, as they now automatically become a list of binaries,
-and this list is then checked against constraints that
-will fail if they were not expecting a list. And in the
-example above, it even converts the values to atoms for
-easier manipulation.</p></div>
-<div class="paragraph"><p>As usual, feedback is more than welcome, and I apologize
-for the rocky structure of this post as it contains all the
-thoughts that went into this rather than just the conclusion.</p></div>
+<div class="paragraph"><p>Now that Cowboy 1.0 is out, I can spend some of my time thinking +about Cowboy 2.0 that will be released soon after Erlang/OTP 18.0. +This entry discusses the proposed changes to query string handling +in Cowboy.</p></div> +<div class="paragraph"><p>Cowboy 2.0 will respond to user wishes by simplifying the interface +of the <code>cowboy_req</code> module. Users want two things: less +juggling with the Req variable, and more maps. Maps is the only +dynamic key/value data structure in Erlang that we can match directly +to extract values, allowing users to greatly simplify their code as +they don’t need to call functions to do everything anymore.</p></div> +<div class="paragraph"><p>Query strings are a good candidate for maps. It’s a list of +key/values, so it’s pretty obvious we can win a lot by using maps. +However query strings have one difference with maps: they can have +duplicate keys.</p></div> +<div class="paragraph"><p>How are we expected to handle duplicate keys? There’s no standard +behavior. It’s up to applications. And looking at what is done in +the wild, there’s no de facto standard either. While some ignore +duplicate keys (keeping the first or the last they find), others +require duplicate keys to end with <code>[]</code> to automatically +put the values in a list, or even worse, languages like PHP even +allow you to do things like <code>key[something][other]</code> and +create a deep structure for it. Finally some allow any key to have +duplicates and just gives you lists of key/values.</p></div> +<div class="paragraph"><p>Cowboy so far had functions to retrieve query string values one +value at a time, and if there were duplicates it would return the +first it finds. It also has a function returning the entire list +with all duplicates, allowing you to filter it to get all of them, +and another function that returns the raw query string.</p></div> +<div class="paragraph"><p>What are duplicates used for? Not that many things actually.</p></div> +<div class="paragraph"><p>One use of duplicate keys is with HTML forms. It is common practice +to give all related checkboxes the same name so you get a list of +what’s been checked. When nothing is checked, nothing is sent at all, +the key is not in the list.</p></div> +<div class="paragraph"><p>Another use of duplicate keys is when generating forms. A good +example of that would be a form that allows uploading any number +of files. When you add a file, client-side code adds another field +to the form. Repeat up to a certain limit.</p></div> +<div class="paragraph"><p>And that’s about it. Of note is that HTML radio elements share +the same name too, but only one key/value is sent, so they are not +relevant here.</p></div> +<div class="paragraph"><p>Normally this would be the part where I tell you how we solve +this elegantly. But I had doubts. Why? Because there’s no good +solutions to solving only this particular problem.</p></div> +<div class="paragraph"><p>I then stopped thinking about duplicate keys for a minute and +started to think about the larger problem.</p></div> +<div class="paragraph"><p>Query strings are input data. They take a particular form, +and may be sent as part of the URI or as part of the request +body. We have other kinds of input data. We have headers and +cookies and the request body in various forms. We also have +path segments in URIs.</p></div> +<div class="paragraph"><p>What do you do with input data? Well you use it to do +something. But there is one thing that you almost always do +(and if you don’t, you really should): you validate it and +you map it into Erlang terms.</p></div> +<div class="paragraph"><p>Cowboy left the user take care of validation and conversion +into Erlang terms so far. Rather, it left the user take care +of it everywhere except one place. Guess where? That’s right, +bindings.</p></div> +<div class="paragraph"><p>If you define routes with bindings then you have the option +to provide constraints. Constraints can be used to do two things: +validate the data and convert it in a more appropriate term. For +example if you use the <code>int</code> constraint, Cowboy will +make sure the binding is an integer, and will replace the value +with the integer representation so that you can use it directly. +In this particular case it not only routes the URI, but also +validates and converts the bindings directly.</p></div> +<div class="paragraph"><p>This is very relevant in the case of our duplicate keys, +because if we have a list with duplicates of a key, chances +are we want to convert that into a list of Erlang terms, and +also make sure that all the elements in this list are expected.</p></div> +<div class="paragraph"><p>The answer to this particular problem is simple. We need a +function that will parse the query string and apply constraints. +But this is not all, there is one other problem to be solved.</p></div> +<div class="paragraph"><p>The other problem is that for the user some keys are mandatory +and some are optional. Optional keys include the ones that +correspond to HTML checkboxes: if the key for one or more +checkbox is missing from the query string, we still want to +have an empty list in our map so we can easily match. Matching +maps is great, but not so much when values might be missing, +so we have to normalize this data a little.</p></div> +<div class="paragraph"><p>This problem is solved by allowing a default value. If the +key is missing and a default exists, set it. If no default +exists, then the key was mandatory and we want to crash.</p></div> +<div class="paragraph"><p>I therefore make a proposal for changing the query string +interface to three functions.</p></div> +<div class="paragraph"><p>The first function already exists, it is <code>cowboy_req:qs(Req)</code> +and it returns only the query string binary. No more Req returned.</p></div> +<div class="paragraph"><p>The second function is a renaming of <code>cowboy_req:qs_vals(Req)</code> +to something more explicit: <code>cowboy_req:parse_qs(Req)</code>. +The new name implies that a parsing operation is done. It was implicit +and cached before. It will be explicit and not cached anymore now. +Again, no more Req returned.</p></div> +<div class="paragraph"><p>The third function is the one I mentioned above. I think +the interface <code>cowboy_req:match_qs(Req, Fields)</code> is +most appropriate. It returns a normalized map that is the same +regardless of optional fields being provided with the request, +allowing for easy matching. It crashes if something went wrong. +Still no Req returned.</p></div> +<div class="paragraph"><p>I feel that this three function interface provides everything +one would need to comfortably write applications. You can get +low level and get the query string directly; you can get a list +of key/value binaries without any additional processing and do it +on your own; or you can get a processed map that contains Erlang +terms ready to be used.</p></div> +<div class="paragraph"><p>I strongly believe that by democratizing the constraints to +more than just bindings, but also to query string, cookies and +other key/values in Cowboy, we can allow the developer to quickly +and easily go from HTTP request to Erlang function calls. The +constraints are reusable functions that can serve as guards +against unwanted data, providing convenience in the process.</p></div> +<div class="paragraph"><p>Your handlers will not look like an endless series of calls +to get and convert the input data, they will instead be just +one call at the beginning followed by the actual application +logic, thanks to constraints and maps.</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="font-weight: bold"><span style="color: #000000">handle</span></span>(<span style="color: #009900">Req</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-></span> + #{<span style="color: #FF6600">name</span><span style="color: #990000">:=</span><span style="color: #009900">Name</span>, <span style="color: #FF6600">email</span><span style="color: #990000">:=</span><span style="color: #009900">Email</span>, <span style="color: #FF6600">choices</span><span style="color: #990000">:=</span><span style="color: #009900">ChoicesList</span>, <span style="color: #FF6600">remember_me</span><span style="color: #990000">:=</span><span style="color: #009900">RememberMe</span>} <span style="color: #990000">=</span> + <span style="font-weight: bold"><span style="color: #000000">cowboy_req:match_qs</span></span>(<span style="color: #009900">Req</span>, [ + <span style="font-weight: bold"><span style="color: #000080">name</span></span>, {<span style="color: #FF6600">email</span>, <span style="color: #FF6600">email</span>}, + {<span style="color: #FF6600">choices</span>, <span style="font-weight: bold"><span style="color: #0000FF">fun</span></span> <span style="font-weight: bold"><span style="color: #000000">check_choices</span></span><span style="color: #990000">/</span><span style="color: #993399">1</span>, []}, + {<span style="color: #FF6600">remember_me</span>, <span style="color: #FF6600">boolean</span>, <span style="color: #000080">false</span>}]), + <span style="font-weight: bold"><span style="color: #000000">save_choices</span></span>(<span style="color: #009900">Name</span>, <span style="color: #009900">Email</span>, <span style="color: #009900">ChoicesList</span>), + <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #009900">RememberMe</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">create_account</span></span>(<span style="color: #009900">Name</span>, <span style="color: #009900">Email</span>); <span style="color: #000080">true</span> <span style="color: #990000">-></span> <span style="color: #FF6600">ok</span> <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>, + {<span style="color: #FF6600">ok</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>}<span style="color: #990000">.</span> + +<span style="font-weight: bold"><span style="color: #000000">check_choices</span></span>(<span style="color: #990000"><<</span><span style="color: #FF0000">"blue"</span><span style="color: #990000">>></span>) <span style="color: #990000">-></span> {<span style="color: #000080">true</span>, <span style="color: #FF6600">blue</span>}; +<span style="font-weight: bold"><span style="color: #000000">check_choices</span></span>(<span style="color: #990000"><<</span><span style="color: #FF0000">"red"</span><span style="color: #990000">>></span>) <span style="color: #990000">-></span> {<span style="color: #000080">true</span>, <span style="color: #FF6600">red</span>}; +<span style="font-weight: bold"><span style="color: #000000">check_choices</span></span>(<span style="color: #990000">_</span>) <span style="color: #990000">-></span> <span style="color: #000080">false</span>;</tt></pre></div></div> +<div class="paragraph"><p>(Don’t look too closely at the structure yet.)</p></div> +<div class="paragraph"><p>As you can see in the above snippet, it becomes really easy +to go from query string to values. You can also use the map +directly as it is guaranteed to only contain the keys you +specified, any extra key is not returned.</p></div> +<div class="paragraph"><p>This would I believe be a huge step up as we can now +focus on writing applications instead of translating HTTP +calls. Cowboy can now take care of it.</p></div> +<div class="paragraph"><p>And to conclude, this also solves our duplicate keys +dilemma, as they now automatically become a list of binaries, +and this list is then checked against constraints that +will fail if they were not expecting a list. And in the +example above, it even converts the values to atoms for +easier manipulation.</p></div> +<div class="paragraph"><p>As usual, feedback is more than welcome, and I apologize +for the rocky structure of this post as it contains all the +thoughts that went into this rather than just the conclusion.</p></div> </article> </div> @@ -231,55 +231,107 @@ thoughts that went into this rather than just the conclusion.</p></div> <h3>More articles</h3> <ul id="articles-nav" class="extra_margin"> - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + + + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + + <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + - <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + + <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + - <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + + <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + - <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + + <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + - <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + + <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + - <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + + <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + - <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + + <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + - <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + + <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + - <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + + <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + - <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + + <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + - <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + </ul> diff --git a/articles/dont-let-it-crash/index.html b/articles/dont-let-it-crash/index.html index 239e479a..e86cb263 100644 --- a/articles/dont-let-it-crash/index.html +++ b/articles/dont-let-it-crash/index.html @@ -7,7 +7,7 @@ <meta name="description" content=""> <meta name="author" content="Loïc Hoguin based on a design from (Soft10) Pol Cámara"> - <meta name="generator" content="Hugo 0.17" /> + <meta name="generator" content="Hugo 0.26" /> <title>Nine Nines: Don't let it crash</title> @@ -74,118 +74,118 @@ </p> </header> -<div class="paragraph"><p>We have a specific mindset when writing Erlang
-programs. We focus on the normal execution of the
-program and don’t handle most of the errors that may
-occur. We sometimes call this normal execution the
-<em>happy path</em>.</p></div>
-<div class="paragraph"><p>The general pattern behind writing only for the
-<em>happy path</em>, letting the VM catch errors (writing
-them to a log for future consumption) and then
-having a supervisor restart the processes that
-failed from a clean state, has a name. We call it
-<em>let it crash</em>; and it drives many of our design
-decisions.</p></div>
-<div class="paragraph"><p>It’s a really great way to program and the results
-are fantastic compared to most other programming
-languages. And yet, <em>let it crash</em> barely convinced
-anyone that they should use Erlang. Why would that
-be?</p></div>
-<div class="paragraph"><p>You may already know that Cowboy is capable of
-handling at least 2 million Websocket connections
-on a single server. This is in large part thanks
-to the capabilities of the VM. Still, 2 million
-is good, much better than most other servers can
-do.</p></div>
-<div class="paragraph"><p>Cowboy is not just a Websocket server; it’s also
-an HTTP and HTTP/2 server, and it handles many
-related features like long polling or the parsing
-of most request headers.</p></div>
-<div class="paragraph"><p>Can you guess how large the Cowboy codebase is,
-without looking at the source?</p></div>
-<div class="paragraph"><p>Do make sure you have a clear answer in your mind
-before you go check.</p></div>
-<div class="paragraph"><p>Good, you are back. Now what were the results? If
-I am correct, you overestimated the size of Cowboy.
-Cowboy is in fact about five thousand lines of code.
-You probably thought it was at least ten thousand.
-About eighty percent of readers will have
-overestimated the size of Cowboy. And you did only
-because I mentioned it can handle millions of
-Websocket connections.</p></div>
-<div class="paragraph"><p>Numerous studies show this effect. Just mentioning
-the large number already prepared your mind to think
-in that direction. Repeating the number made you
-focus even more on it. Then the question asked for
-a number, which ended up larger than the reality.</p></div>
-<div class="paragraph"><p>The same effect can be applied to negotiation for
-example. You generally want to start by giving your
-offer (and not let the other party initiate) and
-you want to give a really large number first. You
-can also prepare your customer by mentioning an even
-larger number in the previous discussion.</p></div>
-<div class="paragraph"><p>And it’s not just numbers either. An experiment
-showed that just by looking at an image of clouds,
-customers of a pillow store were buying pillows
-more comfortable (and more expensive) than those
-who didn’t see that image.</p></div>
-<div class="paragraph"><p>This is the power of associations. It is covered in
-much larger detail in the books
-<a href="https://www.amazon.com/Influence-Psychology-Persuasion-Robert-Cialdini/dp/006124189X">Influence</a>
-and
-<a href="https://www.amazon.com/Pre-Suasion-Revolutionary-Way-Influence-Persuade/dp/1501109790">Pre-suasion</a>.
-I highly recommend reading those and applying what
-you learn to your daily life. I’m definitely not
-a professional psychologist so take this post with
-a grain of salt.</p></div>
-<div class="paragraph"><p>When selling Erlang, whether we are selling it to
-a customer or trying to convince a developer friend
-to start using it, we often talk about how Erlang
-<em>lets you sleep at night</em>, that it is auto healing
-and always gets fantastic uptimes.</p></div>
-<div class="paragraph"><p>And then we talk about <em>let it crash</em>.</p></div>
-<div class="paragraph"><p>And we describe what it means.</p></div>
-<div class="paragraph"><p>We might as well just say that Erlang crashes a lot
-and then take the door. It would have the same effect.
-It doesn’t even stop at programs crashing. You know
-what else crashes? Cars, planes, trains. Often with
-disastrous consequences. Is that really the message
-we want to convey?</p></div>
-<div class="paragraph"><p>They even <a href="https://img.youtube.com/vi/oEUBW2lCkIk/0.jpg">printed it on a t-shirt</a>!
-Keep calm and let it crash. It’s the kind of t-shirt
-you probably shouldn’t wear in an airport, and for good
-reasons. A few people did, then realized what they were
-wearing and were not too smug about it.</p></div>
-<div class="paragraph"><p>And yet this is how we sell Erlang.</p></div>
-<div class="paragraph"><p>A better way would be to focus on the positives, of
-course, but also to make sure that those positives
-are phrased in a way that prevents bad associations
-to be formed in people’s minds.</p></div>
-<div class="paragraph"><p>Instead of <em>let it crash</em>, you can say that Erlang
-has <em>auto healing mechanisms</em>. Healing is a good
-thing and accurately describes what happens in the
-system.</p></div>
-<div class="paragraph"><p>Should you need to go into more details, you will
-probably want to avoid <em>recover from crashes</em> and
-instead say <em>recover from exceptions</em>. Exceptions
-are a pretty neutral word and, should you explain
-what you mean by that, you can talk about exceptions
-that occur for reasons unrelated to Erlang, like
-hardware failure or network instability.</p></div>
-<div class="paragraph"><p>The trick is to always use positive words and
-phrases to describe Erlang, and to use external
-factors to explain how Erlang deals with failures.
-Never mention the failures internal to Erlang
-systems unless you are asked specifically, in
-which case you can say that the auto healing
-applies to all exceptions.</p></div>
-<div class="paragraph"><p>The <em>let it crash</em> philosophy is great when
-learning Erlang or when writing fault-tolerant
-systems. But it’s not going to convince anyone
-to use it unless they were already looking for
-it.</p></div>
-<div class="paragraph"><p>Do you like this post? Tell me on Twitter. I might
-make more.</p></div>
+<div class="paragraph"><p>We have a specific mindset when writing Erlang +programs. We focus on the normal execution of the +program and don’t handle most of the errors that may +occur. We sometimes call this normal execution the +<em>happy path</em>.</p></div> +<div class="paragraph"><p>The general pattern behind writing only for the +<em>happy path</em>, letting the VM catch errors (writing +them to a log for future consumption) and then +having a supervisor restart the processes that +failed from a clean state, has a name. We call it +<em>let it crash</em>; and it drives many of our design +decisions.</p></div> +<div class="paragraph"><p>It’s a really great way to program and the results +are fantastic compared to most other programming +languages. And yet, <em>let it crash</em> barely convinced +anyone that they should use Erlang. Why would that +be?</p></div> +<div class="paragraph"><p>You may already know that Cowboy is capable of +handling at least 2 million Websocket connections +on a single server. This is in large part thanks +to the capabilities of the VM. Still, 2 million +is good, much better than most other servers can +do.</p></div> +<div class="paragraph"><p>Cowboy is not just a Websocket server; it’s also +an HTTP and HTTP/2 server, and it handles many +related features like long polling or the parsing +of most request headers.</p></div> +<div class="paragraph"><p>Can you guess how large the Cowboy codebase is, +without looking at the source?</p></div> +<div class="paragraph"><p>Do make sure you have a clear answer in your mind +before you go check.</p></div> +<div class="paragraph"><p>Good, you are back. Now what were the results? If +I am correct, you overestimated the size of Cowboy. +Cowboy is in fact about five thousand lines of code. +You probably thought it was at least ten thousand. +About eighty percent of readers will have +overestimated the size of Cowboy. And you did only +because I mentioned it can handle millions of +Websocket connections.</p></div> +<div class="paragraph"><p>Numerous studies show this effect. Just mentioning +the large number already prepared your mind to think +in that direction. Repeating the number made you +focus even more on it. Then the question asked for +a number, which ended up larger than the reality.</p></div> +<div class="paragraph"><p>The same effect can be applied to negotiation for +example. You generally want to start by giving your +offer (and not let the other party initiate) and +you want to give a really large number first. You +can also prepare your customer by mentioning an even +larger number in the previous discussion.</p></div> +<div class="paragraph"><p>And it’s not just numbers either. An experiment +showed that just by looking at an image of clouds, +customers of a pillow store were buying pillows +more comfortable (and more expensive) than those +who didn’t see that image.</p></div> +<div class="paragraph"><p>This is the power of associations. It is covered in +much larger detail in the books +<a href="https://www.amazon.com/Influence-Psychology-Persuasion-Robert-Cialdini/dp/006124189X">Influence</a> +and +<a href="https://www.amazon.com/Pre-Suasion-Revolutionary-Way-Influence-Persuade/dp/1501109790">Pre-suasion</a>. +I highly recommend reading those and applying what +you learn to your daily life. I’m definitely not +a professional psychologist so take this post with +a grain of salt.</p></div> +<div class="paragraph"><p>When selling Erlang, whether we are selling it to +a customer or trying to convince a developer friend +to start using it, we often talk about how Erlang +<em>lets you sleep at night</em>, that it is auto healing +and always gets fantastic uptimes.</p></div> +<div class="paragraph"><p>And then we talk about <em>let it crash</em>.</p></div> +<div class="paragraph"><p>And we describe what it means.</p></div> +<div class="paragraph"><p>We might as well just say that Erlang crashes a lot +and then take the door. It would have the same effect. +It doesn’t even stop at programs crashing. You know +what else crashes? Cars, planes, trains. Often with +disastrous consequences. Is that really the message +we want to convey?</p></div> +<div class="paragraph"><p>They even <a href="https://img.youtube.com/vi/oEUBW2lCkIk/0.jpg">printed it on a t-shirt</a>! +Keep calm and let it crash. It’s the kind of t-shirt +you probably shouldn’t wear in an airport, and for good +reasons. A few people did, then realized what they were +wearing and were not too smug about it.</p></div> +<div class="paragraph"><p>And yet this is how we sell Erlang.</p></div> +<div class="paragraph"><p>A better way would be to focus on the positives, of +course, but also to make sure that those positives +are phrased in a way that prevents bad associations +to be formed in people’s minds.</p></div> +<div class="paragraph"><p>Instead of <em>let it crash</em>, you can say that Erlang +has <em>auto healing mechanisms</em>. Healing is a good +thing and accurately describes what happens in the +system.</p></div> +<div class="paragraph"><p>Should you need to go into more details, you will +probably want to avoid <em>recover from crashes</em> and +instead say <em>recover from exceptions</em>. Exceptions +are a pretty neutral word and, should you explain +what you mean by that, you can talk about exceptions +that occur for reasons unrelated to Erlang, like +hardware failure or network instability.</p></div> +<div class="paragraph"><p>The trick is to always use positive words and +phrases to describe Erlang, and to use external +factors to explain how Erlang deals with failures. +Never mention the failures internal to Erlang +systems unless you are asked specifically, in +which case you can say that the auto healing +applies to all exceptions.</p></div> +<div class="paragraph"><p>The <em>let it crash</em> philosophy is great when +learning Erlang or when writing fault-tolerant +systems. But it’s not going to convince anyone +to use it unless they were already looking for +it.</p></div> +<div class="paragraph"><p>Do you like this post? Tell me on Twitter. I might +make more.</p></div> </article> </div> @@ -194,55 +194,107 @@ make more.</p></div> <h3>More articles</h3> <ul id="articles-nav" class="extra_margin"> - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + - <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + + <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + - <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + + <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + - <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + + <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + - <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + + <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + - <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + + <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + - <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + + <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + - <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + + <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + - <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + + <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + - <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + + <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + - <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + + <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + + + </ul> diff --git a/articles/erlang-scalability/index.html b/articles/erlang-scalability/index.html index 213881da..a9e0be42 100644 --- a/articles/erlang-scalability/index.html +++ b/articles/erlang-scalability/index.html @@ -7,7 +7,7 @@ <meta name="description" content=""> <meta name="author" content="Loïc Hoguin based on a design from (Soft10) Pol Cámara"> - <meta name="generator" content="Hugo 0.17" /> + <meta name="generator" content="Hugo 0.26" /> <title>Nine Nines: Erlang Scalability</title> @@ -74,140 +74,140 @@ </p> </header> -<div class="paragraph"><p>I would like to share some experience and theories on
-Erlang scalability.</p></div>
-<div class="paragraph"><p>This will be in the form of a series of hints, which
-may or may not be accompanied with explanations as to why
-things are this way, or how they improve or reduce the scalability
-of a system. I will try to do my best to avoid giving falsehoods,
-even if that means a few things won’t be explained.</p></div>
-<div class="sect1">
-<h2 id="_nifs">NIFs</h2>
-<div class="sectionbody">
-<div class="paragraph"><p>NIFs are considered harmful. I don’t know any single NIF-based
-library that I would recommend. That doesn’t mean they should
-all be avoided, just that if you’re going to want your system to
-scale, you probably shouldn’t use a NIF.</p></div>
-<div class="paragraph"><p>A common case for using NIFs is JSON processing. The problem
-is that JSON is a highly inefficient data structure (similar
-in inefficiency to XML, although perhaps not as bad). If you can
-avoid using JSON, you probably should. MessagePack can replace
-it in many situations.</p></div>
-<div class="paragraph"><p>Long-running NIFs will take over a scheduler and prevent Erlang
-from efficiently handling many processes.</p></div>
-<div class="paragraph"><p>Short-running NIFs will still confuse the scheduler if they
-take more than a few microseconds to run.</p></div>
-<div class="paragraph"><p>Threaded NIFs, or the use of the <code>enif_consume_timeslice</code>
-might help allievate this problem, but they’re not a silver bullet.</p></div>
-<div class="paragraph"><p>And as you already know, a crashing NIF will take down your VM,
-destroying any claims you may have at being scalable.</p></div>
-<div class="paragraph"><p>Never use a NIF because "C is fast". This is only true in
-single-threaded programs.</p></div>
-</div>
-</div>
-<div class="sect1">
-<h2 id="_bifs">BIFs</h2>
-<div class="sectionbody">
-<div class="paragraph"><p>BIFs can also be harmful. While they are generally better than
-NIFs, they are not perfect and some of them might have harmful
-effects on the scheduler.</p></div>
-<div class="paragraph"><p>A great example of this is the <code>erlang:decode_packet/3</code>
-BIF, when used for HTTP request or response decoding. Avoiding
-its use in <em>Cowboy</em> allowed us to see a big increase in
-the number of requests production systems were able to handle,
-up to two times the original amount. Incidentally this is something
-that is impossible to detect using synthetic benchmarks.</p></div>
-<div class="paragraph"><p>BIFs that return immediately are perfectly fine though.</p></div>
-</div>
-</div>
-<div class="sect1">
-<h2 id="_binary_strings">Binary strings</h2>
-<div class="sectionbody">
-<div class="paragraph"><p>Binary strings use less memory, which means you spend less time
-allocating memory compared to list-based strings. They are also
-more natural for strings manipulation because they are optimized
-for appending (as opposed to prepending for lists).</p></div>
-<div class="paragraph"><p>If you can process a binary string using a single match context,
-then the code will run incredibly fast. The effects will be much
-increased if the code was compiled using HiPE, even if your Erlang
-system isn’t compiled natively.</p></div>
-<div class="paragraph"><p>Avoid using <code>binary:split</code> or <code>binary:replace</code>
-if you can avoid it. They have a certain overhead due to supporting
-many options that you probably don’t need for most operations.</p></div>
-</div>
-</div>
-<div class="sect1">
-<h2 id="_buffering_and_streaming">Buffering and streaming</h2>
-<div class="sectionbody">
-<div class="paragraph"><p>Use binaries. They are great for appending, and it’s a direct copy
-from what you receive from a stream (usually a socket or a file).</p></div>
-<div class="paragraph"><p>Be careful to not indefinitely receive data, as you might end up
-having a single binary taking up huge amounts of memory.</p></div>
-<div class="paragraph"><p>If you stream from a socket and know how much data you expect,
-then fetch that data in a single <code>recv</code> call.</p></div>
-<div class="paragraph"><p>Similarly, if you can use a single <code>send</code> call, then
-you should do so, to avoid going back and forth unnecessarily between
-your Erlang process and the Erlang port for your socket.</p></div>
-</div>
-</div>
-<div class="sect1">
-<h2 id="_list_and_binary_comprehensions">List and binary comprehensions</h2>
-<div class="sectionbody">
-<div class="paragraph"><p>Prefer list comprehensions over <code>lists:map/2</code>. The
-compiler will be able to optimize your code greatly, for example
-not creating the result if you don’t need it. As time goes on,
-more optimizations will be added to the compiler and you will
-automatically benefit from them.</p></div>
-</div>
-</div>
-<div class="sect1">
-<h2 id="_gen_server_is_no_silver_bullet">gen_server is no silver bullet</h2>
-<div class="sectionbody">
-<div class="paragraph"><p>It’s a bad idea to use <code>gen_server</code> for everything.
-For two reasons.</p></div>
-<div class="paragraph"><p>There is an overhead everytime the <code>gen_server</code> receives
-a call, a cast or a simple message. It can be a problem if your
-<code>gen_server</code> is in a critical code path where speed
-is all that matters. Do not hesitate to create other kinds of
-processes where it makes sense. And depending on the kind of process,
-you might want to consider making them special processes, which
-would essentially behave the same as a <code>gen_server</code>.</p></div>
-<div class="paragraph"><p>A common mistake is to have a unique <code>gen_server</code> to
-handle queries from many processes. This generally becomes the
-biggest bottleneck you’ll want to fix. You should try to avoid
-relying on a single process, using a pool if you can.</p></div>
-</div>
-</div>
-<div class="sect1">
-<h2 id="_supervisor_and_monitoring">Supervisor and monitoring</h2>
-<div class="sectionbody">
-<div class="paragraph"><p>A <code>supervisor</code> is also a <code>gen_server</code>,
-so the previous points also apply to them.</p></div>
-<div class="paragraph"><p>Sometimes you’re in a situation where you have supervised
-processes but also want to monitor them in one or more other
-processes, effectively duplicating the work. The supervisor
-already knows when processes die, why not use this to our
-advantage?</p></div>
-<div class="paragraph"><p>You can create a custom supervisor process that will perform
-both the supervision and handle exit and other events, allowing
-to avoid the combination of supervising and monitoring which
-can prove harmful when many processes die at once, or when you
-have many short lived processes.</p></div>
-</div>
-</div>
-<div class="sect1">
-<h2 id="_ets_for_lolspeed_tm">ets for LOLSPEED(tm)</h2>
-<div class="sectionbody">
-<div class="paragraph"><p>If you have data queried or modified by many processes, then
-<code>ets</code> public or protected tables will give you the
-performance boost you require. Do not forget to set the
-<code>read_concurrency</code> or <code>write_concurrency</code>
-options though.</p></div>
-<div class="paragraph"><p>You might also be thrilled to know that Erlang R16B will feature
-a big performance improvement for accessing <code>ets</code> tables
-concurrently.</p></div>
-</div>
-</div>
+<div class="paragraph"><p>I would like to share some experience and theories on +Erlang scalability.</p></div> +<div class="paragraph"><p>This will be in the form of a series of hints, which +may or may not be accompanied with explanations as to why +things are this way, or how they improve or reduce the scalability +of a system. I will try to do my best to avoid giving falsehoods, +even if that means a few things won’t be explained.</p></div> +<div class="sect1"> +<h2 id="_nifs">NIFs</h2> +<div class="sectionbody"> +<div class="paragraph"><p>NIFs are considered harmful. I don’t know any single NIF-based +library that I would recommend. That doesn’t mean they should +all be avoided, just that if you’re going to want your system to +scale, you probably shouldn’t use a NIF.</p></div> +<div class="paragraph"><p>A common case for using NIFs is JSON processing. The problem +is that JSON is a highly inefficient data structure (similar +in inefficiency to XML, although perhaps not as bad). If you can +avoid using JSON, you probably should. MessagePack can replace +it in many situations.</p></div> +<div class="paragraph"><p>Long-running NIFs will take over a scheduler and prevent Erlang +from efficiently handling many processes.</p></div> +<div class="paragraph"><p>Short-running NIFs will still confuse the scheduler if they +take more than a few microseconds to run.</p></div> +<div class="paragraph"><p>Threaded NIFs, or the use of the <code>enif_consume_timeslice</code> +might help allievate this problem, but they’re not a silver bullet.</p></div> +<div class="paragraph"><p>And as you already know, a crashing NIF will take down your VM, +destroying any claims you may have at being scalable.</p></div> +<div class="paragraph"><p>Never use a NIF because "C is fast". This is only true in +single-threaded programs.</p></div> +</div> +</div> +<div class="sect1"> +<h2 id="_bifs">BIFs</h2> +<div class="sectionbody"> +<div class="paragraph"><p>BIFs can also be harmful. While they are generally better than +NIFs, they are not perfect and some of them might have harmful +effects on the scheduler.</p></div> +<div class="paragraph"><p>A great example of this is the <code>erlang:decode_packet/3</code> +BIF, when used for HTTP request or response decoding. Avoiding +its use in <em>Cowboy</em> allowed us to see a big increase in +the number of requests production systems were able to handle, +up to two times the original amount. Incidentally this is something +that is impossible to detect using synthetic benchmarks.</p></div> +<div class="paragraph"><p>BIFs that return immediately are perfectly fine though.</p></div> +</div> +</div> +<div class="sect1"> +<h2 id="_binary_strings">Binary strings</h2> +<div class="sectionbody"> +<div class="paragraph"><p>Binary strings use less memory, which means you spend less time +allocating memory compared to list-based strings. They are also +more natural for strings manipulation because they are optimized +for appending (as opposed to prepending for lists).</p></div> +<div class="paragraph"><p>If you can process a binary string using a single match context, +then the code will run incredibly fast. The effects will be much +increased if the code was compiled using HiPE, even if your Erlang +system isn’t compiled natively.</p></div> +<div class="paragraph"><p>Avoid using <code>binary:split</code> or <code>binary:replace</code> +if you can avoid it. They have a certain overhead due to supporting +many options that you probably don’t need for most operations.</p></div> +</div> +</div> +<div class="sect1"> +<h2 id="_buffering_and_streaming">Buffering and streaming</h2> +<div class="sectionbody"> +<div class="paragraph"><p>Use binaries. They are great for appending, and it’s a direct copy +from what you receive from a stream (usually a socket or a file).</p></div> +<div class="paragraph"><p>Be careful to not indefinitely receive data, as you might end up +having a single binary taking up huge amounts of memory.</p></div> +<div class="paragraph"><p>If you stream from a socket and know how much data you expect, +then fetch that data in a single <code>recv</code> call.</p></div> +<div class="paragraph"><p>Similarly, if you can use a single <code>send</code> call, then +you should do so, to avoid going back and forth unnecessarily between +your Erlang process and the Erlang port for your socket.</p></div> +</div> +</div> +<div class="sect1"> +<h2 id="_list_and_binary_comprehensions">List and binary comprehensions</h2> +<div class="sectionbody"> +<div class="paragraph"><p>Prefer list comprehensions over <code>lists:map/2</code>. The +compiler will be able to optimize your code greatly, for example +not creating the result if you don’t need it. As time goes on, +more optimizations will be added to the compiler and you will +automatically benefit from them.</p></div> +</div> +</div> +<div class="sect1"> +<h2 id="_gen_server_is_no_silver_bullet">gen_server is no silver bullet</h2> +<div class="sectionbody"> +<div class="paragraph"><p>It’s a bad idea to use <code>gen_server</code> for everything. +For two reasons.</p></div> +<div class="paragraph"><p>There is an overhead everytime the <code>gen_server</code> receives +a call, a cast or a simple message. It can be a problem if your +<code>gen_server</code> is in a critical code path where speed +is all that matters. Do not hesitate to create other kinds of +processes where it makes sense. And depending on the kind of process, +you might want to consider making them special processes, which +would essentially behave the same as a <code>gen_server</code>.</p></div> +<div class="paragraph"><p>A common mistake is to have a unique <code>gen_server</code> to +handle queries from many processes. This generally becomes the +biggest bottleneck you’ll want to fix. You should try to avoid +relying on a single process, using a pool if you can.</p></div> +</div> +</div> +<div class="sect1"> +<h2 id="_supervisor_and_monitoring">Supervisor and monitoring</h2> +<div class="sectionbody"> +<div class="paragraph"><p>A <code>supervisor</code> is also a <code>gen_server</code>, +so the previous points also apply to them.</p></div> +<div class="paragraph"><p>Sometimes you’re in a situation where you have supervised +processes but also want to monitor them in one or more other +processes, effectively duplicating the work. The supervisor +already knows when processes die, why not use this to our +advantage?</p></div> +<div class="paragraph"><p>You can create a custom supervisor process that will perform +both the supervision and handle exit and other events, allowing +to avoid the combination of supervising and monitoring which +can prove harmful when many processes die at once, or when you +have many short lived processes.</p></div> +</div> +</div> +<div class="sect1"> +<h2 id="_ets_for_lolspeed_tm">ets for LOLSPEED(tm)</h2> +<div class="sectionbody"> +<div class="paragraph"><p>If you have data queried or modified by many processes, then +<code>ets</code> public or protected tables will give you the +performance boost you require. Do not forget to set the +<code>read_concurrency</code> or <code>write_concurrency</code> +options though.</p></div> +<div class="paragraph"><p>You might also be thrilled to know that Erlang R16B will feature +a big performance improvement for accessing <code>ets</code> tables +concurrently.</p></div> +</div> +</div> </article> </div> @@ -216,55 +216,107 @@ concurrently.</p></div> <h3>More articles</h3> <ul id="articles-nav" class="extra_margin"> - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + + + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + + <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + - <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + + <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + - <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + + <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + - <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + + <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + - <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + + <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + - <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + + <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + - <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + + <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + - <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + + <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + - <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + + <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + - <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + + <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + - <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + </ul> diff --git a/articles/erlang-validate-utf8/index.html b/articles/erlang-validate-utf8/index.html index a96aba26..3eceb840 100644 --- a/articles/erlang-validate-utf8/index.html +++ b/articles/erlang-validate-utf8/index.html @@ -7,7 +7,7 @@ <meta name="description" content=""> <meta name="author" content="Loïc Hoguin based on a design from (Soft10) Pol Cámara"> - <meta name="generator" content="Hugo 0.17" /> + <meta name="generator" content="Hugo 0.26" /> <title>Nine Nines: Validating UTF-8 binaries with Erlang</title> @@ -74,191 +74,191 @@ </p> </header> -<div class="paragraph"><p>Yesterday I pushed Websocket permessage-deflate to
-Cowboy master. I also pushed
-<a href="https://github.com/ninenines/cowlib/commit/7e4983b70ddf8cedb967e36fba6a600731bdad5d">a
-change in the way the code validates UTF-8 data</a>
-(required for text and close frames as per the spec).</p></div>
-<div class="paragraph"><p>When looking into why the permessage-deflate tests
-in autobahntestsuite were taking such a long time, I
-found that autobahn is using an adaptation of the
-algorithm named <a href="http://bjoern.hoehrmann.de/utf-8/decoder/dfa/">Flexible
-and Economical UTF-8 Decoder</a>. This is the C99
-implementation:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="font-style: italic"><span style="color: #9A1900">// Copyright (c) 2008-2009 Bjoern Hoehrmann <[email protected]></span></span>
-<span style="font-style: italic"><span style="color: #9A1900">// See http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details.</span></span>
-
-<span style="font-weight: bold"><span style="color: #000080">#define</span></span> UTF8_ACCEPT <span style="color: #993399">0</span>
-<span style="font-weight: bold"><span style="color: #000080">#define</span></span> UTF8_REJECT <span style="color: #993399">1</span>
-
-<span style="font-weight: bold"><span style="color: #0000FF">static</span></span> <span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #008080">uint8_t</span> utf8d<span style="color: #990000">[]</span> <span style="color: #990000">=</span> <span style="color: #FF0000">{</span>
- <span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// 00..1f</span></span>
- <span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// 20..3f</span></span>
- <span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// 40..5f</span></span>
- <span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// 60..7f</span></span>
- <span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// 80..9f</span></span>
- <span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// a0..bf</span></span>
- <span style="color: #993399">8</span><span style="color: #990000">,</span><span style="color: #993399">8</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// c0..df</span></span>
- <span style="color: #993399">0xa</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x4</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// e0..ef</span></span>
- <span style="color: #993399">0xb</span><span style="color: #990000">,</span><span style="color: #993399">0x6</span><span style="color: #990000">,</span><span style="color: #993399">0x6</span><span style="color: #990000">,</span><span style="color: #993399">0x6</span><span style="color: #990000">,</span><span style="color: #993399">0x5</span><span style="color: #990000">,</span><span style="color: #993399">0x8</span><span style="color: #990000">,</span><span style="color: #993399">0x8</span><span style="color: #990000">,</span><span style="color: #993399">0x8</span><span style="color: #990000">,</span><span style="color: #993399">0x8</span><span style="color: #990000">,</span><span style="color: #993399">0x8</span><span style="color: #990000">,</span><span style="color: #993399">0x8</span><span style="color: #990000">,</span><span style="color: #993399">0x8</span><span style="color: #990000">,</span><span style="color: #993399">0x8</span><span style="color: #990000">,</span><span style="color: #993399">0x8</span><span style="color: #990000">,</span><span style="color: #993399">0x8</span><span style="color: #990000">,</span><span style="color: #993399">0x8</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// f0..ff</span></span>
- <span style="color: #993399">0x0</span><span style="color: #990000">,</span><span style="color: #993399">0x1</span><span style="color: #990000">,</span><span style="color: #993399">0x2</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x5</span><span style="color: #990000">,</span><span style="color: #993399">0x8</span><span style="color: #990000">,</span><span style="color: #993399">0x7</span><span style="color: #990000">,</span><span style="color: #993399">0x1</span><span style="color: #990000">,</span><span style="color: #993399">0x1</span><span style="color: #990000">,</span><span style="color: #993399">0x1</span><span style="color: #990000">,</span><span style="color: #993399">0x4</span><span style="color: #990000">,</span><span style="color: #993399">0x6</span><span style="color: #990000">,</span><span style="color: #993399">0x1</span><span style="color: #990000">,</span><span style="color: #993399">0x1</span><span style="color: #990000">,</span><span style="color: #993399">0x1</span><span style="color: #990000">,</span><span style="color: #993399">0x1</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// s0..s0</span></span>
- <span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// s1..s2</span></span>
- <span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// s3..s4</span></span>
- <span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">3</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">3</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// s5..s6</span></span>
- <span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">3</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">3</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">3</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">3</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// s7..s8</span></span>
-<span style="color: #FF0000">}</span><span style="color: #990000">;</span>
-
-uint32_t inline
-<span style="font-weight: bold"><span style="color: #000000">decode</span></span><span style="color: #990000">(</span>uint32_t<span style="color: #990000">*</span> state<span style="color: #990000">,</span> uint32_t<span style="color: #990000">*</span> codep<span style="color: #990000">,</span> <span style="color: #008080">uint32_t</span> byte<span style="color: #990000">)</span> <span style="color: #FF0000">{</span>
- <span style="color: #008080">uint32_t</span> type <span style="color: #990000">=</span> utf8d<span style="color: #990000">[</span>byte<span style="color: #990000">];</span>
-
- <span style="color: #990000">*</span>codep <span style="color: #990000">=</span> <span style="color: #990000">(*</span>state <span style="color: #990000">!=</span> UTF8_ACCEPT<span style="color: #990000">)</span> <span style="color: #990000">?</span>
- <span style="color: #990000">(</span>byte <span style="color: #990000">&</span> <span style="color: #993399">0x3fu</span><span style="color: #990000">)</span> <span style="color: #990000">|</span> <span style="color: #990000">(*</span>codep <span style="color: #990000"><<</span> <span style="color: #993399">6</span><span style="color: #990000">)</span> <span style="color: #990000">:</span>
- <span style="color: #990000">(</span><span style="color: #993399">0xff</span> <span style="color: #990000">>></span> type<span style="color: #990000">)</span> <span style="color: #990000">&</span> <span style="color: #990000">(</span>byte<span style="color: #990000">);</span>
-
- <span style="color: #990000">*</span>state <span style="color: #990000">=</span> utf8d<span style="color: #990000">[</span><span style="color: #993399">256</span> <span style="color: #990000">+</span> <span style="color: #990000">*</span>state<span style="color: #990000">*</span><span style="color: #993399">16</span> <span style="color: #990000">+</span> type<span style="color: #990000">];</span>
- <span style="font-weight: bold"><span style="color: #0000FF">return</span></span> <span style="color: #990000">*</span>state<span style="color: #990000">;</span>
-<span style="color: #FF0000">}</span></tt></pre></div></div>
-<div class="paragraph"><p>And this is the Erlang implementation I came up with:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="font-style: italic"><span style="color: #9A1900">%% This function returns 0 on success, 1 on error, and 2..8 on incomplete data.</span></span>
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<>></span>, <span style="color: #009900">State</span>) <span style="color: #990000">-></span> <span style="color: #009900">State</span>;
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">0</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">128</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">2</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">128</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">144</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">3</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">128</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">144</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">5</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">128</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">144</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">7</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">128</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">144</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">8</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">128</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">144</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">2</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">144</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">160</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">3</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">144</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">160</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">5</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">144</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">160</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">6</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">144</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">160</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">7</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">144</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">160</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">2</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">160</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">192</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">3</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">160</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">192</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">4</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">160</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">192</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">6</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">160</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">192</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">7</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">160</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">192</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">0</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">194</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">224</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">224</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">0</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">4</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">0</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">225</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">237</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">237</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">0</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">5</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">0</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">=:=</span> <span style="color: #993399">238</span>; <span style="color: #009900">C</span> <span style="color: #990000">=:=</span> <span style="color: #993399">239</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">240</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">0</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">6</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">0</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">=:=</span> <span style="color: #993399">241</span>; <span style="color: #009900">C</span> <span style="color: #990000">=:=</span> <span style="color: #993399">242</span>; <span style="color: #009900">C</span> <span style="color: #990000">=:=</span> <span style="color: #993399">243</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">7</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">244</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">0</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">8</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">_</span>, <span style="color: #990000">_</span>) <span style="color: #990000">-></span> <span style="color: #993399">1</span><span style="color: #990000">.</span></tt></pre></div></div>
-<div class="paragraph"><p>Does it look similar to you? So how did we get there?</p></div>
-<div class="paragraph"><p>I started with a naive implementation of the original. First, we
-don’t need the codepoint calculated and extracted for our validation
-function. We just want to know the data is valid, so we only need to
-calculate the next state. Then, the only thing we needed to be careful
-about was that tuples are 1-based, and that we need to stop processing
-the binary when we get the state 1 or when the binary is empty.</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<>></span>, <span style="color: #009900">State</span>) <span style="color: #990000">-></span> <span style="color: #009900">State</span>;
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">_</span>, <span style="color: #993399">1</span>) <span style="color: #990000">-></span> <span style="color: #993399">1</span>;
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #009900">State</span>) <span style="color: #990000">-></span>
- <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="font-weight: bold"><span style="color: #000080">element</span></span>(<span style="color: #993399">257</span> <span style="color: #990000">+</span> <span style="color: #009900">State</span> <span style="color: #990000">*</span> <span style="color: #993399">16</span> <span style="color: #990000">+</span> <span style="font-weight: bold"><span style="color: #000080">element</span></span>(<span style="color: #993399">1</span> <span style="color: #990000">+</span> <span style="color: #009900">C</span>, <span style="font-weight: bold"><span style="color: #000080">?UTF8D</span></span>), <span style="font-weight: bold"><span style="color: #000080">?UTF8D</span></span>))<span style="color: #990000">.</span></tt></pre></div></div>
-<div class="paragraph"><p>The macro <code>?UTF8D</code> is the tuple equivalent of the C array
-in the original code.</p></div>
-<div class="paragraph"><p>Compared to our previous algorithm, this performed about the same.
-In some situations a little faster, in some a little slower. In other words,
-not good enough. But because this new algorithm allows us to avoid a binary
-concatenation this warranted looking further.</p></div>
-<div class="paragraph"><p>It was time to step into crazy land.</p></div>
-<div class="paragraph"><p>Erlang is very good at pattern matching, even more so than doing some
-arithmetic coupled by fetching elements from a tuple. So I decided I was
-going to write all possible clauses for all combinations of <code>C</code>
-and <code>State</code>. And by write I mean generate.</p></div>
-<div class="paragraph"><p>So I opened my Erlang shell, defined the variable <code>D</code> to be
-the tuple <code>?UTF8D</code> with its 400 elements, and then ran the
-following expression (after a bit of trial and error):</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="color: #993399">16</span><span style="color: #990000">></span> <span style="font-weight: bold"><span style="color: #000000">file:write_file</span></span>(<span style="color: #FF0000">"out.txt"</span>,
- [<span style="font-weight: bold"><span style="color: #000000">io_lib:format</span></span>(<span style="color: #FF0000">"validate_utf8(<< ~p, Rest/bits >>, ~p) -> ~p;~n"</span>,
- [<span style="color: #009900">C</span>, <span style="color: #009900">S</span>, <span style="font-weight: bold"><span style="color: #000080">element</span></span>(<span style="color: #993399">257</span> <span style="color: #990000">+</span> <span style="color: #009900">S</span> <span style="color: #990000">*</span> <span style="color: #993399">16</span> <span style="color: #990000">+</span> <span style="font-weight: bold"><span style="color: #000080">element</span></span>(<span style="color: #993399">1</span> <span style="color: #990000">+</span> <span style="color: #009900">C</span>, <span style="color: #009900">D</span>), <span style="color: #009900">D</span>)])
- || <span style="color: #009900">C</span> <span style="color: #990000"><-</span> <span style="font-weight: bold"><span style="color: #000000">lists:seq</span></span>(<span style="color: #993399">0</span>,<span style="color: #993399">255</span>), <span style="color: #009900">S</span> <span style="color: #990000"><-</span> <span style="font-weight: bold"><span style="color: #000000">lists:seq</span></span>(<span style="color: #993399">0</span>,<span style="color: #993399">8</span>)])<span style="color: #990000">.</span>
-<span style="color: #FF6600">ok</span></tt></pre></div></div>
-<div class="paragraph"><p>The result is a 2304 lines long file, containing 2304 clauses.
-People who pay attention to what I say on Twitter will remember
-I said something around 3000 clauses, but that was just me not
-using the right number of states in my estimate.</p></div>
-<div class="paragraph"><p>There was a little more work to be done on this generated
-code that I did using regular expressions. We need to recurse
-when the resulting state is not 1. We also need to stop when
-the binary is empty, making it the 2305th clause.</p></div>
-<div class="paragraph"><p>Still, 2305 is a lot. But hey, the code did work, and faster
-than the previous implementation too! But hey, perhaps I could
-find a way to reduce its size.</p></div>
-<div class="paragraph"><p>Removing all the clauses that return 1 and putting a catch-all
-clause at the end instead reduced the number to about 500, and
-showed that many clauses were similar:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">0</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">0</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">1</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">0</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">2</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">0</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">3</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">0</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">4</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">0</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">5</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">0</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">6</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">0</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">7</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">0</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>);</tt></pre></div></div>
-<div class="paragraph"><p>But also:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">157</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">2</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">157</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">3</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">157</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">5</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">157</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">6</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">157</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">7</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">158</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">2</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">158</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">3</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">158</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">5</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">158</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">6</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">158</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">7</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>);</tt></pre></div></div>
-<div class="paragraph"><p>Patterns, my favorites!</p></div>
-<div class="paragraph"><p>A little more time was spent to edit the 500 or so clauses into
-smaller equivalents, testing that performance was not impacted, and
-comitting the result.</p></div>
-<div class="paragraph"><p>The patterns above can be found here in the resulting function:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">0</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">128</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>);
-<span style="color: #990000">...</span>
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">2</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">144</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">160</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">3</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">144</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">160</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">5</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">144</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">160</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">6</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">144</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">160</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">7</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">144</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">160</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>);
-<span style="color: #990000">...</span></tt></pre></div></div>
-<div class="paragraph"><p>I hope you enjoyed this post.</p></div>
+<div class="paragraph"><p>Yesterday I pushed Websocket permessage-deflate to +Cowboy master. I also pushed +<a href="https://github.com/ninenines/cowlib/commit/7e4983b70ddf8cedb967e36fba6a600731bdad5d">a +change in the way the code validates UTF-8 data</a> +(required for text and close frames as per the spec).</p></div> +<div class="paragraph"><p>When looking into why the permessage-deflate tests +in autobahntestsuite were taking such a long time, I +found that autobahn is using an adaptation of the +algorithm named <a href="http://bjoern.hoehrmann.de/utf-8/decoder/dfa/">Flexible +and Economical UTF-8 Decoder</a>. This is the C99 +implementation:</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="font-style: italic"><span style="color: #9A1900">// Copyright (c) 2008-2009 Bjoern Hoehrmann <[email protected]></span></span> +<span style="font-style: italic"><span style="color: #9A1900">// See http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details.</span></span> + +<span style="font-weight: bold"><span style="color: #000080">#define</span></span> UTF8_ACCEPT <span style="color: #993399">0</span> +<span style="font-weight: bold"><span style="color: #000080">#define</span></span> UTF8_REJECT <span style="color: #993399">1</span> + +<span style="font-weight: bold"><span style="color: #0000FF">static</span></span> <span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #008080">uint8_t</span> utf8d<span style="color: #990000">[]</span> <span style="color: #990000">=</span> <span style="color: #FF0000">{</span> + <span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// 00..1f</span></span> + <span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// 20..3f</span></span> + <span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// 40..5f</span></span> + <span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// 60..7f</span></span> + <span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// 80..9f</span></span> + <span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// a0..bf</span></span> + <span style="color: #993399">8</span><span style="color: #990000">,</span><span style="color: #993399">8</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// c0..df</span></span> + <span style="color: #993399">0xa</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x4</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// e0..ef</span></span> + <span style="color: #993399">0xb</span><span style="color: #990000">,</span><span style="color: #993399">0x6</span><span style="color: #990000">,</span><span style="color: #993399">0x6</span><span style="color: #990000">,</span><span style="color: #993399">0x6</span><span style="color: #990000">,</span><span style="color: #993399">0x5</span><span style="color: #990000">,</span><span style="color: #993399">0x8</span><span style="color: #990000">,</span><span style="color: #993399">0x8</span><span style="color: #990000">,</span><span style="color: #993399">0x8</span><span style="color: #990000">,</span><span style="color: #993399">0x8</span><span style="color: #990000">,</span><span style="color: #993399">0x8</span><span style="color: #990000">,</span><span style="color: #993399">0x8</span><span style="color: #990000">,</span><span style="color: #993399">0x8</span><span style="color: #990000">,</span><span style="color: #993399">0x8</span><span style="color: #990000">,</span><span style="color: #993399">0x8</span><span style="color: #990000">,</span><span style="color: #993399">0x8</span><span style="color: #990000">,</span><span style="color: #993399">0x8</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// f0..ff</span></span> + <span style="color: #993399">0x0</span><span style="color: #990000">,</span><span style="color: #993399">0x1</span><span style="color: #990000">,</span><span style="color: #993399">0x2</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x5</span><span style="color: #990000">,</span><span style="color: #993399">0x8</span><span style="color: #990000">,</span><span style="color: #993399">0x7</span><span style="color: #990000">,</span><span style="color: #993399">0x1</span><span style="color: #990000">,</span><span style="color: #993399">0x1</span><span style="color: #990000">,</span><span style="color: #993399">0x1</span><span style="color: #990000">,</span><span style="color: #993399">0x4</span><span style="color: #990000">,</span><span style="color: #993399">0x6</span><span style="color: #990000">,</span><span style="color: #993399">0x1</span><span style="color: #990000">,</span><span style="color: #993399">0x1</span><span style="color: #990000">,</span><span style="color: #993399">0x1</span><span style="color: #990000">,</span><span style="color: #993399">0x1</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// s0..s0</span></span> + <span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// s1..s2</span></span> + <span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// s3..s4</span></span> + <span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">3</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">3</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// s5..s6</span></span> + <span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">3</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">3</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">3</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">3</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// s7..s8</span></span> +<span style="color: #FF0000">}</span><span style="color: #990000">;</span> + +uint32_t inline +<span style="font-weight: bold"><span style="color: #000000">decode</span></span><span style="color: #990000">(</span>uint32_t<span style="color: #990000">*</span> state<span style="color: #990000">,</span> uint32_t<span style="color: #990000">*</span> codep<span style="color: #990000">,</span> <span style="color: #008080">uint32_t</span> byte<span style="color: #990000">)</span> <span style="color: #FF0000">{</span> + <span style="color: #008080">uint32_t</span> type <span style="color: #990000">=</span> utf8d<span style="color: #990000">[</span>byte<span style="color: #990000">];</span> + + <span style="color: #990000">*</span>codep <span style="color: #990000">=</span> <span style="color: #990000">(*</span>state <span style="color: #990000">!=</span> UTF8_ACCEPT<span style="color: #990000">)</span> <span style="color: #990000">?</span> + <span style="color: #990000">(</span>byte <span style="color: #990000">&</span> <span style="color: #993399">0x3fu</span><span style="color: #990000">)</span> <span style="color: #990000">|</span> <span style="color: #990000">(*</span>codep <span style="color: #990000"><<</span> <span style="color: #993399">6</span><span style="color: #990000">)</span> <span style="color: #990000">:</span> + <span style="color: #990000">(</span><span style="color: #993399">0xff</span> <span style="color: #990000">>></span> type<span style="color: #990000">)</span> <span style="color: #990000">&</span> <span style="color: #990000">(</span>byte<span style="color: #990000">);</span> + + <span style="color: #990000">*</span>state <span style="color: #990000">=</span> utf8d<span style="color: #990000">[</span><span style="color: #993399">256</span> <span style="color: #990000">+</span> <span style="color: #990000">*</span>state<span style="color: #990000">*</span><span style="color: #993399">16</span> <span style="color: #990000">+</span> type<span style="color: #990000">];</span> + <span style="font-weight: bold"><span style="color: #0000FF">return</span></span> <span style="color: #990000">*</span>state<span style="color: #990000">;</span> +<span style="color: #FF0000">}</span></tt></pre></div></div> +<div class="paragraph"><p>And this is the Erlang implementation I came up with:</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="font-style: italic"><span style="color: #9A1900">%% This function returns 0 on success, 1 on error, and 2..8 on incomplete data.</span></span> +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<>></span>, <span style="color: #009900">State</span>) <span style="color: #990000">-></span> <span style="color: #009900">State</span>; +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">0</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">128</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">2</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">128</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">144</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">3</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">128</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">144</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">5</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">128</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">144</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">7</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">128</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">144</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">8</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">128</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">144</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">2</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">144</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">160</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">3</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">144</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">160</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">5</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">144</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">160</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">6</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">144</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">160</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">7</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">144</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">160</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">2</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">160</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">192</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">3</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">160</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">192</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">4</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">160</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">192</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">6</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">160</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">192</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">7</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">160</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">192</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">0</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">194</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">224</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">224</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">0</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">4</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">0</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">225</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">237</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">237</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">0</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">5</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">0</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">=:=</span> <span style="color: #993399">238</span>; <span style="color: #009900">C</span> <span style="color: #990000">=:=</span> <span style="color: #993399">239</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">240</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">0</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">6</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">0</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">=:=</span> <span style="color: #993399">241</span>; <span style="color: #009900">C</span> <span style="color: #990000">=:=</span> <span style="color: #993399">242</span>; <span style="color: #009900">C</span> <span style="color: #990000">=:=</span> <span style="color: #993399">243</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">7</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">244</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">0</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">8</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">_</span>, <span style="color: #990000">_</span>) <span style="color: #990000">-></span> <span style="color: #993399">1</span><span style="color: #990000">.</span></tt></pre></div></div> +<div class="paragraph"><p>Does it look similar to you? So how did we get there?</p></div> +<div class="paragraph"><p>I started with a naive implementation of the original. First, we +don’t need the codepoint calculated and extracted for our validation +function. We just want to know the data is valid, so we only need to +calculate the next state. Then, the only thing we needed to be careful +about was that tuples are 1-based, and that we need to stop processing +the binary when we get the state 1 or when the binary is empty.</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<>></span>, <span style="color: #009900">State</span>) <span style="color: #990000">-></span> <span style="color: #009900">State</span>; +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">_</span>, <span style="color: #993399">1</span>) <span style="color: #990000">-></span> <span style="color: #993399">1</span>; +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #009900">State</span>) <span style="color: #990000">-></span> + <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="font-weight: bold"><span style="color: #000080">element</span></span>(<span style="color: #993399">257</span> <span style="color: #990000">+</span> <span style="color: #009900">State</span> <span style="color: #990000">*</span> <span style="color: #993399">16</span> <span style="color: #990000">+</span> <span style="font-weight: bold"><span style="color: #000080">element</span></span>(<span style="color: #993399">1</span> <span style="color: #990000">+</span> <span style="color: #009900">C</span>, <span style="font-weight: bold"><span style="color: #000080">?UTF8D</span></span>), <span style="font-weight: bold"><span style="color: #000080">?UTF8D</span></span>))<span style="color: #990000">.</span></tt></pre></div></div> +<div class="paragraph"><p>The macro <code>?UTF8D</code> is the tuple equivalent of the C array +in the original code.</p></div> +<div class="paragraph"><p>Compared to our previous algorithm, this performed about the same. +In some situations a little faster, in some a little slower. In other words, +not good enough. But because this new algorithm allows us to avoid a binary +concatenation this warranted looking further.</p></div> +<div class="paragraph"><p>It was time to step into crazy land.</p></div> +<div class="paragraph"><p>Erlang is very good at pattern matching, even more so than doing some +arithmetic coupled by fetching elements from a tuple. So I decided I was +going to write all possible clauses for all combinations of <code>C</code> +and <code>State</code>. And by write I mean generate.</p></div> +<div class="paragraph"><p>So I opened my Erlang shell, defined the variable <code>D</code> to be +the tuple <code>?UTF8D</code> with its 400 elements, and then ran the +following expression (after a bit of trial and error):</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="color: #993399">16</span><span style="color: #990000">></span> <span style="font-weight: bold"><span style="color: #000000">file:write_file</span></span>(<span style="color: #FF0000">"out.txt"</span>, + [<span style="font-weight: bold"><span style="color: #000000">io_lib:format</span></span>(<span style="color: #FF0000">"validate_utf8(<< ~p, Rest/bits >>, ~p) -> ~p;~n"</span>, + [<span style="color: #009900">C</span>, <span style="color: #009900">S</span>, <span style="font-weight: bold"><span style="color: #000080">element</span></span>(<span style="color: #993399">257</span> <span style="color: #990000">+</span> <span style="color: #009900">S</span> <span style="color: #990000">*</span> <span style="color: #993399">16</span> <span style="color: #990000">+</span> <span style="font-weight: bold"><span style="color: #000080">element</span></span>(<span style="color: #993399">1</span> <span style="color: #990000">+</span> <span style="color: #009900">C</span>, <span style="color: #009900">D</span>), <span style="color: #009900">D</span>)]) + || <span style="color: #009900">C</span> <span style="color: #990000"><-</span> <span style="font-weight: bold"><span style="color: #000000">lists:seq</span></span>(<span style="color: #993399">0</span>,<span style="color: #993399">255</span>), <span style="color: #009900">S</span> <span style="color: #990000"><-</span> <span style="font-weight: bold"><span style="color: #000000">lists:seq</span></span>(<span style="color: #993399">0</span>,<span style="color: #993399">8</span>)])<span style="color: #990000">.</span> +<span style="color: #FF6600">ok</span></tt></pre></div></div> +<div class="paragraph"><p>The result is a 2304 lines long file, containing 2304 clauses. +People who pay attention to what I say on Twitter will remember +I said something around 3000 clauses, but that was just me not +using the right number of states in my estimate.</p></div> +<div class="paragraph"><p>There was a little more work to be done on this generated +code that I did using regular expressions. We need to recurse +when the resulting state is not 1. We also need to stop when +the binary is empty, making it the 2305th clause.</p></div> +<div class="paragraph"><p>Still, 2305 is a lot. But hey, the code did work, and faster +than the previous implementation too! But hey, perhaps I could +find a way to reduce its size.</p></div> +<div class="paragraph"><p>Removing all the clauses that return 1 and putting a catch-all +clause at the end instead reduced the number to about 500, and +showed that many clauses were similar:</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">0</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">0</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">1</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">0</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">2</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">0</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">3</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">0</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">4</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">0</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">5</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">0</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">6</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">0</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">7</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">0</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>);</tt></pre></div></div> +<div class="paragraph"><p>But also:</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">157</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">2</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">157</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">3</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">157</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">5</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">157</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">6</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">157</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">7</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">158</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">2</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">158</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">3</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">158</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">5</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">158</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">6</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #993399">158</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">7</span>) <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>);</tt></pre></div></div> +<div class="paragraph"><p>Patterns, my favorites!</p></div> +<div class="paragraph"><p>A little more time was spent to edit the 500 or so clauses into +smaller equivalents, testing that performance was not impacted, and +comitting the result.</p></div> +<div class="paragraph"><p>The patterns above can be found here in the resulting function:</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">0</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">128</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>); +<span style="color: #990000">...</span> +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">2</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">144</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">160</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">3</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">144</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">160</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">5</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">144</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">160</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">6</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">144</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">160</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>); +<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000"><<</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">>></span>, <span style="color: #993399">7</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">>=</span> <span style="color: #993399">144</span>, <span style="color: #009900">C</span> <span style="color: #990000"><</span> <span style="color: #993399">160</span> <span style="color: #990000">-></span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>); +<span style="color: #990000">...</span></tt></pre></div></div> +<div class="paragraph"><p>I hope you enjoyed this post.</p></div> </article> </div> @@ -267,55 +267,107 @@ http://www.gnu.org/software/src-highlite --> <h3>More articles</h3> <ul id="articles-nav" class="extra_margin"> - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + + + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + + <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + - <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + + <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + - <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + + <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + - <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + + <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + - <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + + <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + - <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + + <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + - <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + + <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + - <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + + <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + - <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + + <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + - <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + + <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + - <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + </ul> diff --git a/articles/erlang.mk-and-relx/index.html b/articles/erlang.mk-and-relx/index.html index 359a30e6..28bdc7a5 100644 --- a/articles/erlang.mk-and-relx/index.html +++ b/articles/erlang.mk-and-relx/index.html @@ -7,7 +7,7 @@ <meta name="description" content=""> <meta name="author" content="Loïc Hoguin based on a design from (Soft10) Pol Cámara"> - <meta name="generator" content="Hugo 0.17" /> + <meta name="generator" content="Hugo 0.26" /> <title>Nine Nines: Build Erlang releases with Erlang.mk and Relx</title> @@ -74,94 +74,118 @@ </p> </header> -<div class="paragraph"><p>Building OTP releases has always been a difficult task. Tools like
-Reltool or Rebar have made this simpler, but
-it’s no panacea. This article will show you an alternative and
-hopefully much simpler solution.</p></div>
-<div class="paragraph"><p>There is two steps to building a release. First you need to build
-the various OTP applications you want to include in the release. Once
-done, you need to create the release itself, by including the Erlang
-runtime system alongside the applications, a boot script to start the
-node and all its applications, and some configuration files.</p></div>
-<div class="paragraph"><p><a href="https://github.com/extend/erlang.mk">Erlang.mk</a> solves
-the first step. It is an include file for GNU Make. Just
-including it in a Makefile is enough to allow building your project,
-fetching and building dependencies, building documentation, performing
-static analysis and more.</p></div>
-<div class="paragraph"><p><a href="https://github.com/erlware/relx">Relx</a> solves the second
-step. It is a release creation tool, wrapped into a single executable
-file. It doesn’t require a configuration file. And if you do need one,
-it will be a pretty small one.</p></div>
-<div class="paragraph"><p>Let’s take a look at the smallest Erlang.mk powered
-Makefile. There is only one thing required: defining the project
-name.</p></div>
-<div class="listingblock">
-<div class="content"></div></div>
-<div class="paragraph"><p>Simply doing this allows you to build your application by typing
-<code>make</code>, running tests using <code>make tests</code>, and
-more. It will even compile your <em>.dtl</em> files found in the
-<em>templates/</em> directory if you are using ErlyDTL!</p></div>
-<div class="paragraph"><p>Let’s now take a look at a simplified version of the Makefile for
-this website. I only removed a few targets that were off-topic.</p></div>
-<div class="listingblock">
-<div class="content"></div></div>
-<div class="paragraph"><p>You can see here how to define dependencies. First you list all
-the dependency names, then you have one line per dependency, giving
-the repository URL and the commit number, tag or branch you want.</p></div>
-<div class="paragraph"><p>Then you can see two targets defined, with <code>release</code>
-becoming the default target, because it was defined first. You can
-override the default target <code>all</code>, which builds the
-application and its dependencies, this way.</p></div>
-<div class="paragraph"><p>And as you can see, the <code>release</code> target uses
-Relx to build a release into the <em>rel/ninenines/</em>
-directory. Let’s take a look at the configuration file for this release.</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt>{<span style="color: #FF6600">release</span>, {<span style="color: #FF6600">ninenines</span>, <span style="color: #FF0000">"1"</span>}, [<span style="color: #FF6600">ninenines</span>]}<span style="color: #990000">.</span>
-
-{<span style="color: #FF6600">extended_start_script</span>, <span style="color: #000080">true</span>}<span style="color: #990000">.</span>
-{<span style="color: #FF6600">sys_config</span>, <span style="color: #FF0000">"rel/sys.config"</span>}<span style="color: #990000">.</span>
-
-{<span style="color: #FF6600">overlay</span>, [
- {<span style="color: #FF6600">mkdir</span>, <span style="color: #FF0000">"log"</span>},
- {<span style="color: #FF6600">copy</span>, <span style="color: #FF0000">"rel/vm.args"</span>,
- <span style="color: #FF0000">"releases/\{\{release_name\}\}-\{\{release_version\}\}/vm.args"</span>}
-]}<span style="color: #990000">.</span></tt></pre></div></div>
-<div class="paragraph"><p>The first line defines a release named <code>ninenines</code>, which
-has a version number <code>"1"</code> and includes one application, also
-named <code>ninenines</code>, although it doesn’t have to.</p></div>
-<div class="paragraph"><p>We then use the <code>extended_start_script</code> option to tell
-Relx that we would like to have a start script that allows
-us to not only start the release, but do so with the node in the
-background, or also to allow us to connect to a running node, and so on.
-This start script has the same features as the one tools like
-Rebar generates.</p></div>
-<div class="paragraph"><p>The rest of the file just makes sure our configuration files are
-where we expect them. Relx will automatically take care
-of your <em>sys.config</em> file as long as you tell it where to
-find it. The <em>vm.args</em> file used by the extended start script
-needs to be handled more explicitly by using an overlay however.</p></div>
-<div class="paragraph"><p>How does Relx find what applications to include?
-By looking at the application dependencies in the <em>.app</em>
-file of each OTP application. Make sure you put all dependencies in
-there, <em>including</em> library applications, and Relx
-will find everything for you.</p></div>
-<div class="paragraph"><p>For example, this release includes the following applications.
-Only what’s strictly required.</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><code>compiler-4.9.1 crypto-2.3 kernel-2.16.1 ranch-0.8.3 syntax_tools-1.6.11
-cowboy-0.8.5 erlydtl-0.7.0 ninenines-0.2.0 stdlib-1.19.1</code></pre>
-</div></div>
-<div class="paragraph"><p>The <em>sys.config</em> file is standard and
-<a href="http://www.erlang.org/doc/man/config.html">well documented</a>.
-The <em>vm.args</em> file is just an optionally multiline file
-containing all the flags to pass to the Erlang VM, for example
-<code>-name [email protected] -heart</code>.</p></div>
-<div class="paragraph"><p>Building OTP releases has always been a difficult task. Until now.</p></div>
+<div class="paragraph"><p>Building OTP releases has always been a difficult task. Tools like +Reltool or Rebar have made this simpler, but +it’s no panacea. This article will show you an alternative and +hopefully much simpler solution.</p></div> +<div class="paragraph"><p>There is two steps to building a release. First you need to build +the various OTP applications you want to include in the release. Once +done, you need to create the release itself, by including the Erlang +runtime system alongside the applications, a boot script to start the +node and all its applications, and some configuration files.</p></div> +<div class="paragraph"><p><a href="https://github.com/extend/erlang.mk">Erlang.mk</a> solves +the first step. It is an include file for GNU Make. Just +including it in a Makefile is enough to allow building your project, +fetching and building dependencies, building documentation, performing +static analysis and more.</p></div> +<div class="paragraph"><p><a href="https://github.com/erlware/relx">Relx</a> solves the second +step. It is a release creation tool, wrapped into a single executable +file. It doesn’t require a configuration file. And if you do need one, +it will be a pretty small one.</p></div> +<div class="paragraph"><p>Let’s take a look at the smallest Erlang.mk powered +Makefile. There is only one thing required: defining the project +name.</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="color: #009900">PROJECT =</span> my_project + +include erlang.mk</tt></pre></div></div> +<div class="paragraph"><p>Simply doing this allows you to build your application by typing +<code>make</code>, running tests using <code>make tests</code>, and +more. It will even compile your <em>.dtl</em> files found in the +<em>templates/</em> directory if you are using ErlyDTL!</p></div> +<div class="paragraph"><p>Let’s now take a look at a simplified version of the Makefile for +this website. I only removed a few targets that were off-topic.</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="color: #009900">PROJECT =</span> ninenines + +<span style="color: #009900">DEPS =</span> cowboy erlydtl +<span style="color: #009900">dep_cowboy_commit =</span> 0.8.5 +<span style="color: #009900">dep_erlydtl_commit =</span> 4d0dc8fb + +<span style="font-weight: bold"><span style="color: #000080">.PHONY:</span></span> release clean-release + +<span style="color: #990000">release:</span> clean-release all projects + relx -o rel<span style="color: #990000">/</span><span style="color: #009900">$(PROJECT)</span> + +<span style="color: #990000">clean-release:</span> clean-projects + rm -rf rel<span style="color: #990000">/</span><span style="color: #009900">$(PROJECT)</span> + +include erlang.mk</tt></pre></div></div> +<div class="paragraph"><p>You can see here how to define dependencies. First you list all +the dependency names, then you have one line per dependency, giving +the repository URL and the commit number, tag or branch you want.</p></div> +<div class="paragraph"><p>Then you can see two targets defined, with <code>release</code> +becoming the default target, because it was defined first. You can +override the default target <code>all</code>, which builds the +application and its dependencies, this way.</p></div> +<div class="paragraph"><p>And as you can see, the <code>release</code> target uses +Relx to build a release into the <em>rel/ninenines/</em> +directory. Let’s take a look at the configuration file for this release.</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt>{<span style="color: #FF6600">release</span>, {<span style="color: #FF6600">ninenines</span>, <span style="color: #FF0000">"1"</span>}, [<span style="color: #FF6600">ninenines</span>]}<span style="color: #990000">.</span> + +{<span style="color: #FF6600">extended_start_script</span>, <span style="color: #000080">true</span>}<span style="color: #990000">.</span> +{<span style="color: #FF6600">sys_config</span>, <span style="color: #FF0000">"rel/sys.config"</span>}<span style="color: #990000">.</span> + +{<span style="color: #FF6600">overlay</span>, [ + {<span style="color: #FF6600">mkdir</span>, <span style="color: #FF0000">"log"</span>}, + {<span style="color: #FF6600">copy</span>, <span style="color: #FF0000">"rel/vm.args"</span>, + <span style="color: #FF0000">"releases/\{\{release_name\}\}-\{\{release_version\}\}/vm.args"</span>} +]}<span style="color: #990000">.</span></tt></pre></div></div> +<div class="paragraph"><p>The first line defines a release named <code>ninenines</code>, which +has a version number <code>"1"</code> and includes one application, also +named <code>ninenines</code>, although it doesn’t have to.</p></div> +<div class="paragraph"><p>We then use the <code>extended_start_script</code> option to tell +Relx that we would like to have a start script that allows +us to not only start the release, but do so with the node in the +background, or also to allow us to connect to a running node, and so on. +This start script has the same features as the one tools like +Rebar generates.</p></div> +<div class="paragraph"><p>The rest of the file just makes sure our configuration files are +where we expect them. Relx will automatically take care +of your <em>sys.config</em> file as long as you tell it where to +find it. The <em>vm.args</em> file used by the extended start script +needs to be handled more explicitly by using an overlay however.</p></div> +<div class="paragraph"><p>How does Relx find what applications to include? +By looking at the application dependencies in the <em>.app</em> +file of each OTP application. Make sure you put all dependencies in +there, <em>including</em> library applications, and Relx +will find everything for you.</p></div> +<div class="paragraph"><p>For example, this release includes the following applications. +Only what’s strictly required.</p></div> +<div class="listingblock"> +<div class="content"> +<pre><code>compiler-4.9.1 crypto-2.3 kernel-2.16.1 ranch-0.8.3 syntax_tools-1.6.11 +cowboy-0.8.5 erlydtl-0.7.0 ninenines-0.2.0 stdlib-1.19.1</code></pre> +</div></div> +<div class="paragraph"><p>The <em>sys.config</em> file is standard and +<a href="http://www.erlang.org/doc/man/config.html">well documented</a>. +The <em>vm.args</em> file is just an optionally multiline file +containing all the flags to pass to the Erlang VM, for example +<code>-name [email protected] -heart</code>.</p></div> +<div class="paragraph"><p>Building OTP releases has always been a difficult task. Until now.</p></div> </article> </div> @@ -170,55 +194,107 @@ containing all the flags to pass to the Erlang VM, for example <h3>More articles</h3> <ul id="articles-nav" class="extra_margin"> - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + + + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + + <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + - <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + + <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + - <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + + <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + - <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + + <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + - <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + + <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + - <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + + <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + - <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + + <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + - <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + + <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + - <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + + <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + - <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + + <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + - <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + </ul> diff --git a/articles/erlanger-playbook-september-2015-update/index.html b/articles/erlanger-playbook-september-2015-update/index.html index 355e1d4f..64b2d558 100644 --- a/articles/erlanger-playbook-september-2015-update/index.html +++ b/articles/erlanger-playbook-september-2015-update/index.html @@ -7,7 +7,7 @@ <meta name="description" content=""> <meta name="author" content="Loïc Hoguin based on a design from (Soft10) Pol Cámara"> - <meta name="generator" content="Hugo 0.17" /> + <meta name="generator" content="Hugo 0.26" /> <title>Nine Nines: The Erlanger Playbook September 2015 Update</title> @@ -74,19 +74,19 @@ </p> </header> -<div class="paragraph"><p>An update to The Erlanger Playbook is now available!</p></div>
-<div class="paragraph"><p>The Erlanger Playbook is a book about software development using
-Erlang. It currently covers all areas from the conception, design,
-the writing of code, documentation and tests.</p></div>
-<div class="paragraph"><p>The book is still a work in progress. Future topics will include
-refactoring, debugging and tracing, benchmarking, releases, community
-management (for open source projects).</p></div>
-<div class="paragraph"><p>This update fixes a number of things and adds two chapters: IOlists
-and Erlang building blocks.</p></div>
-<div class="paragraph"><p>Learn more about <a href="/articles/erlanger-playbook">The Erlanger Playbook</a>!</p></div>
-<div class="paragraph"><p>This is a self-published ebook. The base price is 50€. All proceeds
-will be used to allow me to work on open source full time.</p></div>
-<div class="paragraph"><p>Thank you for helping me helping you help us all!</p></div>
+<div class="paragraph"><p>An update to The Erlanger Playbook is now available!</p></div> +<div class="paragraph"><p>The Erlanger Playbook is a book about software development using +Erlang. It currently covers all areas from the conception, design, +the writing of code, documentation and tests.</p></div> +<div class="paragraph"><p>The book is still a work in progress. Future topics will include +refactoring, debugging and tracing, benchmarking, releases, community +management (for open source projects).</p></div> +<div class="paragraph"><p>This update fixes a number of things and adds two chapters: IOlists +and Erlang building blocks.</p></div> +<div class="paragraph"><p>Learn more about <a href="/articles/erlanger-playbook">The Erlanger Playbook</a>!</p></div> +<div class="paragraph"><p>This is a self-published ebook. The base price is 50€. All proceeds +will be used to allow me to work on open source full time.</p></div> +<div class="paragraph"><p>Thank you for helping me helping you help us all!</p></div> </article> </div> @@ -95,55 +95,107 @@ will be used to allow me to work on open source full time.</p></div> <h3>More articles</h3> <ul id="articles-nav" class="extra_margin"> - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + - <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + + <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + - <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + + <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + - <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + + <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + - <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + + <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + - <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + + <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + - <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + + <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + - <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + + <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + - <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + + <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + - <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + + <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + - <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + + <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + + + </ul> diff --git a/articles/erlanger-playbook/index.html b/articles/erlanger-playbook/index.html index cc6bd1fa..7d50cff8 100644 --- a/articles/erlanger-playbook/index.html +++ b/articles/erlanger-playbook/index.html @@ -7,7 +7,7 @@ <meta name="description" content=""> <meta name="author" content="Loïc Hoguin based on a design from (Soft10) Pol Cámara"> - <meta name="generator" content="Hugo 0.17" /> + <meta name="generator" content="Hugo 0.26" /> <title>Nine Nines: The Erlanger Playbook</title> @@ -74,87 +74,87 @@ </p> </header> -<div class="paragraph"><p>I am proud to announce the pre-release of The Erlanger Playbook.</p></div>
-<div class="paragraph"><p>The Erlanger Playbook is a book about software development using
-Erlang. It currently covers all areas from the conception, design,
-the writing of code, documentation and tests.</p></div>
-<div class="paragraph"><p>The book is still a work in progress. Future topics will include
-refactoring, debugging and tracing, benchmarking, releases, community
-management (for open source projects).</p></div>
-<div class="paragraph"><p>The following sections are currently available:</p></div>
-<div class="ulist"><ul>
-<li>
-<p>
-About this book; Changelog; Future additions
-</p>
-</li>
-<li>
-<p>
-<em>Erlang:</em> Building blocks; Patterns
-</p>
-</li>
-<li>
-<p>
-<em>Workflow:</em> Think; Write; Stay productive
-</p>
-</li>
-<li>
-<p>
-<em>Documentation:</em> On documentation; Tutorials; User guide; Manual; README files
-</p>
-</li>
-<li>
-<p>
-<em>Design:</em> RESTful APIs; Lessons learned
-</p>
-</li>
-<li>
-<p>
-<em>Code:</em> Starting a project; Version control; Project structure; Code style; Best practices; Special processes; IOLists; The process dictionary
-</p>
-</li>
-<li>
-<p>
-<em>Tests:</em> On testing; Success typing analysis; Manual testing; Unit testing; Functional testing
-</p>
-</li>
-<li>
-<p>
-<em>Selling Erlang:</em> On persuasion; Don’t let it crash
-</p>
-</li>
-</ul></div>
-<div class="paragraph"><p>Read a preview: <a href="/res/erlanger-preview.pdf">Special processes</a></p></div>
-<div class="paragraph"><p>The book is currently 180 pages long. The final version
-of the book is planned to be between 200 and 250 pages.
-A print version of the book will be considered once the final
-version gets released. The printed book is <strong>not</strong> included
-in the price.</p></div>
-<div class="paragraph"><p>This is a self-published book. The base price is 50€. All proceeds
-will be used to allow me to work on open source full time.</p></div>
-<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
-<input type="hidden" name="cmd" value="_s-xclick">
-<input type="hidden" name="hosted_button_id" value="9M44HJCGX3GVN">
-<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
-<img alt="" border="0" src="https://www.paypalobjects.com/fr_FR/i/scr/pixel.gif" width="1" height="1">
-</form>
-<div class="paragraph"><p>You are more than welcome to pay extra by using this second button.
-It allows you to set the price you want. Make sure to set it to at least
-50€ to receive the book.</p></div>
-<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
-<input type="hidden" name="cmd" value="_s-xclick">
-<input type="hidden" name="hosted_button_id" value="BBW9TR9LBK8C2">
-<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
-<img alt="" border="0" src="https://www.paypalobjects.com/fr_FR/i/scr/pixel.gif" width="1" height="1">
-</form>
-<div class="paragraph"><p>Make sure to provide a valid email address.</p></div>
-<div class="paragraph"><p>There will be a <strong>delay</strong> between payment and sending of the book.
-This process is currently manual.</p></div>
-<div class="paragraph"><p>As the book is a pre-release, feedback is more than welcome. You can
-send your comments to erlanger@ this website.</p></div>
-<div class="paragraph"><p>The plan is to add content regularly until I run out of things to say.
-You will receive updates to the book for free as soon as they are available.</p></div>
-<div class="paragraph"><p>Huge thanks for your interest in buying this book!</p></div>
+<div class="paragraph"><p>I am proud to announce the pre-release of The Erlanger Playbook.</p></div> +<div class="paragraph"><p>The Erlanger Playbook is a book about software development using +Erlang. It currently covers all areas from the conception, design, +the writing of code, documentation and tests.</p></div> +<div class="paragraph"><p>The book is still a work in progress. Future topics will include +refactoring, debugging and tracing, benchmarking, releases, community +management (for open source projects).</p></div> +<div class="paragraph"><p>The following sections are currently available:</p></div> +<div class="ulist"><ul> +<li> +<p> +About this book; Changelog; Future additions +</p> +</li> +<li> +<p> +<em>Erlang:</em> Building blocks; Patterns +</p> +</li> +<li> +<p> +<em>Workflow:</em> Think; Write; Stay productive +</p> +</li> +<li> +<p> +<em>Documentation:</em> On documentation; Tutorials; User guide; Manual; README files +</p> +</li> +<li> +<p> +<em>Design:</em> RESTful APIs; Lessons learned +</p> +</li> +<li> +<p> +<em>Code:</em> Starting a project; Version control; Project structure; Code style; Best practices; Special processes; IOLists; The process dictionary +</p> +</li> +<li> +<p> +<em>Tests:</em> On testing; Success typing analysis; Manual testing; Unit testing; Functional testing +</p> +</li> +<li> +<p> +<em>Selling Erlang:</em> On persuasion; Don’t let it crash +</p> +</li> +</ul></div> +<div class="paragraph"><p>Read a preview: <a href="/res/erlanger-preview.pdf">Special processes</a></p></div> +<div class="paragraph"><p>The book is currently 180 pages long. The final version +of the book is planned to be between 200 and 250 pages. +A print version of the book will be considered once the final +version gets released. The printed book is <strong>not</strong> included +in the price.</p></div> +<div class="paragraph"><p>This is a self-published book. The base price is 50€. All proceeds +will be used to allow me to work on open source full time.</p></div> +<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top"> +<input type="hidden" name="cmd" value="_s-xclick"> +<input type="hidden" name="hosted_button_id" value="9M44HJCGX3GVN"> +<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"> +<img alt="" border="0" src="https://www.paypalobjects.com/fr_FR/i/scr/pixel.gif" width="1" height="1"> +</form> +<div class="paragraph"><p>You are more than welcome to pay extra by using this second button. +It allows you to set the price you want. Make sure to set it to at least +50€ to receive the book.</p></div> +<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top"> +<input type="hidden" name="cmd" value="_s-xclick"> +<input type="hidden" name="hosted_button_id" value="BBW9TR9LBK8C2"> +<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"> +<img alt="" border="0" src="https://www.paypalobjects.com/fr_FR/i/scr/pixel.gif" width="1" height="1"> +</form> +<div class="paragraph"><p>Make sure to provide a valid email address.</p></div> +<div class="paragraph"><p>There will be a <strong>delay</strong> between payment and sending of the book. +This process is currently manual.</p></div> +<div class="paragraph"><p>As the book is a pre-release, feedback is more than welcome. You can +send your comments to erlanger@ this website.</p></div> +<div class="paragraph"><p>The plan is to add content regularly until I run out of things to say. +You will receive updates to the book for free as soon as they are available.</p></div> +<div class="paragraph"><p>Huge thanks for your interest in buying this book!</p></div> </article> </div> @@ -163,55 +163,107 @@ You will receive updates to the book for free as soon as they are available.</p> <h3>More articles</h3> <ul id="articles-nav" class="extra_margin"> - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + - <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + + <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + - <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + + <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + - <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + + <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + - <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + + <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + - <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + + <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + - <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + + <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + - <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + + <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + - <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + + <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + - <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + + <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + - <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + + <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + + + </ul> diff --git a/articles/farwest-funded/index.html b/articles/farwest-funded/index.html index a3280216..c36a91d8 100644 --- a/articles/farwest-funded/index.html +++ b/articles/farwest-funded/index.html @@ -7,7 +7,7 @@ <meta name="description" content=""> <meta name="author" content="Loïc Hoguin based on a design from (Soft10) Pol Cámara"> - <meta name="generator" content="Hugo 0.17" /> + <meta name="generator" content="Hugo 0.26" /> <title>Nine Nines: Farwest got funded!</title> @@ -74,27 +74,27 @@ </p> </header> -<div class="paragraph"><p>This was a triumph! I’m making a note here: HUGE SUCCESS!!</p></div>
-<iframe frameborder="0" scrolling="no" height="400px" width"236px" seamless="seamless" src="https://api.bountysource.com/user/fundraisers/83/embed"></iframe>
-<div class="paragraph"><p>It’s hard to overstate my satisfaction. Thanks to everyone who
-made this possible.</p></div>
-<div class="paragraph"><p>If you have backed this fundraiser, and haven’t provided your
-personal details yet, please do so quickly so that your rewards
-can be sent!</p></div>
-<div class="paragraph"><p>I am hoping that we will be able to make good use of all that
-money. The details of the expenses will be published regularly
-on the <a href="https://github.com/extend/farwest/wiki/2013-Fundraiser">2013 Fundraiser wiki page</a>,
-giving you full disclosure as to how your money is used.</p></div>
-<div class="paragraph"><p>It will take a little time to get things started, we are in
-summer after all! We will however act quickly to make the
-prototype easy enough to use so that the paid UI work can
-begin. This is also when user contributions will be welcome.</p></div>
-<div class="paragraph"><p>You can see the <a href="https://github.com/extend/farwest/wiki/Roadmap">Roadmap</a>
-to get more information on the current plans. This document will
-get updated as time goes on so check again later to see if you
-can help!</p></div>
-<div class="paragraph"><p>Look at me: still talking when there’s open source to do!</p></div>
-<div class="paragraph"><p>Thanks again for all your support. I really appreciate it.</p></div>
+<div class="paragraph"><p>This was a triumph! I’m making a note here: HUGE SUCCESS!!</p></div> +<iframe frameborder="0" scrolling="no" height="400px" width"236px" seamless="seamless" src="https://api.bountysource.com/user/fundraisers/83/embed"></iframe> +<div class="paragraph"><p>It’s hard to overstate my satisfaction. Thanks to everyone who +made this possible.</p></div> +<div class="paragraph"><p>If you have backed this fundraiser, and haven’t provided your +personal details yet, please do so quickly so that your rewards +can be sent!</p></div> +<div class="paragraph"><p>I am hoping that we will be able to make good use of all that +money. The details of the expenses will be published regularly +on the <a href="https://github.com/extend/farwest/wiki/2013-Fundraiser">2013 Fundraiser wiki page</a>, +giving you full disclosure as to how your money is used.</p></div> +<div class="paragraph"><p>It will take a little time to get things started, we are in +summer after all! We will however act quickly to make the +prototype easy enough to use so that the paid UI work can +begin. This is also when user contributions will be welcome.</p></div> +<div class="paragraph"><p>You can see the <a href="https://github.com/extend/farwest/wiki/Roadmap">Roadmap</a> +to get more information on the current plans. This document will +get updated as time goes on so check again later to see if you +can help!</p></div> +<div class="paragraph"><p>Look at me: still talking when there’s open source to do!</p></div> +<div class="paragraph"><p>Thanks again for all your support. I really appreciate it.</p></div> </article> </div> @@ -103,55 +103,107 @@ can help!</p></div> <h3>More articles</h3> <ul id="articles-nav" class="extra_margin"> - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + - <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + + <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + - <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + + <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + - <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + + <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + - <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + + <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + - <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + + <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + - <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + + <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + - <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + + <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + - <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + + <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + - <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + + <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + - <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + + <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + + + </ul> diff --git a/articles/index.html b/articles/index.html index dc52f5d1..ebc2bff4 100644 --- a/articles/index.html +++ b/articles/index.html @@ -7,7 +7,7 @@ <meta name="description" content=""> <meta name="author" content="Loïc Hoguin based on a design from (Soft10) Pol Cámara"> - <meta name="generator" content="Hugo 0.17" /> + <meta name="generator" content="Hugo 0.26" /> <title>Nine Nines: Articles</title> @@ -80,9 +80,9 @@ </header> <p>Cowboy 2.0.0-rc.2 has been released! -
This is the new recommended version of Cowboy.
Its API should not change before release. While
you probably should not use it in production yet,
many do successfully. Use at your own risk. -
This new version contains fixes for the following
issues: -
HTTP/2 server push was using the wrong header
compression context.
HTTP/2 flow control could end up queueing data
in the wrong order when resuming the sending of
data.</p> + This is the new recommended version of Cowboy. Its API should not change before release. While you probably should not use it in production yet, many do successfully. Use at your own risk. + This new version contains fixes for the following issues: + HTTP/2 server push was using the wrong header compression context. HTTP/2 flow control could end up queueing data in the wrong order when resuming the sending of data.</p> <p style="text-align:right"> <a class="read_more" href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Read More</a> @@ -99,8 +99,8 @@ </header> <p>Cowboy 2.0.0-rc.1 has been released! -
This is the new recommended version of Cowboy.
Its API should not change before release. While
you probably should not use it in production yet,
many do successfully. Use at your own risk. -
The plan is to have a new RC version every couple
weeks until the summer ends or later if there are
still blocking issues open. Only issues that can’t
be fixed without making breaking changes to the
interface may block the release.</p> + This is the new recommended version of Cowboy. Its API should not change before release. While you probably should not use it in production yet, many do successfully. Use at your own risk. + The plan is to have a new RC version every couple weeks until the summer ends or later if there are still blocking issues open. Only issues that can’t be fixed without making breaking changes to the interface may block the release.</p> <p style="text-align:right"> <a class="read_more" href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Read More</a> @@ -116,8 +116,8 @@ </p> </header> - <p>Have you ever tried telling someone why they should use
Erlang? You boast the smaller code size, the auto healing
mechanisms, the distribution and they seem really excited.
They wonder why they never heard about Erlang before. And
then you show them what the code looks like. All excitement
goes away. The smiles disappear. Their face starts
becoming really serious. -
You lost them. You know you lost them. They comment on the
syntax, or perhaps you do, already admitting defeat.</p> + <p>Have you ever tried telling someone why they should use Erlang? You boast the smaller code size, the auto healing mechanisms, the distribution and they seem really excited. They wonder why they never heard about Erlang before. And then you show them what the code looks like. All excitement goes away. The smiles disappear. Their face starts becoming really serious. + You lost them. You know you lost them. They comment on the syntax, or perhaps you do, already admitting defeat.</p> <p style="text-align:right"> <a class="read_more" href="https://ninenines.eu/articles/the-elephant-in-the-room/">Read More</a> @@ -133,8 +133,8 @@ </p> </header> - <p>We have a specific mindset when writing Erlang
programs. We focus on the normal execution of the
program and don’t handle most of the errors that may
occur. We sometimes call this normal execution the
happy path. -
The general pattern behind writing only for the
happy path, letting the VM catch errors (writing
them to a log for future consumption) and then
having a supervisor restart the processes that
failed from a clean state, has a name.</p> + <p>We have a specific mindset when writing Erlang programs. We focus on the normal execution of the program and don’t handle most of the errors that may occur. We sometimes call this normal execution the happy path. + The general pattern behind writing only for the happy path, letting the VM catch errors (writing them to a log for future consumption) and then having a supervisor restart the processes that failed from a clean state, has a name.</p> <p style="text-align:right"> <a class="read_more" href="https://ninenines.eu/articles/dont-let-it-crash/">Read More</a> @@ -151,9 +151,9 @@ </header> <p>Cowboy 2.0.0-pre.4 has been released! -
This is the new recommended version of Cowboy.
While I would not recommend putting it in production
just yet, I do recommend you start writing new
applications with this Cowboy version. -
The most significant changes in the pre-release are: -
A new architecture: there now is one process per
connection and one process per request. This was
done because HTTP/2 allows running requests concurrently.</p> + This is the new recommended version of Cowboy. While I would not recommend putting it in production just yet, I do recommend you start writing new applications with this Cowboy version. + The most significant changes in the pre-release are: + A new architecture: there now is one process per connection and one process per request. This was done because HTTP/2 allows running requests concurrently.</p> <p style="text-align:right"> <a class="read_more" href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Read More</a> @@ -170,8 +170,8 @@ </header> <p>Ranch 1.3.0 has been released! -
This release fixes a number of long standing issues and adds
a small number of features: -
The ssl application has been added to the list of dependencies.
If you don’t need it, you can remove it automatically when fetching
Ranch or when building the release. If you do need it, you will no
longer have issues shutting down a node because of Ranch.</p> + This release fixes a number of long standing issues and adds a small number of features: + The ssl application has been added to the list of dependencies. If you don’t need it, you can remove it automatically when fetching Ranch or when building the release. If you do need it, you will no longer have issues shutting down a node because of Ranch.</p> <p style="text-align:right"> <a class="read_more" href="https://ninenines.eu/articles/ranch-1.3/">Read More</a> @@ -187,10 +187,10 @@ </p> </header> - <p>The old mailing list archives have been
added to the site, mainly for referencing purposes. -
The mailing list has been shut down and all personal information
has been deleted. -
If you need help with a project, consider either opening a ticket
on that project’s issues tracker or going through the community
channels (erlang-questions, #ninenines or #erlang on Freenode). -
Prefer tickets; often when people have issues it highlights an
underlying problem in the project or its documentation.</p> + <p>The old mailing list archives have been added to the site, mainly for referencing purposes. + The mailing list has been shut down and all personal information has been deleted. + If you need help with a project, consider either opening a ticket on that project’s issues tracker or going through the community channels (erlang-questions, #ninenines or #erlang on Freenode). + Prefer tickets; often when people have issues it highlights an underlying problem in the project or its documentation.</p> <p style="text-align:right"> <a class="read_more" href="https://ninenines.eu/articles/ml-archives/">Read More</a> @@ -207,8 +207,8 @@ </header> <p>Last week-end I updated the Nine Nines website. -
I switched to Hugo. The site is
now built from Asciidoc
documents. You probably saw me switch to Asciidoc
for documentation this past year. This is the
natural conclusion to that story. The great thing
is that with a little bit of Makefile magic I can
just copy the documentation files into Hugo and
poof, they appear on the website. -
I am very happy with that new setup.</p> + I switched to Hugo. The site is now built from Asciidoc documents. You probably saw me switch to Asciidoc for documentation this past year. This is the natural conclusion to that story. The great thing is that with a little bit of Makefile magic I can just copy the documentation files into Hugo and poof, they appear on the website. + I am very happy with that new setup.</p> <p style="text-align:right"> <a class="read_more" href="https://ninenines.eu/articles/website-update/">Read More</a> @@ -225,9 +225,9 @@ </header> <p>An update to The Erlanger Playbook is now available! -
The Erlanger Playbook is a book about software development using
Erlang. It currently covers all areas from the conception, design,
the writing of code, documentation and tests. -
The book is still a work in progress. Future topics will include
refactoring, debugging and tracing, benchmarking, releases, community
management (for open source projects). -
This update fixes a number of things and adds two chapters: IOlists
and Erlang building blocks.</p> + The Erlanger Playbook is a book about software development using Erlang. It currently covers all areas from the conception, design, the writing of code, documentation and tests. + The book is still a work in progress. Future topics will include refactoring, debugging and tracing, benchmarking, releases, community management (for open source projects). + This update fixes a number of things and adds two chapters: IOlists and Erlang building blocks.</p> <p style="text-align:right"> <a class="read_more" href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">Read More</a> @@ -244,9 +244,9 @@ </header> <p>I am proud to announce the pre-release of The Erlanger Playbook. -
The Erlanger Playbook is a book about software development using
Erlang. It currently covers all areas from the conception, design,
the writing of code, documentation and tests. -
The book is still a work in progress. Future topics will include
refactoring, debugging and tracing, benchmarking, releases, community
management (for open source projects). -
The following sections are currently available:</p> + The Erlanger Playbook is a book about software development using Erlang. It currently covers all areas from the conception, design, the writing of code, documentation and tests. + The book is still a work in progress. Future topics will include refactoring, debugging and tracing, benchmarking, releases, community management (for open source projects). + The following sections are currently available:</p> <p style="text-align:right"> <a class="read_more" href="https://ninenines.eu/articles/erlanger-playbook/">Read More</a> @@ -262,9 +262,9 @@ </p> </header> - <p>Yesterday I pushed Websocket permessage-deflate to
Cowboy master. I also pushed
a
change in the way the code validates UTF-8 data
(required for text and close frames as per the spec). -
When looking into why the permessage-deflate tests
in autobahntestsuite were taking such a long time, I
found that autobahn is using an adaptation of the
algorithm named Flexible
and Economical UTF-8 Decoder. This is the C99
implementation: -
// Copyright (c) 2008-2009 Bjoern Hoehrmann <bjoern@hoehrmann.</p> + <p>Yesterday I pushed Websocket permessage-deflate to Cowboy master. I also pushed a change in the way the code validates UTF-8 data (required for text and close frames as per the spec). + When looking into why the permessage-deflate tests in autobahntestsuite were taking such a long time, I found that autobahn is using an adaptation of the algorithm named Flexible and Economical UTF-8 Decoder. This is the C99 implementation: + // Copyright (c) 2008-2009 Bjoern Hoehrmann <bjoern@hoehrmann.</p> <p style="text-align:right"> <a class="read_more" href="https://ninenines.eu/articles/erlang-validate-utf8/">Read More</a> @@ -280,7 +280,7 @@ </p> </header> - <p>Last week I read a great article
on
contributing to open source by Alvaro Videla. He makes
many great points and I am in agreement with most of it.
This made me want to properly explain my point of view with
regard to open source and contributions. Unlike most open
source evangelism articles I will not talk about ideals or
any of that crap, but rather my personal feelings and
experience.</p> + <p>Last week I read a great article on contributing to open source by Alvaro Videla. He makes many great points and I am in agreement with most of it. This made me want to properly explain my point of view with regard to open source and contributions. Unlike most open source evangelism articles I will not talk about ideals or any of that crap, but rather my personal feelings and experience.</p> <p style="text-align:right"> <a class="read_more" href="https://ninenines.eu/articles/on-open-source/">Read More</a> @@ -296,7 +296,7 @@ </p> </header> - <p>As I am away from home with little to do (some call this
a vacation) I wanted to reflect a little on the story so far,
or how I arrived to Erlang and got to where I am now. The
raw personal experience. It’ll be an article that’s more
about social aspect, communities and marketing a project than
technical considerations. As a period piece, it will also
allow me to reflect on the evolution of Erlang in recent
years.</p> + <p>As I am away from home with little to do (some call this a vacation) I wanted to reflect a little on the story so far, or how I arrived to Erlang and got to where I am now. The raw personal experience. It’ll be an article that’s more about social aspect, communities and marketing a project than technical considerations. As a period piece, it will also allow me to reflect on the evolution of Erlang in recent years.</p> <p style="text-align:right"> <a class="read_more" href="https://ninenines.eu/articles/the-story-so-far/">Read More</a> @@ -312,8 +312,8 @@ </p> </header> - <p>Now that Cowboy 1.0 is out, I can spend some of my time thinking
about Cowboy 2.0 that will be released soon after Erlang/OTP 18.0.
This entry discusses the proposed changes to query string handling
in Cowboy. -
Cowboy 2.0 will respond to user wishes by simplifying the interface
of the cowboy_req module. Users want two things: less
juggling with the Req variable, and more maps. Maps is the only
dynamic key/value data structure in Erlang that we can match directly
to extract values, allowing users to greatly simplify their code as
they don’t need to call functions to do everything anymore.</p> + <p>Now that Cowboy 1.0 is out, I can spend some of my time thinking about Cowboy 2.0 that will be released soon after Erlang/OTP 18.0. This entry discusses the proposed changes to query string handling in Cowboy. + Cowboy 2.0 will respond to user wishes by simplifying the interface of the cowboy_req module. Users want two things: less juggling with the Req variable, and more maps. Maps is the only dynamic key/value data structure in Erlang that we can match directly to extract values, allowing users to greatly simplify their code as they don’t need to call functions to do everything anymore.</p> <p style="text-align:right"> <a class="read_more" href="https://ninenines.eu/articles/cowboy2-qs/">Read More</a> @@ -329,9 +329,9 @@ </p> </header> - <p>I will now be regularly writing posts about project status, plans
and hopes for the future. -
Before that though, there’s one important news to share. -
Until a year ago all development was financed through consulting
and development services. This worked alright but too much time was
spent doing things that didn’t benefit the open source projects.
And that didn’t make me happy at all. Because I like being happy
I stopped that for the most part and spent the year figuring things
out, experimenting and discussing with people about it.</p> + <p>I will now be regularly writing posts about project status, plans and hopes for the future. + Before that though, there’s one important news to share. + Until a year ago all development was financed through consulting and development services. This worked alright but too much time was spent doing things that didn’t benefit the open source projects. And that didn’t make me happy at all. Because I like being happy I stopped that for the most part and spent the year figuring things out, experimenting and discussing with people about it.</p> <p style="text-align:right"> <a class="read_more" href="https://ninenines.eu/articles/january-2014-status/">Read More</a> @@ -348,9 +348,9 @@ </header> <p>This was a triumph! I’m making a note here: HUGE SUCCESS!! -
It’s hard to overstate my satisfaction. Thanks to everyone who
made this possible. -
If you have backed this fundraiser, and haven’t provided your
personal details yet, please do so quickly so that your rewards
can be sent! -
I am hoping that we will be able to make good use of all that
money. The details of the expenses will be published regularly
on the 2013 Fundraiser wiki page,
giving you full disclosure as to how your money is used.</p> + It’s hard to overstate my satisfaction. Thanks to everyone who made this possible. + If you have backed this fundraiser, and haven’t provided your personal details yet, please do so quickly so that your rewards can be sent! + I am hoping that we will be able to make good use of all that money. The details of the expenses will be published regularly on the 2013 Fundraiser wiki page, giving you full disclosure as to how your money is used.</p> <p style="text-align:right"> <a class="read_more" href="https://ninenines.eu/articles/farwest-funded/">Read More</a> @@ -366,8 +366,8 @@ </p> </header> - <p>Building OTP releases has always been a difficult task. Tools like
Reltool or Rebar have made this simpler, but
it’s no panacea. This article will show you an alternative and
hopefully much simpler solution. -
There is two steps to building a release. First you need to build
the various OTP applications you want to include in the release. Once
done, you need to create the release itself, by including the Erlang
runtime system alongside the applications, a boot script to start the
node and all its applications, and some configuration files.</p> + <p>Building OTP releases has always been a difficult task. Tools like Reltool or Rebar have made this simpler, but it’s no panacea. This article will show you an alternative and hopefully much simpler solution. + There is two steps to building a release. First you need to build the various OTP applications you want to include in the release. Once done, you need to create the release itself, by including the Erlang runtime system alongside the applications, a boot script to start the node and all its applications, and some configuration files.</p> <p style="text-align:right"> <a class="read_more" href="https://ninenines.eu/articles/erlang.mk-and-relx/">Read More</a> @@ -383,9 +383,9 @@ </p> </header> - <p>Today we will start the work on the intermediate module
that will be used to run the code for the expressions found
in our file’s body, replacing our interpreter. -
This is what we want to have when all the work is done: -
xerl -> tokens -> AST -> intermediate -> cerl
Today we will perform this work only on the atomic integer
expression however, so we will not build any module at the end.</p> + <p>Today we will start the work on the intermediate module that will be used to run the code for the expressions found in our file’s body, replacing our interpreter. + This is what we want to have when all the work is done: + xerl -> tokens -> AST -> intermediate -> cerl Today we will perform this work only on the atomic integer expression however, so we will not build any module at the end.</p> <p style="text-align:right"> <a class="read_more" href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Read More</a> @@ -401,10 +401,10 @@ </p> </header> - <p>As promised we are adding an expression separator this time.
This will be short and easy. -
In the tokenizer we only need to add a line recognizing the
comma as a valid token. -
, : {token, {',', TokenLine}}.
Then we need to change the following lines in the parser: -
exprs -> expr : ['$1'].
exprs -> expr exprs : ['$1' | '$2'].
And add a comma between the expressions on the second line:</p> + <p>As promised we are adding an expression separator this time. This will be short and easy. + In the tokenizer we only need to add a line recognizing the comma as a valid token. + , : {token, {',', TokenLine}}. Then we need to change the following lines in the parser: + exprs -> expr : ['$1']. exprs -> expr exprs : ['$1' | '$2']. And add a comma between the expressions on the second line:</p> <p style="text-align:right"> <a class="read_more" href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Read More</a> @@ -420,8 +420,8 @@ </p> </header> - <p>I would like to share some experience and theories on
Erlang scalability. -
This will be in the form of a series of hints, which
may or may not be accompanied with explanations as to why
things are this way, or how they improve or reduce the scalability
of a system. I will try to do my best to avoid giving falsehoods,
even if that means a few things won’t be explained.</p> + <p>I would like to share some experience and theories on Erlang scalability. + This will be in the form of a series of hints, which may or may not be accompanied with explanations as to why things are this way, or how they improve or reduce the scalability of a system. I will try to do my best to avoid giving falsehoods, even if that means a few things won’t be explained.</p> <p style="text-align:right"> <a class="read_more" href="https://ninenines.eu/articles/erlang-scalability/">Read More</a> diff --git a/articles/index.xml b/articles/index.xml index 57beccf0..249e5d71 100644 --- a/articles/index.xml +++ b/articles/index.xml @@ -1,13 +1,15 @@ <?xml version="1.0" encoding="utf-8" standalone="yes" ?> <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> <channel> - <title>Articles-rsses on Nine Nines</title> - <link>https://ninenines.eu/articles/index.xml</link> - <description>Recent content in Articles-rsses on Nine Nines</description> + <title>Articles on Nine Nines</title> + <link>https://ninenines.eu/articles/</link> + <description>Recent content in Articles on Nine Nines</description> <generator>Hugo -- gohugo.io</generator> <language>en-us</language> <lastBuildDate>Wed, 23 Aug 2017 18:00:00 +0100</lastBuildDate> - <atom:link href="https://ninenines.eu/articles/index.xml" rel="self" type="application/rss+xml" /> + + <atom:link href="https://ninenines.eu/articles/index.xml" rel="self" type="application/rss+xml" /> + <item> <title>Cowboy 2.0 release candidate 2</title> @@ -15,42 +17,10 @@ <pubDate>Wed, 23 Aug 2017 18:00:00 +0100</pubDate> <guid>https://ninenines.eu/articles/cowboy-2.0.0-rc.2/</guid> - <description><div class="paragraph"><p>Cowboy <code>2.0.0-rc.2</code> has been released!</p></div>
-<div class="paragraph"><p>This is the new recommended version of Cowboy.
-Its API should not change before release. While
-you probably should not use it in production yet,
-many do successfully. Use at your own risk.</p></div>
-<div class="paragraph"><p>This new version contains fixes for the following
-issues:</p></div>
-<div class="ulist"><ul>
-<li>
-<p>
-HTTP/2 server push was using the wrong header
- compression context.
-</p>
-</li>
-<li>
-<p>
-HTTP/2 flow control could end up queueing data
- in the wrong order when resuming the sending of
- data.
-</p>
-</li>
-<li>
-<p>
-The <code>shutdown</code> timeout was not implemented
- and request processes could be killed too quickly.
-</p>
-</li>
-</ul></div>
-<div class="paragraph"><p>What else is new in Cowboy 2.0? Check the
-<a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1">rc.1 announcement</a>.</p></div>
-<div class="paragraph"><p>Please test this new release candidate and provide
-feedback! The best place to provide feedback is via
-tickets. Do not hesitate to open a ticket or bring
-an existing ticket to my attention to get it resolved
-before 2.0.</p></div>
-</description> + <description>Cowboy 2.0.0-rc.2 has been released! + This is the new recommended version of Cowboy. Its API should not change before release. While you probably should not use it in production yet, many do successfully. Use at your own risk. + This new version contains fixes for the following issues: + HTTP/2 server push was using the wrong header compression context. HTTP/2 flow control could end up queueing data in the wrong order when resuming the sending of data.</description> </item> <item> @@ -59,63 +29,9 @@ before 2.0.</p></div> <pubDate>Mon, 24 Jul 2017 18:00:00 +0100</pubDate> <guid>https://ninenines.eu/articles/cowboy-2.0.0-rc.1/</guid> - <description><div class="paragraph"><p>Cowboy <code>2.0.0-rc.1</code> has been released!</p></div>
-<div class="paragraph"><p>This is the new recommended version of Cowboy.
-Its API should not change before release. While
-you probably should not use it in production yet,
-many do successfully. Use at your own risk.</p></div>
-<div class="paragraph"><p>The plan is to have a new RC version every couple
-weeks until the summer ends or later if there are
-still blocking issues open. Only issues that can&#8217;t
-be fixed without making breaking changes to the
-interface may block the release.</p></div>
-<div class="paragraph"><p>Numerous changes were made since Cowboy 1.0. The
-one most people care about is probably HTTP/2, but
-it&#8217;s most likely not the only one worthwhile. The
-full list of changes (excluding types) can be found
-in the user guide chapter
-<a href="https://ninenines.eu/docs/en/cowboy/2.0/guide/migrating_from_1.0/">Migrating from Cowboy 1.0 to 2.0</a>.</p></div>
-<div class="paragraph"><p>As this is not the full release just yet, please pay
-extra attention to details and report anything
-suspicious you find.</p></div>
-<div class="paragraph"><p>There are still some tests failing. Most of those are
-related to standards that are not being followed perfectly
-just yet. Some of those will probably not be fixed before
-Cowboy 2.0 is released. They are edge cases and should not
-prevent interoperability.</p></div>
-<div class="paragraph"><p>The manual received a lot of love. It now has one page per
-function with a detailed description, arguments list, return
-value, changelog and examples. It also links to the other
-relevant manual pages: <a href="https://ninenines.eu/docs/en/cowboy/2.0/manual/">https://ninenines.eu/docs/en/cowboy/2.0/manual/</a></p></div>
-<div class="paragraph"><p>Cowboy is now tested and supported with Erlang/OTP 19.0 or above
-on Arch Linux, FreeBSD, OSX, Ubuntu and Windows 7. Contact me
-if you can provide permanent access to another platform for the
-purposes of testing.</p></div>
-<div class="paragraph"><p>Cowboy is now available from four locations:</p></div>
-<div class="ulist"><ul>
-<li>
-<p>
-<a href="https://git.ninenines.eu/cowboy.git">https://git.ninenines.eu/cowboy.git</a>
-</p>
-</li>
-<li>
-<p>
-<a href="https://github.com/ninenines/cowboy.git">https://github.com/ninenines/cowboy.git</a>
-</p>
-</li>
-<li>
-<p>
-<a href="https://bitbucket.org/ninenines/cowboy.git">https://bitbucket.org/ninenines/cowboy.git</a>
-</p>
-</li>
-<li>
-<p>
-<a href="https://gitlab.com/ninenines/cowboy.git">https://gitlab.com/ninenines/cowboy.git</a>
-</p>
-</li>
-</ul></div>
-<div class="paragraph"><p>They are updated at the same time so there is no real difference.</p></div>
-</description> + <description>Cowboy 2.0.0-rc.1 has been released! + This is the new recommended version of Cowboy. Its API should not change before release. While you probably should not use it in production yet, many do successfully. Use at your own risk. + The plan is to have a new RC version every couple weeks until the summer ends or later if there are still blocking issues open. Only issues that can&#8217;t be fixed without making breaking changes to the interface may block the release.</description> </item> <item> @@ -124,140 +40,8 @@ purposes of testing.</p></div> <pubDate>Sun, 26 Mar 2017 00:00:00 +0100</pubDate> <guid>https://ninenines.eu/articles/the-elephant-in-the-room/</guid> - <description><div class="paragraph"><p>Have you ever tried telling someone why they should use
-Erlang? You boast the smaller code size, the auto healing
-mechanisms, the distribution and they seem really excited.
-They wonder why they never heard about Erlang before. And
-then you show them what the code looks like. All excitement
-goes away. The smiles disappear. Their face starts
-becoming really serious.</p></div>
-<div class="paragraph"><p>You lost them. You know you lost them. They comment on the
-syntax, or perhaps you do, already admitting defeat. It&#8217;s
-unlike anything they have ever used before. And they will
-most likely end up not using it.</p></div>
-<div class="paragraph"><p>What about people who already know what the syntax looks
-like? As soon as you mention Erlang, the topic of the syntax
-comes in. It&#8217;s like nothing else matters.</p></div>
-<div class="paragraph"><p>Perhaps the topic of syntax didn&#8217;t come up. But they&#8217;re
-still not going to try Erlang because of it.</p></div>
-<div class="paragraph"><p>You&#8217;re probably not having these kinds of interactions at
-Erlang conferences. This doesn&#8217;t happen with people who are
-already somewhat interested in, or need, the features that
-Erlang provides. With them the syntax is at worst a minor
-inconvenience.</p></div>
-<div class="paragraph"><p>This happens because most developers are familiar with
-syntaxes that look nothing like Erlang. To be clear, I
-include language features and other concepts like objects
-as part of "syntax" here. Familiarity is a very important
-factor to drive adoption.</p></div>
-<div class="paragraph"><p>You can see an example of that in the Elixir world, where
-the majority of people come from Ruby or already knew and
-liked Ruby. The 2016 survey tells us that 59% of Elixir
-developers were using Ruby primarily before. That&#8217;s in
-large part because of the syntax. They will deny it of
-course and find other reasons. And yet, we don&#8217;t see such
-a strong adoption of Erlang from Ruby developers, before
-or after Elixir appeared.</p></div>
-<div class="paragraph"><p>Side note: have you ever wondered why the Elixir community
-is, I quote, much friendlier than the Ruby community?
-Despite having much of the same people?</p></div>
-<div class="paragraph"><p>Before we continue, let me be clear. I love the Erlang
-syntax. It is simple and explicit. It is powerful, especially
-when dealing with binary data. It has very few quirks.
-It has little to no ambiguity. It&#8217;s great. Except for
-persuading people to use it.</p></div>
-<div class="paragraph"><p>Over the years I have been writing Erlang, I have seen
-very few people point out that the syntax slows down
-adoption. We have no problem with it, so why would others?
-At the same time, people coming to Erlang come to solve
-a real problem they&#8217;re having, so the syntax is fairly
-secondary. Even if they hate it at first, they know they
-can solve their problems despite the syntax.</p></div>
-<div class="paragraph"><p>You don&#8217;t build a popular product or language by solving
-people&#8217;s problems though. In general you end up solving
-some problems and creating new problems. No, you build
-a popular product by <strong>convincing people to use it</strong>. And
-you make them stay with your product by making them
-<strong>commit</strong> to using it.</p></div>
-<div class="paragraph"><p>Take MongoDB for example. It didn&#8217;t become popular by
-working, or even by being practical. It wasn&#8217;t performing
-its primary function and was losing people&#8217;s data. That
-didn&#8217;t stop it from becoming popular. Smart people would
-knowingly use a database that was losing data. Think about
-that for a minute.</p></div>
-<div class="paragraph"><p>MongoDB of course had a huge marketing machine, and they
-focused on that. They helped organize many meetups all
-over the world, complete with various swag items given
-for free, including a small handbook about MongoDB. All
-people had to do was show up.</p></div>
-<div class="paragraph"><p>They didn&#8217;t go tell people to look at all the weaknesses
-their product had. They focused on the strengths. On
-what would convince people to try it. They would go
-to meetups, discuss with others, commit to try it (or
-try it at meetups directly), and by doing so sell MongoDB
-to themselves.</p></div>
-<div class="paragraph"><p>How do we get people to meetups though? That&#8217;d be the
-first step: you need to <strong>catch their attention</strong>.
-I believe MongoDB did this using benchmark results.
-Ironic isn&#8217;t it? MongoDB gets fast benchmark results
-because they lose data, and this gets everyone to buy
-into the product.</p></div>
-<div class="paragraph"><p>The key points to remember about this are:</p></div>
-<div class="ulist"><ul>
-<li>
-<p>
-catch people&#8217;s attention
-</p>
-</li>
-<li>
-<p>
-show your product&#8217;s strengths
-</p>
-</li>
-<li>
-<p>
-make people take a commitment
-</p>
-</li>
-</ul></div>
-<div class="paragraph"><p>Once they commit to something, you win. Everyone will not
-end up ultimately using your product of course, but it&#8217;s
-at the very least become a consideration. It&#8217;s on their
-mind. Their resolve will be stronger when they ultimately
-try it and inevitably run into issues.</p></div>
-<div class="paragraph"><p>Erlang&#8217;s syntax is a weakness. Almost nobody looks at the
-Erlang syntax and falls in love with it at first sight.
-No, it takes time to learn it and understand how good it
-is. You need to sell Erlang to people without showing
-the Erlang syntax. If you do show it, then you need to
-hide the parts that feel alien. Function calls are OK.
-Recursion, not so much. Maps are OK. Records, not.</p></div>
-<div class="paragraph"><p>Avoiding code is not always possible when you try
-to sell it, especially to developers. You can however
-prepare them to accept the alien syntax by admitting
-that the syntax is not perfect before you show it.
-You can do this while praising it at the same time.
-For example, "the syntax is a little out there, but
-it matches the concepts perfectly, it will all make
-sense when you start learning".</p></div>
-<div class="paragraph"><p>This might not be the best introduction. Someone will
-need to A/B test it to find the one that gives the
-best results. But that should give you ideas.</p></div>
-<div class="paragraph"><p>When something terrible happens, mentioning that this
-isn&#8217;t the end of the world <strong>before</strong> you tell others what
-happened will soften their reaction. When someone
-breaks your favorite item and cries over it calling
-themselves stupid, it&#8217;s harder to get mad at them,
-compared to the same event with no emotional reaction.</p></div>
-<div class="paragraph"><p>Our behavior is largely dependent on what&#8217;s at the
-top of our mind, so it&#8217;s up to you to take advantage
-of this to make your case in the best conditions.</p></div>
-<div class="paragraph"><p>Next time you try to make someone use Erlang, remember
-that you should aim for getting a spoken commitment
-out of them, if possible before you show the syntax.
-If that&#8217;s not possible, then prepare them to accept
-the flaws or the weirdness before they see them.</p></div>
-</description> + <description>Have you ever tried telling someone why they should use Erlang? You boast the smaller code size, the auto healing mechanisms, the distribution and they seem really excited. They wonder why they never heard about Erlang before. And then you show them what the code looks like. All excitement goes away. The smiles disappear. Their face starts becoming really serious. + You lost them. You know you lost them. They comment on the syntax, or perhaps you do, already admitting defeat.</description> </item> <item> @@ -266,119 +50,8 @@ the flaws or the weirdness before they see them.</p></div> <pubDate>Sun, 22 Jan 2017 00:00:00 +0100</pubDate> <guid>https://ninenines.eu/articles/dont-let-it-crash/</guid> - <description><div class="paragraph"><p>We have a specific mindset when writing Erlang
-programs. We focus on the normal execution of the
-program and don&#8217;t handle most of the errors that may
-occur. We sometimes call this normal execution the
-<em>happy path</em>.</p></div>
-<div class="paragraph"><p>The general pattern behind writing only for the
-<em>happy path</em>, letting the VM catch errors (writing
-them to a log for future consumption) and then
-having a supervisor restart the processes that
-failed from a clean state, has a name. We call it
-<em>let it crash</em>; and it drives many of our design
-decisions.</p></div>
-<div class="paragraph"><p>It&#8217;s a really great way to program and the results
-are fantastic compared to most other programming
-languages. And yet, <em>let it crash</em> barely convinced
-anyone that they should use Erlang. Why would that
-be?</p></div>
-<div class="paragraph"><p>You may already know that Cowboy is capable of
-handling at least 2 million Websocket connections
-on a single server. This is in large part thanks
-to the capabilities of the VM. Still, 2 million
-is good, much better than most other servers can
-do.</p></div>
-<div class="paragraph"><p>Cowboy is not just a Websocket server; it&#8217;s also
-an HTTP and HTTP/2 server, and it handles many
-related features like long polling or the parsing
-of most request headers.</p></div>
-<div class="paragraph"><p>Can you guess how large the Cowboy codebase is,
-without looking at the source?</p></div>
-<div class="paragraph"><p>Do make sure you have a clear answer in your mind
-before you go check.</p></div>
-<div class="paragraph"><p>Good, you are back. Now what were the results? If
-I am correct, you overestimated the size of Cowboy.
-Cowboy is in fact about five thousand lines of code.
-You probably thought it was at least ten thousand.
-About eighty percent of readers will have
-overestimated the size of Cowboy. And you did only
-because I mentioned it can handle millions of
-Websocket connections.</p></div>
-<div class="paragraph"><p>Numerous studies show this effect. Just mentioning
-the large number already prepared your mind to think
-in that direction. Repeating the number made you
-focus even more on it. Then the question asked for
-a number, which ended up larger than the reality.</p></div>
-<div class="paragraph"><p>The same effect can be applied to negotiation for
-example. You generally want to start by giving your
-offer (and not let the other party initiate) and
-you want to give a really large number first. You
-can also prepare your customer by mentioning an even
-larger number in the previous discussion.</p></div>
-<div class="paragraph"><p>And it&#8217;s not just numbers either. An experiment
-showed that just by looking at an image of clouds,
-customers of a pillow store were buying pillows
-more comfortable (and more expensive) than those
-who didn&#8217;t see that image.</p></div>
-<div class="paragraph"><p>This is the power of associations. It is covered in
-much larger detail in the books
-<a href="https://www.amazon.com/Influence-Psychology-Persuasion-Robert-Cialdini/dp/006124189X">Influence</a>
-and
-<a href="https://www.amazon.com/Pre-Suasion-Revolutionary-Way-Influence-Persuade/dp/1501109790">Pre-suasion</a>.
-I highly recommend reading those and applying what
-you learn to your daily life. I&#8217;m definitely not
-a professional psychologist so take this post with
-a grain of salt.</p></div>
-<div class="paragraph"><p>When selling Erlang, whether we are selling it to
-a customer or trying to convince a developer friend
-to start using it, we often talk about how Erlang
-<em>lets you sleep at night</em>, that it is auto healing
-and always gets fantastic uptimes.</p></div>
-<div class="paragraph"><p>And then we talk about <em>let it crash</em>.</p></div>
-<div class="paragraph"><p>And we describe what it means.</p></div>
-<div class="paragraph"><p>We might as well just say that Erlang crashes a lot
-and then take the door. It would have the same effect.
-It doesn&#8217;t even stop at programs crashing. You know
-what else crashes? Cars, planes, trains. Often with
-disastrous consequences. Is that really the message
-we want to convey?</p></div>
-<div class="paragraph"><p>They even <a href="https://img.youtube.com/vi/oEUBW2lCkIk/0.jpg">printed it on a t-shirt</a>!
-Keep calm and let it crash. It&#8217;s the kind of t-shirt
-you probably shouldn&#8217;t wear in an airport, and for good
-reasons. A few people did, then realized what they were
-wearing and were not too smug about it.</p></div>
-<div class="paragraph"><p>And yet this is how we sell Erlang.</p></div>
-<div class="paragraph"><p>A better way would be to focus on the positives, of
-course, but also to make sure that those positives
-are phrased in a way that prevents bad associations
-to be formed in people&#8217;s minds.</p></div>
-<div class="paragraph"><p>Instead of <em>let it crash</em>, you can say that Erlang
-has <em>auto healing mechanisms</em>. Healing is a good
-thing and accurately describes what happens in the
-system.</p></div>
-<div class="paragraph"><p>Should you need to go into more details, you will
-probably want to avoid <em>recover from crashes</em> and
-instead say <em>recover from exceptions</em>. Exceptions
-are a pretty neutral word and, should you explain
-what you mean by that, you can talk about exceptions
-that occur for reasons unrelated to Erlang, like
-hardware failure or network instability.</p></div>
-<div class="paragraph"><p>The trick is to always use positive words and
-phrases to describe Erlang, and to use external
-factors to explain how Erlang deals with failures.
-Never mention the failures internal to Erlang
-systems unless you are asked specifically, in
-which case you can say that the auto healing
-applies to all exceptions.</p></div>
-<div class="paragraph"><p>The <em>let it crash</em> philosophy is great when
-learning Erlang or when writing fault-tolerant
-systems. But it&#8217;s not going to convince anyone
-to use it unless they were already looking for
-it.</p></div>
-<div class="paragraph"><p>Do you like this post? Tell me on Twitter. I might
-make more.</p></div>
-</description> + <description>We have a specific mindset when writing Erlang programs. We focus on the normal execution of the program and don&#8217;t handle most of the errors that may occur. We sometimes call this normal execution the happy path. + The general pattern behind writing only for the happy path, letting the VM catch errors (writing them to a log for future consumption) and then having a supervisor restart the processes that failed from a clean state, has a name.</description> </item> <item> @@ -387,117 +60,10 @@ make more.</p></div> <pubDate>Tue, 03 Jan 2017 00:00:00 +0100</pubDate> <guid>https://ninenines.eu/articles/cowboy-2.0.0-pre.4/</guid> - <description><div class="paragraph"><p>Cowboy <code>2.0.0-pre.4</code> has been released!</p></div>
-<div class="paragraph"><p>This is the new recommended version of Cowboy.
-While I would not recommend putting it in production
-just yet, I do recommend you start writing new
-applications with this Cowboy version.</p></div>
-<div class="paragraph"><p>The most significant changes in the pre-release are:</p></div>
-<div class="ulist"><ul>
-<li>
-<p>
-A new architecture: there now is one process per
- connection and one process per request. This was
- done because HTTP/2 allows running requests concurrently.
-</p>
-</li>
-<li>
-<p>
-Stream handlers. Every request, response and data goes
- through stream handlers. They are meant to replace hooks
- and more. They will be documented in a future pre-release.
- Check <code>cowboy_stream</code> and <code>cowboy_stream_h</code> if interested.
-</p>
-</li>
-<li>
-<p>
-Numerous changes to the <code>cowboy_req</code> interface. This
- is very close to final. Check the manual for what changed.
-</p>
-</li>
-<li>
-<p>
-The Req object is no longer passed in Websocket callbacks.
-</p>
-</li>
-<li>
-<p>
-It is now possible to send frames directly from <code>websocket_init/1</code>.
-</p>
-</li>
-<li>
-<p>
-SPDY support was removed, now that we have HTTP/2.
-</p>
-</li>
-<li>
-<p>
-Update Ranch to 1.3. We still depend on Cowlib master
- for the time being.
-</p>
-</li>
-<li>
-<p>
-A much improved manual.
-</p>
-</li>
-</ul></div>
-<div class="paragraph"><p>The manual received a lot of love. It now has one page per
-function with a detailed description, arguments list, return
-value, changelog and examples. It also links to the other
-relevant manual pages: <a href="https://ninenines.eu/docs/en/cowboy/2.0/manual/">https://ninenines.eu/docs/en/cowboy/2.0/manual/</a></p></div>
-<div class="paragraph"><p>I am quite proud of the manual right now. While more
-improvements can be made, what we have now is way better
-than before. Feedback for further improvements is welcome!</p></div>
-<div class="paragraph"><p>This is a significant step toward Cowboy 2.0. Almost all
-the breaking changes are in. A few more pre-releases are
-planned and will be released on a weekly basis (with exceptions).</p></div>
-<div class="paragraph"><p>Cowboy is now tested and supported with Erlang/OTP 18.0 or above
-on Arch Linux, FreeBSD, OSX, Ubuntu and Windows 7. Contact me
-if you can provide permanent access to another platform for the
-purposes of testing.</p></div>
-<div class="paragraph"><p>Cowboy is now available from four locations:</p></div>
-<div class="ulist"><ul>
-<li>
-<p>
-<a href="https://git.ninenines.eu/cowboy.git">https://git.ninenines.eu/cowboy.git</a>
-</p>
-</li>
-<li>
-<p>
-<a href="https://github.com/ninenines/cowboy.git">https://github.com/ninenines/cowboy.git</a>
-</p>
-</li>
-<li>
-<p>
-<a href="https://bitbucket.org/ninenines/cowboy.git">https://bitbucket.org/ninenines/cowboy.git</a>
-</p>
-</li>
-<li>
-<p>
-<a href="https://gitlab.com/ninenines/cowboy.git">https://gitlab.com/ninenines/cowboy.git</a>
-</p>
-</li>
-</ul></div>
-<div class="paragraph"><p>They are updated at the same time so there is no real difference.</p></div>
-<div class="paragraph"><p>Cowboy 2.0 will be released once all the breaking changes
-are completed and the temporarily removed features are
-added back.</p></div>
-<div class="paragraph"><p>Thanks for your patience. I know it took a long time.</p></div>
-<hr/>
-<div class="paragraph"><p>Half-price on all donations because I need a new hat:</p></div>
-<form action="https://www.paypal.com/cgi-bin/webscr" method="post" style="display:inline">
-<input type="hidden" name="cmd" value="_donations">
-<input type="hidden" name="business" value="[email protected]">
-<input type="hidden" name="lc" value="FR">
-<input type="hidden" name="item_name" value="Loic Hoguin">
-<input type="hidden" name="item_number" value="99s">
-<input type="hidden" name="currency_code" value="EUR">
-<input type="hidden" name="bn" value="PP-DonationsBF:btn_donate_LG.gif:NonHosted">
-<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
-<img alt="" border="0" src="https://www.paypalobjects.com/fr_FR/i/scr/pixel.gif" width="1" height="1">
-</form>
-</description> + <description>Cowboy 2.0.0-pre.4 has been released! + This is the new recommended version of Cowboy. While I would not recommend putting it in production just yet, I do recommend you start writing new applications with this Cowboy version. + The most significant changes in the pre-release are: + A new architecture: there now is one process per connection and one process per request. This was done because HTTP/2 allows running requests concurrently.</description> </item> <item> @@ -506,89 +72,9 @@ added back.</p></div> <pubDate>Mon, 28 Nov 2016 00:00:00 +0100</pubDate> <guid>https://ninenines.eu/articles/ranch-1.3/</guid> - <description><div class="paragraph"><p>Ranch <code>1.3.0</code> has been released!</p></div>
-<div class="paragraph"><p>This release fixes a number of long standing issues and adds
-a small number of features:</p></div>
-<div class="paragraph"><p>The <code>ssl</code> application has been added to the list of dependencies.
-If you don&#8217;t need it, you can remove it automatically when fetching
-Ranch or when building the release. If you do need it, you will no
-longer have issues shutting down a node because of Ranch.</p></div>
-<div class="paragraph"><p>The <code>ranch:info/0</code> and <code>ranch:procs/2</code> can be used to retrieve
-information about Ranch&#8217;s state. Use it for diagnostic and
-discovery purposes.</p></div>
-<div class="paragraph"><p>SSL listeners can now be configured without a certificate, for setups
-that make use of the SNI extension.</p></div>
-<div class="paragraph"><p>Transport options are now a blacklist, meaning all unknown options
-will be accepted. However Dialyzer will warn if said option is not
-defined in Ranch&#8217;s type specifications. Please send a patch when that
-happens!</p></div>
-<div class="paragraph"><p>Various bugs have been fixed, including the bug where the
-number of active connections could become negative. Common
-errors at listener startup should be easier to read (for
-example when the port is already in use).</p></div>
-<div class="paragraph"><p>See the <a href="https://git.ninenines.eu/ranch.git/plain/CHANGELOG.asciidoc">CHANGELOG</a>
-for more details.</p></div>
-<div class="paragraph"><p>Ranch is now tested and supported with Erlang/OTP R16B or above
-on Arch Linux, FreeBSD, OSX, Ubuntu and Windows 7. Contact me
-if you can provide permanent access to another platform for the
-purposes of testing.</p></div>
-<div class="paragraph"><p>Ranch is now available from four locations:</p></div>
-<div class="ulist"><ul>
-<li>
-<p>
-<a href="https://git.ninenines.eu/ranch.git">https://git.ninenines.eu/ranch.git</a>
-</p>
-</li>
-<li>
-<p>
-<a href="https://github.com/ninenines/ranch.git">https://github.com/ninenines/ranch.git</a>
-</p>
-</li>
-<li>
-<p>
-<a href="https://bitbucket.org/ninenines/ranch.git">https://bitbucket.org/ninenines/ranch.git</a>
-</p>
-</li>
-<li>
-<p>
-<a href="https://gitlab.com/ninenines/ranch.git">https://gitlab.com/ninenines/ranch.git</a>
-</p>
-</li>
-</ul></div>
-<div class="paragraph"><p>They are updated at the same time so there is no real difference.</p></div>
-<div class="paragraph"><p>The most recent Ranch commit is now always signed. You can import the
-<a href="https://pgp.mit.edu/pks/lookup?op=vindex&amp;fingerprint=on&amp;exact=on&amp;search=0xF19F189CECC7439699CEDD7A6EF7A77066CCCC8A">signing key for Loïc Hoguin</a> with:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt>$ gpg --keyserver hkp<span style="color: #990000">:</span>//keys<span style="color: #990000">.</span>gnupg<span style="color: #990000">.</span>net --recv-key 66CCCC8A</tt></pre></div></div>
-<div class="paragraph"><p>The primary key fingerprint is <code>F19F 189C ECC7 4396 99CE DD7A 6EF7 A770 66CC CC8A</code>.</p></div>
-<div class="paragraph"><p>When verifying signatures in git, the following should appear:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt>gpg<span style="color: #990000">:</span> Signature made Sat <span style="color: #993399">26</span> Nov <span style="color: #993399">2016</span> <span style="color: #993399">12</span><span style="color: #990000">:</span><span style="color: #993399">58</span><span style="color: #990000">:</span><span style="color: #993399">35</span> PM CET
-gpg<span style="color: #990000">:</span> using RSA key 71366FF21851DF03
-gpg<span style="color: #990000">:</span> Good signature from <span style="color: #FF0000">"Loïc Hoguin &lt;[email protected]&gt;"</span> <span style="color: #990000">[</span>unknown<span style="color: #990000">]</span>
-gpg<span style="color: #990000">:</span> WARNING<span style="color: #990000">:</span> This key is not certified with a trusted signature<span style="color: #990000">!</span>
-gpg<span style="color: #990000">:</span> There is no indication that the signature belongs to the owner<span style="color: #990000">.</span>
-Primary key fingerprint<span style="color: #990000">:</span> F19F 189C ECC7 <span style="color: #993399">4396</span> 99CE DD7A 6EF7 A770 66CC CC8A
- Subkey fingerprint<span style="color: #990000">:</span> FEDA <span style="color: #993399">6E41</span> B390 F745 A385 5CDC <span style="color: #993399">7136</span> 6FF2 <span style="color: #993399">1851</span> DF03</tt></pre></div></div>
-<div class="paragraph"><p>You can safely ignore the warning if you don&#8217;t know what it
-means, as long as everything else is correct.</p></div>
-<div class="paragraph"><p>Mirrors and signature verification will soon be implemented
-directly in Erlang.mk. In the meantime, you will need to
-set them up manually.</p></div>
-<div class="paragraph"><p>Most of this work was done to fix issues in RabbitMQ. Paid
-customers get priority; contact me if you have some issues
-that need fixing sooner rather than later.</p></div>
-<div class="paragraph"><p>Expect future releases to be announced in this space.</p></div>
-<div class="paragraph"><p>Thanks for reading!</p></div>
-</description> + <description>Ranch 1.3.0 has been released! + This release fixes a number of long standing issues and adds a small number of features: + The ssl application has been added to the list of dependencies. If you don&#8217;t need it, you can remove it automatically when fetching Ranch or when building the release. If you do need it, you will no longer have issues shutting down a node because of Ranch.</description> </item> <item> @@ -597,17 +83,10 @@ that need fixing sooner rather than later.</p></div> <pubDate>Mon, 29 Aug 2016 00:00:00 +0100</pubDate> <guid>https://ninenines.eu/articles/ml-archives/</guid> - <description><div class="paragraph"><p>The <a href="https://ninenines.eu/archives/extend">old mailing list archives</a> have been
-added to the site, mainly for referencing purposes.</p></div>
-<div class="paragraph"><p>The mailing list has been shut down and all personal information
-has been deleted.</p></div>
-<div class="paragraph"><p>If you need help with a project, consider either opening a ticket
-on that project&#8217;s issues tracker or going through the community
-channels (erlang-questions, #ninenines or #erlang on Freenode).</p></div>
-<div class="paragraph"><p>Prefer tickets; often when people have issues it highlights an
-underlying problem in the project or its documentation.</p></div>
-<div class="paragraph"><p>Thanks.</p></div>
-</description> + <description>The old mailing list archives have been added to the site, mainly for referencing purposes. + The mailing list has been shut down and all personal information has been deleted. + If you need help with a project, consider either opening a ticket on that project&#8217;s issues tracker or going through the community channels (erlang-questions, #ninenines or #erlang on Freenode). + Prefer tickets; often when people have issues it highlights an underlying problem in the project or its documentation.</description> </item> <item> @@ -616,64 +95,9 @@ underlying problem in the project or its documentation.</p></div> <pubDate>Sat, 02 Apr 2016 00:00:00 +0100</pubDate> <guid>https://ninenines.eu/articles/website-update/</guid> - <description><div class="paragraph"><p>Last week-end I updated the Nine Nines website.</p></div>
-<div class="paragraph"><p>I switched to <a href="http://gohugo.io/">Hugo</a>. The site is
-now built from <a href="http://asciidoc.org/">Asciidoc</a>
-documents. You probably saw me switch to Asciidoc
-for documentation this past year. This is the
-natural conclusion to that story. The great thing
-is that with a little bit of Makefile magic I can
-just copy the documentation files into Hugo and
-poof, they appear on the website.</p></div>
-<div class="paragraph"><p>I am very happy with that new setup. I can now
-post my thoughts again. Woo! Expect regular posts
-from now on. I will try to replace my long series
-of tweets with posts.</p></div>
-<div class="paragraph"><p>The sections have been rearranged. There used to
-be a separate training section; now
-<a href="https://ninenines.eu/services">all my services</a> are described in
-one page. I have also clarified my areas of
-expertise. There used to be confusion in the past,
-so now it should be clearer that I am not a
-distributed systems expert.</p></div>
-<div class="paragraph"><p>On that note, if you are looking for my
-services right now, I&#8217;m not available. I&#8217;ll have
-to work 7 days a week for a while. Try again in a
-couple months. More on that in a future post.</p></div>
-<div class="paragraph"><p>The <a href="https://ninenines.eu/docs">documentation</a> becomes a first class
-citizen. Bullet and Cowlib don&#8217;t have proper
-documentation&#8230; yet. I have started working on the
-Cowlib documentation, and Bullet shouldn&#8217;t take too
-long. All these projects will be documented when
-Cowboy gets to 2.0, and will all be supported
-equally. Note that the Cowboy 1.0 documentation
-still has the old website templates and links.
-Don&#8217;t worry about it.</p></div>
-<div class="paragraph"><p>The mailing lists link has been removed. I did
-announce a few months back that mailing lists were
-going to go. They&#8217;re still up right now, but not
-for long. I am planning to put the archives
-read-only, link to them from a future post and
-be done with it. If you have a question, open a
-ticket on Github. Then I can just decide to leave
-the ticket open if I want to do improvements based
-on your feedback.</p></div>
-<div class="paragraph"><p>I have replaced most of the "we" by "I". I am
-a one-man company right now. Have been for a while.
-Doesn&#8217;t make sense to keep a facade. I want to be
-close to users, not put a barrier between us.</p></div>
-<div class="paragraph"><p>The RSS changed. The old link doesn&#8217;t work anymore.
-The new link is at <a href="https://ninenines.eu/index.xml">/index.xml</a>,
-or <a href="https://ninenines.eu/articles/index.xml">/articles/index.xml</a>
-if you only care about my posts. I guess that&#8217;s the
-one most people want.</p></div>
-<div class="paragraph"><p>I still have some tweaks to do, but it will take a
-while. My long term plan is to remove Bootstrap, use
-vanilla CSS and as little JS as possible. The reason
-for that is that it&#8217;s cheaper than upgrading libraries
-every few years. Life is too short to spend it
-upgrading JS libraries.</p></div>
-</description> + <description>Last week-end I updated the Nine Nines website. + I switched to Hugo. The site is now built from Asciidoc documents. You probably saw me switch to Asciidoc for documentation this past year. This is the natural conclusion to that story. The great thing is that with a little bit of Makefile magic I can just copy the documentation files into Hugo and poof, they appear on the website. + I am very happy with that new setup.</description> </item> <item> @@ -682,20 +106,10 @@ upgrading JS libraries.</p></div> <pubDate>Wed, 02 Sep 2015 00:00:00 +0100</pubDate> <guid>https://ninenines.eu/articles/erlanger-playbook-september-2015-update/</guid> - <description><div class="paragraph"><p>An update to The Erlanger Playbook is now available!</p></div>
-<div class="paragraph"><p>The Erlanger Playbook is a book about software development using
-Erlang. It currently covers all areas from the conception, design,
-the writing of code, documentation and tests.</p></div>
-<div class="paragraph"><p>The book is still a work in progress. Future topics will include
-refactoring, debugging and tracing, benchmarking, releases, community
-management (for open source projects).</p></div>
-<div class="paragraph"><p>This update fixes a number of things and adds two chapters: IOlists
-and Erlang building blocks.</p></div>
-<div class="paragraph"><p>Learn more about <a href="https://ninenines.eu/articles/erlanger-playbook">The Erlanger Playbook</a>!</p></div>
-<div class="paragraph"><p>This is a self-published ebook. The base price is 50€. All proceeds
-will be used to allow me to work on open source full time.</p></div>
-<div class="paragraph"><p>Thank you for helping me helping you help us all!</p></div>
-</description> + <description>An update to The Erlanger Playbook is now available! + The Erlanger Playbook is a book about software development using Erlang. It currently covers all areas from the conception, design, the writing of code, documentation and tests. + The book is still a work in progress. Future topics will include refactoring, debugging and tracing, benchmarking, releases, community management (for open source projects). + This update fixes a number of things and adds two chapters: IOlists and Erlang building blocks.</description> </item> <item> @@ -704,88 +118,10 @@ will be used to allow me to work on open source full time.</p></div> <pubDate>Thu, 18 Jun 2015 00:00:00 +0100</pubDate> <guid>https://ninenines.eu/articles/erlanger-playbook/</guid> - <description><div class="paragraph"><p>I am proud to announce the pre-release of The Erlanger Playbook.</p></div>
-<div class="paragraph"><p>The Erlanger Playbook is a book about software development using
-Erlang. It currently covers all areas from the conception, design,
-the writing of code, documentation and tests.</p></div>
-<div class="paragraph"><p>The book is still a work in progress. Future topics will include
-refactoring, debugging and tracing, benchmarking, releases, community
-management (for open source projects).</p></div>
-<div class="paragraph"><p>The following sections are currently available:</p></div>
-<div class="ulist"><ul>
-<li>
-<p>
-About this book; Changelog; Future additions
-</p>
-</li>
-<li>
-<p>
-<em>Erlang:</em> Building blocks; Patterns
-</p>
-</li>
-<li>
-<p>
-<em>Workflow:</em> Think; Write; Stay productive
-</p>
-</li>
-<li>
-<p>
-<em>Documentation:</em> On documentation; Tutorials; User guide; Manual; README files
-</p>
-</li>
-<li>
-<p>
-<em>Design:</em> RESTful APIs; Lessons learned
-</p>
-</li>
-<li>
-<p>
-<em>Code:</em> Starting a project; Version control; Project structure; Code style; Best practices; Special processes; IOLists; The process dictionary
-</p>
-</li>
-<li>
-<p>
-<em>Tests:</em> On testing; Success typing analysis; Manual testing; Unit testing; Functional testing
-</p>
-</li>
-<li>
-<p>
-<em>Selling Erlang:</em> On persuasion; Don&#8217;t let it crash
-</p>
-</li>
-</ul></div>
-<div class="paragraph"><p>Read a preview: <a href="https://ninenines.eu/res/erlanger-preview.pdf">Special processes</a></p></div>
-<div class="paragraph"><p>The book is currently 180 pages long. The final version
-of the book is planned to be between 200 and 250 pages.
-A print version of the book will be considered once the final
-version gets released. The printed book is <strong>not</strong> included
-in the price.</p></div>
-<div class="paragraph"><p>This is a self-published book. The base price is 50€. All proceeds
-will be used to allow me to work on open source full time.</p></div>
-<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
-<input type="hidden" name="cmd" value="_s-xclick">
-<input type="hidden" name="hosted_button_id" value="9M44HJCGX3GVN">
-<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
-<img alt="" border="0" src="https://www.paypalobjects.com/fr_FR/i/scr/pixel.gif" width="1" height="1">
-</form>
-<div class="paragraph"><p>You are more than welcome to pay extra by using this second button.
-It allows you to set the price you want. Make sure to set it to at least
-50€ to receive the book.</p></div>
-<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
-<input type="hidden" name="cmd" value="_s-xclick">
-<input type="hidden" name="hosted_button_id" value="BBW9TR9LBK8C2">
-<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
-<img alt="" border="0" src="https://www.paypalobjects.com/fr_FR/i/scr/pixel.gif" width="1" height="1">
-</form>
-<div class="paragraph"><p>Make sure to provide a valid email address.</p></div>
-<div class="paragraph"><p>There will be a <strong>delay</strong> between payment and sending of the book.
-This process is currently manual.</p></div>
-<div class="paragraph"><p>As the book is a pre-release, feedback is more than welcome. You can
-send your comments to erlanger@ this website.</p></div>
-<div class="paragraph"><p>The plan is to add content regularly until I run out of things to say.
-You will receive updates to the book for free as soon as they are available.</p></div>
-<div class="paragraph"><p>Huge thanks for your interest in buying this book!</p></div>
-</description> + <description>I am proud to announce the pre-release of The Erlanger Playbook. + The Erlanger Playbook is a book about software development using Erlang. It currently covers all areas from the conception, design, the writing of code, documentation and tests. + The book is still a work in progress. Future topics will include refactoring, debugging and tracing, benchmarking, releases, community management (for open source projects). + The following sections are currently available:</description> </item> <item> @@ -794,192 +130,9 @@ You will receive updates to the book for free as soon as they are available.< <pubDate>Fri, 06 Mar 2015 00:00:00 +0100</pubDate> <guid>https://ninenines.eu/articles/erlang-validate-utf8/</guid> - <description><div class="paragraph"><p>Yesterday I pushed Websocket permessage-deflate to
-Cowboy master. I also pushed
-<a href="https://github.com/ninenines/cowlib/commit/7e4983b70ddf8cedb967e36fba6a600731bdad5d">a
-change in the way the code validates UTF-8 data</a>
-(required for text and close frames as per the spec).</p></div>
-<div class="paragraph"><p>When looking into why the permessage-deflate tests
-in autobahntestsuite were taking such a long time, I
-found that autobahn is using an adaptation of the
-algorithm named <a href="http://bjoern.hoehrmann.de/utf-8/decoder/dfa/">Flexible
-and Economical UTF-8 Decoder</a>. This is the C99
-implementation:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="font-style: italic"><span style="color: #9A1900">// Copyright (c) 2008-2009 Bjoern Hoehrmann &lt;[email protected]&gt;</span></span>
-<span style="font-style: italic"><span style="color: #9A1900">// See http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details.</span></span>
-
-<span style="font-weight: bold"><span style="color: #000080">#define</span></span> UTF8_ACCEPT <span style="color: #993399">0</span>
-<span style="font-weight: bold"><span style="color: #000080">#define</span></span> UTF8_REJECT <span style="color: #993399">1</span>
-
-<span style="font-weight: bold"><span style="color: #0000FF">static</span></span> <span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #008080">uint8_t</span> utf8d<span style="color: #990000">[]</span> <span style="color: #990000">=</span> <span style="color: #FF0000">{</span>
- <span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// 00..1f</span></span>
- <span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// 20..3f</span></span>
- <span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// 40..5f</span></span>
- <span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// 60..7f</span></span>
- <span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span><span style="color: #993399">9</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// 80..9f</span></span>
- <span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span><span style="color: #993399">7</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// a0..bf</span></span>
- <span style="color: #993399">8</span><span style="color: #990000">,</span><span style="color: #993399">8</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// c0..df</span></span>
- <span style="color: #993399">0xa</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x4</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// e0..ef</span></span>
- <span style="color: #993399">0xb</span><span style="color: #990000">,</span><span style="color: #993399">0x6</span><span style="color: #990000">,</span><span style="color: #993399">0x6</span><span style="color: #990000">,</span><span style="color: #993399">0x6</span><span style="color: #990000">,</span><span style="color: #993399">0x5</span><span style="color: #990000">,</span><span style="color: #993399">0x8</span><span style="color: #990000">,</span><span style="color: #993399">0x8</span><span style="color: #990000">,</span><span style="color: #993399">0x8</span><span style="color: #990000">,</span><span style="color: #993399">0x8</span><span style="color: #990000">,</span><span style="color: #993399">0x8</span><span style="color: #990000">,</span><span style="color: #993399">0x8</span><span style="color: #990000">,</span><span style="color: #993399">0x8</span><span style="color: #990000">,</span><span style="color: #993399">0x8</span><span style="color: #990000">,</span><span style="color: #993399">0x8</span><span style="color: #990000">,</span><span style="color: #993399">0x8</span><span style="color: #990000">,</span><span style="color: #993399">0x8</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// f0..ff</span></span>
- <span style="color: #993399">0x0</span><span style="color: #990000">,</span><span style="color: #993399">0x1</span><span style="color: #990000">,</span><span style="color: #993399">0x2</span><span style="color: #990000">,</span><span style="color: #993399">0x3</span><span style="color: #990000">,</span><span style="color: #993399">0x5</span><span style="color: #990000">,</span><span style="color: #993399">0x8</span><span style="color: #990000">,</span><span style="color: #993399">0x7</span><span style="color: #990000">,</span><span style="color: #993399">0x1</span><span style="color: #990000">,</span><span style="color: #993399">0x1</span><span style="color: #990000">,</span><span style="color: #993399">0x1</span><span style="color: #990000">,</span><span style="color: #993399">0x4</span><span style="color: #990000">,</span><span style="color: #993399">0x6</span><span style="color: #990000">,</span><span style="color: #993399">0x1</span><span style="color: #990000">,</span><span style="color: #993399">0x1</span><span style="color: #990000">,</span><span style="color: #993399">0x1</span><span style="color: #990000">,</span><span style="color: #993399">0x1</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// s0..s0</span></span>
- <span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">0</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// s1..s2</span></span>
- <span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// s3..s4</span></span>
- <span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">2</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">3</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">3</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// s5..s6</span></span>
- <span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">3</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">3</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">3</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">3</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span><span style="color: #993399">1</span><span style="color: #990000">,</span> <span style="font-style: italic"><span style="color: #9A1900">// s7..s8</span></span>
-<span style="color: #FF0000">}</span><span style="color: #990000">;</span>
-
-uint32_t inline
-<span style="font-weight: bold"><span style="color: #000000">decode</span></span><span style="color: #990000">(</span>uint32_t<span style="color: #990000">*</span> state<span style="color: #990000">,</span> uint32_t<span style="color: #990000">*</span> codep<span style="color: #990000">,</span> <span style="color: #008080">uint32_t</span> byte<span style="color: #990000">)</span> <span style="color: #FF0000">{</span>
- <span style="color: #008080">uint32_t</span> type <span style="color: #990000">=</span> utf8d<span style="color: #990000">[</span>byte<span style="color: #990000">];</span>
-
- <span style="color: #990000">*</span>codep <span style="color: #990000">=</span> <span style="color: #990000">(*</span>state <span style="color: #990000">!=</span> UTF8_ACCEPT<span style="color: #990000">)</span> <span style="color: #990000">?</span>
- <span style="color: #990000">(</span>byte <span style="color: #990000">&amp;</span> <span style="color: #993399">0x3fu</span><span style="color: #990000">)</span> <span style="color: #990000">|</span> <span style="color: #990000">(*</span>codep <span style="color: #990000">&lt;&lt;</span> <span style="color: #993399">6</span><span style="color: #990000">)</span> <span style="color: #990000">:</span>
- <span style="color: #990000">(</span><span style="color: #993399">0xff</span> <span style="color: #990000">&gt;&gt;</span> type<span style="color: #990000">)</span> <span style="color: #990000">&amp;</span> <span style="color: #990000">(</span>byte<span style="color: #990000">);</span>
-
- <span style="color: #990000">*</span>state <span style="color: #990000">=</span> utf8d<span style="color: #990000">[</span><span style="color: #993399">256</span> <span style="color: #990000">+</span> <span style="color: #990000">*</span>state<span style="color: #990000">*</span><span style="color: #993399">16</span> <span style="color: #990000">+</span> type<span style="color: #990000">];</span>
- <span style="font-weight: bold"><span style="color: #0000FF">return</span></span> <span style="color: #990000">*</span>state<span style="color: #990000">;</span>
-<span style="color: #FF0000">}</span></tt></pre></div></div>
-<div class="paragraph"><p>And this is the Erlang implementation I came up with:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="font-style: italic"><span style="color: #9A1900">%% This function returns 0 on success, 1 on error, and 2..8 on incomplete data.</span></span>
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;&gt;&gt;</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-&gt;</span> <span style="color: #009900">State</span>;
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">0</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">&lt;</span> <span style="color: #993399">128</span> <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">2</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">&gt;=</span> <span style="color: #993399">128</span>, <span style="color: #009900">C</span> <span style="color: #990000">&lt;</span> <span style="color: #993399">144</span> <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">3</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">&gt;=</span> <span style="color: #993399">128</span>, <span style="color: #009900">C</span> <span style="color: #990000">&lt;</span> <span style="color: #993399">144</span> <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">5</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">&gt;=</span> <span style="color: #993399">128</span>, <span style="color: #009900">C</span> <span style="color: #990000">&lt;</span> <span style="color: #993399">144</span> <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">7</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">&gt;=</span> <span style="color: #993399">128</span>, <span style="color: #009900">C</span> <span style="color: #990000">&lt;</span> <span style="color: #993399">144</span> <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">8</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">&gt;=</span> <span style="color: #993399">128</span>, <span style="color: #009900">C</span> <span style="color: #990000">&lt;</span> <span style="color: #993399">144</span> <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">2</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">&gt;=</span> <span style="color: #993399">144</span>, <span style="color: #009900">C</span> <span style="color: #990000">&lt;</span> <span style="color: #993399">160</span> <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">3</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">&gt;=</span> <span style="color: #993399">144</span>, <span style="color: #009900">C</span> <span style="color: #990000">&lt;</span> <span style="color: #993399">160</span> <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">5</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">&gt;=</span> <span style="color: #993399">144</span>, <span style="color: #009900">C</span> <span style="color: #990000">&lt;</span> <span style="color: #993399">160</span> <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">6</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">&gt;=</span> <span style="color: #993399">144</span>, <span style="color: #009900">C</span> <span style="color: #990000">&lt;</span> <span style="color: #993399">160</span> <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">7</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">&gt;=</span> <span style="color: #993399">144</span>, <span style="color: #009900">C</span> <span style="color: #990000">&lt;</span> <span style="color: #993399">160</span> <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">2</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">&gt;=</span> <span style="color: #993399">160</span>, <span style="color: #009900">C</span> <span style="color: #990000">&lt;</span> <span style="color: #993399">192</span> <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">3</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">&gt;=</span> <span style="color: #993399">160</span>, <span style="color: #009900">C</span> <span style="color: #990000">&lt;</span> <span style="color: #993399">192</span> <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">4</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">&gt;=</span> <span style="color: #993399">160</span>, <span style="color: #009900">C</span> <span style="color: #990000">&lt;</span> <span style="color: #993399">192</span> <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">6</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">&gt;=</span> <span style="color: #993399">160</span>, <span style="color: #009900">C</span> <span style="color: #990000">&lt;</span> <span style="color: #993399">192</span> <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">7</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">&gt;=</span> <span style="color: #993399">160</span>, <span style="color: #009900">C</span> <span style="color: #990000">&lt;</span> <span style="color: #993399">192</span> <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">0</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">&gt;=</span> <span style="color: #993399">194</span>, <span style="color: #009900">C</span> <span style="color: #990000">&lt;</span> <span style="color: #993399">224</span> <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #993399">224</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">0</span>) <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">4</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">0</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">&gt;=</span> <span style="color: #993399">225</span>, <span style="color: #009900">C</span> <span style="color: #990000">&lt;</span> <span style="color: #993399">237</span> <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #993399">237</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">0</span>) <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">5</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">0</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">=:=</span> <span style="color: #993399">238</span>; <span style="color: #009900">C</span> <span style="color: #990000">=:=</span> <span style="color: #993399">239</span> <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #993399">240</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">0</span>) <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">6</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">0</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">=:=</span> <span style="color: #993399">241</span>; <span style="color: #009900">C</span> <span style="color: #990000">=:=</span> <span style="color: #993399">242</span>; <span style="color: #009900">C</span> <span style="color: #990000">=:=</span> <span style="color: #993399">243</span> <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">7</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #993399">244</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">0</span>) <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">8</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">_</span>, <span style="color: #990000">_</span>) <span style="color: #990000">-&gt;</span> <span style="color: #993399">1</span><span style="color: #990000">.</span></tt></pre></div></div>
-<div class="paragraph"><p>Does it look similar to you? So how did we get there?</p></div>
-<div class="paragraph"><p>I started with a naive implementation of the original. First, we
-don&#8217;t need the codepoint calculated and extracted for our validation
-function. We just want to know the data is valid, so we only need to
-calculate the next state. Then, the only thing we needed to be careful
-about was that tuples are 1-based, and that we need to stop processing
-the binary when we get the state 1 or when the binary is empty.</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;&gt;&gt;</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-&gt;</span> <span style="color: #009900">State</span>;
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">_</span>, <span style="color: #993399">1</span>) <span style="color: #990000">-&gt;</span> <span style="color: #993399">1</span>;
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-&gt;</span>
- <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="font-weight: bold"><span style="color: #000080">element</span></span>(<span style="color: #993399">257</span> <span style="color: #990000">+</span> <span style="color: #009900">State</span> <span style="color: #990000">*</span> <span style="color: #993399">16</span> <span style="color: #990000">+</span> <span style="font-weight: bold"><span style="color: #000080">element</span></span>(<span style="color: #993399">1</span> <span style="color: #990000">+</span> <span style="color: #009900">C</span>, <span style="font-weight: bold"><span style="color: #000080">?UTF8D</span></span>), <span style="font-weight: bold"><span style="color: #000080">?UTF8D</span></span>))<span style="color: #990000">.</span></tt></pre></div></div>
-<div class="paragraph"><p>The macro <code>?UTF8D</code> is the tuple equivalent of the C array
-in the original code.</p></div>
-<div class="paragraph"><p>Compared to our previous algorithm, this performed about the same.
-In some situations a little faster, in some a little slower. In other words,
-not good enough. But because this new algorithm allows us to avoid a binary
-concatenation this warranted looking further.</p></div>
-<div class="paragraph"><p>It was time to step into crazy land.</p></div>
-<div class="paragraph"><p>Erlang is very good at pattern matching, even more so than doing some
-arithmetic coupled by fetching elements from a tuple. So I decided I was
-going to write all possible clauses for all combinations of <code>C</code>
-and <code>State</code>. And by write I mean generate.</p></div>
-<div class="paragraph"><p>So I opened my Erlang shell, defined the variable <code>D</code> to be
-the tuple <code>?UTF8D</code> with its 400 elements, and then ran the
-following expression (after a bit of trial and error):</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="color: #993399">16</span><span style="color: #990000">&gt;</span> <span style="font-weight: bold"><span style="color: #000000">file:write_file</span></span>(<span style="color: #FF0000">"out.txt"</span>,
- [<span style="font-weight: bold"><span style="color: #000000">io_lib:format</span></span>(<span style="color: #FF0000">"validate_utf8(&lt;&lt; ~p, Rest/bits &gt;&gt;, ~p) -&gt; ~p;~n"</span>,
- [<span style="color: #009900">C</span>, <span style="color: #009900">S</span>, <span style="font-weight: bold"><span style="color: #000080">element</span></span>(<span style="color: #993399">257</span> <span style="color: #990000">+</span> <span style="color: #009900">S</span> <span style="color: #990000">*</span> <span style="color: #993399">16</span> <span style="color: #990000">+</span> <span style="font-weight: bold"><span style="color: #000080">element</span></span>(<span style="color: #993399">1</span> <span style="color: #990000">+</span> <span style="color: #009900">C</span>, <span style="color: #009900">D</span>), <span style="color: #009900">D</span>)])
- || <span style="color: #009900">C</span> <span style="color: #990000">&lt;-</span> <span style="font-weight: bold"><span style="color: #000000">lists:seq</span></span>(<span style="color: #993399">0</span>,<span style="color: #993399">255</span>), <span style="color: #009900">S</span> <span style="color: #990000">&lt;-</span> <span style="font-weight: bold"><span style="color: #000000">lists:seq</span></span>(<span style="color: #993399">0</span>,<span style="color: #993399">8</span>)])<span style="color: #990000">.</span>
-<span style="color: #FF6600">ok</span></tt></pre></div></div>
-<div class="paragraph"><p>The result is a 2304 lines long file, containing 2304 clauses.
-People who pay attention to what I say on Twitter will remember
-I said something around 3000 clauses, but that was just me not
-using the right number of states in my estimate.</p></div>
-<div class="paragraph"><p>There was a little more work to be done on this generated
-code that I did using regular expressions. We need to recurse
-when the resulting state is not 1. We also need to stop when
-the binary is empty, making it the 2305th clause.</p></div>
-<div class="paragraph"><p>Still, 2305 is a lot. But hey, the code did work, and faster
-than the previous implementation too! But hey, perhaps I could
-find a way to reduce its size.</p></div>
-<div class="paragraph"><p>Removing all the clauses that return 1 and putting a catch-all
-clause at the end instead reduced the number to about 500, and
-showed that many clauses were similar:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #993399">0</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">0</span>) <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #993399">1</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">0</span>) <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #993399">2</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">0</span>) <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #993399">3</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">0</span>) <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #993399">4</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">0</span>) <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #993399">5</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">0</span>) <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #993399">6</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">0</span>) <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #993399">7</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">0</span>) <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>);</tt></pre></div></div>
-<div class="paragraph"><p>But also:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #993399">157</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">2</span>) <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #993399">157</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">3</span>) <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #993399">157</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">5</span>) <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #993399">157</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">6</span>) <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #993399">157</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">7</span>) <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #993399">158</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">2</span>) <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #993399">158</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">3</span>) <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #993399">158</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">5</span>) <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #993399">158</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">6</span>) <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #993399">158</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">7</span>) <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>);</tt></pre></div></div>
-<div class="paragraph"><p>Patterns, my favorites!</p></div>
-<div class="paragraph"><p>A little more time was spent to edit the 500 or so clauses into
-smaller equivalents, testing that performance was not impacted, and
-comitting the result.</p></div>
-<div class="paragraph"><p>The patterns above can be found here in the resulting function:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">0</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">&lt;</span> <span style="color: #993399">128</span> <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>);
-<span style="color: #990000">...</span>
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">2</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">&gt;=</span> <span style="color: #993399">144</span>, <span style="color: #009900">C</span> <span style="color: #990000">&lt;</span> <span style="color: #993399">160</span> <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">0</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">3</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">&gt;=</span> <span style="color: #993399">144</span>, <span style="color: #009900">C</span> <span style="color: #990000">&lt;</span> <span style="color: #993399">160</span> <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">5</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">&gt;=</span> <span style="color: #993399">144</span>, <span style="color: #009900">C</span> <span style="color: #990000">&lt;</span> <span style="color: #993399">160</span> <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">2</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">6</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">&gt;=</span> <span style="color: #993399">144</span>, <span style="color: #009900">C</span> <span style="color: #990000">&lt;</span> <span style="color: #993399">160</span> <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>);
-<span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #990000">&lt;&lt;</span> <span style="color: #009900">C</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span> <span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">7</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">C</span> <span style="color: #990000">&gt;=</span> <span style="color: #993399">144</span>, <span style="color: #009900">C</span> <span style="color: #990000">&lt;</span> <span style="color: #993399">160</span> <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">validate_utf8</span></span>(<span style="color: #009900">Rest</span>, <span style="color: #993399">3</span>);
-<span style="color: #990000">...</span></tt></pre></div></div>
-<div class="paragraph"><p>I hope you enjoyed this post.</p></div>
-</description> + <description>Yesterday I pushed Websocket permessage-deflate to Cowboy master. I also pushed a change in the way the code validates UTF-8 data (required for text and close frames as per the spec). + When looking into why the permessage-deflate tests in autobahntestsuite were taking such a long time, I found that autobahn is using an adaptation of the algorithm named Flexible and Economical UTF-8 Decoder. This is the C99 implementation: + // Copyright (c) 2008-2009 Bjoern Hoehrmann &lt;bjoern@hoehrmann.</description> </item> <item> @@ -988,124 +141,7 @@ http://www.gnu.org/software/src-highlite --> <pubDate>Fri, 05 Sep 2014 00:00:00 +0100</pubDate> <guid>https://ninenines.eu/articles/on-open-source/</guid> - <description><div class="paragraph"><p>Last week I read a great article
-<a href="http://videlalvaro.github.io/2014/08/on-contributing-to-opensource.html">on
-contributing to open source</a> by Alvaro Videla. He makes
-many great points and I am in agreement with most of it.
-This made me want to properly explain my point of view with
-regard to open source and contributions. Unlike most open
-source evangelism articles I will not talk about ideals or
-any of that crap, but rather my personal feelings and
-experience.</p></div>
-<div class="paragraph"><p>I have been doing open source work for quite some time.
-My very first open source project was a graphics driver
-for (the very early version of) the PCSX2 emulator. That
-was more than ten years ago, and there
-<a href="http://ngemu.com/threads/gstaris-0-6.30469/">isn&#8217;t
-much left to look at today</a>. This was followed by a
-<a href="https://github.com/extend/wee">PHP framework</a>
-(started long before Zend Framework was even a thing) and
-a few other small projects. None of them really took off.
-It&#8217;s alright, that&#8217;s pretty much the fate of most open
-source projects. You spend a lot of work and sweat and
-get very little in return from others.</p></div>
-<div class="paragraph"><p>This sounds harsh but this is the reality of all open
-source projects. If you are thinking of building a project
-and releasing it as open source, you should be prepared
-for that. This is how most of your projects will feel like.
-Don&#8217;t release a project as open source thinking everyone
-will pat you on the back and cheer, this won&#8217;t happen. In
-fact if your project is a too small improvement over existing
-software, what many people will do is say you have NIH
-syndrome, regardless of the improvement you bring. So you
-need not to rely on other people in order to get your
-enjoyment out of building open source software.</p></div>
-<div class="paragraph"><p>In my case I get enjoyment from thinking about problems
-that need solving. Often times the problems are already
-solved, but nevermind that, I still think about them and
-sometimes come up with something I feel is better and then
-write code for it. Writing code is also fun, but not as
-fun as using my brain to imagine solutions.</p></div>
-<div class="paragraph"><p>You don&#8217;t need thousands of users to do that. So are
-users worthless to me then? No, of course not. In fact
-they are an important component: they bring me problems
-that need solving. So users are very important to me.
-But that&#8217;s not the only reason.</p></div>
-<div class="paragraph"><p>I got lucky that the Cowboy project became popular.
-And seeing it be this popular, and some of my other projects
-also do quite well, made me believe I could perhaps work
-full time on open source. If I can work full time then
-I can produce better software. What I had one hour to
-work on before I can now spend a day on, and experiment
-until I am satisfied. This is very useful because that
-means I can get it almost right from the beginning, and
-avoid the million API breaking changes that occured
-before Cowboy 1.0 was released.</p></div>
-<div class="paragraph"><p>To be able to work full time on open source however,
-I need money. This is a largely unspoken topic of open
-source work. The work is never free. You can download the
-product for free, but someone has to pay for the work
-itself. Life is unfortunately not free.</p></div>
-<div class="paragraph"><p>Large projects and some lucky people have their work
-sponsored by their employers. Everyone else has to deal
-with it differently. In my case I was sponsored for a
-while by the <a href="http://leo-project.net/leofs/">LeoFS</a>
-project, but that ended. I also had the Farwest fundraiser,
-which was a success, although the project stalled after that.
-(Fear not, as Farwest will make a comeback as a conglomerate
-of Web development projects in the future.) After that I set
-up the <a href="http://ninenines.eu/support/">sponsoring scheme</a>,
-which I can proudly say today brings in enough money to
-cover my food and shelter. Great!</p></div>
-<div class="paragraph"><p>This is a start, but it&#8217;s of course not enough. Life
-is a little more than food and shelter, and so I am still
-looking for sponsors. This is not a very glorious experience,
-as I am essentially looking for scraps that companies can
-throw away. Still, if a handful more companies were doing
-that, not only would I be able to live comfortably, but I
-would also be able to stop worrying about the future as I
-could put money on the side for when it gets rough.</p></div>
-<div class="paragraph"><p>A few companies giving me some scrap money so I could
-live and work independently is by far the most important
-thing anyone can do to help my projects, including Cowboy.
-Yes, they&#8217;re even more important than code contributions,
-bug reports and feedback. Because this money gives me the
-time I need to handle the code contributions, bug reports
-and feedback.</p></div>
-<div class="paragraph"><p>If Cowboy or another project is a large part of your
-product or infrastructure, then the best thing you can do
-is become a sponsor. The second best is opening tickets
-and/or providing feedback. The third best is providing
-good code contributions.</p></div>
-<div class="paragraph"><p>I will not expand on the feedback part. Feedback is
-very important, and even just a high five or a retweet
-is already good feedback. It&#8217;s not very complicated.</p></div>
-<div class="paragraph"><p>I want to expand a little on code contributions
-however. Not long ago I ran across the term "patch bomb"
-which means dropping patches and expecting the project
-maintainers to merge them and maintain them. I receive
-a lot of patches, and often have to refuse them. Causes
-for refusal vary. Some patches only benefit the people
-who submitted them (or a very small number of people).
-Some patches are not refined enough to be included.
-Others are out of scope of the project. These are some
-of the reasons why I refuse patches. Having limited
-time and resources, I have to focus my efforts on the
-code used by the larger number of users. I have to
-prioritize patches from submitters who are reactive
-and address the issues pointed out. And I have to plainly
-refuse other patches.</p></div>
-<div class="paragraph"><p>I believe this wraps up my thoughts on open source.
-Overall I had a great experience, the Erlang community
-being nice and understanding of the issues at hand in
-general. And if the money problem could be solved soon,
-then I would be one of the luckiest and happiest open
-source developer on Earth.</p></div>
-<div class="paragraph"><p>Think about it the next time you see a donation button
-or a request for funds or sponsoring. You can considerably
-improve an open source developer&#8217;s life with very little
-of your company&#8217;s money.</p></div>
-</description> + <description>Last week I read a great article on contributing to open source by Alvaro Videla. He makes many great points and I am in agreement with most of it. This made me want to properly explain my point of view with regard to open source and contributions. Unlike most open source evangelism articles I will not talk about ideals or any of that crap, but rather my personal feelings and experience.</description> </item> <item> @@ -1114,231 +150,7 @@ of your company&#8217;s money.</p></div> <pubDate>Sat, 23 Aug 2014 00:00:00 +0100</pubDate> <guid>https://ninenines.eu/articles/the-story-so-far/</guid> - <description><div class="paragraph"><p>As I am away from home with little to do (some call this
-a vacation) I wanted to reflect a little on the story so far,
-or how I arrived to Erlang and got to where I am now. The
-raw personal experience. It&#8217;ll be an article that&#8217;s more
-about social aspect, communities and marketing a project than
-technical considerations. As a period piece, it will also
-allow me to reflect on the evolution of Erlang in recent
-years.</p></div>
-<div class="paragraph"><p>Once upon a time-- Okay this isn&#8217;t a fairy tale. The story
-begins with a short chapter in 2010. The year 2010 started
-with a fairly major event in my life: the US servers for the
-online game I stopped playing a few months before, but was
-still involved with through its community, were closing. OMG!
-Someone found a way to log packets and started working on a
-private server; meanwhile the JP servers were still up. And
-that&#8217;s pretty much it.</p></div>
-<div class="paragraph"><p>Fast forward a few months and it became pretty clear that
-the private server was going nowhere considering all the drama
-surrounding it-- which is actually not unusual, but it was
-more entertaining than average and the technical abilities of
-people running the project were obviously lacking so I decided
-to obtain those logged packets and look at things myself. I
-didn&#8217;t want to do a private server yet, I only wanted to take
-a peek to see how things worked, and perhaps organize some
-effort to document the protocol.</p></div>
-<div class="paragraph"><p>There was 10GB of logs. I didn&#8217;t have an easy to use
-language to analyze them, and hex editors wouldn&#8217;t cut it for
-most purposes, so I had to look elsewhere. This was a good
-opportunity to start learning this PHP killer I read about
-before, which also happens to feature syntax for matching
-binaries, called Erlang. To be perfectly honest I wouldn&#8217;t
-have touched the logs if I didn&#8217;t have the added motivation
-to play with and learn a new language.</p></div>
-<div class="paragraph"><p>At the time it was pretty hard to learn Erlang. In my
-experience there was Joe&#8217;s book (which I always recommend
-first as I believe it is the best to learn the Erlang side
-of things; but falls a little short on OTP), and there was
-about 5 chapters of LYSE. There were a couple other books
-I never managed to get into (sorry guys), and there was also
-a few interesting blogs, some of which I can&#8217;t find anymore.
-Finally the #erlang IRC community was there but I was strictly
-lurking at the time.</p></div>
-<div class="paragraph"><p>What a difference compared to 4 years later! (That&#8217;s
-today, by the way!) Now we have more books than I can
-remember, tons of articles covering various aspects of the
-language and platform, many targeting beginners but a good
-number of them also about advanced topics. We even have a
-free online book, LYSE, with more than 30 chapters covering
-pretty much everything. Needless to say I never finished
-reading LYSE as it got written slower than I learnt.</p></div>
-<div class="paragraph"><p>Back to 2010. I wrote a parser for the logs, and
-aggregated those results into one CSV file per packet type
-so I could open them in Gnumeric and aggregate some more,
-but manually this time, and draw conclusions on the packet
-structures. That was pretty easy. Even for a beginner.
-Anyone can go from zero to that level in a day or two.
-Then, having mastered binary pattern matching, I wanted
-to learn some more Erlang, by making this aggregation
-faster. What I had done before worked, but I wasn&#8217;t going
-to wait forever to process everything sequentially. So I
-looked and found a project called <code>plists</code> (still exists,
-but not maintained AFAIK). I downloaded that project and
-replaced my <code>lists:</code> calls to <code>plists:</code>.
-Boom. In just a few minutes all logs were processed, and
-I had learnt something new.</p></div>
-<div class="paragraph"><p>It is particularly interesting to note that the lack of
-a package manager or index never bothered me. Neither before
-nor after learning Erlang. My experience with package
-managers was mostly related to Ubuntu, a little Perl and
-Python, and PHP&#8217;s Pear. Let&#8217;s just stay polite and say it
-was always a terrible experience. So searching on the Web
-didn&#8217;t feel awkward, because even if I used a tool or
-website I would have ended up doing a search or two anyway.
-This is in contrast to the package index feature in
-<a href="https://github.com/ninenines/erlang.mk">Erlang.mk</a>,
-which is meant to simplify specifying dependencies more
-than anything: <code>DEPS = cowboy</code>. It does not
-attempt to solve any other problem, and will only attempt
-to solve one extra problem in the near future, which is
-the discovery of packages. So expect some kind of website
-listing packages soon enough.</p></div>
-<div class="paragraph"><p>I want to use this parenthese to also point out that at
-the time there was a very small number of projects out there,
-at least compared to today. While you sometimes hear people
-complain about lack of certain libraries, it is so much
-better now than it was before! The situation improves very
-quickly, so much that it&#8217;s not going to be that big an issue
-soon enough.</p></div>
-<div class="paragraph"><p>Wanting to know more about that game&#8217;s protocol, in the
-year 2010, I ended up starting to write more Erlang code to
-simulate a server and use the server to query the client and
-see what was happening, documenting the packets and so on.
-This eventually lead to a larger project implementing more
-and more until people got their hopes up for a revival of
-the game, all the while the now competing original server
-project died in a stream of drama and technical incompetence.
-Of course, I ended up doing what any good Internet citizen
-would do, I crushed people&#8217;s hopes, but that&#8217;s not important
-to our story. The important part is that before giving up
-on this project, I not only learnt a good deal of Erlang
-and a little deal of OTP (which I did not touch until 6
-months after I started with Erlang; see the paragraph
-about learning material above), but I also had an intriguing
-idea pop into my mind for what would become my greatest
-success yet.</p></div>
-<div class="paragraph"><p>The giving up part was not easy. Having had financial
-difficulties all year 2010 and part of 2009, I resolved
-to travel back to Paris to try and make it. I ended up
-sleeping in offices for 6 months, being hosted by a shady
-person, and hearing my fair share of stories about
-the dark side of business. While there I also worked for
-another company with someone who would end up becoming
-another high profile Erlang developer. The situation
-slowly improved, I started taking part in the #erlang
-IRC discussions, giving up my status of lurker and, a
-few months into 2011, started working on the Apache killer
-project: Cowboy.</p></div>
-<div class="paragraph"><p>This is the part where I probably should get accused of
-racism and other fun things, but I never did. And I think
-that speaks lots about the Erlang community. In all my time
-writing Erlang code, I can count the number of conflicts I
-had with other people on a single hand. This is the nicest
-programming community I have ever seen, by far. And the
-humblest too. The Erlang community feels like Japan. And
-I love Japan. So I love the Erlang community. I can&#8217;t say
-this enough. This is something that stayed true for all
-my time using Erlang, and despite the rise of alternative
-languages that are not Japan the Erlang community has
-remained very Japan.</p></div>
-<div class="paragraph"><p>The first published version of Cowboy was written in
-two weeks. A little before those two weeks, during, and
-a while after, pretty much everything I said on the
-Internets was that Cowboy was going to be the greatest
-HTTP server ever, that the other servers were problematic
-(and just to be clear, Yaws was rarely if ever mentioned,
-due to being in a perceived different league of "full
-featured servers" while Cowboy was a "lightweight server"),
-and that Cowboy will be the best replacement to a Mochiweb
-or Misultin application. This, alongside a lot of time
-spent on IRC telling people to use Cowboy when they were
-asking for an HTTP server to use, probably made me sound
-very annoying. But it worked, and Cowboy started getting
-its first users, despite being only a few weeks old. Of
-course, as soon as I got my very first user, I started
-claiming Cowboy had "a lot of users".</p></div>
-<div class="paragraph"><p>Looking back today I would definitely find myself annoying,
-this wasn&#8217;t just an idle comment there. For about a year,
-maybe a little more, all I ever said was that Cowboy was
-the best. This probably made me a little dumber in the
-process (as if I wasn&#8217;t enough! I know). Being French, I
-sometimes would also say things quite abruptly. To stay
-polite, I probably sounded like an asshole. I learnt to
-stop being so French over time thankfully.</p></div>
-<div class="paragraph"><p>I think what was most important to Cowboy at the time,
-was three things. First, it felt fresh. It was new, had new
-ideas, tried to do things differently and followed "new" old
-best practices (the OTP way-- which was simply too obscure
-for most people at the time). Second, it had me spending
-all my time telling people to use it whenever they were
-looking for an HTTP server. Third, it had me helping people
-get started with it and guide them all the steps of the way.
-Mostly because it didn&#8217;t have a very good documentation, but
-still, hand holding does wonders.</p></div>
-<div class="paragraph"><p>To be able to help people every time they had a problem,
-I did not spend all my days reading IRC. Instead I simply
-made sure to be notified when someone said <code>cowboy</code>.
-The same way many people subscribe to alerts when their
-company is mentioned in the news. Nothing fancy.</p></div>
-<div class="paragraph"><p>Time went on, Cowboy grew, or as some like to say,
-completely destroyed the competition, and many people
-eventually moved from Mochiweb and Misultin to Cowboy.
-And then Roberto Ostinelli stopped Misultin development
-and told everyone to move to Cowboy. This is the most
-humble and selfless act I have ever seen in the programming
-sphere, and I only have one thing to say about it: GG.
-Thanks for the fish. He left me with the tasks of improving
-Cowboy examples, documentation and strongly believed that
-the Misultin interface was more user friendly out of all
-the servers. So I added many examples, as many lines of
-documentation as we have of code, and strongly believe
-that Cowboy 2.0 will be the most user friendly interface
-out of all servers. But only time will tell.</p></div>
-<div class="paragraph"><p>With the rise of the project and the rise in the number
-of users, my previous strategy (completely incidental, by
-the way, and definitely not a well thought out plan to
-become popular) stopped working. It was taking me too much
-time. The important aspects slowly drifted. If I wanted to
-support more users, I would have to spend less time with
-each individual user. This was actually a hard problem.
-You basically have to make people understand they can&#8217;t
-just come to you directly when they have a problem, they
-have to follow proper channels. It becomes less personal,
-and might be felt like you don&#8217;t care about them anymore.
-You have to hurt some people&#8217;s feelings at this point. It
-is quite unfortunate, and also quite difficult to do. There
-is some unwritten rule that says early adopters deserve
-more, but in the real world it never works like this. So
-I probably hurt some people&#8217;s feelings at some point. But
-that&#8217;s okay. Because even if you make sure to be as nice
-as possible when you tell people to go through proper
-channels from now on, some people will still get offended.
-There&#8217;s nothing you can do about it.</p></div>
-<div class="paragraph"><p>From that point onward the important points about the
-project was getting the documentation done, making sure
-people knew about the proper channels to get help and
-report issues, etc. Basically making myself less needed.
-This is quite a contrast with the first days, but I believe
-Cowboy made that transition successfully.</p></div>
-<div class="paragraph"><p>Not only did I win time by not having to hold hands with
-everyone all the time (not that I didn&#8217;t like it, but you
-know, the sweat), but I also won time thanks to the increased
-project popularity. Indeed, the more users you have, the more
-annoying guys there are to tell people to use your project
-and that it&#8217;s the best and everything. Which is great. At
-least, it&#8217;s great if you don&#8217;t pay too much attention to it.
-Sometimes people will give an advice that is, in your opinion,
-a bad advice. And that&#8217;s okay. Don&#8217;t intervene every time
-someone gives a bad advice, learn to let it go. People will
-figure it out. You learn by making mistakes, after all. Use
-this extra time to make sure other people don&#8217;t end up
-giving the same bad advice instead. Fix the code or the
-documentation that led to this mistake. Slowly improve the
-project and make sure it doesn&#8217;t happen again.</p></div>
-<div class="paragraph"><p>This is my story. So far, anyway.</p></div>
-</description> + <description>As I am away from home with little to do (some call this a vacation) I wanted to reflect a little on the story so far, or how I arrived to Erlang and got to where I am now. The raw personal experience. It&#8217;ll be an article that&#8217;s more about social aspect, communities and marketing a project than technical considerations. As a period piece, it will also allow me to reflect on the evolution of Erlang in recent years.</description> </item> <item> @@ -1347,156 +159,8 @@ project and make sure it doesn&#8217;t happen again.</p></div> <pubDate>Wed, 20 Aug 2014 00:00:00 +0100</pubDate> <guid>https://ninenines.eu/articles/cowboy2-qs/</guid> - <description><div class="paragraph"><p>Now that Cowboy 1.0 is out, I can spend some of my time thinking
-about Cowboy 2.0 that will be released soon after Erlang/OTP 18.0.
-This entry discusses the proposed changes to query string handling
-in Cowboy.</p></div>
-<div class="paragraph"><p>Cowboy 2.0 will respond to user wishes by simplifying the interface
-of the <code>cowboy_req</code> module. Users want two things: less
-juggling with the Req variable, and more maps. Maps is the only
-dynamic key/value data structure in Erlang that we can match directly
-to extract values, allowing users to greatly simplify their code as
-they don&#8217;t need to call functions to do everything anymore.</p></div>
-<div class="paragraph"><p>Query strings are a good candidate for maps. It&#8217;s a list of
-key/values, so it&#8217;s pretty obvious we can win a lot by using maps.
-However query strings have one difference with maps: they can have
-duplicate keys.</p></div>
-<div class="paragraph"><p>How are we expected to handle duplicate keys? There&#8217;s no standard
-behavior. It&#8217;s up to applications. And looking at what is done in
-the wild, there&#8217;s no de facto standard either. While some ignore
-duplicate keys (keeping the first or the last they find), others
-require duplicate keys to end with <code>[]</code> to automatically
-put the values in a list, or even worse, languages like PHP even
-allow you to do things like <code>key[something][other]</code> and
-create a deep structure for it. Finally some allow any key to have
-duplicates and just gives you lists of key/values.</p></div>
-<div class="paragraph"><p>Cowboy so far had functions to retrieve query string values one
-value at a time, and if there were duplicates it would return the
-first it finds. It also has a function returning the entire list
-with all duplicates, allowing you to filter it to get all of them,
-and another function that returns the raw query string.</p></div>
-<div class="paragraph"><p>What are duplicates used for? Not that many things actually.</p></div>
-<div class="paragraph"><p>One use of duplicate keys is with HTML forms. It is common practice
-to give all related checkboxes the same name so you get a list of
-what&#8217;s been checked. When nothing is checked, nothing is sent at all,
-the key is not in the list.</p></div>
-<div class="paragraph"><p>Another use of duplicate keys is when generating forms. A good
-example of that would be a form that allows uploading any number
-of files. When you add a file, client-side code adds another field
-to the form. Repeat up to a certain limit.</p></div>
-<div class="paragraph"><p>And that&#8217;s about it. Of note is that HTML radio elements share
-the same name too, but only one key/value is sent, so they are not
-relevant here.</p></div>
-<div class="paragraph"><p>Normally this would be the part where I tell you how we solve
-this elegantly. But I had doubts. Why? Because there&#8217;s no good
-solutions to solving only this particular problem.</p></div>
-<div class="paragraph"><p>I then stopped thinking about duplicate keys for a minute and
-started to think about the larger problem.</p></div>
-<div class="paragraph"><p>Query strings are input data. They take a particular form,
-and may be sent as part of the URI or as part of the request
-body. We have other kinds of input data. We have headers and
-cookies and the request body in various forms. We also have
-path segments in URIs.</p></div>
-<div class="paragraph"><p>What do you do with input data? Well you use it to do
-something. But there is one thing that you almost always do
-(and if you don&#8217;t, you really should): you validate it and
-you map it into Erlang terms.</p></div>
-<div class="paragraph"><p>Cowboy left the user take care of validation and conversion
-into Erlang terms so far. Rather, it left the user take care
-of it everywhere except one place. Guess where? That&#8217;s right,
-bindings.</p></div>
-<div class="paragraph"><p>If you define routes with bindings then you have the option
-to provide constraints. Constraints can be used to do two things:
-validate the data and convert it in a more appropriate term. For
-example if you use the <code>int</code> constraint, Cowboy will
-make sure the binding is an integer, and will replace the value
-with the integer representation so that you can use it directly.
-In this particular case it not only routes the URI, but also
-validates and converts the bindings directly.</p></div>
-<div class="paragraph"><p>This is very relevant in the case of our duplicate keys,
-because if we have a list with duplicates of a key, chances
-are we want to convert that into a list of Erlang terms, and
-also make sure that all the elements in this list are expected.</p></div>
-<div class="paragraph"><p>The answer to this particular problem is simple. We need a
-function that will parse the query string and apply constraints.
-But this is not all, there is one other problem to be solved.</p></div>
-<div class="paragraph"><p>The other problem is that for the user some keys are mandatory
-and some are optional. Optional keys include the ones that
-correspond to HTML checkboxes: if the key for one or more
-checkbox is missing from the query string, we still want to
-have an empty list in our map so we can easily match. Matching
-maps is great, but not so much when values might be missing,
-so we have to normalize this data a little.</p></div>
-<div class="paragraph"><p>This problem is solved by allowing a default value. If the
-key is missing and a default exists, set it. If no default
-exists, then the key was mandatory and we want to crash.</p></div>
-<div class="paragraph"><p>I therefore make a proposal for changing the query string
-interface to three functions.</p></div>
-<div class="paragraph"><p>The first function already exists, it is <code>cowboy_req:qs(Req)</code>
-and it returns only the query string binary. No more Req returned.</p></div>
-<div class="paragraph"><p>The second function is a renaming of <code>cowboy_req:qs_vals(Req)</code>
-to something more explicit: <code>cowboy_req:parse_qs(Req)</code>.
-The new name implies that a parsing operation is done. It was implicit
-and cached before. It will be explicit and not cached anymore now.
-Again, no more Req returned.</p></div>
-<div class="paragraph"><p>The third function is the one I mentioned above. I think
-the interface <code>cowboy_req:match_qs(Req, Fields)</code> is
-most appropriate. It returns a normalized map that is the same
-regardless of optional fields being provided with the request,
-allowing for easy matching. It crashes if something went wrong.
-Still no Req returned.</p></div>
-<div class="paragraph"><p>I feel that this three function interface provides everything
-one would need to comfortably write applications. You can get
-low level and get the query string directly; you can get a list
-of key/value binaries without any additional processing and do it
-on your own; or you can get a processed map that contains Erlang
-terms ready to be used.</p></div>
-<div class="paragraph"><p>I strongly believe that by democratizing the constraints to
-more than just bindings, but also to query string, cookies and
-other key/values in Cowboy, we can allow the developer to quickly
-and easily go from HTTP request to Erlang function calls. The
-constraints are reusable functions that can serve as guards
-against unwanted data, providing convenience in the process.</p></div>
-<div class="paragraph"><p>Your handlers will not look like an endless series of calls
-to get and convert the input data, they will instead be just
-one call at the beginning followed by the actual application
-logic, thanks to constraints and maps.</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="font-weight: bold"><span style="color: #000000">handle</span></span>(<span style="color: #009900">Req</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-&gt;</span>
- #{<span style="color: #FF6600">name</span><span style="color: #990000">:=</span><span style="color: #009900">Name</span>, <span style="color: #FF6600">email</span><span style="color: #990000">:=</span><span style="color: #009900">Email</span>, <span style="color: #FF6600">choices</span><span style="color: #990000">:=</span><span style="color: #009900">ChoicesList</span>, <span style="color: #FF6600">remember_me</span><span style="color: #990000">:=</span><span style="color: #009900">RememberMe</span>} <span style="color: #990000">=</span>
- <span style="font-weight: bold"><span style="color: #000000">cowboy_req:match_qs</span></span>(<span style="color: #009900">Req</span>, [
- <span style="font-weight: bold"><span style="color: #000080">name</span></span>, {<span style="color: #FF6600">email</span>, <span style="color: #FF6600">email</span>},
- {<span style="color: #FF6600">choices</span>, <span style="font-weight: bold"><span style="color: #0000FF">fun</span></span> <span style="font-weight: bold"><span style="color: #000000">check_choices</span></span><span style="color: #990000">/</span><span style="color: #993399">1</span>, []},
- {<span style="color: #FF6600">remember_me</span>, <span style="color: #FF6600">boolean</span>, <span style="color: #000080">false</span>}]),
- <span style="font-weight: bold"><span style="color: #000000">save_choices</span></span>(<span style="color: #009900">Name</span>, <span style="color: #009900">Email</span>, <span style="color: #009900">ChoicesList</span>),
- <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #009900">RememberMe</span> <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">create_account</span></span>(<span style="color: #009900">Name</span>, <span style="color: #009900">Email</span>); <span style="color: #000080">true</span> <span style="color: #990000">-&gt;</span> <span style="color: #FF6600">ok</span> <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>,
- {<span style="color: #FF6600">ok</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>}<span style="color: #990000">.</span>
-
-<span style="font-weight: bold"><span style="color: #000000">check_choices</span></span>(<span style="color: #990000">&lt;&lt;</span><span style="color: #FF0000">"blue"</span><span style="color: #990000">&gt;&gt;</span>) <span style="color: #990000">-&gt;</span> {<span style="color: #000080">true</span>, <span style="color: #FF6600">blue</span>};
-<span style="font-weight: bold"><span style="color: #000000">check_choices</span></span>(<span style="color: #990000">&lt;&lt;</span><span style="color: #FF0000">"red"</span><span style="color: #990000">&gt;&gt;</span>) <span style="color: #990000">-&gt;</span> {<span style="color: #000080">true</span>, <span style="color: #FF6600">red</span>};
-<span style="font-weight: bold"><span style="color: #000000">check_choices</span></span>(<span style="color: #990000">_</span>) <span style="color: #990000">-&gt;</span> <span style="color: #000080">false</span>;</tt></pre></div></div>
-<div class="paragraph"><p>(Don&#8217;t look too closely at the structure yet.)</p></div>
-<div class="paragraph"><p>As you can see in the above snippet, it becomes really easy
-to go from query string to values. You can also use the map
-directly as it is guaranteed to only contain the keys you
-specified, any extra key is not returned.</p></div>
-<div class="paragraph"><p>This would I believe be a huge step up as we can now
-focus on writing applications instead of translating HTTP
-calls. Cowboy can now take care of it.</p></div>
-<div class="paragraph"><p>And to conclude, this also solves our duplicate keys
-dilemma, as they now automatically become a list of binaries,
-and this list is then checked against constraints that
-will fail if they were not expecting a list. And in the
-example above, it even converts the values to atoms for
-easier manipulation.</p></div>
-<div class="paragraph"><p>As usual, feedback is more than welcome, and I apologize
-for the rocky structure of this post as it contains all the
-thoughts that went into this rather than just the conclusion.</p></div>
-</description> + <description>Now that Cowboy 1.0 is out, I can spend some of my time thinking about Cowboy 2.0 that will be released soon after Erlang/OTP 18.0. This entry discusses the proposed changes to query string handling in Cowboy. + Cowboy 2.0 will respond to user wishes by simplifying the interface of the cowboy_req module. Users want two things: less juggling with the Req variable, and more maps. Maps is the only dynamic key/value data structure in Erlang that we can match directly to extract values, allowing users to greatly simplify their code as they don&#8217;t need to call functions to do everything anymore.</description> </item> <item> @@ -1505,147 +169,121 @@ thoughts that went into this rather than just the conclusion.</p></div& <pubDate>Tue, 07 Jan 2014 00:00:00 +0100</pubDate> <guid>https://ninenines.eu/articles/january-2014-status/</guid> - <description><div class="paragraph"><p>I will now be regularly writing posts about project status, plans
-and hopes for the future.</p></div>
-<div class="paragraph"><p>Before that though, there&#8217;s one important news to share.</p></div>
-<div class="paragraph"><p>Until a year ago all development was financed through consulting
-and development services. This worked alright but too much time was
-spent doing things that didn&#8217;t benefit the open source projects.
-And that didn&#8217;t make me happy at all. Because I like being happy
-I stopped that for the most part and spent the year figuring things
-out, experimenting and discussing with people about it.</p></div>
-<div class="paragraph"><p>What makes me happy is answering these "what if" questions.
-Ranch and Cowboy are a direct product of that, as they originate
-from the "what if we could have a server running different protocols
-on different ports but all part of the same application?"; Erlang.mk
-is a bit different: "this works great for me, what if it could
-become the standard solution for building Erlang applications?".</p></div>
-<div class="paragraph"><p>When I successfully answer the question, this becomes a project
-that may end up largely benefiting the Erlang community. I love
-Erlang and I love enabling people to build awesome products based
-on my projects. It&#8217;s a lot more rewarding than activities like
-consulting where you only help one company at a time. And it&#8217;s
-also a much better use of my time as this has a bigger impact on
-the community.</p></div>
-<div class="paragraph"><p>The hard part is to figure out how to be able to spend 100%
-of the time on projects that you basically give away for free,
-and still be able to afford living.</p></div>
-<div class="paragraph"><p>The immediate solution was getting work sponsored by the
-<a href="http://www.leofs.org/">LeoFS project</a>. LeoFS is a great
-distributed file storage that I can only recommend to anyone who
-needs to store files or large pieces of data. The sponsorship
-works pretty great, and spurred development of the SPDY code in
-Cowboy amongst other things, plus a couple upcoming projects
-done more recently and getting a final touch before release.</p></div>
-<div class="paragraph"><p>It turns out sponsoring works great. So I&#8217;m thinking of
-expanding on it and hopefully get enough sponsoring for fulltime
-open source development. So I figured out a few things that
-can give incentive to companies willing to sponsor.</p></div>
-<div class="paragraph"><p>Sponsors can <em>request that a particular version of Cowboy
-be maintained indefinitely</em> (as long as they&#8217;re sponsoring).
-This means fixes will be backported. This doesn&#8217;t include
-features although I can take requests depending on feasability.</p></div>
-<div class="paragraph"><p>Sponsors can <em>have a direct, private line of communication</em>,
-useful when they need help debugging or optimizing their product.</p></div>
-<div class="paragraph"><p>Sponsors can <em>get their name associated with one of the
-project</em> and get a good standing in the community thanks
-to this. They would be featured in the README of the project
-which is viewed by hundreds of developers daily.</p></div>
-<div class="paragraph"><p>Sponsors can <em>be listed on this website</em>. I will modify
-the front page when we get a few more sponsors, they will be
-featured below the carousel of projects.</p></div>
-<div class="paragraph"><p>Please <a href="mailto:[email protected]">contact us</a> if
-you are interested in sponsoring, and say how much you are willing
-to sponsor. The goal here is only to have enough money to make a
-living and attend a few conferences. There&#8217;s an upper limit in the
-amount needed per year, so the more sponsors there are the cheaper
-it becomes to everyone.</p></div>
-<div class="paragraph"><p>The upper limit stems from the new legal entity that will replace
-the current Nine Nines. This is mostly to lower the legal costs and
-simplify the administrative stuff and allow me to dedicate all my
-time on what&#8217;s important. From your point of view it&#8217;s business as
-usual.</p></div>
-<div class="paragraph"><p>Now on to project statuses and future works.</p></div>
-<div class="sect1">
-<h2 id="_cowboy">Cowboy</h2>
-<div class="sectionbody">
-<div class="paragraph"><p>Cowboy is getting ready for a 1.0 release. Once multipart support
-is in, all that&#8217;s left is finishing the guide, improving tests and
-finishing moving code to the cowlib project. I hope everything will
-be ready around the time R17B is released.</p></div>
-<div class="paragraph"><p>I already dream of some API breaking changes after 1.0, which
-would essentially become 2.0 when they&#8217;re done. An extensive survey
-will be setup after the 1.0 release to get more information on what
-people like and don&#8217;t like about the API.</p></div>
-<div class="paragraph"><p>And of course, when clients start implementing HTTP/2.0 then we
-will too.</p></div>
-</div>
-</div>
-<div class="sect1">
-<h2 id="_ranch">Ranch</h2>
-<div class="sectionbody">
-<div class="paragraph"><p>Ranch is also getting close to 1.0. I am currently writing a
-test suite for upgrades. After that I also would like to write
-a chaos_monkey test suite and add a getting started chapter to the
-guide.</p></div>
-<div class="paragraph"><p>Ranch is pretty solid otherwise, it&#8217;s hard to foresee new
-features at this point.</p></div>
-</div>
-</div>
-<div class="sect1">
-<h2 id="_erlang_mk">Erlang.mk</h2>
-<div class="sectionbody">
-<div class="paragraph"><p>I didn&#8217;t expect this project to become popular. Glad it did though.</p></div>
-<div class="paragraph"><p>Windows support is planned, but will require GNU Make 4.
-Thankfully, it&#8217;s available at least through cygwin. Make,
-Git and Erlang will be the only required dependencies
-because the rest of the external calls will be converted to
-using Guile, a Scheme included since GNU Make 4. So it is
-Guile that will download the needed files, magically fill
-the list of modules in the <em>.app</em> file and so on, allowing
-us to provide a truly cross-platform solution without
-losing on the performance we benefit from using Make.</p></div>
-<div class="paragraph"><p>Also note that it is possible to check whether Guile
-is available so we will be able to fallback to the current
-code for older systems.</p></div>
-<div class="paragraph"><p>I am also thinking about adding an extra column to the package
-index, indicating the preferred tag or commit number to be used.
-This would allow us to skip the individual <code>dep</code> lines
-entirely if the information in the package index is good enough.
-And committing that file to your project would be the only thing
-needed to lock the dependencies. Of course if a <code>dep</code>
-line is specified this would instead override the file.</p></div>
-</div>
-</div>
-<div class="sect1">
-<h2 id="_alien_shaman">Alien Shaman</h2>
-<div class="sectionbody">
-<div class="paragraph"><p>This is the two-parts project requested by the LeoFS team.
-This is essentially a "distributed bigwig". I am hoping to
-have a prototype up in a few days.</p></div>
-<div class="paragraph"><p>Alien is the part that allows writing and enabling probes
-in your nodes. Probes send events which may get filtered before
-being forwarded to their destination. The events may be sent
-to a local process, a remote process, over UDP, TCP or SSL.
-Events may also be received by a process called a relay, which
-may be used to group or aggregate data before it is being sent
-over the network, reducing the footprint overall.</p></div>
-<div class="paragraph"><p>Shaman is the UI for it. It will ultimately be able to display
-any event as long as it&#8217;s configured to do so. Events may be logs,
-numeric values displayed on graphs updated in real time, lists of
-items like processes and so on.</p></div>
-</div>
-</div>
-<div class="sect1">
-<h2 id="_feedback">Feedback</h2>
-<div class="sectionbody">
-<div class="paragraph"><p>That&#8217;s it for today! There will be another status update once
-Shaman is out. But for now I have to focus on it.</p></div>
-<div class="paragraph"><p>As always, please send feedback on the projects, this post,
-the sponsoring idea, anything really! Thanks.</p></div>
-</div>
-</div>
-</description> + <description>I will now be regularly writing posts about project status, plans and hopes for the future. + Before that though, there&#8217;s one important news to share. + Until a year ago all development was financed through consulting and development services. This worked alright but too much time was spent doing things that didn&#8217;t benefit the open source projects. And that didn&#8217;t make me happy at all. Because I like being happy I stopped that for the most part and spent the year figuring things out, experimenting and discussing with people about it.</description> + </item> + + <item> + <title>Farwest got funded!</title> + <link>https://ninenines.eu/articles/farwest-funded/</link> + <pubDate>Thu, 27 Jun 2013 00:00:00 +0100</pubDate> + + <guid>https://ninenines.eu/articles/farwest-funded/</guid> + <description>This was a triumph! I&#8217;m making a note here: HUGE SUCCESS!! + It&#8217;s hard to overstate my satisfaction. Thanks to everyone who made this possible. + If you have backed this fundraiser, and haven&#8217;t provided your personal details yet, please do so quickly so that your rewards can be sent! + I am hoping that we will be able to make good use of all that money. The details of the expenses will be published regularly on the 2013 Fundraiser wiki page, giving you full disclosure as to how your money is used.</description> + </item> + + <item> + <title>Build Erlang releases with Erlang.mk and Relx</title> + <link>https://ninenines.eu/articles/erlang.mk-and-relx/</link> + <pubDate>Tue, 28 May 2013 00:00:00 +0100</pubDate> + + <guid>https://ninenines.eu/articles/erlang.mk-and-relx/</guid> + <description>Building OTP releases has always been a difficult task. Tools like Reltool or Rebar have made this simpler, but it&#8217;s no panacea. This article will show you an alternative and hopefully much simpler solution. + There is two steps to building a release. First you need to build the various OTP applications you want to include in the release. Once done, you need to create the release itself, by including the Erlang runtime system alongside the applications, a boot script to start the node and all its applications, and some configuration files.</description> + </item> + + <item> + <title>Xerl: intermediate module</title> + <link>https://ninenines.eu/articles/xerl-0.5-intermediate-module/</link> + <pubDate>Mon, 25 Mar 2013 00:00:00 +0100</pubDate> + + <guid>https://ninenines.eu/articles/xerl-0.5-intermediate-module/</guid> + <description>Today we will start the work on the intermediate module that will be used to run the code for the expressions found in our file&#8217;s body, replacing our interpreter. + This is what we want to have when all the work is done: + xerl -&gt; tokens -&gt; AST -&gt; intermediate -&gt; cerl Today we will perform this work only on the atomic integer expression however, so we will not build any module at the end.</description> + </item> + + <item> + <title>Xerl: expression separator</title> + <link>https://ninenines.eu/articles/xerl-0.4-expression-separator/</link> + <pubDate>Fri, 01 Mar 2013 00:00:00 +0100</pubDate> + + <guid>https://ninenines.eu/articles/xerl-0.4-expression-separator/</guid> + <description>As promised we are adding an expression separator this time. This will be short and easy. + In the tokenizer we only need to add a line recognizing the comma as a valid token. + , : {token, {',', TokenLine}}. Then we need to change the following lines in the parser: + exprs -&gt; expr : ['$1']. exprs -&gt; expr exprs : ['$1' | '$2']. And add a comma between the expressions on the second line:</description> + </item> + + <item> + <title>Erlang Scalability</title> + <link>https://ninenines.eu/articles/erlang-scalability/</link> + <pubDate>Mon, 18 Feb 2013 00:00:00 +0100</pubDate> + + <guid>https://ninenines.eu/articles/erlang-scalability/</guid> + <description>I would like to share some experience and theories on Erlang scalability. + This will be in the form of a series of hints, which may or may not be accompanied with explanations as to why things are this way, or how they improve or reduce the scalability of a system. I will try to do my best to avoid giving falsehoods, even if that means a few things won&#8217;t be explained.</description> + </item> + + <item> + <title>Xerl: atomic expressions</title> + <link>https://ninenines.eu/articles/xerl-0.3-atomic-expressions/</link> + <pubDate>Mon, 18 Feb 2013 00:00:00 +0100</pubDate> + + <guid>https://ninenines.eu/articles/xerl-0.3-atomic-expressions/</guid> + <description>We will be adding atomic integer expressions to our language. These look as follow in Erlang: + 42. And the result of this expression is of course 42. + We will be running this expression at compile time, since we don&#8217;t have the means to run code at runtime yet. This will of course result in no module being compiled, but that&#8217;s OK, it will allow us to discuss a few important things we&#8217;ll have to plan for later on.</description> + </item> + + <item> + <title>Xerl: two modules</title> + <link>https://ninenines.eu/articles/xerl-0.2-two-modules/</link> + <pubDate>Sun, 03 Feb 2013 00:00:00 +0100</pubDate> + + <guid>https://ninenines.eu/articles/xerl-0.2-two-modules/</guid> + <description>Everything is an expression. + This sentence carries profound meaning. We will invoke it many times over the course of these articles. + If everything is an expression, then the language shouldn&#8217;t have any problem with me defining two modules in the same source file. + mod first_module begin end mod second_module begin end Likewise, it shouldn&#8217;t have any problem with me defining a module inside another module. + mod out_module begin mod in_module begin end end Of course, in the context of the Erlang VM, these two snippets are equivalent; there is nothing preventing you from calling the in_module module from any other module.</description> + </item> + + <item> + <title>Xerl: empty modules</title> + <link>https://ninenines.eu/articles/xerl-0.1-empty-modules/</link> + <pubDate>Wed, 30 Jan 2013 00:00:00 +0100</pubDate> + + <guid>https://ninenines.eu/articles/xerl-0.1-empty-modules/</guid> + <description>Let&#8217;s build a programming language. I call it Xerl: eXtended ERLang. It&#8217;ll be an occasion for us to learn a few things, especially me. + Unlike in Erlang, in this language, everything is an expression. This means that modules and functions are expression, and indeed that you can have more than one module per file. + We are just starting, so let&#8217;s no go ahead of ourselves here. We&#8217;ll begin with writing the code allowing us to compile an empty module.</description> + </item> + + <item> + <title>Build an FTP Server with Ranch in 30 Minutes</title> + <link>https://ninenines.eu/articles/ranch-ftp/</link> + <pubDate>Wed, 14 Nov 2012 00:00:00 +0100</pubDate> + + <guid>https://ninenines.eu/articles/ranch-ftp/</guid> + <description>Last week I was speaking at the London Erlang Factory Lite where I presented a live demonstration of building an FTP server using Ranch. As there was no slide, you should use this article as a reference instead. + The goal of this article is to showcase how to use Ranch for writing a network protocol implementation, how Ranch gets out of the way to let you write the code that matters, and the common techniques used when writing servers.</description> + </item> + + <item> + <title>Erlang Tic Tac Toe</title> + <link>https://ninenines.eu/articles/tictactoe/</link> + <pubDate>Wed, 17 Oct 2012 00:00:00 +0100</pubDate> + + <guid>https://ninenines.eu/articles/tictactoe/</guid> + <description>Everyone knows Tic Tac Toe, right? + Players choose either to be the Xs or the Os, then place their symbol on a 3x3 board one after another, trying to create a line of 3 of them. + Writing an algorithm to check for victory sounds easy, right? It&#8217;s easily tested, considering there&#8217;s only 8 possible winning rows (3 horizontal, 3 vertical and 2 diagonal). + In Erlang though, you probably wouldn&#8217;t want an algorithm.</description> </item> </channel> diff --git a/articles/january-2014-status/index.html b/articles/january-2014-status/index.html index aaaa0845..39a776ef 100644 --- a/articles/january-2014-status/index.html +++ b/articles/january-2014-status/index.html @@ -7,7 +7,7 @@ <meta name="description" content=""> <meta name="author" content="Loïc Hoguin based on a design from (Soft10) Pol Cámara"> - <meta name="generator" content="Hugo 0.17" /> + <meta name="generator" content="Hugo 0.26" /> <title>Nine Nines: January 2014 status</title> @@ -74,146 +74,146 @@ </p> </header> -<div class="paragraph"><p>I will now be regularly writing posts about project status, plans
-and hopes for the future.</p></div>
-<div class="paragraph"><p>Before that though, there’s one important news to share.</p></div>
-<div class="paragraph"><p>Until a year ago all development was financed through consulting
-and development services. This worked alright but too much time was
-spent doing things that didn’t benefit the open source projects.
-And that didn’t make me happy at all. Because I like being happy
-I stopped that for the most part and spent the year figuring things
-out, experimenting and discussing with people about it.</p></div>
-<div class="paragraph"><p>What makes me happy is answering these "what if" questions.
-Ranch and Cowboy are a direct product of that, as they originate
-from the "what if we could have a server running different protocols
-on different ports but all part of the same application?"; Erlang.mk
-is a bit different: "this works great for me, what if it could
-become the standard solution for building Erlang applications?".</p></div>
-<div class="paragraph"><p>When I successfully answer the question, this becomes a project
-that may end up largely benefiting the Erlang community. I love
-Erlang and I love enabling people to build awesome products based
-on my projects. It’s a lot more rewarding than activities like
-consulting where you only help one company at a time. And it’s
-also a much better use of my time as this has a bigger impact on
-the community.</p></div>
-<div class="paragraph"><p>The hard part is to figure out how to be able to spend 100%
-of the time on projects that you basically give away for free,
-and still be able to afford living.</p></div>
-<div class="paragraph"><p>The immediate solution was getting work sponsored by the
-<a href="http://www.leofs.org/">LeoFS project</a>. LeoFS is a great
-distributed file storage that I can only recommend to anyone who
-needs to store files or large pieces of data. The sponsorship
-works pretty great, and spurred development of the SPDY code in
-Cowboy amongst other things, plus a couple upcoming projects
-done more recently and getting a final touch before release.</p></div>
-<div class="paragraph"><p>It turns out sponsoring works great. So I’m thinking of
-expanding on it and hopefully get enough sponsoring for fulltime
-open source development. So I figured out a few things that
-can give incentive to companies willing to sponsor.</p></div>
-<div class="paragraph"><p>Sponsors can <em>request that a particular version of Cowboy
-be maintained indefinitely</em> (as long as they’re sponsoring).
-This means fixes will be backported. This doesn’t include
-features although I can take requests depending on feasability.</p></div>
-<div class="paragraph"><p>Sponsors can <em>have a direct, private line of communication</em>,
-useful when they need help debugging or optimizing their product.</p></div>
-<div class="paragraph"><p>Sponsors can <em>get their name associated with one of the
-project</em> and get a good standing in the community thanks
-to this. They would be featured in the README of the project
-which is viewed by hundreds of developers daily.</p></div>
-<div class="paragraph"><p>Sponsors can <em>be listed on this website</em>. I will modify
-the front page when we get a few more sponsors, they will be
-featured below the carousel of projects.</p></div>
-<div class="paragraph"><p>Please <a href="mailto:[email protected]">contact us</a> if
-you are interested in sponsoring, and say how much you are willing
-to sponsor. The goal here is only to have enough money to make a
-living and attend a few conferences. There’s an upper limit in the
-amount needed per year, so the more sponsors there are the cheaper
-it becomes to everyone.</p></div>
-<div class="paragraph"><p>The upper limit stems from the new legal entity that will replace
-the current Nine Nines. This is mostly to lower the legal costs and
-simplify the administrative stuff and allow me to dedicate all my
-time on what’s important. From your point of view it’s business as
-usual.</p></div>
-<div class="paragraph"><p>Now on to project statuses and future works.</p></div>
-<div class="sect1">
-<h2 id="_cowboy">Cowboy</h2>
-<div class="sectionbody">
-<div class="paragraph"><p>Cowboy is getting ready for a 1.0 release. Once multipart support
-is in, all that’s left is finishing the guide, improving tests and
-finishing moving code to the cowlib project. I hope everything will
-be ready around the time R17B is released.</p></div>
-<div class="paragraph"><p>I already dream of some API breaking changes after 1.0, which
-would essentially become 2.0 when they’re done. An extensive survey
-will be setup after the 1.0 release to get more information on what
-people like and don’t like about the API.</p></div>
-<div class="paragraph"><p>And of course, when clients start implementing HTTP/2.0 then we
-will too.</p></div>
-</div>
-</div>
-<div class="sect1">
-<h2 id="_ranch">Ranch</h2>
-<div class="sectionbody">
-<div class="paragraph"><p>Ranch is also getting close to 1.0. I am currently writing a
-test suite for upgrades. After that I also would like to write
-a chaos_monkey test suite and add a getting started chapter to the
-guide.</p></div>
-<div class="paragraph"><p>Ranch is pretty solid otherwise, it’s hard to foresee new
-features at this point.</p></div>
-</div>
-</div>
-<div class="sect1">
-<h2 id="_erlang_mk">Erlang.mk</h2>
-<div class="sectionbody">
-<div class="paragraph"><p>I didn’t expect this project to become popular. Glad it did though.</p></div>
-<div class="paragraph"><p>Windows support is planned, but will require GNU Make 4.
-Thankfully, it’s available at least through cygwin. Make,
-Git and Erlang will be the only required dependencies
-because the rest of the external calls will be converted to
-using Guile, a Scheme included since GNU Make 4. So it is
-Guile that will download the needed files, magically fill
-the list of modules in the <em>.app</em> file and so on, allowing
-us to provide a truly cross-platform solution without
-losing on the performance we benefit from using Make.</p></div>
-<div class="paragraph"><p>Also note that it is possible to check whether Guile
-is available so we will be able to fallback to the current
-code for older systems.</p></div>
-<div class="paragraph"><p>I am also thinking about adding an extra column to the package
-index, indicating the preferred tag or commit number to be used.
-This would allow us to skip the individual <code>dep</code> lines
-entirely if the information in the package index is good enough.
-And committing that file to your project would be the only thing
-needed to lock the dependencies. Of course if a <code>dep</code>
-line is specified this would instead override the file.</p></div>
-</div>
-</div>
-<div class="sect1">
-<h2 id="_alien_shaman">Alien Shaman</h2>
-<div class="sectionbody">
-<div class="paragraph"><p>This is the two-parts project requested by the LeoFS team.
-This is essentially a "distributed bigwig". I am hoping to
-have a prototype up in a few days.</p></div>
-<div class="paragraph"><p>Alien is the part that allows writing and enabling probes
-in your nodes. Probes send events which may get filtered before
-being forwarded to their destination. The events may be sent
-to a local process, a remote process, over UDP, TCP or SSL.
-Events may also be received by a process called a relay, which
-may be used to group or aggregate data before it is being sent
-over the network, reducing the footprint overall.</p></div>
-<div class="paragraph"><p>Shaman is the UI for it. It will ultimately be able to display
-any event as long as it’s configured to do so. Events may be logs,
-numeric values displayed on graphs updated in real time, lists of
-items like processes and so on.</p></div>
-</div>
-</div>
-<div class="sect1">
-<h2 id="_feedback">Feedback</h2>
-<div class="sectionbody">
-<div class="paragraph"><p>That’s it for today! There will be another status update once
-Shaman is out. But for now I have to focus on it.</p></div>
-<div class="paragraph"><p>As always, please send feedback on the projects, this post,
-the sponsoring idea, anything really! Thanks.</p></div>
-</div>
-</div>
+<div class="paragraph"><p>I will now be regularly writing posts about project status, plans +and hopes for the future.</p></div> +<div class="paragraph"><p>Before that though, there’s one important news to share.</p></div> +<div class="paragraph"><p>Until a year ago all development was financed through consulting +and development services. This worked alright but too much time was +spent doing things that didn’t benefit the open source projects. +And that didn’t make me happy at all. Because I like being happy +I stopped that for the most part and spent the year figuring things +out, experimenting and discussing with people about it.</p></div> +<div class="paragraph"><p>What makes me happy is answering these "what if" questions. +Ranch and Cowboy are a direct product of that, as they originate +from the "what if we could have a server running different protocols +on different ports but all part of the same application?"; Erlang.mk +is a bit different: "this works great for me, what if it could +become the standard solution for building Erlang applications?".</p></div> +<div class="paragraph"><p>When I successfully answer the question, this becomes a project +that may end up largely benefiting the Erlang community. I love +Erlang and I love enabling people to build awesome products based +on my projects. It’s a lot more rewarding than activities like +consulting where you only help one company at a time. And it’s +also a much better use of my time as this has a bigger impact on +the community.</p></div> +<div class="paragraph"><p>The hard part is to figure out how to be able to spend 100% +of the time on projects that you basically give away for free, +and still be able to afford living.</p></div> +<div class="paragraph"><p>The immediate solution was getting work sponsored by the +<a href="http://www.leofs.org/">LeoFS project</a>. LeoFS is a great +distributed file storage that I can only recommend to anyone who +needs to store files or large pieces of data. The sponsorship +works pretty great, and spurred development of the SPDY code in +Cowboy amongst other things, plus a couple upcoming projects +done more recently and getting a final touch before release.</p></div> +<div class="paragraph"><p>It turns out sponsoring works great. So I’m thinking of +expanding on it and hopefully get enough sponsoring for fulltime +open source development. So I figured out a few things that +can give incentive to companies willing to sponsor.</p></div> +<div class="paragraph"><p>Sponsors can <em>request that a particular version of Cowboy +be maintained indefinitely</em> (as long as they’re sponsoring). +This means fixes will be backported. This doesn’t include +features although I can take requests depending on feasability.</p></div> +<div class="paragraph"><p>Sponsors can <em>have a direct, private line of communication</em>, +useful when they need help debugging or optimizing their product.</p></div> +<div class="paragraph"><p>Sponsors can <em>get their name associated with one of the +project</em> and get a good standing in the community thanks +to this. They would be featured in the README of the project +which is viewed by hundreds of developers daily.</p></div> +<div class="paragraph"><p>Sponsors can <em>be listed on this website</em>. I will modify +the front page when we get a few more sponsors, they will be +featured below the carousel of projects.</p></div> +<div class="paragraph"><p>Please <a href="mailto:[email protected]">contact us</a> if +you are interested in sponsoring, and say how much you are willing +to sponsor. The goal here is only to have enough money to make a +living and attend a few conferences. There’s an upper limit in the +amount needed per year, so the more sponsors there are the cheaper +it becomes to everyone.</p></div> +<div class="paragraph"><p>The upper limit stems from the new legal entity that will replace +the current Nine Nines. This is mostly to lower the legal costs and +simplify the administrative stuff and allow me to dedicate all my +time on what’s important. From your point of view it’s business as +usual.</p></div> +<div class="paragraph"><p>Now on to project statuses and future works.</p></div> +<div class="sect1"> +<h2 id="_cowboy">Cowboy</h2> +<div class="sectionbody"> +<div class="paragraph"><p>Cowboy is getting ready for a 1.0 release. Once multipart support +is in, all that’s left is finishing the guide, improving tests and +finishing moving code to the cowlib project. I hope everything will +be ready around the time R17B is released.</p></div> +<div class="paragraph"><p>I already dream of some API breaking changes after 1.0, which +would essentially become 2.0 when they’re done. An extensive survey +will be setup after the 1.0 release to get more information on what +people like and don’t like about the API.</p></div> +<div class="paragraph"><p>And of course, when clients start implementing HTTP/2.0 then we +will too.</p></div> +</div> +</div> +<div class="sect1"> +<h2 id="_ranch">Ranch</h2> +<div class="sectionbody"> +<div class="paragraph"><p>Ranch is also getting close to 1.0. I am currently writing a +test suite for upgrades. After that I also would like to write +a chaos_monkey test suite and add a getting started chapter to the +guide.</p></div> +<div class="paragraph"><p>Ranch is pretty solid otherwise, it’s hard to foresee new +features at this point.</p></div> +</div> +</div> +<div class="sect1"> +<h2 id="_erlang_mk">Erlang.mk</h2> +<div class="sectionbody"> +<div class="paragraph"><p>I didn’t expect this project to become popular. Glad it did though.</p></div> +<div class="paragraph"><p>Windows support is planned, but will require GNU Make 4. +Thankfully, it’s available at least through cygwin. Make, +Git and Erlang will be the only required dependencies +because the rest of the external calls will be converted to +using Guile, a Scheme included since GNU Make 4. So it is +Guile that will download the needed files, magically fill +the list of modules in the <em>.app</em> file and so on, allowing +us to provide a truly cross-platform solution without +losing on the performance we benefit from using Make.</p></div> +<div class="paragraph"><p>Also note that it is possible to check whether Guile +is available so we will be able to fallback to the current +code for older systems.</p></div> +<div class="paragraph"><p>I am also thinking about adding an extra column to the package +index, indicating the preferred tag or commit number to be used. +This would allow us to skip the individual <code>dep</code> lines +entirely if the information in the package index is good enough. +And committing that file to your project would be the only thing +needed to lock the dependencies. Of course if a <code>dep</code> +line is specified this would instead override the file.</p></div> +</div> +</div> +<div class="sect1"> +<h2 id="_alien_shaman">Alien Shaman</h2> +<div class="sectionbody"> +<div class="paragraph"><p>This is the two-parts project requested by the LeoFS team. +This is essentially a "distributed bigwig". I am hoping to +have a prototype up in a few days.</p></div> +<div class="paragraph"><p>Alien is the part that allows writing and enabling probes +in your nodes. Probes send events which may get filtered before +being forwarded to their destination. The events may be sent +to a local process, a remote process, over UDP, TCP or SSL. +Events may also be received by a process called a relay, which +may be used to group or aggregate data before it is being sent +over the network, reducing the footprint overall.</p></div> +<div class="paragraph"><p>Shaman is the UI for it. It will ultimately be able to display +any event as long as it’s configured to do so. Events may be logs, +numeric values displayed on graphs updated in real time, lists of +items like processes and so on.</p></div> +</div> +</div> +<div class="sect1"> +<h2 id="_feedback">Feedback</h2> +<div class="sectionbody"> +<div class="paragraph"><p>That’s it for today! There will be another status update once +Shaman is out. But for now I have to focus on it.</p></div> +<div class="paragraph"><p>As always, please send feedback on the projects, this post, +the sponsoring idea, anything really! Thanks.</p></div> +</div> +</div> </article> </div> @@ -222,55 +222,107 @@ the sponsoring idea, anything really! Thanks.</p></div> <h3>More articles</h3> <ul id="articles-nav" class="extra_margin"> - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + + + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + + <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + - <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + + <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + - <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + + <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + - <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + + <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + - <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + + <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + - <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + + <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + - <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + + <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + - <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + + <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + - <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + + <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + - <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + + <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + - <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + </ul> diff --git a/articles/ml-archives/index.html b/articles/ml-archives/index.html index 34fa9ff1..e668b252 100644 --- a/articles/ml-archives/index.html +++ b/articles/ml-archives/index.html @@ -7,7 +7,7 @@ <meta name="description" content=""> <meta name="author" content="Loïc Hoguin based on a design from (Soft10) Pol Cámara"> - <meta name="generator" content="Hugo 0.17" /> + <meta name="generator" content="Hugo 0.26" /> <title>Nine Nines: Mailing list archived</title> @@ -74,16 +74,16 @@ </p> </header> -<div class="paragraph"><p>The <a href="/archives/extend">old mailing list archives</a> have been
-added to the site, mainly for referencing purposes.</p></div>
-<div class="paragraph"><p>The mailing list has been shut down and all personal information
-has been deleted.</p></div>
-<div class="paragraph"><p>If you need help with a project, consider either opening a ticket
-on that project’s issues tracker or going through the community
-channels (erlang-questions, #ninenines or #erlang on Freenode).</p></div>
-<div class="paragraph"><p>Prefer tickets; often when people have issues it highlights an
-underlying problem in the project or its documentation.</p></div>
-<div class="paragraph"><p>Thanks.</p></div>
+<div class="paragraph"><p>The <a href="/archives/extend">old mailing list archives</a> have been +added to the site, mainly for referencing purposes.</p></div> +<div class="paragraph"><p>The mailing list has been shut down and all personal information +has been deleted.</p></div> +<div class="paragraph"><p>If you need help with a project, consider either opening a ticket +on that project’s issues tracker or going through the community +channels (erlang-questions, #ninenines or #erlang on Freenode).</p></div> +<div class="paragraph"><p>Prefer tickets; often when people have issues it highlights an +underlying problem in the project or its documentation.</p></div> +<div class="paragraph"><p>Thanks.</p></div> </article> </div> @@ -92,55 +92,107 @@ underlying problem in the project or its documentation.</p></div> <h3>More articles</h3> <ul id="articles-nav" class="extra_margin"> - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + - <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + + <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + - <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + + <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + - <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + + <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + - <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + + <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + - <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + + <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + - <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + + <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + - <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + + <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + - <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + + <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + - <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + + <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + - <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + + <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + + + </ul> diff --git a/articles/on-open-source/index.html b/articles/on-open-source/index.html index bc587fdd..60564636 100644 --- a/articles/on-open-source/index.html +++ b/articles/on-open-source/index.html @@ -7,7 +7,7 @@ <meta name="description" content=""> <meta name="author" content="Loïc Hoguin based on a design from (Soft10) Pol Cámara"> - <meta name="generator" content="Hugo 0.17" /> + <meta name="generator" content="Hugo 0.26" /> <title>Nine Nines: On open source</title> @@ -74,123 +74,123 @@ </p> </header> -<div class="paragraph"><p>Last week I read a great article
-<a href="http://videlalvaro.github.io/2014/08/on-contributing-to-opensource.html">on
-contributing to open source</a> by Alvaro Videla. He makes
-many great points and I am in agreement with most of it.
-This made me want to properly explain my point of view with
-regard to open source and contributions. Unlike most open
-source evangelism articles I will not talk about ideals or
-any of that crap, but rather my personal feelings and
-experience.</p></div>
-<div class="paragraph"><p>I have been doing open source work for quite some time.
-My very first open source project was a graphics driver
-for (the very early version of) the PCSX2 emulator. That
-was more than ten years ago, and there
-<a href="http://ngemu.com/threads/gstaris-0-6.30469/">isn’t
-much left to look at today</a>. This was followed by a
-<a href="https://github.com/extend/wee">PHP framework</a>
-(started long before Zend Framework was even a thing) and
-a few other small projects. None of them really took off.
-It’s alright, that’s pretty much the fate of most open
-source projects. You spend a lot of work and sweat and
-get very little in return from others.</p></div>
-<div class="paragraph"><p>This sounds harsh but this is the reality of all open
-source projects. If you are thinking of building a project
-and releasing it as open source, you should be prepared
-for that. This is how most of your projects will feel like.
-Don’t release a project as open source thinking everyone
-will pat you on the back and cheer, this won’t happen. In
-fact if your project is a too small improvement over existing
-software, what many people will do is say you have NIH
-syndrome, regardless of the improvement you bring. So you
-need not to rely on other people in order to get your
-enjoyment out of building open source software.</p></div>
-<div class="paragraph"><p>In my case I get enjoyment from thinking about problems
-that need solving. Often times the problems are already
-solved, but nevermind that, I still think about them and
-sometimes come up with something I feel is better and then
-write code for it. Writing code is also fun, but not as
-fun as using my brain to imagine solutions.</p></div>
-<div class="paragraph"><p>You don’t need thousands of users to do that. So are
-users worthless to me then? No, of course not. In fact
-they are an important component: they bring me problems
-that need solving. So users are very important to me.
-But that’s not the only reason.</p></div>
-<div class="paragraph"><p>I got lucky that the Cowboy project became popular.
-And seeing it be this popular, and some of my other projects
-also do quite well, made me believe I could perhaps work
-full time on open source. If I can work full time then
-I can produce better software. What I had one hour to
-work on before I can now spend a day on, and experiment
-until I am satisfied. This is very useful because that
-means I can get it almost right from the beginning, and
-avoid the million API breaking changes that occured
-before Cowboy 1.0 was released.</p></div>
-<div class="paragraph"><p>To be able to work full time on open source however,
-I need money. This is a largely unspoken topic of open
-source work. The work is never free. You can download the
-product for free, but someone has to pay for the work
-itself. Life is unfortunately not free.</p></div>
-<div class="paragraph"><p>Large projects and some lucky people have their work
-sponsored by their employers. Everyone else has to deal
-with it differently. In my case I was sponsored for a
-while by the <a href="http://leo-project.net/leofs/">LeoFS</a>
-project, but that ended. I also had the Farwest fundraiser,
-which was a success, although the project stalled after that.
-(Fear not, as Farwest will make a comeback as a conglomerate
-of Web development projects in the future.) After that I set
-up the <a href="http://ninenines.eu/support/">sponsoring scheme</a>,
-which I can proudly say today brings in enough money to
-cover my food and shelter. Great!</p></div>
-<div class="paragraph"><p>This is a start, but it’s of course not enough. Life
-is a little more than food and shelter, and so I am still
-looking for sponsors. This is not a very glorious experience,
-as I am essentially looking for scraps that companies can
-throw away. Still, if a handful more companies were doing
-that, not only would I be able to live comfortably, but I
-would also be able to stop worrying about the future as I
-could put money on the side for when it gets rough.</p></div>
-<div class="paragraph"><p>A few companies giving me some scrap money so I could
-live and work independently is by far the most important
-thing anyone can do to help my projects, including Cowboy.
-Yes, they’re even more important than code contributions,
-bug reports and feedback. Because this money gives me the
-time I need to handle the code contributions, bug reports
-and feedback.</p></div>
-<div class="paragraph"><p>If Cowboy or another project is a large part of your
-product or infrastructure, then the best thing you can do
-is become a sponsor. The second best is opening tickets
-and/or providing feedback. The third best is providing
-good code contributions.</p></div>
-<div class="paragraph"><p>I will not expand on the feedback part. Feedback is
-very important, and even just a high five or a retweet
-is already good feedback. It’s not very complicated.</p></div>
-<div class="paragraph"><p>I want to expand a little on code contributions
-however. Not long ago I ran across the term "patch bomb"
-which means dropping patches and expecting the project
-maintainers to merge them and maintain them. I receive
-a lot of patches, and often have to refuse them. Causes
-for refusal vary. Some patches only benefit the people
-who submitted them (or a very small number of people).
-Some patches are not refined enough to be included.
-Others are out of scope of the project. These are some
-of the reasons why I refuse patches. Having limited
-time and resources, I have to focus my efforts on the
-code used by the larger number of users. I have to
-prioritize patches from submitters who are reactive
-and address the issues pointed out. And I have to plainly
-refuse other patches.</p></div>
-<div class="paragraph"><p>I believe this wraps up my thoughts on open source.
-Overall I had a great experience, the Erlang community
-being nice and understanding of the issues at hand in
-general. And if the money problem could be solved soon,
-then I would be one of the luckiest and happiest open
-source developer on Earth.</p></div>
-<div class="paragraph"><p>Think about it the next time you see a donation button
-or a request for funds or sponsoring. You can considerably
-improve an open source developer’s life with very little
-of your company’s money.</p></div>
+<div class="paragraph"><p>Last week I read a great article +<a href="http://videlalvaro.github.io/2014/08/on-contributing-to-opensource.html">on +contributing to open source</a> by Alvaro Videla. He makes +many great points and I am in agreement with most of it. +This made me want to properly explain my point of view with +regard to open source and contributions. Unlike most open +source evangelism articles I will not talk about ideals or +any of that crap, but rather my personal feelings and +experience.</p></div> +<div class="paragraph"><p>I have been doing open source work for quite some time. +My very first open source project was a graphics driver +for (the very early version of) the PCSX2 emulator. That +was more than ten years ago, and there +<a href="http://ngemu.com/threads/gstaris-0-6.30469/">isn’t +much left to look at today</a>. This was followed by a +<a href="https://github.com/extend/wee">PHP framework</a> +(started long before Zend Framework was even a thing) and +a few other small projects. None of them really took off. +It’s alright, that’s pretty much the fate of most open +source projects. You spend a lot of work and sweat and +get very little in return from others.</p></div> +<div class="paragraph"><p>This sounds harsh but this is the reality of all open +source projects. If you are thinking of building a project +and releasing it as open source, you should be prepared +for that. This is how most of your projects will feel like. +Don’t release a project as open source thinking everyone +will pat you on the back and cheer, this won’t happen. In +fact if your project is a too small improvement over existing +software, what many people will do is say you have NIH +syndrome, regardless of the improvement you bring. So you +need not to rely on other people in order to get your +enjoyment out of building open source software.</p></div> +<div class="paragraph"><p>In my case I get enjoyment from thinking about problems +that need solving. Often times the problems are already +solved, but nevermind that, I still think about them and +sometimes come up with something I feel is better and then +write code for it. Writing code is also fun, but not as +fun as using my brain to imagine solutions.</p></div> +<div class="paragraph"><p>You don’t need thousands of users to do that. So are +users worthless to me then? No, of course not. In fact +they are an important component: they bring me problems +that need solving. So users are very important to me. +But that’s not the only reason.</p></div> +<div class="paragraph"><p>I got lucky that the Cowboy project became popular. +And seeing it be this popular, and some of my other projects +also do quite well, made me believe I could perhaps work +full time on open source. If I can work full time then +I can produce better software. What I had one hour to +work on before I can now spend a day on, and experiment +until I am satisfied. This is very useful because that +means I can get it almost right from the beginning, and +avoid the million API breaking changes that occured +before Cowboy 1.0 was released.</p></div> +<div class="paragraph"><p>To be able to work full time on open source however, +I need money. This is a largely unspoken topic of open +source work. The work is never free. You can download the +product for free, but someone has to pay for the work +itself. Life is unfortunately not free.</p></div> +<div class="paragraph"><p>Large projects and some lucky people have their work +sponsored by their employers. Everyone else has to deal +with it differently. In my case I was sponsored for a +while by the <a href="http://leo-project.net/leofs/">LeoFS</a> +project, but that ended. I also had the Farwest fundraiser, +which was a success, although the project stalled after that. +(Fear not, as Farwest will make a comeback as a conglomerate +of Web development projects in the future.) After that I set +up the <a href="http://ninenines.eu/support/">sponsoring scheme</a>, +which I can proudly say today brings in enough money to +cover my food and shelter. Great!</p></div> +<div class="paragraph"><p>This is a start, but it’s of course not enough. Life +is a little more than food and shelter, and so I am still +looking for sponsors. This is not a very glorious experience, +as I am essentially looking for scraps that companies can +throw away. Still, if a handful more companies were doing +that, not only would I be able to live comfortably, but I +would also be able to stop worrying about the future as I +could put money on the side for when it gets rough.</p></div> +<div class="paragraph"><p>A few companies giving me some scrap money so I could +live and work independently is by far the most important +thing anyone can do to help my projects, including Cowboy. +Yes, they’re even more important than code contributions, +bug reports and feedback. Because this money gives me the +time I need to handle the code contributions, bug reports +and feedback.</p></div> +<div class="paragraph"><p>If Cowboy or another project is a large part of your +product or infrastructure, then the best thing you can do +is become a sponsor. The second best is opening tickets +and/or providing feedback. The third best is providing +good code contributions.</p></div> +<div class="paragraph"><p>I will not expand on the feedback part. Feedback is +very important, and even just a high five or a retweet +is already good feedback. It’s not very complicated.</p></div> +<div class="paragraph"><p>I want to expand a little on code contributions +however. Not long ago I ran across the term "patch bomb" +which means dropping patches and expecting the project +maintainers to merge them and maintain them. I receive +a lot of patches, and often have to refuse them. Causes +for refusal vary. Some patches only benefit the people +who submitted them (or a very small number of people). +Some patches are not refined enough to be included. +Others are out of scope of the project. These are some +of the reasons why I refuse patches. Having limited +time and resources, I have to focus my efforts on the +code used by the larger number of users. I have to +prioritize patches from submitters who are reactive +and address the issues pointed out. And I have to plainly +refuse other patches.</p></div> +<div class="paragraph"><p>I believe this wraps up my thoughts on open source. +Overall I had a great experience, the Erlang community +being nice and understanding of the issues at hand in +general. And if the money problem could be solved soon, +then I would be one of the luckiest and happiest open +source developer on Earth.</p></div> +<div class="paragraph"><p>Think about it the next time you see a donation button +or a request for funds or sponsoring. You can considerably +improve an open source developer’s life with very little +of your company’s money.</p></div> </article> </div> @@ -199,55 +199,107 @@ of your company’s money.</p></div> <h3>More articles</h3> <ul id="articles-nav" class="extra_margin"> - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + - <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + + <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + - <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + + <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + - <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + + <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + - <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + + <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + - <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + + <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + - <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + + <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + - <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + + <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + - <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + + <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + - <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + + <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + - <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + + <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + + + </ul> diff --git a/articles/page/1/index.html b/articles/page/1/index.html index 0e547dc4..edf636b5 100644 --- a/articles/page/1/index.html +++ b/articles/page/1/index.html @@ -1 +1 @@ -<!DOCTYPE html><html><head><title>https://ninenines.eu/articles/</title><link rel="canonical" href="https://ninenines.eu/articles/"/><meta http-equiv="content-type" content="text/html; charset=utf-8" /><meta http-equiv="refresh" content="0; url=https://ninenines.eu/articles/" /></head></html>
\ No newline at end of file +<!DOCTYPE html><html><head><title>https://ninenines.eu/articles/</title><link rel="canonical" href="https://ninenines.eu/articles/"/><meta name="robots" content="noindex"><meta http-equiv="content-type" content="text/html; charset=utf-8" /><meta http-equiv="refresh" content="0; url=https://ninenines.eu/articles/" /></head></html>
\ No newline at end of file diff --git a/articles/page/2/index.html b/articles/page/2/index.html index 6cb50477..75561425 100644 --- a/articles/page/2/index.html +++ b/articles/page/2/index.html @@ -7,7 +7,7 @@ <meta name="description" content=""> <meta name="author" content="Loïc Hoguin based on a design from (Soft10) Pol Cámara"> - <meta name="generator" content="Hugo 0.17" /> + <meta name="generator" content="Hugo 0.26" /> <title>Nine Nines: Articles</title> @@ -79,9 +79,9 @@ </p> </header> - <p>We will be adding atomic integer expressions to our language.
These look as follow in Erlang: -
42.
And the result of this expression is of course 42. -
We will be running this expression at compile time, since we
don’t have the means to run code at runtime yet. This will of
course result in no module being compiled, but that’s OK, it will
allow us to discuss a few important things we’ll have to plan for
later on.</p> + <p>We will be adding atomic integer expressions to our language. These look as follow in Erlang: + 42. And the result of this expression is of course 42. + We will be running this expression at compile time, since we don’t have the means to run code at runtime yet. This will of course result in no module being compiled, but that’s OK, it will allow us to discuss a few important things we’ll have to plan for later on.</p> <p style="text-align:right"> <a class="read_more" href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Read More</a> @@ -98,10 +98,10 @@ </header> <p>Everything is an expression. -
This sentence carries profound meaning. We will invoke it many
times over the course of these articles. -
If everything is an expression, then the language shouldn’t have
any problem with me defining two modules in the same source file. -
mod first_module
begin
end
mod second_module
begin
end
Likewise, it shouldn’t have any problem with me defining a
module inside another module. -
mod out_module
begin
mod in_module
begin
end
end
Of course, in the context of the Erlang VM, these two snippets
are equivalent; there is nothing preventing you from calling the
in_module module from any other module.</p> + This sentence carries profound meaning. We will invoke it many times over the course of these articles. + If everything is an expression, then the language shouldn’t have any problem with me defining two modules in the same source file. + mod first_module begin end mod second_module begin end Likewise, it shouldn’t have any problem with me defining a module inside another module. + mod out_module begin mod in_module begin end end Of course, in the context of the Erlang VM, these two snippets are equivalent; there is nothing preventing you from calling the in_module module from any other module.</p> <p style="text-align:right"> <a class="read_more" href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Read More</a> @@ -117,9 +117,9 @@ </p> </header> - <p>Let’s build a programming language. I call it Xerl: eXtended ERLang.
It’ll be an occasion for us to learn a few things, especially me. -
Unlike in Erlang, in this language, everything is an expression.
This means that modules and functions are expression, and indeed that
you can have more than one module per file. -
We are just starting, so let’s no go ahead of ourselves here. We’ll
begin with writing the code allowing us to compile an empty module.</p> + <p>Let’s build a programming language. I call it Xerl: eXtended ERLang. It’ll be an occasion for us to learn a few things, especially me. + Unlike in Erlang, in this language, everything is an expression. This means that modules and functions are expression, and indeed that you can have more than one module per file. + We are just starting, so let’s no go ahead of ourselves here. We’ll begin with writing the code allowing us to compile an empty module.</p> <p style="text-align:right"> <a class="read_more" href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Read More</a> @@ -135,8 +135,8 @@ </p> </header> - <p>Last week I was speaking at the
London Erlang Factory Lite
where I presented a live demonstration of building an FTP server using
Ranch.
As there was no slide, you should use this article as a reference instead. -
The goal of this article is to showcase how to use Ranch for writing
a network protocol implementation, how Ranch gets out of the way to let
you write the code that matters, and the common techniques used when
writing servers.</p> + <p>Last week I was speaking at the London Erlang Factory Lite where I presented a live demonstration of building an FTP server using Ranch. As there was no slide, you should use this article as a reference instead. + The goal of this article is to showcase how to use Ranch for writing a network protocol implementation, how Ranch gets out of the way to let you write the code that matters, and the common techniques used when writing servers.</p> <p style="text-align:right"> <a class="read_more" href="https://ninenines.eu/articles/ranch-ftp/">Read More</a> @@ -152,10 +152,10 @@ </p> </header> - <p>Everyone knows Tic Tac Toe,
right? -
Players choose either to be the Xs or the Os, then place their symbol
on a 3x3 board one after another, trying to create a line of 3 of them. -
Writing an algorithm to check for victory sounds easy, right? It’s
easily tested, considering there’s only 8 possible winning rows (3 horizontal,
3 vertical and 2 diagonal). -
In Erlang though, you probably wouldn’t want an algorithm.</p> + <p>Everyone knows Tic Tac Toe, right? + Players choose either to be the Xs or the Os, then place their symbol on a 3x3 board one after another, trying to create a line of 3 of them. + Writing an algorithm to check for victory sounds easy, right? It’s easily tested, considering there’s only 8 possible winning rows (3 horizontal, 3 vertical and 2 diagonal). + In Erlang though, you probably wouldn’t want an algorithm.</p> <p style="text-align:right"> <a class="read_more" href="https://ninenines.eu/articles/tictactoe/">Read More</a> diff --git a/articles/ranch-1.3/index.html b/articles/ranch-1.3/index.html index 3364c077..db486dc5 100644 --- a/articles/ranch-1.3/index.html +++ b/articles/ranch-1.3/index.html @@ -7,7 +7,7 @@ <meta name="description" content=""> <meta name="author" content="Loïc Hoguin based on a design from (Soft10) Pol Cámara"> - <meta name="generator" content="Hugo 0.17" /> + <meta name="generator" content="Hugo 0.26" /> <title>Nine Nines: Ranch 1.3</title> @@ -74,88 +74,88 @@ </p> </header> -<div class="paragraph"><p>Ranch <code>1.3.0</code> has been released!</p></div>
-<div class="paragraph"><p>This release fixes a number of long standing issues and adds
-a small number of features:</p></div>
-<div class="paragraph"><p>The <code>ssl</code> application has been added to the list of dependencies.
-If you don’t need it, you can remove it automatically when fetching
-Ranch or when building the release. If you do need it, you will no
-longer have issues shutting down a node because of Ranch.</p></div>
-<div class="paragraph"><p>The <code>ranch:info/0</code> and <code>ranch:procs/2</code> can be used to retrieve
-information about Ranch’s state. Use it for diagnostic and
-discovery purposes.</p></div>
-<div class="paragraph"><p>SSL listeners can now be configured without a certificate, for setups
-that make use of the SNI extension.</p></div>
-<div class="paragraph"><p>Transport options are now a blacklist, meaning all unknown options
-will be accepted. However Dialyzer will warn if said option is not
-defined in Ranch’s type specifications. Please send a patch when that
-happens!</p></div>
-<div class="paragraph"><p>Various bugs have been fixed, including the bug where the
-number of active connections could become negative. Common
-errors at listener startup should be easier to read (for
-example when the port is already in use).</p></div>
-<div class="paragraph"><p>See the <a href="https://git.ninenines.eu/ranch.git/plain/CHANGELOG.asciidoc">CHANGELOG</a>
-for more details.</p></div>
-<div class="paragraph"><p>Ranch is now tested and supported with Erlang/OTP R16B or above
-on Arch Linux, FreeBSD, OSX, Ubuntu and Windows 7. Contact me
-if you can provide permanent access to another platform for the
-purposes of testing.</p></div>
-<div class="paragraph"><p>Ranch is now available from four locations:</p></div>
-<div class="ulist"><ul>
-<li>
-<p>
-<a href="https://git.ninenines.eu/ranch.git">https://git.ninenines.eu/ranch.git</a>
-</p>
-</li>
-<li>
-<p>
-<a href="https://github.com/ninenines/ranch.git">https://github.com/ninenines/ranch.git</a>
-</p>
-</li>
-<li>
-<p>
-<a href="https://bitbucket.org/ninenines/ranch.git">https://bitbucket.org/ninenines/ranch.git</a>
-</p>
-</li>
-<li>
-<p>
-<a href="https://gitlab.com/ninenines/ranch.git">https://gitlab.com/ninenines/ranch.git</a>
-</p>
-</li>
-</ul></div>
-<div class="paragraph"><p>They are updated at the same time so there is no real difference.</p></div>
-<div class="paragraph"><p>The most recent Ranch commit is now always signed. You can import the
-<a href="https://pgp.mit.edu/pks/lookup?op=vindex&fingerprint=on&exact=on&search=0xF19F189CECC7439699CEDD7A6EF7A77066CCCC8A">signing key for Loïc Hoguin</a> with:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt>$ gpg --keyserver hkp<span style="color: #990000">:</span>//keys<span style="color: #990000">.</span>gnupg<span style="color: #990000">.</span>net --recv-key 66CCCC8A</tt></pre></div></div>
-<div class="paragraph"><p>The primary key fingerprint is <code>F19F 189C ECC7 4396 99CE DD7A 6EF7 A770 66CC CC8A</code>.</p></div>
-<div class="paragraph"><p>When verifying signatures in git, the following should appear:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt>gpg<span style="color: #990000">:</span> Signature made Sat <span style="color: #993399">26</span> Nov <span style="color: #993399">2016</span> <span style="color: #993399">12</span><span style="color: #990000">:</span><span style="color: #993399">58</span><span style="color: #990000">:</span><span style="color: #993399">35</span> PM CET
-gpg<span style="color: #990000">:</span> using RSA key 71366FF21851DF03
-gpg<span style="color: #990000">:</span> Good signature from <span style="color: #FF0000">"Loïc Hoguin <[email protected]>"</span> <span style="color: #990000">[</span>unknown<span style="color: #990000">]</span>
-gpg<span style="color: #990000">:</span> WARNING<span style="color: #990000">:</span> This key is not certified with a trusted signature<span style="color: #990000">!</span>
-gpg<span style="color: #990000">:</span> There is no indication that the signature belongs to the owner<span style="color: #990000">.</span>
-Primary key fingerprint<span style="color: #990000">:</span> F19F 189C ECC7 <span style="color: #993399">4396</span> 99CE DD7A 6EF7 A770 66CC CC8A
- Subkey fingerprint<span style="color: #990000">:</span> FEDA <span style="color: #993399">6E41</span> B390 F745 A385 5CDC <span style="color: #993399">7136</span> 6FF2 <span style="color: #993399">1851</span> DF03</tt></pre></div></div>
-<div class="paragraph"><p>You can safely ignore the warning if you don’t know what it
-means, as long as everything else is correct.</p></div>
-<div class="paragraph"><p>Mirrors and signature verification will soon be implemented
-directly in Erlang.mk. In the meantime, you will need to
-set them up manually.</p></div>
-<div class="paragraph"><p>Most of this work was done to fix issues in RabbitMQ. Paid
-customers get priority; contact me if you have some issues
-that need fixing sooner rather than later.</p></div>
-<div class="paragraph"><p>Expect future releases to be announced in this space.</p></div>
-<div class="paragraph"><p>Thanks for reading!</p></div>
+<div class="paragraph"><p>Ranch <code>1.3.0</code> has been released!</p></div> +<div class="paragraph"><p>This release fixes a number of long standing issues and adds +a small number of features:</p></div> +<div class="paragraph"><p>The <code>ssl</code> application has been added to the list of dependencies. +If you don’t need it, you can remove it automatically when fetching +Ranch or when building the release. If you do need it, you will no +longer have issues shutting down a node because of Ranch.</p></div> +<div class="paragraph"><p>The <code>ranch:info/0</code> and <code>ranch:procs/2</code> can be used to retrieve +information about Ranch’s state. Use it for diagnostic and +discovery purposes.</p></div> +<div class="paragraph"><p>SSL listeners can now be configured without a certificate, for setups +that make use of the SNI extension.</p></div> +<div class="paragraph"><p>Transport options are now a blacklist, meaning all unknown options +will be accepted. However Dialyzer will warn if said option is not +defined in Ranch’s type specifications. Please send a patch when that +happens!</p></div> +<div class="paragraph"><p>Various bugs have been fixed, including the bug where the +number of active connections could become negative. Common +errors at listener startup should be easier to read (for +example when the port is already in use).</p></div> +<div class="paragraph"><p>See the <a href="https://git.ninenines.eu/ranch.git/plain/CHANGELOG.asciidoc">CHANGELOG</a> +for more details.</p></div> +<div class="paragraph"><p>Ranch is now tested and supported with Erlang/OTP R16B or above +on Arch Linux, FreeBSD, OSX, Ubuntu and Windows 7. Contact me +if you can provide permanent access to another platform for the +purposes of testing.</p></div> +<div class="paragraph"><p>Ranch is now available from four locations:</p></div> +<div class="ulist"><ul> +<li> +<p> +<a href="https://git.ninenines.eu/ranch.git">https://git.ninenines.eu/ranch.git</a> +</p> +</li> +<li> +<p> +<a href="https://github.com/ninenines/ranch.git">https://github.com/ninenines/ranch.git</a> +</p> +</li> +<li> +<p> +<a href="https://bitbucket.org/ninenines/ranch.git">https://bitbucket.org/ninenines/ranch.git</a> +</p> +</li> +<li> +<p> +<a href="https://gitlab.com/ninenines/ranch.git">https://gitlab.com/ninenines/ranch.git</a> +</p> +</li> +</ul></div> +<div class="paragraph"><p>They are updated at the same time so there is no real difference.</p></div> +<div class="paragraph"><p>The most recent Ranch commit is now always signed. You can import the +<a href="https://pgp.mit.edu/pks/lookup?op=vindex&fingerprint=on&exact=on&search=0xF19F189CECC7439699CEDD7A6EF7A77066CCCC8A">signing key for Loïc Hoguin</a> with:</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt>$ gpg --keyserver hkp<span style="color: #990000">:</span>//keys<span style="color: #990000">.</span>gnupg<span style="color: #990000">.</span>net --recv-key 66CCCC8A</tt></pre></div></div> +<div class="paragraph"><p>The primary key fingerprint is <code>F19F 189C ECC7 4396 99CE DD7A 6EF7 A770 66CC CC8A</code>.</p></div> +<div class="paragraph"><p>When verifying signatures in git, the following should appear:</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt>gpg<span style="color: #990000">:</span> Signature made Sat <span style="color: #993399">26</span> Nov <span style="color: #993399">2016</span> <span style="color: #993399">12</span><span style="color: #990000">:</span><span style="color: #993399">58</span><span style="color: #990000">:</span><span style="color: #993399">35</span> PM CET +gpg<span style="color: #990000">:</span> using RSA key 71366FF21851DF03 +gpg<span style="color: #990000">:</span> Good signature from <span style="color: #FF0000">"Loïc Hoguin <[email protected]>"</span> <span style="color: #990000">[</span>unknown<span style="color: #990000">]</span> +gpg<span style="color: #990000">:</span> WARNING<span style="color: #990000">:</span> This key is not certified with a trusted signature<span style="color: #990000">!</span> +gpg<span style="color: #990000">:</span> There is no indication that the signature belongs to the owner<span style="color: #990000">.</span> +Primary key fingerprint<span style="color: #990000">:</span> F19F 189C ECC7 <span style="color: #993399">4396</span> 99CE DD7A 6EF7 A770 66CC CC8A + Subkey fingerprint<span style="color: #990000">:</span> FEDA <span style="color: #993399">6E41</span> B390 F745 A385 5CDC <span style="color: #993399">7136</span> 6FF2 <span style="color: #993399">1851</span> DF03</tt></pre></div></div> +<div class="paragraph"><p>You can safely ignore the warning if you don’t know what it +means, as long as everything else is correct.</p></div> +<div class="paragraph"><p>Mirrors and signature verification will soon be implemented +directly in Erlang.mk. In the meantime, you will need to +set them up manually.</p></div> +<div class="paragraph"><p>Most of this work was done to fix issues in RabbitMQ. Paid +customers get priority; contact me if you have some issues +that need fixing sooner rather than later.</p></div> +<div class="paragraph"><p>Expect future releases to be announced in this space.</p></div> +<div class="paragraph"><p>Thanks for reading!</p></div> </article> </div> @@ -164,55 +164,107 @@ that need fixing sooner rather than later.</p></div> <h3>More articles</h3> <ul id="articles-nav" class="extra_margin"> - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + - <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + + <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + - <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + + <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + - <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + + <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + - <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + + <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + - <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + + <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + - <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + + <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + - <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + + <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + - <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + + <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + - <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + + <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + - <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + + <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + + + </ul> diff --git a/articles/ranch-ftp/index.html b/articles/ranch-ftp/index.html index 727d4b1a..241750f0 100644 --- a/articles/ranch-ftp/index.html +++ b/articles/ranch-ftp/index.html @@ -7,7 +7,7 @@ <meta name="description" content=""> <meta name="author" content="Loïc Hoguin based on a design from (Soft10) Pol Cámara"> - <meta name="generator" content="Hugo 0.17" /> + <meta name="generator" content="Hugo 0.26" /> <title>Nine Nines: Build an FTP Server with Ranch in 30 Minutes</title> @@ -74,216 +74,216 @@ </p> </header> -<div class="paragraph"><p>Last week I was speaking at the
-<a href="http://www.erlang-factory.com/conference/London2012/speakers/LoicHoguin">London Erlang Factory Lite</a>
-where I presented a live demonstration of building an FTP server using
-<a href="http://ninenines.eu/docs/en/ranch/HEAD/README">Ranch</a>.
-As there was no slide, you should use this article as a reference instead.</p></div>
-<div class="paragraph"><p>The goal of this article is to showcase how to use Ranch for writing
-a network protocol implementation, how Ranch gets out of the way to let
-you write the code that matters, and the common techniques used when
-writing servers.</p></div>
-<div class="paragraph"><p>Let’s start by creating an empty project. Create a new directory and
-then open a terminal into that directory. The first step is to add Ranch
-as a dependency. Create the <code>rebar.config</code> file and add the
-following 3 lines.</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt>{<span style="color: #FF6600">deps</span>, [
- {<span style="color: #FF6600">ranch</span>, <span style="color: #FF0000">".*"</span>, {<span style="color: #FF6600">git</span>, <span style="color: #FF0000">"git://github.com/extend/ranch.git"</span>, <span style="color: #FF0000">"master"</span>}}
-]}<span style="color: #990000">.</span></tt></pre></div></div>
-<div class="paragraph"><p>This makes your application depend on the last Ranch version available
-on the <em>master</em> branch. This is fine for development, however when
-you start pushing your application to production you will want to revisit
-this file to hardcode the exact version you are using, to make sure you
-run the same version of dependencies in production.</p></div>
-<div class="paragraph"><p>You can now fetch the dependencies.</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt>$ rebar get-deps
-<span style="color: #990000">==></span> ranch_ftp <span style="color: #990000">(</span>get-deps<span style="color: #990000">)</span>
-Pulling ranch from {git<span style="color: #990000">,</span><span style="color: #FF0000">"git://github.com/extend/ranch.git"</span><span style="color: #990000">,</span><span style="color: #FF0000">"master"</span>}
-Cloning into <span style="color: #FF0000">'ranch'</span><span style="color: #990000">...</span>
-<span style="color: #990000">==></span> ranch <span style="color: #990000">(</span>get-deps<span style="color: #990000">)</span></tt></pre></div></div>
-<div class="paragraph"><p>This will create a <em>deps/</em> folder containing Ranch.</p></div>
-<div class="paragraph"><p>We don’t actually need anything else to write the protocol code.
-We could make an application for it, but this isn’t the purpose of this
-article so let’s just move on to writing the protocol itself. Create
-the file <em>ranch_ftp_protocol.erl</em> and open it in your favorite
-editor.</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt>$ vim ranch_ftp_protocol<span style="color: #990000">.</span>erl</tt></pre></div></div>
-<div class="paragraph"><p>Let’s start with a blank protocol module.</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="font-weight: bold"><span style="color: #000080">-module</span></span>(<span style="color: #FF6600">ranch_ftp_protocol</span>)<span style="color: #990000">.</span>
-<span style="font-weight: bold"><span style="color: #000080">-export</span></span>([<span style="font-weight: bold"><span style="color: #000000">start_link</span></span><span style="color: #990000">/</span><span style="color: #993399">4</span>, <span style="font-weight: bold"><span style="color: #000000">init</span></span><span style="color: #990000">/</span><span style="color: #993399">3</span>])<span style="color: #990000">.</span>
-
-<span style="font-weight: bold"><span style="color: #000000">start_link</span></span>(<span style="color: #009900">ListenerPid</span>, <span style="color: #009900">Socket</span>, <span style="color: #009900">Transport</span>, <span style="color: #009900">Opts</span>) <span style="color: #990000">-></span>
- <span style="color: #009900">Pid</span> <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000080">spawn_link</span></span>(<span style="font-weight: bold"><span style="color: #000080">?MODULE</span></span>, <span style="color: #FF6600">init</span>, [<span style="color: #009900">ListenerPid</span>, <span style="color: #009900">Socket</span>, <span style="color: #009900">Transport</span>]),
- {<span style="color: #FF6600">ok</span>, <span style="color: #009900">Pid</span>}<span style="color: #990000">.</span>
-
-<span style="font-weight: bold"><span style="color: #000000">init</span></span>(<span style="color: #009900">ListenerPid</span>, <span style="color: #009900">Socket</span>, <span style="color: #009900">Transport</span>) <span style="color: #990000">-></span>
- <span style="font-weight: bold"><span style="color: #000000">io:format</span></span>(<span style="color: #FF0000">"Got a connection!~n"</span>),
- <span style="color: #FF6600">ok</span><span style="color: #990000">.</span></tt></pre></div></div>
-<div class="paragraph"><p>When Ranch receives a connection, it will call the <code>start_link/4</code>
-function with the listener’s pid, socket, transport module to be used,
-and the options we define when starting the listener. We don’t need options
-for the purpose of this article, so we don’t pass them to the process we are
-creating.</p></div>
-<div class="paragraph"><p>Let’s open a shell and start a Ranch listener to begin accepting
-connections. We only need to call one function. You should probably open
-it in another terminal and keep it open for convenience. If you quit
-the shell you will have to repeat the commands to proceed.</p></div>
-<div class="paragraph"><p>Also note that you need to type <code>c(ranch_ftp_protocol).</code>
-to recompile and reload the code for the protocol. You do not need to
-restart any process however.</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt>$ erl -pa ebin deps<span style="color: #990000">/*</span>/ebin
-Erlang R15B02 <span style="color: #990000">(</span>erts-<span style="color: #993399">5.9</span><span style="color: #990000">.</span><span style="color: #993399">2</span><span style="color: #990000">)</span> <span style="color: #990000">[</span><span style="font-weight: bold"><span style="color: #0000FF">source</span></span><span style="color: #990000">]</span> <span style="color: #990000">[</span><span style="color: #993399">64</span>-bit<span style="color: #990000">]</span> <span style="color: #990000">[</span>smp<span style="color: #990000">:</span><span style="color: #993399">4</span><span style="color: #990000">:</span><span style="color: #993399">4</span><span style="color: #990000">]</span> <span style="color: #990000">[</span>async-threads<span style="color: #990000">:</span><span style="color: #993399">0</span><span style="color: #990000">]</span> <span style="color: #990000">[</span>hipe<span style="color: #990000">]</span> <span style="color: #990000">[</span>kernel-poll<span style="color: #990000">:</span><span style="font-weight: bold"><span style="color: #0000FF">false</span></span><span style="color: #990000">]</span>
-
-Eshell V5<span style="color: #990000">.</span><span style="color: #993399">9.2</span> <span style="color: #990000">(</span>abort with <span style="color: #990000">^</span>G<span style="color: #990000">)</span></tt></pre></div></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="color: #993399">1</span><span style="color: #990000">></span> <span style="font-weight: bold"><span style="color: #000000">application:start</span></span>(<span style="color: #FF6600">ranch</span>)<span style="color: #990000">.</span>
-<span style="color: #FF6600">ok</span>
-<span style="color: #993399">2</span><span style="color: #990000">></span> <span style="font-weight: bold"><span style="color: #000000">ranch:start_listener</span></span>(<span style="color: #FF6600">my_ftp</span>, <span style="color: #993399">10</span>,
- <span style="color: #FF6600">ranch_tcp</span>, [{<span style="color: #FF6600">port</span>, <span style="color: #993399">2121</span>}],
- <span style="color: #FF6600">ranch_ftp_protocol</span>, [])<span style="color: #990000">.</span>
-{<span style="color: #FF6600">ok</span>,<span style="color: #990000"><</span><span style="color: #993399">0.40</span><span style="color: #990000">.</span><span style="color: #993399">0</span><span style="color: #990000">></span>}</tt></pre></div></div>
-<div class="paragraph"><p>This starts a listener named <code>my_ftp</code> that runs your very own
-<code>ranch_ftp_protocol</code> over TCP, listening on port <code>2121</code>.
-The last argument is the options given to the protocol that we ignored
-earlier.</p></div>
-<div class="paragraph"><p>To try your code, you can use the following command. It should be able
-to connect, the server will print a message in the console, and then
-the client will print an error.</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt>$ ftp localhost <span style="color: #993399">2121</span></tt></pre></div></div>
-<div class="paragraph"><p>Let’s move on to actually writing the protocol.</p></div>
-<div class="paragraph"><p>Once you have created the new process and returned the pid, Ranch will
-give ownership of the socket to you. This requires a synchronization
-step though.</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="font-weight: bold"><span style="color: #000000">init</span></span>(<span style="color: #009900">ListenerPid</span>, <span style="color: #009900">Socket</span>, <span style="color: #009900">Transport</span>) <span style="color: #990000">-></span>
- <span style="color: #0000FF">ok</span> <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">ranch:accept_ack</span></span>(<span style="color: #009900">ListenerPid</span>),
- <span style="color: #FF6600">ok</span><span style="color: #990000">.</span></tt></pre></div></div>
-<div class="paragraph"><p>Now that you acknowledged the new connection, you can use it safely.</p></div>
-<div class="paragraph"><p>When an FTP server accepts a connection, it starts by sending a
-welcome message which can be one or more lines starting with the
-code <code>200</code>. Then the server will wait for the client
-to authenticate the user, and if the authentication went successfully,
-which it will always do for the purpose of this article, it will reply
-with a <code>230</code> code.</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="font-weight: bold"><span style="color: #000000">init</span></span>(<span style="color: #009900">ListenerPid</span>, <span style="color: #009900">Socket</span>, <span style="color: #009900">Transport</span>) <span style="color: #990000">-></span>
- <span style="color: #0000FF">ok</span> <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">ranch:accept_ack</span></span>(<span style="color: #009900">ListenerPid</span>),
- <span style="color: #009900">Transport</span><span style="color: #990000">:</span><span style="font-weight: bold"><span style="color: #000000">send</span></span>(<span style="color: #009900">Socket</span>, <span style="color: #990000"><<</span><span style="color: #FF0000">"200 My cool FTP server welcomes you!\r\n"</span><span style="color: #990000">>></span>),
- {<span style="color: #FF6600">ok</span>, <span style="color: #009900">Data</span>} <span style="color: #990000">=</span> <span style="color: #009900">Transport</span><span style="color: #990000">:</span><span style="font-weight: bold"><span style="color: #000000">recv</span></span>(<span style="color: #009900">Socket</span>, <span style="color: #993399">0</span>, <span style="color: #993399">30000</span>),
- <span style="font-weight: bold"><span style="color: #000000">auth</span></span>(<span style="color: #009900">Socket</span>, <span style="color: #009900">Transport</span>, <span style="color: #009900">Data</span>)<span style="color: #990000">.</span>
-
-<span style="font-weight: bold"><span style="color: #000000">auth</span></span>(<span style="color: #009900">Socket</span>, <span style="color: #009900">Transport</span>, <span style="color: #990000"><<</span><span style="color: #FF0000">"USER "</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span><span style="color: #990000">>></span>) <span style="color: #990000">-></span>
- <span style="font-weight: bold"><span style="color: #000000">io:format</span></span>(<span style="color: #FF0000">"User authenticated! ~p~n"</span>, [<span style="color: #009900">Rest</span>]),
- <span style="color: #009900">Transport</span><span style="color: #990000">:</span><span style="font-weight: bold"><span style="color: #000000">send</span></span>(<span style="color: #009900">Socket</span>, <span style="color: #990000"><<</span><span style="color: #FF0000">"230 Auth OK\r\n"</span><span style="color: #990000">>></span>),
- <span style="color: #FF6600">ok</span><span style="color: #990000">.</span></tt></pre></div></div>
-<div class="paragraph"><p>As you can see we don’t need complex parsing code. We can simply
-match on the binary in the argument!</p></div>
-<div class="paragraph"><p>Next we need to loop receiving data commands and optionally
-execute them, if we want our server to become useful.</p></div>
-<div class="paragraph"><p>We will replace the <code>ok.</code> line with the call to
-the following function. The new function is recursive, each call
-receiving data from the socket and sending a response. For now
-we will send an error response for all commands the client sends.</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="font-weight: bold"><span style="color: #000000">loop</span></span>(<span style="color: #009900">Socket</span>, <span style="color: #009900">Transport</span>) <span style="color: #990000">-></span>
- <span style="font-weight: bold"><span style="color: #0000FF">case</span></span> <span style="color: #009900">Transport</span><span style="color: #990000">:</span><span style="font-weight: bold"><span style="color: #000000">recv</span></span>(<span style="color: #009900">Socket</span>, <span style="color: #993399">0</span>, <span style="color: #993399">30000</span>) <span style="font-weight: bold"><span style="color: #0000FF">of</span></span>
- {<span style="color: #FF6600">ok</span>, <span style="color: #009900">Data</span>} <span style="color: #990000">-></span>
- <span style="font-weight: bold"><span style="color: #000000">handle</span></span>(<span style="color: #009900">Socket</span>, <span style="color: #009900">Transport</span>, <span style="color: #009900">Data</span>),
- <span style="font-weight: bold"><span style="color: #000000">loop</span></span>(<span style="color: #009900">Socket</span>, <span style="color: #009900">Transport</span>);
- {<span style="color: #FF6600">error</span>, <span style="color: #990000">_</span>} <span style="color: #990000">-></span>
- <span style="font-weight: bold"><span style="color: #000000">io:format</span></span>(<span style="color: #FF0000">"The client disconnected~n"</span>)
- <span style="font-weight: bold"><span style="color: #0000FF">end</span></span><span style="color: #990000">.</span>
-
-<span style="font-weight: bold"><span style="color: #000000">handle</span></span>(<span style="color: #009900">Socket</span>, <span style="color: #009900">Transport</span>, <span style="color: #009900">Data</span>) <span style="color: #990000">-></span>
- <span style="font-weight: bold"><span style="color: #000000">io:format</span></span>(<span style="color: #FF0000">"Command received ~p~n"</span>, [<span style="color: #009900">Data</span>]),
- <span style="color: #009900">Transport</span><span style="color: #990000">:</span><span style="font-weight: bold"><span style="color: #000000">send</span></span>(<span style="color: #009900">Socket</span>, <span style="color: #990000"><<</span><span style="color: #FF0000">"500 Bad command\r\n"</span><span style="color: #990000">>></span>)<span style="color: #990000">.</span></tt></pre></div></div>
-<div class="paragraph"><p>With this we are almost ready to start implementing commands.
-But with code like this we might have errors if the client doesn’t
-send just one command per packet, or if the packets arrive too fast,
-or if a command is split over multiple packets.</p></div>
-<div class="paragraph"><p>To solve this, we need to use a buffer. Each time we receive data,
-we will append to the buffer, and then check if we have received a
-command fully before running it. The code could look similar to the
-following.</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="font-weight: bold"><span style="color: #000000">loop</span></span>(<span style="color: #009900">Socket</span>, <span style="color: #009900">Transport</span>, <span style="color: #009900">Buffer</span>) <span style="color: #990000">-></span>
- <span style="font-weight: bold"><span style="color: #0000FF">case</span></span> <span style="color: #009900">Transport</span><span style="color: #990000">:</span><span style="font-weight: bold"><span style="color: #000000">recv</span></span>(<span style="color: #009900">Socket</span>, <span style="color: #993399">0</span>, <span style="color: #993399">30000</span>) <span style="font-weight: bold"><span style="color: #0000FF">of</span></span>
- {<span style="color: #FF6600">ok</span>, <span style="color: #009900">Data</span>} <span style="color: #990000">-></span>
- <span style="color: #009900">Buffer2</span> <span style="color: #990000">=</span> <span style="color: #990000"><<</span> <span style="color: #009900">Buffer</span><span style="color: #990000">/</span><span style="font-weight: bold"><span style="color: #000080">binary</span></span>, <span style="color: #009900">Data</span><span style="color: #990000">/</span><span style="font-weight: bold"><span style="color: #000080">binary</span></span> <span style="color: #990000">>></span>,
- {<span style="color: #009900">Commands</span>, <span style="color: #009900">Rest</span>} <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">split</span></span>(<span style="color: #009900">Buffer2</span>),
- [<span style="font-weight: bold"><span style="color: #000000">handle</span></span>(<span style="color: #009900">Socket</span>, <span style="color: #009900">Transport</span>, <span style="color: #009900">C</span>) || <span style="color: #009900">C</span> <span style="color: #990000"><-</span> <span style="color: #009900">Commands</span>],
- <span style="font-weight: bold"><span style="color: #000000">loop</span></span>(<span style="color: #009900">Socket</span>, <span style="color: #009900">Transport</span>, <span style="color: #009900">Rest</span>);
- {<span style="color: #FF6600">error</span>, <span style="color: #990000">_</span>} <span style="color: #990000">-></span>
- <span style="font-weight: bold"><span style="color: #000000">io:format</span></span>(<span style="color: #FF0000">"The client disconnected~n"</span>)
- <span style="font-weight: bold"><span style="color: #0000FF">end</span></span><span style="color: #990000">.</span></tt></pre></div></div>
-<div class="paragraph"><p>The implementation of <code>split/1</code> is left as an exercice
-to the reader. You will also probably want to handle the <code>QUIT</code>
-command, which must stop any processing and close the connection.</p></div>
-<div class="paragraph"><p>The attentive reader will also take note that in the case of text-
-based protocols where commands are separated by line breaks, you can
-set an option using <code>Transport:setopts/2</code> and have all the
-buffering done for you for free by Erlang itself.</p></div>
-<div class="paragraph"><p>As you can surely notice by now, Ranch allows us to build network
-applications by getting out of our way entirely past the initial setup.
-It lets you use the power of binary pattern matching to write text and
-binary protocol implementations in just a few lines of code.</p></div>
-<div class="ulist"><ul>
-<li>
-<p>
-<a href="http://www.erlang-factory.com/conference/London2012/speakers/LoicHoguin">Watch the talk</a>
-</p>
-</li>
-</ul></div>
+<div class="paragraph"><p>Last week I was speaking at the +<a href="http://www.erlang-factory.com/conference/London2012/speakers/LoicHoguin">London Erlang Factory Lite</a> +where I presented a live demonstration of building an FTP server using +<a href="http://ninenines.eu/docs/en/ranch/HEAD/README">Ranch</a>. +As there was no slide, you should use this article as a reference instead.</p></div> +<div class="paragraph"><p>The goal of this article is to showcase how to use Ranch for writing +a network protocol implementation, how Ranch gets out of the way to let +you write the code that matters, and the common techniques used when +writing servers.</p></div> +<div class="paragraph"><p>Let’s start by creating an empty project. Create a new directory and +then open a terminal into that directory. The first step is to add Ranch +as a dependency. Create the <code>rebar.config</code> file and add the +following 3 lines.</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt>{<span style="color: #FF6600">deps</span>, [ + {<span style="color: #FF6600">ranch</span>, <span style="color: #FF0000">".*"</span>, {<span style="color: #FF6600">git</span>, <span style="color: #FF0000">"git://github.com/extend/ranch.git"</span>, <span style="color: #FF0000">"master"</span>}} +]}<span style="color: #990000">.</span></tt></pre></div></div> +<div class="paragraph"><p>This makes your application depend on the last Ranch version available +on the <em>master</em> branch. This is fine for development, however when +you start pushing your application to production you will want to revisit +this file to hardcode the exact version you are using, to make sure you +run the same version of dependencies in production.</p></div> +<div class="paragraph"><p>You can now fetch the dependencies.</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt>$ rebar get-deps +<span style="color: #990000">==></span> ranch_ftp <span style="color: #990000">(</span>get-deps<span style="color: #990000">)</span> +Pulling ranch from {git<span style="color: #990000">,</span><span style="color: #FF0000">"git://github.com/extend/ranch.git"</span><span style="color: #990000">,</span><span style="color: #FF0000">"master"</span>} +Cloning into <span style="color: #FF0000">'ranch'</span><span style="color: #990000">...</span> +<span style="color: #990000">==></span> ranch <span style="color: #990000">(</span>get-deps<span style="color: #990000">)</span></tt></pre></div></div> +<div class="paragraph"><p>This will create a <em>deps/</em> folder containing Ranch.</p></div> +<div class="paragraph"><p>We don’t actually need anything else to write the protocol code. +We could make an application for it, but this isn’t the purpose of this +article so let’s just move on to writing the protocol itself. Create +the file <em>ranch_ftp_protocol.erl</em> and open it in your favorite +editor.</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt>$ vim ranch_ftp_protocol<span style="color: #990000">.</span>erl</tt></pre></div></div> +<div class="paragraph"><p>Let’s start with a blank protocol module.</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="font-weight: bold"><span style="color: #000080">-module</span></span>(<span style="color: #FF6600">ranch_ftp_protocol</span>)<span style="color: #990000">.</span> +<span style="font-weight: bold"><span style="color: #000080">-export</span></span>([<span style="font-weight: bold"><span style="color: #000000">start_link</span></span><span style="color: #990000">/</span><span style="color: #993399">4</span>, <span style="font-weight: bold"><span style="color: #000000">init</span></span><span style="color: #990000">/</span><span style="color: #993399">3</span>])<span style="color: #990000">.</span> + +<span style="font-weight: bold"><span style="color: #000000">start_link</span></span>(<span style="color: #009900">ListenerPid</span>, <span style="color: #009900">Socket</span>, <span style="color: #009900">Transport</span>, <span style="color: #009900">Opts</span>) <span style="color: #990000">-></span> + <span style="color: #009900">Pid</span> <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000080">spawn_link</span></span>(<span style="font-weight: bold"><span style="color: #000080">?MODULE</span></span>, <span style="color: #FF6600">init</span>, [<span style="color: #009900">ListenerPid</span>, <span style="color: #009900">Socket</span>, <span style="color: #009900">Transport</span>]), + {<span style="color: #FF6600">ok</span>, <span style="color: #009900">Pid</span>}<span style="color: #990000">.</span> + +<span style="font-weight: bold"><span style="color: #000000">init</span></span>(<span style="color: #009900">ListenerPid</span>, <span style="color: #009900">Socket</span>, <span style="color: #009900">Transport</span>) <span style="color: #990000">-></span> + <span style="font-weight: bold"><span style="color: #000000">io:format</span></span>(<span style="color: #FF0000">"Got a connection!~n"</span>), + <span style="color: #FF6600">ok</span><span style="color: #990000">.</span></tt></pre></div></div> +<div class="paragraph"><p>When Ranch receives a connection, it will call the <code>start_link/4</code> +function with the listener’s pid, socket, transport module to be used, +and the options we define when starting the listener. We don’t need options +for the purpose of this article, so we don’t pass them to the process we are +creating.</p></div> +<div class="paragraph"><p>Let’s open a shell and start a Ranch listener to begin accepting +connections. We only need to call one function. You should probably open +it in another terminal and keep it open for convenience. If you quit +the shell you will have to repeat the commands to proceed.</p></div> +<div class="paragraph"><p>Also note that you need to type <code>c(ranch_ftp_protocol).</code> +to recompile and reload the code for the protocol. You do not need to +restart any process however.</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt>$ erl -pa ebin deps<span style="color: #990000">/*</span>/ebin +Erlang R15B02 <span style="color: #990000">(</span>erts-<span style="color: #993399">5.9</span><span style="color: #990000">.</span><span style="color: #993399">2</span><span style="color: #990000">)</span> <span style="color: #990000">[</span><span style="font-weight: bold"><span style="color: #0000FF">source</span></span><span style="color: #990000">]</span> <span style="color: #990000">[</span><span style="color: #993399">64</span>-bit<span style="color: #990000">]</span> <span style="color: #990000">[</span>smp<span style="color: #990000">:</span><span style="color: #993399">4</span><span style="color: #990000">:</span><span style="color: #993399">4</span><span style="color: #990000">]</span> <span style="color: #990000">[</span>async-threads<span style="color: #990000">:</span><span style="color: #993399">0</span><span style="color: #990000">]</span> <span style="color: #990000">[</span>hipe<span style="color: #990000">]</span> <span style="color: #990000">[</span>kernel-poll<span style="color: #990000">:</span><span style="font-weight: bold"><span style="color: #0000FF">false</span></span><span style="color: #990000">]</span> + +Eshell V5<span style="color: #990000">.</span><span style="color: #993399">9.2</span> <span style="color: #990000">(</span>abort with <span style="color: #990000">^</span>G<span style="color: #990000">)</span></tt></pre></div></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="color: #993399">1</span><span style="color: #990000">></span> <span style="font-weight: bold"><span style="color: #000000">application:start</span></span>(<span style="color: #FF6600">ranch</span>)<span style="color: #990000">.</span> +<span style="color: #FF6600">ok</span> +<span style="color: #993399">2</span><span style="color: #990000">></span> <span style="font-weight: bold"><span style="color: #000000">ranch:start_listener</span></span>(<span style="color: #FF6600">my_ftp</span>, <span style="color: #993399">10</span>, + <span style="color: #FF6600">ranch_tcp</span>, [{<span style="color: #FF6600">port</span>, <span style="color: #993399">2121</span>}], + <span style="color: #FF6600">ranch_ftp_protocol</span>, [])<span style="color: #990000">.</span> +{<span style="color: #FF6600">ok</span>,<span style="color: #990000"><</span><span style="color: #993399">0.40</span><span style="color: #990000">.</span><span style="color: #993399">0</span><span style="color: #990000">></span>}</tt></pre></div></div> +<div class="paragraph"><p>This starts a listener named <code>my_ftp</code> that runs your very own +<code>ranch_ftp_protocol</code> over TCP, listening on port <code>2121</code>. +The last argument is the options given to the protocol that we ignored +earlier.</p></div> +<div class="paragraph"><p>To try your code, you can use the following command. It should be able +to connect, the server will print a message in the console, and then +the client will print an error.</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt>$ ftp localhost <span style="color: #993399">2121</span></tt></pre></div></div> +<div class="paragraph"><p>Let’s move on to actually writing the protocol.</p></div> +<div class="paragraph"><p>Once you have created the new process and returned the pid, Ranch will +give ownership of the socket to you. This requires a synchronization +step though.</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="font-weight: bold"><span style="color: #000000">init</span></span>(<span style="color: #009900">ListenerPid</span>, <span style="color: #009900">Socket</span>, <span style="color: #009900">Transport</span>) <span style="color: #990000">-></span> + <span style="color: #0000FF">ok</span> <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">ranch:accept_ack</span></span>(<span style="color: #009900">ListenerPid</span>), + <span style="color: #FF6600">ok</span><span style="color: #990000">.</span></tt></pre></div></div> +<div class="paragraph"><p>Now that you acknowledged the new connection, you can use it safely.</p></div> +<div class="paragraph"><p>When an FTP server accepts a connection, it starts by sending a +welcome message which can be one or more lines starting with the +code <code>200</code>. Then the server will wait for the client +to authenticate the user, and if the authentication went successfully, +which it will always do for the purpose of this article, it will reply +with a <code>230</code> code.</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="font-weight: bold"><span style="color: #000000">init</span></span>(<span style="color: #009900">ListenerPid</span>, <span style="color: #009900">Socket</span>, <span style="color: #009900">Transport</span>) <span style="color: #990000">-></span> + <span style="color: #0000FF">ok</span> <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">ranch:accept_ack</span></span>(<span style="color: #009900">ListenerPid</span>), + <span style="color: #009900">Transport</span><span style="color: #990000">:</span><span style="font-weight: bold"><span style="color: #000000">send</span></span>(<span style="color: #009900">Socket</span>, <span style="color: #990000"><<</span><span style="color: #FF0000">"200 My cool FTP server welcomes you!\r\n"</span><span style="color: #990000">>></span>), + {<span style="color: #FF6600">ok</span>, <span style="color: #009900">Data</span>} <span style="color: #990000">=</span> <span style="color: #009900">Transport</span><span style="color: #990000">:</span><span style="font-weight: bold"><span style="color: #000000">recv</span></span>(<span style="color: #009900">Socket</span>, <span style="color: #993399">0</span>, <span style="color: #993399">30000</span>), + <span style="font-weight: bold"><span style="color: #000000">auth</span></span>(<span style="color: #009900">Socket</span>, <span style="color: #009900">Transport</span>, <span style="color: #009900">Data</span>)<span style="color: #990000">.</span> + +<span style="font-weight: bold"><span style="color: #000000">auth</span></span>(<span style="color: #009900">Socket</span>, <span style="color: #009900">Transport</span>, <span style="color: #990000"><<</span><span style="color: #FF0000">"USER "</span>, <span style="color: #009900">Rest</span><span style="color: #990000">/</span><span style="color: #FF6600">bits</span><span style="color: #990000">>></span>) <span style="color: #990000">-></span> + <span style="font-weight: bold"><span style="color: #000000">io:format</span></span>(<span style="color: #FF0000">"User authenticated! ~p~n"</span>, [<span style="color: #009900">Rest</span>]), + <span style="color: #009900">Transport</span><span style="color: #990000">:</span><span style="font-weight: bold"><span style="color: #000000">send</span></span>(<span style="color: #009900">Socket</span>, <span style="color: #990000"><<</span><span style="color: #FF0000">"230 Auth OK\r\n"</span><span style="color: #990000">>></span>), + <span style="color: #FF6600">ok</span><span style="color: #990000">.</span></tt></pre></div></div> +<div class="paragraph"><p>As you can see we don’t need complex parsing code. We can simply +match on the binary in the argument!</p></div> +<div class="paragraph"><p>Next we need to loop receiving data commands and optionally +execute them, if we want our server to become useful.</p></div> +<div class="paragraph"><p>We will replace the <code>ok.</code> line with the call to +the following function. The new function is recursive, each call +receiving data from the socket and sending a response. For now +we will send an error response for all commands the client sends.</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="font-weight: bold"><span style="color: #000000">loop</span></span>(<span style="color: #009900">Socket</span>, <span style="color: #009900">Transport</span>) <span style="color: #990000">-></span> + <span style="font-weight: bold"><span style="color: #0000FF">case</span></span> <span style="color: #009900">Transport</span><span style="color: #990000">:</span><span style="font-weight: bold"><span style="color: #000000">recv</span></span>(<span style="color: #009900">Socket</span>, <span style="color: #993399">0</span>, <span style="color: #993399">30000</span>) <span style="font-weight: bold"><span style="color: #0000FF">of</span></span> + {<span style="color: #FF6600">ok</span>, <span style="color: #009900">Data</span>} <span style="color: #990000">-></span> + <span style="font-weight: bold"><span style="color: #000000">handle</span></span>(<span style="color: #009900">Socket</span>, <span style="color: #009900">Transport</span>, <span style="color: #009900">Data</span>), + <span style="font-weight: bold"><span style="color: #000000">loop</span></span>(<span style="color: #009900">Socket</span>, <span style="color: #009900">Transport</span>); + {<span style="color: #FF6600">error</span>, <span style="color: #990000">_</span>} <span style="color: #990000">-></span> + <span style="font-weight: bold"><span style="color: #000000">io:format</span></span>(<span style="color: #FF0000">"The client disconnected~n"</span>) + <span style="font-weight: bold"><span style="color: #0000FF">end</span></span><span style="color: #990000">.</span> + +<span style="font-weight: bold"><span style="color: #000000">handle</span></span>(<span style="color: #009900">Socket</span>, <span style="color: #009900">Transport</span>, <span style="color: #009900">Data</span>) <span style="color: #990000">-></span> + <span style="font-weight: bold"><span style="color: #000000">io:format</span></span>(<span style="color: #FF0000">"Command received ~p~n"</span>, [<span style="color: #009900">Data</span>]), + <span style="color: #009900">Transport</span><span style="color: #990000">:</span><span style="font-weight: bold"><span style="color: #000000">send</span></span>(<span style="color: #009900">Socket</span>, <span style="color: #990000"><<</span><span style="color: #FF0000">"500 Bad command\r\n"</span><span style="color: #990000">>></span>)<span style="color: #990000">.</span></tt></pre></div></div> +<div class="paragraph"><p>With this we are almost ready to start implementing commands. +But with code like this we might have errors if the client doesn’t +send just one command per packet, or if the packets arrive too fast, +or if a command is split over multiple packets.</p></div> +<div class="paragraph"><p>To solve this, we need to use a buffer. Each time we receive data, +we will append to the buffer, and then check if we have received a +command fully before running it. The code could look similar to the +following.</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="font-weight: bold"><span style="color: #000000">loop</span></span>(<span style="color: #009900">Socket</span>, <span style="color: #009900">Transport</span>, <span style="color: #009900">Buffer</span>) <span style="color: #990000">-></span> + <span style="font-weight: bold"><span style="color: #0000FF">case</span></span> <span style="color: #009900">Transport</span><span style="color: #990000">:</span><span style="font-weight: bold"><span style="color: #000000">recv</span></span>(<span style="color: #009900">Socket</span>, <span style="color: #993399">0</span>, <span style="color: #993399">30000</span>) <span style="font-weight: bold"><span style="color: #0000FF">of</span></span> + {<span style="color: #FF6600">ok</span>, <span style="color: #009900">Data</span>} <span style="color: #990000">-></span> + <span style="color: #009900">Buffer2</span> <span style="color: #990000">=</span> <span style="color: #990000"><<</span> <span style="color: #009900">Buffer</span><span style="color: #990000">/</span><span style="font-weight: bold"><span style="color: #000080">binary</span></span>, <span style="color: #009900">Data</span><span style="color: #990000">/</span><span style="font-weight: bold"><span style="color: #000080">binary</span></span> <span style="color: #990000">>></span>, + {<span style="color: #009900">Commands</span>, <span style="color: #009900">Rest</span>} <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">split</span></span>(<span style="color: #009900">Buffer2</span>), + [<span style="font-weight: bold"><span style="color: #000000">handle</span></span>(<span style="color: #009900">Socket</span>, <span style="color: #009900">Transport</span>, <span style="color: #009900">C</span>) || <span style="color: #009900">C</span> <span style="color: #990000"><-</span> <span style="color: #009900">Commands</span>], + <span style="font-weight: bold"><span style="color: #000000">loop</span></span>(<span style="color: #009900">Socket</span>, <span style="color: #009900">Transport</span>, <span style="color: #009900">Rest</span>); + {<span style="color: #FF6600">error</span>, <span style="color: #990000">_</span>} <span style="color: #990000">-></span> + <span style="font-weight: bold"><span style="color: #000000">io:format</span></span>(<span style="color: #FF0000">"The client disconnected~n"</span>) + <span style="font-weight: bold"><span style="color: #0000FF">end</span></span><span style="color: #990000">.</span></tt></pre></div></div> +<div class="paragraph"><p>The implementation of <code>split/1</code> is left as an exercice +to the reader. You will also probably want to handle the <code>QUIT</code> +command, which must stop any processing and close the connection.</p></div> +<div class="paragraph"><p>The attentive reader will also take note that in the case of text- +based protocols where commands are separated by line breaks, you can +set an option using <code>Transport:setopts/2</code> and have all the +buffering done for you for free by Erlang itself.</p></div> +<div class="paragraph"><p>As you can surely notice by now, Ranch allows us to build network +applications by getting out of our way entirely past the initial setup. +It lets you use the power of binary pattern matching to write text and +binary protocol implementations in just a few lines of code.</p></div> +<div class="ulist"><ul> +<li> +<p> +<a href="http://www.erlang-factory.com/conference/London2012/speakers/LoicHoguin">Watch the talk</a> +</p> +</li> +</ul></div> </article> </div> @@ -292,55 +292,107 @@ binary protocol implementations in just a few lines of code.</p></div> <h3>More articles</h3> <ul id="articles-nav" class="extra_margin"> - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + + + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + + <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + - <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + + <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + - <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + + <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + - <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + + <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + - <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + + <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + - <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + + <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + - <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + + <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + - <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + + <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + - <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + + <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + - <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + + <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + - <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + </ul> diff --git a/articles/the-elephant-in-the-room/index.html b/articles/the-elephant-in-the-room/index.html index c9def49a..a445edfc 100644 --- a/articles/the-elephant-in-the-room/index.html +++ b/articles/the-elephant-in-the-room/index.html @@ -7,7 +7,7 @@ <meta name="description" content=""> <meta name="author" content="Loïc Hoguin based on a design from (Soft10) Pol Cámara"> - <meta name="generator" content="Hugo 0.17" /> + <meta name="generator" content="Hugo 0.26" /> <title>Nine Nines: The elephant in the room</title> @@ -74,139 +74,139 @@ </p> </header> -<div class="paragraph"><p>Have you ever tried telling someone why they should use
-Erlang? You boast the smaller code size, the auto healing
-mechanisms, the distribution and they seem really excited.
-They wonder why they never heard about Erlang before. And
-then you show them what the code looks like. All excitement
-goes away. The smiles disappear. Their face starts
-becoming really serious.</p></div>
-<div class="paragraph"><p>You lost them. You know you lost them. They comment on the
-syntax, or perhaps you do, already admitting defeat. It’s
-unlike anything they have ever used before. And they will
-most likely end up not using it.</p></div>
-<div class="paragraph"><p>What about people who already know what the syntax looks
-like? As soon as you mention Erlang, the topic of the syntax
-comes in. It’s like nothing else matters.</p></div>
-<div class="paragraph"><p>Perhaps the topic of syntax didn’t come up. But they’re
-still not going to try Erlang because of it.</p></div>
-<div class="paragraph"><p>You’re probably not having these kinds of interactions at
-Erlang conferences. This doesn’t happen with people who are
-already somewhat interested in, or need, the features that
-Erlang provides. With them the syntax is at worst a minor
-inconvenience.</p></div>
-<div class="paragraph"><p>This happens because most developers are familiar with
-syntaxes that look nothing like Erlang. To be clear, I
-include language features and other concepts like objects
-as part of "syntax" here. Familiarity is a very important
-factor to drive adoption.</p></div>
-<div class="paragraph"><p>You can see an example of that in the Elixir world, where
-the majority of people come from Ruby or already knew and
-liked Ruby. The 2016 survey tells us that 59% of Elixir
-developers were using Ruby primarily before. That’s in
-large part because of the syntax. They will deny it of
-course and find other reasons. And yet, we don’t see such
-a strong adoption of Erlang from Ruby developers, before
-or after Elixir appeared.</p></div>
-<div class="paragraph"><p>Side note: have you ever wondered why the Elixir community
-is, I quote, much friendlier than the Ruby community?
-Despite having much of the same people?</p></div>
-<div class="paragraph"><p>Before we continue, let me be clear. I love the Erlang
-syntax. It is simple and explicit. It is powerful, especially
-when dealing with binary data. It has very few quirks.
-It has little to no ambiguity. It’s great. Except for
-persuading people to use it.</p></div>
-<div class="paragraph"><p>Over the years I have been writing Erlang, I have seen
-very few people point out that the syntax slows down
-adoption. We have no problem with it, so why would others?
-At the same time, people coming to Erlang come to solve
-a real problem they’re having, so the syntax is fairly
-secondary. Even if they hate it at first, they know they
-can solve their problems despite the syntax.</p></div>
-<div class="paragraph"><p>You don’t build a popular product or language by solving
-people’s problems though. In general you end up solving
-some problems and creating new problems. No, you build
-a popular product by <strong>convincing people to use it</strong>. And
-you make them stay with your product by making them
-<strong>commit</strong> to using it.</p></div>
-<div class="paragraph"><p>Take MongoDB for example. It didn’t become popular by
-working, or even by being practical. It wasn’t performing
-its primary function and was losing people’s data. That
-didn’t stop it from becoming popular. Smart people would
-knowingly use a database that was losing data. Think about
-that for a minute.</p></div>
-<div class="paragraph"><p>MongoDB of course had a huge marketing machine, and they
-focused on that. They helped organize many meetups all
-over the world, complete with various swag items given
-for free, including a small handbook about MongoDB. All
-people had to do was show up.</p></div>
-<div class="paragraph"><p>They didn’t go tell people to look at all the weaknesses
-their product had. They focused on the strengths. On
-what would convince people to try it. They would go
-to meetups, discuss with others, commit to try it (or
-try it at meetups directly), and by doing so sell MongoDB
-to themselves.</p></div>
-<div class="paragraph"><p>How do we get people to meetups though? That’d be the
-first step: you need to <strong>catch their attention</strong>.
-I believe MongoDB did this using benchmark results.
-Ironic isn’t it? MongoDB gets fast benchmark results
-because they lose data, and this gets everyone to buy
-into the product.</p></div>
-<div class="paragraph"><p>The key points to remember about this are:</p></div>
-<div class="ulist"><ul>
-<li>
-<p>
-catch people’s attention
-</p>
-</li>
-<li>
-<p>
-show your product’s strengths
-</p>
-</li>
-<li>
-<p>
-make people take a commitment
-</p>
-</li>
-</ul></div>
-<div class="paragraph"><p>Once they commit to something, you win. Everyone will not
-end up ultimately using your product of course, but it’s
-at the very least become a consideration. It’s on their
-mind. Their resolve will be stronger when they ultimately
-try it and inevitably run into issues.</p></div>
-<div class="paragraph"><p>Erlang’s syntax is a weakness. Almost nobody looks at the
-Erlang syntax and falls in love with it at first sight.
-No, it takes time to learn it and understand how good it
-is. You need to sell Erlang to people without showing
-the Erlang syntax. If you do show it, then you need to
-hide the parts that feel alien. Function calls are OK.
-Recursion, not so much. Maps are OK. Records, not.</p></div>
-<div class="paragraph"><p>Avoiding code is not always possible when you try
-to sell it, especially to developers. You can however
-prepare them to accept the alien syntax by admitting
-that the syntax is not perfect before you show it.
-You can do this while praising it at the same time.
-For example, "the syntax is a little out there, but
-it matches the concepts perfectly, it will all make
-sense when you start learning".</p></div>
-<div class="paragraph"><p>This might not be the best introduction. Someone will
-need to A/B test it to find the one that gives the
-best results. But that should give you ideas.</p></div>
-<div class="paragraph"><p>When something terrible happens, mentioning that this
-isn’t the end of the world <strong>before</strong> you tell others what
-happened will soften their reaction. When someone
-breaks your favorite item and cries over it calling
-themselves stupid, it’s harder to get mad at them,
-compared to the same event with no emotional reaction.</p></div>
-<div class="paragraph"><p>Our behavior is largely dependent on what’s at the
-top of our mind, so it’s up to you to take advantage
-of this to make your case in the best conditions.</p></div>
-<div class="paragraph"><p>Next time you try to make someone use Erlang, remember
-that you should aim for getting a spoken commitment
-out of them, if possible before you show the syntax.
-If that’s not possible, then prepare them to accept
-the flaws or the weirdness before they see them.</p></div>
+<div class="paragraph"><p>Have you ever tried telling someone why they should use +Erlang? You boast the smaller code size, the auto healing +mechanisms, the distribution and they seem really excited. +They wonder why they never heard about Erlang before. And +then you show them what the code looks like. All excitement +goes away. The smiles disappear. Their face starts +becoming really serious.</p></div> +<div class="paragraph"><p>You lost them. You know you lost them. They comment on the +syntax, or perhaps you do, already admitting defeat. It’s +unlike anything they have ever used before. And they will +most likely end up not using it.</p></div> +<div class="paragraph"><p>What about people who already know what the syntax looks +like? As soon as you mention Erlang, the topic of the syntax +comes in. It’s like nothing else matters.</p></div> +<div class="paragraph"><p>Perhaps the topic of syntax didn’t come up. But they’re +still not going to try Erlang because of it.</p></div> +<div class="paragraph"><p>You’re probably not having these kinds of interactions at +Erlang conferences. This doesn’t happen with people who are +already somewhat interested in, or need, the features that +Erlang provides. With them the syntax is at worst a minor +inconvenience.</p></div> +<div class="paragraph"><p>This happens because most developers are familiar with +syntaxes that look nothing like Erlang. To be clear, I +include language features and other concepts like objects +as part of "syntax" here. Familiarity is a very important +factor to drive adoption.</p></div> +<div class="paragraph"><p>You can see an example of that in the Elixir world, where +the majority of people come from Ruby or already knew and +liked Ruby. The 2016 survey tells us that 59% of Elixir +developers were using Ruby primarily before. That’s in +large part because of the syntax. They will deny it of +course and find other reasons. And yet, we don’t see such +a strong adoption of Erlang from Ruby developers, before +or after Elixir appeared.</p></div> +<div class="paragraph"><p>Side note: have you ever wondered why the Elixir community +is, I quote, much friendlier than the Ruby community? +Despite having much of the same people?</p></div> +<div class="paragraph"><p>Before we continue, let me be clear. I love the Erlang +syntax. It is simple and explicit. It is powerful, especially +when dealing with binary data. It has very few quirks. +It has little to no ambiguity. It’s great. Except for +persuading people to use it.</p></div> +<div class="paragraph"><p>Over the years I have been writing Erlang, I have seen +very few people point out that the syntax slows down +adoption. We have no problem with it, so why would others? +At the same time, people coming to Erlang come to solve +a real problem they’re having, so the syntax is fairly +secondary. Even if they hate it at first, they know they +can solve their problems despite the syntax.</p></div> +<div class="paragraph"><p>You don’t build a popular product or language by solving +people’s problems though. In general you end up solving +some problems and creating new problems. No, you build +a popular product by <strong>convincing people to use it</strong>. And +you make them stay with your product by making them +<strong>commit</strong> to using it.</p></div> +<div class="paragraph"><p>Take MongoDB for example. It didn’t become popular by +working, or even by being practical. It wasn’t performing +its primary function and was losing people’s data. That +didn’t stop it from becoming popular. Smart people would +knowingly use a database that was losing data. Think about +that for a minute.</p></div> +<div class="paragraph"><p>MongoDB of course had a huge marketing machine, and they +focused on that. They helped organize many meetups all +over the world, complete with various swag items given +for free, including a small handbook about MongoDB. All +people had to do was show up.</p></div> +<div class="paragraph"><p>They didn’t go tell people to look at all the weaknesses +their product had. They focused on the strengths. On +what would convince people to try it. They would go +to meetups, discuss with others, commit to try it (or +try it at meetups directly), and by doing so sell MongoDB +to themselves.</p></div> +<div class="paragraph"><p>How do we get people to meetups though? That’d be the +first step: you need to <strong>catch their attention</strong>. +I believe MongoDB did this using benchmark results. +Ironic isn’t it? MongoDB gets fast benchmark results +because they lose data, and this gets everyone to buy +into the product.</p></div> +<div class="paragraph"><p>The key points to remember about this are:</p></div> +<div class="ulist"><ul> +<li> +<p> +catch people’s attention +</p> +</li> +<li> +<p> +show your product’s strengths +</p> +</li> +<li> +<p> +make people take a commitment +</p> +</li> +</ul></div> +<div class="paragraph"><p>Once they commit to something, you win. Everyone will not +end up ultimately using your product of course, but it’s +at the very least become a consideration. It’s on their +mind. Their resolve will be stronger when they ultimately +try it and inevitably run into issues.</p></div> +<div class="paragraph"><p>Erlang’s syntax is a weakness. Almost nobody looks at the +Erlang syntax and falls in love with it at first sight. +No, it takes time to learn it and understand how good it +is. You need to sell Erlang to people without showing +the Erlang syntax. If you do show it, then you need to +hide the parts that feel alien. Function calls are OK. +Recursion, not so much. Maps are OK. Records, not.</p></div> +<div class="paragraph"><p>Avoiding code is not always possible when you try +to sell it, especially to developers. You can however +prepare them to accept the alien syntax by admitting +that the syntax is not perfect before you show it. +You can do this while praising it at the same time. +For example, "the syntax is a little out there, but +it matches the concepts perfectly, it will all make +sense when you start learning".</p></div> +<div class="paragraph"><p>This might not be the best introduction. Someone will +need to A/B test it to find the one that gives the +best results. But that should give you ideas.</p></div> +<div class="paragraph"><p>When something terrible happens, mentioning that this +isn’t the end of the world <strong>before</strong> you tell others what +happened will soften their reaction. When someone +breaks your favorite item and cries over it calling +themselves stupid, it’s harder to get mad at them, +compared to the same event with no emotional reaction.</p></div> +<div class="paragraph"><p>Our behavior is largely dependent on what’s at the +top of our mind, so it’s up to you to take advantage +of this to make your case in the best conditions.</p></div> +<div class="paragraph"><p>Next time you try to make someone use Erlang, remember +that you should aim for getting a spoken commitment +out of them, if possible before you show the syntax. +If that’s not possible, then prepare them to accept +the flaws or the weirdness before they see them.</p></div> </article> </div> @@ -215,55 +215,107 @@ the flaws or the weirdness before they see them.</p></div> <h3>More articles</h3> <ul id="articles-nav" class="extra_margin"> - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + - <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + + <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + - <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + + <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + - <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + + <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + - <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + + <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + - <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + + <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + - <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + + <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + - <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + + <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + - <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + + <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + - <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + + <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + - <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + + <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + + + </ul> diff --git a/articles/the-story-so-far/index.html b/articles/the-story-so-far/index.html index 72936401..dc642a87 100644 --- a/articles/the-story-so-far/index.html +++ b/articles/the-story-so-far/index.html @@ -7,7 +7,7 @@ <meta name="description" content=""> <meta name="author" content="Loïc Hoguin based on a design from (Soft10) Pol Cámara"> - <meta name="generator" content="Hugo 0.17" /> + <meta name="generator" content="Hugo 0.26" /> <title>Nine Nines: The story so far</title> @@ -74,230 +74,230 @@ </p> </header> -<div class="paragraph"><p>As I am away from home with little to do (some call this
-a vacation) I wanted to reflect a little on the story so far,
-or how I arrived to Erlang and got to where I am now. The
-raw personal experience. It’ll be an article that’s more
-about social aspect, communities and marketing a project than
-technical considerations. As a period piece, it will also
-allow me to reflect on the evolution of Erlang in recent
-years.</p></div>
-<div class="paragraph"><p>Once upon a time-- Okay this isn’t a fairy tale. The story
-begins with a short chapter in 2010. The year 2010 started
-with a fairly major event in my life: the US servers for the
-online game I stopped playing a few months before, but was
-still involved with through its community, were closing. OMG!
-Someone found a way to log packets and started working on a
-private server; meanwhile the JP servers were still up. And
-that’s pretty much it.</p></div>
-<div class="paragraph"><p>Fast forward a few months and it became pretty clear that
-the private server was going nowhere considering all the drama
-surrounding it-- which is actually not unusual, but it was
-more entertaining than average and the technical abilities of
-people running the project were obviously lacking so I decided
-to obtain those logged packets and look at things myself. I
-didn’t want to do a private server yet, I only wanted to take
-a peek to see how things worked, and perhaps organize some
-effort to document the protocol.</p></div>
-<div class="paragraph"><p>There was 10GB of logs. I didn’t have an easy to use
-language to analyze them, and hex editors wouldn’t cut it for
-most purposes, so I had to look elsewhere. This was a good
-opportunity to start learning this PHP killer I read about
-before, which also happens to feature syntax for matching
-binaries, called Erlang. To be perfectly honest I wouldn’t
-have touched the logs if I didn’t have the added motivation
-to play with and learn a new language.</p></div>
-<div class="paragraph"><p>At the time it was pretty hard to learn Erlang. In my
-experience there was Joe’s book (which I always recommend
-first as I believe it is the best to learn the Erlang side
-of things; but falls a little short on OTP), and there was
-about 5 chapters of LYSE. There were a couple other books
-I never managed to get into (sorry guys), and there was also
-a few interesting blogs, some of which I can’t find anymore.
-Finally the #erlang IRC community was there but I was strictly
-lurking at the time.</p></div>
-<div class="paragraph"><p>What a difference compared to 4 years later! (That’s
-today, by the way!) Now we have more books than I can
-remember, tons of articles covering various aspects of the
-language and platform, many targeting beginners but a good
-number of them also about advanced topics. We even have a
-free online book, LYSE, with more than 30 chapters covering
-pretty much everything. Needless to say I never finished
-reading LYSE as it got written slower than I learnt.</p></div>
-<div class="paragraph"><p>Back to 2010. I wrote a parser for the logs, and
-aggregated those results into one CSV file per packet type
-so I could open them in Gnumeric and aggregate some more,
-but manually this time, and draw conclusions on the packet
-structures. That was pretty easy. Even for a beginner.
-Anyone can go from zero to that level in a day or two.
-Then, having mastered binary pattern matching, I wanted
-to learn some more Erlang, by making this aggregation
-faster. What I had done before worked, but I wasn’t going
-to wait forever to process everything sequentially. So I
-looked and found a project called <code>plists</code> (still exists,
-but not maintained AFAIK). I downloaded that project and
-replaced my <code>lists:</code> calls to <code>plists:</code>.
-Boom. In just a few minutes all logs were processed, and
-I had learnt something new.</p></div>
-<div class="paragraph"><p>It is particularly interesting to note that the lack of
-a package manager or index never bothered me. Neither before
-nor after learning Erlang. My experience with package
-managers was mostly related to Ubuntu, a little Perl and
-Python, and PHP’s Pear. Let’s just stay polite and say it
-was always a terrible experience. So searching on the Web
-didn’t feel awkward, because even if I used a tool or
-website I would have ended up doing a search or two anyway.
-This is in contrast to the package index feature in
-<a href="https://github.com/ninenines/erlang.mk">Erlang.mk</a>,
-which is meant to simplify specifying dependencies more
-than anything: <code>DEPS = cowboy</code>. It does not
-attempt to solve any other problem, and will only attempt
-to solve one extra problem in the near future, which is
-the discovery of packages. So expect some kind of website
-listing packages soon enough.</p></div>
-<div class="paragraph"><p>I want to use this parenthese to also point out that at
-the time there was a very small number of projects out there,
-at least compared to today. While you sometimes hear people
-complain about lack of certain libraries, it is so much
-better now than it was before! The situation improves very
-quickly, so much that it’s not going to be that big an issue
-soon enough.</p></div>
-<div class="paragraph"><p>Wanting to know more about that game’s protocol, in the
-year 2010, I ended up starting to write more Erlang code to
-simulate a server and use the server to query the client and
-see what was happening, documenting the packets and so on.
-This eventually lead to a larger project implementing more
-and more until people got their hopes up for a revival of
-the game, all the while the now competing original server
-project died in a stream of drama and technical incompetence.
-Of course, I ended up doing what any good Internet citizen
-would do, I crushed people’s hopes, but that’s not important
-to our story. The important part is that before giving up
-on this project, I not only learnt a good deal of Erlang
-and a little deal of OTP (which I did not touch until 6
-months after I started with Erlang; see the paragraph
-about learning material above), but I also had an intriguing
-idea pop into my mind for what would become my greatest
-success yet.</p></div>
-<div class="paragraph"><p>The giving up part was not easy. Having had financial
-difficulties all year 2010 and part of 2009, I resolved
-to travel back to Paris to try and make it. I ended up
-sleeping in offices for 6 months, being hosted by a shady
-person, and hearing my fair share of stories about
-the dark side of business. While there I also worked for
-another company with someone who would end up becoming
-another high profile Erlang developer. The situation
-slowly improved, I started taking part in the #erlang
-IRC discussions, giving up my status of lurker and, a
-few months into 2011, started working on the Apache killer
-project: Cowboy.</p></div>
-<div class="paragraph"><p>This is the part where I probably should get accused of
-racism and other fun things, but I never did. And I think
-that speaks lots about the Erlang community. In all my time
-writing Erlang code, I can count the number of conflicts I
-had with other people on a single hand. This is the nicest
-programming community I have ever seen, by far. And the
-humblest too. The Erlang community feels like Japan. And
-I love Japan. So I love the Erlang community. I can’t say
-this enough. This is something that stayed true for all
-my time using Erlang, and despite the rise of alternative
-languages that are not Japan the Erlang community has
-remained very Japan.</p></div>
-<div class="paragraph"><p>The first published version of Cowboy was written in
-two weeks. A little before those two weeks, during, and
-a while after, pretty much everything I said on the
-Internets was that Cowboy was going to be the greatest
-HTTP server ever, that the other servers were problematic
-(and just to be clear, Yaws was rarely if ever mentioned,
-due to being in a perceived different league of "full
-featured servers" while Cowboy was a "lightweight server"),
-and that Cowboy will be the best replacement to a Mochiweb
-or Misultin application. This, alongside a lot of time
-spent on IRC telling people to use Cowboy when they were
-asking for an HTTP server to use, probably made me sound
-very annoying. But it worked, and Cowboy started getting
-its first users, despite being only a few weeks old. Of
-course, as soon as I got my very first user, I started
-claiming Cowboy had "a lot of users".</p></div>
-<div class="paragraph"><p>Looking back today I would definitely find myself annoying,
-this wasn’t just an idle comment there. For about a year,
-maybe a little more, all I ever said was that Cowboy was
-the best. This probably made me a little dumber in the
-process (as if I wasn’t enough! I know). Being French, I
-sometimes would also say things quite abruptly. To stay
-polite, I probably sounded like an asshole. I learnt to
-stop being so French over time thankfully.</p></div>
-<div class="paragraph"><p>I think what was most important to Cowboy at the time,
-was three things. First, it felt fresh. It was new, had new
-ideas, tried to do things differently and followed "new" old
-best practices (the OTP way-- which was simply too obscure
-for most people at the time). Second, it had me spending
-all my time telling people to use it whenever they were
-looking for an HTTP server. Third, it had me helping people
-get started with it and guide them all the steps of the way.
-Mostly because it didn’t have a very good documentation, but
-still, hand holding does wonders.</p></div>
-<div class="paragraph"><p>To be able to help people every time they had a problem,
-I did not spend all my days reading IRC. Instead I simply
-made sure to be notified when someone said <code>cowboy</code>.
-The same way many people subscribe to alerts when their
-company is mentioned in the news. Nothing fancy.</p></div>
-<div class="paragraph"><p>Time went on, Cowboy grew, or as some like to say,
-completely destroyed the competition, and many people
-eventually moved from Mochiweb and Misultin to Cowboy.
-And then Roberto Ostinelli stopped Misultin development
-and told everyone to move to Cowboy. This is the most
-humble and selfless act I have ever seen in the programming
-sphere, and I only have one thing to say about it: GG.
-Thanks for the fish. He left me with the tasks of improving
-Cowboy examples, documentation and strongly believed that
-the Misultin interface was more user friendly out of all
-the servers. So I added many examples, as many lines of
-documentation as we have of code, and strongly believe
-that Cowboy 2.0 will be the most user friendly interface
-out of all servers. But only time will tell.</p></div>
-<div class="paragraph"><p>With the rise of the project and the rise in the number
-of users, my previous strategy (completely incidental, by
-the way, and definitely not a well thought out plan to
-become popular) stopped working. It was taking me too much
-time. The important aspects slowly drifted. If I wanted to
-support more users, I would have to spend less time with
-each individual user. This was actually a hard problem.
-You basically have to make people understand they can’t
-just come to you directly when they have a problem, they
-have to follow proper channels. It becomes less personal,
-and might be felt like you don’t care about them anymore.
-You have to hurt some people’s feelings at this point. It
-is quite unfortunate, and also quite difficult to do. There
-is some unwritten rule that says early adopters deserve
-more, but in the real world it never works like this. So
-I probably hurt some people’s feelings at some point. But
-that’s okay. Because even if you make sure to be as nice
-as possible when you tell people to go through proper
-channels from now on, some people will still get offended.
-There’s nothing you can do about it.</p></div>
-<div class="paragraph"><p>From that point onward the important points about the
-project was getting the documentation done, making sure
-people knew about the proper channels to get help and
-report issues, etc. Basically making myself less needed.
-This is quite a contrast with the first days, but I believe
-Cowboy made that transition successfully.</p></div>
-<div class="paragraph"><p>Not only did I win time by not having to hold hands with
-everyone all the time (not that I didn’t like it, but you
-know, the sweat), but I also won time thanks to the increased
-project popularity. Indeed, the more users you have, the more
-annoying guys there are to tell people to use your project
-and that it’s the best and everything. Which is great. At
-least, it’s great if you don’t pay too much attention to it.
-Sometimes people will give an advice that is, in your opinion,
-a bad advice. And that’s okay. Don’t intervene every time
-someone gives a bad advice, learn to let it go. People will
-figure it out. You learn by making mistakes, after all. Use
-this extra time to make sure other people don’t end up
-giving the same bad advice instead. Fix the code or the
-documentation that led to this mistake. Slowly improve the
-project and make sure it doesn’t happen again.</p></div>
-<div class="paragraph"><p>This is my story. So far, anyway.</p></div>
+<div class="paragraph"><p>As I am away from home with little to do (some call this +a vacation) I wanted to reflect a little on the story so far, +or how I arrived to Erlang and got to where I am now. The +raw personal experience. It’ll be an article that’s more +about social aspect, communities and marketing a project than +technical considerations. As a period piece, it will also +allow me to reflect on the evolution of Erlang in recent +years.</p></div> +<div class="paragraph"><p>Once upon a time-- Okay this isn’t a fairy tale. The story +begins with a short chapter in 2010. The year 2010 started +with a fairly major event in my life: the US servers for the +online game I stopped playing a few months before, but was +still involved with through its community, were closing. OMG! +Someone found a way to log packets and started working on a +private server; meanwhile the JP servers were still up. And +that’s pretty much it.</p></div> +<div class="paragraph"><p>Fast forward a few months and it became pretty clear that +the private server was going nowhere considering all the drama +surrounding it-- which is actually not unusual, but it was +more entertaining than average and the technical abilities of +people running the project were obviously lacking so I decided +to obtain those logged packets and look at things myself. I +didn’t want to do a private server yet, I only wanted to take +a peek to see how things worked, and perhaps organize some +effort to document the protocol.</p></div> +<div class="paragraph"><p>There was 10GB of logs. I didn’t have an easy to use +language to analyze them, and hex editors wouldn’t cut it for +most purposes, so I had to look elsewhere. This was a good +opportunity to start learning this PHP killer I read about +before, which also happens to feature syntax for matching +binaries, called Erlang. To be perfectly honest I wouldn’t +have touched the logs if I didn’t have the added motivation +to play with and learn a new language.</p></div> +<div class="paragraph"><p>At the time it was pretty hard to learn Erlang. In my +experience there was Joe’s book (which I always recommend +first as I believe it is the best to learn the Erlang side +of things; but falls a little short on OTP), and there was +about 5 chapters of LYSE. There were a couple other books +I never managed to get into (sorry guys), and there was also +a few interesting blogs, some of which I can’t find anymore. +Finally the #erlang IRC community was there but I was strictly +lurking at the time.</p></div> +<div class="paragraph"><p>What a difference compared to 4 years later! (That’s +today, by the way!) Now we have more books than I can +remember, tons of articles covering various aspects of the +language and platform, many targeting beginners but a good +number of them also about advanced topics. We even have a +free online book, LYSE, with more than 30 chapters covering +pretty much everything. Needless to say I never finished +reading LYSE as it got written slower than I learnt.</p></div> +<div class="paragraph"><p>Back to 2010. I wrote a parser for the logs, and +aggregated those results into one CSV file per packet type +so I could open them in Gnumeric and aggregate some more, +but manually this time, and draw conclusions on the packet +structures. That was pretty easy. Even for a beginner. +Anyone can go from zero to that level in a day or two. +Then, having mastered binary pattern matching, I wanted +to learn some more Erlang, by making this aggregation +faster. What I had done before worked, but I wasn’t going +to wait forever to process everything sequentially. So I +looked and found a project called <code>plists</code> (still exists, +but not maintained AFAIK). I downloaded that project and +replaced my <code>lists:</code> calls to <code>plists:</code>. +Boom. In just a few minutes all logs were processed, and +I had learnt something new.</p></div> +<div class="paragraph"><p>It is particularly interesting to note that the lack of +a package manager or index never bothered me. Neither before +nor after learning Erlang. My experience with package +managers was mostly related to Ubuntu, a little Perl and +Python, and PHP’s Pear. Let’s just stay polite and say it +was always a terrible experience. So searching on the Web +didn’t feel awkward, because even if I used a tool or +website I would have ended up doing a search or two anyway. +This is in contrast to the package index feature in +<a href="https://github.com/ninenines/erlang.mk">Erlang.mk</a>, +which is meant to simplify specifying dependencies more +than anything: <code>DEPS = cowboy</code>. It does not +attempt to solve any other problem, and will only attempt +to solve one extra problem in the near future, which is +the discovery of packages. So expect some kind of website +listing packages soon enough.</p></div> +<div class="paragraph"><p>I want to use this parenthese to also point out that at +the time there was a very small number of projects out there, +at least compared to today. While you sometimes hear people +complain about lack of certain libraries, it is so much +better now than it was before! The situation improves very +quickly, so much that it’s not going to be that big an issue +soon enough.</p></div> +<div class="paragraph"><p>Wanting to know more about that game’s protocol, in the +year 2010, I ended up starting to write more Erlang code to +simulate a server and use the server to query the client and +see what was happening, documenting the packets and so on. +This eventually lead to a larger project implementing more +and more until people got their hopes up for a revival of +the game, all the while the now competing original server +project died in a stream of drama and technical incompetence. +Of course, I ended up doing what any good Internet citizen +would do, I crushed people’s hopes, but that’s not important +to our story. The important part is that before giving up +on this project, I not only learnt a good deal of Erlang +and a little deal of OTP (which I did not touch until 6 +months after I started with Erlang; see the paragraph +about learning material above), but I also had an intriguing +idea pop into my mind for what would become my greatest +success yet.</p></div> +<div class="paragraph"><p>The giving up part was not easy. Having had financial +difficulties all year 2010 and part of 2009, I resolved +to travel back to Paris to try and make it. I ended up +sleeping in offices for 6 months, being hosted by a shady +person, and hearing my fair share of stories about +the dark side of business. While there I also worked for +another company with someone who would end up becoming +another high profile Erlang developer. The situation +slowly improved, I started taking part in the #erlang +IRC discussions, giving up my status of lurker and, a +few months into 2011, started working on the Apache killer +project: Cowboy.</p></div> +<div class="paragraph"><p>This is the part where I probably should get accused of +racism and other fun things, but I never did. And I think +that speaks lots about the Erlang community. In all my time +writing Erlang code, I can count the number of conflicts I +had with other people on a single hand. This is the nicest +programming community I have ever seen, by far. And the +humblest too. The Erlang community feels like Japan. And +I love Japan. So I love the Erlang community. I can’t say +this enough. This is something that stayed true for all +my time using Erlang, and despite the rise of alternative +languages that are not Japan the Erlang community has +remained very Japan.</p></div> +<div class="paragraph"><p>The first published version of Cowboy was written in +two weeks. A little before those two weeks, during, and +a while after, pretty much everything I said on the +Internets was that Cowboy was going to be the greatest +HTTP server ever, that the other servers were problematic +(and just to be clear, Yaws was rarely if ever mentioned, +due to being in a perceived different league of "full +featured servers" while Cowboy was a "lightweight server"), +and that Cowboy will be the best replacement to a Mochiweb +or Misultin application. This, alongside a lot of time +spent on IRC telling people to use Cowboy when they were +asking for an HTTP server to use, probably made me sound +very annoying. But it worked, and Cowboy started getting +its first users, despite being only a few weeks old. Of +course, as soon as I got my very first user, I started +claiming Cowboy had "a lot of users".</p></div> +<div class="paragraph"><p>Looking back today I would definitely find myself annoying, +this wasn’t just an idle comment there. For about a year, +maybe a little more, all I ever said was that Cowboy was +the best. This probably made me a little dumber in the +process (as if I wasn’t enough! I know). Being French, I +sometimes would also say things quite abruptly. To stay +polite, I probably sounded like an asshole. I learnt to +stop being so French over time thankfully.</p></div> +<div class="paragraph"><p>I think what was most important to Cowboy at the time, +was three things. First, it felt fresh. It was new, had new +ideas, tried to do things differently and followed "new" old +best practices (the OTP way-- which was simply too obscure +for most people at the time). Second, it had me spending +all my time telling people to use it whenever they were +looking for an HTTP server. Third, it had me helping people +get started with it and guide them all the steps of the way. +Mostly because it didn’t have a very good documentation, but +still, hand holding does wonders.</p></div> +<div class="paragraph"><p>To be able to help people every time they had a problem, +I did not spend all my days reading IRC. Instead I simply +made sure to be notified when someone said <code>cowboy</code>. +The same way many people subscribe to alerts when their +company is mentioned in the news. Nothing fancy.</p></div> +<div class="paragraph"><p>Time went on, Cowboy grew, or as some like to say, +completely destroyed the competition, and many people +eventually moved from Mochiweb and Misultin to Cowboy. +And then Roberto Ostinelli stopped Misultin development +and told everyone to move to Cowboy. This is the most +humble and selfless act I have ever seen in the programming +sphere, and I only have one thing to say about it: GG. +Thanks for the fish. He left me with the tasks of improving +Cowboy examples, documentation and strongly believed that +the Misultin interface was more user friendly out of all +the servers. So I added many examples, as many lines of +documentation as we have of code, and strongly believe +that Cowboy 2.0 will be the most user friendly interface +out of all servers. But only time will tell.</p></div> +<div class="paragraph"><p>With the rise of the project and the rise in the number +of users, my previous strategy (completely incidental, by +the way, and definitely not a well thought out plan to +become popular) stopped working. It was taking me too much +time. The important aspects slowly drifted. If I wanted to +support more users, I would have to spend less time with +each individual user. This was actually a hard problem. +You basically have to make people understand they can’t +just come to you directly when they have a problem, they +have to follow proper channels. It becomes less personal, +and might be felt like you don’t care about them anymore. +You have to hurt some people’s feelings at this point. It +is quite unfortunate, and also quite difficult to do. There +is some unwritten rule that says early adopters deserve +more, but in the real world it never works like this. So +I probably hurt some people’s feelings at some point. But +that’s okay. Because even if you make sure to be as nice +as possible when you tell people to go through proper +channels from now on, some people will still get offended. +There’s nothing you can do about it.</p></div> +<div class="paragraph"><p>From that point onward the important points about the +project was getting the documentation done, making sure +people knew about the proper channels to get help and +report issues, etc. Basically making myself less needed. +This is quite a contrast with the first days, but I believe +Cowboy made that transition successfully.</p></div> +<div class="paragraph"><p>Not only did I win time by not having to hold hands with +everyone all the time (not that I didn’t like it, but you +know, the sweat), but I also won time thanks to the increased +project popularity. Indeed, the more users you have, the more +annoying guys there are to tell people to use your project +and that it’s the best and everything. Which is great. At +least, it’s great if you don’t pay too much attention to it. +Sometimes people will give an advice that is, in your opinion, +a bad advice. And that’s okay. Don’t intervene every time +someone gives a bad advice, learn to let it go. People will +figure it out. You learn by making mistakes, after all. Use +this extra time to make sure other people don’t end up +giving the same bad advice instead. Fix the code or the +documentation that led to this mistake. Slowly improve the +project and make sure it doesn’t happen again.</p></div> +<div class="paragraph"><p>This is my story. So far, anyway.</p></div> </article> </div> @@ -306,55 +306,107 @@ project and make sure it doesn’t happen again.</p></div> <h3>More articles</h3> <ul id="articles-nav" class="extra_margin"> - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + - <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + + <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + - <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + + <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + - <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + + <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + - <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + + <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + - <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + + <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + - <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + + <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + - <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + + <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + - <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + + <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + - <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + + <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + - <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + + <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + + + </ul> diff --git a/articles/tictactoe/index.html b/articles/tictactoe/index.html index e466f27d..15498ed7 100644 --- a/articles/tictactoe/index.html +++ b/articles/tictactoe/index.html @@ -7,7 +7,7 @@ <meta name="description" content=""> <meta name="author" content="Loïc Hoguin based on a design from (Soft10) Pol Cámara"> - <meta name="generator" content="Hugo 0.17" /> + <meta name="generator" content="Hugo 0.26" /> <title>Nine Nines: Erlang Tic Tac Toe</title> @@ -74,89 +74,89 @@ </p> </header> -<div class="paragraph"><p>Everyone knows <a href="http://en.wikipedia.org/wiki/Tic-tac-toe">Tic Tac Toe</a>,
-right?</p></div>
-<div class="paragraph"><p>Players choose either to be the Xs or the Os, then place their symbol
-on a 3x3 board one after another, trying to create a line of 3 of them.</p></div>
-<div class="paragraph"><p>Writing an algorithm to check for victory sounds easy, right? It’s
-easily tested, considering there’s only 8 possible winning rows (3 horizontal,
-3 vertical and 2 diagonal).</p></div>
-<div class="paragraph"><p>In Erlang though, you probably wouldn’t want an algorithm. Erlang has
-this cool feature called pattern matching which will allow us to completely
-avoid writing the algorithm by instead letting us match directly on the
-solutions.</p></div>
-<div class="paragraph"><p>Let’s first create a board. A board is a list of 3 rows each containing
-3 columns. It can also be thought of as a tuple containing 9 elements.
-A tuple is easier to manipulate so this is what we are going to use.
-Each position can either contain an <code>x</code>, an <code>o</code>,
-or be <code>undefined</code>.</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="font-weight: bold"><span style="color: #000000">new</span></span>() <span style="color: #990000">-></span>
- {<span style="color: #000080">undefined</span>, <span style="color: #000080">undefined</span>, <span style="color: #000080">undefined</span>,
- <span style="color: #000080">undefined</span>, <span style="color: #000080">undefined</span>, <span style="color: #000080">undefined</span>,
- <span style="color: #000080">undefined</span>, <span style="color: #000080">undefined</span>, <span style="color: #000080">undefined</span>}<span style="color: #990000">.</span></tt></pre></div></div>
-<div class="paragraph"><p>Now that we have a board, if we want to play, we need a function that
-will allow players to, you know, actually play their moves. Rows and
-columns are numbered 1 to 3 so we need a little math to correctly
-deduce the element’s position.</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="font-weight: bold"><span style="color: #000000">play</span></span>(<span style="color: #009900">Who</span>, <span style="color: #009900">X</span>, <span style="color: #009900">Y</span>, <span style="color: #009900">Board</span>) <span style="color: #990000">-></span>
- <span style="font-weight: bold"><span style="color: #000080">setelement</span></span>((<span style="color: #009900">Y</span> <span style="color: #990000">-</span> <span style="color: #993399">1</span>) <span style="color: #990000">*</span> <span style="color: #993399">3</span> <span style="color: #990000">+</span> <span style="color: #009900">X</span>, <span style="color: #009900">Board</span>, <span style="color: #009900">Who</span>)<span style="color: #990000">.</span></tt></pre></div></div>
-<div class="paragraph"><p>This function returns the board with the element modified. Of course,
-as you probably noticed, we aren’t checking that the arguments are correct,
-or that the element was already set. This is left as an exercise to the
-reader.</p></div>
-<div class="paragraph"><p>After playing the move, we need to check whether someone won. That’s
-where you’d write an algorithm, and that’s where I wouldn’t. Let’s just
-pattern match all of them!</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="font-weight: bold"><span style="color: #000000">check</span></span>(<span style="color: #009900">Board</span>) <span style="color: #990000">-></span>
- <span style="font-weight: bold"><span style="color: #0000FF">case</span></span> <span style="color: #009900">Board</span> <span style="font-weight: bold"><span style="color: #0000FF">of</span></span>
- {<span style="color: #FF6600">x</span>, <span style="color: #FF6600">x</span>, <span style="color: #FF6600">x</span>,
- <span style="color: #990000">_</span>, <span style="color: #990000">_</span>, <span style="color: #990000">_</span>,
- <span style="color: #990000">_</span>, <span style="color: #990000">_</span>, <span style="color: #990000">_</span>} <span style="color: #990000">-></span> {<span style="color: #FF6600">victory</span>, <span style="color: #FF6600">x</span>};
-
- {<span style="color: #FF6600">x</span>, <span style="color: #990000">_</span>, <span style="color: #990000">_</span>,
- <span style="color: #990000">_</span>, <span style="color: #FF6600">x</span>, <span style="color: #990000">_</span>,
- <span style="color: #990000">_</span>, <span style="color: #990000">_</span>, <span style="color: #FF6600">x</span>} <span style="color: #990000">-></span> {<span style="color: #FF6600">victory</span>, <span style="color: #FF6600">x</span>};
-
- {<span style="color: #FF6600">x</span>, <span style="color: #990000">_</span>, <span style="color: #990000">_</span>,
- <span style="color: #FF6600">x</span>, <span style="color: #990000">_</span>, <span style="color: #990000">_</span>,
- <span style="color: #FF6600">x</span>, <span style="color: #990000">_</span>, <span style="color: #990000">_</span>} <span style="color: #990000">-></span> {<span style="color: #FF6600">victory</span>, <span style="color: #FF6600">x</span>};
-
- <span style="font-style: italic"><span style="color: #9A1900">%% [snip]</span></span>
-
- <span style="color: #990000">_</span> <span style="color: #990000">-></span> <span style="color: #FF6600">ok</span>
- <span style="font-weight: bold"><span style="color: #0000FF">end</span></span><span style="color: #990000">.</span></tt></pre></div></div>
-<div class="paragraph"><p>Pattern matching allows us to simply <em>draw</em> the solutions
-directly inside our code, and if the board matches any of them, then we
-have a victory or a draw, otherwise the game can continue.</p></div>
-<div class="paragraph"><p>The <code>_</code> variable is special in that it always matches,
-allowing us to focus strictly on the winning row. And because it’s very
-graphical, if we were to have messed up somewhere, then we’d only need
-take a quick glance to be sure the winning solutions are the right ones.</p></div>
-<div class="paragraph"><p>Erlang allows us to transform algorithms into very graphical code thanks
-to its pattern matching feature, and let us focus on doing things instead
-of writing algorithms to do things.</p></div>
-<div class="ulist"><ul>
-<li>
-<p>
-<a href="/res/tictactoe.erl">tictactoe.erl</a>
-</p>
-</li>
-</ul></div>
+<div class="paragraph"><p>Everyone knows <a href="http://en.wikipedia.org/wiki/Tic-tac-toe">Tic Tac Toe</a>, +right?</p></div> +<div class="paragraph"><p>Players choose either to be the Xs or the Os, then place their symbol +on a 3x3 board one after another, trying to create a line of 3 of them.</p></div> +<div class="paragraph"><p>Writing an algorithm to check for victory sounds easy, right? It’s +easily tested, considering there’s only 8 possible winning rows (3 horizontal, +3 vertical and 2 diagonal).</p></div> +<div class="paragraph"><p>In Erlang though, you probably wouldn’t want an algorithm. Erlang has +this cool feature called pattern matching which will allow us to completely +avoid writing the algorithm by instead letting us match directly on the +solutions.</p></div> +<div class="paragraph"><p>Let’s first create a board. A board is a list of 3 rows each containing +3 columns. It can also be thought of as a tuple containing 9 elements. +A tuple is easier to manipulate so this is what we are going to use. +Each position can either contain an <code>x</code>, an <code>o</code>, +or be <code>undefined</code>.</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="font-weight: bold"><span style="color: #000000">new</span></span>() <span style="color: #990000">-></span> + {<span style="color: #000080">undefined</span>, <span style="color: #000080">undefined</span>, <span style="color: #000080">undefined</span>, + <span style="color: #000080">undefined</span>, <span style="color: #000080">undefined</span>, <span style="color: #000080">undefined</span>, + <span style="color: #000080">undefined</span>, <span style="color: #000080">undefined</span>, <span style="color: #000080">undefined</span>}<span style="color: #990000">.</span></tt></pre></div></div> +<div class="paragraph"><p>Now that we have a board, if we want to play, we need a function that +will allow players to, you know, actually play their moves. Rows and +columns are numbered 1 to 3 so we need a little math to correctly +deduce the element’s position.</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="font-weight: bold"><span style="color: #000000">play</span></span>(<span style="color: #009900">Who</span>, <span style="color: #009900">X</span>, <span style="color: #009900">Y</span>, <span style="color: #009900">Board</span>) <span style="color: #990000">-></span> + <span style="font-weight: bold"><span style="color: #000080">setelement</span></span>((<span style="color: #009900">Y</span> <span style="color: #990000">-</span> <span style="color: #993399">1</span>) <span style="color: #990000">*</span> <span style="color: #993399">3</span> <span style="color: #990000">+</span> <span style="color: #009900">X</span>, <span style="color: #009900">Board</span>, <span style="color: #009900">Who</span>)<span style="color: #990000">.</span></tt></pre></div></div> +<div class="paragraph"><p>This function returns the board with the element modified. Of course, +as you probably noticed, we aren’t checking that the arguments are correct, +or that the element was already set. This is left as an exercise to the +reader.</p></div> +<div class="paragraph"><p>After playing the move, we need to check whether someone won. That’s +where you’d write an algorithm, and that’s where I wouldn’t. Let’s just +pattern match all of them!</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="font-weight: bold"><span style="color: #000000">check</span></span>(<span style="color: #009900">Board</span>) <span style="color: #990000">-></span> + <span style="font-weight: bold"><span style="color: #0000FF">case</span></span> <span style="color: #009900">Board</span> <span style="font-weight: bold"><span style="color: #0000FF">of</span></span> + {<span style="color: #FF6600">x</span>, <span style="color: #FF6600">x</span>, <span style="color: #FF6600">x</span>, + <span style="color: #990000">_</span>, <span style="color: #990000">_</span>, <span style="color: #990000">_</span>, + <span style="color: #990000">_</span>, <span style="color: #990000">_</span>, <span style="color: #990000">_</span>} <span style="color: #990000">-></span> {<span style="color: #FF6600">victory</span>, <span style="color: #FF6600">x</span>}; + + {<span style="color: #FF6600">x</span>, <span style="color: #990000">_</span>, <span style="color: #990000">_</span>, + <span style="color: #990000">_</span>, <span style="color: #FF6600">x</span>, <span style="color: #990000">_</span>, + <span style="color: #990000">_</span>, <span style="color: #990000">_</span>, <span style="color: #FF6600">x</span>} <span style="color: #990000">-></span> {<span style="color: #FF6600">victory</span>, <span style="color: #FF6600">x</span>}; + + {<span style="color: #FF6600">x</span>, <span style="color: #990000">_</span>, <span style="color: #990000">_</span>, + <span style="color: #FF6600">x</span>, <span style="color: #990000">_</span>, <span style="color: #990000">_</span>, + <span style="color: #FF6600">x</span>, <span style="color: #990000">_</span>, <span style="color: #990000">_</span>} <span style="color: #990000">-></span> {<span style="color: #FF6600">victory</span>, <span style="color: #FF6600">x</span>}; + + <span style="font-style: italic"><span style="color: #9A1900">%% [snip]</span></span> + + <span style="color: #990000">_</span> <span style="color: #990000">-></span> <span style="color: #FF6600">ok</span> + <span style="font-weight: bold"><span style="color: #0000FF">end</span></span><span style="color: #990000">.</span></tt></pre></div></div> +<div class="paragraph"><p>Pattern matching allows us to simply <em>draw</em> the solutions +directly inside our code, and if the board matches any of them, then we +have a victory or a draw, otherwise the game can continue.</p></div> +<div class="paragraph"><p>The <code>_</code> variable is special in that it always matches, +allowing us to focus strictly on the winning row. And because it’s very +graphical, if we were to have messed up somewhere, then we’d only need +take a quick glance to be sure the winning solutions are the right ones.</p></div> +<div class="paragraph"><p>Erlang allows us to transform algorithms into very graphical code thanks +to its pattern matching feature, and let us focus on doing things instead +of writing algorithms to do things.</p></div> +<div class="ulist"><ul> +<li> +<p> +<a href="/res/tictactoe.erl">tictactoe.erl</a> +</p> +</li> +</ul></div> </article> </div> @@ -165,55 +165,107 @@ of writing algorithms to do things.</p></div> <h3>More articles</h3> <ul id="articles-nav" class="extra_margin"> - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + + + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + + <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + - <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + + <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + - <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + + <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + - <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + + <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + - <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + + <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + - <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + + <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + - <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + + <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + - <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + + <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + - <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + + <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + - <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + + <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + - <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + </ul> diff --git a/articles/website-update/index.html b/articles/website-update/index.html index 8df1c432..b13c1402 100644 --- a/articles/website-update/index.html +++ b/articles/website-update/index.html @@ -7,7 +7,7 @@ <meta name="description" content=""> <meta name="author" content="Loïc Hoguin based on a design from (Soft10) Pol Cámara"> - <meta name="generator" content="Hugo 0.17" /> + <meta name="generator" content="Hugo 0.26" /> <title>Nine Nines: Website update</title> @@ -74,63 +74,63 @@ </p> </header> -<div class="paragraph"><p>Last week-end I updated the Nine Nines website.</p></div>
-<div class="paragraph"><p>I switched to <a href="http://gohugo.io/">Hugo</a>. The site is
-now built from <a href="http://asciidoc.org/">Asciidoc</a>
-documents. You probably saw me switch to Asciidoc
-for documentation this past year. This is the
-natural conclusion to that story. The great thing
-is that with a little bit of Makefile magic I can
-just copy the documentation files into Hugo and
-poof, they appear on the website.</p></div>
-<div class="paragraph"><p>I am very happy with that new setup. I can now
-post my thoughts again. Woo! Expect regular posts
-from now on. I will try to replace my long series
-of tweets with posts.</p></div>
-<div class="paragraph"><p>The sections have been rearranged. There used to
-be a separate training section; now
-<a href="/services">all my services</a> are described in
-one page. I have also clarified my areas of
-expertise. There used to be confusion in the past,
-so now it should be clearer that I am not a
-distributed systems expert.</p></div>
-<div class="paragraph"><p>On that note, if you are looking for my
-services right now, I’m not available. I’ll have
-to work 7 days a week for a while. Try again in a
-couple months. More on that in a future post.</p></div>
-<div class="paragraph"><p>The <a href="/docs">documentation</a> becomes a first class
-citizen. Bullet and Cowlib don’t have proper
-documentation… yet. I have started working on the
-Cowlib documentation, and Bullet shouldn’t take too
-long. All these projects will be documented when
-Cowboy gets to 2.0, and will all be supported
-equally. Note that the Cowboy 1.0 documentation
-still has the old website templates and links.
-Don’t worry about it.</p></div>
-<div class="paragraph"><p>The mailing lists link has been removed. I did
-announce a few months back that mailing lists were
-going to go. They’re still up right now, but not
-for long. I am planning to put the archives
-read-only, link to them from a future post and
-be done with it. If you have a question, open a
-ticket on Github. Then I can just decide to leave
-the ticket open if I want to do improvements based
-on your feedback.</p></div>
-<div class="paragraph"><p>I have replaced most of the "we" by "I". I am
-a one-man company right now. Have been for a while.
-Doesn’t make sense to keep a facade. I want to be
-close to users, not put a barrier between us.</p></div>
-<div class="paragraph"><p>The RSS changed. The old link doesn’t work anymore.
-The new link is at <a href="/index.xml">/index.xml</a>,
-or <a href="/articles/index.xml">/articles/index.xml</a>
-if you only care about my posts. I guess that’s the
-one most people want.</p></div>
-<div class="paragraph"><p>I still have some tweaks to do, but it will take a
-while. My long term plan is to remove Bootstrap, use
-vanilla CSS and as little JS as possible. The reason
-for that is that it’s cheaper than upgrading libraries
-every few years. Life is too short to spend it
-upgrading JS libraries.</p></div>
+<div class="paragraph"><p>Last week-end I updated the Nine Nines website.</p></div> +<div class="paragraph"><p>I switched to <a href="http://gohugo.io/">Hugo</a>. The site is +now built from <a href="http://asciidoc.org/">Asciidoc</a> +documents. You probably saw me switch to Asciidoc +for documentation this past year. This is the +natural conclusion to that story. The great thing +is that with a little bit of Makefile magic I can +just copy the documentation files into Hugo and +poof, they appear on the website.</p></div> +<div class="paragraph"><p>I am very happy with that new setup. I can now +post my thoughts again. Woo! Expect regular posts +from now on. I will try to replace my long series +of tweets with posts.</p></div> +<div class="paragraph"><p>The sections have been rearranged. There used to +be a separate training section; now +<a href="/services">all my services</a> are described in +one page. I have also clarified my areas of +expertise. There used to be confusion in the past, +so now it should be clearer that I am not a +distributed systems expert.</p></div> +<div class="paragraph"><p>On that note, if you are looking for my +services right now, I’m not available. I’ll have +to work 7 days a week for a while. Try again in a +couple months. More on that in a future post.</p></div> +<div class="paragraph"><p>The <a href="/docs">documentation</a> becomes a first class +citizen. Bullet and Cowlib don’t have proper +documentation… yet. I have started working on the +Cowlib documentation, and Bullet shouldn’t take too +long. All these projects will be documented when +Cowboy gets to 2.0, and will all be supported +equally. Note that the Cowboy 1.0 documentation +still has the old website templates and links. +Don’t worry about it.</p></div> +<div class="paragraph"><p>The mailing lists link has been removed. I did +announce a few months back that mailing lists were +going to go. They’re still up right now, but not +for long. I am planning to put the archives +read-only, link to them from a future post and +be done with it. If you have a question, open a +ticket on Github. Then I can just decide to leave +the ticket open if I want to do improvements based +on your feedback.</p></div> +<div class="paragraph"><p>I have replaced most of the "we" by "I". I am +a one-man company right now. Have been for a while. +Doesn’t make sense to keep a facade. I want to be +close to users, not put a barrier between us.</p></div> +<div class="paragraph"><p>The RSS changed. The old link doesn’t work anymore. +The new link is at <a href="/index.xml">/index.xml</a>, +or <a href="/articles/index.xml">/articles/index.xml</a> +if you only care about my posts. I guess that’s the +one most people want.</p></div> +<div class="paragraph"><p>I still have some tweaks to do, but it will take a +while. My long term plan is to remove Bootstrap, use +vanilla CSS and as little JS as possible. The reason +for that is that it’s cheaper than upgrading libraries +every few years. Life is too short to spend it +upgrading JS libraries.</p></div> </article> </div> @@ -139,55 +139,107 @@ upgrading JS libraries.</p></div> <h3>More articles</h3> <ul id="articles-nav" class="extra_margin"> - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + - <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + + <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + - <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + + <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + - <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + + <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + - <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + + <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + - <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + + <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + - <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + + <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + - <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + + <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + - <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + + <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + - <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + + <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + - <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + + <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + + + </ul> diff --git a/articles/xerl-0.1-empty-modules/index.html b/articles/xerl-0.1-empty-modules/index.html index 0a113770..c541ecdc 100644 --- a/articles/xerl-0.1-empty-modules/index.html +++ b/articles/xerl-0.1-empty-modules/index.html @@ -7,7 +7,7 @@ <meta name="description" content=""> <meta name="author" content="Loïc Hoguin based on a design from (Soft10) Pol Cámara"> - <meta name="generator" content="Hugo 0.17" /> + <meta name="generator" content="Hugo 0.26" /> <title>Nine Nines: Xerl: empty modules</title> @@ -74,144 +74,144 @@ </p> </header> -<div class="paragraph"><p>Let’s build a programming language. I call it Xerl: eXtended ERLang.
-It’ll be an occasion for us to learn a few things, especially me.</p></div>
-<div class="paragraph"><p>Unlike in Erlang, in this language, everything is an expression.
-This means that modules and functions are expression, and indeed that
-you can have more than one module per file.</p></div>
-<div class="paragraph"><p>We are just starting, so let’s no go ahead of ourselves here. We’ll
-begin with writing the code allowing us to compile an empty module.</p></div>
-<div class="paragraph"><p>We will compile to Core Erlang: this is one of the many intermediate
-step your Erlang code compiles to before it becomes BEAM machine code.
-Core Erlang is a very neat language for machine generated code, and we
-will learn many things about it.</p></div>
-<div class="paragraph"><p>Today we will only focus on compiling the following code:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="color: #FF6600">mod</span> <span style="color: #FF6600">my_module</span>
-<span style="font-weight: bold"><span style="color: #0000FF">begin</span></span>
-<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
-<div class="paragraph"><p>Compilation will be done in a few steps. First, the source file will
-be transformed in a tree of tokens by the lexer. Then, the parser will
-use that tree of tokens and convert it to the AST, bringing semantical
-meaning to our representation. Finally, the code generator will transform
-this AST to Core Erlang AST, which will then be compiled.</p></div>
-<div class="paragraph"><p>We will use <em>leex</em> for the lexer. This lexer uses .xrl files
-which are then compiled to .erl files that you can then compile to BEAM.
-The file is divided in three parts: definitions, rules and Erlang code.
-Definitions and Erlang code are obvious; rules are what concerns us.</p></div>
-<div class="paragraph"><p>We only need two things: atoms and whitespaces. Atoms are a lowercase
-letter followed by any letter, number, _ or @. Whitespace is either a
-space, an horizontal tab, \r or \n. There exists other kinds of whitespaces
-but we simply do not allow them in the Xerl language.</p></div>
-<div class="paragraph"><p>Rules consist of a regular expression followed by Erlang code. The
-latter must return a token representation or the atom <code>skip_token</code>.</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt>{<span style="color: #009900">L</span>}{<span style="color: #009900">A</span>}<span style="color: #990000">*</span> <span style="color: #990000">:</span>
- <span style="color: #009900">Atom</span> <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000080">list_to_atom</span></span>(<span style="color: #009900">TokenChars</span>),
- {<span style="color: #FF6600">token</span>, <span style="font-weight: bold"><span style="color: #0000FF">case</span></span> <span style="font-weight: bold"><span style="color: #000000">reserved_word</span></span>(<span style="color: #009900">Atom</span>) <span style="font-weight: bold"><span style="color: #0000FF">of</span></span>
- <span style="color: #000080">true</span> <span style="color: #990000">-></span> {<span style="color: #009900">Atom</span>, <span style="color: #009900">TokenLine</span>};
- <span style="color: #000080">false</span> <span style="color: #990000">-></span> {<span style="font-weight: bold"><span style="color: #000080">atom</span></span>, <span style="color: #009900">TokenLine</span>, <span style="color: #009900">Atom</span>}
- <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>}<span style="color: #990000">.</span>
-
-{<span style="color: #009900">WS</span>}<span style="color: #990000">+</span> <span style="color: #990000">:</span> <span style="color: #FF6600">skip_token</span><span style="color: #990000">.</span></tt></pre></div></div>
-<div class="paragraph"><p>The first rule matches an atom, which is converted to either a special
-representation for reserved words, or an atom tuple. The
-<code>TokenChars</code> variable represents the match as a string, and
-the <code>TokenLine</code> variable contains the line number.
-<a href="https://github.com/extend/xerl/blob/0.1/src/xerl_lexer.xrl">View the complete file</a>.</p></div>
-<div class="paragraph"><p>We obtain the following result from the lexer:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt>[{<span style="color: #FF6600">mod</span>,<span style="color: #993399">1</span>},{<span style="font-weight: bold"><span style="color: #000080">atom</span></span>,<span style="color: #993399">1</span>,<span style="color: #FF6600">my_module</span>},{<span style="color: #FF6600">'begin'</span>,<span style="color: #993399">2</span>},{<span style="color: #FF6600">'end'</span>,<span style="color: #993399">3</span>}]</tt></pre></div></div>
-<div class="paragraph"><p>The second step is to parse this list of tokens to add semantic meaning
-and generate what is called an <em>abstract syntax tree</em>. We will be
-using the <em>yecc</em> parser generator for this. This time it will take
-.yrl files but the process is the same as before. The file is a little
-more complex than for the lexer, we need to define at the very least
-terminals, nonterminals and root symbols, the grammar itself, and
-optionally some Erlang code.</p></div>
-<div class="paragraph"><p>To compile our module, we need a few things. First, everything is an
-expression. We thus need list of expressions and individual expressions.
-We will support a single expression for now, the <code>mod</code>
-expression which defines a module. And that’s it! We end up with the
-following grammar:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="color: #FF6600">exprs</span> <span style="color: #990000">-></span> <span style="color: #FF6600">expr</span> <span style="color: #990000">:</span> [<span style="color: #FF6600">'$1'</span>]<span style="color: #990000">.</span>
-<span style="color: #FF6600">exprs</span> <span style="color: #990000">-></span> <span style="color: #FF6600">expr</span> <span style="color: #FF6600">exprs</span> <span style="color: #990000">:</span> [<span style="color: #FF6600">'$1'</span> | <span style="color: #FF6600">'$2'</span>]<span style="color: #990000">.</span>
-
-<span style="color: #FF6600">expr</span> <span style="color: #990000">-></span> <span style="color: #FF6600">module</span> <span style="color: #990000">:</span> <span style="color: #FF6600">'$1'</span><span style="color: #990000">.</span>
-
-<span style="color: #FF6600">module</span> <span style="color: #990000">-></span> <span style="color: #FF6600">'mod'</span> <span style="font-weight: bold"><span style="color: #000080">atom</span></span> <span style="color: #FF6600">'begin'</span> <span style="color: #FF6600">'end'</span> <span style="color: #990000">:</span>
- {<span style="color: #FF6600">'mod'</span>, <span style="font-weight: bold"><span style="color: #000080">?line</span></span>(<span style="color: #FF6600">'$1'</span>), <span style="color: #FF6600">'$2'</span>, []}<span style="color: #990000">.</span></tt></pre></div></div>
-<div class="paragraph"><p><a href="https://github.com/extend/xerl/blob/0.1/src/xerl_parser.yrl">View the complete file</a>.</p></div>
-<div class="paragraph"><p>We obtain the following result from the parser:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt>[{<span style="color: #FF6600">mod</span>,<span style="color: #993399">1</span>,{<span style="font-weight: bold"><span style="color: #000080">atom</span></span>,<span style="color: #993399">1</span>,<span style="color: #FF6600">my_module</span>},[]}]</tt></pre></div></div>
-<div class="paragraph"><p>We obtain a list of a single <code>mod</code> expression. Just like
-we wanted. Last step is generating the Core Erlang code from it.</p></div>
-<div class="paragraph"><p>Code generation generally is comprised of several steps. We will
-discuss these in more details later on. For now, we will focus on the
-minimal needed for successful compilation.</p></div>
-<div class="paragraph"><p>We can use the <code>cerl</code> module to generate Core Erlang AST.
-We will simply be using functions, which allows us to avoid learning
-and keeping up to date with the internal representation.</p></div>
-<div class="paragraph"><p>There’s one important thing to do when generating Core Erlang AST
-for a module: create the <code>module_info/{0,1}</code> functions.
-Indeed, these are added to Erlang before it becomes Core Erlang, and
-so we need to replicate this ourselves. Do not be concerned however,
-as this only takes a few lines of extra code.</p></div>
-<div class="paragraph"><p>As you can see by
-<a href="https://github.com/extend/xerl/blob/0.1/src/xerl_codegen.erl">looking at the complete file</a>,
-the code generator echoes the grammar we defined in the parser, and
-simply applies the appropriate Core Erlang functions for each expressions.</p></div>
-<div class="paragraph"><p>We obtain the following pretty-printed Core Erlang generated code:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="color: #FF6600">module</span> <span style="color: #FF6600">'my_module'</span> [<span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">0</span>,
- <span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">1</span>]
- <span style="color: #FF6600">attributes</span> []
-<span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">0</span> <span style="color: #990000">=</span>
- <span style="font-weight: bold"><span style="color: #0000FF">fun</span></span> () <span style="color: #990000">-></span>
- <span style="font-weight: bold"><span style="color: #000080">call</span></span> <span style="color: #FF6600">'erlang'</span><span style="color: #990000">:</span><span style="color: #FF6600">'get_module_info'</span>
- (<span style="color: #FF6600">'empty_module'</span>)
-<span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">1</span> <span style="color: #990000">=</span>
- <span style="font-weight: bold"><span style="color: #0000FF">fun</span></span> (<span style="color: #009900">Key</span>) <span style="color: #990000">-></span>
- <span style="font-weight: bold"><span style="color: #000080">call</span></span> <span style="color: #FF6600">'erlang'</span><span style="color: #990000">:</span><span style="color: #FF6600">'get_module_info'</span>
- (<span style="color: #FF6600">'empty_module'</span>, <span style="color: #009900">Key</span>)
-<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
-<div class="paragraph"><p>For convenience I added all the steps in a <code>xerl:compile/1</code>
-function that you can use against your own .xerl files.</p></div>
-<div class="paragraph"><p>That’s it for today! We will go into more details over each steps in
-the next few articles.</p></div>
-<div class="ulist"><ul>
-<li>
-<p>
-<a href="https://github.com/extend/xerl/blob/0.1/">View the source</a>
-</p>
-</li>
-</ul></div>
+<div class="paragraph"><p>Let’s build a programming language. I call it Xerl: eXtended ERLang. +It’ll be an occasion for us to learn a few things, especially me.</p></div> +<div class="paragraph"><p>Unlike in Erlang, in this language, everything is an expression. +This means that modules and functions are expression, and indeed that +you can have more than one module per file.</p></div> +<div class="paragraph"><p>We are just starting, so let’s no go ahead of ourselves here. We’ll +begin with writing the code allowing us to compile an empty module.</p></div> +<div class="paragraph"><p>We will compile to Core Erlang: this is one of the many intermediate +step your Erlang code compiles to before it becomes BEAM machine code. +Core Erlang is a very neat language for machine generated code, and we +will learn many things about it.</p></div> +<div class="paragraph"><p>Today we will only focus on compiling the following code:</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="color: #FF6600">mod</span> <span style="color: #FF6600">my_module</span> +<span style="font-weight: bold"><span style="color: #0000FF">begin</span></span> +<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div> +<div class="paragraph"><p>Compilation will be done in a few steps. First, the source file will +be transformed in a tree of tokens by the lexer. Then, the parser will +use that tree of tokens and convert it to the AST, bringing semantical +meaning to our representation. Finally, the code generator will transform +this AST to Core Erlang AST, which will then be compiled.</p></div> +<div class="paragraph"><p>We will use <em>leex</em> for the lexer. This lexer uses .xrl files +which are then compiled to .erl files that you can then compile to BEAM. +The file is divided in three parts: definitions, rules and Erlang code. +Definitions and Erlang code are obvious; rules are what concerns us.</p></div> +<div class="paragraph"><p>We only need two things: atoms and whitespaces. Atoms are a lowercase +letter followed by any letter, number, _ or @. Whitespace is either a +space, an horizontal tab, \r or \n. There exists other kinds of whitespaces +but we simply do not allow them in the Xerl language.</p></div> +<div class="paragraph"><p>Rules consist of a regular expression followed by Erlang code. The +latter must return a token representation or the atom <code>skip_token</code>.</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt>{<span style="color: #009900">L</span>}{<span style="color: #009900">A</span>}<span style="color: #990000">*</span> <span style="color: #990000">:</span> + <span style="color: #009900">Atom</span> <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000080">list_to_atom</span></span>(<span style="color: #009900">TokenChars</span>), + {<span style="color: #FF6600">token</span>, <span style="font-weight: bold"><span style="color: #0000FF">case</span></span> <span style="font-weight: bold"><span style="color: #000000">reserved_word</span></span>(<span style="color: #009900">Atom</span>) <span style="font-weight: bold"><span style="color: #0000FF">of</span></span> + <span style="color: #000080">true</span> <span style="color: #990000">-></span> {<span style="color: #009900">Atom</span>, <span style="color: #009900">TokenLine</span>}; + <span style="color: #000080">false</span> <span style="color: #990000">-></span> {<span style="font-weight: bold"><span style="color: #000080">atom</span></span>, <span style="color: #009900">TokenLine</span>, <span style="color: #009900">Atom</span>} + <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>}<span style="color: #990000">.</span> + +{<span style="color: #009900">WS</span>}<span style="color: #990000">+</span> <span style="color: #990000">:</span> <span style="color: #FF6600">skip_token</span><span style="color: #990000">.</span></tt></pre></div></div> +<div class="paragraph"><p>The first rule matches an atom, which is converted to either a special +representation for reserved words, or an atom tuple. The +<code>TokenChars</code> variable represents the match as a string, and +the <code>TokenLine</code> variable contains the line number. +<a href="https://github.com/extend/xerl/blob/0.1/src/xerl_lexer.xrl">View the complete file</a>.</p></div> +<div class="paragraph"><p>We obtain the following result from the lexer:</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt>[{<span style="color: #FF6600">mod</span>,<span style="color: #993399">1</span>},{<span style="font-weight: bold"><span style="color: #000080">atom</span></span>,<span style="color: #993399">1</span>,<span style="color: #FF6600">my_module</span>},{<span style="color: #FF6600">'begin'</span>,<span style="color: #993399">2</span>},{<span style="color: #FF6600">'end'</span>,<span style="color: #993399">3</span>}]</tt></pre></div></div> +<div class="paragraph"><p>The second step is to parse this list of tokens to add semantic meaning +and generate what is called an <em>abstract syntax tree</em>. We will be +using the <em>yecc</em> parser generator for this. This time it will take +.yrl files but the process is the same as before. The file is a little +more complex than for the lexer, we need to define at the very least +terminals, nonterminals and root symbols, the grammar itself, and +optionally some Erlang code.</p></div> +<div class="paragraph"><p>To compile our module, we need a few things. First, everything is an +expression. We thus need list of expressions and individual expressions. +We will support a single expression for now, the <code>mod</code> +expression which defines a module. And that’s it! We end up with the +following grammar:</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="color: #FF6600">exprs</span> <span style="color: #990000">-></span> <span style="color: #FF6600">expr</span> <span style="color: #990000">:</span> [<span style="color: #FF6600">'$1'</span>]<span style="color: #990000">.</span> +<span style="color: #FF6600">exprs</span> <span style="color: #990000">-></span> <span style="color: #FF6600">expr</span> <span style="color: #FF6600">exprs</span> <span style="color: #990000">:</span> [<span style="color: #FF6600">'$1'</span> | <span style="color: #FF6600">'$2'</span>]<span style="color: #990000">.</span> + +<span style="color: #FF6600">expr</span> <span style="color: #990000">-></span> <span style="color: #FF6600">module</span> <span style="color: #990000">:</span> <span style="color: #FF6600">'$1'</span><span style="color: #990000">.</span> + +<span style="color: #FF6600">module</span> <span style="color: #990000">-></span> <span style="color: #FF6600">'mod'</span> <span style="font-weight: bold"><span style="color: #000080">atom</span></span> <span style="color: #FF6600">'begin'</span> <span style="color: #FF6600">'end'</span> <span style="color: #990000">:</span> + {<span style="color: #FF6600">'mod'</span>, <span style="font-weight: bold"><span style="color: #000080">?line</span></span>(<span style="color: #FF6600">'$1'</span>), <span style="color: #FF6600">'$2'</span>, []}<span style="color: #990000">.</span></tt></pre></div></div> +<div class="paragraph"><p><a href="https://github.com/extend/xerl/blob/0.1/src/xerl_parser.yrl">View the complete file</a>.</p></div> +<div class="paragraph"><p>We obtain the following result from the parser:</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt>[{<span style="color: #FF6600">mod</span>,<span style="color: #993399">1</span>,{<span style="font-weight: bold"><span style="color: #000080">atom</span></span>,<span style="color: #993399">1</span>,<span style="color: #FF6600">my_module</span>},[]}]</tt></pre></div></div> +<div class="paragraph"><p>We obtain a list of a single <code>mod</code> expression. Just like +we wanted. Last step is generating the Core Erlang code from it.</p></div> +<div class="paragraph"><p>Code generation generally is comprised of several steps. We will +discuss these in more details later on. For now, we will focus on the +minimal needed for successful compilation.</p></div> +<div class="paragraph"><p>We can use the <code>cerl</code> module to generate Core Erlang AST. +We will simply be using functions, which allows us to avoid learning +and keeping up to date with the internal representation.</p></div> +<div class="paragraph"><p>There’s one important thing to do when generating Core Erlang AST +for a module: create the <code>module_info/{0,1}</code> functions. +Indeed, these are added to Erlang before it becomes Core Erlang, and +so we need to replicate this ourselves. Do not be concerned however, +as this only takes a few lines of extra code.</p></div> +<div class="paragraph"><p>As you can see by +<a href="https://github.com/extend/xerl/blob/0.1/src/xerl_codegen.erl">looking at the complete file</a>, +the code generator echoes the grammar we defined in the parser, and +simply applies the appropriate Core Erlang functions for each expressions.</p></div> +<div class="paragraph"><p>We obtain the following pretty-printed Core Erlang generated code:</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="color: #FF6600">module</span> <span style="color: #FF6600">'my_module'</span> [<span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">0</span>, + <span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">1</span>] + <span style="color: #FF6600">attributes</span> [] +<span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">0</span> <span style="color: #990000">=</span> + <span style="font-weight: bold"><span style="color: #0000FF">fun</span></span> () <span style="color: #990000">-></span> + <span style="font-weight: bold"><span style="color: #000080">call</span></span> <span style="color: #FF6600">'erlang'</span><span style="color: #990000">:</span><span style="color: #FF6600">'get_module_info'</span> + (<span style="color: #FF6600">'empty_module'</span>) +<span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">1</span> <span style="color: #990000">=</span> + <span style="font-weight: bold"><span style="color: #0000FF">fun</span></span> (<span style="color: #009900">Key</span>) <span style="color: #990000">-></span> + <span style="font-weight: bold"><span style="color: #000080">call</span></span> <span style="color: #FF6600">'erlang'</span><span style="color: #990000">:</span><span style="color: #FF6600">'get_module_info'</span> + (<span style="color: #FF6600">'empty_module'</span>, <span style="color: #009900">Key</span>) +<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div> +<div class="paragraph"><p>For convenience I added all the steps in a <code>xerl:compile/1</code> +function that you can use against your own .xerl files.</p></div> +<div class="paragraph"><p>That’s it for today! We will go into more details over each steps in +the next few articles.</p></div> +<div class="ulist"><ul> +<li> +<p> +<a href="https://github.com/extend/xerl/blob/0.1/">View the source</a> +</p> +</li> +</ul></div> </article> </div> @@ -220,55 +220,107 @@ the next few articles.</p></div> <h3>More articles</h3> <ul id="articles-nav" class="extra_margin"> - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + + + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + + <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + - <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + + <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + - <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + + <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + - <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + + <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + - <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + + <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + - <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + + <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + - <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + + <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + - <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + + <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + - <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + + <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + - <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + + <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + - <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + </ul> diff --git a/articles/xerl-0.2-two-modules/index.html b/articles/xerl-0.2-two-modules/index.html index 632248a0..279aaa23 100644 --- a/articles/xerl-0.2-two-modules/index.html +++ b/articles/xerl-0.2-two-modules/index.html @@ -7,7 +7,7 @@ <meta name="description" content=""> <meta name="author" content="Loïc Hoguin based on a design from (Soft10) Pol Cámara"> - <meta name="generator" content="Hugo 0.17" /> + <meta name="generator" content="Hugo 0.26" /> <title>Nine Nines: Xerl: two modules</title> @@ -74,149 +74,149 @@ </p> </header> -<div class="paragraph"><p>Everything is an expression.</p></div>
-<div class="paragraph"><p>This sentence carries profound meaning. We will invoke it many
-times over the course of these articles.</p></div>
-<div class="paragraph"><p>If everything is an expression, then the language shouldn’t have
-any problem with me defining two modules in the same source file.</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="color: #FF6600">mod</span> <span style="color: #FF6600">first_module</span>
-<span style="font-weight: bold"><span style="color: #0000FF">begin</span></span>
-<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
-
-<span style="color: #FF6600">mod</span> <span style="color: #FF6600">second_module</span>
-<span style="font-weight: bold"><span style="color: #0000FF">begin</span></span>
-<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
-<div class="paragraph"><p>Likewise, it shouldn’t have any problem with me defining a
-module inside another module.</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="color: #FF6600">mod</span> <span style="color: #FF6600">out_module</span>
-<span style="font-weight: bold"><span style="color: #0000FF">begin</span></span>
- <span style="color: #FF6600">mod</span> <span style="color: #FF6600">in_module</span>
- <span style="font-weight: bold"><span style="color: #0000FF">begin</span></span>
- <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
-<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
-<div class="paragraph"><p>Of course, in the context of the Erlang VM, these two snippets
-are equivalent; there is nothing preventing you from calling the
-<code>in_module</code> module from any other module. The <code>mod</code>
-instruction means a module should be created in the Erlang VM,
-with no concept of scope attached.</p></div>
-<div class="paragraph"><p>Still we need to handle both. To do this we will add a step
-between the parser and the code generator that will walk over the
-abstract syntax tree, from here onward shortened as <em>AST</em>,
-and transform the AST by executing it where applicable.</p></div>
-<div class="paragraph"><p>What happens when you execute a <code>mod</code> instruction?
-A module is created. Since we are compiling, that simply means
-the compiler will branch out and create a module.</p></div>
-<div class="paragraph"><p>If everything is an expression, does that mean this will allow
-me to create modules at runtime using the same syntax? Yes, but
-let’s not get ahead of ourselves yet.</p></div>
-<div class="paragraph"><p>For now we will just iterate over the AST, and will compile
-a module for each <code>mod</code> found. Modules cannot contain
-expressions yet, so there’s no need to recurse over it at this
-point. This should solve the compilation of our first snippet.</p></div>
-<div class="paragraph"><p>The <code>compile/1</code> function becomes:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="font-weight: bold"><span style="color: #000000">compile</span></span>(<span style="color: #009900">Filename</span>) <span style="color: #990000">-></span>
- <span style="font-weight: bold"><span style="color: #000000">io:format</span></span>(<span style="color: #FF0000">"Compiling ~s...~n"</span>, [<span style="color: #009900">Filename</span>]),
- {<span style="color: #FF6600">ok</span>, <span style="color: #009900">Src</span>} <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">file:read_file</span></span>(<span style="color: #009900">Filename</span>),
- {<span style="color: #FF6600">ok</span>, <span style="color: #009900">Tokens</span>, <span style="color: #990000">_</span>} <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">xerl_lexer:string</span></span>(<span style="font-weight: bold"><span style="color: #000080">binary_to_list</span></span>(<span style="color: #009900">Src</span>)),
- {<span style="color: #FF6600">ok</span>, <span style="color: #009900">Exprs</span>} <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">xerl_parser:parse</span></span>(<span style="color: #009900">Tokens</span>),
- <span style="font-weight: bold"><span style="color: #000000">execute</span></span>(<span style="color: #009900">Filename</span>, <span style="color: #009900">Exprs</span>, [])<span style="color: #990000">.</span>
-
-<span style="font-weight: bold"><span style="color: #000000">execute</span></span>(<span style="color: #990000">_</span>, [], <span style="color: #009900">Modules</span>) <span style="color: #990000">-></span>
- <span style="font-weight: bold"><span style="color: #000000">io:format</span></span>(<span style="color: #FF0000">"Done...~n"</span>),
- {<span style="color: #FF6600">ok</span>, <span style="font-weight: bold"><span style="color: #000000">lists:reverse</span></span>(<span style="color: #009900">Modules</span>)};
-<span style="font-weight: bold"><span style="color: #000000">execute</span></span>(<span style="color: #009900">Filename</span>, [<span style="color: #009900">Expr</span> <span style="color: #990000">=</span> {<span style="color: #FF6600">mod</span>, <span style="color: #990000">_</span>, {<span style="font-weight: bold"><span style="color: #000080">atom</span></span>, <span style="color: #990000">_</span>, <span style="color: #009900">Name</span>}, []}|<span style="color: #009900">Tail</span>], <span style="color: #009900">Modules</span>) <span style="color: #990000">-></span>
- {<span style="color: #FF6600">ok</span>, [<span style="color: #009900">Core</span>]} <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">xerl_codegen:exprs</span></span>([<span style="color: #009900">Expr</span>]),
- {<span style="color: #FF6600">ok</span>, [{<span style="color: #009900">Name</span>, []}]} <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">core_lint:module</span></span>(<span style="color: #009900">Core</span>),
- <span style="font-weight: bold"><span style="color: #000000">io:format</span></span>(<span style="color: #FF0000">"~s~n"</span>, [<span style="font-weight: bold"><span style="color: #000000">core_pp:format</span></span>(<span style="color: #009900">Core</span>)]),
- {<span style="color: #FF6600">ok</span>, <span style="color: #990000">_</span>, <span style="color: #009900">Beam</span>} <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">compile:forms</span></span>(<span style="color: #009900">Core</span>,
- [<span style="font-weight: bold"><span style="color: #000080">binary</span></span>, <span style="color: #FF6600">from_core</span>, <span style="color: #FF6600">return_errors</span>, {<span style="color: #FF6600">source</span>, <span style="color: #009900">Filename</span>}]),
- {<span style="color: #FF6600">module</span>, <span style="color: #009900">Name</span>} <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">code:load_binary</span></span>(<span style="color: #009900">Name</span>, <span style="color: #009900">Filename</span>, <span style="color: #009900">Beam</span>),
- <span style="font-weight: bold"><span style="color: #000000">execute</span></span>(<span style="color: #009900">Filename</span>, <span style="color: #009900">Tail</span>, [<span style="color: #009900">Name</span>|<span style="color: #009900">Modules</span>])<span style="color: #990000">.</span></tt></pre></div></div>
-<div class="paragraph"><p>Running this compiler over the first snippet yields the following
-result:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="color: #009900">Compiling</span> <span style="font-weight: bold"><span style="color: #000000">test</span></span><span style="color: #990000">/</span><span style="font-weight: bold"><span style="color: #000000">mod_SUITE_data</span></span><span style="color: #990000">/</span><span style="color: #FF6600">two_modules</span><span style="color: #990000">.</span><span style="color: #FF6600">xerl</span><span style="color: #990000">...</span>
-<span style="color: #FF6600">module</span> <span style="color: #FF6600">'first_module'</span> [<span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">0</span>,
- <span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">1</span>]
- <span style="color: #FF6600">attributes</span> []
-<span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">0</span> <span style="color: #990000">=</span>
- <span style="font-weight: bold"><span style="color: #0000FF">fun</span></span> () <span style="color: #990000">-></span>
- <span style="font-weight: bold"><span style="color: #000080">call</span></span> <span style="color: #FF6600">'erlang'</span><span style="color: #990000">:</span><span style="color: #FF6600">'get_module_info'</span>
- (<span style="color: #FF6600">'first_module'</span>)
-<span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">1</span> <span style="color: #990000">=</span>
- <span style="font-weight: bold"><span style="color: #0000FF">fun</span></span> (<span style="color: #009900">Key</span>) <span style="color: #990000">-></span>
- <span style="font-weight: bold"><span style="color: #000080">call</span></span> <span style="color: #FF6600">'erlang'</span><span style="color: #990000">:</span><span style="color: #FF6600">'get_module_info'</span>
- (<span style="color: #FF6600">'first_module'</span>, <span style="color: #009900">Key</span>)
-<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
-<span style="color: #FF6600">module</span> <span style="color: #FF6600">'second_module'</span> [<span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">0</span>,
- <span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">1</span>]
- <span style="color: #FF6600">attributes</span> []
-<span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">0</span> <span style="color: #990000">=</span>
- <span style="font-weight: bold"><span style="color: #0000FF">fun</span></span> () <span style="color: #990000">-></span>
- <span style="font-weight: bold"><span style="color: #000080">call</span></span> <span style="color: #FF6600">'erlang'</span><span style="color: #990000">:</span><span style="color: #FF6600">'get_module_info'</span>
- (<span style="color: #FF6600">'second_module'</span>)
-<span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">1</span> <span style="color: #990000">=</span>
- <span style="font-weight: bold"><span style="color: #0000FF">fun</span></span> (<span style="color: #009900">Key</span>) <span style="color: #990000">-></span>
- <span style="font-weight: bold"><span style="color: #000080">call</span></span> <span style="color: #FF6600">'erlang'</span><span style="color: #990000">:</span><span style="color: #FF6600">'get_module_info'</span>
- (<span style="color: #FF6600">'second_module'</span>, <span style="color: #009900">Key</span>)
-<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
-<span style="color: #009900">Done</span><span style="color: #990000">...</span>
-{<span style="color: #FF6600">ok</span>,[<span style="color: #FF6600">first_module</span>,<span style="color: #FF6600">second_module</span>]}</tt></pre></div></div>
-<div class="paragraph"><p>Everything looks fine. And we can check that the two modules have
-been loaded into the VM:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="color: #993399">9</span><span style="color: #990000">></span> <span style="color: #FF6600">m</span>(<span style="color: #FF6600">first_module</span>)<span style="color: #990000">.</span>
-<span style="color: #009900">Module</span> <span style="color: #FF6600">first_module</span> <span style="color: #FF6600">compiled</span><span style="color: #990000">:</span> <span style="color: #009900">Date</span><span style="color: #990000">:</span> <span style="color: #009900">February</span> <span style="color: #993399">2</span> <span style="color: #993399">2013</span>, <span style="color: #009900">Time</span><span style="color: #990000">:</span> <span style="color: #993399">14.56</span>
-<span style="color: #009900">Compiler</span> <span style="color: #FF6600">options</span><span style="color: #990000">:</span> [<span style="color: #FF6600">from_core</span>]
-<span style="color: #009900">Object</span> <span style="font-weight: bold"><span style="color: #000000">file: test</span></span><span style="color: #990000">/</span><span style="font-weight: bold"><span style="color: #000000">mod_SUITE_data</span></span><span style="color: #990000">/</span><span style="color: #FF6600">two_modules</span><span style="color: #990000">.</span><span style="color: #FF6600">xerl</span>
-<span style="color: #009900">Exports</span><span style="color: #990000">:</span>
- <span style="font-weight: bold"><span style="color: #000080">module_info</span></span><span style="color: #990000">/</span><span style="color: #993399">0</span>
- <span style="font-weight: bold"><span style="color: #000080">module_info</span></span><span style="color: #990000">/</span><span style="color: #993399">1</span>
-<span style="color: #FF6600">ok</span>
-<span style="color: #993399">10</span><span style="color: #990000">></span> <span style="color: #FF6600">m</span>(<span style="color: #FF6600">second_module</span>)<span style="color: #990000">.</span>
-<span style="color: #009900">Module</span> <span style="color: #FF6600">second_module</span> <span style="color: #FF6600">compiled</span><span style="color: #990000">:</span> <span style="color: #009900">Date</span><span style="color: #990000">:</span> <span style="color: #009900">February</span> <span style="color: #993399">2</span> <span style="color: #993399">2013</span>, <span style="color: #009900">Time</span><span style="color: #990000">:</span> <span style="color: #993399">14.56</span>
-<span style="color: #009900">Compiler</span> <span style="color: #FF6600">options</span><span style="color: #990000">:</span> [<span style="color: #FF6600">from_core</span>]
-<span style="color: #009900">Object</span> <span style="font-weight: bold"><span style="color: #000000">file: test</span></span><span style="color: #990000">/</span><span style="font-weight: bold"><span style="color: #000000">mod_SUITE_data</span></span><span style="color: #990000">/</span><span style="color: #FF6600">two_modules</span><span style="color: #990000">.</span><span style="color: #FF6600">xerl</span>
-<span style="color: #009900">Exports</span><span style="color: #990000">:</span>
- <span style="font-weight: bold"><span style="color: #000080">module_info</span></span><span style="color: #990000">/</span><span style="color: #993399">0</span>
- <span style="font-weight: bold"><span style="color: #000080">module_info</span></span><span style="color: #990000">/</span><span style="color: #993399">1</span>
-<span style="color: #FF6600">ok</span></tt></pre></div></div>
-<div class="paragraph"><p>So far so good!</p></div>
-<div class="paragraph"><p>What about the second snippet? It brings up many questions. What
-happens once a <code>mod</code> expression has been executed at
-compile time? If it’s an expression then it has to have a result,
-right? Right. We are still a bit lacking with expressions for now,
-though, so let’s get back to it after we add more.</p></div>
-<div class="ulist"><ul>
-<li>
-<p>
-<a href="https://github.com/extend/xerl/blob/0.2/">View the source</a>
-</p>
-</li>
-</ul></div>
+<div class="paragraph"><p>Everything is an expression.</p></div> +<div class="paragraph"><p>This sentence carries profound meaning. We will invoke it many +times over the course of these articles.</p></div> +<div class="paragraph"><p>If everything is an expression, then the language shouldn’t have +any problem with me defining two modules in the same source file.</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="color: #FF6600">mod</span> <span style="color: #FF6600">first_module</span> +<span style="font-weight: bold"><span style="color: #0000FF">begin</span></span> +<span style="font-weight: bold"><span style="color: #0000FF">end</span></span> + +<span style="color: #FF6600">mod</span> <span style="color: #FF6600">second_module</span> +<span style="font-weight: bold"><span style="color: #0000FF">begin</span></span> +<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div> +<div class="paragraph"><p>Likewise, it shouldn’t have any problem with me defining a +module inside another module.</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="color: #FF6600">mod</span> <span style="color: #FF6600">out_module</span> +<span style="font-weight: bold"><span style="color: #0000FF">begin</span></span> + <span style="color: #FF6600">mod</span> <span style="color: #FF6600">in_module</span> + <span style="font-weight: bold"><span style="color: #0000FF">begin</span></span> + <span style="font-weight: bold"><span style="color: #0000FF">end</span></span> +<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div> +<div class="paragraph"><p>Of course, in the context of the Erlang VM, these two snippets +are equivalent; there is nothing preventing you from calling the +<code>in_module</code> module from any other module. The <code>mod</code> +instruction means a module should be created in the Erlang VM, +with no concept of scope attached.</p></div> +<div class="paragraph"><p>Still we need to handle both. To do this we will add a step +between the parser and the code generator that will walk over the +abstract syntax tree, from here onward shortened as <em>AST</em>, +and transform the AST by executing it where applicable.</p></div> +<div class="paragraph"><p>What happens when you execute a <code>mod</code> instruction? +A module is created. Since we are compiling, that simply means +the compiler will branch out and create a module.</p></div> +<div class="paragraph"><p>If everything is an expression, does that mean this will allow +me to create modules at runtime using the same syntax? Yes, but +let’s not get ahead of ourselves yet.</p></div> +<div class="paragraph"><p>For now we will just iterate over the AST, and will compile +a module for each <code>mod</code> found. Modules cannot contain +expressions yet, so there’s no need to recurse over it at this +point. This should solve the compilation of our first snippet.</p></div> +<div class="paragraph"><p>The <code>compile/1</code> function becomes:</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="font-weight: bold"><span style="color: #000000">compile</span></span>(<span style="color: #009900">Filename</span>) <span style="color: #990000">-></span> + <span style="font-weight: bold"><span style="color: #000000">io:format</span></span>(<span style="color: #FF0000">"Compiling ~s...~n"</span>, [<span style="color: #009900">Filename</span>]), + {<span style="color: #FF6600">ok</span>, <span style="color: #009900">Src</span>} <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">file:read_file</span></span>(<span style="color: #009900">Filename</span>), + {<span style="color: #FF6600">ok</span>, <span style="color: #009900">Tokens</span>, <span style="color: #990000">_</span>} <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">xerl_lexer:string</span></span>(<span style="font-weight: bold"><span style="color: #000080">binary_to_list</span></span>(<span style="color: #009900">Src</span>)), + {<span style="color: #FF6600">ok</span>, <span style="color: #009900">Exprs</span>} <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">xerl_parser:parse</span></span>(<span style="color: #009900">Tokens</span>), + <span style="font-weight: bold"><span style="color: #000000">execute</span></span>(<span style="color: #009900">Filename</span>, <span style="color: #009900">Exprs</span>, [])<span style="color: #990000">.</span> + +<span style="font-weight: bold"><span style="color: #000000">execute</span></span>(<span style="color: #990000">_</span>, [], <span style="color: #009900">Modules</span>) <span style="color: #990000">-></span> + <span style="font-weight: bold"><span style="color: #000000">io:format</span></span>(<span style="color: #FF0000">"Done...~n"</span>), + {<span style="color: #FF6600">ok</span>, <span style="font-weight: bold"><span style="color: #000000">lists:reverse</span></span>(<span style="color: #009900">Modules</span>)}; +<span style="font-weight: bold"><span style="color: #000000">execute</span></span>(<span style="color: #009900">Filename</span>, [<span style="color: #009900">Expr</span> <span style="color: #990000">=</span> {<span style="color: #FF6600">mod</span>, <span style="color: #990000">_</span>, {<span style="font-weight: bold"><span style="color: #000080">atom</span></span>, <span style="color: #990000">_</span>, <span style="color: #009900">Name</span>}, []}|<span style="color: #009900">Tail</span>], <span style="color: #009900">Modules</span>) <span style="color: #990000">-></span> + {<span style="color: #FF6600">ok</span>, [<span style="color: #009900">Core</span>]} <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">xerl_codegen:exprs</span></span>([<span style="color: #009900">Expr</span>]), + {<span style="color: #FF6600">ok</span>, [{<span style="color: #009900">Name</span>, []}]} <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">core_lint:module</span></span>(<span style="color: #009900">Core</span>), + <span style="font-weight: bold"><span style="color: #000000">io:format</span></span>(<span style="color: #FF0000">"~s~n"</span>, [<span style="font-weight: bold"><span style="color: #000000">core_pp:format</span></span>(<span style="color: #009900">Core</span>)]), + {<span style="color: #FF6600">ok</span>, <span style="color: #990000">_</span>, <span style="color: #009900">Beam</span>} <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">compile:forms</span></span>(<span style="color: #009900">Core</span>, + [<span style="font-weight: bold"><span style="color: #000080">binary</span></span>, <span style="color: #FF6600">from_core</span>, <span style="color: #FF6600">return_errors</span>, {<span style="color: #FF6600">source</span>, <span style="color: #009900">Filename</span>}]), + {<span style="color: #FF6600">module</span>, <span style="color: #009900">Name</span>} <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">code:load_binary</span></span>(<span style="color: #009900">Name</span>, <span style="color: #009900">Filename</span>, <span style="color: #009900">Beam</span>), + <span style="font-weight: bold"><span style="color: #000000">execute</span></span>(<span style="color: #009900">Filename</span>, <span style="color: #009900">Tail</span>, [<span style="color: #009900">Name</span>|<span style="color: #009900">Modules</span>])<span style="color: #990000">.</span></tt></pre></div></div> +<div class="paragraph"><p>Running this compiler over the first snippet yields the following +result:</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="color: #009900">Compiling</span> <span style="font-weight: bold"><span style="color: #000000">test</span></span><span style="color: #990000">/</span><span style="font-weight: bold"><span style="color: #000000">mod_SUITE_data</span></span><span style="color: #990000">/</span><span style="color: #FF6600">two_modules</span><span style="color: #990000">.</span><span style="color: #FF6600">xerl</span><span style="color: #990000">...</span> +<span style="color: #FF6600">module</span> <span style="color: #FF6600">'first_module'</span> [<span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">0</span>, + <span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">1</span>] + <span style="color: #FF6600">attributes</span> [] +<span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">0</span> <span style="color: #990000">=</span> + <span style="font-weight: bold"><span style="color: #0000FF">fun</span></span> () <span style="color: #990000">-></span> + <span style="font-weight: bold"><span style="color: #000080">call</span></span> <span style="color: #FF6600">'erlang'</span><span style="color: #990000">:</span><span style="color: #FF6600">'get_module_info'</span> + (<span style="color: #FF6600">'first_module'</span>) +<span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">1</span> <span style="color: #990000">=</span> + <span style="font-weight: bold"><span style="color: #0000FF">fun</span></span> (<span style="color: #009900">Key</span>) <span style="color: #990000">-></span> + <span style="font-weight: bold"><span style="color: #000080">call</span></span> <span style="color: #FF6600">'erlang'</span><span style="color: #990000">:</span><span style="color: #FF6600">'get_module_info'</span> + (<span style="color: #FF6600">'first_module'</span>, <span style="color: #009900">Key</span>) +<span style="font-weight: bold"><span style="color: #0000FF">end</span></span> +<span style="color: #FF6600">module</span> <span style="color: #FF6600">'second_module'</span> [<span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">0</span>, + <span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">1</span>] + <span style="color: #FF6600">attributes</span> [] +<span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">0</span> <span style="color: #990000">=</span> + <span style="font-weight: bold"><span style="color: #0000FF">fun</span></span> () <span style="color: #990000">-></span> + <span style="font-weight: bold"><span style="color: #000080">call</span></span> <span style="color: #FF6600">'erlang'</span><span style="color: #990000">:</span><span style="color: #FF6600">'get_module_info'</span> + (<span style="color: #FF6600">'second_module'</span>) +<span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">1</span> <span style="color: #990000">=</span> + <span style="font-weight: bold"><span style="color: #0000FF">fun</span></span> (<span style="color: #009900">Key</span>) <span style="color: #990000">-></span> + <span style="font-weight: bold"><span style="color: #000080">call</span></span> <span style="color: #FF6600">'erlang'</span><span style="color: #990000">:</span><span style="color: #FF6600">'get_module_info'</span> + (<span style="color: #FF6600">'second_module'</span>, <span style="color: #009900">Key</span>) +<span style="font-weight: bold"><span style="color: #0000FF">end</span></span> +<span style="color: #009900">Done</span><span style="color: #990000">...</span> +{<span style="color: #FF6600">ok</span>,[<span style="color: #FF6600">first_module</span>,<span style="color: #FF6600">second_module</span>]}</tt></pre></div></div> +<div class="paragraph"><p>Everything looks fine. And we can check that the two modules have +been loaded into the VM:</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="color: #993399">9</span><span style="color: #990000">></span> <span style="color: #FF6600">m</span>(<span style="color: #FF6600">first_module</span>)<span style="color: #990000">.</span> +<span style="color: #009900">Module</span> <span style="color: #FF6600">first_module</span> <span style="color: #FF6600">compiled</span><span style="color: #990000">:</span> <span style="color: #009900">Date</span><span style="color: #990000">:</span> <span style="color: #009900">February</span> <span style="color: #993399">2</span> <span style="color: #993399">2013</span>, <span style="color: #009900">Time</span><span style="color: #990000">:</span> <span style="color: #993399">14.56</span> +<span style="color: #009900">Compiler</span> <span style="color: #FF6600">options</span><span style="color: #990000">:</span> [<span style="color: #FF6600">from_core</span>] +<span style="color: #009900">Object</span> <span style="font-weight: bold"><span style="color: #000000">file: test</span></span><span style="color: #990000">/</span><span style="font-weight: bold"><span style="color: #000000">mod_SUITE_data</span></span><span style="color: #990000">/</span><span style="color: #FF6600">two_modules</span><span style="color: #990000">.</span><span style="color: #FF6600">xerl</span> +<span style="color: #009900">Exports</span><span style="color: #990000">:</span> + <span style="font-weight: bold"><span style="color: #000080">module_info</span></span><span style="color: #990000">/</span><span style="color: #993399">0</span> + <span style="font-weight: bold"><span style="color: #000080">module_info</span></span><span style="color: #990000">/</span><span style="color: #993399">1</span> +<span style="color: #FF6600">ok</span> +<span style="color: #993399">10</span><span style="color: #990000">></span> <span style="color: #FF6600">m</span>(<span style="color: #FF6600">second_module</span>)<span style="color: #990000">.</span> +<span style="color: #009900">Module</span> <span style="color: #FF6600">second_module</span> <span style="color: #FF6600">compiled</span><span style="color: #990000">:</span> <span style="color: #009900">Date</span><span style="color: #990000">:</span> <span style="color: #009900">February</span> <span style="color: #993399">2</span> <span style="color: #993399">2013</span>, <span style="color: #009900">Time</span><span style="color: #990000">:</span> <span style="color: #993399">14.56</span> +<span style="color: #009900">Compiler</span> <span style="color: #FF6600">options</span><span style="color: #990000">:</span> [<span style="color: #FF6600">from_core</span>] +<span style="color: #009900">Object</span> <span style="font-weight: bold"><span style="color: #000000">file: test</span></span><span style="color: #990000">/</span><span style="font-weight: bold"><span style="color: #000000">mod_SUITE_data</span></span><span style="color: #990000">/</span><span style="color: #FF6600">two_modules</span><span style="color: #990000">.</span><span style="color: #FF6600">xerl</span> +<span style="color: #009900">Exports</span><span style="color: #990000">:</span> + <span style="font-weight: bold"><span style="color: #000080">module_info</span></span><span style="color: #990000">/</span><span style="color: #993399">0</span> + <span style="font-weight: bold"><span style="color: #000080">module_info</span></span><span style="color: #990000">/</span><span style="color: #993399">1</span> +<span style="color: #FF6600">ok</span></tt></pre></div></div> +<div class="paragraph"><p>So far so good!</p></div> +<div class="paragraph"><p>What about the second snippet? It brings up many questions. What +happens once a <code>mod</code> expression has been executed at +compile time? If it’s an expression then it has to have a result, +right? Right. We are still a bit lacking with expressions for now, +though, so let’s get back to it after we add more.</p></div> +<div class="ulist"><ul> +<li> +<p> +<a href="https://github.com/extend/xerl/blob/0.2/">View the source</a> +</p> +</li> +</ul></div> </article> </div> @@ -225,55 +225,107 @@ though, so let’s get back to it after we add more.</p></div> <h3>More articles</h3> <ul id="articles-nav" class="extra_margin"> - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + + + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + + <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + - <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + + <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + - <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + + <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + - <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + + <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + - <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + + <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + - <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + + <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + - <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + + <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + - <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + + <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + - <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + + <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + - <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + + <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + - <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + </ul> diff --git a/articles/xerl-0.3-atomic-expressions/index.html b/articles/xerl-0.3-atomic-expressions/index.html index f3042180..b49b5613 100644 --- a/articles/xerl-0.3-atomic-expressions/index.html +++ b/articles/xerl-0.3-atomic-expressions/index.html @@ -7,7 +7,7 @@ <meta name="description" content=""> <meta name="author" content="Loïc Hoguin based on a design from (Soft10) Pol Cámara"> - <meta name="generator" content="Hugo 0.17" /> + <meta name="generator" content="Hugo 0.26" /> <title>Nine Nines: Xerl: atomic expressions</title> @@ -74,153 +74,153 @@ </p> </header> -<div class="paragraph"><p>We will be adding atomic integer expressions to our language.
-These look as follow in Erlang:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="color: #993399">42</span><span style="color: #990000">.</span></tt></pre></div></div>
-<div class="paragraph"><p>And the result of this expression is of course 42.</p></div>
-<div class="paragraph"><p>We will be running this expression at compile time, since we
-don’t have the means to run code at runtime yet. This will of
-course result in no module being compiled, but that’s OK, it will
-allow us to discuss a few important things we’ll have to plan for
-later on.</p></div>
-<div class="paragraph"><p>First, we must of course accept integers in the tokenizer.</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt>{<span style="color: #009900">D</span>}<span style="color: #990000">+</span> <span style="color: #990000">:</span> {<span style="color: #FF6600">token</span>, {<span style="font-weight: bold"><span style="color: #000080">integer</span></span>, <span style="color: #009900">TokenLine</span>, <span style="font-weight: bold"><span style="color: #000080">list_to_integer</span></span>(<span style="color: #009900">TokenChars</span>)}}<span style="color: #990000">.</span></tt></pre></div></div>
-<div class="paragraph"><p>We must then accept atomic integer expressions in the parser.
-This is a simple change. The integer token is terminal so we need
-to add it to the list of terminals, and then we only need to add
-it as a possible expression.</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="color: #FF6600">expr</span> <span style="color: #990000">-></span> <span style="color: #FF6600">integer</span> <span style="color: #990000">:</span> <span style="color: #FF6600">'$1'</span><span style="color: #990000">.</span></tt></pre></div></div>
-<div class="paragraph"><p>A file containing only the number 42 (with no terminating dot)
-will give the following result when parsing it. This is incidentally
-the same result as when tokenizing.</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt>[{<span style="font-weight: bold"><span style="color: #000080">integer</span></span>,<span style="color: #993399">1</span>,<span style="color: #993399">42</span>}]</tt></pre></div></div>
-<div class="paragraph"><p>We must then evaluate it. We’re going to interpret it for now.
-Since the result of this expression is not stored in a variable,
-we are going to simply print it on the screen and discard it.</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="font-weight: bold"><span style="color: #000000">execute</span></span>(<span style="color: #009900">Filename</span>, [{<span style="font-weight: bold"><span style="color: #000080">integer</span></span>, <span style="color: #990000">_</span>, <span style="color: #009900">Int</span>}|<span style="color: #009900">Tail</span>], <span style="color: #009900">Modules</span>) <span style="color: #990000">-></span>
- <span style="font-weight: bold"><span style="color: #000000">io:format</span></span>(<span style="color: #FF0000">"integer ~p~n"</span>, [<span style="color: #009900">Int</span>]),
- <span style="font-weight: bold"><span style="color: #000000">execute</span></span>(<span style="color: #009900">Filename</span>, <span style="color: #009900">Tail</span>, <span style="color: #009900">Modules</span>)<span style="color: #990000">.</span></tt></pre></div></div>
-<div class="paragraph"><p>You might think by now that what we’ve done so far this time
-is useless. It brings up many interesting questions though.</p></div>
-<div class="ulist"><ul>
-<li>
-<p>
-What happens if a file contains two integers?
-</p>
-</li>
-<li>
-<p>
-Can we live without expression separators?
-</p>
-</li>
-<li>
-<p>
-Do we need an interpreter for the compile step?
-</p>
-</li>
-</ul></div>
-<div class="paragraph"><p>This is what happens when we create a file that contains two
-integers on two separate lines:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt>[{<span style="font-weight: bold"><span style="color: #000080">integer</span></span>,<span style="color: #993399">1</span>,<span style="color: #993399">42</span>},{<span style="font-weight: bold"><span style="color: #000080">integer</span></span>,<span style="color: #993399">2</span>,<span style="color: #993399">43</span>}]</tt></pre></div></div>
-<div class="paragraph"><p>And on the same lines:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt>[{<span style="font-weight: bold"><span style="color: #000080">integer</span></span>,<span style="color: #993399">1</span>,<span style="color: #993399">42</span>},{<span style="font-weight: bold"><span style="color: #000080">integer</span></span>,<span style="color: #993399">1</span>,<span style="color: #993399">43</span>}]</tt></pre></div></div>
-<div class="paragraph"><p>Does this mean we do not need separators between expressions?
-Not quite. The <code>+</code> and <code>-</code> operators are an
-example of why we can’t have nice things. They are ambiguous. They
-have two different meanings: make an atomic integer positive or
-negative, or perform an addition or a substraction between two
-integers. Without a separator you won’t be able to know if the
-following snippet is one or two expressions:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="color: #993399">42</span> <span style="color: #990000">-</span> <span style="color: #993399">12</span></tt></pre></div></div>
-<div class="paragraph"><p>Can we use the line ending as an expression separator then?
-Some languages make whitespace important, often the line
-separator becomes the expression separator. I do not think this
-is the best idea, it can lead to errors. For example the following
-snippet would be two expressions:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="color: #009900">Var</span> <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">some_module:some_function</span></span>() <span style="color: #990000">+</span> <span style="font-weight: bold"><span style="color: #000000">some_module:other_function</span></span>()
- <span style="color: #990000">+</span> <span style="font-weight: bold"><span style="color: #000000">another_module:another_function</span></span>()</tt></pre></div></div>
-<div class="paragraph"><p>It is not obvious what would happen unless you are a veteran
-of the language, and so we will not go down that road. We will use
-an expression separator just like in Erlang: the comma. We will
-however allow a trailing comma to make copy pasting code easier,
-even if this means some old academics guy will go nuts about it
-later on. This trailing comma will be optional and simply discarded
-by the parser when encountered. We will implement this next.</p></div>
-<div class="paragraph"><p>The question as to how we will handle running expressions
-remains. We have two choices here: we can write an interpreter,
-or we can compile the code and run it. Writing an interpreter
-would require us to do twice the work, and we are lazy, so we will
-not do that.</p></div>
-<div class="paragraph"><p>You might already know that Erlang does not use the same code
-for compiling and for evaluating commands in the shell. The main
-reason for this is that in Erlang everything isn’t an expression.
-Indeed, the compiler compiles forms which contain expressions,
-but you can’t have forms in the shell.</p></div>
-<div class="paragraph"><p>How are we going to compile the code that isn’t part of a module
-then? What do we need to run at compile-time, anyway? The body of
-the file itself, of course. The body of module declarations. That’s
-about it.</p></div>
-<div class="paragraph"><p>For the file itself, we can simply compile it as a big function
-that will be executed. Then, everytime we encounter a module
-declaration, we will run the compiler on its body, making its body
-essentially a big function that will be executed. The same mechanism
-will be applied when we encounter a module declaration at runtime.</p></div>
-<div class="paragraph"><p>At runtime there’s nothing else for us to do, the result of this
-operation will load all the compiled modules. At compile time we
-will also want to save them to a file. We’ll see later how we can
-do that.</p></div>
-<div class="ulist"><ul>
-<li>
-<p>
-<a href="https://github.com/extend/xerl/blob/0.3/">View the source</a>
-</p>
-</li>
-</ul></div>
+<div class="paragraph"><p>We will be adding atomic integer expressions to our language. +These look as follow in Erlang:</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="color: #993399">42</span><span style="color: #990000">.</span></tt></pre></div></div> +<div class="paragraph"><p>And the result of this expression is of course 42.</p></div> +<div class="paragraph"><p>We will be running this expression at compile time, since we +don’t have the means to run code at runtime yet. This will of +course result in no module being compiled, but that’s OK, it will +allow us to discuss a few important things we’ll have to plan for +later on.</p></div> +<div class="paragraph"><p>First, we must of course accept integers in the tokenizer.</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt>{<span style="color: #009900">D</span>}<span style="color: #990000">+</span> <span style="color: #990000">:</span> {<span style="color: #FF6600">token</span>, {<span style="font-weight: bold"><span style="color: #000080">integer</span></span>, <span style="color: #009900">TokenLine</span>, <span style="font-weight: bold"><span style="color: #000080">list_to_integer</span></span>(<span style="color: #009900">TokenChars</span>)}}<span style="color: #990000">.</span></tt></pre></div></div> +<div class="paragraph"><p>We must then accept atomic integer expressions in the parser. +This is a simple change. The integer token is terminal so we need +to add it to the list of terminals, and then we only need to add +it as a possible expression.</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="color: #FF6600">expr</span> <span style="color: #990000">-></span> <span style="color: #FF6600">integer</span> <span style="color: #990000">:</span> <span style="color: #FF6600">'$1'</span><span style="color: #990000">.</span></tt></pre></div></div> +<div class="paragraph"><p>A file containing only the number 42 (with no terminating dot) +will give the following result when parsing it. This is incidentally +the same result as when tokenizing.</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt>[{<span style="font-weight: bold"><span style="color: #000080">integer</span></span>,<span style="color: #993399">1</span>,<span style="color: #993399">42</span>}]</tt></pre></div></div> +<div class="paragraph"><p>We must then evaluate it. We’re going to interpret it for now. +Since the result of this expression is not stored in a variable, +we are going to simply print it on the screen and discard it.</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="font-weight: bold"><span style="color: #000000">execute</span></span>(<span style="color: #009900">Filename</span>, [{<span style="font-weight: bold"><span style="color: #000080">integer</span></span>, <span style="color: #990000">_</span>, <span style="color: #009900">Int</span>}|<span style="color: #009900">Tail</span>], <span style="color: #009900">Modules</span>) <span style="color: #990000">-></span> + <span style="font-weight: bold"><span style="color: #000000">io:format</span></span>(<span style="color: #FF0000">"integer ~p~n"</span>, [<span style="color: #009900">Int</span>]), + <span style="font-weight: bold"><span style="color: #000000">execute</span></span>(<span style="color: #009900">Filename</span>, <span style="color: #009900">Tail</span>, <span style="color: #009900">Modules</span>)<span style="color: #990000">.</span></tt></pre></div></div> +<div class="paragraph"><p>You might think by now that what we’ve done so far this time +is useless. It brings up many interesting questions though.</p></div> +<div class="ulist"><ul> +<li> +<p> +What happens if a file contains two integers? +</p> +</li> +<li> +<p> +Can we live without expression separators? +</p> +</li> +<li> +<p> +Do we need an interpreter for the compile step? +</p> +</li> +</ul></div> +<div class="paragraph"><p>This is what happens when we create a file that contains two +integers on two separate lines:</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt>[{<span style="font-weight: bold"><span style="color: #000080">integer</span></span>,<span style="color: #993399">1</span>,<span style="color: #993399">42</span>},{<span style="font-weight: bold"><span style="color: #000080">integer</span></span>,<span style="color: #993399">2</span>,<span style="color: #993399">43</span>}]</tt></pre></div></div> +<div class="paragraph"><p>And on the same lines:</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt>[{<span style="font-weight: bold"><span style="color: #000080">integer</span></span>,<span style="color: #993399">1</span>,<span style="color: #993399">42</span>},{<span style="font-weight: bold"><span style="color: #000080">integer</span></span>,<span style="color: #993399">1</span>,<span style="color: #993399">43</span>}]</tt></pre></div></div> +<div class="paragraph"><p>Does this mean we do not need separators between expressions? +Not quite. The <code>+</code> and <code>-</code> operators are an +example of why we can’t have nice things. They are ambiguous. They +have two different meanings: make an atomic integer positive or +negative, or perform an addition or a substraction between two +integers. Without a separator you won’t be able to know if the +following snippet is one or two expressions:</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="color: #993399">42</span> <span style="color: #990000">-</span> <span style="color: #993399">12</span></tt></pre></div></div> +<div class="paragraph"><p>Can we use the line ending as an expression separator then? +Some languages make whitespace important, often the line +separator becomes the expression separator. I do not think this +is the best idea, it can lead to errors. For example the following +snippet would be two expressions:</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="color: #009900">Var</span> <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">some_module:some_function</span></span>() <span style="color: #990000">+</span> <span style="font-weight: bold"><span style="color: #000000">some_module:other_function</span></span>() + <span style="color: #990000">+</span> <span style="font-weight: bold"><span style="color: #000000">another_module:another_function</span></span>()</tt></pre></div></div> +<div class="paragraph"><p>It is not obvious what would happen unless you are a veteran +of the language, and so we will not go down that road. We will use +an expression separator just like in Erlang: the comma. We will +however allow a trailing comma to make copy pasting code easier, +even if this means some old academics guy will go nuts about it +later on. This trailing comma will be optional and simply discarded +by the parser when encountered. We will implement this next.</p></div> +<div class="paragraph"><p>The question as to how we will handle running expressions +remains. We have two choices here: we can write an interpreter, +or we can compile the code and run it. Writing an interpreter +would require us to do twice the work, and we are lazy, so we will +not do that.</p></div> +<div class="paragraph"><p>You might already know that Erlang does not use the same code +for compiling and for evaluating commands in the shell. The main +reason for this is that in Erlang everything isn’t an expression. +Indeed, the compiler compiles forms which contain expressions, +but you can’t have forms in the shell.</p></div> +<div class="paragraph"><p>How are we going to compile the code that isn’t part of a module +then? What do we need to run at compile-time, anyway? The body of +the file itself, of course. The body of module declarations. That’s +about it.</p></div> +<div class="paragraph"><p>For the file itself, we can simply compile it as a big function +that will be executed. Then, everytime we encounter a module +declaration, we will run the compiler on its body, making its body +essentially a big function that will be executed. The same mechanism +will be applied when we encounter a module declaration at runtime.</p></div> +<div class="paragraph"><p>At runtime there’s nothing else for us to do, the result of this +operation will load all the compiled modules. At compile time we +will also want to save them to a file. We’ll see later how we can +do that.</p></div> +<div class="ulist"><ul> +<li> +<p> +<a href="https://github.com/extend/xerl/blob/0.3/">View the source</a> +</p> +</li> +</ul></div> </article> </div> @@ -229,55 +229,107 @@ do that.</p></div> <h3>More articles</h3> <ul id="articles-nav" class="extra_margin"> - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + - <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + + <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + - <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + + <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + - <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + + <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + - <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + + <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + - <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + + <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + - <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + + <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + - <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + + <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + - <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + + <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + - <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + + <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + - <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + + <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + + + </ul> diff --git a/articles/xerl-0.4-expression-separator/index.html b/articles/xerl-0.4-expression-separator/index.html index 4bf4a3e8..75298905 100644 --- a/articles/xerl-0.4-expression-separator/index.html +++ b/articles/xerl-0.4-expression-separator/index.html @@ -7,7 +7,7 @@ <meta name="description" content=""> <meta name="author" content="Loïc Hoguin based on a design from (Soft10) Pol Cámara"> - <meta name="generator" content="Hugo 0.17" /> + <meta name="generator" content="Hugo 0.26" /> <title>Nine Nines: Xerl: expression separator</title> @@ -74,58 +74,58 @@ </p> </header> -<div class="paragraph"><p>As promised we are adding an expression separator this time.
-This will be short and easy.</p></div>
-<div class="paragraph"><p>In the tokenizer we only need to add a line recognizing the
-comma as a valid token.</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt>, <span style="color: #990000">:</span> {<span style="color: #FF6600">token</span>, {<span style="color: #FF6600">','</span>, <span style="color: #009900">TokenLine</span>}}<span style="color: #990000">.</span></tt></pre></div></div>
-<div class="paragraph"><p>Then we need to change the following lines in the parser:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="color: #FF6600">exprs</span> <span style="color: #990000">-></span> <span style="color: #FF6600">expr</span> <span style="color: #990000">:</span> [<span style="color: #FF6600">'$1'</span>]<span style="color: #990000">.</span>
-<span style="color: #FF6600">exprs</span> <span style="color: #990000">-></span> <span style="color: #FF6600">expr</span> <span style="color: #FF6600">exprs</span> <span style="color: #990000">:</span> [<span style="color: #FF6600">'$1'</span> | <span style="color: #FF6600">'$2'</span>]<span style="color: #990000">.</span></tt></pre></div></div>
-<div class="paragraph"><p>And add a comma between the expressions on the second line:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="color: #FF6600">exprs</span> <span style="color: #990000">-></span> <span style="color: #FF6600">expr</span> <span style="color: #990000">:</span> [<span style="color: #FF6600">'$1'</span>]<span style="color: #990000">.</span>
-<span style="color: #FF6600">exprs</span> <span style="color: #990000">-></span> <span style="color: #FF6600">expr</span> <span style="color: #FF6600">','</span> <span style="color: #FF6600">exprs</span> <span style="color: #990000">:</span> [<span style="color: #FF6600">'$1'</span> | <span style="color: #FF6600">'$3'</span>]<span style="color: #990000">.</span></tt></pre></div></div>
-<div class="paragraph"><p>That takes care of everything except the optional trailing
-comma at the end of our lists of expressions. We just need an
-additional rule to take care of this.</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="color: #FF6600">exprs</span> <span style="color: #990000">-></span> <span style="color: #FF6600">expr</span> <span style="color: #FF6600">','</span> <span style="color: #990000">:</span> [<span style="color: #FF6600">'$1'</span>]<span style="color: #990000">.</span></tt></pre></div></div>
-<div class="paragraph"><p>That’s it.</p></div>
-<div class="paragraph"><p>Wondering why we don’t have this optional trailing comma in
-Erlang considering how easy it was and the number of people
-complaining about it? Yeah, me too. But that’s for someone else
-to answer.</p></div>
-<div class="paragraph"><p>Another change I want to talk about is a simple modification
-of the compiler code to use an <code>#env{}</code> record for
-tracking state instead of passing around individual variables.
-This will be required later on when we make modules into proper
-expressions so I thought it was a good idea to anticipate.</p></div>
-<div class="ulist"><ul>
-<li>
-<p>
-<a href="https://github.com/extend/xerl/blob/0.4/">View the source</a>
-</p>
-</li>
-</ul></div>
+<div class="paragraph"><p>As promised we are adding an expression separator this time. +This will be short and easy.</p></div> +<div class="paragraph"><p>In the tokenizer we only need to add a line recognizing the +comma as a valid token.</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt>, <span style="color: #990000">:</span> {<span style="color: #FF6600">token</span>, {<span style="color: #FF6600">','</span>, <span style="color: #009900">TokenLine</span>}}<span style="color: #990000">.</span></tt></pre></div></div> +<div class="paragraph"><p>Then we need to change the following lines in the parser:</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="color: #FF6600">exprs</span> <span style="color: #990000">-></span> <span style="color: #FF6600">expr</span> <span style="color: #990000">:</span> [<span style="color: #FF6600">'$1'</span>]<span style="color: #990000">.</span> +<span style="color: #FF6600">exprs</span> <span style="color: #990000">-></span> <span style="color: #FF6600">expr</span> <span style="color: #FF6600">exprs</span> <span style="color: #990000">:</span> [<span style="color: #FF6600">'$1'</span> | <span style="color: #FF6600">'$2'</span>]<span style="color: #990000">.</span></tt></pre></div></div> +<div class="paragraph"><p>And add a comma between the expressions on the second line:</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="color: #FF6600">exprs</span> <span style="color: #990000">-></span> <span style="color: #FF6600">expr</span> <span style="color: #990000">:</span> [<span style="color: #FF6600">'$1'</span>]<span style="color: #990000">.</span> +<span style="color: #FF6600">exprs</span> <span style="color: #990000">-></span> <span style="color: #FF6600">expr</span> <span style="color: #FF6600">','</span> <span style="color: #FF6600">exprs</span> <span style="color: #990000">:</span> [<span style="color: #FF6600">'$1'</span> | <span style="color: #FF6600">'$3'</span>]<span style="color: #990000">.</span></tt></pre></div></div> +<div class="paragraph"><p>That takes care of everything except the optional trailing +comma at the end of our lists of expressions. We just need an +additional rule to take care of this.</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="color: #FF6600">exprs</span> <span style="color: #990000">-></span> <span style="color: #FF6600">expr</span> <span style="color: #FF6600">','</span> <span style="color: #990000">:</span> [<span style="color: #FF6600">'$1'</span>]<span style="color: #990000">.</span></tt></pre></div></div> +<div class="paragraph"><p>That’s it.</p></div> +<div class="paragraph"><p>Wondering why we don’t have this optional trailing comma in +Erlang considering how easy it was and the number of people +complaining about it? Yeah, me too. But that’s for someone else +to answer.</p></div> +<div class="paragraph"><p>Another change I want to talk about is a simple modification +of the compiler code to use an <code>#env{}</code> record for +tracking state instead of passing around individual variables. +This will be required later on when we make modules into proper +expressions so I thought it was a good idea to anticipate.</p></div> +<div class="ulist"><ul> +<li> +<p> +<a href="https://github.com/extend/xerl/blob/0.4/">View the source</a> +</p> +</li> +</ul></div> </article> </div> @@ -134,55 +134,107 @@ expressions so I thought it was a good idea to anticipate.</p></div> <h3>More articles</h3> <ul id="articles-nav" class="extra_margin"> - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + - <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + + <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + - <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + + <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + - <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + + <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + - <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + + <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + - <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + + <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + - <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + + <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + - <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + + <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + - <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + + <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + - <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + + <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + - <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + + <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + + + </ul> diff --git a/articles/xerl-0.5-intermediate-module/index.html b/articles/xerl-0.5-intermediate-module/index.html index dc9f2a2a..38627277 100644 --- a/articles/xerl-0.5-intermediate-module/index.html +++ b/articles/xerl-0.5-intermediate-module/index.html @@ -7,7 +7,7 @@ <meta name="description" content=""> <meta name="author" content="Loïc Hoguin based on a design from (Soft10) Pol Cámara"> - <meta name="generator" content="Hugo 0.17" /> + <meta name="generator" content="Hugo 0.26" /> <title>Nine Nines: Xerl: intermediate module</title> @@ -74,136 +74,136 @@ </p> </header> -<div class="paragraph"><p>Today we will start the work on the intermediate module
-that will be used to run the code for the expressions found
-in our file’s body, replacing our interpreter.</p></div>
-<div class="paragraph"><p>This is what we want to have when all the work is done:</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><code>xerl -> tokens -> AST -> intermediate -> cerl</code></pre>
-</div></div>
-<div class="paragraph"><p>Today we will perform this work only on the atomic integer
-expression however, so we will not build any module at the end.
-We have a few more things to take care of before getting there.
-This does mean that we completely break compilation of modules
-though, so hopefully we can resolve that soon.</p></div>
-<div class="paragraph"><p>This intermediate representation is in the form of a module
-which contains a single function: <code>run/0</code>. This function
-contains all the expressions from our Xerl source file.</p></div>
-<div class="paragraph"><p>In the case of a Xerl source file only containing the integer
-<code>42</code>, we will obtain the following module ready to
-be executed:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="font-weight: bold"><span style="color: #000080">-module</span></span>(<span style="color: #FF6600">'$xerl_intermediate'</span>)<span style="color: #990000">.</span>
-<span style="font-weight: bold"><span style="color: #000080">-export</span></span>([<span style="font-weight: bold"><span style="color: #000000">run</span></span><span style="color: #990000">/</span><span style="color: #993399">0</span>])<span style="color: #990000">.</span>
-
-<span style="font-weight: bold"><span style="color: #000000">run</span></span>() <span style="color: #990000">-></span>
- <span style="color: #993399">42</span><span style="color: #990000">.</span></tt></pre></div></div>
-<div class="paragraph"><p>Running it will of course give us a result of <code>42</code>,
-the same we had when interpreting expressions.</p></div>
-<div class="paragraph"><p>The resulting Core Erlang code looks like this:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="color: #FF6600">module</span> <span style="color: #FF6600">'$xerl_intermediate'</span> [<span style="color: #FF6600">'run'</span><span style="color: #990000">/</span><span style="color: #993399">0</span>]
- <span style="color: #FF6600">attributes</span> []
-<span style="color: #FF6600">'run'</span><span style="color: #990000">/</span><span style="color: #993399">0</span> <span style="color: #990000">=</span>
- <span style="font-weight: bold"><span style="color: #0000FF">fun</span></span> () <span style="color: #990000">-></span>
- <span style="color: #993399">42</span>
-<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
-<div class="paragraph"><p>The nice thing about doing it like this is that other than the
-definition of the intermediate module and its <code>run/0</code>
-function, we can use the same code we are using for generating
-the final Beam file. It may also be faster than interpreting
-if you have complex modules.</p></div>
-<div class="paragraph"><p>Of course this here only works for the simplest cases, as you
-cannot declare a module or a function inside another Erlang function.
-We will need to wrap these into function calls to the Xerl compiler
-that will take care of compiling them, making them available for
-any subsequent expression. We will also need to pass the environment
-to the <code>run</code> function to keep track of all this.</p></div>
-<div class="paragraph"><p>This does mean that we will have different code for compiling
-<code>fun</code> and <code>mod</code> expressions when creating
-the intermediate module. But the many other expressions don’t need
-any special care.</p></div>
-<div class="paragraph"><p>Right now we’ve used the <code>'$xerl_intermediate'</code> atom
-for the intermediate module name because we only have one, but we
-will need to have a more random name later on when we’ll implement
-modules this way.</p></div>
-<div class="paragraph"><p>The attentive mind will know by now that when compiling a Xerl
-file containing one module, we will need to compile two intermediate
-modules: one for the file body, and one for the module’s body. Worry
-not though, if we only detect <code>mod</code> instructions in the file
-body, we can just skip this phase.</p></div>
-<div class="paragraph"><p>While we’re at it, we’ll modify our code generator to handle lists
-of expressions, which didn’t actually work with integer literals
-before.</p></div>
-<div class="paragraph"><p>We’re going to use Core Erlang sequences for running the many
-expressions. Sequences work like <code>let</code>, except no value
-is actually bound. Perfect for our case, since we don’t support
-binding values at this time anyway.</p></div>
-<div class="paragraph"><p>Sequences have an argument and a body, both being Core Erlang
-expressions. The simplest way to have many expressions is to use
-a simple expression for the argument and a sequence for the rest
-of the expressions. When we encounter the last expression in the
-list, we do not create a sequence.</p></div>
-<div class="paragraph"><p>The result is this very simple function:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="font-weight: bold"><span style="color: #000000">comp_body</span></span>([<span style="color: #009900">Expr</span>]) <span style="color: #990000">-></span>
- <span style="font-weight: bold"><span style="color: #000000">expr</span></span>(<span style="color: #009900">Expr</span>);
-<span style="font-weight: bold"><span style="color: #000000">comp_body</span></span>([<span style="color: #009900">Expr</span>|<span style="color: #009900">Exprs</span>]) <span style="color: #990000">-></span>
- <span style="color: #009900">Arg</span> <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">expr</span></span>(<span style="color: #009900">Expr</span>),
- <span style="color: #009900">Body</span> <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">comp_body</span></span>(<span style="color: #009900">Exprs</span>),
- <span style="font-weight: bold"><span style="color: #000000">cerl:c_seq</span></span>(<span style="color: #009900">Arg</span>, <span style="color: #009900">Body</span>)<span style="color: #990000">.</span></tt></pre></div></div>
-<div class="paragraph"><p>In the case of our example above, a sequence will not be created,
-we only have one expression. If we were to have <code>42, 43, 44</code>
-in our Xerl source file, we would have a result equivalent to the
-following before optimization:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="font-weight: bold"><span style="color: #000080">-module</span></span>(<span style="color: #FF6600">'$xerl_intermediate'</span>)<span style="color: #990000">.</span>
-<span style="font-weight: bold"><span style="color: #000080">-export</span></span>([<span style="font-weight: bold"><span style="color: #000000">run</span></span><span style="color: #990000">/</span><span style="color: #993399">0</span>])<span style="color: #990000">.</span>
-
-<span style="font-weight: bold"><span style="color: #000000">run</span></span>() <span style="color: #990000">-></span>
- <span style="color: #993399">42</span>,
- <span style="color: #993399">43</span>,
- <span style="color: #993399">44</span><span style="color: #990000">.</span></tt></pre></div></div>
-<div class="paragraph"><p>And the result is of course <code>44</code>.</p></div>
-<div class="paragraph"><p>The resulting Core Erlang code looks like this:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="color: #FF6600">module</span> <span style="color: #FF6600">'$xerl_intermediate'</span> [<span style="color: #FF6600">'run'</span><span style="color: #990000">/</span><span style="color: #993399">0</span>]
- <span style="color: #FF6600">attributes</span> []
-<span style="color: #FF6600">'run'</span><span style="color: #990000">/</span><span style="color: #993399">0</span> <span style="color: #990000">=</span>
- <span style="font-weight: bold"><span style="color: #0000FF">fun</span></span> () <span style="color: #990000">-></span>
- <span style="color: #FF6600">do</span> <span style="color: #993399">42</span>
- <span style="color: #FF6600">do</span> <span style="color: #993399">43</span>
- <span style="color: #993399">44</span>
-<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
-<div class="paragraph"><p>Feels very lisp-y, right? Yep.</p></div>
-<div class="ulist"><ul>
-<li>
-<p>
-<a href="https://github.com/extend/xerl/blob/0.5/">View the source</a>
-</p>
-</li>
-</ul></div>
+<div class="paragraph"><p>Today we will start the work on the intermediate module +that will be used to run the code for the expressions found +in our file’s body, replacing our interpreter.</p></div> +<div class="paragraph"><p>This is what we want to have when all the work is done:</p></div> +<div class="listingblock"> +<div class="content"> +<pre><code>xerl -> tokens -> AST -> intermediate -> cerl</code></pre> +</div></div> +<div class="paragraph"><p>Today we will perform this work only on the atomic integer +expression however, so we will not build any module at the end. +We have a few more things to take care of before getting there. +This does mean that we completely break compilation of modules +though, so hopefully we can resolve that soon.</p></div> +<div class="paragraph"><p>This intermediate representation is in the form of a module +which contains a single function: <code>run/0</code>. This function +contains all the expressions from our Xerl source file.</p></div> +<div class="paragraph"><p>In the case of a Xerl source file only containing the integer +<code>42</code>, we will obtain the following module ready to +be executed:</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="font-weight: bold"><span style="color: #000080">-module</span></span>(<span style="color: #FF6600">'$xerl_intermediate'</span>)<span style="color: #990000">.</span> +<span style="font-weight: bold"><span style="color: #000080">-export</span></span>([<span style="font-weight: bold"><span style="color: #000000">run</span></span><span style="color: #990000">/</span><span style="color: #993399">0</span>])<span style="color: #990000">.</span> + +<span style="font-weight: bold"><span style="color: #000000">run</span></span>() <span style="color: #990000">-></span> + <span style="color: #993399">42</span><span style="color: #990000">.</span></tt></pre></div></div> +<div class="paragraph"><p>Running it will of course give us a result of <code>42</code>, +the same we had when interpreting expressions.</p></div> +<div class="paragraph"><p>The resulting Core Erlang code looks like this:</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="color: #FF6600">module</span> <span style="color: #FF6600">'$xerl_intermediate'</span> [<span style="color: #FF6600">'run'</span><span style="color: #990000">/</span><span style="color: #993399">0</span>] + <span style="color: #FF6600">attributes</span> [] +<span style="color: #FF6600">'run'</span><span style="color: #990000">/</span><span style="color: #993399">0</span> <span style="color: #990000">=</span> + <span style="font-weight: bold"><span style="color: #0000FF">fun</span></span> () <span style="color: #990000">-></span> + <span style="color: #993399">42</span> +<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div> +<div class="paragraph"><p>The nice thing about doing it like this is that other than the +definition of the intermediate module and its <code>run/0</code> +function, we can use the same code we are using for generating +the final Beam file. It may also be faster than interpreting +if you have complex modules.</p></div> +<div class="paragraph"><p>Of course this here only works for the simplest cases, as you +cannot declare a module or a function inside another Erlang function. +We will need to wrap these into function calls to the Xerl compiler +that will take care of compiling them, making them available for +any subsequent expression. We will also need to pass the environment +to the <code>run</code> function to keep track of all this.</p></div> +<div class="paragraph"><p>This does mean that we will have different code for compiling +<code>fun</code> and <code>mod</code> expressions when creating +the intermediate module. But the many other expressions don’t need +any special care.</p></div> +<div class="paragraph"><p>Right now we’ve used the <code>'$xerl_intermediate'</code> atom +for the intermediate module name because we only have one, but we +will need to have a more random name later on when we’ll implement +modules this way.</p></div> +<div class="paragraph"><p>The attentive mind will know by now that when compiling a Xerl +file containing one module, we will need to compile two intermediate +modules: one for the file body, and one for the module’s body. Worry +not though, if we only detect <code>mod</code> instructions in the file +body, we can just skip this phase.</p></div> +<div class="paragraph"><p>While we’re at it, we’ll modify our code generator to handle lists +of expressions, which didn’t actually work with integer literals +before.</p></div> +<div class="paragraph"><p>We’re going to use Core Erlang sequences for running the many +expressions. Sequences work like <code>let</code>, except no value +is actually bound. Perfect for our case, since we don’t support +binding values at this time anyway.</p></div> +<div class="paragraph"><p>Sequences have an argument and a body, both being Core Erlang +expressions. The simplest way to have many expressions is to use +a simple expression for the argument and a sequence for the rest +of the expressions. When we encounter the last expression in the +list, we do not create a sequence.</p></div> +<div class="paragraph"><p>The result is this very simple function:</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="font-weight: bold"><span style="color: #000000">comp_body</span></span>([<span style="color: #009900">Expr</span>]) <span style="color: #990000">-></span> + <span style="font-weight: bold"><span style="color: #000000">expr</span></span>(<span style="color: #009900">Expr</span>); +<span style="font-weight: bold"><span style="color: #000000">comp_body</span></span>([<span style="color: #009900">Expr</span>|<span style="color: #009900">Exprs</span>]) <span style="color: #990000">-></span> + <span style="color: #009900">Arg</span> <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">expr</span></span>(<span style="color: #009900">Expr</span>), + <span style="color: #009900">Body</span> <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">comp_body</span></span>(<span style="color: #009900">Exprs</span>), + <span style="font-weight: bold"><span style="color: #000000">cerl:c_seq</span></span>(<span style="color: #009900">Arg</span>, <span style="color: #009900">Body</span>)<span style="color: #990000">.</span></tt></pre></div></div> +<div class="paragraph"><p>In the case of our example above, a sequence will not be created, +we only have one expression. If we were to have <code>42, 43, 44</code> +in our Xerl source file, we would have a result equivalent to the +following before optimization:</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="font-weight: bold"><span style="color: #000080">-module</span></span>(<span style="color: #FF6600">'$xerl_intermediate'</span>)<span style="color: #990000">.</span> +<span style="font-weight: bold"><span style="color: #000080">-export</span></span>([<span style="font-weight: bold"><span style="color: #000000">run</span></span><span style="color: #990000">/</span><span style="color: #993399">0</span>])<span style="color: #990000">.</span> + +<span style="font-weight: bold"><span style="color: #000000">run</span></span>() <span style="color: #990000">-></span> + <span style="color: #993399">42</span>, + <span style="color: #993399">43</span>, + <span style="color: #993399">44</span><span style="color: #990000">.</span></tt></pre></div></div> +<div class="paragraph"><p>And the result is of course <code>44</code>.</p></div> +<div class="paragraph"><p>The resulting Core Erlang code looks like this:</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.8 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt><span style="color: #FF6600">module</span> <span style="color: #FF6600">'$xerl_intermediate'</span> [<span style="color: #FF6600">'run'</span><span style="color: #990000">/</span><span style="color: #993399">0</span>] + <span style="color: #FF6600">attributes</span> [] +<span style="color: #FF6600">'run'</span><span style="color: #990000">/</span><span style="color: #993399">0</span> <span style="color: #990000">=</span> + <span style="font-weight: bold"><span style="color: #0000FF">fun</span></span> () <span style="color: #990000">-></span> + <span style="color: #FF6600">do</span> <span style="color: #993399">42</span> + <span style="color: #FF6600">do</span> <span style="color: #993399">43</span> + <span style="color: #993399">44</span> +<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div> +<div class="paragraph"><p>Feels very lisp-y, right? Yep.</p></div> +<div class="ulist"><ul> +<li> +<p> +<a href="https://github.com/extend/xerl/blob/0.5/">View the source</a> +</p> +</li> +</ul></div> </article> </div> @@ -212,55 +212,107 @@ http://www.gnu.org/software/src-highlite --> <h3>More articles</h3> <ul id="articles-nav" class="extra_margin"> - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li> + + + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li> + + <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + - <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li> + + <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + - <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don't let it crash</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li> + + <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + - <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li> + + <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + - <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li> + + <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + - <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li> + + <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + - <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li> + + <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + - <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li> + + <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + - <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li> + + <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + - <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li> + + <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + - <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li> + + <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + - <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li> + + <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + - <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li> + + <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + - <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li> + + <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + - <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li> + + <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + - <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li> + </ul> |