<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ville on Medium]]></title>
        <description><![CDATA[Stories by Ville on Medium]]></description>
        <link>https://medium.com/@efexen?source=rss-d3ac379287b2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*luWA1mfLN96wIxTSqotujA.jpeg</url>
            <title>Stories by Ville on Medium</title>
            <link>https://medium.com/@efexen?source=rss-d3ac379287b2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 18:12:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@efexen/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Keeping it short]]></title>
            <link>https://medium.com/@efexen/keeping-it-short-8d1cdeca076a?source=rss-d3ac379287b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/8d1cdeca076a</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[refactoring]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[technical-debt]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Ville]]></dc:creator>
            <pubDate>Wed, 15 Aug 2018 08:55:53 GMT</pubDate>
            <atom:updated>2018-08-15T08:56:35.759Z</atom:updated>
            <content:encoded><![CDATA[<h4>Tips for making and keeping your functions small</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QRbu9V6pGyvzUrYFr9jS6A.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/jl8x6XpE8Y4?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Evan Kirby</a> on <a href="https://unsplash.com/search/photos/different?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Using Lines of Code (LoC) for measuring developer productivity is a well known poor metric; roughly equivalent to measuring success in building aeroplanes by weight of the planes produced.</p><p>However looking into LoC in a code base can be a powerful proxy for technical debt issues and issues of complexity when considering a single file, class, module or a function.</p><p>Long functions or methods typically violate good coding practices by exhibiting the following issues</p><ul><li>They have too much functionality in a given scope and increase the cognitive load required for the person reading the code</li><li>Long functions make it difficult to re-use code effectively</li><li>Effective testing may become difficult as the individual parts of the function are hard to isolate</li><li>They become increasingly difficult to change without introducing errors</li><li>Lack of effective shared state management as many unrelated variables can be changed in a single scope</li></ul><p>In this short article I want to cover some basic tips and techniques that you can apply to existing code bases to refactor long functions. More importantly you can apply these as you are writing your code preventing the technical debt accruing in the first place.</p><blockquote>Much like financial debt, technical debt is cheapest to pay off closest to the moment of creation and sometimes it can be nearly free by not creating it in the first place.</blockquote><h4>Extract a function</h4><p>This is by far the easiest way to keep the size of your functions small and might seem almost trivial but it provides other benefits you may not consider initially.</p><p>When adding a piece of functionality, rather than appending the code to the bottom of the current function, why not create a new function with that added functionality, a descriptive name and call it from the function that was initially to receive the code instead.</p><p>Say we had the following simple function for finding an area of a rectangle</p><pre>function area(rectangle) {<br>  return rectangle.width * rectangle.height;<br>}</pre><p>If we then get asked to add something such as simple logging we could do this</p><pre>function area(rectangle) {<br>  console.log(&quot;Width: &quot; + rectangle.width);<br>  console.log(&quot;Height: &quot; + rectangle.height);<br>  return rectangle.width * rectangle.height;<br>}</pre><p>This is probably fine as we still only have less than a handful of lines but for the sake of this point we could instead do this</p><pre>function area(rectangle) {<br>  logDimensions(rectangle);<br>  return rectangle.width * rectangle.height;<br>}</pre><pre>function logDimensions(shape) {<br>  console.log(&quot;Width: &quot; + shape.width);<br>  console.log(&quot;Height: &quot; + shape.height);<br>}</pre><p>Our total number of lines has increased but our functions have remained small which was our aim. Also you might notice we’ve created a reusable function to log dimensions that could be helpful for other functions we might implement.</p><p>Most importantly for me though we’ve made reading the area function easier, I can quickly decide whether I’m interested in the logging part of the code, if not I can skip over the single line rather than attempting to interpret what the code is trying to accomplish.</p><p>Say we had the following naive function for turning a traffic light from red to green.</p><p>Let’s look at how we could use this for an existing piece of code</p><pre>function changeRedToGreen() {<br>  // Reset all lights<br>  setLight(RED_LIGHT, false);<br>  setLight(YELLOW_LIGHT, false);<br>  setLight(GREEN_LIGHT, false);<br>  <br>  // Set to Red + Yellow<br>  setLight(RED_LIGHT, true);<br>  setLight(YELLOW_LIGHT, true);<br>  <br>  // Start timer to set Green<br>  setTimeout(function() {<br>    setLight(RED_LIGHT, false);<br>    setLight(YELLOW_LIGHT, false);<br>    setLight(GREEN_LIGHT, true);  <br>  }, 4000);<br>}</pre><p>By extracting some methods we could reduce this to</p><pre>function changeRedToGreen() {<br>  resetLights();<br>  setStandbyLights(true);<br>  <br>  setTimeout(function() {<br>    setStandbyLights(false);<br>    setLight(GREEN_LIGHT, true);<br>  }, 4000);<br>}</pre><pre>function resetLights() {<br>  setLight(RED_LIGHT, false);<br>  setLight(YELLOW_LIGHT, false);<br>  setLight(GREEN_LIGHT, false);<br>}</pre><pre>function setStandbyLights(state) {<br>  setLight(RED_LIGHT, state);<br>  setLight(YELLOW_LIGHT, state);<br>}</pre><p>We started with 14 lines (17 with comments) and ended up with 20 total. Our longest function however went from 12 to 7 which is a very nice reduction.</p><p>You might have also noticed that I removed the comments after having chosen descriptive function names instead.</p><h4>Extracting an anonymous function</h4><p>Many modern languages also allow for anonymous inline functions as we saw in the traffic light example above</p><pre>setTimeout(function() {<br>  setStandbyLights(false);<br>  setLight(GREEN_LIGHT, true);<br>}, 4000);</pre><p>Whilst very useful; I’ve found that they are often a main culprit for long hard to read functions as we hide actions and concepts that could be better named and extracted out.</p><p>Let’s do this bit of refactoring for our traffic light code from above</p><pre>function changeRedToGreen() {<br>  resetLights();<br>  setStandbyLights(true);<br>  <br>  setTimeout(setOnlyGreen, 4000);<br>}</pre><pre>function setOnlyGreen() {<br>  setStandbyLights(false);<br>  setLight(GREEN_LIGHT, true);<br>}</pre><pre>...</pre><p>In this scenario we’ve only increased our total line count by 1 but our longest function is now only 3 lines long.</p><p>Passing a named function instead of an anonymous inline one makes the intent explicit and means we don’t have to analyse the contents to determine whether or not it is of interest to us.</p><h4>Is my function too long?</h4><p>How long is too long? That depends on a number of factors ranging from the language you are working in to the business domain and team preferences.</p><p>Personally for me when working with modern expressive programming languages around 5 lines is a good length that’s easily achievable.</p><p>There are some easy to spot indicators that might hint at a function that is too long:</p><ul><li>Use of comments to describe separate parts of the function, such as the original light example above</li><li>Long nested blocks of code, such as several lines of code in each branch of a conditional</li><li>Deep nesting or inline functions, these tend to hint at a concept that could be named separately</li><li>Multiple responsibilities, if you were to describe what the function does and use the word “and” it’s likely to be doing too many things</li><li>Distinct separation of multiple segments in the function by white space</li></ul><p>With these two very simple extractions you should be able to not just keep your functions short but also make your code more expressive and easier to reason about.</p><p>What I really like about these techniques is that you should be able to apply both of these to new code quickly to prevent long functions in the first place but also to your existing code without undertaking extensive refactoring or restructuring of your code.</p><blockquote>Finally don’t be fooled by the simplicity, small improvements like these are at the core of a high quality code base.</blockquote><p>I’d love to hear about your experiences with keeping your functions short, I’m planning the next part with more advanced techniques so if you have a technique or a tip to share get in touch.</p><p>Thanks for reading and please click the 👏 icon below if you liked this post and if Code Quality is of interest to you follow me here and on Twitter <a href="https://twitter.com/efexen">@efexen</a> If you haven’t already can I recommend checking out some of my other posts and let me know what you think 👍</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8d1cdeca076a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Periodic tasks with Elixir — Part 2]]></title>
            <link>https://medium.com/@efexen/periodic-tasks-with-elixir-part-2-8aaee425aed0?source=rss-d3ac379287b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/8aaee425aed0</guid>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[functional-programming]]></category>
            <dc:creator><![CDATA[Ville]]></dc:creator>
            <pubDate>Sun, 31 Dec 2017 00:14:42 GMT</pubDate>
            <atom:updated>2017-12-31T00:14:42.630Z</atom:updated>
            <content:encoded><![CDATA[<h4>Alternative implementation and dealing with drift</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8zGDZwWuVTjLCpXQsVr9ag.jpeg" /></figure><p>My post about performing recurring or periodic tasks in Elixir using receive timeouts and Tasks couple of weeks ago sparked quite a few conversations which was amazing! Thank you to everyone here on Medium, Twitter and in Reddit for sharing your experiences and suggesting alternatives.</p><p>Two of the things that came up most was using Process.send_after and concerns about drift caused by execution of the work. We’ll look at both of these in this post.</p><p>If you haven’t checked out the first post yet you can find it here: <a href="https://medium.com/@efexen/periodic-tasks-with-elixir-5d9050bcbdb3">Periodic tasks with Elixir</a></p><h4>Process.send_after/3</h4><p>As soon as I had posted the first part couple of my colleagues immediately asked if there was a reason I’d not used Process.send_after/3 instead. I have to admit that I wasn’t even aware this existed.</p><p>Replicating a similar barebones module we developed in the first part would look like this</p><pre>defmodule Periodic.Safter do<br>  use GenServer</pre><pre>  def start_link() do<br>    GenServer.start_link(__MODULE__, %{})<br>  end</pre><pre>  def init(state) do<br>    schedule_work()<br>    {:ok, state}<br>  end</pre><pre>  def handle_info(:work, state) do<br>    # do important stuff<br>    IO.puts &quot;Important stuff in progress...&quot;<br>    schedule_work()<br>    {:noreply, state}<br>  end</pre><pre>  defp schedule_work() do<br>    Process.send_after(self(), :work, 1_000)<br>  end</pre><pre>end</pre><p>It appears this is originally from a <a href="https://stackoverflow.com/a/32097971">stackoverflow answer</a> by Jose Valim in 2015 it also appears in the GenServer docs for <a href="https://hexdocs.pm/elixir/GenServer.html#module-receiving-regular-messages">Receive regular messages</a></p><p>Very similar at first look and without a deep dive under the hood I’d imagine they work the same way as well so for me it comes down to semantics.</p><p>For the simplest use cases and where we don’t need to track state I’d still lean toward the original. Trading the ceremony of state handling that comes with GenServer with the empty receive block.</p><h4>Dealing with drift</h4><p>Both of the techniques used so far suffer from drift in time where the execution time of the work to be done shifts the start of the next.</p><p>Say we wanted to do a piece of work every 1 second but the work we are doing takes 100 milliseconds to complete. After 10 seconds elapsed we would have only done the work 9 times as each execution was shifted.</p><p>Most of the time the simplest thing you can do is just spawn a separate process to perform the work and let the current process get back to scheduling the next piece of work.</p><p>Let’s take out GenServer example from earlier</p><pre>def handle_info(:work, state) do<br>  # do important stuff<br>  IO.puts &quot;Important stuff in progress...&quot;<br>  schedule_work()<br>  {:noreply, state}<br>end</pre><p>We can simply do this instead</p><pre>def handle_info(:work, state) do<br>  spawn_link(&amp;do_work/0)<br>  schedule_work()<br>  {:noreply, state}<br>end</pre><pre>defp do_work() do<br>  # do important stuff<br>  IO.puts &quot;Important stuff in progress...&quot;<br>end</pre><p>By using spawn_link/1 we keep the same behavior as before in terms of exit signal handling and what happens if the code that does the work crashes.</p><p>Spawning processes is super fast in Elixir so this should all but mitigate your drift. For fun I decided to test out how long the spawn_link/1 takes in the above example and it was about 10 microseconds on average 😍 Quick back of envelope math would suggest a drift of 1 second after 100,000 executions.</p><p>A more complex and a more accurate alternative would be to store the time of last execution in the GenServer state and work out the amount of drift and then use this as argument for the nextschedule_work call so it can be deducted from the wait time to compensate.</p><h4>Existing libraries</h4><p>Finally there’s of course some great packages around to solve this for you.</p><p><a href="https://github.com/erlware/erlcron">Erlcron</a> seems to be a popular Erlang choice and provides easy(ish) to read job descriptions like these:</p><pre>{{once, 3600},<br>    {io, fwrite, [&quot;Hello, world!~n&quot;]}}<br><br>{{daily, {every, {23, sec}, {between, {3, pm}, {3, 30, pm}}}},<br>    {io, fwrite, [&quot;Hello, world!~n&quot;]}}</pre><p>Or <a href="https://github.com/c-rack/quantum-elixir">Quantum</a> for Elixir which appears to be well maintained and a popular choice. Quantum opts for describing your jobs in the config using the cron syntax</p><pre># Every minute<br>{&quot;* * * * *&quot;, {Heartbeat, :send, []}}</pre><pre># Runs every midnight:<br>{&quot;@daily&quot;, {Backup, :backup, []}}</pre><p>In the end both solutions seem to have some trade offs in terms of semantics that leave me still wanting a cleaner solution. Having surveyed the existing libraries I’m tempted to write a simple package for even cleaner syntax. Let me know if you’d be interested in that.</p><p>Hope these posts have helped you get some ideas on how you might tackle those periodic tasks in your next project and how to tackle the issue with drift.</p><p>Please click the 👏 icon below if you liked this post and follow me here or on Twitter <a href="https://twitter.com/efexen">@efexen</a> to hear about new articles. If you haven’t already can I recommend checking out some of my other posts and let me know what you think 👍</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8aaee425aed0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Incrementally moving to Elixir]]></title>
            <link>https://medium.com/@efexen/incrementally-moving-to-elixir-da1b25307684?source=rss-d3ac379287b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/da1b25307684</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[service-design]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Ville]]></dc:creator>
            <pubDate>Fri, 22 Dec 2017 12:42:36 GMT</pubDate>
            <atom:updated>2017-12-22T12:42:36.252Z</atom:updated>
            <content:encoded><![CDATA[<h4>Moving from a Rails monolith to Elixir services with queues</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SazUGxVN2vi5t30vCkaKSA.jpeg" /></figure><p>Like many working in a legacy Ruby system and learning Elixir we were struggling to figure out how to start moving our code over. Here I wanted to share a technique we used a year ago to start the process.</p><h4>Background</h4><p>At Fitzdares (a bookmakers) we have an ageing monolith of a system written in Rails over 7 or so years by various teams and contractors and much like the building above it’s starting to show it’s age and as is the case with many monoliths the responsibilities of the system started to include everything imaginable.</p><p>We decided we would focus our efforts on improving the code quality and performance for the core responsibilities of the system which for us were bet capturing and settling.</p><p>At the same time we would break out parts of the system that could and <em>should</em> live outside of the monolith.</p><h4>Finding a candidate context</h4><p>One such part was the task of processing one of our busier price data feeds.</p><p>The data feed is a push feed, very noisy requiring simple filtering to determine whether the data is of interest to us, spikey in traffic where we regularly go from ~30 updates per minute to 2000+ for a few minutes and then back down.</p><p>The old solution was using the <a href="https://github.com/thuehlinger/daemons">daemons gem</a> to spin up the full Rails environment, subscribe to the feed, do filtering, construct an ActiveRecord object and save to the database.</p><p>This was also running co-located on a beast of a server with a stack of other daemons and tasks.</p><p>Finally we had quite a few stability issues with the processing and resource competition on the server.</p><h4>Scoping out the work</h4><p>Having found a great candidate in need of attention and one with a set of properties that made it great use case for Elixir we were ecstatic!</p><p>We started picking the old code apart to figure out the size of the task</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/283/1*4ZZgxd4DFAmVqd3pNpkA3g.gif" /></figure><p>What we found was stacks of ActiveRecord Callbacks, auto updates to related models, ActiveRecord Observers etc 💔</p><p>The size of the task kept growing and growing with each part we opened up to a point where it was fast becoming a major undertaking that none of us felt comfortable estimating accurately.</p><h4>Incremental migration</h4><p>Most of the code up to the point of calling create on the record was of reasonable size and complexity.</p><p>We decided that we would write a new Elixir service to subscribe to the data feeds, process and filter the prices. Finally it would hand over persisting to the database to the old code.</p><p>Essentially we pulled out all the code before the call to create from the old codebase and wrote the new Elixir service to create a JSON object that has all the same values as the ActiveRecord object would have.</p><h4>Gluing the old and the new together</h4><p>This left us with a choice of how to do the handover from our new service to the old.</p><p>First option was to create a new HTTP API endpoint in the monolith or using something like gRPC but these both suffered from the same problem in that the core could still be brought to it’s knees when the spikes in activity happen.</p><p>We could have throttled sending the updates from the new service but that didn’t really feel like responsibility of the new service either.</p><p>As we already make extensive use of <a href="https://sidekiq.org/">Sidekiq</a> for all of our background processing tasks we decided to use that instead.</p><h4>Bringing it all together</h4><p>Our new Elixir service receives updates, spins up a new process for each update, majority of the processes we let die away as part of the filtering.</p><p>For the ones that survive we apply the secret sauce and then using the lovely <a href="https://github.com/whatyouhide/redix">Redix</a> Redis client by <a href="https://github.com/whatyouhide">Andrea Leopardi</a> we create a job in a new Sidekiq queue with the processed update as payload.</p><p>Back in the land of the monolith we created a new Sidekiq worker to pick jobs from this new queue and simply take the payload, map it to an ActiveRecord model and save it; firing all the callbacks, payloads and everything else.</p><p>This allowed us to use concurrence to filter out the noise from the feed, protect the core from the spikey traffic and ship the new service in a timely predictable manner leveraging existing infrastructure and setup.</p><h4>Moving forward</h4><p>Best part of this approach was that the story doesn’t end there! It allowed us to put something in place quickly and resolve some of the early issues.</p><p>Now it was trivial for us to pick each callback, observer action and other magic bit that happened as part of saving the record and move them across to the new service one by one as individual efforts rather than needing to do them all in one big project.</p><p>For me it felt like establishing a solid base camp close to the foot of the mountain and mapping out the rest of the journey through the camps to conquer the mountain rather than attempting the climb in one big push.</p><p>We’ve had great success doing this and I hope it’s given you ideas on how you might start moving code across in smaller chunks.</p><p>Please click the 👏 icon below if you liked this post and follow me here or on Twitter <a href="https://twitter.com/efexen">@efexen</a> to hear about new articles. If you haven’t already can I recommend checking out some of my other posts and let me know what you think 👍</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da1b25307684" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Periodic tasks with Elixir]]></title>
            <link>https://medium.com/@efexen/periodic-tasks-with-elixir-5d9050bcbdb3?source=rss-d3ac379287b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/5d9050bcbdb3</guid>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[elixir]]></category>
            <dc:creator><![CDATA[Ville]]></dc:creator>
            <pubDate>Thu, 14 Dec 2017 21:25:33 GMT</pubDate>
            <atom:updated>2017-12-31T00:16:35.446Z</atom:updated>
            <content:encoded><![CDATA[<h4>No more Googling for Cron syntax</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8obrhD__u0bGwdIO0ilWLw.png" /></figure><p>I’d argue that most projects I’ve worked on over the years all have eventually included a periodic task of some sorts; daily reminder email, overnight processing task, polling an API that doesn’t provide a web hook etc.</p><p>With Ruby the answer was always a cron job that would invoke a rake task. This had couple of problems with it, first I could never remember the crontab format. Second was where to place the configuration and how to make sure it was up to date.</p><p>Gems like <a href="https://github.com/javan/whenever">Whenever</a> would help fix many of my grievances but with Elixir there’s in my opinion something even nicer.</p><h4>Using receive/1 for timeouts</h4><p>Elixir has a function receive/1 which is defined in the Kernel.SpecialForms module and is available for use anywhere in your code without the module prefix.</p><p>The receive/1 takes an optional after clause with a timeout value that gets executed if the process has not received a matching message in the given time. We can combine this with a recursive call to execute code at given intervals.</p><p>If that sounds cryptic I hope this helps</p><pre>defmodule Example do</pre><pre>def process() do<br>  receive do<br>    after<br>      5_000 -&gt;<br>        IO.puts &quot;5 seconds elapsed&quot;<br>        process()<br>    end<br>  end</pre><pre>end</pre><p>If you were to call the process/0 function here it would keep printing “5 seconds elapsed” every 5 seconds.</p><h4>Creating a periodic Task module</h4><p>The function above isn’t terribly useful by itself, for one it never returns and besides we’d want it to start when the application starts.</p><p>We can create a module that starts our process in a Task and can be added to the applications supervision tree</p><pre>defmodule Example.BitcoinPriceUpdater do<br>  use Task</pre><pre>  def start_link(_arg) do<br>    Task.start_link(&amp;poll/0)<br>  end</pre><pre>  def poll() do<br>    receive do<br>    after<br>      60_000 -&gt;<br>        get_price()<br>        poll()<br>    end<br>  end</pre><pre>  defp get_price() do<br>    # Call API &amp; Persist<br>    IO.puts &quot;To the moon!&quot;<br>  end</pre><pre>end</pre><p>If you are on Elixir 1.5 or newer by using the use Task at the top of your module your Application supervisor can do something like this</p><pre>defmodule Example.Application do<br>  <a href="http://twitter.com/moduledoc">@moduledoc</a> false</pre><pre>  use Application</pre><pre>  def start(_type, _args) do<br>    children = [<br>      Example.BitcoinPriceUpdater<br>    ]</pre><pre>    opts = [strategy: :one_for_one, name: Example.Supervisor]<br>    Supervisor.start_link(children, opts)<br>  end<br>end</pre><p>If you are on an older version of Elixir you’ll have to specify the children with something like this instead</p><pre>children = [<br>  worker(Example.BitcoinPriceUpdater, [])<br>]</pre><p>In any case what you have is a module as part of your Application supervision tree that is started automatically when your Application is started and it will keep calling the given piece of code periodically.</p><p>There you have it a simple little module that you can use to add periodic tasks to your applications with ease and no more worrying about updating the crontab.</p><p>In my experience the timeout is accurate enough for most tasks like this and I’ve had couple running in production for a year or so now and it’s not given me any trouble.</p><p>Having said that I wouldn’t rely on this for anything where accuracy is very important and also keep in mind that if your process crashes or you restart the app the timer starts from 0.</p><p>Please do click the 👏 icon below if you liked this post and follow me here or on Twitter <a href="https://twitter.com/efexen">@efexen</a> to hear about new articles. If you haven’t already can I recommend checking out my <a href="https://medium.com/@efexen/quick-easy-elixir-refactorings-part-1-17376e9c455a">Elixir Refactoring Series</a> as well 👍</p><p>Next: <a href="https://medium.com/@efexen/periodic-tasks-with-elixir-part-2-8aaee425aed0">Periodic tasks with Elixir — Part 2</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5d9050bcbdb3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Quick & Easy Elixir Refactorings — Part 4]]></title>
            <link>https://medium.com/hackernoon/quick-easy-elixir-refactorings-part-4-4096a8022988?source=rss-d3ac379287b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/4096a8022988</guid>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[refactoring]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Ville]]></dc:creator>
            <pubDate>Sat, 02 Dec 2017 22:02:22 GMT</pubDate>
            <atom:updated>2019-04-29T04:06:44.199Z</atom:updated>
            <content:encoded><![CDATA[<h4>Nested conditionals</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3Go_cRIV7eO_KC4djZ71bg.jpeg" /></figure><p>In the previous part we looked at how to refactor away conditionals in the middle of your functions by passing in a function instead. Before that we looked at <a href="https://hackernoon.com/tagged/refactoring">refactoring</a> away conditionals at the beginning and end of your functions.</p><p>If you’ve not read through the series yet I recommend you start from the beginning</p><p><a href="https://medium.com/@efexen/quick-easy-elixir-refactorings-part-1-17376e9c455a">Part 1 — Functions starting with a conditional</a><a href="https://medium.com/@efexen/quick-easy-elixir-refactorings-part-2-4cd66bad1b20"><br>Part 2 — Functions ending with a conditional</a><br><a href="https://medium.com/@efexen/quick-easy-elixir-refactorings-part-3-def1aae4b072">Part 3 — Conditionals in the middle</a></p><p>In this post we will look at a way to deal with nested conditionals. One could be forgiven for thinking I don’t like conditionals by this point 😉</p><h4>Nested conditionals</h4><p>Nested conditionals are a far bigger problem in other languages and usually tend to be caused by having functions that are just too long and should already be split up but there are times when these come up and it’d be nice to have a concise way of dealing with them.</p><p>An example could be something like this</p><pre>defmodule Example do</pre><pre>  def authorised?(user) do<br>    case UserAuthenticator.authorised?(user) do<br>      {:ok, _user} -&gt;<br>        true<br>      {:error, _user} -&gt;<br>        case LegacyUserAuthenticator.authorised?(user) do<br>          {:ok, _user} -&gt;<br>            true<br>          {:error, _user} -&gt;<br>            false<br>        end<br>    end<br>  end</pre><pre>end</pre><p>Not terribly elegant piece of code and slightly tricky to read as well. Imagine if instead of returning simple boolean we’d execute some longer piece of logic instead 😓</p><p>We could split up the authorised?/1 function to get rid of the nesting by doing something like this</p><pre>def authorised?(user) do<br>  case UserAuthenticator.authorised?(user) do<br>    {:ok, _user} -&gt;<br>      true<br>    {:error, _} -&gt;<br>      legacy_authorized?(user)<br>  end<br>end</pre><pre>defp legacy_authorized?(user) do<br>  case LegacyAuthenticator.authorised?(user) do<br>    {:ok, _user} -&gt;<br>      true<br>    {:error, _} -&gt;<br>      false<br>  end<br>end</pre><p>Hooray no more nesting 🙌 And by using the techniques from earlier on in this series we could eliminate the conditionals altogether to get something like this</p><pre>def authorised?(user) do<br>  user<br>  |&gt; UserAuthenticator.authorised?()<br>  |&gt; check_authorised()<br>end</pre><pre>def check_authorised({:ok, _}), do: true<br>def check_authorised({:error, user}) do<br>  user<br>  |&gt; LegacyAuthenticator.authorised?()<br>  |&gt; check_legacy()<br>end</pre><pre>def check_legacy({:ok, _}), do: true<br>def check_legacy(_), do: false</pre><p>This is nice when you have nesting in both branches of the initial conditional as it allows you to split all of that up across lot of little functions.</p><p>Fortunately with our example we only have a nested conditional in one of the branches which allows us to look at an alternative using the the with statement</p><pre>def authorised?(user) do<br>  with {:error, _} &lt;- UserAuthenticator.authorised?(user),<br>       {:error, _} &lt;- LegacyAuthenticator.authorised?(user) do<br>         false<br>       else<br>         {:ok, _} -&gt; true<br>       end<br>  end</pre><p>😮 😍</p><p>What we’ve ended up with is technically still a conditional but compared to our alternatives above I think it’s a very elegant solution to the initial problem.</p><p>If you’re not familiar with the with statement I urge you to play around with it as it can make code that is expected to follow a certain happy path really easy to reason about and certainly clearer than bunch of nested conditionals.</p><p>Please click the applause icon 👏 if you liked this post and follow me here or on Twitter <a href="https://twitter.com/efexen">@efexen</a> to find short actionable posts where we’ll look at more simple tricks for leveling up your <a href="https://hackernoon.com/tagged/elixir">Elixir</a> code 👍</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fdde502%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2Fhackernoon%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href">https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4096a8022988" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/quick-easy-elixir-refactorings-part-4-4096a8022988">Quick &amp; Easy Elixir Refactorings — Part 4</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Quick & Easy Elixir Refactorings — Part 3]]></title>
            <link>https://medium.com/@efexen/quick-easy-elixir-refactorings-part-3-def1aae4b072?source=rss-d3ac379287b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/def1aae4b072</guid>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[refactoring]]></category>
            <dc:creator><![CDATA[Ville]]></dc:creator>
            <pubDate>Wed, 29 Nov 2017 19:37:32 GMT</pubDate>
            <atom:updated>2017-12-02T22:03:16.035Z</atom:updated>
            <content:encoded><![CDATA[<h4>Conditionals in the middle</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7luYzDW5Xym1RgRU9SMuRw.jpeg" /></figure><p>In the last part we looked at a technique for refactoring away conditionals at the end of your functions and before that we looked at using pattern matching to eliminate conditionals from the top of your functions.</p><p>If you’ve not checked them out yet I recommend you do</p><p><a href="https://medium.com/@efexen/quick-easy-elixir-refactorings-part-1-17376e9c455a">Part 1 — Functions starting with a conditional</a><a href="https://medium.com/@efexen/quick-easy-elixir-refactorings-part-2-4cd66bad1b20"><br>Part 2 — Functions ending with a conditional</a></p><p>In this post we’ll be looking at how we can clean up some code where two or more functions need to have the same start and end but something slightly different in the middle.</p><h4>Conditionals in the middle</h4><p>There’s couple of variants to this kind of thing I can think of. These usually come up when we are requested to add a feature to something already in place but is something a little bit different. You know, that special case 😉</p><p>Lets say we have a function that looks something like this</p><pre>defmodule Example do</pre><pre>  def parse_name(email) do<br>    email<br>    |&gt; String.split(&quot;@&quot;)<br>    |&gt; hd()<br>    |&gt; String.split(&quot;.&quot;)<br>    |&gt; Enum.join(&quot; &quot;)<br>  end</pre><pre>end</pre><p>We get an email address, take the bit before @ symbol, separate on a full stop to get first name and last name and join them back together to make a full name. There’s better ways of doing that but it’s good for our purposes here.</p><p>Say now an additional requirement came in and we need to sometimes capitalise the first name and last name.</p><p>First thing we could do is</p><pre>def parse_pretty_name(email) do<br>  email<br>  |&gt; String.split(&quot;@&quot;)<br>  |&gt; hd()<br>  |&gt; String.split(&quot;.&quot;)<br>  |&gt; Enum.map(&amp;String.capitalize/1)<br>  |&gt; Enum.join(&quot; &quot;)<br>end</pre><p>Identical to the existing one apart from the additional 4th line in the pipeline with call to String.capitalize/1</p><p>Doesn’t feel quite right duplicating all that other logic. So alternatively we could pass something like an option to the function</p><pre>def parse_name(email, pretty \\ false) do<br>  names = email<br>  |&gt; String.split(&quot;@&quot;)<br>  |&gt; hd()<br>  |&gt; String.split(&quot;.&quot;)</pre><pre>  if pretty do<br>    names = Enum.map(names, &amp;String.capitalize/1)<br>  end<br>  <br>  Enum.join(names, &quot; &quot;)<br>end</pre><p>Doesn’t look very nice and if we compile this the Elixir compiler gives us a warning about setting a variable inside a conditional and gives a recommendation to fix it to something like this</p><pre>def parse_name(email, pretty \\ false) do<br>  names = email<br>  |&gt; String.split(&quot;@&quot;)<br>  |&gt; hd()<br>  |&gt; String.split(&quot;.&quot;)</pre><pre>  names =<br>    case pretty do<br>      true -&gt; Enum.map(names, &amp;String.capitalize/1)<br>      _ -&gt; names<br>    end</pre><pre>  Enum.join(names, &quot; &quot;)<br>end</pre><p>Aaaaaaaa…it’s getting worse! No compiler errors though 😉</p><p>Let’s have a look at an alternative where we’ll extract the bit that is different away.</p><pre>def parse_name(email) do<br>  do_parse_name(email, &amp;(&amp;1))<br>end</pre><pre>def parse_pretty_name(email) do<br>  do_parse_name(email, &amp;capitalize_names/1)<br>end</pre><pre>defp do_parse_name(email, transform) do<br>  email<br>  |&gt; String.split(&quot;@&quot;)<br>  |&gt; hd()<br>  |&gt; String.split(&quot;.&quot;)<br>  |&gt; transform.()<br>  |&gt; Enum.join(&quot; &quot;)<br>end</pre><pre>defp capitalize_names(names) do<br>  Enum.map(names, &amp;String.capitalize/1)<br>end</pre><p>So we’ve gone back to having a pair of functions with prescriptive names rather than options, although we could have kept the same name and pattern matched for the option here instead.</p><p>We’ve created a new private function which takes as it’s arguments the email but also a transform function which it then calls in the pipeline.</p><p>Our first function parse_name/1 now just calls the new private “do” function and passes in an anonymous function which simply returns whatever argument it gets essentially not doing anything.</p><p>The second function calls the same “do” function but uses <a href="http://elixir-lang.github.io/getting-started/modules-and-functions.html#function-capturing">function capturing</a> to pass in the new capitalize_names/1 private function as the transform function. Neat 👌</p><p>I’d probably leave it at that but we could go one step further if we wanted by having the “do nothing” anonymous function as default value for the transform argument 💥</p><pre>def parse_name(email, transform \\ &amp;(&amp;1)) do<br>  email<br>  |&gt; String.split(&quot;@&quot;)<br>  |&gt; hd()<br>  |&gt; String.split(&quot;.&quot;)<br>  |&gt; transform.()<br>  |&gt; Enum.join(&quot; &quot;)<br>end</pre><pre>def parse_pretty_name(email) do<br>  parse_name(email, &amp;capitalize_names/1)<br>end</pre><pre>defp capitalize_names(names) do<br>  Enum.map(names, &amp;String.capitalize/1)<br>end</pre><p>What I like about the final solution is that we’ve kept the neat looking easy to follow pipeline, we’ve eliminated conditionals, we’ve eliminated duplicated code and we’ve extracted the part that is different to a function on it’s own with a nice descriptive name.</p><p>This technique is great if you have some conditionals in the middle of your functions ruining your beautiful pipelines or lot of code duplicated around the differentiating piece of code.</p><p>Please do click the 👏 icon below if you liked this post and follow me here or on Twitter <a href="https://twitter.com/efexen">@efexen</a> to be notified of the next part where we’ll look at more simple tricks for leveling up your Elixir code 👍</p><p>Next: <a href="https://medium.com/@efexen/quick-easy-elixir-refactorings-part-4-4096a8022988">Quick &amp; Easy Elixir Refactorings — Part 4</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=def1aae4b072" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Quick & Easy Elixir Refactorings — Part 2]]></title>
            <link>https://medium.com/@efexen/quick-easy-elixir-refactorings-part-2-4cd66bad1b20?source=rss-d3ac379287b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/4cd66bad1b20</guid>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[refactoring]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Ville]]></dc:creator>
            <pubDate>Sat, 25 Nov 2017 22:36:20 GMT</pubDate>
            <atom:updated>2017-11-29T19:38:39.881Z</atom:updated>
            <content:encoded><![CDATA[<h4>Functions ending with a conditional</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6EVmC10rTK3sOq_hBTltoA.jpeg" /></figure><p>Last time we looked at using pattern matching instead of starting our functions with conditionals. If you haven’t checked it out yet you can find it here: <a href="https://medium.com/@efexen/quick-easy-elixir-refactorings-part-1-17376e9c455a">Quick &amp; Easy Elixir Refactorings — Part 1</a></p><p>This time we’ll look at a super simple technique you can use to remove the conditional from the end of your functions by extracting a function and next time we’ll deal with conditionals in the middle of your function.</p><p>All of these techniques by themselves may seem hardly worth it and not making a big difference but stay with me; I’m hoping in couple of posts time when we bring all these techniques together to move from an imperative style to a functional style it will all make sense.</p><h4>Functions ending with a conditional</h4><p>These functions as the title states finish up with a conditional statement, quite often these are found in a create or update action of a controller in a framework like Phoenix or wherever we are performing an operation and branching our logic with the result.</p><p>A typical example would be something like this</p><pre>defmodule ExampleWeb.ExampleController do<br>  use ExampleWeb, :controller<br>  alias Example.Things<br>  alias Example.ThingUpdater</pre><pre>  def update(conn, %{&quot;id&quot; =&gt; id, &quot;wibble&quot; =&gt; wibble}) do<br>    thing = Things.get(id)</pre><pre>    case ThingUpdater.set_wibble(thing, wibble) do<br>      {:ok, thing} -&gt;<br>        conn<br>        |&gt; put_flash(&quot;Huzzah!&quot;)<br>        |&gt; redirect to: thing_path(conn, :index)<br>      {:error, message} -&gt;<br>        conn<br>        |&gt; put_flash(message)<br>        |&gt; render &quot;edit.html&quot;<br>    end<br>  end<br>end</pre><p>We get a thing and attempt to update it and want to do something different depending on whether it succeeded or not.</p><p>Quite a bit happening for one function. What we could do is extract the conditional to a separate private function or two.</p><pre>...<br>def update(conn, %{&quot;id&quot; =&gt; id, &quot;wibble&quot; =&gt; wibble}) do<br>  thing = Things.get(id)<br>  result = ThingUpdater.set_wibble(thing, wibble)<br>  respond(conn, result)<br>end</pre><pre>defp respond(conn, {:ok, thing}) do<br>  conn<br>  |&gt; put_flash(&quot;Huzzah!&quot;)<br>  |&gt; redirect to: thing_path(conn, :index)<br>end</pre><pre>defp respond(conn, {:error, message}) do<br>  conn<br>  |&gt; put_flash(message)<br>  |&gt; render &quot;edit.html&quot;<br>end<br>...</pre><p>I’ve omitted the beginning and end of the module which have not changed. Just by capturing the result and pattern matching it in the function signatures this already feels a bit neater to me.</p><p>If we swap around the arguments for our new respond/2 function however we can get rid of the unnecessary assigning and use the pipeline operator to tidy this up even further</p><pre>def update(conn, %{&quot;id&quot; =&gt; id, &quot;wibble&quot; =&gt; wibble}) do<br>  Things.get(id)<br>  |&gt; ThingUpdater.set_wibble(wibble)<br>  |&gt; respond(conn)<br>end</pre><pre>def respond({:ok, thing}, conn) do<br>  conn<br>  |&gt; put_flash(&quot;Huzzah!&quot;)<br>  |&gt; redirect to: thing_path(conn, :index)<br>end</pre><pre>def respond({:error, message}, conn) do<br>  conn<br>  |&gt; put_flash(message)<br>  |&gt; render &quot;edit.html&quot;, thing: thing<br>end</pre><p>If your functions are ending with conditionals try the technique above and see if you can split your function that deals with many things to smaller more focused chunks and use pattern matching to eliminate the conditional altogether.</p><p>Bonus of doing this is that it also makes it easier and neater to use pipelines to describe the flow 😍</p><p>Please do click the 👏 icon below if you liked this post and follow me here or on Twitter <a href="https://twitter.com/efexen">@efexen</a> to be notified of the next part where we’ll look at more simple tricks for leveling up your Elixir code 👍</p><p>Next: <a href="https://medium.com/@efexen/quick-easy-elixir-refactorings-part-3-def1aae4b072">Quick &amp; Easy Elixir Refactorings — Part 3</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4cd66bad1b20" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Quick & Easy Elixir Refactorings — Part 1]]></title>
            <link>https://medium.com/@efexen/quick-easy-elixir-refactorings-part-1-17376e9c455a?source=rss-d3ac379287b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/17376e9c455a</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[refactoring]]></category>
            <dc:creator><![CDATA[Ville]]></dc:creator>
            <pubDate>Tue, 21 Nov 2017 21:56:20 GMT</pubDate>
            <atom:updated>2017-11-25T22:43:14.988Z</atom:updated>
            <content:encoded><![CDATA[<p>Over the next few blog posts I’ll be covering some quick easy refactorings that could help you tidy up your Elixir codebase.</p><p>We’ll go over some patterns you might find in your code and look at simple techniques you can use to hopefully make your code neater, easier to work with in the future and more readable.</p><p>In this first post I’ll cover functions that start with a conditional. In following posts we’ll cover functions that start with similar code but with different ends and functions that have something slightly different in the middle among others.</p><h4>Functions starting with a conditional</h4><p>This is a pattern I see a lot with people new to Elixir or pattern matching, especially with a good Ruby background where they already have a great practise of writing small functions.</p><p>The first thing to happen in these functions is we check something that was passed in.</p><pre>defmodule Example do</pre><pre>  def is_zero?(number) do<br>    if number == 0 do<br>      true<br>    else<br>      false<br>    end<br>  end</pre><pre>end</pre><p>Contrived example for sure and first thing you could do is get rid of the useless if structure like this</p><pre>defmodule Example do</pre><pre>  def is_zero?(number) do<br>    number == 0<br>  end</pre><pre>end</pre><p>But lets imagine this was little more complicated. What we can do instead is do the conditional branching using pattern matching in the function signature</p><pre>defmodule Example do</pre><pre>  def is_zero?(0), do: true<br>  def is_zero?(_), do: false</pre><pre>end</pre><p>This is particularly nice if you started with a 8–9 line function where both branches had 3 or so lines of code.</p><p>This is also handy for case statements</p><pre>defmodule Example do</pre><pre>  def send(message) do<br>    case message.type do<br>      :sms -&gt;<br>        # some SMS send code<br>      :email -&gt;<br>        # email send code<br>      :slack -&gt;<br>        # Slack code<br>      _ -&gt;<br>        # Bad type catch<br>    end<br>  end</pre><pre>end</pre><p>becomes something like</p><pre>defmodule Example do</pre><pre>  def send(%{type: :sms}) do<br>    # some SMS send code<br>  end</pre><pre>  def send(%{type: :email}) do<br>    # some email send code<br>  end</pre><pre>  def send(%{type: :slack}) do<br>    # Slack code<br>  end</pre><pre>  def send(_) do<br>    # Bad type catch<br>  end</pre><pre>end</pre><p>or even</p><pre>defmodule Example do</pre><pre>  def send(%{type: :sms}), do: # some SMS send code<br>  def send(%{type: :email}), do: # some email send code<br>  def send(%{type: :slack}), do: # Slack code<br>  def send(_), do: # Bad type catch</pre><pre>end</pre><p>If your functions start by inspecting the values passed in and branching from there there’s a good chance you can use pattern matching to tidy things up.</p><p>Please click the high fives icon below if you liked this post and follow me here and on Twitter <a href="https://twitter.com/efexen">@efexen</a> for the next post where we’ll look at more simple tricks for leveling up your Elixir code 👍</p><p>Next: <a href="https://medium.com/@efexen/quick-easy-elixir-refactorings-part-2-4cd66bad1b20">Quick &amp; Easy Elixir Refactorings — Part 2</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17376e9c455a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The 3 reasons why I ask about code patterns]]></title>
            <link>https://medium.com/@efexen/the-3-reasons-why-i-ask-about-code-patterns-a6085924d2b7?source=rss-d3ac379287b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6085924d2b7</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[personal-development]]></category>
            <category><![CDATA[hiring]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[interview]]></category>
            <dc:creator><![CDATA[Ville]]></dc:creator>
            <pubDate>Sat, 07 Jan 2017 20:24:13 GMT</pubDate>
            <atom:updated>2017-01-07T20:33:30.876Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MC16Tg1OgyD-dLa2s-3DEA.jpeg" /></figure><p>I’ve spent a lot of time interviewing Ruby and JavaScript developers in the past year and I always ask about code patterns. The responses I’ve received have been rather varied and also rather surprising.</p><p>I have three main reasons why I ask about patterns and why I think you should too.</p><h4>Proven solutions for known problems</h4><p>This is the obvious one. Lot of smart people spent a lot of time coming up with great ways to solve many of the problems you are likely to run into whilst you’re refactoring problematic code or building out new features.</p><p>Patterns often get a bad rap as it’s easy to over use them and shove them in places where they’re not appropriate making the code just more confusing rather than providing the good solution intended.</p><p>This stands true especially in certain younger programming communities where many of the developers have only seen the bad side of patterns and not where they have helped solve problems and tame code that would otherwise be wild and tricky to work with.</p><p>Even if you disagree with use of patterns or the language community shuns them I feel it would be good to learn about them and be aware of them.</p><h4>Measure what you’ve learnt on your own</h4><p>Many of the developers I interview are either entirely self taught or have spent a lot of time after their degrees or courses learning on their own and that’s fantastic!</p><p>As you might know I’m a big advocate for self improvement and I think every ambitious developer should dedicate some time to learning, if your company provides opportunities for this; Great!, if not you should be asking why not.</p><p>Self learning can be tricky though, what do you concentrate on learning and how do you find out about the thing you don’t yet know about? Most language books and courses stop a bit shy of patterns and so by asking about patterns I can get an idea of the depth of learning you’ve engaged in.</p><p>Have you just skimmed the surface of a thousand languages and frameworks or have you at some point dug a bit deeper to find out about the underlying patterns and paradigms that so many of them are built upon?</p><h4>They make communication easier</h4><p>Finally this might be one of the key reasons why I ask about them and am delighted if you do know at least some patterns: they make communication about the work much easier if you are to join my team.</p><p>Surprising amount of developers especially mid and senior level when asked about patterns answer with something along the lines of: “I use quite a few of them I just don’t know the names”. Unfortunately that makes talking about code a bit of a pain.</p><p>Say we are having an early chat and throwing around ideas about how to implement something, or we’re doing a code review and there’s some refactoring to do:</p><p>Compare these two exchanges:</p><p>“We could use a class here where we’ll restrict the use of the constructor by making it a private method and then creating a class method that will create a new instance of that class and then stores it as a static variable so if requested again we can return the same instance again”</p><p>or</p><p>“Singleton class could be good here”</p><p>Slightly tortured example off the top of my head but I think you get the point. Imagine people building houses but instead of using words like “brick” they’d have to somehow otherwise communicate across the concept of a rectangular baked piece of clay and other gunk…</p><p>If you are hiring developers I urge you to ask about patterns as the answers I found are often very enlightening and if you are a developer looking to up your game and improve your skill set I urge you to start looking at some well known patterns.</p><p>I promise you it will help you with your ever day work and could make that vital bit of difference in your next interview ;)</p><p>I would love to hear about your opinions so please do get in touch on Twitter <a href="https://twitter.com/efexen">@efexen</a> and if you have any comments or questions I’d love to hear them too.</p><p>Finally if you enjoyed reading this post can I ask that you do recommend it, share it with others and follow me. Thanks</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a6085924d2b7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to start Lightning Talks]]></title>
            <link>https://medium.com/hackernoon/how-to-start-lightning-talks-304b673b412f?source=rss-d3ac379287b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/304b673b412f</guid>
            <category><![CDATA[public-speaking]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[management]]></category>
            <category><![CDATA[company-culture]]></category>
            <dc:creator><![CDATA[Ville]]></dc:creator>
            <pubDate>Thu, 10 Nov 2016 21:14:28 GMT</pubDate>
            <atom:updated>2019-04-29T04:11:02.079Z</atom:updated>
            <content:encoded><![CDATA[<p>In case you’ve not heard the term before <a href="https://hackernoon.com/tagged/lightning">lightning</a> talks are short presentations — literally fast transfers of information.</p><p>I started lightning talks at my previous couple of companies and they quickly became my most successful initiatives gaining rave support from everyone from owner/founders to temporary summer interns.</p><p>Here’s some notes to help you introduce lightning talks at your company including why I think they’re great, rules I’ve found useful and other things I’ve learned running them.</p><h3>Why</h3><p>Lightning talks are simply short concise presentations usually given by a single presenter on a topic of their choosing to a voluntary audience.</p><p>There’s a ton of great benefits both direct and indirect I’ve witnessed as a result of running these talks and here’s some of my favourites.</p><h4>Knowledge Sharing</h4><p>Sharing the knowledge we’ve gained is one of the most valuable things we can do with our time and this is the number one reason why I initially started these talks.</p><p>Sharing knowledge creates a culture that celebrates those who make the extra effort to gain an understanding of something and encourages others to do so.</p><p>It helps highlight talents, ideas and passions and provides an opportunity for the speaker to gain a deeper understanding of the material by considering how to present it to others.</p><h4>Practising public speaking</h4><p>Most people including myself are terrified of public speaking yet would like to get better at it. The best way to feel less nervous and get better at it is by practising.</p><p>Speaking at an industry conference in front of hundreds or even thousands of your peers can be a daunting debilitating prospect but practising on a smaller friendly audience in short slots can give you the confidence to submit that proposal.</p><p>Even if you are a confident speaker it’s still a great way to keep your skills honed and an excellent opportunity to try out a new style or technique.</p><h4>Test out ideas</h4><p>Do you have an idea that you’d like to gain some feedback on? Maybe you’re considering writing a blog post or even a book? Maybe you have an idea for a local user group or conference <a href="https://hackernoon.com/tagged/talk">talk</a>?</p><p>Lightning talks are a great way for you to test out your idea on a small audience and gain valuable feedback.</p><h3>The Rules</h3><p>Whilst the lightning talks are relaxed and informal in nature I found the following rules helped make them effective.</p><h4>Topic</h4><p>The topic can be anything the speaker finds interesting and wants to share.</p><p>Whether the topic is related to the business, their job role or not; the idea is to keep this entirely open. The same applies to the level of the talk, the speaker may decide to make the talk accessible to everyone or make it extremely technical, assuming a high level of previous knowledge on the topic.</p><p>The reason this works well is that the topic should be announced before hand which gives the audience an opportunity to decide whether they want to attend or not.</p><p>You shouldn’t restrict the topic to be industry or technology specific as you want the barrier for entry to be as low as possible, also you might miss out on great talks that while not directly relevant can still work to motivate and inspire the attendees.</p><h4>Audience</h4><p>If feasible, I would recommend an open invitation to the entire company. Some of the most interesting talks I’ve witnessed weren’t from Development but from other departments.</p><p>I’ve also often heard great things from attendees from other departments about the technical talks by developers even though by their own admission some of it may go over their heads.</p><p>Likewise, exposing the developers to other parts of the business can lead to a deeper understanding of, and appreciation for, what everyone does. It may even spark some great new cross departmental initiatives.</p><h4>Scheduling</h4><p>The ideal day for holding the talks tends to be Fridays, especially if you already have weekly meetings scheduled for that day.</p><p>Momentum plays an important role with establishing the talks and weekly talks are ideal if the size of the company allows for it, fortnightly is a good alternative for smaller teams or if you struggle to find enough speakers for every week.</p><p>Once a month tends to be too infrequent and if anything comes up it can easily be months without the talks taking place.</p><p>The important thing is to try and select a time slot that is as convenient as possible for as many people as possible to maximise attendance.</p><h4>Time slot</h4><p>The talks should be between 5 and 15 minutes in length followed by up to 15 minutes of questions or discussion. It is important to emphasise the 15 minute limit and the speaker should be made aware that they will be cut off if they exceed this.</p><p>It is important to stick to these times as it allows you to make a promise to your attendees that this won’t take more than a maximum of 30 minutes of their time. This encourages people to attend talks they might be unsure of as they are aware of the time investment ahead of time.</p><p>This can also make all the difference in getting management buy in as it’s strictly time boxed. A further added perk is that anyone wanting to give a PechaKucha format talk can do so within these rules!</p><p>Timing wise I’ve always preferred the morning as many may be too busy tying up loose ends to make a clean break for the weekend in the afternoon.</p><h3>Helpful notes</h3><p>Here I’ve collected some notes that will hopefully help you make lightning talks a success.</p><h4>Outline</h4><p>I’ve found it helpful to MC the lightning talks and follow this format:</p><ul><li>Welcome everyone and thank them for coming</li><li>Mention the talk next week</li><li>Introduce the speaker</li><li>Remind everyone how to get involved speaking</li><li>Invite applause for the speaker</li><li>The talk followed by questions</li><li>Thank the speaker &amp; final applause</li></ul><p>This can be extremely simple. The script I follow goes roughly like so:</p><p><em>“Happy Friday everyone, thanks for coming. Next week we have Dorian talking about Controllerless Phoenix Apps. But now we have Ollie who’s going to tell us about Ember Data. I’m always looking for more speakers so if you’d like to speak come and talk to me. Give a hand to Ollie.”</em></p><h4>Finding Speakers</h4><p>You may find getting people to speak either very easy or very slow to start with. If you are fortunate enough to have plenty of people signing up then get organised, create a simple schedule and stick to it.</p><p>Unfortunately the beginning can be quite tricky with most people unsure and not wanting to be the first ones to go. That’s why I’d highly recommend having your first lightning talk be about lightning talks themselves! This is a great opportunity to demonstrate the idea and communicate everything across.</p><p>To further encourage everyone to get involved I usually present the following ways they can do so</p><ul><li>Want to talk and have a topic in mind? Let’s get you scheduled in!</li><li>Don’t want to talk yet but would like to hear about a particular topic. Make a note of the topic for the next group.</li><li>Want to talk but don’t have a specific topic in mind. Get a topic someone has requested or check the list below for sample ideas.</li><li>Don’t want to talk and don’t have ideas. Attend and show support for the speakers ;)</li></ul><p>Finally: Nagging works. Even if you have the next 4 weeks filled up always be on the lookout for more and build a healthy pipeline. If possible have a general talk ready you can give if someone has to cancel unexpectedly and nag some more. It can be tough in the beginning but momentum is a beautiful thing.</p><h4>Choosing initial topics</h4><p>It can be tricky to come up with topics in the beginning as you might be unsure what is appropriate.</p><p>The best advice I can give is that you want to choose something fairly narrow in scope, 15 minutes is not a lot of time and most topics could end up feeling rushed if squeezed in.</p><p>Some easy topic ideas to get started could include:</p><ul><li>“A day in the life of X “— A brief description of your job role</li><li>“Key takeaways from the Lean Startup” — A short review of a recent book you’ve read</li><li>“S in SOLID” — Explanation of a programming principle or technique</li><li>“Hidden psychology in supermarkets” — Interesting topic you’ve read about recently</li><li>“Watch me Flex(box)” — Introducing a new technology</li><li>“A Web Love Story” — A short story of how your career started</li></ul><h4>Filming</h4><p>It’s a great idea to film your lightning talks. Not only can you make them available to everyone internally who couldn’t make it but also you could choose to publish an appropriate selection to Youtube or Vimeo showcasing the company culture which could aid with hiring.</p><p>The benefits are great but the camera can also make the speaker feel uncomfortable and could cause someone to not speak!</p><p>For this reason I always ask the speaker in private prior to the talk whether they are comfortable being filmed and make sure they know it is ok to say no.</p><h3>Conclusion</h3><p>Now it’s up to you. Here’s a short checklist of how to get started step by step</p><ul><li>Ask around to see if you find any early interest or speakers</li><li>Get management buy-in (see the Why section at the top for ammo)</li><li>Prepare your first talk to introduce the talks</li><li>Send out an email inviting everyone along</li><li>Find someone to speak the following week you can announce</li><li>Host your first lightning talk!</li></ul><p>Creating a culture of knowledge sharing is incredible and I hope this post has given you the tools and inspiration to start hosting lightning talks at your company.</p><p>I would love to hear about your experiences and any further learnings you may have gained running these yourself. Please do get in touch on Twitter <a href="https://twitter.com/efexen">@efexen</a> and if you have any comments or questions I’d love to hear them.</p><p>Finally if you enjoyed reading this post can I ask that you do recommend it and share it with others.</p><blockquote><a href="http://bit.ly/Hackernoon">Hacker Noon</a> is how hackers start their afternoons. We’re a part of the <a href="http://bit.ly/atAMIatAMI">@AMI</a>family. We are now <a href="http://bit.ly/hackernoonsubmission">accepting submissions</a> and happy to <a href="/service/mailto:partners@amipublications.com">discuss advertising &amp;sponsorship</a> opportunities.</blockquote><blockquote>To learn more, <a href="https://goo.gl/4ofytp">read our about page</a>, <a href="http://bit.ly/HackernoonFB">like/message us on Facebook</a>, or simply, <a href="https://goo.gl/k7XYbx">tweet/DM @HackerNoon.</a></blockquote><blockquote>If you enjoyed this story, we recommend reading our <a href="http://bit.ly/hackernoonlatestt">latest tech stories</a> and <a href="https://hackernoon.com/trending">trending tech stories</a>. Until next time, don’t take the realities of the world for granted!</blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fdde502%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2Fhackernoon%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href">https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=304b673b412f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/how-to-start-lightning-talks-304b673b412f">How to start Lightning Talks</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>