<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>elixir Archives | Programming Zen</title>
	<atom:link href="https://programmingzen.com/tag/elixir/feed/" rel="self" type="application/rss+xml" />
	<link>https://programmingzen.com/tag/elixir/</link>
	<description>Meditations on programming, startups, and technology</description>
	<lastBuildDate>Sat, 09 May 2020 04:08:22 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
<site xmlns="com-wordpress:feed-additions:1">1397766</site>	<item>
		<title>Removing Duplicates From a List in Elixir</title>
		<link>https://programmingzen.com/remove-duplicates-from-list-elixir/</link>
					<comments>https://programmingzen.com/remove-duplicates-from-list-elixir/#comments</comments>
		
		<dc:creator><![CDATA[Antonio Cangiano]]></dc:creator>
		<pubDate>Thu, 07 May 2020 04:27:39 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[elixir]]></category>
		<category><![CDATA[elixir-cookbook]]></category>
		<category><![CDATA[Enum]]></category>
		<category><![CDATA[List]]></category>
		<category><![CDATA[recursion]]></category>
		<category><![CDATA[tips]]></category>
		<guid isPermaLink="false">https://programmingzen.com/?p=2486</guid>

					<description><![CDATA[<p>Thanks to the Enum module, in Elixir we can trivially remove duplicates from a list. In the following example, we take a list of integers and pass it to the Enum.uniq/1 function which removes duplicates from the list without altering the original order of the remaining elements. If you are trying to only remove consecutive duplicate elements, then there is Enum.dedup/1: (Note: We append /1 simply as a notation indicating the arity of a function, that is how many arguments it accepts. my_func/1 accepts one argument, my_func/2 two, and so on.) Enum is full of helpful functions when working with </p>
<p>The post <a href="https://programmingzen.com/remove-duplicates-from-list-elixir/">Removing Duplicates From a List in Elixir</a> appeared first on <a href="https://programmingzen.com">Programming Zen</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Thanks to the <code>Enum</code> module, in Elixir we can trivially remove duplicates from a list.</p>



<p>In the following example, we take a list of integers and pass it to the <code>Enum.uniq/1</code> function which removes duplicates from the list without altering the original order of the remaining elements.</p>



<pre class="wp-block-code"><code>list = &#91;1, 2, 2, 3, 3, 1, 2, 4]
Enum.uniq(list) # Returns &#91;1, 2, 3, 4]</code></pre>



<p>If you are trying to only remove consecutive duplicate elements, then there is <code>Enum.dedup/1</code>:</p>



<pre class="wp-block-code"><code>list = &#91;1, 2, 2, 3, 3, 1, 2, 4]
Enum.dedup(list) # Returns &#91;1, 2, 3, 1, 2, 4]</code></pre>



<p>(Note: We append <code>/1</code> simply as a notation indicating the <em>arity</em> of a function, that is how many arguments it accepts. <code>my_func/1</code> accepts one argument, <code>my_func/2</code> two, and so on.)</p>



<p><a rel="noreferrer noopener" href="https://hexdocs.pm/elixir/Enum.html" target="_blank">Enum is full of helpful functions</a> when working with collection data types that implement the <code>Enumerable</code> protocol (e.g., lists, maps, ranges, streams, etc.) and it&#8217;s worth getting acquainted with.</p>



<h2 class="wp-block-heading">Removing duplicates using recursion</h2>



<p>Alright, Elixir does the heavy lifting for us in this case, but how would we go about removing duplicates from a list in Elixir without using <code>Enum.uniq/1</code>? I mean from scratch, simply using recursion without relying on <code>Enum</code>, sets, <code>:lists.usort/1</code>, etc. </p>



<p>It is worth asking such a question to both exercise our recursion muscle (something that doesn&#8217;t come naturally to most programmers) and so that we&#8217;re ready to handle conceptually similar problems that do not have pre-made functions but could benefit from a recursive solution.</p>



<p>There are likely a few ways to implement this, but this what sprang to mind when I thought about it:</p>



<pre class="wp-block-code"><code>defmodule MyList do
  def uniq(&#91;]), do: &#91;]

  def uniq(&#91;head | tail]) do
    &#91;head | for(x &lt;- uniq(tail), x != head, do: x)]
  end
end</code></pre>



<p>Calling <code>MyList.uniq(list)</code> will then return the same list without duplicates as <code>Enum.uniq(list)</code>did. (Although, it&#8217;s worth noting, that we implemented a <code>List</code>-specific version of the <code>uniq/1</code> function).</p>



<p>Let&#8217;s see how this works. If the list is empty (i.e., <code>[]</code>) we obviously return an empty list, as there is nothing to remove. This is our base case for the recursion.</p>



<p>If the list is not empty, it will have a head and a tail, and we use Elixir&#8217;s pattern matching to bind the first element of the list passed to the function to <code>head</code> and the rest of the elements to the list <code>tail</code>. </p>



<p>Note that a proper list with a single element will simply have an empty list as its tail. So writing <code>[3]</code> is equivalent to writing <code>[3|[]]</code> where <code>3</code> is the head, <code>[]</code> is the tail, and <code>|</code> is the cons operator (short for constructor operator, as it&#8217;s used to construct lists).</p>



<p>So far so good. Here is where things get a little trickier. Let&#8217;s analyze this line:</p>



<pre class="wp-block-code"><code>    &#91;head | for(x &lt;- uniq(tail), x != head, do: x)]</code></pre>



<p>The code is wrapped in square brackets <code>[...]</code>which means that we are returning a list. Then you&#8217;ll notice the <code>|</code> <em>cons</em> operator. So we are constructing a list that has <code>head</code> as its first element and whatever the rest of that line of code does, as its tail.</p>



<p>This makes sense if you think about it. Sure, the list might have duplicates, but the first element will always be included. If a duplicate of the first element exists, that&#8217;s the one that is going to be removed and not the first element.</p>



<p>So we are building a list and the first element of the original list is also the first element of our deduplicated list. What goes into the rest of the list?</p>



<h3 class="wp-block-heading">Comprehensions</h3>



<p>We see a <code>for</code>. Unlike many programming languages, <code>for</code> is not a loop keyword in Elixir. Rather, it is used for comprehensions (a form of syntax sugar to generate lists from existing collections). Syntax, which is not too different from mathematical notation.</p>



<p>Here is a simple example of how to use them:</p>



<pre class="wp-block-code"><code>for x &lt;- &#91;1, 2, 3, 4], do: x + x # Returns &#91;2, 4, 6, 8]</code></pre>



<p>&#8220;For each element <code>x</code> in <code>[1, 2, 3, 4]</code> do <code>x + x</code> and put the result in a list.&#8221;</p>



<p>It also accepts filters, which allows us to specify a condition:</p>



<pre class="wp-block-code"><code>for x &lt;- &#91;1, 2, 3, 4], x &lt; 3, do: x + x # Returns &#91;2, 4]</code></pre>



<p>In this example, the condition is that <code>x</code> is smaller than <code>3</code>, so only the first two elements, which are lesser than <code>3</code>, get doubled and added to the resulting list.</p>



<h3 class="wp-block-heading">Recursing our way to the base case</h3>



<p>OK, back to our &#8220;cryptic&#8221; line:</p>



<pre class="wp-block-code"><code>    &#91;head | for(x &lt;- uniq(tail), x != head, do: x)]</code></pre>



<p><code>head</code> is our first element and then we are using a comprehension to generate a list without duplicates.</p>



<p>We are saying, for each <code>x</code> in a deduplicated <code>tail</code>, add <code>x</code> to the list if it&#8217;s different from our first element <code>head</code>.</p>



<p>The part that gets people weirded out about is recursively calling <code>uniq(tail)</code>. We can get away with this because we have a base case that ensures we don&#8217;t recurse forever.  </p>



<p>At each call of <code>uniq(tail)</code> we are making the tail shorter by one element. </p>



<p>For example, executing <code>MyList.uniq([1, 2, 3, 3])</code> will make the following recursive calls:</p>



<ul class="wp-block-list"><li><code>MyList.uniq([1, 2, 3, 3])</code></li><li><code>MyList.uniq([2, 3, 3])</code></li><li><code>MyList.uniq([3, 3])</code></li><li><code>MyList.uniq([3])</code></li><li><code>MyList.uniq([])</code></li></ul>



<p>When we eventually get to the tail being <code>[]</code>, which is our base case,<code>[]</code> is returned and <code>MyList.uniq/1</code> is no longer called.</p>



<p>Recursion can be hard to grasp at first, but it&#8217;s a powerful tool and a staple of functional programming, so it&#8217;s well worth practicing.</p>



<p>As pointed out in the comment section, this implementation is quite illustrative but not very efficient. In production, you&#8217;d want to opt for the built-in functions or implement a tail-recursive version that leverages <code><a rel="noreferrer noopener" href="https://hexdocs.pm/elixir/MapSet.html" target="_blank">MapSet</a></code>. And although tail recursion is faster in this case, it&#8217;s worth noting that even that is <a href="http://erlang.org/doc/efficiency_guide/myths.html" target="_blank" rel="noreferrer noopener">not a silver bullet</a>.</p>
<p>The post <a href="https://programmingzen.com/remove-duplicates-from-list-elixir/">Removing Duplicates From a List in Elixir</a> appeared first on <a href="https://programmingzen.com">Programming Zen</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://programmingzen.com/remove-duplicates-from-list-elixir/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2486</post-id>	</item>
		<item>
		<title>Specify a Port when Booting a Phoenix Application</title>
		<link>https://programmingzen.com/specify-a-port-when-booting-a-phoenix-app/</link>
					<comments>https://programmingzen.com/specify-a-port-when-booting-a-phoenix-app/#comments</comments>
		
		<dc:creator><![CDATA[Antonio Cangiano]]></dc:creator>
		<pubDate>Mon, 04 May 2020 00:16:48 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[cowboy]]></category>
		<category><![CDATA[elixir]]></category>
		<category><![CDATA[elixir-cookbook]]></category>
		<category><![CDATA[phoenix]]></category>
		<category><![CDATA[port]]></category>
		<category><![CDATA[sever]]></category>
		<category><![CDATA[tips]]></category>
		<guid isPermaLink="false">https://programmingzen.com/?p=2474</guid>

					<description><![CDATA[<p>When developing a Phoenix application, you&#8217;ll boot the server with: mix phx.server. This will start Cowboy in development mode, which by default accepts connections on port 4000. But how do you specify a different port? In Phoenix, there is no -P or -p option. You&#8217;ll need to edit your config/dev.exs configuration file to change the host key as follows: System.get_env(&#34;PORT&#34;, &#34;4000&#34;) retrieves the value of the PORT environment variable if one has been set. If the environment doesn&#8217;t have the specified variable (i.e., PORT), it will default to 4000. You can then boot your Phoenix server by passing the variable </p>
<p>The post <a href="https://programmingzen.com/specify-a-port-when-booting-a-phoenix-app/">Specify a Port when Booting a Phoenix Application</a> appeared first on <a href="https://programmingzen.com">Programming Zen</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>When developing a Phoenix application, you&#8217;ll boot the server with: <code>mix phx.server</code>. This will start Cowboy in development mode, which by default accepts connections on port <code>4000</code>. But how do you specify a different port? In Phoenix, there is no <code>-P</code> or <code>-p</code> option.</p>



<p>You&#8217;ll need to edit your <code>config/dev.exs</code> configuration file to change the <code>host</code> key as follows:</p>



<pre class="wp-block-code"><code>http: &#91;port: System.get_env("PORT", "4000")],</code></pre>



<p><code>System.get_env("PORT", "4000")</code> retrieves the value of the <code>PORT</code> environment variable if one has been set. If the environment doesn&#8217;t have the specified variable (i.e., <code>PORT</code>), it will default to <code>4000</code>.</p>



<p>You can then boot your Phoenix server by passing the variable value to the command as follows:</p>



<pre class="wp-block-code"><code>$ PORT=5000 mix phx.server</code></pre>



<p>This will run the server on the port you specified, in this example <code>5000</code>.</p>



<p>The name of the environment variable is arbitrary. We used <code style="font-size: 16px;">PORT</code> but we could have opted for <code style="font-size: 16px;">PHX_PORT</code> or something else altogether. Just so long as your configuration file and environment use the same name.</p>



<p>You can, of course, set the environment variable outside of the <code>mix phx.server</code> command, for example in your shell profile.</p>
<p>The post <a href="https://programmingzen.com/specify-a-port-when-booting-a-phoenix-app/">Specify a Port when Booting a Phoenix Application</a> appeared first on <a href="https://programmingzen.com">Programming Zen</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://programmingzen.com/specify-a-port-when-booting-a-phoenix-app/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2474</post-id>	</item>
		<item>
		<title>Developing with Elixir/OTP Course Review</title>
		<link>https://programmingzen.com/developing-with-elixir-otp-course-review/</link>
					<comments>https://programmingzen.com/developing-with-elixir-otp-course-review/#comments</comments>
		
		<dc:creator><![CDATA[Antonio Cangiano]]></dc:creator>
		<pubDate>Thu, 30 Apr 2020 04:01:22 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Reviews]]></category>
		<category><![CDATA[elixir]]></category>
		<category><![CDATA[erlang]]></category>
		<category><![CDATA[online courses]]></category>
		<category><![CDATA[OTP]]></category>
		<category><![CDATA[pragmaticstudio]]></category>
		<category><![CDATA[review]]></category>
		<category><![CDATA[Ruby]]></category>
		<guid isPermaLink="false">https://programmingzen.com/?p=2457</guid>

					<description><![CDATA[<p>Ruby was the first programming language I truly fell in love with. Yes, I had used several others before (and have since), but Ruby was and still is something dear to me. I can appreciate the usefulness of Python, the simplicity of Go, and the mind-expanding nature of Haskell. Yet, anything that isn&#x2019;t Ruby felt like a usability downgrade. It&#x2019;s all highly subjective, &#xE7;a va sans dire, but Ruby was always my favorite. It&#x2019;s not every day that a language comes along and genuinely excites me to the point of putting Ruby aside (within the scope of what it&#x2019;s great </p>
<p>The post <a href="https://programmingzen.com/developing-with-elixir-otp-course-review/">Developing with Elixir/OTP Course Review</a> appeared first on <a href="https://programmingzen.com">Programming Zen</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Ruby was the first programming language I truly fell in love with. Yes, I had used several others before (and have since), but Ruby was and still is something dear to me.</p>



<p>I can appreciate the usefulness of Python, the simplicity of Go, and the mind-expanding nature of Haskell. Yet, anything that isn&#8217;t Ruby felt like a usability downgrade. It&#8217;s all highly subjective, ça va sans dire, but Ruby was always my favorite.</p>



<p>It&#8217;s not every day that a language comes along and genuinely excites me to the point of putting Ruby aside (within the scope of what it&#8217;s great at doing).</p>



<h2 class="wp-block-heading">I &lt;3 Elixir</h2>



<p>That language is Elixir. I&#8217;ve been using it on and off for a few years now. I first <a href="https://programmingzen.com/next-programming-language/">talked about it</a> back in 2016 and even managed to convince my team at IBM to adopt it to an extent. It&#8217;s working out well for us so far and I have a hunch we might double down on it soon.</p>



<p>Since I have a little more time, due to being stuck inside, I&#8217;ve been on a &#8220;study anything in sight related to Elixir and Phoenix&#8221; kick lately.</p>



<p>I am a big fan of Mike and Nicole Clark of The Pragmatic Studio and in the past have highly <a href="https://programmingzen.com/rails-books/">recommended their Ruby and Rails courses</a>. So I decided to start taking their Elixir courses as well. In this post, I&#8217;ll give you a fairly detailed review of their largest course on the subject, <a rel="noreferrer noopener" href="https://pragmaticstudio.com/elixir" target="_blank">Developing with Elixir/OTP</a>.</p>



<h2 class="wp-block-heading">Who is it for?</h2>



<figure class="wp-block-image size-full is-resized"><img data-recalc-dims="1" fetchpriority="high" decoding="async" src="https://i0.wp.com/programmingzen.com/wp-content/uploads/2020/04/developing-with-elixir-otp-review.png?resize=768%2C434&#038;ssl=1" alt="Developing with Elixir/OTP Course Review" class="wp-image-2460" width="768" height="434" srcset="https://i0.wp.com/programmingzen.com/wp-content/uploads/2020/04/developing-with-elixir-otp-review.png?w=1536&amp;ssl=1 1536w, https://i0.wp.com/programmingzen.com/wp-content/uploads/2020/04/developing-with-elixir-otp-review.png?resize=300%2C169&amp;ssl=1 300w, https://i0.wp.com/programmingzen.com/wp-content/uploads/2020/04/developing-with-elixir-otp-review.png?resize=1024%2C578&amp;ssl=1 1024w, https://i0.wp.com/programmingzen.com/wp-content/uploads/2020/04/developing-with-elixir-otp-review.png?resize=768%2C434&amp;ssl=1 768w" sizes="(max-width: 768px) 100vw, 768px" /></figure>



<p>Developing with Elixir/OTP is aimed at programmers. It&#8217;s so well explained that beginners can give it a shot, however, they are not the target audience.</p>



<p>The course assumes you have zero knowledge of Elixir itself but it&#8217;s not going to explain basic programming concepts when they are not novel or unique to Elixir.</p>



<p>Experience with Ruby is not required nor assumed, but it&#8217;s beneficial. This isn&#8217;t so much due to the way the course is presented (though there are a couple of nods to Ruby programmers). Rather, it&#8217;s the similarity (on the surface) between the two languages.</p>



<h2 class="wp-block-heading">How much time do you need to invest?</h2>



<p>Developing with Elixir/OTP is a 6.5 hour course divided across 30 modules. There is no way for you to take this course in 6.5 hours and get anything worthwhile from it.</p>



<p>In fact, the secret sauce is that each module has a Notes section dedicated to expanding on the topic, providing tips and tricks, as well as exercises.&nbsp;</p>



<p>I would estimate that it took me around 20 hours or so to finish, despite being very familiar with the subject matter. Mind you, I do like to experiment quite a bit within IEx to veer off the beaten path.</p>



<p>Estimate 30 hours of your time, an hour per module, if you intend to fully absorb and experiment with the material presented.</p>



<p>Unlike their Rails course, you won&#8217;t develop two applications (one while watching the videos and one in the Notes section). In this course, there is only one application that is mostly developed in the videos and then enhanced in the Notes through exercises.</p>



<p>This will save you a lot of time at the small expense of having to pause and resume the video to type along.</p>



<p>Another time-saver is that the code for each module in the course is provided so that you&#8217;re never lost. Particularly useful to copy and paste the more tedious parts (e.g., sample data and template code).</p>



<h2 class="wp-block-heading">What will you build?</h2>



<p>The course starts off by developing a simple web server. Think, high-level transformations of requests into responses. It builds it from the ground up and then layers a simple RESTful API for a fictitious wildlife reserve on top.</p>



<p>They start off with the simplest thing, a function that transforms one specific request into one specific response, and then move up all the way to actually serving the API over HTTP.</p>



<p>The goal, as often stated in the course, is not to replace an established and much more robust web server like Cowboy or a framework like Phoenix. At all.</p>



<p>Instead, it serves two pedagogical purposes. First, it teaches you how to use the language to solve a fairly complex problem. Second, it gives you a deeper understanding of how the production-ready tools you are going to adopt actually work within.</p>



<p>This approach is endemic to their teaching method. For example, they&#8217;ll develop a simple web server and API from scratch and then show you how similar it is to the equivalent Phoenix version. By the time you hit module 17 on Phoenix, you don&#8217;t quite know Phoenix but it should feel oddly familiar. After all, you built a naïve/simplified version of the same controllers, router, templates, etc. from scratch. This is, of course, a deliberate choice.</p>



<p>The same is true when they implement a simple GenServer from scratch and then are able to seamlessly replace it with the real deal (with <code>use GenServer</code>). Yes, you developed the Fisher-Price version of the production-ready tools, but you now understand how they work under the hood. All before Mike and Nicole proceed to teach you how to use the battle-tested ones.</p>



<p>I&#8217;m a fan of this didactic approach and I think it will serve most people well.</p>



<h2 class="wp-block-heading">What will you learn?</h2>



<p>It might be surprising to some but this course does not provide the typical tour of data types and data structures available in the language.</p>



<p>Instead, it uses the language to build something from the beginning and, in the process, it quickly exposes you to a variety of concepts, including how to use common data types.</p>



<p>It doesn&#8217;t cover them thoroughly, however, so reading the <a rel="noreferrer noopener" href="https://elixir-lang.org/getting-started/introduction.html" target="_blank">Elixir tutorial</a> on the official site would be very beneficial prior to or after taking this course.</p>



<p>The course starts off with several modules that are heavily focused on pattern matching. This is a good choice because pattern matching is one of the most valuable and pervasive features of Elixir.</p>



<p>As you would expect, there is also quite a bit of emphasis on immutable data structures, the pipe operator, recursion, and the Enum module.</p>



<p>In the process you&#8217;ll also learn a lot about IEx, Mix, organizing your code in a logical and idiomatic manner, defining Structs as the safer alternatives to maps, and comprehensions. </p>



<p>Testing is covered adequately but not extensively in its own module. Not in a TDD manner from the very start of the course like they did in some of their previous courses. This has, again, didactical advantages even if you choose to adopt TDD in your actual work.</p>



<p>In the second half of the course, things get a little more serious courtesy of OTP, delving deeper into working with sockets, the actor model, Task, GenServer, and linking and monitoring processes.</p>



<h2 class="wp-block-heading">Other points worth making</h2>



<p>In more or less random order:</p>



<ul class="wp-block-list"><li>The course is up to date to Elixir 1.10.x, somewhat rare among Elixir courses. Some of the videos show Mike and Nicole using a previous version (i.e., 1.5), but the Notes use the latest version and the rare differences are noted.  For example, the video shows the old <code>mix new</code> project format which included a <code>config</code> folder. In their hands-on notes for the video, they have a comprehensive &#8220;I don&#8217;t see a config directory&#8221; section to address it. You&#8217;re basically never lost or confused due to version discrepancies.</li><li>The overall quality is excellent. It&#8217;s a really polished product in terms of audio, video, text, and visuals used to aid in explaining the more conceptual parts.</li><li>They answer the overwhelming majority of your &#8220;wait a second&#8221; questions and objections. Either later in the video or right in the notes for that particular module. They genuinely anticipate most questions, which is the hallmark of a great course.</li><li>Most modules have a single 5-15 minute video, but some modules include two videos. So the modules are&#8230; well, modular.</li><li>Although this course will equip you to start studying Phoenix, it doesn&#8217;t really cover the subject. There is a module, as I mentioned, which is just enough to whet your appetite for the framework.</li><li>Erlang interoperability is at least in part addressed in module 20, where sample code from the documentation of <code>gen_tcp</code> is converted from Erlang to Elixir code.</li><li>The course is full of small tips like enabling command history in IEx (with <code>export ERL_AFLAGS="-kernel shell_history enabled"</code>), speeding up unit tests by making them asynchronous (i.e., <code>use ExUnit.Case, async: true</code>), using <code>flush()</code> to clear a process&#8217; mailbox, etc.</li></ul>



<h2 class="wp-block-heading">Is it worth the price?</h2>



<p>At $89, <a href="https://pragmaticstudio.com/elixir">Developing with Elixir/OTP</a> is not your average Udemy course that&#8217;s routinely discounted to $12. That&#8217;s because it&#8217;s not your average course.</p>



<p>If I had to rate it, I&#8217;d give it a 4.5 out of 5. I highly recommend it to working programmers who are interested in picking up Elixir quickly.</p>



<p>I would argue that it&#8217;s a great, current resource that is well worth the price of admission if you favor learning from videos.</p>
<p>The post <a href="https://programmingzen.com/developing-with-elixir-otp-course-review/">Developing with Elixir/OTP Course Review</a> appeared first on <a href="https://programmingzen.com">Programming Zen</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://programmingzen.com/developing-with-elixir-otp-course-review/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2457</post-id>	</item>
		<item>
		<title>String Length in Elixir</title>
		<link>https://programmingzen.com/string-length-in-elixir/</link>
					<comments>https://programmingzen.com/string-length-in-elixir/#comments</comments>
		
		<dc:creator><![CDATA[Antonio Cangiano]]></dc:creator>
		<pubDate>Mon, 14 Oct 2019 12:00:11 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[elixir]]></category>
		<category><![CDATA[elixir-cookbook]]></category>
		<category><![CDATA[standard library]]></category>
		<category><![CDATA[strings]]></category>
		<category><![CDATA[unicode]]></category>
		<guid isPermaLink="false">https://programmingzen.com/?p=2286</guid>

					<description><![CDATA[<p>In a previous post, I wrote about Hello World in Elixir. Using such a simple program allowed me to discuss a few concepts about the language. This post explores strings further, by discussing how to find the length of a string in Elixir. Simple enough, but there is more than meets the eye. Elixir String Length In Elixir, you can return the number of characters in a string with the String.length/1 function: String.length(&#34;Antonio&#34;) # 7 String.length(&#34;&#34;) # 0 String.length(&#34;r&#233;sum&#233;&#34;) # 6 Discussion In the case of a string like, &#34;Antonio&#34;, there isn&#8217;t much to discuss. String.length(&#34;Antonio&#34;) returns the number of </p>
<p>The post <a href="https://programmingzen.com/string-length-in-elixir/">String Length in Elixir</a> appeared first on <a href="https://programmingzen.com">Programming Zen</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>In a previous post, I wrote about <a href="https://programmingzen.com/elixir-hello-world/">Hello World in Elixir</a>. Using such a simple program allowed me to discuss a few concepts about the language. This post explores strings further, by discussing how to find the <strong>length of a string in Elixir</strong>.</p>



<p>Simple enough, but there is more than meets the eye.</p>



<h2 class="wp-block-heading">Elixir String Length</h2>



<p>In Elixir, you can return the number of characters in a string with the <code>String.length/1</code> function:</p>



<pre class="wp-block-code"><code class="prettyprinted">String.length("Antonio") # 7
String.length("")        # 0
String.length("résumé")  # 6</code></pre>



<h2 class="wp-block-heading">Discussion</h2>



<p>In the case of a string like, <code>"Antonio"</code>, there isn&#8217;t much to discuss. <code>String.length("Antonio")</code> returns the number of characters in the string.</p>



<p>The string clearly has 7 characters and since each character in this particular string can be represented with a single byte, its raw representation is 7 bytes as well.</p>



<p>Things become more interesting when a string contains special characters. </p>



<p>Consider the string, <code>"résumé"</code>. In this case, <code>String.length/1</code> returns 6. You can think of this as the number of &#8220;visible&#8221; or &#8220;user-perceived&#8221; characters in the string. However, let&#8217;s investigate its raw representation:</p>



<pre class="wp-block-code"><code class="prettyprinted">iex(2)&gt; i "résumé"
Term
  "résumé"
Data type
  BitString
Byte size
  8
Description
  This is a string: a UTF-8 encoded binary. It's printed surrounded by
  "double quotes" because all UTF-8 encoded code points in it are printable.
Raw representation
  &lt;&lt;114, 195, 169, 115, 117, 109, 195, 169&gt;&gt;
Reference modules
  String, :binary
Implemented protocols
  Collectable, IEx.Info, Inspect, List.Chars, String.Chars</code></pre>



<p>You&#8217;ll notice that the string&#8217;s actual data type is BitString. Specifically, this binary is made up of 8 bytes, even though there are only 6 user-perceived characters. This is because it takes 2 bytes to represent its accented é characters.</p>



<p>If you are interested in the number of bytes within a string, instead of its length, you can use the <code>Kernel.byte_size/1</code> function:</p>



<pre class="wp-block-code"><code class="prettyprinted">iex(3)&gt; string = "résumé"
"résumé"

iex(4)&gt; String.length(string)
6

iex(5)&gt; byte_size(string)
8</code></pre>



<p>From a performance standpoint, it&#8217;s worth noting that <code>Kernel.byte_size/1</code> is more efficient than <code>String.length/1</code>. Unlike the latter, which takes longer as the string grows, <code>Kernel.byte_size/1</code> will return in constant time.</p>



<p><a href="https://hexdocs.pm/elixir/String.html">Strings</a> in Elixir are UTF-8 encoded binaries. You can think of them as collections of code points. A code point is a Unicode character, whose underlying representation might require one or more bytes. For example, the é characters in the string <code>"résumé"</code> are code points whose representation requires two bytes each.</p>



<p>The Unicode standard also defines some special characters as the combination of other characters. In other words, even though they appear to the reader as a single character, they are in fact a combination of two or more code points. These are known as grapheme clusters.</p>



<p>For example, the e-acute letter can be represented as a single code point as we&#8217;ve done so far (this is also known as a precomposed character) or as a combination of two code points (the letter e and a combining acute accent). These look the same but they are technically two different characters as far as Elixir is concerned; so the two strings below end up representing two different binaries:</p>



<pre><code class="prettyprinted">iex(6)&gt; "é" == "e&#769;"
false</code></pre>



<p>When working with strings, you&#8217;ll often want to consider them in terms of the user-perceived characters, rather than their code points or the binary they actually represent.</p>



<p>To help us out, the Elixir <code>String</code> module provides us with <code>String.graphemes/1</code> which returns a list of characters, without splitting grapheme clusters into the underlying code points. If you need the codepoints, you can always use <code>String.codepoints/1</code>.</p>



<p>To see the distinction between code points and graphemes in action, consider the following string (using the grapheme cluster built from two code points):</p>



<pre class="wp-block-code"><code class="prettyprinted">iex(7)&gt; String.codepoints("cliche&#769;")
["c", "l", "i", "c", "h", "e", "&#769;"]

iex(8)&gt; String.graphemes("cliche&#769;")
["c", "l", "i", "c", "h", "e&#769;"]</code></pre>



<p>As you can see, <code>String.codepoints/1</code> shows us a list of code points in the string, and the special e-acute gets split into two code points. If you look closely, you&#8217;ll notice the accent as the last code point in the list.</p>



<p><code>String.graphemes/1</code> simply returns the list of graphemes and is the closest thing that we have to a function that provides a list of user-perceived characters.</p>



<p>Now, consider its length and byte size:</p>



<pre class="wp-block-code"><code class="prettyprinted">ie(9)&gt; String.length("cliche&#769;")
6

iex(10)&gt; byte_size("cliche&#769;")
8</code></pre>



<p><code>String.length/1</code> returns 6, the number of user-perceived characters in the string. <code>Kernel.byte_size/1</code> returns 8 because it takes 3 bytes to represent the special character/grapheme (1 for the letter e, and 2 for the combining acute accent).</p>



<p>We used the expression &#8220;visible&#8221; or &#8220;user-perceived&#8221; characters to give us an intuitive understanding.  Now that you know more about bytes, code points, and graphemes, we can be a little more precise and say that <code>String.length/1</code> returns the number of graphemes in a string.</p>



<p>Finally, if you wanted to know the number of codepoints, you could trivially compose the <code>Kernel.length/1</code> function and the <code>String.codepoints/1</code> function:</p>



<pre class="wp-block-code"><code class="prettyprinted">"cliche&#769;"
  |&gt; String.codepoints()
  |&gt; length()</code></pre>



<p>Note that if you are trying this in IEx, you&#8217;ll need to use the backslash character to continue on new lines:</p>



<pre class="wp-block-code"><code>iex(11)> "cliche&#769;" \
...(11)> |> String.codepoints() \
...(11)> |> length()
7</code></pre>



<p>So in summary, our string contains 6 graphemes, 7 code points, and 8 bytes.</p>
<p>The post <a href="https://programmingzen.com/string-length-in-elixir/">String Length in Elixir</a> appeared first on <a href="https://programmingzen.com">Programming Zen</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://programmingzen.com/string-length-in-elixir/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2286</post-id>	</item>
		<item>
		<title>Elixir Hello World</title>
		<link>https://programmingzen.com/elixir-hello-world/</link>
					<comments>https://programmingzen.com/elixir-hello-world/#respond</comments>
		
		<dc:creator><![CDATA[Antonio Cangiano]]></dc:creator>
		<pubDate>Fri, 11 Oct 2019 04:49:04 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[elixir]]></category>
		<category><![CDATA[elixir-cookbook]]></category>
		<category><![CDATA[erlang]]></category>
		<category><![CDATA[puts]]></category>
		<category><![CDATA[standard library]]></category>
		<category><![CDATA[strings]]></category>
		<guid isPermaLink="false">https://programmingzen.com/?p=2268</guid>

					<description><![CDATA[<p>It is customary to start programming language tutorials with Hello World programs. So today I&#x2019;m sharing with you a Hello World in Elixir, one of my favorite programming languages (along with Ruby and Python, of course). As you likely know, a Hello World is a very simple program that displays the phrase, Hello, World! Our Elixir Hello World might not be too exciting but it will allow us to discuss quite a few fundamental concepts. Hello World in Elixir As you might expect, this is very straightforward: How to run it The easiest way to run this line of code </p>
<p>The post <a href="https://programmingzen.com/elixir-hello-world/">Elixir Hello World</a> appeared first on <a href="https://programmingzen.com">Programming Zen</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>It is customary to start programming language tutorials with Hello World programs. So today I&#8217;m sharing with you a <strong>Hello World in Elixir</strong>, one of my favorite programming languages (along with Ruby and Python, of course).</p>



<p>As you likely know, a Hello World is a very simple program that displays the phrase, <code>Hello, World!</code></p>



<p>Our <strong>Elixir Hello World</strong> might not be too exciting but it will allow us to discuss quite a few fundamental concepts.</p>



<h2 class="wp-block-heading">Hello World in Elixir</h2>



<p>As you might expect, this is very straightforward:</p>



<pre class="wp-block-code"><code>IO.puts("Hello, World!")</code></pre>



<h2 class="wp-block-heading">How to run it</h2>



<p>The easiest way to run this line of code is to launch IEx (i.e., Interactive Elixir). This will also act as a sanity test to ensure that you have installed Elixir correctly on your machine.</p>



<pre class="wp-block-code"><code>$ iex
Erlang/OTP 22 [erts-10.4.4] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe] [dtrace]

Interactive Elixir (1.9.1) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> </code></pre>



<p>For the best experience on Windows, including tab-based autocompletion in IEx, it&#8217;s worth passing the <code>--werl</code> flag to IEx or permanently enabling it by setting the environment variable <code>IEX_WITH_WERL</code> to <code>true</code>.</p>



<pre class="wp-block-code"><code>C:\> iex --werl</code></pre>



<p>Once you type your Elixir Hello World and press enter, IEx will print out the message <code>Hello, World!</code> and then display the return value of the function, which is the atom <code>:ok</code><sup>1</sup> (indicating that the function executed successfully):</p>



<pre class="wp-block-code"><code>iex(2)> IO.puts("Hello, World!")
Hello, World!
:ok
iex(3)></code></pre>



<p>Alternatively, you could place our one-liner in a <code>hello.exs</code> file and execute it as a script:</p>



<pre class="wp-block-code"><code>$ elixir hello.exs
Hello, World!</code></pre>



<p>You could also create a whole (Mix) project for this, but arguably that is overkill for our humble Hello World. </p>



<h2 class="wp-block-heading">Discussion</h2>



<p><code>puts</code> is a function that prints a message and adds a newline character. <code>write</code> is the variant that does the same but doesn&#8217;t append a newline. They both belong to the <code>IO</code> module, a module that includes, as the name implies, various functions for handling input and output.</p>



<p>At any time, we can learn more about a function by using the <code>h</code> helper within IEx:</p>



<pre class="wp-block-code"><code>iex(3)> h IO.puts

                        def puts(device \\ :stdio, item)

  @spec puts(device(), chardata() | String.Chars.t()) :: :ok

Writes item to the given device, similar to write/2, but adds a newline at the
end.

By default, the device is the standard output. It returns :ok if it succeeds.

## Examples

    IO.puts("Hello World!")
    #=> Hello World!

    IO.puts(:stderr, "error")
    #=> error

iex(4)></code></pre>



<p>Unlike languages like Python and Ruby, in Elixir you need to use a qualified call that includes the module name in order to invoke this function.</p>



<p>If we don&#8217;t qualify the call, we get a compile error:</p>



<pre class="wp-block-code"><code>iex(4)> puts("Hello, World!")
** (CompileError) iex:1: undefined function puts/1</code></pre>



<p>If you wanted to omit the module name, you could import the module (i.e., <code>import IO</code>) beforehand, or more realistically, limit the import to the function(s) that you need:</p>



<pre class="wp-block-code"><code>import IO, only: [puts: 1]

puts("Hello, World!")</code></pre>



<p>That <code>puts: 1</code> indicates that we are specifically importing the version of the function that accepts one argument. You&#8217;ll see that function referred to as <code>IO.puts/1</code> and we say that it has an arity of one or it&#8217;s a one-arity function.</p>



<p>The arity of a function (i.e., the number of arguments it accepts) is important because in Elixir you can have functions with the same name but different arities.</p>



<p>In fact, there are technically two variants of the <code>puts</code> function, <code>IO.puts/1</code> which we just used, and <code>IO.puts/2</code> which also allows us to specify an IO device as its first argument. (I say <em>technically</em> because they are both declared within a single function definition.)</p>



<p>By default, the function prints to the standard output. This can be easily verified by looking at the Elixir source code:</p>



<pre class="wp-block-code"><code>def puts(device \\ :stdio, item) do
  :io.put_chars(map_dev(device), [to_chardata(item), ?\n])
end</code></pre>



<p>As you can see, the underlying implementation makes a call to the Erlang&#8217;s <code>IO.put_chars/2</code> function.</p>



<p>What&#8217;s worth noting here is that:</p>



<ul class="wp-block-list"><li>In Elixir, default parameters can be specified using <code>\\</code>.</li><li>The default IO device for the function is the atom <code>:stdio</code> which maps to <code>:standard_io</code> in Erlang. Basically, by default, it will print to your stdout unless you pass a different device to the function.</li><li>Another common value for the device is <code>:stderr</code> which is a shortcut for Erlang&#8217;s <code>:standard_error</code>.</li><li>When we call the function without a device (leveraging the default parameter) we are calling <code>IO.puts/1</code>. When we pass it a device as its first argument and a string as its second argument, we are calling <code>IO.puts/2</code>.</li></ul>



<p>In practice, you&#8217;ll most commonly use <code>IO.puts/2</code> when printing to the standard error, instead of the standard output:</p>



<pre class="wp-block-code"><code>iex(5)> IO.puts(:stderr, "Hello, Post-Apocalyptic World!")
Hello, Post-Apocalyptic World!
:ok</code></pre>



<p>For such messages, there are also <code>IO.warn/1</code> (used below) and <code>IO.warn/2</code> which output to the standard error and in addition, include a stacktrace (provided by the developer in the case of <code>IO.warn/2</code>).</p>



<pre class="wp-block-code"><code>iex(6)> IO.warn("Hello, Post-Apocalyptic World!")
warning: Hello, Post-Apocalyptic World!
  (stdlib) erl_eval.erl:680: :erl_eval.do_apply/6
  (elixir) src/elixir.erl:275: :elixir.eval_forms/4
  (iex) lib/iex/evaluator.ex:257: IEx.Evaluator.handle_eval/5
  (iex) lib/iex/evaluator.ex:237: IEx.Evaluator.do_eval/3
  (iex) lib/iex/evaluator.ex:215: IEx.Evaluator.eval/3

:ok</code></pre>



<p>In most cases, parentheses are optional in Elixir, so we could omit them.<sup>2</sup></p>



<pre class="wp-block-code"><code>IO.puts "Hello, World!"</code></pre>



<p>It&#8217;s worth noting that strings are double-quoted literals in Elixir. Unlike other languages, single-quoted literals are not an alternative way of representing strings.</p>



<p>In Elixir, single-quoted literals represent a related but ultimately different datatype (i.e., List), as we can verify by using the handy data type information helper <code>i</code> in IEx:</p>



<pre class="wp-block-code"><code>iex(7)> i "Hello, World!"
Term
  "Hello, World!"
Data type
  BitString
Byte size
  13
Description
  This is a string: a UTF-8 encoded binary. It's printed surrounded by
  "double quotes" because all UTF-8 encoded code points in it are printable.
Raw representation
  &lt;&lt;72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33>>
Reference modules
  String, :binary
Implemented protocols
  Collectable, IEx.Info, Inspect, List.Chars, String.Chars

iex(8)> i 'Hello, World!'
Term
  'Hello, World!'
Data type
  List
Description
  This is a list of integers that is printed as a sequence of characters
  delimited by single quotes because all the integers in it represent printable
  ASCII characters. Conventionally, a list of Unicode code points is known as a
  charlist and a list of ASCII characters is a subset of it.
Raw representation
  [72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33]
Reference modules
  List
Implemented protocols
  Collectable, Enumerable, IEx.Info, Inspect, List.Chars, String.Chars
iex(9)></code></pre>



<p>Strings are encoded in UTF-8, so you can use special characters and even emojis.</p>



<pre><code class="prettyprinted">iex(9)&gt; IO.puts("Fabrizio De André")
Fabrizio De André
:ok

iex(10)&gt; IO.puts("Hello, &#127758;!")
Hello, &#127758;!
:ok</code></pre>



<p>It&#8217;s also possible to print a given character by specifying its UTF-8 codepoint.</p>



<pre><code class="prettyprinted">iex(11)> > IO.puts("Hello, #{<<127758 :: utf8>>}!")
Hello, &#127758;!
:ok</code></pre>



<p>If you are familiar with Ruby, you&#8217;ll recognize the same string interpolation syntax in which the expression that needs to be evaluated is enclosed within <code>#{}</code>.</p>



<p>Windows users encountering issues related to special characters can improve their experience by changing the active console code page by executing <code>chcp 65001</code> in their Command Prompt, before executing IEx.</p>



<p>It doesn&#8217;t get any simpler than a Hello World program, but as you can see, if you dig a little deeper, you can find out quite a few things about a given programming language.</p>



<p>In the next Elixir-related post, I&#8217;ll publish a similar discussion for another seemingly trivial problem: the length of a string in Elixir. It will give us an opportunity to discuss strings more deeply. Subscribe, if you don&#8217;t already, to be notified of its publication.</p>



<h2 class="wp-block-heading">Footnotes</h2>



<ol class="wp-block-list"><li>Atoms are constants whose values are their own names. The value of <code>:ok</code> is <code>:ok</code>. If you are familiar with Ruby, atoms are equivalent to symbols.</li><li>A glaring exception to the parentheses being optional are non-qualified/local calls with zero-arity. In those cases, parentheses are required to distinguish simple variables (e.g., <code>user_list</code>) from actual function calls (e.g., <code>list_user()</code>). To avoid ambiguity, it&#8217;s also important to include parentheses with one-arity functions within pipelines (e.g., <code>"Hello, World!" |&gt; IO.puts()</code>). For stylistic recommendations of when to use parentheses and when to omit them, consider reading these two style guides (<a href="https://github.com/christopheradams/elixir_style_guide#parentheses">1</a>, <a href="https://github.com/lexmag/elixir-style-guide#parentheses">2</a>). At any rate, do not obsess over this. <code>mix format</code> or a properly configured editor will typically take care of applying idiomatic and consistent styling for you.</li></ol>
<p>The post <a href="https://programmingzen.com/elixir-hello-world/">Elixir Hello World</a> appeared first on <a href="https://programmingzen.com">Programming Zen</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://programmingzen.com/elixir-hello-world/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2268</post-id>	</item>
		<item>
		<title>In Praise of Function Pre and Postconditions</title>
		<link>https://programmingzen.com/in-praise-of-function-pre-and-postconditions/</link>
					<comments>https://programmingzen.com/in-praise-of-function-pre-and-postconditions/#comments</comments>
		
		<dc:creator><![CDATA[Antonio Cangiano]]></dc:creator>
		<pubDate>Sun, 03 Jul 2016 13:00:59 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[clojure]]></category>
		<category><![CDATA[defensive programming]]></category>
		<category><![CDATA[design by contract]]></category>
		<category><![CDATA[elixir]]></category>
		<category><![CDATA[postconditions]]></category>
		<category><![CDATA[preconditions]]></category>
		<category><![CDATA[whiley]]></category>
		<guid isPermaLink="false">http://programmingzen.com/?p=1694</guid>

					<description><![CDATA[<p>I call it my billion-dollar mistake. It was the invention of the null reference. &#x2014; Sir Tony Hoare In mathematics, functions have a domain and a codomain. These are respectively the set of inputs and the set of possible outputs. The function then simply relates an input to an output. For example, consider the square root function: A function&#x2019;s definition is only complete when its domain and codomain are defined. For such a common function we generally implicitly assume that the domain and codomain are the set of nonnegative real numbers: You could, however, change the function by simply extending </p>
<p>The post <a href="https://programmingzen.com/in-praise-of-function-pre-and-postconditions/">In Praise of Function Pre and Postconditions</a> appeared first on <a href="https://programmingzen.com">Programming Zen</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p style="text-align: right; font-style: italic; margin-bottom: 30px;">I call it my billion-dollar mistake. It was the invention of the null reference.<br />
— Sir Tony Hoare</p>
<p>In mathematics, functions have a domain and a codomain. These are respectively the set of inputs and the set of possible outputs. The function then simply relates an input to an output.</p>
<p>For example, consider the square root function:</p>
<div style="text-align: center;"><img decoding="async" src="https://s0.wp.com/latex.php?latex=f%28x%29+%3D+%5Csqrt%7Bx%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" alt="f(x) = &#92;sqrt{x}" class="latex" /></div>
<p>A function’s definition is only complete when its domain and codomain<a id="fnref:1" class="footnote" title="see footnote" href="#fn:1">[1]</a> are defined.</p>
<p>For such a common function we generally implicitly assume that the domain and codomain are the set of nonnegative real numbers:</p>
<div style="text-align: center;"><img decoding="async" src="https://s0.wp.com/latex.php?latex=f%3A+%5Cmathbb%7BR%7D%5E%7B%2B%7D+%5Crightarrow+%5Cmathbb%7BR%7D%5E%7B%2B%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" alt="f: &#92;mathbb{R}^{+} &#92;rightarrow &#92;mathbb{R}^{+}" class="latex" /></div>
<p>You could, however, change the function by simply extending the domain to all real numbers, which would require you to define the codomain as the set of complex numbers:</p>
<div style="text-align: center;"><img decoding="async" src="https://s0.wp.com/latex.php?latex=f%3A+%5Cmathbb%7BR%7D+%5Crightarrow+%5Cmathbb%7BC%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" alt="f: &#92;mathbb{R} &#92;rightarrow &#92;mathbb{C}" class="latex" /></div>
<p>This function can then relate, say, <code>-1</code> to <code>i</code>.</p>
<p>When it comes to programming, things are not much different.<a id="fnref:2" class="footnote" title="see footnote" href="#fn:2">[2]</a> In most languages, we still call them functions, and they still relate an input to an output (after some computation).<a id="fnref:3" class="footnote" title="see footnote" href="#fn:3">[3]</a></p>
<p>Much like in mathematics, the input doesn’t necessarily have to be a number and can often be a composite data type, a list of arguments, or even other functions (in the case of higher-order functions, for example).</p>
<h3>Domain and Codomain Defined via Type Signature</h3>
<p>As far as most mainstream programming languages go, the parallels essentially stop there. In fact, most languages fail to provide us with built-in features to completely define the function by specifying its domain and codomain. And I would argue that we are missing out.</p>
<p>Statically typed programming languages partially offer a way to define the domain and codomain of a function, by specifying the parameters and return value types. Take the <code>Sqrt</code> method definition in C#:</p>
<pre class="prettyprint lang:c# mark:1 decode:true" title="Type-level domain and codomain constraints (in C#)">public static double Sqrt(double x)
{
  &#47;&#47;...
}</pre>
<p>An exception will occur if the argument passed to the function is not a double (or can’t be cast into a double). The same goes for the return value.</p>
<p>This type signature provides a basic element of safety. It ensures that we are actually passing a number to the function, instead of, say, <code>null</code> by mistake. It also ensures that we are returning a value in the first place and that the function’s return value is of the double type.</p>
<p>We essentially narrowed down<a id="fnref:4" class="footnote" title="see footnote" href="#fn:4">[4]</a> our domain and codomain to:</p>
<div style="text-align: center;"><img decoding="async" src="https://s0.wp.com/latex.php?latex=f%3A+%5Cmathbb%7BR%7D+%5Crightarrow+%5Cmathbb%7BR%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" alt="f: &#92;mathbb{R} &#92;rightarrow &#92;mathbb{R}" class="latex" /></div>
<p>Amusingly, if we call <code>Math.Sqrt(-9)</code> in C#, the function will not raise an exception because both the argument and the return values fit the type declaration.</p>
<p>In fact, the function would return <code>Double.NaN</code>, which is the result of an undefined operation, but still technically a double. Other languages will handle the situation differently.<a id="fnref:5" class="footnote" title="see footnote" href="#fn:5">[5]</a></p>
<p>A significant number of software bugs are caused by programmer expectations being silently violated. Wouldn’t it be nice if we could use a feature to easily specify fine-tuned conditions on the acceptable input and output values like we do in mathematics?</p>
<p>For instance, ensuring that an error is automatically raised at runtime if the return value of the square root function isn&#8217;t a nonnegative number?</p>
<h3>Preconditions and Postconditions</h3>
<p>While developing the Eiffel programming language, Prof. Bertrand Meyer came up with the idea of <a href="https://en.wikipedia.org/wiki/Design_by_contract">Design by contract (DbC)</a>. Two key concepts of this software methodology are preconditions and postconditions, which are enforced integrity checks on specified input and output values, respectively.</p>
<p>Preconditions are slowly becoming more common. For example, Elixir has guard expressions, which allow us to limit the set of values the function will accept:</p>
<pre class="prettyprint lang:erlang mark:2,8 decode:true " title="Guards in Elixir">defmodule Math do
  def sqrt(x) when x &gt;= 0 do
    :math.sqrt(x)
  end
end

IO.puts Math.sqrt(9)    # Prints 3
IO.puts Math.sqrt(-9)   # Raises a FunctionClauseError</pre>
<p>Notice how an error is raised when we are trying to call the function with an input outside of the domain specified by the guard.</p>
<p>Guard expressions in named functions were introduced in Elixir in order to fully flesh out its powerful pattern matching capabilities.<a id="fnref:6" class="footnote" title="see footnote" href="#fn:6">[6]</a> Nevertheless, they act as preconditions that enable us to define the domain of the function.</p>
<p>To enforce checks on return values we need postconditions. For this example, I’ll use Clojure since it provides both preconditions and postconditions:</p>
<pre class="prettyprint lang:clojure mark:2,3,7,8 decode:true ">(defn limited-sqrt &#091;x&#093;
    {:pre  &#091;(pos? x)&#093;
     :post &#091;(&gt;= % 0), (&lt; % 10)&#093;}
    (Math&#47;sqrt x))

(limited-sqrt 9)   ;; 3.0
(limited-sqrt -9)  ;; AssertionError Assert failed: (pos? x)
(limited-sqrt 144) ;; AssertionError Assert failed: (&lt; % 10)
</pre>
<p>I intentionally made the example contrived by limiting the function codomain to values between 0 and 10, to demonstrate how postconditions are also caught at runtime (line 8).</p>
<h3>Extended Static Checking</h3>
<p>Some programming languages take the concept further by introducing <em>verifying compilers</em> that check the mathematical correctness and adherence to the formal specification.</p>
<p>The compiler will essentially take care of traversing all possible branches to determine whether the range of values the program could calculate meets the specification for the given function.</p>
<p>Creating such a compiler for an existing language is extremely hard. We are always contending with the <a href="https://en.wikipedia.org/wiki/Halting_problem" target="_blank">halting problem</a>. It is possible, however, to design languages specifically with that aim in mind.</p>
<p><a href="https://whiley.org/" target="_blank">Whiley</a> is one such language for the JVM.</p>
<p>Consider this example:</p>
<pre class="prettyprint lang:default mark:4,5 decode:true " title="Whiley example">import whiley.lang.System

function max(int x, int y) -&gt; (int z)
ensures x == z || y == z
ensures x &lt;= z &amp;&amp; y &lt;= z:
    if x &gt; y:
        return x
    else:
        return y

method main(System.Console console):
    console.out.println(max(4, 10))</pre>
<p>Whiley&#8217;s compiler will verify that x, y, and z meet the conditions indicated in the specification (on lines 4 and 5). Namely, that the returned value is either of the two arguments and that both of them are less than or equal to it.</p>
<p>If we create a faulty version of the algorithm as shown below, we’ll catch the error before even running the program:</p>
<pre class="prettyprint lang:default mark:6,8 decode:true ">import whiley.lang.System

&#47;&#47; Bad implementation
function max(int x, int y) -&gt; (int z)
ensures x == z || y == z
ensures x &lt;= z &amp;&amp; y &lt;= z:
    if x &gt; y:
        return y
    else:
        return x

method main(System.Console console):
    console.out.println(max(4, 10))</pre>
<p>In fact, although <code>max(4, 10)</code> does not enter the if branch, the compiler determines that there are inputs for which that return y would not satisfy the highlighted postcondition.</p>
<p>True enough if you consider <code>max(3, 2)</code> for a moment. x (3) &gt; y (2), so in this faulty implementation, we return z (2). However, x (3) is not less than or equal to z (2), so the postcondition fails.</p>
<p>Whiley is an extreme case of course, and as discussed, its verifying compiler is a virtually intractable problem for regular programming languages which were not specifically designed for it. Nevertheless, I wanted to show you how far this powerful concept can be pushed.</p>
<h3>Conclusion</h3>
<p>I would love to see pre and postconditions become built-in features of more mainstream programming languages.</p>
<p>Especially since many mainstream programming languages don’t offer referential transparency. Side effects caused by mutable data structures and having to account for state mean that we have even less predictability about return values than in purely functional programming languages.</p>
<p>As shown by Elixir, Clojure, and even Whiley, adding such specifications doesn&#8217;t require any significant syntactic overhead either.</p>
<p>With dynamically typed programming languages we stress the importance of having tests because we don’t have a compiler to catch as many of our mistakes. (Though testing is key either way.)</p>
<p>Pre and postconditions add a complementary layer of safety, regardless of the language&#8217;s typing system. By using both Design by Contract principles and testing, we can build more robust software. (Definitely check out other features of DbC as well, including class invariants. There are lots of good ideas in there.)</p>
<p>If you’d like to get started, you can probably find a library for your favorite language. If not, creating your own should be fairly easy.</p>
<p>However, I’d advocate for such conditions/assertions to be a core part of most languages. And that’s because of the difference in the adoption rate of opt-in vs opt-out features.</p>
<p>With pre and postconditions built into the language, documented in the intro tutorial that everyone reads, you’ll cultivate a community with a penchant for defensive programming, who will actually make use of the feature.</p>
<p>&nbsp;</p>
<div class="footnotes">
<hr />
<ol>
<li id="fn:1">Some readers might be more familiar with the word <em>range</em> or <em>image</em>. In our examples, range and codomain coincide, even though in general, the range is a subset of the codomain. <a class="reversefootnote" title="return to article" href="#fnref:1">^</a></li>
<li id="fn:2">When a function has an algorithmic bug and we get the wrong output, we are still defining a function. Just not the intended one. <a class="reversefootnote" title="return to article" href="#fnref:2">^</a></li>
<li id="fn:3">I’ll use the word function even when the proper nomenclature of the specific language might call for another word, such as <em>method</em>. <a class="reversefootnote" title="return to article" href="#fnref:3">^</a></li>
<li id="fn:4">Obviously, doubles are represented in memory as double precision floating-point numbers, and therefore not actual real numbers. So they are technically a subset of the rational numbers <img decoding="async" src="https://s0.wp.com/latex.php?latex=%5Cmathbb%7BQ%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" alt="&#92;mathbb{Q}" class="latex" />. <a class="reversefootnote" title="return to article" href="#fnref:4">^</a></li>
<li id="fn:5">Both Ruby and Julia, for example, will raise a <code>DomainError</code> in such a scenario. <a class="reversefootnote" title="return to article" href="#fnref:5">^</a></li>
<li id="fn:6">Here we could have a second declaration with <code>when x &lt; 0</code> to match function calls with negative arguments, perhaps leveraging that function implementation to provide a more informative error message. <a class="reversefootnote" title="return to article" href="#fnref:6">^</a></li>
</ol>
</div>
<p>The post <a href="https://programmingzen.com/in-praise-of-function-pre-and-postconditions/">In Praise of Function Pre and Postconditions</a> appeared first on <a href="https://programmingzen.com">Programming Zen</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://programmingzen.com/in-praise-of-function-pre-and-postconditions/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1694</post-id>	</item>
		<item>
		<title>A Language for the Next 10 Years</title>
		<link>https://programmingzen.com/next-programming-language/</link>
					<comments>https://programmingzen.com/next-programming-language/#comments</comments>
		
		<dc:creator><![CDATA[Antonio Cangiano]]></dc:creator>
		<pubDate>Tue, 14 Jun 2016 16:30:22 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[beam]]></category>
		<category><![CDATA[clojure]]></category>
		<category><![CDATA[elixir]]></category>
		<category><![CDATA[erlang]]></category>
		<category><![CDATA[jvm]]></category>
		<category><![CDATA[language for the next decade]]></category>
		<category><![CDATA[programming languages]]></category>
		<category><![CDATA[trends]]></category>
		<guid isPermaLink="false">http://programmingzen.com/?p=1679</guid>

					<description><![CDATA[<p>In early 2006 I had just started my career in IBM. I was the &#x201C;Ruby Guy&#x201D; (or alternatively, the &#x201C;Rails Guy&#x201D;). During a meeting with a few high-profile engineers, I presented what Ruby brought to the table. An IBM Distinguished Engineer stopped me in my tracks and said, &#x201C;It sounds slow&#x201D;. I love Ruby as much as a programmer can possibly love a programming language, but that engineer&#x2019;s conjecture was right on the money. Ruby&#x2019;s emphasis has always been on programmer efficiency, not execution efficiency. Generally speaking, Ruby programs are significantly slower than equivalent programs in C or Java. A </p>
<p>The post <a href="https://programmingzen.com/next-programming-language/">A Language for the Next 10 Years</a> appeared first on <a href="https://programmingzen.com">Programming Zen</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In early 2006 I had just started my career in IBM. I was the “Ruby Guy”<a id="fnref:1" class="footnote" title="see footnote" href="#fn:1">[1]</a> (or alternatively, the “Rails Guy”).</p>
<p>During a meeting with a few high-profile engineers, I presented what Ruby brought to the table. An IBM Distinguished Engineer<a id="fnref:2" class="footnote" title="see footnote" href="#fn:2">[2]</a> stopped me in my tracks and said, “It sounds slow”.</p>
<p>I love Ruby as much as a programmer can possibly love a programming language, but that engineer’s conjecture was right on the money. Ruby’s emphasis has always been on programmer efficiency, not execution efficiency.</p>
<p>Generally speaking, Ruby programs are significantly slower than equivalent programs in C or Java.</p>
<p>A lot of work has been done to improve Ruby’s performance, with a good degree of success, and that’s terrific &#8211; but is it enough in today’s world?</p>
<p>In many ways, yes. You’re not going to employ Ruby to calculate 13 trillion digits of Pi, nor will you use it to power the backend of a messaging app with millions of users.</p>
<p>However, Ruby will suit most scripts just fine. Further, I would argue that Rails still gives you the best bang for your buck in terms of web frameworks, when it comes to a large subset of CRUD-based web applications.</p>
<p>Ruby is lovely and has many uses, however, what Ruby is not, is the language that will define the next ten years. As beautifully designed as it is, it simply isn’t the ideal language to tackle the challenges that an increasingly distributed world throws at us.</p>
<p>Concurrency is the name of the game, and Ruby is, for the most part, limited in its ability to cope with it (despite <a href="https://github.com/ruby-concurrency/concurrent-ruby">valuable efforts</a>). It’s not that you can’t do concurrency in Ruby, it’s that there are much better, battle-tested tools to do so.</p>
<p>If you are a fellow Ruby developer who would like to remain relevant in the next decade, I highly suggest that you start looking for something new to pair to Ruby as your main language. (Though, fair warning, you might end up replacing Ruby with it.)</p>
<p>Your main language for the next ten years will be highly dependent on the development context, of course. If you develop iOS apps, Swift is such a language. Android apps? <a href="https://kotlinlang.org/">Kotlin</a> is looking good and might have a shot at that. Data Science? <a href="https://julialang.org/">Julia</a>, if they can sort out a few performance issues, could get the edge over Python and R. System programming? <a href="https://www.rust-lang.org/">Rust</a> and Go will be worth a close look, too.<a id="fnref:3" class="footnote" title="see footnote" href="#fn:3">[3]</a></p>
<p>I’m enough of a generalist to dabble in many programming domains, but above all, I’m a web developer, so my main language for the next decade will have to excel in distributed environments where n machines make m requests, for large values of n and m (e.g., IoT alone enables this scenario).</p>
<p>So what comes after Ruby? Some people might argue that it’s Node.js. Not for me personally, though. I’m afraid Ruby has spoiled me. I find Ruby to be a joy to use. JavaScript, not so much.</p>
<p>We are looking for a high-level language that can handle concurrency like a champ, has an elegant, highly readable syntax, provides a great user experience for the developer, and… is functional. In short, fun and functional. 🙂</p>
<p>I find functional programming (with immutable data types) to be a significantly better approach to thinking about most problems, and modeling solutions for them, than Object Oriented programming.<a id="fnref:4" class="footnote" title="see footnote" href="#fn:4">[4]</a> I blame my past dabbling with Haskell and Clojure for this.</p>
<p>Speaking of Clojure, on the JVM, both Scala (w/ Akka), and Clojure (w/ STM &amp; Pulsar) are valid options.</p>
<p>Of the two, Clojure is the one that comes closer to a great fit for me. Very close. Unfortunately, I&#8217;m somewhat of an aesthete, and coming from Ruby, the Lisp syntax still feels like a downgrade.<a id="fnref:5" class="footnote" title="see footnote" href="#fn:5">[5]</a></p>
<p>Further, the JVM is great, but when it comes to dependable concurrency, you really can’t beat what the Erlang VM (i.e., BEAM) has to offer (<a href="https://www.fastcompany.com/3026758/inside-erlang-the-rare-programming-language-behind-whatsapps-success">ask the team at Whatsapp</a>).</p>
<p>The problem with Erlang is that its Prolog-like syntax feels obsolete. I have never seen an Erlang program and said to myself, “Wow, that was a joy to read”. Or refactor. It’s not the worst, but I personally find it to be a fairly uninspiring language to work with.</p>
<p><img data-recalc-dims="1" decoding="async" style="display: block; margin-left: auto; margin-right: auto;" title="Expression terminators in Erland.jpg" src="https://i0.wp.com/programmingzen.com/wp-content/uploads/2016/06/Expression-terminators-in-Erland.jpg?resize=500%2C272&#038;ssl=1" alt="Expression terminators in Erlang" width="500" height="272" border="0" /></p>
<p>Thankfully Erlang is not the only language for its highly fault-tolerant and concurrent VM. There is indeed a language worth getting excited about.</p>
<p>For me, that language is Elixir. Elixir fits all the requirements above and feels like a joy to both read and use.</p>
<p><img data-recalc-dims="1" decoding="async" style="float: right;" title="Elixir.gif" src="https://i0.wp.com/programmingzen.com/wp-content/uploads/2016/06/Elixir.gif?resize=100%2C191&#038;ssl=1" alt="Elixir" width="100" height="191" border="0" /></p>
<p>Like many other Rubyists, when I first found Elixir I thought of it as Ruby for the Erlang VM, due to its largely familiar syntax. But it turns out to be so much more than that. In fact, it’s much more than Erlang as well.</p>
<p>To hastily summarize, we get:</p>
<ul>
<li>A highly readable, elegant, concurrent, functional programming language.</li>
<li>The fantastic Erlang VM (i.e., BEAM) and OTP integration.</li>
<li>Shared nothing Actor-based concurrency.</li>
<li>Metaprogramming via macros.</li>
<li>Polymorphism via protocols.</li>
<li>A whole host of other nice features (pipeline operator, pattern matching, docstrings, streams, mix, etc).</li>
<li>An excellent web framework called <a href="https://www.phoenixframework.org/">Phoenix</a>.</li>
<li>A fast growing supportive community, that it’s reminiscent of Ruby during the early days of Rails.</li>
</ul>
<p>Ruby’s usage skyrocketed in the past decade and I would argue that Elixir, though not widely adopted as of yet, is well equipped to do the same in the coming ten years.</p>
<p><a href="https://elixir-lang.org/">Give it a try</a> and let me know how you like it.</p>
<div class="footnotes">
<hr />
<ol>
<li id="fn:1">Though <a href="https://en.wikipedia.org/wiki/Sam_Ruby">Sam</a> was both literally and figuratively a Ruby guy. 😉  <a class="reversefootnote" title="return to article" href="#fnref:1">^</a></li>
<li id="fn:2">Now an IBM Fellow, which is the highest honor a tech person at IBM can achieve. It’s worth noting that I had not mentioned performance at all until that point. He simply figured it out based on the features of the language.  <a class="reversefootnote" title="return to article" href="#fnref:2">^</a></li>
<li id="fn:3">Some might like <a href="https://nim-lang.org/">Nim</a>, instead. <a href="https://crystal-lang.org/">Crystal</a>, with its Ruby-like syntax, is probably the most interesting option for Rubyists, despite being at very early stages of development.  <a class="reversefootnote" title="return to article" href="#fnref:3">^</a></li>
<li id="fn:4">I suspect that the next decade, outside of system programming, will belong to functional languages (or hybrid languages heavily influenced by functional programming).  <a class="reversefootnote" title="return to article" href="#fnref:4">^</a></li>
<li id="fn:5">I know, I know, I’m putting a lot of emphasis on syntax. That’s because it matters more than most people give it credit for.  <a class="reversefootnote" title="return to article" href="#fnref:5">^</a></li>
</ol>
</div>
<p>The post <a href="https://programmingzen.com/next-programming-language/">A Language for the Next 10 Years</a> appeared first on <a href="https://programmingzen.com">Programming Zen</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://programmingzen.com/next-programming-language/feed/</wfw:commentRss>
			<slash:comments>16</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1679</post-id>	</item>
		<item>
		<title>Rails Is Old Hat, and That&#8217;s Okay</title>
		<link>https://programmingzen.com/rails-is-an-old-hat/</link>
					<comments>https://programmingzen.com/rails-is-an-old-hat/#comments</comments>
		
		<dc:creator><![CDATA[Antonio Cangiano]]></dc:creator>
		<pubDate>Tue, 09 Dec 2014 16:43:23 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[elixir]]></category>
		<category><![CDATA[Node.js]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<guid isPermaLink="false">http://programmingzen.com/?p=1579</guid>

					<description><![CDATA[<p>Not too long ago, someone I know said, &#x201C;At this point in time, Rails is old hat&#x201D;, in reference to the fact that many developers are adopting newer technologies like Node.js. I don&#x2019;t see this as a negative, true as it might be. When Rails arrived on the scene a decade ago, it was thoroughly impressive and quite the improvement over the status quo in the PHP, Java, and even Ruby communities. At the time, despite some shortcomings, it was revolutionary. Not surprisingly, as time went on the framework evolved, improved, and became more mature. The whole ecosystem around it </p>
<p>The post <a href="https://programmingzen.com/rails-is-an-old-hat/">Rails Is Old Hat, and That&#8217;s Okay</a> appeared first on <a href="https://programmingzen.com">Programming Zen</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Not too long ago, someone I know said, “At this point in time, Rails is old hat”, in reference to the fact that many developers are adopting newer technologies like Node.js.</p>
<p>I don’t see this as a negative, true as it might be. When Rails arrived on the scene a decade ago, it was thoroughly impressive and quite the improvement over the status quo in the PHP, Java, and even Ruby communities. At the time, despite some shortcomings, it was revolutionary.</p>
<p>Not surprisingly, as time went on the framework evolved, improved, and became more mature. The whole ecosystem around it grew exponentially. You can now deploy scalable Rails applications. It is the darling framework of most startups in Silicon Valley. You can leverage advanced support in editors and IDEs, run it on different platforms (e.g., on the JVM via JRuby), and find Rails developers to hire with relative ease.</p>
<p>As it grew to become the tool of choice of countless web developers, it managed to have a massive influence on other communities as well. It contributed to raising the bar for frameworks in other languages and as a result we have at least a bit of Rails inspired frameworks in virtually every language today. We are more productive almost regardless of the language we choose, and in many cases we have Rails to thank for it.</p>
<p>What Rails lost in the process is the massive competitive advantage it had in its early days over virtually everything else that was out there. <a id="fnref-1" class="footnote" title="see footnote" href="#fn-1">[1]</a> It hasn’t failed to grow. It hasn’t failed to innovate. It simply matured and so did the rest of the web world.</p>
<p>I think it’s important for developers to reinvent themselves, or at least stay up-to-date on what’s available out there. That’s how I came to discover Rails in the first place. This is true for programmers in general, and its especially true for my professional role which includes technical evangelism in a team that continually reinvents itself.</p>
<p>When you go talk to a new generation of programmers, you need to be able to speak their language. And today for many, in my experience, that means speaking Node.js, instead of Rails.</p>
<p>That’s okay. Ruby on Rails might be old news by now, but it remains a perfectly capable solution for a wide array of problems. It has become the status quo and there is nothing wrong with that.</p>
<p>As we look for new runtimes, languages, and frameworks that innovate further and better solve those particular use cases where Rails doesn’t shine, we might stumble upon a new and innovative solution that make today’s Rails look like J2EE or PHP did to us back in 2004. <a id="fnref-2" class="footnote" title="see footnote" href="#fn-2">[2]</a> Until then, it’s worth keeping an eye open while still wearing that old, comfortable, and very trusty hat that has been helping us get the job done for a decade now.</p>
<div class="footnotes">
<hr />
<ol>
<li id="fn-1">A few exceptions aside. Django comes to mind. <a class="reversefootnote" title="return to article" href="#fnref-1">^</a></li>
<li id="fn-2">Elixir is headed in the right direction, language wise. Meteor.js shows flashes of brilliance at times. Still, we’re not there yet. <a class="reversefootnote" title="return to article" href="#fnref-2">^</a></li>
</ol>
</div>
<p>The post <a href="https://programmingzen.com/rails-is-an-old-hat/">Rails Is Old Hat, and That&#8217;s Okay</a> appeared first on <a href="https://programmingzen.com">Programming Zen</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://programmingzen.com/rails-is-an-old-hat/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1579</post-id>	</item>
		<item>
		<title>3 Upcoming Languages That Are Worth Exploring</title>
		<link>https://programmingzen.com/3-upcoming-languages-that-are-worth-exploring/</link>
					<comments>https://programmingzen.com/3-upcoming-languages-that-are-worth-exploring/#comments</comments>
		
		<dc:creator><![CDATA[Antonio Cangiano]]></dc:creator>
		<pubDate>Tue, 25 Nov 2014 21:22:05 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[data science]]></category>
		<category><![CDATA[elixir]]></category>
		<category><![CDATA[future]]></category>
		<category><![CDATA[go]]></category>
		<category><![CDATA[julia]]></category>
		<category><![CDATA[languages]]></category>
		<guid isPermaLink="false">http://programmingzen.com/?p=1568</guid>

					<description><![CDATA[<p>Being at the forefront of technology is something that I&#x2019;ve always sincerely enjoyed. For example I was one of the first C# programmers in Italy back when C# was still in beta, and I was there in the early days of Rails as well (just a few months after its initial release). Over the years I&#x2019;ve dared to risk and have made some educated bets on technology that have served my career well. I share this as a way of illuminating the&#xA0;fact that there is a reward to be had if you enjoy keeping up with technology and the programming </p>
<p>The post <a href="https://programmingzen.com/3-upcoming-languages-that-are-worth-exploring/">3 Upcoming Languages That Are Worth Exploring</a> appeared first on <a href="https://programmingzen.com">Programming Zen</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Being at the forefront of technology is something that I’ve always sincerely enjoyed. For example I was one of the first C# programmers in Italy back when C# was still in beta, and I was there in the early days of Rails as well (just a few months after its initial release). Over the years I’ve dared to risk and have made some educated bets on technology that have served my career well.<a id="fnref:1" class="footnote" title="see footnote" href="#fn:1">[1]</a></p>
<p>I share this as a way of illuminating the fact that there is a reward to be had if you enjoy keeping up with technology and the programming world &#8211; and it’s a payoff that goes hand-in-hand with the sheer fun of exploring and using new cool technologies.</p>
<p>We live in a world that moves quickly, with significant innovations being introduced every couple of years and entire tectonic shifts coming along every decade or so.</p>
<p>This doesn’t just apply to programming languages either &#8211; we’re talking databases (e.g., NoSQL), paradigms (e.g., parallelism and concurrency), new approaches (e.g., Big Data in the Cloud), new frameworks (e.g., Meteor), and many other corners of this vast field.</p>
<p>In the programming world, in order to stay competitive, you can not ever stop learning. If you’re not leading the pack, you apt to be left in the dust.<a id="fnref:2" class="footnote" title="see footnote" href="#fn:2">[2]</a></p>
<p>One way to keep up is to never stop experimenting, playing with new languages and technologies in your spare time and applying them to non-mission critical projects. That’s the strategy I have grown accustom to at least, and again, no complaints from me when it comes to taking such an approach.</p>
<p>Wayne Gretzky, arguably &#8211; if not flat out &#8211; the best hockey player of all time, has a great quote that applies to hockey as much as it does to life in general.</p>
<blockquote><p>I skate to where the puck is going to be, not where it has been.</p></blockquote>
<p>Damn, Gretzky was good on the ice. Anyway, back to the topic. Some developers might consider R or Node.js to be the future. In reality, that’s where the puck is now.</p>
<p>Where will the puck be in three, five, or ten years? We’ll have to wait and see to know for sure. Meanwhile, I encourage you to explore three programming languages that might very well be headed in the same direction of that most iconic of Canadian sports equipment, the humble yet mighty, puck.</p>
<ul>
<li><strong><a href="https://golang.org/">GO</a></strong>: A fast, truly cross-platform, concurrent language that resembles a modern C on steroids.</li>
<li><strong><a href="https://julialang.org/">Julia</a></strong>: A very high level language that’s aiming to be the future of scientific computing and data science, including integrating with existing solutions such as Python scientific packages. Think of it like a modern Fortran on steroids.</li>
<li><strong><a href="https://elixir-lang.org/">Elixir</a></strong>: This language fully leverages the power, reliability, and concurrent nature of the Erlang VM, but does so with an elegant Ruby-like syntax. It’s Ruby taking steroids in the gym she goes to seven times a week.</li>
</ul>
<p>I make no promises or guarantees that these languages will pick up massive momentum over time. What I can promise you is that you’ll enjoy and learn from them in the moment. Each one is not only promising, but already delivering and is well worth checking out, if you haven’t already.</p>
<p>Let me know where the puck is headed for you.</p>
<div class="footnotes">
<hr />
<ol>
<li id="fn:1">I also saw Node.js coming from a mile away, but I didn’t have a strong need for it, so I played with and used it, but never really got too involved. <a class="reversefootnote" title="return to article" href="#fnref:1">&#8593;</a></li>
<li id="fn:2">Yes, some people specialized in a particular enterprise solution 20 or 30 years ago and still make a living by relying on it, however this might not hold true in the future. As an industry, we are moving faster and faster away from that approach. <a class="reversefootnote" title="return to article" href="#fnref:2">&#8593;</a></li>
</ol>
</div>
<p>The post <a href="https://programmingzen.com/3-upcoming-languages-that-are-worth-exploring/">3 Upcoming Languages That Are Worth Exploring</a> appeared first on <a href="https://programmingzen.com">Programming Zen</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://programmingzen.com/3-upcoming-languages-that-are-worth-exploring/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1568</post-id>	</item>
	</channel>
</rss>
