<?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 Tom on Medium]]></title>
        <description><![CDATA[Stories by Tom on Medium]]></description>
        <link>https://medium.com/@inconclusive?source=rss-c9b51acb947a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*nTq6JUWGNLlw4cxBR1cp5Q.png</url>
            <title>Stories by Tom on Medium</title>
            <link>https://medium.com/@inconclusive?source=rss-c9b51acb947a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 22:50:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@inconclusive/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[Software Metrics Best Practices]]></title>
            <link>https://levelup.gitconnected.com/software-metrics-best-practices-b91c37d87c73?source=rss-c9b51acb947a------2</link>
            <guid isPermaLink="false">https://medium.com/p/b91c37d87c73</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Tom]]></dc:creator>
            <pubDate>Thu, 23 Sep 2021 17:10:33 GMT</pubDate>
            <atom:updated>2021-09-23T17:10:33.380Z</atom:updated>
            <content:encoded><![CDATA[<p>How to save yourself time and sanity when things don’t go according to plan.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uoKyAHjqKi4kFEPpByoTSA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@laundemrl?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Launde Morel</a> on <a href="https://unsplash.com/?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>For the sake of putting things in context, it’s worth taking a step back first and consider monitoring as a whole before diving into metrics. There are three main practices for monitoring software in production: logging, metrics, and tracing.</p><p>Probably the simplest to put in place is logging, although some thoughts should go into how log messages are formatted, collected and aggregated. This is the first tool that a developer or an administrator can use to gather intel about incidents.</p><p>Logs can contain a lot of information which can be a good thing when debugging a specific problem. However, that’s precisely why they stop being useful in other circumstances.</p><p>A typical application produces a lot of logs and it’s not uncommon to see gigabytes of logs accumulating over short periods of time.</p><p>In that regard, metrics are the exact opposite of logs. They aggregate information into a few key numbers and provide a macroscopic view of the systems under monitoring.</p><p>Finally, we can add tracing to the mix in order to view log messages related to a specific request or event.</p><p>If we want a microscopic, fine-grained view of the system, we could filter all logs between two dates but there would be a lot of noise. Instead, we can annotate all logs with a request identifier and then filter by that.</p><p>Tracing typically goes one step further by allowing <em>spans</em> to be nested. For example, we might have a span — with a span identifier — for all incoming requests and a subspan for a specific part of the request handler.</p><h3>The Four Golden Signals</h3><p>In their excellent book <a href="https://sre.google/sre-book/table-of-contents/">Site Reliability Engineer</a>, engineers from Google describe four so-called golden signals for monitoring services.</p><ul><li>Latency is the time it took to process a request.</li><li>Traffic is the amount of incoming requests in a period of time.</li><li>Errors are an indicator of how many issues occurred when processing these requests.</li><li>Saturation is a collection of metrics measuring the load on the system, e.g. the memory used, the CPU time, etc.</li></ul><p>Of course, you can replace the word <em>request</em> by <em>event</em> or <em>batch</em> and adapt this list to other types of systems.</p><p>It is vital to make sure you monitor the data you need to get an accurate picture of what’s going in your system before going any futher.</p><p>However, this is not enough. Data is just data and more work is required to turn all of it into valuable information.</p><h3>Useful Dashboards</h3><p>First of all, a useful dashboard doesn’t have a gazillion graphs with moving needles and flashing colours everywhere. This might look fancy to some but it is almost certainly a waste of time.</p><p>There is a lot more value in taking the time to think of a few key views from which we can quickly see 1) whether the system is operating properly and 2) what exactly is wrong with it when things don’t go according to plan.</p><p>Here are some questions to ask when adding some view to a dashboard.</p><ul><li>Can someone see with ease if something is wrong?</li><li>Does the view give an indication about how to fix the issue? Or is there another view which can give that information?</li><li>Would a problem shown on that view be visible on another one as well, i.e. is it redundant?</li></ul><p>Once you have identified valuable information to show on a dashboard, the next question that naturally arises is how to organise them.</p><p>A good rule of thumb is to go from the generic to the specific.</p><p>Imagine yourself in the shoes of the person in charge of fixing production at 3am.</p><p>The first question you are probably going to ask is whether everything is okay. If, say, you can see an increased error rate, the next question is going to be: what kind of errors?</p><p>In that sense, a dashboard should be readable almost as a story.</p><p>This process can be dramatically eased by accompanying all views with</p><ul><li><em>What</em>: What is shown exactly. A descriptive title and appropriate axis labels are a good start but it is often not enough.</li><li><em>How</em>: How to use/interpret the view, i.e. what is expected and what is abnormal. If it is above a certain threshold, what does it imply?</li><li><em>Why</em>: During an incident, someone looking at this view wants to know the why, i.e. identifying the root cause. Views can be accompanied by either pointers to other views or dashboards to look at or hints at what might be wrong with the system.</li></ul><p>Don’t forget you are not limited to a single dashboard either and that different dashboard can be created for different purposes, audience and level of granularity.</p><p>For example, there could be one dashboard showing generic metrics about the number of active users, the conversion rate, etc. for management.</p><p>Another generic one could show the requests per second, the error rate, the CPU time, and memory used designed for people operating the system.</p><p>Yet another might show more granular information about errors and might be used when the error rate is unusually high. A link to this dashboard should be placed next to the aforementioned view showing error rates.</p><h3>Alerts</h3><p>In a perfect world, customers contact their service provider immediately when something is not quite working while providing a detailed description of the incident together with error messages or screenshots.</p><p>Unfortunately, this is rarely the case. (And we can’t really blame them.)</p><p>More often than not, users would just give up cursing your company only to give it a go later or worse, they would start looking at competitors.</p><p>You, therefore, want to know about incidents as early as possible. Maybe even before it starts seriousely impacting anyone. That is, you need alerting.</p><p>Just as dashboards, alerts should be designed with their consumers in mind, e.g. a software developer who already spent the whole day working and just got woken up in the middle of the night feeling very groggy.</p><p>There are two main rules for alerts.</p><p>The first rule is to keep them to a minimum. A constant stream of alerts and notifications is just noise that quickly gets ignored. Not only it’s not achieving its goal but it’s a sure path to burning out.</p><p>It might be worth revisiting the alerts and incidents from the previous few months and to classify them into four quadrants of true/false positives/ negatives and tidy things up.</p><p>The second rule is to make alerts informative. If you are half awake, you don’t want to have to decrypt an alert message which was written in a hurry.</p><p>Careful thoughts should go into alert messages beforehand while we have time and the building is not figuratively on fire.</p><p>On top of not making any unreasonable assumption about knowledge of the systems and removing any ambiguity, messages should also come with pointers as to where to look next.</p><p>A good rule of thumb is to accompany all alerts with a link to the relevant metrics dashboard.</p><h3>Conclusion</h3><p>There is a lot more to say about monitoring of course but I think this is already a good start if you are unsure how to approach it from a high-level perspective.</p><p>There are two running themes to keep in mind:</p><ul><li>Monitoring requires more thought than is usually allocated to it. Time spent carefully designing monitoring upfront is time saved during an incident.</li><li>Dashboards and alerts should always be designed with their consumers in mind.</li></ul><h3>Further Reading</h3><ul><li><a href="https://sre.google/sre-book/table-of-contents/">Site Reliability Engineering</a>, Google (in particular, <a href="https://sre.google/sre-book/monitoring-distributed-systems/">Monitoring Distributed Systems</a>)</li><li><a href="https://grafana.com/docs/grafana/latest/best-practices/">Best practices</a>, Grafana Labs</li><li><a href="https://openmetrics.io/">Open Metrics</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b91c37d87c73" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/software-metrics-best-practices-b91c37d87c73">Software Metrics Best Practices</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Improve Continuous Integration Process]]></title>
            <link>https://medium.com/better-programming/how-to-improve-continous-integration-process-541242d7a1fb?source=rss-c9b51acb947a------2</link>
            <guid isPermaLink="false">https://medium.com/p/541242d7a1fb</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Tom]]></dc:creator>
            <pubDate>Tue, 07 Sep 2021 12:15:04 GMT</pubDate>
            <atom:updated>2022-09-19T20:44:46.746Z</atom:updated>
            <content:encoded><![CDATA[<h3>How To Improve Continuous Integration Processes</h3><h4>Use CI beyond continuous testing</h4><figure><img alt="People looking at a laptop" src="https://cdn-images-1.medium.com/max/1024/0*6TGCG0Ts2fev07gm" /><figcaption>Photo by <a href="https://unsplash.com/@johnschno?utm_source=medium&amp;utm_medium=referral">John Schnobrich</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Status Quo</h3><p>The name continuous integration (or CI) gets thrown around a lot among developers without much thought going into what it actually means. It’s more commonly known (at least in my experience) as a synonym for continuous testing, or more specifically to designate whatever system is in charge of building and testing the application whenever a new commit is pushed or a pull request is created.</p><p>This is however a reductive definition of continuous integration, and there is much more to it than that.</p><p>The convention that seems to be most prevalent among tech startups (again that’s just my experience) is that all developers work in development branches and send a pull request when their work is ready to be merged. All these changes are pushed to a central repository such as GitHub and some CI system like Travis or GitHub Actions builds and tests the code.</p><p>In essence, continuous integration is about integrating the various parallel lines of work into a common code base often.</p><p>In what follows, I’ll describe other things that teams might want to use or consider to improve make integration even more continuous. Some of it will sound obvious but I think it can be interesting to actually think about it for a second to ensure that it is indeed the direction you are following.</p><h3>Why Should We Care Anyway?</h3><p>The most obvious reason is that long-lasting versions of the codebase that are not merged into the main branch on a regular basis cause more merge conflicts and often, these conflicts are harder to resolve. All that unnecessary work can be avoided by adopting healthy practices.</p><p>In addition to additional work resolving conflicts, not integrating often feels slow for the developers involved. They might feel like things are not moving forward and their work doesn’t really have a strong impact.</p><p>Not only can it make people miserable, but it can also seriously hinder people’s performance and retention.</p><p>I would also be curious to see the impact of stretching work over a long period of time on the number of bugs that are introduced as a result. It’s probably not too crazy to assume that people are less likely to keep all the moving pieces in their heads and therefore more likely to make mistakes.</p><h3>Rebasing Often</h3><p>On an individual level, the easiest way to start is to rebase often. That is, integrating the other way around: from the main codebase to the development branch.</p><p>It’s not a very interesting point but it’s worth mentioning as this can very easily be overlooked when having one’s nose to the grindstone.</p><h3>Merging More Often</h3><p>It should be clear by now that the main focus should be on merging more often to integrate the changes as early as possible and give a chance to other developers to unearth any issue — such as conflicts — through rebasing their own changes.</p><h3>Breaking Changes Into Smaller Pull Requests</h3><p>Probably the most natural way of approaching a task is to do it all at once and then send a massive pull request to get reviewed by an unlucky colleague.</p><p>Besides breaking the task into smaller ones that are still valuable on their own — which you should definitely do — one can also break it into smaller tasks that don’t necessarily provide value on their own. It might sound silly but it can really help get things moving.</p><p>Think about adding support for new cases to a function and getting it merged <em>before</em> you make the changes to actually use it. Or the other way around, making a new endpoint use a dummy implementation which can be filled later. See the section about feature flags in that case.</p><p>It’s worth mentioning that a side effect of this might be that you end up merging code that won’t actually be needed when you come to implement the rest and realise that your assumptions were wrong. You should keep that in mind and comment your code appropriately. Surely your compiler, linter, and such can help in that matter.</p><p>Another advantage of smaller changes is that they can be reviewed in more detail and potential issues can be unearthed earlier. I don’t know about you but I’m not as attentive when asked to review a pull request with 1,500 additions and 700 deletions.</p><p>In all honesty, I’m often not following my own advice, since of course, breaking changes into smaller pull requests is only feasible if you don’t have to wait a week for these to be reviewed and merged which leads to the following point.</p><p>This is (to some extent) a team initiative more than solo practice.</p><h3>Prioritizing Code Reviews</h3><p>It is tempting to prioritize our own work thinking that by focusing on our current task, we’ll be able to finish faster, and maybe it will be easier to keep the problem in our head. As a result, we may end up postponing a code review to a later date.</p><p>While it can increase your own productivity because everything else is remaining the same, this is — in my opinion — a reductive way of seeing things.</p><p>Software engineering is more often than not a team sport. What matters at the end of the day is how much the project moves forward rather than individual contributions. As a result, we should switch our focus from ourselves to the performance of the team as a whole.</p><p>Putting the team first, prioritizing code reviews becomes the most efficient path since it enables another team member to be productive.</p><p>As a rule of thumb, I try — although it’s easier said than done — reviewing pull requests first thing after any break I take. After such a break, your working memory has been mostly cleared anyway so you might as well do something else like a review before starting working on the current task again.</p><h4>Reviewed in a day or merged</h4><p>Here is something that you might want to try and which I have found quite effective in one of my previous teams.</p><p>After having identified pull requests waiting for review as having a major impact on our work, we decided that we would be allowed to merge any pull request that had been waiting for more than 48 hours.</p><p>A ticking clock often is an excellent motivator.</p><h3>Feature Flags</h3><p>Systematic use of feature flags to enable changes brings two important benefits to the table when it comes to continuous integration.</p><p>The first is that smaller changes become possible. For instance, a new feature doesn’t have to be fully implemented or polished before being merged if it won’t actually be used by any user yet. Some edge cases can be left unhandled or part of the code might be a temporary dummy implementation for testing.</p><p>The second benefit is <em>derisking</em> code changes. Part of the reason we do code reviews in the first place is to detect issues before they hit production and impact real users. Feature flags can be used to defer this task to a later time. If a bug wasn’t found by a reviewer, it can be found after the changes making their way to the main code base but before the feature is enabled for everyone. This means that reviews can potentially be a little bit faster.</p><h3>Decoupling</h3><p>A whole team working on the same code base will inevitably lead to two people making changes to the same thing, which will lead to merge conflicts. Any way to reduce the chance of that happening is a step forward for continuous integration.</p><p>Aside from carefully picking tasks that are least likely to cause conflicts, it also helps to keep an eye on reducing coupling within the codebase. Of course, it’s a good thing in itself as it reduces complexity, allows for faster development, and reduces the likelihood of mistakes.</p><h3>Splitting a Monolith</h3><p>Splitting a monolithic application into microservices has been all the rage lately as companies are moving towards the cloud. The typical reason for doing so is to make the application more scalable and resilient.</p><p>Independent components (microservices or otherwise) can be built independently which can seriously boost the ability of a team to deploy changes fast.</p><p>Sure, it brings its own complexity and it’s a lot of work but it’s worth thinking of how much more productive developers could be if they didn’t have to wait for an hour before the tests are run and the application deployed to production.</p><h3>Resilience as a Tool To Move Faster</h3><p>Putting more emphasis on the system’s resilience certainly helps you sleep at night as well as helping mitigate the effects of bugs and errors, thus allowing changes to be integrated early.</p><p>This might not be obvious at first glance that improving the infrastructure of production would help with continuous integration but I’m convinced that it does have a real impact.</p><p>One way to approach it is to <a href="https://betterprogramming.pub/developers-should-be-a-little-bit-reckless-3d2521ad9641">allow developers to be reckless</a>.</p><h3>Continuous Deployment</h3><p>When breaking a change into smaller pull requests or using feature flags to test and experiment with new features, it’s important to have a short feedback loop.</p><p>In this context, this translates to a short release cycle. It doesn’t get any shorter than continuous deployment, of course, since you end up deploying changes to production as fast as your build and test suite can run.</p><p>A short release cycle is a prerequisite for some of the techniques discussed above. For instance, it’s very easy to fall back to doing larger pull requests if merging smaller changes doesn’t lead to any kind of feedback besides the stress of potentially “breaking the build.”</p><p>This was kind of a random patchwork of thoughts about improving continuous integration without much structure. Hopefully, you can find it useful if only to start thinking about ways you can improve your own workflow beyond simply running tests on pull requests.</p><p>If you like stories like this one, consider a <a href="https://inconclusive.medium.com/membership">membership to Medium</a> and/or <a href="https://inconclusive.medium.com/subscribe">subscribe</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=541242d7a1fb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/how-to-improve-continous-integration-process-541242d7a1fb">How To Improve Continuous Integration Process</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[VS Code Remote Containers with Nix]]></title>
            <link>https://levelup.gitconnected.com/vs-code-remote-containers-with-nix-2a6f230d1e4e?source=rss-c9b51acb947a------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a6f230d1e4e</guid>
            <category><![CDATA[development-environment]]></category>
            <category><![CDATA[software-engineer]]></category>
            <category><![CDATA[nix]]></category>
            <category><![CDATA[vscode]]></category>
            <category><![CDATA[remote-containers]]></category>
            <dc:creator><![CDATA[Tom]]></dc:creator>
            <pubDate>Tue, 31 Aug 2021 17:26:29 GMT</pubDate>
            <atom:updated>2021-09-07T15:03:02.804Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sox1gxzzZ0MlzdGzvcMVJA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@helloitsammiel?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">ammiel jr</a> on <a href="https://unsplash.com/s/photos/container?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p><a href="https://nixos.org/learn.html">Nix</a> already provides a neat way to create a development environment with strong guarantees in terms of reproducibility. However, it still requires developers to install it on their computer which, even though Nix doesn’t install anything in directories such as /usr, can be met with some resistance.</p><p>On the other hand, VS Code’s <a href="https://code.visualstudio.com/docs/remote/devcontainerjson-reference">devcontainers</a> allow a developer to start working on a project without too much hassle granted they use VS Code and have Docker running. They also might feel better about things running in containers and not polluting their host system.</p><p>Here, I’ll describe how to bring these two solutions together and get the best of both worlds. One can use Nix directly on their host system or use VS Code and develop inside a container with the Nix environment.</p><p>This is the setup I have been using for a few months now on some projects. Initially, I was concerned that the overhead of a container might become a problem but it turned out that fear was unfounded.</p><h3>Nix environment</h3><p>This setup is using Nix Flakes to create a development environment. The entrypoint is in flake.nix at the root of the project.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e6d1a5cacb0dcdaa44b7396d7a30f960/href">https://medium.com/media/e6d1a5cacb0dcdaa44b7396d7a30f960/href</a></iframe><p>The flake exports a devShell which is defined in nix/shell.nix as follows. This is just a dummy development environment with the Haskell compiler for the sake of demonstration.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2474fe8c230744b0a0f22eaae318af12/href">https://medium.com/media/2474fe8c230744b0a0f22eaae318af12/href</a></iframe><p>Running nix flake upgrade for the first time will create a new file flake.lock with pinned versions of Nixpkgs and flake-utils. This file should be version-controlled with the rest of the project.</p><p>These basic files are already useful for anyone willing to run Nix on the host rather than inside a container. The command nix develop drops you into a shell with this Nix development environment.</p><h3>Docker image</h3><p>We now need a Docker image with Nix and some more configuration to automatically load the development environment when started.</p><p>Since this relies on Nix Flakes, we need Nix 2.4 (prerelease as of this writing) instead of the latest “official” version.</p><p>The Dockerfile is in .devcontainer/ together with the configuration for Remote Containers since it’s specific to this usage.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6dde7530a29f02056347a639c03a4aeb/href">https://medium.com/media/6dde7530a29f02056347a639c03a4aeb/href</a></iframe><p>This Dockerfile copies .devcontainer/nix.conf inside the container. It’s used to set some options that are needed to make Nix 2.4 work but it’s also a convenient way to share configuration amongst developers. For example, you could set substituters and trusted-public-keys to add some Nix cache.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a692a0324fba8e1338847e297d0abdc5/href">https://medium.com/media/a692a0324fba8e1338847e297d0abdc5/href</a></iframe><p>Finally, .devcontainer/profile.sh loads the Nix development environment as follows.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aeede3dcef197708caaec6279d4a22c4/href">https://medium.com/media/aeede3dcef197708caaec6279d4a22c4/href</a></iframe><p>Don’t forget to make this file executable by running the following command.</p><pre>chmod +x .devcontainer/profile.sh</pre><p>The file .devcontainer/.profile can be added to .gitignore or equivalent. It is only there to make sure the development environment is not garbage collected if you run nix store gc.</p><h3>Configuration for the container</h3><p>The final step is to tell VS Code how to load the devcontainer. This is achieved by adding a configuration at .devcontainer/devcontainer.json.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/225ca3ba609b0c0a4ee3c04752179c05/href">https://medium.com/media/225ca3ba609b0c0a4ee3c04752179c05/href</a></iframe><p>A volume called yourproject_nix will be created and mounted at /nix. This implies that you won’t need to recompile all Nix derivations after rebuilding the container.</p><p>In this example, the VS Code’s extension bbenoist.nix is automatically installed in the container. You might want to add other extensions specific to your project’s tech stack.</p><p>If you like stories like this one, consider a <a href="https://tomferon.medium.com/membership">membership to Medium</a> and/or <a href="https://tomferon.medium.com/subscribe">subscribe</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a6f230d1e4e" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/vs-code-remote-containers-with-nix-2a6f230d1e4e">VS Code Remote Containers with Nix</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Nix Flakes with Bazel]]></title>
            <link>https://levelup.gitconnected.com/using-nix-flakes-with-bazel-8189719ea799?source=rss-c9b51acb947a------2</link>
            <guid isPermaLink="false">https://medium.com/p/8189719ea799</guid>
            <category><![CDATA[software]]></category>
            <category><![CDATA[build-system]]></category>
            <category><![CDATA[nix]]></category>
            <category><![CDATA[bazel]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Tom]]></dc:creator>
            <pubDate>Mon, 30 Aug 2021 01:10:14 GMT</pubDate>
            <atom:updated>2021-09-07T15:02:24.786Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*aj4IXogfazuERicINvKofA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@christinem?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Christine Makhlouf</a> on <a href="https://unsplash.com/s/photos/flake?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p><a href="https://nixos.wiki/wiki/Flakes">Nix Flakes</a> are a new feature of Nix 2.4 (still prerelease as of this writing) to make Nix derivations composable and can be used to distribute derivations to other people.</p><p>This is not a post about what Nix Flakes are though and I recommend reading the series from Tweag (<a href="https://nixos.wiki/wiki/Flakes">first here</a>) to get up to speed if you haven’t already.</p><p>Support for flakes is of course not very widespread. This is a very short explanation of how I bridged the gap between Nix Flakes and Bazel on a project of mine. It’s not complicated but not exactly obvious at first glance.</p><h3>A simple development environment</h3><p>First, we create a simple flake.nix at the root of the project. It uses flake-utils to easily create environments for various systems, e.g. x86_64-linux. We take Bazel from a different version of Nixpkgs since it was broken on nixpkgs-unstable last time I tried.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e185bcb9b39aa9de921186f4ff86d0c2/href">https://medium.com/media/e185bcb9b39aa9de921186f4ff86d0c2/href</a></iframe><p>The “old” nixpkgs (as in import &lt;nixpkgs&gt; {}) is available at attributes such as nixpkgs.legacyPackages.x86_64-linux where nixpkgs here is a flake used as an input to our flake.</p><p>Just for the sake of demonstration, we define a simple Nix overlay which overrides ghc from nixpkgs with a different derivation at nix/haskell/overlay.nix.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0cb4a19f16855402555c1987d5a318f8/href">https://medium.com/media/0cb4a19f16855402555c1987d5a318f8/href</a></iframe><p>In order let Bazel know that the Nix environment depends on this file, we can create BUILD.bazel files in nix/haskell/ with the following rule. This is used later on in WORKSPACE.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/383c6144e7524f308e13d2d32eba5086/href">https://medium.com/media/383c6144e7524f308e13d2d32eba5086/href</a></iframe><p>Next, we can define our development environment as before. I like to put it in nix/shell.nix so (almost) all Nix code ends up in nix/.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eca72f65e14004034e9c8f7565c2572d/href">https://medium.com/media/eca72f65e14004034e9c8f7565c2572d/href</a></iframe><p>Running nix develop should drop you into a shell with Bazel and Python available. Since it’s the first time it runs, another file flake.lock should be generated with the pinned versions of inputs.</p><h3>The bridge</h3><p><a href="https://github.com/tweag/rules_nixpkgs">rules_nixpkgs</a> doesn’t have native support for Nix Flakes so we need to bridge the gap with a simple file that exposes the same nixpkgs as in the flake. We also want any overlay to be applied so Bazel uses the correct version of dependencies.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/30e86b185688efbda870659feeb45f7d/href">https://medium.com/media/30e86b185688efbda870659feeb45f7d/href</a></iframe><h3>Bazel workspace</h3><p>Finally, we can use rules_nixpkgs with our bridge as if we were not using flakes at all.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a0367f49e9810f98c237b7d5886cd43/href">https://medium.com/media/4a0367f49e9810f98c237b7d5886cd43/href</a></iframe><p>As you can see, the key is just that file bazel-nixpkgs.nix which is pretty straightforward. One nice side effect of having this file is also being able to load Nixpkgs in the nix repl by simply typing :l ./bazel-nixpkgs.nix. This trick turned out to be very useful for debugging.</p><p>If you like stories like this one, consider a <a href="https://tomferon.medium.com/membership">membership to Medium</a> and/or <a href="https://tomferon.medium.com/subscribe">subscribe</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8189719ea799" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/using-nix-flakes-with-bazel-8189719ea799">Using Nix Flakes with Bazel</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Pick the Right Language to Display on Your Website]]></title>
            <link>https://medium.com/better-programming/how-to-pick-the-right-language-to-display-on-your-website-37ec0338a659?source=rss-c9b51acb947a------2</link>
            <guid isPermaLink="false">https://medium.com/p/37ec0338a659</guid>
            <category><![CDATA[user-experience]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Tom]]></dc:creator>
            <pubDate>Tue, 18 Feb 2020 14:35:19 GMT</pubDate>
            <atom:updated>2021-09-07T15:01:45.701Z</atom:updated>
            <content:encoded><![CDATA[<h4>Why IP geolocation is bad, and a better strategy to choose the right language for your users</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9-L_uK57zaNyJOLn7DCGxQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@kmanni?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">katie manning</a> on <a href="https://unsplash.com/?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Localisation on the web can be frustrating sometimes. Sadly, this is a problem you only encounter if you travel, you live abroad, or if you live in a multi-lingual country. That covers a lot of people but not necessarily those in charge of a web project.</p><p>It seems that the default choice made is to select a language based on the country the user is in — this, in turn, is based on their IP address. Even though this works if you’re an English-speaker living in Palo Alto, it fails miserably in a lot of other cases.</p><p>Indeed, it relies on the assumption that countries have one language and all people in said country speak that language as their primary language (or at all). This is utterly wrong. For example, in the U.S., only about 80% of the population uses English as their first language and about 13% uses Spanish instead. In Belgium, we have three official languages, namely Dutch (55% of the population), French (38%), and German (0.4%).</p><p>Not only does the default choice gives wrong answers, but it’s also overly complicated. In order to implement it, you would probably have to integrate with an external API, making your application more complex than it has to be and maybe less responsive. All of that for a suboptimal solution.</p><h3>HTTP Has You Covered</h3><p>The HTTP protocol specifies the header Accept-Language for that specific purpose. With every request, the browser sends a list of languages with optional weights representing the preferences of the user.</p><p>Here are some examples from <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language">MDN’s documentation</a>:</p><pre>Accept-Language: de<br>Accept-Language: de-CH<br>Accept-Language: en-US,en;q=0.5</pre><p>By default, browsers send the language of their graphical interface, which is quite likely to be the user’s preferred language.</p><p>It’s not a silver bullet, though, and should be used as a last resort when we have no other ways of knowing the user’s preference in this particular instance. For example, my browser is in English but I would rather see the website in French, my mother tongue, when I log in to the Belgian tax website.</p><p>So how else could we know what language to choose?</p><h3>Explicit and Implicit Choices</h3><p>Of course, if the user made an explicit choice by picking a language in a menu or in their settings if they’re logged in, then this must be the language they’re shown. But there are also implicit choices.</p><p>Most of the time, traffic is coming from somewhere else rather than having the visitor type the URL in the address bar. This can give you a clue as to the language preferred by the user. If I Google something and see a result in English, I want to see the English version when I click on the link.</p><p>Some websites hide the language in a cookie or in the session. It’s better to put it straight into the URL. That way, any link already contains an implicit choice. Search results will lead to the correct version and so will links on social media or any other pages.</p><h3>Fallback Strategy</h3><p>OK, but maybe someone actually types the domain name in the address bar and has changed the browser’s settings to send Accept-Language: * or something like that. What do you do then?</p><p>It might be tempting to guess based on IP geolocation, but there is another dead-simple solution. So simple and obvious, in fact, that I don’t understand why more websites don’t use it.</p><p>Just ask.</p><p>You might not know what language the user speaks and might not be able to make a good guess, but the user knows.</p><p>After all this, there is still a possibility that you made the wrong choice. Make it easy for users to change the language. It’s not rare to see websites where it’s genuinely difficult to find the language menu. Most often it’s because the menu is written in the current language (which the user might not speak) without any visual cue. Use flags or some icon that can be understood by everyone.</p><p>In summary, a more reasonable way of picking a language goes like this:</p><ul><li>If the user has made another explicit choice, use it. Try putting the language in the URL for any page that might be indexed by search engines or shared.</li><li>If there is an implicit choice — e.g., from the URL — use that language.</li><li>Otherwise, use Accept-Language.</li><li>If none of this works, just ask the user.</li></ul><p>If you like stories like this one, consider a <a href="https://tomferon.medium.com/membership">membership to Medium</a> and/or <a href="https://tomferon.medium.com/subscribe">subscribe</a>.</p><h4>Further reading</h4><ul><li><a href="https://factfinder.census.gov/faces/tableservices/jsf/pages/productview.xhtml?pid=ACS_17_5YR_S1601&amp;prodType=table">Language spoken at home</a>, US Census Bureau</li><li><a href="https://ec.europa.eu/commfrontoffice/publicopinion/archives/ebs/ebs_386_en.pdf">Europeans and their languages</a>, European Commission (PDF)</li><li><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language">Accept-Language</a>, MDN web docs</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=37ec0338a659" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/how-to-pick-the-right-language-to-display-on-your-website-37ec0338a659">How to Pick the Right Language to Display on Your Website</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Coding Exercises Should Not Be Used to Rank Candidates]]></title>
            <link>https://medium.com/better-programming/coding-exercises-should-not-be-used-to-rank-candidates-7b0fbde86fe6?source=rss-c9b51acb947a------2</link>
            <guid isPermaLink="false">https://medium.com/p/7b0fbde86fe6</guid>
            <category><![CDATA[project-management]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[hiring]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Tom]]></dc:creator>
            <pubDate>Mon, 17 Feb 2020 16:46:16 GMT</pubDate>
            <atom:updated>2021-09-07T15:00:47.248Z</atom:updated>
            <content:encoded><![CDATA[<h4>Programming exercises aren’t the work we do every day</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jdgkU9sQWvaZnuiGLyc5_g.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@andrewtneel?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Andrew Neel</a> on <a href="https://unsplash.com/s/photos/assignment?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Coding exercises are one of those practices so entrenched in our industry that we reproduce them unthinkingly, forgetting why they are there in the first place. It’s not uncommon to see companies requiring candidates to perform tasks that take 6–8 hours, without even questioning it.</p><p>I believe this is detrimental to both candidates and hiring companies.</p><h3>It Shouldn’t Take That Long</h3><p>In my opinion, a coding exercise (if there is one) shouldn’t take longer than an hour. The longer the task is, the more bias you introduce to the hiring process.</p><p>The most obvious reason is that some people may simply not have the time, for legitimate reasons. Some candidate might still have a full-time job elsewhere and other obligations when they get home.</p><p>The ethics of requiring people to use so much of their free time to work on a coding exercise without any pay seems highly questionable to me.</p><p>But even if we set the ethics aside, long coding tasks not only create bias when selecting candidates — as some of them drop out of the race when presented with the task — but also <em>after</em> the exercise is complete. People with more time will spend more time on it. For example, you might reject one candidate in favour of another because the first didn’t write tests but the second did. What is that really telling you, though? That the first candidate doesn’t know about testing? Unlikely. It may simply mean that the second candidate had more time to spare.</p><p>So no, sorry, I won’t waste a whole day during the weekend working on a coding task for a job that I might not even get!</p><h3>The Code Is Only One Part of the Job</h3><p>If we make our selection purely based on the code produced by candidates in a coding exercise, it’s no wonder we end up with under-performing teams. Being able to solve a very specific problem doesn’t say much about other equally or even more important part of the job.</p><p>Someone’s ability to properly architecture an application is only visible in larger projects — there’s virtually no architecture in a coding task. I think this is especially important when hiring senior developers.</p><p>In the same way that a piece of code (and the need for architecture) doesn’t exist in a vacuum, a developer must collaborate with others for a software project to succeed. A coding task does not measure that in any way.</p><p>These are just some examples of important things ignored by take-home exercises. To that list we can add the candidates ability to learn new technologies, their understanding of the ecosystem, or even their ability to work with legacy code.</p><p>In other words, how well a candidate performs at a coding exercise is not a good measure of how good a developer they are.</p><h3>Familiarity With the Problem and Technology</h3><p>Not knowing the existence of a function that can make the code more readable is mostly irrelevant. When discriminating based on that kind of criteria, you select candidates that are the most familiar with both the technology and the problem of the coding task. It doesn’t say much about the candidate’s strength.</p><p>To illustrate, a strong candidate with many years of experience in Scala applying for a job in Haskell might write something like sequenceA (map f xs) as a weaker candidate with more knowledge of Haskell itself would write the shorter traverse f xs. Here, we would be selecting on how familiar the candidate is with the base library in Haskell, which is mostly irrelevant. Looking at how much they understand functional programming might be more important, for example.</p><p>This is arguably more a problem with how reviewing is done than with the coding task itself. Still, the tendency to judge based on these irrelevant details is real. I think that’s a kind of things people do without even realising it.</p><h3>There’s Already Code out There</h3><p>A lot of developers have code published on GitHub. If a candidate already has code available in the target language for you to look at, it might actually be more valuable than a coding task.</p><p>Such projects are generally bigger than a coding exercise. It means there will be some design and architecture involved. You can also expect to see a more accurate picture of how the candidate works and handles problems.</p><p>The code is likely to be about a project that the candidate understands well rather than some esoteric problem that you sometimes see in coding exercises that have nothing to do with the end job.</p><h4>… and the code which is not out there</h4><p>If someone has three years, say, of experience working with language X, they can write code in language X. You don’t need a coding task to verify that fact.</p><p>I would even say that anyone with enough experience in a developer position can be reasonably deemed able to write code, otherwise it’s highly unlikely they would manage to stay in their job. Moreover, they probably know enough to be able to quickly pick up new technologies and languages.</p><p>Coding tasks are not to be totally thrown away though. I think they can be useful for one thing: filtering out candidates who clearly don’t have the skills for the job.</p><p>In summary, I think we should keep our coding tasks short and use them only as a quick test, when pre-existing code or previous positions don’t give enough information about a candidate.</p><p>If you like stories like this one, consider a <a href="https://tomferon.medium.com/membership">membership to Medium</a> and/or <a href="https://tomferon.medium.com/subscribe">subscribe</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7b0fbde86fe6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/coding-exercises-should-not-be-used-to-rank-candidates-7b0fbde86fe6">Coding Exercises Should Not Be Used to Rank Candidates</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Nix setup for Haskell with ghcide and HLint]]></title>
            <link>https://medium.com/purely-functional/nix-setup-for-haskell-with-ghcide-and-hlint-3e268343efed?source=rss-c9b51acb947a------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e268343efed</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[haskell]]></category>
            <category><![CDATA[nix]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Tom]]></dc:creator>
            <pubDate>Tue, 04 Feb 2020 06:41:42 GMT</pubDate>
            <atom:updated>2021-09-07T15:00:04.741Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WPj8L8YYUUOBurRB1kV5xA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@moyse?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Taton Moïse</a> on <a href="https://unsplash.com/s/photos/machinery?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Nix is an amazing tool but it’s not always easy to find out how to make everything fit together. This article is going to show you how I use it for my Haskell projects. The Nix environment provides everything and nothing (e.g. the compiler) needs to be installed on the machine beforehand.</p><p>With this setup, I get errors and suggestions from <a href="https://github.com/digital-asset/ghcide">ghcide</a> and <a href="https://github.com/ndmitchell/hlint">HLint</a> directly inside VSCode. Haskell dependencies are built with Nix and, more often than not, downloaded from the Nix cache instead. This a completely reproducible environment.</p><p>I also use <a href="https://direnv.net/">direnv</a> to automatically (re)load the environment but I’m not going to cover this here. You can have a look at the repository with the code or read my previous article <a href="https://medium.com/better-programming/easily-reproducible-development-environments-with-nix-and-direnv-e8753f456110">Easy Reproducible Development Environments with Nix and direnv</a>. If you’re not really familiar with Nix, I recommend reading that article and get back to this one later.</p><h3>Demo project</h3><p>For the sake of demonstration, we will create a Cabal package called demo. This is a simple package composed of a library with two modules and an executable. It simply prints a number on the screen.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/79d6c3c784f8d068d74152044021c882/href">https://medium.com/media/79d6c3c784f8d068d74152044021c882/href</a></iframe><p>Now we can add the modules of the library.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cbf52398722cb8cc99da3d9109e50276/href">https://medium.com/media/cbf52398722cb8cc99da3d9109e50276/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/45b00a56c79b331f7a816d27e6209f21/href">https://medium.com/media/45b00a56c79b331f7a816d27e6209f21/href</a></iframe><p>The two modules are there to demonstrate that ghcide is capable of loading the project properly and resolves the type of secretNumber (defined in Module) when inspecting the file src/OtherModule.hs.</p><p>Now comes the executable code. It uses text to show a current limitation of ghcide. More on this later.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/983eaa1e08806dcb639629a386a2f7b4/href">https://medium.com/media/983eaa1e08806dcb639629a386a2f7b4/href</a></iframe><h3>Nix configuration</h3><p>First, we want to pin the version of Nixpkgs so that the environment is fully reproducible. The file nix/sources.nix serves that purpose. You can imagine adding other sources like repositories of dependencies for instance.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e4dcb4d46375573fa57468bab2da9101/href">https://medium.com/media/e4dcb4d46375573fa57468bab2da9101/href</a></iframe><p>We can then use this specific version of the Nixpkgs repository in nix/nixpkgs.nix.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3715c0c3f0573d3500582568ef0087a3/href">https://medium.com/media/3715c0c3f0573d3500582568ef0087a3/href</a></iframe><p>Notice that we pass a list of overlays containing only one for Haskell. Other overlays could be added for, say, Python. The Haskell overlay is where most of the configuration sits. Its job is to add or replace some of the Haskell packages that come with Nixpkgs.</p><p>For example, we want pkgs.haskell.packages.ghc865.hedgehog to be the version 1.0 of hedgehog instead of the version 1.0.1 as is the case in this version of Nixpkgs.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1bacfa9f6d81132c22c38b2840cdc94e/href">https://medium.com/media/1bacfa9f6d81132c22c38b2840cdc94e/href</a></iframe><p>Having the right versions of packages is good but, without a compiler, we won’t go very far. nix/haskell/default.nix is in charge of exposing the tools for use by nix-shell.</p><p>It uses ghcWithHoogle which creates a derivation with a wrapper around GHC that sets the paths to packages properly so that the given packages are available to it. Packages will thus be installed by Nix and not by Cabal. This means it can make use of caches instead of recompiling them. Moreover, we&#39;ll be able to use hoogle server and navigates to <a href="http://localhost:8080/">http://localhost:8080</a> to search for definitions and these packages.</p><p>The list of packages is dynamically extracted from demo.cabal by using cabal2nix to avoid duplication.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/241269b7cf5958236a4574d689abd29d/href">https://medium.com/media/241269b7cf5958236a4574d689abd29d/href</a></iframe><p>We now have all the building blocks required by the development environment and can combine them into nix/shell.nix.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3db3e78bbd1d0e01cf4c557dc91c58be/href">https://medium.com/media/3db3e78bbd1d0e01cf4c557dc91c58be/href</a></iframe><p>Setting NIX_GHC_LIBDIR in there makes ghcide look in the right place for packages. Otherwise, you end up with errors such as cannot satisfy -package-id something.</p><p>Finally, we create shell.nix at the root of the repository importing nix/shell.nix, so that we can call the command nix-shell without arguments.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e53bd955738fa014dc15a5d230cfb0a2/href">https://medium.com/media/e53bd955738fa014dc15a5d230cfb0a2/href</a></iframe><h3>Configuration for ghcide</h3><p>ghcide uses <a href="https://github.com/mpickering/hie-bios">hie-bios</a> to find your project to determine the flags it needs to pass to GHC. We add a file called hie.yaml at the root of the repository to help hie-bios find the project&#39;s modules. As of this writing, ghcide does not support multi cradles yet, so only the first one is used. This is a relatively new feature though.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6c1f9bba513a474c7d1cd5a2518bb0a3/href">https://medium.com/media/6c1f9bba513a474c7d1cd5a2518bb0a3/href</a></iframe><p>In VSCode with the <a href="https://marketplace.visualstudio.com/items?itemName=DigitalAssetHoldingsLLC.ghcide">ghcide extension</a>, we can now get types, errors and code actions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*frS3fls67ya5DsPWeLrTeA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IgNzvUJOR60-2VQie6BYSw.jpeg" /></figure><p>The executable hlint is also in the environment, so we can get linting suggestions alongside annotations from ghcide with the extension <a href="https://marketplace.visualstudio.com/items?itemName=hoovercj.haskell-linter">haskell-linter</a>.</p><p>Nix is a complex beast and it’s hard to get started but I found that having an automatically-built development environment integrated with the editor is truly a game-changer.</p><p>Hopefully, this showed you one way of using Nix for Haskell projects which worked pretty well for me so far. There are certainly other ways and you will probably have to get some inspiration here and there to get a setup tailored to your needs.</p><p>If you like stories like this one, consider a <a href="https://tomferon.medium.com/membership">membership to Medium</a> and/or <a href="https://tomferon.medium.com/subscribe">subscribe</a>.</p><h3>Further reading</h3><ul><li>The <a href="https://github.com/thoferon/haskell-nix-setup">repository</a> with the code in this article on GitHub</li><li><a href="https://direnv.net/">direnv</a></li><li><a href="https://medium.com/better-programming/easily-reproducible-development-environments-with-nix-and-direnv-e8753f456110">Easy Reproducible Development Environments with Nix and direnv</a></li><li><a href="https://github.com/digital-asset/ghcide">ghcide</a></li><li><a href="https://github.com/ndmitchell/hlint">HLint</a></li><li><a href="https://github.com/mpickering/hie-bios">hie-bios</a></li><li><a href="https://marketplace.visualstudio.com/items?itemName=DigitalAssetHoldingsLLC.ghcide">ghcide extension</a> for VSCode</li><li><a href="https://marketplace.visualstudio.com/items?itemName=hoovercj.haskell-linter">haskell-linter extension</a> for VSCode</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e268343efed" width="1" height="1" alt=""><hr><p><a href="https://medium.com/purely-functional/nix-setup-for-haskell-with-ghcide-and-hlint-3e268343efed">Nix setup for Haskell with ghcide and HLint</a> was originally published in <a href="https://medium.com/purely-functional">Purely Functional</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Easily Reproducible Development Environments With Nix and direnv]]></title>
            <link>https://medium.com/better-programming/easily-reproducible-development-environments-with-nix-and-direnv-e8753f456110?source=rss-c9b51acb947a------2</link>
            <guid isPermaLink="false">https://medium.com/p/e8753f456110</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Tom]]></dc:creator>
            <pubDate>Wed, 22 Jan 2020 00:46:59 GMT</pubDate>
            <atom:updated>2021-09-07T14:59:22.011Z</atom:updated>
            <content:encoded><![CDATA[<h3>Easy Reproducible Development Environments with Nix and direnv</h3><h4>Automatic (re)loading of development environments without polluting the operating system and requiring no VMs or containers</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-FHeJVvLAM31Xmcn_bjXqQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@vantorin?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Nikita Vantorin</a> on <a href="https://unsplash.com/s/photos/development?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Getting a working development environment is often far from an easy task. I remember projects where it took new developers (including me) two or three days before getting everything working together on their development computer.</p><p>Using <a href="https://www.docker.com/">Docker</a> and <a href="https://docs.docker.com/compose/">Docker Compose</a> can be very useful in that area but they can only get you so far. They are good for running dependencies without having to worry about building them.</p><p>For example, you can run the database your application runs inside a container and be done with it. Some people are running the application itself inside a container by mounting the code source as a volume.</p><p>It solves the issue of having to install libraries and tooling but it is not as easy as it sounds. What about your text editor for instance? Can you get linting to work painlessly in it?</p><p>In addition to being manual and error-prone, the issue of installing everything locally is that you end up with a whole bunch of programs and libraries on your computer.</p><p>If you work on several projects, it can even get worse when some of them are using different versions of the same thing or conflicting systems.</p><p>Wouldn’t it be nice to be able to install a development environment locally (no containers or VMs) while still leaving your operating system alone?</p><p><a href="https://nixos.org/nix/about.html">Nix</a> solves this issue. All derivations are installed in the Nix store, a directory containing the result of building a derivation. You can think of a derivation as a recipe for how to build a program or a library. That is, nothing ends up polluting your /usr/local/bin.</p><h3>A (Very) Quick Overview of Nix</h3><p>It’s difficult to categorize Nix. On the website, it is presented as a “purely functional package manager”. However, it could also be thought of as a programming language, a configuration tool, and a build tool.</p><p>In a nutshell, Nix expressions are programs written in a purely functional programming language and can return a single derivation or a set of derivations.</p><p>Derivations are data structures describing how to get all the dependencies and build an artifact such as an executable or a library. Nix can then build these derivations and store the result in the Nix store, in practice in /nix/store.</p><p>A key aspect of Nix is that builds are <em>reproducible</em>. It means that, given some derivation, it doesn’t matter on what computer or what time you attempt to build it, it will produce the same result (with a few exceptions for practical reasons).</p><p>To avoid building things that have already been built, the paths in the Nix store are named with the structure hash-name-version where hash is the hash of the derivation. That way, if a derivation is needed again, Nix will see it’s already in the Nix store and won’t rebuild it again.</p><p>Similarly, Nix caches also help prevent duplicated work. If a derivation has already been built on a remote machine that is sharing its Nix store as a cache with your computer, Nix will simply download it instead of building the derivation locally.</p><p>Nix can be used to build just about anything: dependencies for your project, your project itself, but also Docker containers and a whole Linux system with <a href="https://nixos.org/nixos/manual">NixOS</a>.</p><h3>Nixpkgs</h3><p><a href="https://nixos.org/nixpkgs/manual/">Nixpkgs</a> is a huge resource of Nix expressions with lots and lots of derivations for common programs and libraries. According to its README file, it has over 40,000 packages as of this writing.</p><p>It also has a bunch of helper functions and ways to build dependencies for different programming languages and frameworks. Worth mentioning are <a href="https://golang.org/">Go</a>, Node, Java, Python, <a href="https://www.rust-lang.org/">Rust</a>, and <a href="https://www.haskell.org/">Haskell</a>.</p><h3>nix-shell</h3><p>nix-shell is a command-line tool used to start an interactive shell in an environment based on some derivation(s).</p><p>By default, it will look for a shell.nix or default.nix in the current directory which should return a derivation. Then, it will reproduce the environment in which the build of the derivation would run, that is an environment where all the dependencies are available.</p><p>It’s also convenient sometimes to use nix-shell to quickly drop in a shell with some programs. This can be achieved with the -p option. For example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f580ed06ca6f7886c5e252e124a0d59b/href">https://medium.com/media/f580ed06ca6f7886c5e252e124a0d59b/href</a></iframe><h3>Development Environment Without direnv</h3><p>We need a file called shell.nix at the root of our project so we can call nix-shell and have all the dependencies and development tools available. However, to keep things organized, all the Nix code will be in a directory nix/.</p><p>Don’t worry too much about not fully understanding the Nix code. The goal here is to demonstrate how to use Nix to create a development environment, not to teach you Nix itself.</p><p>If you want to learn more about the language itself, this <a href="https://nixos.org/nix/manual/#chap-writing-nix-expressions">section</a> of the manual is all you need to get started.</p><p>We also want to fix the version of Nixpkgs so that the development environment is fully reproducible. nix/sources.nix is going to contain external references like these.</p><p>Here, e4d0e33f36491a0e08a3b1a15db13366d7d0785f is the hash of the commit we want to get derivations from.</p><pre>{<br>  nixpkgs = builtins.fetchGit {<br>    url = &quot;https://github.com/NixOS/nixpkgs.git&quot;;<br>    rev = &quot;e4d0e33f36491a0e08a3b1a15db13366d7d0785f&quot;;<br>  };<br>}</pre><p>Let’s say our project is a small executable written in Haskell printing the value of the environment variable PORT and a random number by calling cowsay.</p><p>Not too fancy but it still requires a development environment where we can compile Haskell programs so we need a compiler, the libraries random and process, and the program cowsay.</p><p>In nix/shell.nix, we can now create the derivation for the environment with the help of the function pkgs.mkShell.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/90480c1a3f6815b05d0bb35b7a6d6276/href">https://medium.com/media/90480c1a3f6815b05d0bb35b7a6d6276/href</a></iframe><p>As you can see, mkShell takes an attribute set (equivalent to an object in JavaScript or a dictionary in Python). buildInputs is the list of dependencies. You could add pkgs.docker-compose or pkgs.nodejs-12_x in there for example.</p><p>Keys that are not used such as PORT are added to the environment variables as-is. Don&#39;t worry too much about ghcWithPackages as this is a Haskell-specific way of pulling libraries together with the compiler.</p><p>It is convenient to call the command nix-shell without any argument from the root directory, so we need a file shell.nix at the root. It&#39;s simply importing nix/shell.nix.</p><pre>import nix/shell.nix</pre><p>Finally, here’s the code of our little program for demonstration purposes.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/047b058b5ea5e01319e9ced4be3db6e5/href">https://medium.com/media/047b058b5ea5e01319e9ced4be3db6e5/href</a></iframe><p>After calling nix-shell, we can compile and run the program as follows.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/409e0ab4ed2e03354420931d8e65cdb2/href">https://medium.com/media/409e0ab4ed2e03354420931d8e65cdb2/href</a></iframe><h3>Automatic (Re)loading With direnv</h3><p>The problem with using nix-shell directly is that, every time you change your environment&#39;s specification, you need to exit and reload the shell. Moreover, it overrides the prompt.</p><p>Maybe more importantly, if the shell is not currently active, there is no garbage collection root, a symbolic link in /nix/var/nix/gcroots. This is how Nix keeps track of what paths in the Nix store are used and what can be removed.</p><p>It means that running nix-collect-garbage would delete all paths required by your development environment, thus requiring you to rebuild or re-download dependencies next time you run nix-shell because Nix has no idea you still need it.</p><p><a href="https://direnv.net/">Direnv</a> can be used to solve these issues. It looks for a file .envrc and loads the environment when entering the directory. Exiting the directory unloads the environment. It is not a Nix tool but it comes with a function called use_nix that loads/unloads Nix environments with nix-shell.</p><p>Let’s add a file .envrc to our dummy project. The contents of direnv/use_nix.sh are not listed here but you can have a look in the <a href="https://github.com/thoferon/nix-direnv/blob/master/direnv/use_nix.sh">demo repository</a>. The code of use_nix comes from <a href="https://github.com/direnv/direnv/wiki/Nix">direnv’s Wiki page about Nix</a>.</p><pre>#!/usr/bin/env bash</pre><pre>. direnv/use_nix.sh</pre><pre>use_nix -s shell.nix \<br>  -w nix/sources.nix \<br>  -w nix/shell.nix</pre><p>The options -w tells direnv to reload the environment when one of these files changes. The first time you will have to call direnv allow to tell direnv that it’s OK to run this particular .envrc.</p><p>That’s it! The only prerequisites this project needs now are Nix and direnv with direnv not even being strictly necessary.</p><p>This won’t pollute the developers’ computers because Nix is not installing anything in the usual directory such as /usr/local/bin and everyone is running the exact same environment since the version of Nixpkgs is pinned in nix/sources.nix (don&#39;t forget to update it every now and then).</p><h3>Support for VS Code</h3><p>VS Code has extensions for both Nix and direnv, although you only need <a href="https://github.com/rubymaniac/vscode-direnv">the extension for direnv</a> in this case. You can quickly install it by typing ext install direnv in the open dialog (ctrl+p).</p><p>If some extensions require some tools from the Nix environment, it might require the editor to be reloaded but, other than that, I had a pretty smooth experience with it.</p><h3>Conclusion</h3><p>Using these two tools together made managing dependencies significantly easier for me. No need for long setups anymore that take two days before you can even start working on a project.</p><p>Nix has a steep learning curve but a lot can be achieved with it without knowing much about the language and the internals of the tooling.</p><p>It doesn’t take long to get it working, so give a shot!</p><p>If you like stories like this one, consider a <a href="https://tomferon.medium.com/membership">membership to Medium</a> and/or <a href="https://tomferon.medium.com/subscribe">subscribe</a>.</p><h3>Further Reading</h3><ul><li>The <a href="https://github.com/thoferon/nix-direnv">repository</a> with the code from this article.</li><li><a href="https://www.docker.com/">Docker</a> and <a href="https://docs.docker.com/compose/">Docker Compose</a>.</li><li><a href="https://nixos.org/nix/manual/">Nix manual</a> and its section about <a href="https://nixos.org/nix/manual/#chap-writing-nix-expressions">writing Nix expressions</a>.</li><li><a href="https://nixos.org/nixos/manual/">NixOS manual</a>.</li><li><a href="https://nixos.org/nixpkgs/manual/">Nixpkgs manual</a>.</li><li><a href="https://direnv.net/">direnv</a></li><li><a href="https://github.com/direnv/direnv/wiki/Nix">direnv’s Wiki page about Nix</a>.</li><li><a href="https://github.com/rubymaniac/vscode-direnv">vscode-direnv</a>, the VS Code extension for direnv.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e8753f456110" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/easily-reproducible-development-environments-with-nix-and-direnv-e8753f456110">Easily Reproducible Development Environments With Nix and direnv</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Functional Patterns to Carve Side-Effects Away From Logic]]></title>
            <link>https://medium.com/better-programming/functional-patterns-to-carve-side-effects-away-from-logic-42158d9ef889?source=rss-c9b51acb947a------2</link>
            <guid isPermaLink="false">https://medium.com/p/42158d9ef889</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Tom]]></dc:creator>
            <pubDate>Tue, 14 Jan 2020 22:56:38 GMT</pubDate>
            <atom:updated>2021-09-07T14:58:33.923Z</atom:updated>
            <content:encoded><![CDATA[<h4>Improve the testability of your code with functional programming</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2RjNxLZloej2yTz6JtwkKQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@drew_beamer?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Drew Beamer</a> on <a href="https://unsplash.com/s/photos/split?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>You may have heard of monads, effect systems, or final tagless and bounced back to the previous page thinking it was just academic mumbo jumbo with little practicality.</p><p>To be fair, they certainly are amongst the concepts with steeper learning curves but they are still widely applicable.</p><p>There is a common, dead-simple idea behind all of them. It is a recurring theme throughout functional programming, especially in a purely functional programming language such as <a href="https://www.haskell.org/">Haskell</a>.</p><p>The key concept is to split your program to have the logic on one side and the execution with the side-effects on the other.</p><p>We’ll go through some examples in JavaScript since it has become the lingua franca of programming and I want to keep this language-agnostic.</p><h3>Using Dependency Injection</h3><p>A widespread technique in the object-oriented world that can be used to take the side-effects out of some code is <a href="https://www.freecodecamp.org/news/a-quick-intro-to-dependency-injection-what-it-is-and-when-to-use-it-7578c84fa88f/">dependency injection</a>.</p><p>All the code that has-side effects can be replaced by calls to functions or methods on objects that are received as an argument or passed at initialization time.</p><p>It is fairly straightforward and widely-understood and should probably be favored over the later techniques. Albeit less powerful than them, dependency injection consumes fewer fancy points and helps keep complexity under control.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d789ed27e93b12928f55bc9d5643b925/href">https://medium.com/media/d789ed27e93b12928f55bc9d5643b925/href</a></iframe><h3>Encoding the Program as a Value</h3><p>Things become interesting once the program is encoded as a value. Indeed, values can be analyzed and transformed.</p><p>It opens the gate to optimizations, generating documentation automatically, or adding functionality to programs without changing them directly. For example, you could add access control to a program while keeping the program completely unaware of its existence.</p><p>The application code is therefore pure since it only returns a value without any side-effect. It is the role of an interpreter to execute the program. We essentially split the code into two (or more) parts:</p><ul><li>Some pure code that returns a description of an effectful program as a value.</li><li>Optionally, some function(s) transforming programs.</li><li>An interpreter that runs programs encoded as a value.</li></ul><h3>Sequential Programs</h3><p>Here is a simple example where the user tries to guess a number. The program is composed of simpler programs (print, read, and pure) which are encoded as values.</p><p>Each of them is an object with an action, some values specific to that action and the next action to take after this one. Note that next is a function taking the result of the current action and returning a new program.</p><p>We can also define operations of such programs. For example, bind takes a program and a function that takes its result and returns a new program and combines the two to form a third program.</p><p>bind traverses the chain of actions and replaces the last one (a pure) by a call to the given function. Note that the recursion happens inside next which means it doesn&#39;t happen until it is called, i.e. bind is lazy.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/206cdee2aed7fd4e99885d98611da943/href">https://medium.com/media/206cdee2aed7fd4e99885d98611da943/href</a></iframe><p>Because of its sequential nature, the next step is only known after having executed the current one.</p><p>For example, depending on the user input, the program can branch into different subprograms. This limits us into what we can do with such values.</p><p>Indeed, we can’t analyze the next action before having interpreted the current one and fed the result to its next function. This doesn&#39;t mean we can&#39;t do interesting things with it though, as we will see further.</p><h3>Non-Sequential Programs</h3><p>If we don’t need to execute one action after another, we can encode the program in a way that still allows it to be statically analyzed, which is analyzed without running the code.</p><p>Here is a simple example of a JSON parser. As before, there is a basic program called pure that simply returns a constant. The difference is the function apply instead of bind.</p><p>apply takes two programs — the former returning a function and the latter a value — and returns a new program that runs the two and applies the value to the function.</p><p>By combining programs in this way, we have access to the subprograms without having to run anything.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0534776a76d5a430da29f33721295d1f/href">https://medium.com/media/0534776a76d5a430da29f33721295d1f/href</a></iframe><p>As in the previous example, there is quite a lot of boilerplate and it is not very practical to use. There is certainly room for improvement but the goal is only to convey the underlying idea of programs as values.</p><h3>Testing</h3><p>One use case of such constructs is to make testing easier. The only thing needed is another interpreter that does not have the side-effects.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab38ea321d52acba3942b4ccdae6b15d/href">https://medium.com/media/ab38ea321d52acba3942b4ccdae6b15d/href</a></iframe><h3>Generating Documentation</h3><p>In the case of non-sequential programs, we don’t have to execute the code to analyze it. It means we can do interesting things like generating documentation automatically.</p><p>Take our previous parsing example, we can generate documentation in the form of a JSON object for the parser. For our example, it would return { &quot;database&quot;: { &quot;port&quot;: &quot;number&quot;, &quot;username&quot;: &quot;string&quot; } }.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a8be7901cef9b302c3270e77ab7c4bd7/href">https://medium.com/media/a8be7901cef9b302c3270e77ab7c4bd7/href</a></iframe><h3>Relation to Concepts</h3><p>In the functional world, <em>monads</em> would be used — more specifically <em>free monads</em> — in the case of sequential programs.</p><p>This is very close to what our little game does, although much of the boilerplate would be alleviated by the abstraction provided by a library such as <a href="https://hackage.haskell.org/package/free">free</a> in Haskell.</p><p>For non-sequential programs such as parsers, a very similar abstraction to what has been shown here is the <em>applicative functor</em> (or just <em>applicative</em>) and its cousin, the <em>free applicative</em>.</p><p>Finally, dependency injection is closer to the <em>final tagless</em> approach.</p><h3>Conclusion</h3><p>The examples here are of little practical use in most real-life situations considering the amount of boilerplate and complexity they introduce but, hopefully, they show the key idea behind these constructs without being too obfuscated.</p><p>Separating the definition of programs from their interpretation allows us to add steps in-between, to transform the program before interpretation. We can also have different interpreters for tests or for static analysis (like generating documentation).</p><p>Languages like Haskell have syntactic sugars and operators that make the use of, for example, monads and free applicatives, very convenient (and, in fact, ubiquitous.)</p><p>Whatever language you use, there is surely a way to encode programs in a more convenient way than presented here.</p><p>If you like stories like this one, consider a <a href="https://tomferon.medium.com/membership">membership to Medium</a> and/or <a href="https://tomferon.medium.com/subscribe">subscribe</a>.</p><h3>Further Reading</h3><ul><li><a href="https://www.freecodecamp.org/news/a-quick-intro-to-dependency-injection-what-it-is-and-when-to-use-it-7578c84fa88f/">A quick intro to dependency injection</a>, Bhavya Karia on freeCodeCamp.</li><li><a href="https://curiosity-driven.org/monads-in-javascript">Monads in Javascript</a>, Curiosity-Driven.</li><li>The Haskell library <a href="https://hackage.haskell.org/package/free">free</a>, Hackage.</li><li><a href="https://gist.github.com/thoferon/a4e1ee37fc85c6237d3c4cf3826b7390">The code of this article</a> on GitHub gist.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=42158d9ef889" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/functional-patterns-to-carve-side-effects-away-from-logic-42158d9ef889">Functional Patterns to Carve Side-Effects Away From Logic</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Case For Conventional Commits in Git]]></title>
            <link>https://medium.com/better-programming/a-case-for-conventional-commits-in-git-d70c65245009?source=rss-c9b51acb947a------2</link>
            <guid isPermaLink="false">https://medium.com/p/d70c65245009</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Tom]]></dc:creator>
            <pubDate>Mon, 13 Jan 2020 21:28:12 GMT</pubDate>
            <atom:updated>2021-09-07T14:57:15.804Z</atom:updated>
            <content:encoded><![CDATA[<h4>Add structure and improve the readability of your commits</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v6XeL5ZKVBpwwZlqHp-Isw.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@yancymin?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Yancy Min</a> on <a href="https://unsplash.com/s/photos/git?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>About a year ago, I started to use conventional commits for my personal projects and at work and haven’t regretted it so far. It led me to more clearly communicate what changes are about. My commit history is a lot more manageable as a result.</p><p><em>Conventional commits </em>are a specification for formatting commit messages that’s lightweight and readable by both humans and machines. Even without using tools that can parse them, it’s still useful for developers alone.</p><p>Each commit message has a type classifying changes into features, fixes, tests, etc. It also has an optional scope for which part of the project is affected by the change and a short explanation of what has been done. Then comes the body with more details and the context in which it all happened. Finally, the footer would contain information such as the ticket number from the issue tracker and similar metadata.</p><p>The easiest way to get an idea of what it looks like is by seeing some examples. Here’s a minimal commit message satisfying the rules.</p><pre>feat: add an endpoint to get contents recommendation</pre><pre>GET /contents/:topics/recommendation returns a JSON with some<br>recommendations for the user.</pre><p>The following is a longer commit message with more details. It has a scope (api) and a footer with metadata.</p><pre>test(api): assess test suite quality with mutation analysis</pre><pre>Add a new executable `mutation-analysis` that analyses the API&#39;s<br>test suite and returns a score that we can use to keep track of<br>how good our tests are at catching defects. This is a better<br>approach than code coverage.</pre><pre>It works by running the tests against mutants of the API<br>(slightly different versions of the code, e.g. a &lt; could be<br>replaced with a &lt;=) and counting the proportion of mutants that<br>the tests catch. This is relying on the assumption that most<br>mutants are invalid and should make the tests fail.</pre><pre>Issue: ABC-456<br>Approved-By: Tom Feron</pre><p>You can learn more about how to format them by reading the <a href="https://www.conventionalcommits.org/en/v1.0.0/">specification</a>. My goal for the rest of this piece is to share my experience with them and how they provided me with value.</p><h3>Lightweight</h3><p>As you can see, they’re very simple and hardly need any commitment. There’s nothing to set up and no dependencies on any tool. If you change your mind, you can simply stop using them.</p><p>The cost of starting with conventional commits is therefore virtually null.</p><p>It might take a little longer for you to write commit messages, but your teammates — or your future self — will thank you for it.</p><p>The only requirement is to decide on some commit types (or <a href="https://github.com/conventional-changelog/commitlint/tree/master/%40commitlint/config-conventional">steal some</a>) and scopes if you decide to use them. In the beginning, some improvisation is perfectly fine, though. Just use whatever feels sensible and adjust later.</p><h3>Easier to Go Through</h3><p>An important part of software development is communicating with other human beings rather than computers. This includes commenting on your code, <a href="https://medium.com/swlh/your-job-as-a-developer-handling-complexity-66e0c7063a35">keeping things simple</a> (even at the cost of performance sometimes), and also making good commit messages.</p><p>Clear communication implies conveying meaning rapidly and accurately. With that goal in mind, standard formatting helps others quickly parse a commit message to get a sense of what the change is about and highlights the key information.</p><p>What I noticed after using conventional commits for a while was how it pushes me to give more explanation and context. When I would have previously written commit messages such as “Fix tests” — come on, who hasn’t? — I now would write commit messages like the following:</p><pre>test(api): fix comment&#39;s JSON in endpoint test</pre><pre>The key `actorId` was deprecated a few months ago and removed<br>recently but the test suite hadn&#39;t been updated.</pre><p>Note that I’m using test for test fixes here except if it implies a bug in the application code. fix should be reserved to bug fixes. Indeed, it makes debugging regressions and release tracking easier. Speaking of which ...</p><h3>1 commit = 1 change</h3><p>Something else I noticed when using conventional commits is how it forces me to commit one change at a time. When you have to start your commit with feat(task-runner): something, you think twice before committing some unrelated refactoring at the same time.</p><p>It’s sometimes acceptable to put some unrelated function renaming — or reformatting of some piece of code — in the same commit as a new feature you’re working on and mention it in the commit message’s body.</p><p>While this is sometimes true, there’s a right balance to find between too many commits and the noise that comes with it. You don’t necessarily want to bury changes into other commits, thus obfuscating the commit history.</p><p>You don’t need conventional commits to clearly split changes into separate commits, but, from my experience, it helps to get the necessary discipline to do so.</p><h3>Release Tracking</h3><p>In the days of Agile development, it’s hard to keep track of what has changed and when it did. This is particularly problematic when debugging issues in production. Conventional commits tell you the kind of change and its scope for every commit in a parsable way for both humans and machines.</p><p>Another situation when tracking releases is useful is for traffic analysis. Knowing that the spike in conversion of your website happened right after the deployment of 3d0e862dacf9655236bd73c31676170037e87483, or even fix spacing, is not exactly helpful.</p><p>With conventional commits, you can filter out irrelevant commits based on the type and scope and only show the changes susceptible to be the root cause of what you can observe.</p><h3>Changelog</h3><p>In preparation for a sprint review, have you ever been asked (or asked your colleagues yourself), “What did we ship this week?” Your task manager or kanban board might not be very helpful in showing what has actually been merged. Some changes aren’t captured by such tools, and others are only parts of a Jira issue but still deliver value and are worth mentioning.</p><p>Once again, conventional commits can help in automatically generating a changelog that accurately reflects what’s actually happened.</p><p>There are some tools available to automate that process. For example, <a href="https://github.com/conventional-changelog/conventional-changelog">conventional-changelog</a> is a set of tools designed for that very purpose.</p><h3>Conclusion</h3><p>Considering how easy it is to start using conventional commits and the almost nonexistent cost, you’d encourage anyone to at least give it a shot and see for themselves how it plays out.</p><p>There’s no need to automate anything in the beginning. Conventional commits are already useful when only used by people.</p><p>If you like stories like this one, consider a <a href="https://tomferon.medium.com/membership">membership to Medium</a> and/or <a href="https://tomferon.medium.com/subscribe">subscribe</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d70c65245009" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/a-case-for-conventional-commits-in-git-d70c65245009">A Case For Conventional Commits in Git</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>