<p>I’m working on an Elixir app at the moment and really enjoying it, but some of my recent dabbling in the type-safe worlds of <a href="https://elm-lang.org">Elm</a> and <a href="https://crystal-lang.org">Crystal</a> have left me desiring a bit more structure in my code. The app I’m building involves a multi-step data transformation and so I have a data structure to properly represent this process. But since Elixir is a dynamically typed language, you can’t, for example, have a non-nillable field in a struct. The Elixir/Erlang ecosystem does, however, have a type-checking syntax called <a href="https://hexdocs.pm/elixir/typespecs.html">Type Specs</a>, along with a tool, <a href="http://erlang.org/doc/man/dialyzer.html">Dialyzer</a>,...</p>
Blog Entries tagged "elixir"
<p>I’m in the middle of writing an application in <a href="https://elixir-lang.org">Elixir</a> and <a href="https://www.phoenixframework.org">Phoenix</a>, so when I saw a link to <a href="https://dashbit.co/blog/a-new-authentication-solution-for-phoenix">an article by José Valim</a> on an upcoming authentication solution for Phoenix, my initial reaction (before reading it) was negative. José is the author of the <a href="https://github.com/plataformatec/devise">Devise framework</a> for Ruby-on-Rails, so I assumed it was going to be the same idea, but for Elixir and Phoenix. I’ve implemented Devise in a handful of Rails apps, and each and every time I ended up ripping it out and writing my own auth solution (often based on <a href="http://railscasts.com/episodes/250-authentication-from-scratch-revised">this Railscasts tutorial</a>). The reason is that while...</p>
<p>When using Elixir, I’ve long missed the special <code>_</code> helper from <a href="https://en.wikipedia.org/wiki/Interactive_Ruby_Shell">irb</a> that returns the result of the previous expression. Sometimes I actually type it out of pure habit.</p> <p>Little did I know that Elixir has the same thing, except better.</p> <p>IEx.Helpers has a function <code>v(n \\ -1)</code> that returns the value of the nth expression in the session history. So <code>v</code> alone returns the previous expression and <code>v(-2)</code> returns the one before it.</p> <div class="highlight"><pre class="highlight elixir"><code><span class="n">iex</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">></span> <span class="s2">"abc"</span> <span class="n">iex</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span><span class="o">></span> <span class="s2">"zyx"</span> <span class="n">iex</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span><span class="o">></span> <span class="n">v</span> <span class="s2">"zyx"</span> <span class="n">iex</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span><span class="o">></span> <span class="n">v</span><span class="p">(</span><span class="o">-</span><span class="mi">3</span><span class="p">)</span> <span class="s2">"abc"</span> </code></pre></div>
<p>In Vim-land, I use the <a href="https://www.github.com/janko-m/vim-test">vim-test plugin</a> for quickly executing tests from a command line shortcut<sup id="fnref1"><a href="#fn1">1</a></sup>. I wanted to reproduce this behavior in <a href="https://code.visualstudio.com">Visual Studio Code</a>, but I couldn’t find an extension that worked in multiple languages (namely, Ruby, Elixir, Javascript, and Elm). I’m mostly just using VSCode for Elixir, but I still liked the idea of finding a more general purpose solution.</p> <p>So instead I used VSCode’s support for <a href="https://code.visualstudio.com/docs/editor/tasks">Tasks</a> to build the functionality myself. So in my project’s <code>tasks.json</code> file, I have the following 3 tasks for running all tests, a single...</p>
<p>I’ve played around with <a href="https://code.visualstudio.com">VSCode</a> here and there, but as a fairly picky Vim user who doesn’t do TypeScript, I never quite understood the hype.</p> <p>Today I started up a new Elixir / Phoenix project (more on that to come) and tried out the <a href="https://github.com/JakeBecker/vscode-elixir-ls">Elixir Language Server Extension</a> and the integration is <strong>very</strong> impression. Code completion, debugger support, automatic inference of Dialyzer <a href="https://hexdocs.pm/elixir/typespecs.html">Typespecs</a>, documentation on hover, and more….</p> <p>I don’t expect to be using VSCode as my standard editor (again, picky Vim user<sup id="fnref1"><a href="#fn1">1</a></sup>), but I think I’ll stick with it on Elixir projects.</p> <div class="footnotes"> <hr> <ol> </ol> </div>