<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Clojure on David Mohl</title>
    <link>https://david.coffee/tags/clojure/</link>
    <description>Recent content in Clojure on David Mohl</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <lastBuildDate>Fri, 22 Jan 2016 10:30:23 +0000</lastBuildDate><atom:link href="https://david.coffee/tags/clojure/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Hello (Neo)Vim, good to see you again!</title>
      <link>https://david.coffee/hello-neovim-good-to-see-you-again/</link>
      <pubDate>Fri, 22 Jan 2016 10:30:23 +0000</pubDate>
      
      <guid>https://david.coffee/hello-neovim-good-to-see-you-again/</guid><description>&lt;p&gt;It’s weird that I am writing about editors so much but trying a new editor every few months kind of
became a tradition. It spices things up and allows me to learn something new that I maybe didn’t know yet before. Or just discover a new tool that improves my workflow.&lt;/p&gt;
&lt;p&gt;When I wrote about spacemacs, I thought spacemacs would be the thing that I would use for everything. Then I ported it to atom with &lt;a href=&#34;https://github.com/dvcrn/proton&#34;&gt;proton&lt;/a&gt; and thought that would be the tool I would be using for everything since I could just implement features on the spot that it didn’t have yet. So what happened that I am writing about editors again?&lt;/p&gt;
&lt;p&gt;As a VIM fan, I like micro optimizations. One thing in my workflow that I couldn’t stand was hammering &lt;code&gt;j&lt;/code&gt; &lt;code&gt;j&lt;/code&gt; &lt;code&gt;j&lt;/code&gt; &lt;code&gt;j&lt;/code&gt; to go down instead of &lt;code&gt;4j&lt;/code&gt;. I knew this keybinding was a lot faster, I just couldn’t get to teach myself to actually use it. After a bit of research I couldn’t find anything that helps me inside atom or emacs - but I found &lt;a href=&#34;https://github.com/wikitopian/hardmode&#34;&gt;hardmode for vim&lt;/a&gt;. It was a bit overkill since it disables all &lt;code&gt;hjkl&lt;/code&gt; keys but a good start. Then I found &lt;a href=&#34;https://github.com/takac/vim-hardtime&#34;&gt;hardtime&lt;/a&gt; and it was like my prayers have been answered 🙏. It allows me to use &lt;code&gt;hjkl&lt;/code&gt; exactly x times - and I can specify how much x is! Only problem - I need to use raw VIM.&lt;/p&gt;
&lt;h2 id=&#34;hello-neovim-again&#34;&gt;Hello NeoVim (again)&lt;/h2&gt;
&lt;p&gt;Instead of vim though I grabbed NeoVim as my weapon of choice. Stuffed in my old config file just… to realize that things are not working the way I want them to. Plugins were outdated, keybindings were ‘meh’ and my &lt;a href=&#34;https://github.com/dvcrn/dotfiles/blob/master/vim/.vimrc&#34;&gt;old vimrc&lt;/a&gt; a complete mess. How were I ever able to work with this??&lt;/p&gt;
&lt;p&gt;It had to go and something new had to be in it’s place, so I opened up a new vim pane and started hacking on my new vimrc with the goal that everything I use should be heavily optimized, consistent and use NeoVims async features if possible. No more &lt;a href=&#34;https://github.com/scrooloose/syntastic&#34;&gt;syntastic&lt;/a&gt; lags on linting - &lt;a href=&#34;https://github.com/benekastah/neomake&#34;&gt;neomake&lt;/a&gt; runs completely async!&lt;/p&gt;
&lt;p&gt;I replaced vundle with the async &lt;a href=&#34;https://github.com/junegunn/vim-plug&#34;&gt;vim-plug&lt;/a&gt; and re-added crucial packages that I needed - but something was still missing. I can’t just assign random leader keybindings after having such a blast with the spacemacs mnemonic. After changing the leader to &lt;code&gt;&amp;lt;SPC&amp;gt;&lt;/code&gt; and re-arranging the keybindings a bit I was quite surprised to see what I ended up doing - &lt;a href=&#34;https://github.com/dvcrn/dotfiles/blob/master/vim/nvim/keybindings.vim#L70-L112&#34;&gt;re-creating mnemonic keybindings in vim&lt;/a&gt;! I also went the extra steps and moved everything related into a package of some sorts. A bit of sourcing here and there and suddenly &lt;a href=&#34;https://github.com/dvcrn/dotfiles/blob/master/vim/nvim/.nvimrc#L79-L104&#34;&gt;I had “layers”&lt;/a&gt;! Just like in proton or spacemacs!&lt;/p&gt;
&lt;h2 id=&#34;quality-plugins-ahead&#34;&gt;Quality plugins ahead&lt;/h2&gt;
&lt;p&gt;What eventually got me really into vim were probably the amazing plugins of &lt;a href=&#34;https://github.com/junegunn/&#34;&gt;junegunn&lt;/a&gt;, the guy that wrote vim-plug. I am absolutely impressed about the quality of these and didn’t have this much fun with vim for a long time. Stuff like &lt;a href=&#34;https://github.com/junegunn/fzf&#34;&gt;fzf&lt;/a&gt; makes almost every command feel consistent.&lt;/p&gt;
&lt;p&gt;He even wrote a color scheme using the official colors of probably my favorite city on the planet - &lt;a href=&#34;https://github.com/junegunn/seoul256.vim&#34;&gt;Seoul&lt;/a&gt;. Just look how pretty it is:&lt;/p&gt;
&lt;p&gt;
&lt;img class=&#34;img-fluid&#34; src=&#34;./neovim-1.png&#34; alt=&#34;screenshot&#34; /&gt;

&lt;/p&gt;
&lt;p&gt;In all seriousness, his plugin collection is amazing and I can highly recommend you to check it out if you are using vim. He might be the next tpope!&lt;/p&gt;
&lt;h2 id=&#34;tldr&#34;&gt;tl;dr&lt;/h2&gt;
&lt;p&gt;hardtime for vim made me go back into vim territory and NeoVim made me stay.&lt;/p&gt;
&lt;p&gt;If you are a gvim guy like me, check out &lt;a href=&#34;https://github.com/equalsraf/neovim-qt&#34;&gt;neovim-qt&lt;/a&gt;. It is a lot faster performance wise and more stable than &lt;a href=&#34;https://github.com/rogual/neovim-dot-app&#34;&gt;Neovim.app&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Also my &lt;a href=&#34;https://github.com/dvcrn/dotfiles/tree/master/vim/nvim&#34;&gt;nvim dotfiles&lt;/a&gt; are a great starting point to get into vim. Everything is written very decoupled so you could just use whatever modules / packages you want and not source the rest.&lt;/p&gt;
&lt;p&gt;Do I now use vim for everyting? Nah, probably not. proton is still my main weapon. These days I&amp;rsquo;m on a VIM streak with the goal to master the more advanced text navigation commands but most of time time proton (if the atom-shell wouldn&amp;rsquo;t suck so much battery&amp;hellip;.).&lt;/p&gt;
&lt;p&gt;Let me know your thoughts &lt;a href=&#34;https://twitter.com/davicorn&#34;&gt;on twitter&lt;/a&gt;.&lt;/p&gt;
</description>
      <content:encoded><![CDATA[<p>It’s weird that I am writing about editors so much but trying a new editor every few months kind of
became a tradition. It spices things up and allows me to learn something new that I maybe didn’t know yet before. Or just discover a new tool that improves my workflow.</p>
<p>When I wrote about spacemacs, I thought spacemacs would be the thing that I would use for everything. Then I ported it to atom with <a href="https://github.com/dvcrn/proton">proton</a> and thought that would be the tool I would be using for everything since I could just implement features on the spot that it didn’t have yet. So what happened that I am writing about editors again?</p>
<p>As a VIM fan, I like micro optimizations. One thing in my workflow that I couldn’t stand was hammering <code>j</code> <code>j</code> <code>j</code> <code>j</code> to go down instead of <code>4j</code>. I knew this keybinding was a lot faster, I just couldn’t get to teach myself to actually use it. After a bit of research I couldn’t find anything that helps me inside atom or emacs - but I found <a href="https://github.com/wikitopian/hardmode">hardmode for vim</a>. It was a bit overkill since it disables all <code>hjkl</code> keys but a good start. Then I found <a href="https://github.com/takac/vim-hardtime">hardtime</a> and it was like my prayers have been answered 🙏. It allows me to use <code>hjkl</code> exactly x times - and I can specify how much x is! Only problem - I need to use raw VIM.</p>
<h2 id="hello-neovim-again">Hello NeoVim (again)</h2>
<p>Instead of vim though I grabbed NeoVim as my weapon of choice. Stuffed in my old config file just… to realize that things are not working the way I want them to. Plugins were outdated, keybindings were ‘meh’ and my <a href="https://github.com/dvcrn/dotfiles/blob/master/vim/.vimrc">old vimrc</a> a complete mess. How were I ever able to work with this??</p>
<p>It had to go and something new had to be in it’s place, so I opened up a new vim pane and started hacking on my new vimrc with the goal that everything I use should be heavily optimized, consistent and use NeoVims async features if possible. No more <a href="https://github.com/scrooloose/syntastic">syntastic</a> lags on linting - <a href="https://github.com/benekastah/neomake">neomake</a> runs completely async!</p>
<p>I replaced vundle with the async <a href="https://github.com/junegunn/vim-plug">vim-plug</a> and re-added crucial packages that I needed - but something was still missing. I can’t just assign random leader keybindings after having such a blast with the spacemacs mnemonic. After changing the leader to <code>&lt;SPC&gt;</code> and re-arranging the keybindings a bit I was quite surprised to see what I ended up doing - <a href="https://github.com/dvcrn/dotfiles/blob/master/vim/nvim/keybindings.vim#L70-L112">re-creating mnemonic keybindings in vim</a>! I also went the extra steps and moved everything related into a package of some sorts. A bit of sourcing here and there and suddenly <a href="https://github.com/dvcrn/dotfiles/blob/master/vim/nvim/.nvimrc#L79-L104">I had “layers”</a>! Just like in proton or spacemacs!</p>
<h2 id="quality-plugins-ahead">Quality plugins ahead</h2>
<p>What eventually got me really into vim were probably the amazing plugins of <a href="https://github.com/junegunn/">junegunn</a>, the guy that wrote vim-plug. I am absolutely impressed about the quality of these and didn’t have this much fun with vim for a long time. Stuff like <a href="https://github.com/junegunn/fzf">fzf</a> makes almost every command feel consistent.</p>
<p>He even wrote a color scheme using the official colors of probably my favorite city on the planet - <a href="https://github.com/junegunn/seoul256.vim">Seoul</a>. Just look how pretty it is:</p>
<p>
<img class="img-fluid" src="./neovim-1.png" alt="screenshot" />

</p>
<p>In all seriousness, his plugin collection is amazing and I can highly recommend you to check it out if you are using vim. He might be the next tpope!</p>
<h2 id="tldr">tl;dr</h2>
<p>hardtime for vim made me go back into vim territory and NeoVim made me stay.</p>
<p>If you are a gvim guy like me, check out <a href="https://github.com/equalsraf/neovim-qt">neovim-qt</a>. It is a lot faster performance wise and more stable than <a href="https://github.com/rogual/neovim-dot-app">Neovim.app</a>.</p>
<p>Also my <a href="https://github.com/dvcrn/dotfiles/tree/master/vim/nvim">nvim dotfiles</a> are a great starting point to get into vim. Everything is written very decoupled so you could just use whatever modules / packages you want and not source the rest.</p>
<p>Do I now use vim for everyting? Nah, probably not. proton is still my main weapon. These days I&rsquo;m on a VIM streak with the goal to master the more advanced text navigation commands but most of time time proton (if the atom-shell wouldn&rsquo;t suck so much battery&hellip;.).</p>
<p>Let me know your thoughts <a href="https://twitter.com/davicorn">on twitter</a>.</p>
]]></content:encoded>
    </item>
    
    <item>
      <title>Sweet, sweet Elixir - the language of my dreams?</title>
      <link>https://david.coffee/sweet-sweet-elixir-the-language-of-my-dreams/</link>
      <pubDate>Fri, 22 Jan 2016 10:30:23 +0000</pubDate>
      
      <guid>https://david.coffee/sweet-sweet-elixir-the-language-of-my-dreams/</guid><description>&lt;p&gt;I like learning new languages, I think that’s no secret. It’s a fun task that teaches you new interesting takes on existing problems. A language can make your programmers life very easy but could also turn it into a living hell. In fact, I am always on the hunt to find the &lt;em&gt;perfect&lt;/em&gt; language for me. That thing that I &lt;strong&gt;want&lt;/strong&gt; to use for everything.&lt;/p&gt;
&lt;h3 id=&#34;meet-clojurescript&#34;&gt;Meet ClojureScript&lt;/h3&gt;
&lt;p&gt;Lately I’ve been doing a lot of clojure. I am glad that I finally arrived at a point where I don’t have to look into the documentation just to find out how to append something to a vector. Clojure is &lt;strong&gt;extremely well&lt;/strong&gt; designed. I learned a lot just by listening to talks (especially the rich hickey ones!) and reading about the languages&amp;rsquo; core concepts and the reasons behind them. But above all, Clojure is just fun to use and ClojureScript is even more fun! I love using it and even wrote a &lt;a href=&#34;https://github.com/dvcrn/markright&#34;&gt;MarkDown editor&lt;/a&gt; in it. Lately clojurescript ended up becoming the magic that fueles my &lt;a href=&#34;https://github.com/dvcrn/proton&#34;&gt;entire main editor&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;What’s amazing about ClojureScript is that it can literally go everywhere javascript can go and man can javascript go to places these days. I even started to build freaking &lt;a href=&#34;https://dvcrn.github.io/clojurescript/react/2015/11/19/my-cljs-talk.html&#34;&gt;native apps&lt;/a&gt; with it! Imagine I would tell that to someone a few years back:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;A: Oh that app looks cool. How did you build it?
B: Ah I’m using clojurescript to control the native view properties.
A: cloj… what?
B: Yeah, it cross compiles to javascript.
A: Javascript? native?
B: Javascript is then using react native to bridge into ObjC
A: 😮
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I like clojurescript to that degree that I start to feel bothered if someone asks me to write raw javascript these days. I like it that much.&lt;/p&gt;
&lt;h3 id=&#34;clojure&#34;&gt;Clojure&lt;/h3&gt;
&lt;p&gt;The only thing I am not 100% happy with right now is… well… clojure! I tried a few times to use it on the serverside but it just never felt completely right to me. I ended up searching all these little building blocks like migrations, database connections, router and templating, and proceeded to stack them together… somehow.&lt;/p&gt;
&lt;p&gt;Then there was the big problem of libraries getting abandoned. Here’s a example: When I wrote my first server it took me ages to find &lt;a href=&#34;https://github.com/budu/lobos&#34;&gt;lobos&lt;/a&gt; - the migration library everyone told me to use. Shortly after, it turned inactive and communication around it died. Suddenly noone wanted to use lobos. A few questions here and there and people told me to &lt;em&gt;just&lt;/em&gt; write SQL files and pipe them with clojure into the db.&lt;/p&gt;
&lt;p&gt;Clojure people feel to me like these people that like to build stuff raw and by themselves. To have full control over every aspect and if a building block doesn&amp;rsquo;t exist yet - it will just get written on the spot.
My server eventually worked and that is what counts, right? But I wasn’t happy maintaining it. All these lego bricks felt glued together in a not stable way.&lt;/p&gt;
&lt;p&gt;So I kept going on my way, sometimes using clojure, but most of the times django for my server stuff. I kept adding things to my &lt;em&gt;you-should-check-that-out-list&lt;/em&gt; including Go, Rust, and a few frameworks here and there, just waiting for me to have some more free time.&lt;/p&gt;
&lt;p&gt;A few days ago I wanted to start a new side project - an app to be specific. My fingers were itching to do a real world app in clojurescript but needed something for the server. I started mocking things up with django but then took a short look at my list. On first place was something called &lt;em&gt;elixir&lt;/em&gt;. “Elixir, huh?”, I thought and opened the website&lt;/p&gt;
&lt;h3 id=&#34;hello-elixir&#34;&gt;Hello Elixir&lt;/h3&gt;
&lt;p&gt;When I first checked out Elixir I didn’t think of much. Looks like ruby and feels like ruby with a bit of clojure sugar sprinkled in. The &lt;code&gt;|&amp;gt;&lt;/code&gt; operator is obviously taken straight out it. Atoms are no longer state containers but now what I would call… a keyword? In any way, being a functional language inspired by clojure and coming directly &lt;em&gt;from&lt;/em&gt; clojure I felt home right away.&lt;/p&gt;
&lt;p&gt;I downloaded &lt;a href=&#34;http://www.phoenixframework.org&#34;&gt;phoenix&lt;/a&gt;, figured out &lt;a href=&#34;https://github.com/elixir-lang/ecto&#34;&gt;ecto&lt;/a&gt;, hacked my API server together and went on with my app. That was until I had to implement a image upload and resize service to s3.&lt;/p&gt;
&lt;p&gt;My django instinct told me to find the &lt;a href=&#34;http://celeryproject.org&#34;&gt;celery&lt;/a&gt; of the elixir world but what came next completely changed my way I looked at the language.&lt;/p&gt;
&lt;p&gt;You see - I didn’t read the entire documentation on elixir-lang (which I should have done). I wanted to get a feel for the language first before going into all the little details. When I asked on the elixir slack for the idiomatic way of implementing a worker I got pointed to the &lt;a href=&#34;http://elixir-lang.org/getting-started/processes.html&#34;&gt;processes&lt;/a&gt;, &lt;a href=&#34;http://elixir-lang.org/getting-started/mix-otp/agent.html&#34;&gt;agents&lt;/a&gt; and &lt;a href=&#34;http://elixir-lang.org/getting-started/mix-otp/genserver.html&#34;&gt;genserver&lt;/a&gt; guides.&lt;/p&gt;
&lt;p&gt;I knew that elixir is running inside the erlang VM but I never used erlang before and all I knew about it was from hearing about it.&lt;/p&gt;
&lt;h3 id=&#34;mind--&#34;&gt;Mind = 💥&lt;/h3&gt;
&lt;p&gt;To summarise it very short: The concurrency handling of elixir is just effing amazing. Without any troubles and at any time you can spin up subprocesses, pass stuff to them, link them together and build your little network.&lt;/p&gt;
&lt;p&gt;Processes are completely isolated and very well managed. I never had the feeling that using processes will now lock me into a big headache network of synchronisation, orchestration and possible chaos. And even if something goes wrong - elixir and erlang actually &lt;em&gt;encourage&lt;/em&gt; you to let things fail! No try/catch blocks and exception handling. You just let the process fail and the supervisor will take care of troubleshooting and restart that thing - just like that!&lt;/p&gt;
&lt;p&gt;Here’s an example that really shows how powerful this is: State management! The recommended way of storing state in elixir is… a process! You have a process that holds your piece of state and reacts to defined messages passed to it: e.g. &lt;em&gt;store&lt;/em&gt; and &lt;em&gt;retrieve&lt;/em&gt;. I mean… what?!&lt;/p&gt;
&lt;p&gt;If you now connect another node to your mesh network, that node could immediately send messages to the same state management process if it knows it’s identifier (e.g. &lt;code&gt;:kwstore1&lt;/code&gt;). Just like that you suddenly have state management - but synchronised on multiple machines… I mean… what?!?!&lt;/p&gt;
&lt;h3 id=&#34;the-joy-of-concurrency-and-even-more---&#34;&gt;The joy of concurrency and even more 😮 = 💥&lt;/h3&gt;
&lt;p&gt;Elixir doesn’t care if you have 1 node or a thousand. It directly works with all of them right away.&lt;/p&gt;
&lt;p&gt;Let’s go back to my image upload and resize example: In django I would take the image, push it to s3, push a message into amqp / redis, tell the user “success” and let a worker process the resizing before marking the image as “processed” in a db. 3 components: Web server, queue server, worker.&lt;/p&gt;
&lt;p&gt;Now elixir. I take the image, put it on the disk and push the original to s3. I tell the user “success” but at the &lt;em&gt;same time&lt;/em&gt; spin up a child process with the reference to image on the disk. The user gets his “success” but the child process lives on! It does it’s resizing stuff, uploads to s3, updates the db and if something goes wrong like a timeout from s3, then so what? It just crashes, the supervisor restarts the process and it tries again. All while the user is already gone! Without a queue! Without a worker! Out of the box!&lt;/p&gt;
&lt;p&gt;To give that more context, on heroku with django I would have to scale up another worker process (costs $), add a amqp server (even more $) and let everything run at the same time. On heroku with elixir I can literally have all of that inside a free dyno! I could even spin up 50 worker processes and it could still run inside the same free dyno without a cent extra if I am nice with memory.&lt;/p&gt;
&lt;p&gt;And you know actually how easy it is to spawn a simple child process?&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;spawn fn -&amp;gt;
	IO.puts “Hello from Child”
end
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;But I’m just scratching the surface of this amazing language. Phoenix for example has built in support for websockets, you know what this means when it comes to elixir? You could connect to server1, I could connect to server98934 which is part of the same mesh and we could &lt;strong&gt;still&lt;/strong&gt; chat with each other without any extra work!&lt;/p&gt;
&lt;p&gt;Elixir made it damn appealing to use concurrency programming. I never fear that I will break something essential because it is just this well done. It is designed that it actually encourages you to use these features more often - because seriously, why wouldn’t you?&lt;/p&gt;
&lt;h3 id=&#34;scripted-elixir&#34;&gt;Scripted Elixir&lt;/h3&gt;
&lt;p&gt;Amazing syntax, functional programming, REPL driven development, unbeatable concurrency model - how could you make this language even more attractive? I will tell you how:&lt;/p&gt;
&lt;p&gt;Elixir has 2 ways of executing your code: Pre-compiled and scripted. Pre-compiled means that once you are ready to run your app you tell elixir (or mix) to compile everything down and execute it. But what could &lt;em&gt;scripted&lt;/em&gt; mean?&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;[i] λ elixir -e ‘IO.puts “Hello World”’
Hello World
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;…that’s what it means! Elixir comes with a &lt;a href=&#34;http://elixir-lang.org/getting-started/modules.html#scripted-mode&#34;&gt;scripted mode&lt;/a&gt; that compiles your code on the spot in memory before executing it! No slow spinning up java to execute your clojure code or compile it into javascript. Executing elixir in scripted mode takes 1 second at max and doesn’t require you to have anything set up. No project, no mix - nothing.&lt;/p&gt;
&lt;h3 id=&#34;the-language-of-my-dreams&#34;&gt;The language of my dreams?&lt;/h3&gt;
&lt;p&gt;I know it is too early to judge but I really like Elixir. I didn’t have this much fun programming on the server since I initially discovered django. Pair Elixir on the server with clojurescript on the client and you have the stack of my dreams - powerful and fun programming on the client and server at the same time (let’s call it &lt;em&gt;dave-stack&lt;/em&gt;).&lt;/p&gt;
&lt;p&gt;I will continue my journey with Elixir. If you didn’t check it out - I highly urge you to do so. It could very easily become the next ruby in a very short time.&lt;/p&gt;
</description>
      <content:encoded><![CDATA[<p>I like learning new languages, I think that’s no secret. It’s a fun task that teaches you new interesting takes on existing problems. A language can make your programmers life very easy but could also turn it into a living hell. In fact, I am always on the hunt to find the <em>perfect</em> language for me. That thing that I <strong>want</strong> to use for everything.</p>
<h3 id="meet-clojurescript">Meet ClojureScript</h3>
<p>Lately I’ve been doing a lot of clojure. I am glad that I finally arrived at a point where I don’t have to look into the documentation just to find out how to append something to a vector. Clojure is <strong>extremely well</strong> designed. I learned a lot just by listening to talks (especially the rich hickey ones!) and reading about the languages&rsquo; core concepts and the reasons behind them. But above all, Clojure is just fun to use and ClojureScript is even more fun! I love using it and even wrote a <a href="https://github.com/dvcrn/markright">MarkDown editor</a> in it. Lately clojurescript ended up becoming the magic that fueles my <a href="https://github.com/dvcrn/proton">entire main editor</a>.</p>
<p>What’s amazing about ClojureScript is that it can literally go everywhere javascript can go and man can javascript go to places these days. I even started to build freaking <a href="https://dvcrn.github.io/clojurescript/react/2015/11/19/my-cljs-talk.html">native apps</a> with it! Imagine I would tell that to someone a few years back:</p>
<pre tabindex="0"><code>A: Oh that app looks cool. How did you build it?
B: Ah I’m using clojurescript to control the native view properties.
A: cloj… what?
B: Yeah, it cross compiles to javascript.
A: Javascript? native?
B: Javascript is then using react native to bridge into ObjC
A: 😮
</code></pre><p>I like clojurescript to that degree that I start to feel bothered if someone asks me to write raw javascript these days. I like it that much.</p>
<h3 id="clojure">Clojure</h3>
<p>The only thing I am not 100% happy with right now is… well… clojure! I tried a few times to use it on the serverside but it just never felt completely right to me. I ended up searching all these little building blocks like migrations, database connections, router and templating, and proceeded to stack them together… somehow.</p>
<p>Then there was the big problem of libraries getting abandoned. Here’s a example: When I wrote my first server it took me ages to find <a href="https://github.com/budu/lobos">lobos</a> - the migration library everyone told me to use. Shortly after, it turned inactive and communication around it died. Suddenly noone wanted to use lobos. A few questions here and there and people told me to <em>just</em> write SQL files and pipe them with clojure into the db.</p>
<p>Clojure people feel to me like these people that like to build stuff raw and by themselves. To have full control over every aspect and if a building block doesn&rsquo;t exist yet - it will just get written on the spot.
My server eventually worked and that is what counts, right? But I wasn’t happy maintaining it. All these lego bricks felt glued together in a not stable way.</p>
<p>So I kept going on my way, sometimes using clojure, but most of the times django for my server stuff. I kept adding things to my <em>you-should-check-that-out-list</em> including Go, Rust, and a few frameworks here and there, just waiting for me to have some more free time.</p>
<p>A few days ago I wanted to start a new side project - an app to be specific. My fingers were itching to do a real world app in clojurescript but needed something for the server. I started mocking things up with django but then took a short look at my list. On first place was something called <em>elixir</em>. “Elixir, huh?”, I thought and opened the website</p>
<h3 id="hello-elixir">Hello Elixir</h3>
<p>When I first checked out Elixir I didn’t think of much. Looks like ruby and feels like ruby with a bit of clojure sugar sprinkled in. The <code>|&gt;</code> operator is obviously taken straight out it. Atoms are no longer state containers but now what I would call… a keyword? In any way, being a functional language inspired by clojure and coming directly <em>from</em> clojure I felt home right away.</p>
<p>I downloaded <a href="http://www.phoenixframework.org">phoenix</a>, figured out <a href="https://github.com/elixir-lang/ecto">ecto</a>, hacked my API server together and went on with my app. That was until I had to implement a image upload and resize service to s3.</p>
<p>My django instinct told me to find the <a href="http://celeryproject.org">celery</a> of the elixir world but what came next completely changed my way I looked at the language.</p>
<p>You see - I didn’t read the entire documentation on elixir-lang (which I should have done). I wanted to get a feel for the language first before going into all the little details. When I asked on the elixir slack for the idiomatic way of implementing a worker I got pointed to the <a href="http://elixir-lang.org/getting-started/processes.html">processes</a>, <a href="http://elixir-lang.org/getting-started/mix-otp/agent.html">agents</a> and <a href="http://elixir-lang.org/getting-started/mix-otp/genserver.html">genserver</a> guides.</p>
<p>I knew that elixir is running inside the erlang VM but I never used erlang before and all I knew about it was from hearing about it.</p>
<h3 id="mind--">Mind = 💥</h3>
<p>To summarise it very short: The concurrency handling of elixir is just effing amazing. Without any troubles and at any time you can spin up subprocesses, pass stuff to them, link them together and build your little network.</p>
<p>Processes are completely isolated and very well managed. I never had the feeling that using processes will now lock me into a big headache network of synchronisation, orchestration and possible chaos. And even if something goes wrong - elixir and erlang actually <em>encourage</em> you to let things fail! No try/catch blocks and exception handling. You just let the process fail and the supervisor will take care of troubleshooting and restart that thing - just like that!</p>
<p>Here’s an example that really shows how powerful this is: State management! The recommended way of storing state in elixir is… a process! You have a process that holds your piece of state and reacts to defined messages passed to it: e.g. <em>store</em> and <em>retrieve</em>. I mean… what?!</p>
<p>If you now connect another node to your mesh network, that node could immediately send messages to the same state management process if it knows it’s identifier (e.g. <code>:kwstore1</code>). Just like that you suddenly have state management - but synchronised on multiple machines… I mean… what?!?!</p>
<h3 id="the-joy-of-concurrency-and-even-more---">The joy of concurrency and even more 😮 = 💥</h3>
<p>Elixir doesn’t care if you have 1 node or a thousand. It directly works with all of them right away.</p>
<p>Let’s go back to my image upload and resize example: In django I would take the image, push it to s3, push a message into amqp / redis, tell the user “success” and let a worker process the resizing before marking the image as “processed” in a db. 3 components: Web server, queue server, worker.</p>
<p>Now elixir. I take the image, put it on the disk and push the original to s3. I tell the user “success” but at the <em>same time</em> spin up a child process with the reference to image on the disk. The user gets his “success” but the child process lives on! It does it’s resizing stuff, uploads to s3, updates the db and if something goes wrong like a timeout from s3, then so what? It just crashes, the supervisor restarts the process and it tries again. All while the user is already gone! Without a queue! Without a worker! Out of the box!</p>
<p>To give that more context, on heroku with django I would have to scale up another worker process (costs $), add a amqp server (even more $) and let everything run at the same time. On heroku with elixir I can literally have all of that inside a free dyno! I could even spin up 50 worker processes and it could still run inside the same free dyno without a cent extra if I am nice with memory.</p>
<p>And you know actually how easy it is to spawn a simple child process?</p>
<pre tabindex="0"><code>spawn fn -&gt;
	IO.puts “Hello from Child”
end
</code></pre><p>But I’m just scratching the surface of this amazing language. Phoenix for example has built in support for websockets, you know what this means when it comes to elixir? You could connect to server1, I could connect to server98934 which is part of the same mesh and we could <strong>still</strong> chat with each other without any extra work!</p>
<p>Elixir made it damn appealing to use concurrency programming. I never fear that I will break something essential because it is just this well done. It is designed that it actually encourages you to use these features more often - because seriously, why wouldn’t you?</p>
<h3 id="scripted-elixir">Scripted Elixir</h3>
<p>Amazing syntax, functional programming, REPL driven development, unbeatable concurrency model - how could you make this language even more attractive? I will tell you how:</p>
<p>Elixir has 2 ways of executing your code: Pre-compiled and scripted. Pre-compiled means that once you are ready to run your app you tell elixir (or mix) to compile everything down and execute it. But what could <em>scripted</em> mean?</p>
<pre tabindex="0"><code>[i] λ elixir -e ‘IO.puts “Hello World”’
Hello World
</code></pre><p>…that’s what it means! Elixir comes with a <a href="http://elixir-lang.org/getting-started/modules.html#scripted-mode">scripted mode</a> that compiles your code on the spot in memory before executing it! No slow spinning up java to execute your clojure code or compile it into javascript. Executing elixir in scripted mode takes 1 second at max and doesn’t require you to have anything set up. No project, no mix - nothing.</p>
<h3 id="the-language-of-my-dreams">The language of my dreams?</h3>
<p>I know it is too early to judge but I really like Elixir. I didn’t have this much fun programming on the server since I initially discovered django. Pair Elixir on the server with clojurescript on the client and you have the stack of my dreams - powerful and fun programming on the client and server at the same time (let’s call it <em>dave-stack</em>).</p>
<p>I will continue my journey with Elixir. If you didn’t check it out - I highly urge you to do so. It could very easily become the next ruby in a very short time.</p>
]]></content:encoded>
    </item>
    
  </channel>
</rss>
