<?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 Lucas Sonnabend on Medium]]></title>
        <description><![CDATA[Stories by Lucas Sonnabend on Medium]]></description>
        <link>https://medium.com/@lucas_sonnabend?source=rss-29d38576ad72------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*SKDxANPhcZbM3B8xediw6g.jpeg</url>
            <title>Stories by Lucas Sonnabend on Medium</title>
            <link>https://medium.com/@lucas_sonnabend?source=rss-29d38576ad72------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 17:13:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lucas_sonnabend/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[The programming languages that helped me master software engineering]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://levelup.gitconnected.com/the-programming-languages-that-helped-me-master-software-engineering-12793de99fbb?source=rss-29d38576ad72------2"><img src="https://cdn-images-1.medium.com/max/2388/1*pZ1B39upfCtidBODfO1geg.png" width="2388"></a></p><p class="medium-feed-snippet">My journey through different programming languages and the lessons I took from them</p><p class="medium-feed-link"><a href="https://levelup.gitconnected.com/the-programming-languages-that-helped-me-master-software-engineering-12793de99fbb?source=rss-29d38576ad72------2">Continue reading on Level Up Coding »</a></p></div>]]></description>
            <link>https://levelup.gitconnected.com/the-programming-languages-that-helped-me-master-software-engineering-12793de99fbb?source=rss-29d38576ad72------2</link>
            <guid isPermaLink="false">https://medium.com/p/12793de99fbb</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Lucas Sonnabend]]></dc:creator>
            <pubDate>Sun, 24 Oct 2021 21:19:14 GMT</pubDate>
            <atom:updated>2021-10-24T21:19:14.624Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[How to Write Clean JavaScript Code with Functional Programming]]></title>
            <link>https://javascript.plainenglish.io/how-to-write-clean-javascript-code-with-functional-programming-54fd60a56074?source=rss-29d38576ad72------2</link>
            <guid isPermaLink="false">https://medium.com/p/54fd60a56074</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Lucas Sonnabend]]></dc:creator>
            <pubDate>Tue, 19 Oct 2021 05:43:02 GMT</pubDate>
            <atom:updated>2021-10-19T05:43:02.523Z</atom:updated>
            <content:encoded><![CDATA[<h4>Refactor your imperative code into functional code to improve readability without sacrificing performance.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cY0XMzjnZGPmBG8VlO0hCw.jpeg" /><figcaption>Cartoon adapted from <a href="https://geek-and-poke.com/geekandpoke/2013/9/18/the-art-of-programming">geek-and-poke.com</a>, Licence <a href="https://creativecommons.org/licenses/by/3.0/">CC-BY-3.0</a></figcaption></figure><p>I am a big advocate for writing code in a functional style. When done correctly, it is easier to read, decompose and test. Yet, a lot of people seem to be sceptical about it and worry about performance implications.</p><p>So let me try to convince you of the advantages of writing in a functional style with a real-world example, both in imperative and functional style.</p><p>I don’t advocate always writing functional code. Sometimes it makes sense to have code organised around objects, have side effects that interact with the environment or store state. But that still leaves plenty of occasions to use immutable variables and pure functions to help structure your code.</p><h3>The Real-World Example</h3><p>I based the following example on a similar problem I came across at work. We have a long list of objects with id and amount And we want to find entities with the same id and merge them into a single entity.</p><h4>Procedural solution</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/33e63f35c80f271b47da5a1325d498ef/href">https://medium.com/media/33e63f35c80f271b47da5a1325d498ef/href</a></iframe><p>What makes this procedural? The main idea is that you have a result object that starts as empty and continuously append to it. This object is mutable; a surefire tell that this function is not very functional.</p><h4>Functional Solution</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fb9f43d99526a0215e312bc2127fdda5/href">https://medium.com/media/fb9f43d99526a0215e312bc2127fdda5/href</a></iframe><p>This solution heavily relies on the <a href="https://lodash.com/d">lodash</a> library. Its approach is to group all objects by their id and merge any groups with more than one object into a single entity. To make it slightly more efficient, it uses <a href="https://www.geeksforgeeks.org/lodash-_-chain-method/">chain</a> functionality. I’ll explain this in more detail later.</p><p>No variable in this solution is re-assigned or modified, so all of them are immutable. The foreach has been replaced by a map, another typical pattern of functional programming.</p><p>On the first view, you might say that the functional solution looks more complex, but let me explain why I favour it.</p><h3>Immutable Variables make it Easier to Read</h3><p>It might sound surprising to you, but please bear with me. Immutable variables make it much easier to understand what a variable contains. A variable is created once and never modified, have exactly one place to read to find out what the variable contains.</p><p>In the procedural example, the result is first an empty object, according to line 2. According to line 10, we turn it into a map from id to entity, and the values consist of the input objects. But according to lines 5–8, it is not just a map, as values are updated on an id collision. Hopefully, you can see how the complexity builds up, even though the example is relatively small. Imagine a more complex scenario, where you write to an object in 5–6 different places! The same can never happen if all your variables are immutable!</p><h3>Smaller Scopes make it Easier to Break Code into Sub-Functions</h3><p>The functional example is split into two functions, the procedural code is not, and there is a reason behind it!</p><p>The map and the forEach loop do roughly the same, they iterate through the items and merge duplicates, but they are build up in very different ways.</p><p>The body of the forEach loop updates resultsbut this is defined outside the scope of the function body. Because the loop body accesses variables in the outer scope at any time, you cannot understand them in isolation. If you were to refactor the body of the loop into a sub-function, you would have to pass in the results object as an <a href="https://www.informit.com/articles/article.aspx?p=1382188">output variable, a definite code smell</a>.</p><p>On the other hand, map applies a function that is entirely free of any side effects. All inputs are passed in by value, and the only way data flows out is via return statements. Everything else is limited to the scope of that function.</p><p>As you can see, writing your code in a functional style makes it easier to split it into sub-problems, and by extension, sub-functions.</p><h3>It is Easier to Test</h3><p>We just established that the functional solution accommodates smaller sub-functions. As a result, we can test them individually. That, in turn, makes it easier to cover more edge cases, and you have more confidence that your code works!</p><p>Tests for smaller sub-functions also means better regression tests. A failure of a particular test will narrow down the problem, and the fix will be more straightforward.</p><h3>It is just as Fast as the Procedural Solution</h3><p>A common prejudice against functional programming is that less performant than a comparable imperative solution. After all, C is one of the fastest languages, and it is purely functional.</p><p>Functional programs can indeed have a performance penalty, for example, because immutable variables result in a bigger memory footprint. This is because instead of updating the same object in memory, it is copied across repeatedly. A more naive functional solution might have intermediate objects for the grouped items and use more memory.</p><p>Here lodash chains come to the rescue. Instead of computing and storing the entire set of intermediate values, the execution is lazy. IT defers computation until the value() call and merges intermediate steps to avoid building complete sets of intermediate values.</p><p>But you can always argue about performance; the easiest way is to run the code and measure it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*_jmxHZiTRn8QLxUIe3pV0w.png" /><figcaption>Runtime comparison for the procedural and function solutions</figcaption></figure><p>As you can see, the functional solution is slightly slower for smaller input sizes between 10K and 50K elements and ever so slightly faster for larger ones. The only significant outlier is for 5M elements, where the functional code takes 20 seconds, compared to 13 seconds for the procedural code.</p><p>Tweaking node.js itself with the following --max-old-space-size=2048 --max-semi-space-size=2048 eliminates that difference. So it’s fair to say that there is neither a performance penalty nor benefit.</p><h3>A Note on Other Languages</h3><p>I based the example and arguments on JavaScript running with node.js, but can this be applied to other languages, too? Yes, but with some limitations.</p><p>The arguments around readability, scoping, and testability are applicable pretty much across any language, but the syntax and supporting libraries around it will, of course, differ.</p><p>When it comes to performance benefits or penalties, it will depend on implementation details of the language’s runtime environment. When in doubt here, you will have to measure it yourself and do your research.</p><p>I come for a python background, where best practice advises to use list comprehensions, maps and filters because it can be significantly faster. Still, the actual speedup often lies within internal details of the python interpreter and runtime.</p><h3>Final Thoughts</h3><p>Hopefully, these arguments convinced you to make your code more functional, even if it is just by a tiny amount. But, of course, it requires practice, effort and sometimes a different way of thinking to find a concise functional representation. Nevertheless, the payoff is a new angle to approach a problem. In addition, your code will become more readable and testable, and who doesn’t like that?</p><p>There is a lot more to functional programming than what I touched on in this article. That’s why I have been calling it a functional style instead of functional. I haven’t touched on concepts like functions as first-class entities, currying, or pattern matching.</p><p>Unfortunately, I also don’t have a silver bullet to teach functional programming. But writing a more functional code is always a good start, be it in a fully functional language like Haskell or multi-paradigm languages like Python and JavaScript.</p><p>P.s.: I’m promoting the _.chain method of lodash knowing that <a href="https://medium.com/bootstart/why-using-chain-is-a-mistake-9bc1f80d51ba">this article is arguing against using it</a>. The main arguments against it are bundle size and build-time. I have been using this server-side with node.js, where neither of them is crucial to me. For front-end code, this might be more important. Either way, the article dives into some more functional programming concepts and is worth a read!</p><p><em>For more articles around software engineering, </em><a href="https://medium.com/@lucas_sonnabend/membership"><strong><em>sign up on Medium with my referral link</em></strong></a><em> and check out </em><a href="http://plainenglish.io/"><strong><em>plainenglish.io</em></strong></a><strong><em>.</em></strong></p><p><em>More content at </em><a href="http://plainenglish.io/"><strong><em>plainenglish.io</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=54fd60a56074" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/how-to-write-clean-javascript-code-with-functional-programming-54fd60a56074">How to Write Clean JavaScript Code with Functional Programming</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Is Bitclout the Next Big Social Platform? I Am Yet to Be Convinced]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/swlh/is-bitclout-the-next-big-social-platform-i-am-yet-to-be-convinced-f2fdddded4da?source=rss-29d38576ad72------2"><img src="https://cdn-images-1.medium.com/max/2600/0*mEPdeDnZmKaQ9-sj" width="6000"></a></p><p class="medium-feed-snippet">My take at understanding the platform and what risks and rewards it has to offer to its users.</p><p class="medium-feed-link"><a href="https://medium.com/swlh/is-bitclout-the-next-big-social-platform-i-am-yet-to-be-convinced-f2fdddded4da?source=rss-29d38576ad72------2">Continue reading on The Startup »</a></p></div>]]></description>
            <link>https://medium.com/swlh/is-bitclout-the-next-big-social-platform-i-am-yet-to-be-convinced-f2fdddded4da?source=rss-29d38576ad72------2</link>
            <guid isPermaLink="false">https://medium.com/p/f2fdddded4da</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[social-media]]></category>
            <dc:creator><![CDATA[Lucas Sonnabend]]></dc:creator>
            <pubDate>Sun, 10 Oct 2021 21:17:34 GMT</pubDate>
            <atom:updated>2021-10-10T21:17:34.675Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Advanced Unit Tests: 5 Pitfalls and How To Avoid Them]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/better-programming/advanced-unit-tests-5-pitfalls-and-how-to-avoid-them-eb6e04ec9654?source=rss-29d38576ad72------2"><img src="https://cdn-images-1.medium.com/max/1360/1*n3N9ImuorlK4DniQaZ2bnw.jpeg" width="1360"></a></p><p class="medium-feed-snippet">Not all unit tests are equal; some might be harmful</p><p class="medium-feed-link"><a href="https://medium.com/better-programming/advanced-unit-tests-5-pitfalls-and-how-to-avoid-them-eb6e04ec9654?source=rss-29d38576ad72------2">Continue reading on Better Programming »</a></p></div>]]></description>
            <link>https://medium.com/better-programming/advanced-unit-tests-5-pitfalls-and-how-to-avoid-them-eb6e04ec9654?source=rss-29d38576ad72------2</link>
            <guid isPermaLink="false">https://medium.com/p/eb6e04ec9654</guid>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Lucas Sonnabend]]></dc:creator>
            <pubDate>Tue, 28 Sep 2021 16:02:53 GMT</pubDate>
            <atom:updated>2021-09-28T16:02:53.521Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[How I Solved a Challenging Concurrency Bug in Python]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/better-programming/how-i-solved-a-challenging-concurrency-bug-in-python-cbf635d4bea9?source=rss-29d38576ad72------2"><img src="https://cdn-images-1.medium.com/max/2600/0*D9XffjTPvQywGOBE" width="5184"></a></p><p class="medium-feed-snippet">Investigating the fundamentals and complexities of event loops, signals, and locks</p><p class="medium-feed-link"><a href="https://medium.com/better-programming/how-i-solved-a-challenging-concurrency-bug-in-python-cbf635d4bea9?source=rss-29d38576ad72------2">Continue reading on Better Programming »</a></p></div>]]></description>
            <link>https://medium.com/better-programming/how-i-solved-a-challenging-concurrency-bug-in-python-cbf635d4bea9?source=rss-29d38576ad72------2</link>
            <guid isPermaLink="false">https://medium.com/p/cbf635d4bea9</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Lucas Sonnabend]]></dc:creator>
            <pubDate>Mon, 20 Sep 2021 16:11:56 GMT</pubDate>
            <atom:updated>2021-09-20T17:25:18.774Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[What Software Engineers Can Learn From Submarines]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/better-programming/what-software-engineers-can-learn-from-submarines-2e90215d3f96?source=rss-29d38576ad72------2"><img src="https://cdn-images-1.medium.com/max/2600/0*oAxmTEHXrjlK2ylo" width="4032"></a></p><p class="medium-feed-snippet">How you can apply David Marquet&#x2019;s leadership principles on a submarine for software engineering</p><p class="medium-feed-link"><a href="https://medium.com/better-programming/what-software-engineers-can-learn-from-submarines-2e90215d3f96?source=rss-29d38576ad72------2">Continue reading on Better Programming »</a></p></div>]]></description>
            <link>https://medium.com/better-programming/what-software-engineers-can-learn-from-submarines-2e90215d3f96?source=rss-29d38576ad72------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e90215d3f96</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[leadership]]></category>
            <dc:creator><![CDATA[Lucas Sonnabend]]></dc:creator>
            <pubDate>Fri, 10 Sep 2021 12:47:38 GMT</pubDate>
            <atom:updated>2021-09-10T12:47:38.427Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Why You Should Not Use MongoDB For Your Project]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://javascript.plainenglish.io/why-you-should-not-use-mongodb-for-your-project-bf0f1caa6672?source=rss-29d38576ad72------2"><img src="https://cdn-images-1.medium.com/max/2600/0*c_XZi6iFrS1CFVYe" width="4979"></a></p><p class="medium-feed-snippet">Most of the time, you will be better off with a relational database.</p><p class="medium-feed-link"><a href="https://javascript.plainenglish.io/why-you-should-not-use-mongodb-for-your-project-bf0f1caa6672?source=rss-29d38576ad72------2">Continue reading on JavaScript in Plain English »</a></p></div>]]></description>
            <link>https://javascript.plainenglish.io/why-you-should-not-use-mongodb-for-your-project-bf0f1caa6672?source=rss-29d38576ad72------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf0f1caa6672</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[mongodb]]></category>
            <dc:creator><![CDATA[Lucas Sonnabend]]></dc:creator>
            <pubDate>Fri, 03 Sep 2021 10:27:36 GMT</pubDate>
            <atom:updated>2021-09-03T10:27:36.042Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Python features that you will miss in TypeScript]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://levelup.gitconnected.com/python-features-that-you-will-miss-in-typescript-78ecc440b8bc?source=rss-29d38576ad72------2"><img src="https://cdn-images-1.medium.com/max/2600/0*G6G1IweBv411ufK9" width="3379"></a></p><p class="medium-feed-snippet">Sometimes you truly appreciate something when it is gone</p><p class="medium-feed-link"><a href="https://levelup.gitconnected.com/python-features-that-you-will-miss-in-typescript-78ecc440b8bc?source=rss-29d38576ad72------2">Continue reading on Level Up Coding »</a></p></div>]]></description>
            <link>https://levelup.gitconnected.com/python-features-that-you-will-miss-in-typescript-78ecc440b8bc?source=rss-29d38576ad72------2</link>
            <guid isPermaLink="false">https://medium.com/p/78ecc440b8bc</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Lucas Sonnabend]]></dc:creator>
            <pubDate>Mon, 30 Aug 2021 12:58:28 GMT</pubDate>
            <atom:updated>2021-08-31T19:05:33.618Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[7 Tips for Empathetic Code Reviews]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/better-programming/7-tips-for-empathetic-code-reviews-901e8b049a88?source=rss-29d38576ad72------2"><img src="https://cdn-images-1.medium.com/max/2600/0*-7ICSLvsQVE3opQt" width="5472"></a></p><p class="medium-feed-snippet">Being honest is easy, being kind is hard</p><p class="medium-feed-link"><a href="https://medium.com/better-programming/7-tips-for-empathetic-code-reviews-901e8b049a88?source=rss-29d38576ad72------2">Continue reading on Better Programming »</a></p></div>]]></description>
            <link>https://medium.com/better-programming/7-tips-for-empathetic-code-reviews-901e8b049a88?source=rss-29d38576ad72------2</link>
            <guid isPermaLink="false">https://medium.com/p/901e8b049a88</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Lucas Sonnabend]]></dc:creator>
            <pubDate>Mon, 23 Aug 2021 16:02:43 GMT</pubDate>
            <atom:updated>2021-08-23T16:02:43.182Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Git Merge vs. Git Rebase Workflow: Which Is Better?]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/better-programming/git-merge-vs-git-rebase-workflow-which-is-better-47511fba0a6a?source=rss-29d38576ad72------2"><img src="https://cdn-images-1.medium.com/max/2600/0*wW0UnpWhXsvath67" width="5931"></a></p><p class="medium-feed-snippet">And why our team chose merging over rebasing</p><p class="medium-feed-link"><a href="https://medium.com/better-programming/git-merge-vs-git-rebase-workflow-which-is-better-47511fba0a6a?source=rss-29d38576ad72------2">Continue reading on Better Programming »</a></p></div>]]></description>
            <link>https://medium.com/better-programming/git-merge-vs-git-rebase-workflow-which-is-better-47511fba0a6a?source=rss-29d38576ad72------2</link>
            <guid isPermaLink="false">https://medium.com/p/47511fba0a6a</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Lucas Sonnabend]]></dc:creator>
            <pubDate>Wed, 11 Aug 2021 16:25:02 GMT</pubDate>
            <atom:updated>2021-08-11T17:18:40.354Z</atom:updated>
        </item>
    </channel>
</rss>