<?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 Sam x Smith on Medium]]></title>
        <description><![CDATA[Stories by Sam x Smith on Medium]]></description>
        <link>https://medium.com/@samxsmith?source=rss-2e2e04c49552------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*qYzYD9SoLyJ6bNdFdWsOPw.jpeg</url>
            <title>Stories by Sam x Smith on Medium</title>
            <link>https://medium.com/@samxsmith?source=rss-2e2e04c49552------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 06:55:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@samxsmith/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[Add feature flags with the end in mind]]></title>
            <link>https://medium.com/samxsmith/add-feature-flags-with-the-end-in-mind-c0231c87f367?source=rss-2e2e04c49552------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0231c87f367</guid>
            <category><![CDATA[software-best-practices]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Sam x Smith]]></dc:creator>
            <pubDate>Mon, 20 Dec 2021 18:48:44 GMT</pubDate>
            <atom:updated>2024-07-24T19:19:28.686Z</atom:updated>
            <content:encoded><![CDATA[<p>Check out my email 📩 newsletter for engineers that care about delivery, business impact, and career growth ➡️ <a href="http://bit.ly/dev-dispatch">http://bit.ly/dev-dispatch</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KIJGlltuREThyACKXeB9ug.jpeg" /><figcaption>flags, flags, everywhere…</figcaption></figure><p><strong><em>Hi, I’m Sam, and I do most of my writing at </em></strong><a href="http://samxsmith.com/"><strong><em>samxsmith.com</em></strong></a><strong><em>.</em></strong></p><p>Since I first started using feature flags as the primary way to separate release from deploy and start shipping faster, unblocking git-flow and getting better control of shit, the feature-flagging train has really gathered some speed. I don’t need to go through the pros and cons, <a href="https://featureflags.io/">https://featureflags.io</a> is a great resource, alongside all the internet discussion on the topic.</p><h3>Complexity Spiral</h3><p>Something I think that site doesn’t tackle in its Best Practices, which it ought to, is optimising for removal. Feature Flags are great, but they multiply code paths and add complexity to everything. Every time you add a binary feature flag that affects all existing code paths, you’re doubling the possibilities. By the time you’ve done that 3 times, you’ve created 8x the complexity (2³).</p><p>For larger repos, multiple teams committing, running their own releases and experiments, that soon mounts up. Without proper management, I’ve seen repos easily run up 300+ feature flags. Assuming only 2 variants per flag (and some have many variants — red, blue, green….) we’re talking more combinations of code paths than grains of sand on earth.</p><p>Now imagine debugging something occurring on one of those combos, somewhere 🤔.<br>The combination explosion makes simple services unfathomably complex. Understanding anything requires comprehension of feature flag state for tens or hundreds of flags. Contributing to a codebase with a thousand upstream possibilities is a nasty, smelly affair.</p><p>Like all things that buy you time early, their debt compounds without proper management.</p><h3>Deep Roots</h3><p>Trees dig deeper and deeper roots with age. Feature flags not implemented well in code can do just the same.</p><p>A flag like ShowNewWidgets might need to be read in a number of places. There might also be a desire to access flags at the root of the code path. This is particularly true if accessing the flag requires user context, which you don’t want to pass around everywhere.</p><p>For these two reasons it’s common to see something as high up as the request controller, reading a whole bunch of flags:</p><pre>func requestHandler(w http.ResponseWriter, r *http.Request) {<br>   user := parseUserDetails(r)<br>   shouldUseFeatureA := features.IsOn(FeatureA)<br>   shouldUseFeatureB := features.IsOn(FeatureB)<br>   ....<br>   shouldUseFeatureZ := features.IsOn(FeatureZ)<br>   ....<br>}</pre><p>Once we’ve got all these values, they then have to passed down through the code path to where they’re used. Something like the following is common:</p><pre>type Opts struct {<br>   IncludeWidgets: shouldUseFeatureA,<br>   OverrideOldDBRepo: shouldUseFeatureZ,<br>   UseV2Query: shouldUseFeatureB || shouldUseFeatureX,<br>}</pre><p>…and as these values are passed down, their names change and the logic that applies to them increasingly obfuscates the origin of the value, the flags that determine them:</p><pre>func someOtherFunc(o Opts) {<br>   var sqlStatement string<br>   <br>   if o.UseV2Query &amp;&amp; o.OverrideOldDBRepo {<br>      sqlStatement = fasterQuery<br>   } else { ... }<br>   ...<br>}</pre><p>Now if I want to come and remove a flag, there’s a barrier to what should be a simple task.</p><p>If FeatureX is rolled out, I want to delete it from the code to remove a set of combinations and simplify things. But how would I go about that safely? features.IsOn(FeatureB) will always resolve to true now, so I could simply replace that statement with shouldUseFeatureB := true but that isn’t actually removing any complexity. The checks against that value still exist inside the codebase, and that is the cognitive overhead we want to reduce. We want to remove all such checks and only use the new codepath.</p><p>Opts.UseV2Query is an OR statement with FeatureB and FeatureX . We need to consider the impact of this if we remove FeatureB . If FeatureB is always true we can’t delete this check, or else it will alter the outcome of the OR condition. Further down, Opts.UseV2Query determines which query to use, again in combination with another flag, this time in an AND condition. Once again we need to be sure that our removal of the flag leaves the code in the same state as if the flag remained, 100% on.</p><p>Indeed, as flags are passed deeper and deeper, we need to evaluate each and every place that the flag contributes to a decision, in order to remove the flag, its repercussions and the cognitive overhead it contributes to the source code. The deeper it is passed, and the more it is used, the harder it becomes to remove. The roots are dug too deep.</p><h3>Short &amp; Sweet</h3><p>Your feature flagging tool should have a TTL option on any flag, a date you prescribe after which it will make your life hell until that flag is gone. Try a short default. Most experiments don’t need more than a few weeks, and flags for safe releases can be removed the day after it’s rolled out. Your tool should have alerts for that too.</p><p>There are several advantages to short, sharp, in-and-out flag use.</p><p>First, it minimises the spreading effect of any flag-derived value. Fewer people will have time to use it, in fewer places. Get it out before the roots dig too deep, latch onto to too many things.</p><p>Second, the sooner you remove a flag, the more knowledge you have to hand about the flag. I’ve had flags that have been there for months, and I can’t remember what they did. I’ve seen flags laying around for years. Everyone involved with the flag has now left the company, retired. Get the flag out while its role and use is fresh in memory.</p><p>Third, if you get a flag out of the code as soon as it has no use, you get it out before you have time to add another. If you move onto another project, with old flags still in the code, you’re likely to add another flag before you remove that one. Flag combinations grow and things become exponentially complex. To fight this, you could try the one in, one out rule. You can’t add a flag without removing one.</p><p>Short lived flags are good hygiene. Long lived flags are tech debt.</p><h3>Hot Potatoes</h3><p>Reading flags in bulk, and passing their values around like parcels is dangerous. The value of a feature flag is determined externally from the code. That’s their greatest strength and their greatest threat. If I don’t know that the value I’m dealing with is being toggled as part of an experiment, I can’t treat it with the caution it deserves. When it comes to removing that value, good luck.</p><p>To prevent the dissemination of a flag off into the horizon, apply one rule: pretend it’s PII. Access it, read it, and drop it. Don’t pass it, save it or rename it. Every time a flag gets passed, there’s an opportunity to rename it, an opportunity often taken. Renaming it hides its source, making it harder and harder to remove the complexity later.</p><blockquote>“but, but, I need to read it in multiple places, and I don’t want code reuse”</blockquote><p>Deal with it. <a href="https://go-proverbs.github.io/">“A little copying is better than a little dependency”</a> and WAAAY better than a lot of tech debt.</p><blockquote>“Ugh, but accessing a flag requires passing around a user’s details”</blockquote><p>That’s true, and that can be a pain. But if you were passing a flag value, why can’t you pass user values? In Go you should have constant access to the context . That’s the perfect place to store user information relevant to the entire code path.</p><blockquote>“mmm, but I don’t want my domain layers to depend on a specific feature flag implementation”</blockquote><p>That’s good instinct. There’s no reason why it needs to. Your context-stored user type can easily abstract this away, with a context helper.</p><pre>package featureflags</pre><pre>type ctxKey string<br>const resolverKey ctxKey = &quot;feature_flag_resolver&quot;</pre><pre>type resolver interface {<br>   GetBinaryFlag(flagName string) bool<br>   GetMultivariateFlag(flagName string) string<br>}</pre><pre>func SetResolver(ctx context.Context, r resolver) context.Context {<br>    return context.WithValue(ctx, resolverKey, r)<br>}</pre><pre>func GetBinaryFlag(ctx context.Context, flagName string) bool {<br>    r, ok := ctx.Value(resolverKey).(resolver)<br>    if !ok {<br>        return false<br>    }<br>    return r.GetBinaryFlag(flagName)<br>}</pre><pre>func GetBinaryFlag(ctx context.Context, flagName) bool {<br>    r, ok := ctx.Value(resolverKey).(resolver)<br>    if !ok {<br>        return &quot;&quot;<br>    }<br>    return r.GetMultivariateFlag(flagName)<br>}</pre><p>Your controller can create the resolver, with the user info it has at the code path entrance. Each time you need to access a flag, all you need is its name and context .</p><p>Now, to remove any flag from the codebase, we can reliably search for each place it is used, and get a clear guage of its use and impact. In most cases, you will simply be able to delete the condition around it.</p><p>This drastically reduces the work required, and risk taken, to delete a flag. That minimises flags in the codebase, forks in the user journey, debug-time, cognitive overhead, and safety.</p><p>Optimise for removal.</p><p><strong><em>Thanks for reading. If you found this useful, you might also enjoy my more in depth </em></strong><a href="http://samxsmith.com/"><strong><em>writing at samxsmith.com</em></strong></a><strong><em>.</em></strong></p><p>Have a good day :)</p><p>Check out my email 📩 newsletter for engineers that care about delivery, business impact, and career growth ➡️ <a href="http://bit.ly/dev-dispatch">http://bit.ly/dev-dispatch</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0231c87f367" width="1" height="1" alt=""><hr><p><a href="https://medium.com/samxsmith/add-feature-flags-with-the-end-in-mind-c0231c87f367">Add feature flags with the end in mind</a> was originally published in <a href="https://medium.com/samxsmith">samxsmith</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Better feedback loops for a better life]]></title>
            <link>https://samxsmith.medium.com/better-feedback-loops-for-a-better-life-530202504c75?source=rss-2e2e04c49552------2</link>
            <guid isPermaLink="false">https://medium.com/p/530202504c75</guid>
            <category><![CDATA[life-hacking]]></category>
            <category><![CDATA[improvement]]></category>
            <category><![CDATA[feedback-loop]]></category>
            <category><![CDATA[learning]]></category>
            <dc:creator><![CDATA[Sam x Smith]]></dc:creator>
            <pubDate>Tue, 23 Mar 2021 20:28:11 GMT</pubDate>
            <atom:updated>2021-05-01T09:09:21.661Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://www.samxsmith.com/better-feedback"><strong><em>Originally published @ samxsmith.com</em></strong></a></p><p>A feedback loop is a good start, but a really good feedback loop is a force multiplier to everything else that you’re doing.</p><p>What makes a feedback loop “good”?</p><h3>Feedback loops must be tight, accurate and strong</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q3uEe2Yil1mNqbqU8r9DrA.jpeg" /></figure><h3>A good feedback loop is tight</h3><p>A good feedback loop is one where feedback is timely, where <strong>the gap between action and reaction is small.</strong> The exact time that is reasonable is relative to the size or duration of the activity, but tighter is always better.</p><p>Rapid feedback maximises rep count.</p><p><strong>Perform a rep. Get instant feedback. Adjust. Repeat.</strong></p><p>High rep count with continuous micro-adjustments is the fastest way to improve at anything. Having to wait for feedback could mean one of two things. It might limit rep count, while you wait for the feedback. This is slow and frustrating. The other option could be worse though. If you do many reps before you get feedback, <strong>you will have internalised bad habits.</strong></p><p>Recently I drove along a road that is for buses only, because the sign is not easily visible. I didn’t realise I’d done anything wrong. So I drove that way again a few days’ later. Local government is slow, so by the time the fine came through the post, I’d driven that way several times. That particular bureaucratic feedback loop cost me several hundred pounds before I corrected my mistake.</p><p>When I learned to play piano, I was playing chords with a strange claw-like hand position before someone spotted and corrected me. By then, I had ingrained a bad habit through hours of practice, and it felt like starting again from scratch.</p><p><strong>In both cases, a slow feedback loop caused me to double down on my mistake.</strong></p><p>When I was working at the place where we couldn’t check things locally, we had to push to a development environment to validate even the smallest changes. Micro-adjustments couldn’t be checked for at least 15 minutes. This painfully slow feedback loop led to very very low rep count, stunting progress.</p><p>Another consequence of that kind of slow feedback is that <strong>you lose the cognitive or physical context.</strong> When it was testing code changes, I’d make a change, wait the quarter hour, and have lost entirely my train of thought. This is mentally exhausting because you have to continually retrace your steps. When we could run it locally, and test a hypothesis in seconds, the loop was so timely that the thoughts were still present.</p><p><strong>Think. Test. Feeback. Rethink.</strong></p><p>The same applies to physical practices too. If you are learning tennis, and at the end of each point your coach talks over your technique for a shot you made, but you’ve made a couple of shots since, you have likely lost the muscle memory of how that shot felt to you. You have no basis for understanding their thoughts. They say you swung too low, but you can’t remember how low you swung, or whether it felt low or anything else. You’ve lost the physical context, so you can’t make much use of their feedback.</p><p>In contrast if your coach set up an exercise where you return a shot, and then they immediately discuss it, then you still have the context of how that shot felt right there. Now if they say you swung through too low, you have <strong>right there in muscle memory the sensation of how it felt, and can adjust accordingly.</strong></p><p>Tight feedback loops allow high reps without enforcing bad habits, delivered while the context is still fresh. They facilitate rapid micro-improvement that can supercharge your learning and development.</p><h3>A good feedback loop is accurate</h3><p>It might seem banal to note that a feedback loop should be accurate, but the implications of the idea are worth exploring. <strong>Feedback does not equate to outcome.</strong> For example, in investing, or any other form of gambling, it’s possible to succeed despite making significant errors. <strong>Indeed in many domains we can succeed despite our approach, rather than because of it.</strong></p><h4><a href="https://www.samxsmith.com/better-feedback">Read the full post at samxsmith.com</a>…</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=530202504c75" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why feedback trumps theory]]></title>
            <link>https://samxsmith.medium.com/why-feedback-trumps-theory-62703ad4f4b4?source=rss-2e2e04c49552------2</link>
            <guid isPermaLink="false">https://medium.com/p/62703ad4f4b4</guid>
            <category><![CDATA[deliberate-practice]]></category>
            <category><![CDATA[feedback-loop]]></category>
            <category><![CDATA[learning]]></category>
            <dc:creator><![CDATA[Sam x Smith]]></dc:creator>
            <pubDate>Sun, 21 Mar 2021 16:03:05 GMT</pubDate>
            <atom:updated>2021-05-01T09:08:45.541Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://www.samxsmith.com/feedback-over-theory"><strong><em>Originally published @ samxsmith.com</em></strong></a></p><p>Feedback loops are a naturally occurring phenomena. Homeostasis is achieved in the body with a number of feedback loops that alter our physiology, and our behaviour. When we get cold, we shiver to create heat energy, and sweat when it’s too cold. When we are scared we get a hit of adrenaline that raises our heart rate ready to defend ourselves or run. These processes <strong>respond to an environment or state, and provide a reaction to correct for it.</strong></p><p>We can make use of our own feedback loops to correct and improve, to learn and test.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sLWvNEkEeFJgePLn2H1CZw.jpeg" /></figure><h3>Feedback loops are worth your time</h3><p>I dedicate a disproportionate portion of time to feedback loop design, a specific kind of system design where the aim is a cycle that nudges us in ways big or small towards our goals. I think a lot about <strong>feedback loops and how they supercharge deliberate practice.</strong> When I am learning or trying anything new, feedback loops are the first thing I think about.</p><p><strong>“If I’m going to try this, how will I know if I’m doing it well? How will I know how to get better?”</strong></p><p>Getting this right is a force multiplier to everything. <strong>Improving a feedback loop has a compound effect on the speed of improving at anything else.</strong></p><p>This would be my TedTalk!</p><h3>Feedback loops trump theory</h3><p>On <a href="https://tim.blog/2020/03/14/josh-waitzkin-transcript-412/">this episode of the Tim Ferrriss Show</a>, an episode with more than a few absolute gems, Josh Waitzkin talks about Chess players of the past, and how they would need to study for many years to gauge the best moves for the millions of permutations of a Chess match. Over decades they’d build a wealth of experience that would enable them to select winning moves. Today things are a little different, because we have computers that can give highly accurate assessments of the best move in a given situation in seconds. <strong>A practicing chess player today can make a bad move and be instantly notified.</strong> Now they can be nudged in the right direction, and internalise the correct strategies, <strong>without years of broad theoretical study</strong> just to get to the point of identifying the correct move.</p><p>For a recent client, I was helping a team to extract some of their legacy system. As we went along there would be many times when the behaviour of the existing system was unclear. There was an engineer in that team who had been there since the inception of the legacy system, and the team would routinely turn to him with questions when we hit these obstacles.</p><h4><a href="https://www.samxsmith.com/feedback-over-theory">Read the full article at samxsmith.com</a>…</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=62703ad4f4b4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[focus.]]></title>
            <link>https://samxsmith.medium.com/focus-6d3eb9ff2c44?source=rss-2e2e04c49552------2</link>
            <guid isPermaLink="false">https://medium.com/p/6d3eb9ff2c44</guid>
            <category><![CDATA[focus]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[time-management]]></category>
            <dc:creator><![CDATA[Sam x Smith]]></dc:creator>
            <pubDate>Sun, 07 Mar 2021 17:40:14 GMT</pubDate>
            <atom:updated>2021-04-30T20:01:20.934Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://www.samxsmith.com/focus"><strong><em>Originally published @ samxsmith.com</em></strong></a></p><h3>Focus is worthwhile</h3><p>The most important skill I can imagine, a skill I lack almost entirely, is the ability to focus. Without focus, you can’t learn or work, or enjoy any experience. Very few forms of modern work can be done in micro-bursts. They require commitment of larger blocks of time. Learning is a skill or set of skills by itself, but all of them require some degree of focus. Deliberate practice necessitates awareness of a particular skill, and the presence to be sensitive to its feedback. Most important of all, you really can’t enjoy anything that you aren’t focused on. Having a conversation with a close friend is easily ruined if your mind is elsewhere.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/0*lLnbsKV2TWgea-EA.jpeg" /></figure><p>Focus, and its fruits, are also better rewarded than ever. Expertise and mastery present opportunities never before available. Experts are able to teach direct to consumers, distributing their material worldwide at incredible margins. Innovators, people who dedicate themselves to focusing on a problem until they have solved or removed it, are more empowered than at any other point in history, to make global change at a handsome profit. <strong>Focus is lucrative.</strong></p><p>Work that requires deep thought, the development of indefinable human insight, is by far the hardest work to automate. If you’re scared that “robots are taking our jobs” rest assured, that doing the focused work that results in highly sought skills and intuition will make you very difficult to replace.</p><p>Not to mention that in a world of endless options and seeming chaos, <strong>pursuing the depths of your curiosity and passion is just about the most rewarding work that you can do.</strong> Unlike the Platte River, famously a mile wide and just an inch deep, <strong>mastery, expertise, insight and joy come from plumbing the murky, ill-explored depths.</strong></p><h3>focus is not what this world is designed for</h3><p>Attention has become a saleable commodity though. Big technology companies want your attention, as much as possible. The phone you carry around in your pocket is a distraction machine. Your email inbox is built to keep you hitting refresh. Just about every modern technology is designed to make you addicted, to keep you there.</p><p>This is the price we pay for the convenience of using these things for free, and it may or may not be a worthy trade. These advances have added a great deal to our lives and it would be wrong to admonish them entirely, provided we stay in control.</p><p>With large corporations fighting for your attention, at every moment of the day, <strong>you have to be conscious and intentional about your choices.</strong> Here are some that we face every day:</p><p><strong>Work or be distracted.<br>Talk to our family or be distracted.<br>Eat or be distracted.<br>Sleep or be distracted.</strong></p><p>We would all, I imagine, like to think we land on the sane, left hand side of these trades, but how often is that the case? <strong>How often do we focus on the things that we say MATTER ?</strong></p><p>This is not an attack on technology. Technology is just the most obvious way in which we allow ourselves to be distracted. <strong>We make choices all the time, where the opportunity cost is focused work.</strong> In recent weeks, I have been trying to bring my own attention to these decisions.</p><h4><a href="https://www.samxsmith.com/focus"><strong><em>Read the full article at samxsmith.com</em></strong></a><strong><em>…</em></strong></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6d3eb9ff2c44" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Concentric Circles for System Design]]></title>
            <link>https://samxsmith.medium.com/concentric-circles-for-system-design-7171648e5ad1?source=rss-2e2e04c49552------2</link>
            <guid isPermaLink="false">https://medium.com/p/7171648e5ad1</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[clean-architecture]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[clean-code]]></category>
            <dc:creator><![CDATA[Sam x Smith]]></dc:creator>
            <pubDate>Thu, 25 Feb 2021 20:25:52 GMT</pubDate>
            <atom:updated>2024-07-24T19:19:51.800Z</atom:updated>
            <content:encoded><![CDATA[<p>Check out my email 📩 newsletter for engineers that care about delivery, business impact, and career growth ➡️ <a href="http://bit.ly/dev-dispatch">http://bit.ly/dev-dispatch</a></p><p>I’ve been building and maintaining software for a while, and the rules of design are visceral: I feel that something is sensible, or problematic. As I spend more of my time mentoring &amp; leading others though, it becomes less important to know what is wrong or right, and <strong>more important to be able to communicate ideas about good design</strong> in a slightly more formal way. Because my decisions had become instinctive, embedded, I’d lost some of the ability to explain what I meant and why. Certainly, the principles ingrained in me had long since lost their English translations.</p><p>To solve this problem, I revisited a (not-so-old) classic, Clean Architecture by Bob Martin. Bob’s discussion of layered design in that book is fantastic. <strong>Clear, yet broad and virtually universal, it is still the mental model I use.</strong></p><p>In an effort to cement my ability to communicate these concepts to colleagues and friends, I wanted to get some reps in here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/318/1*a4g7_b5oC_qMIWN5d2j0xA.jpeg" /></figure><h3>What is layering?</h3><p>Layering is an arrangement of dependencies hierarchically, stacked or encapsulating one another. Each layer is distinctly separate, rather than intermingled. Each layer can only communicate with the layer above or below it. This creates increasing levels of abstraction.</p><p>We generally divide layers based on <strong>the level of generality vs specificity</strong> of the work each does. This will become more clear as we get to concrete explanations below.</p><h3>Why layer?</h3><p>Firstly, <strong>the formal separation which layers enforce makes maintenance much easier.</strong> We can manage stability per layer, and clearly define the dependency graph. Each layer does a certain job, extending the single responsibility principle.</p><p>Layering makes the connections between levels of specificity explicit. We can manage this coupling with interfaces, producing a layer-to-layer abstraction, to allow easy extension and substitution. The result is <strong>a system of self-sufficient layers, that can do their part, and then hand off to the next layer.</strong></p><p>Check out my email 📩 newsletter for engineers that care about delivery, business impact, and career growth ➡️ <a href="http://bit.ly/dev-dispatch">http://bit.ly/dev-dispatch</a></p><h4><a href="https://www.samxsmith.com/writing/concentric-circles-software/">Read the full article at samxsmith.com</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7171648e5ad1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Zettlekasten]]></title>
            <link>https://samxsmith.medium.com/why-zettlekasten-59d6308a0a0d?source=rss-2e2e04c49552------2</link>
            <guid isPermaLink="false">https://medium.com/p/59d6308a0a0d</guid>
            <category><![CDATA[obsidian]]></category>
            <category><![CDATA[building-a-second-brain]]></category>
            <category><![CDATA[knowledge-management]]></category>
            <category><![CDATA[second-brain]]></category>
            <category><![CDATA[zettelkasten]]></category>
            <dc:creator><![CDATA[Sam x Smith]]></dc:creator>
            <pubDate>Thu, 18 Feb 2021 11:07:18 GMT</pubDate>
            <atom:updated>2021-04-30T20:00:34.897Z</atom:updated>
            <content:encoded><![CDATA[<h3>How I take notes to develop insight</h3><p><em>Published @ </em><a href="https://www.samxsmith.com/zettelkasten"><em>samxsmith.com</em></a></p><p>In the unlikely event that you were interested in asking about the idea that has had <strong>the greatest impact on my life</strong>, I would be able to answer instantly:</p><p>Zettlekasten.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cUm4l1dKRxduVfi6NkBLeg.jpeg" /></figure><p>I had been searching for Zettlekasten long before I knew it existed. I tried to implement it before I realised there were tools and whole communities based around this idea. I was in fact in the early stages of creating my own tool for doing this, when I stumbled across the internet subcultures of Zettlekasten &amp; Obsidian. The day that I did marks a moment of enlightenment for me, ending the dark ages prior.</p><p><strong>This should be taught in school.</strong> Everyone, in my view, interested in thinking about anything should use Zettlekasten. I’m quite angry that even as a note-taking nerd, Zettlekasten eluded me for so long.</p><p>I’m here to share it with you, in the hope that it can help you as it has helped me. Each of the benefits I list may resonate with you more or less than others, but I’m confident that any one of these benefits will make it worth your while.</p><h3>Please note</h3><p>I am a huge fan of <strong>Zettlekasten</strong> so you should be aware of my bias. My hunt for this system for so long may make it unduly exciting to me. Even so, I do believe the benefits are logically evident, as other more rational beings seem to prove.</p><p>Second, although I have been using a system similar to <strong>Zettlekasten</strong> for a few years, I only discovered <strong>Zettlekasten</strong> relatively recently. Therefore my views here should not be taken as gospel or stress-tested. In fact my exact views are still in development, using <strong>Zettlekasten</strong> to help of course. For well developed and more experienced views on this, I have provided a number of resources from which I have personally benefited.</p><p>I am choosing to write this now following my reading of <strong>How to Take Smart Notes</strong> by Sönke Ahrens. Throughout, Ahrens&#39; ideas and examples are referenced. As I will discuss later, the book is a good resource for using <strong>Zettlekasten</strong> but is especially focused on academic writers. My hope here is to make clear <strong>the benefits for a much wider set of people.</strong></p><h3>TL; DR</h3><p>If you’re a thinker or “knowledge worker” in any capacity, and you don’t capture your thoughts in a way that lets them connect and develop, then you are destined to constantly repeat those thought processes, without accumulation or progress.</p><p>Zettlekasten is an idea-focused, connection-rich, bottom-up method for making and storing notes. In this way, <strong>it resembles your brain</strong>, and can effectively act as a physical snapshot of your thinking, allowing thought to accumulate and in time, for insights to emerge.</p><h3>Table of Content</h3><ul><li><a href="https://www.samxsmith.com/zettelkasten#linear">Insight isn’t linear</a></li><li><a href="https://www.samxsmith.com/zettelkasten#isolated">Insight isn’t isolated</a></li><li><a href="https://www.samxsmith.com/zettelkasten#serendipity">Insight requires serendipity</a></li><li><a href="https://www.samxsmith.com/zettelkasten#accumulate">Insight should accumulate</a></li><li><a href="https://www.samxsmith.com/zettelkasten#foriterative">Note taking for iterative, connected, serendipitous, accumulative thought</a></li><li><a href="https://www.samxsmith.com/zettelkasten#what">What is Zettlekasten?</a></li><li><a href="https://www.samxsmith.com/zettelkasten#why">So why Zettlekasten?</a></li><li><a href="https://www.samxsmith.com/zettelkasten#case">A case study</a></li><li><a href="https://www.samxsmith.com/zettelkasten#once">Use once, apply everywhere</a></li><li><a href="https://www.samxsmith.com/zettelkasten#time">Time Consuming</a></li><li><a href="https://www.samxsmith.com/zettelkasten#next">Where next</a></li></ul><h3>Insight isn’t linear</h3><p>We can’t plan for insight to happen. <strong>We do not sit down at our desk and decide to have an insight.</strong> There is no series of steps that guarantees insight at the end. Yet many people, students, writers, software engineers, to list only those areas in which I can speak from experience, often approach insight as if it is linear.</p><p>The example Ahrens provides is of a student who is handed an essay assignment. Typical advice for this student is to sit down and make an essay plan, selecting a very narrow topic, and then to go and read about it. Once their reading is done, they should write an outline, then the essay.</p><p>As Ahrens points out, how is the student expected to plan an essay prior to doing reading? On what basis can they choose an interesting topic if no reading has happened? Conversely, if they choose to do the reading before choosing their topic, how would they know what to read?</p><p>It becomes clear that this cannot be executed as a linear process. <strong>For ideas and insights to emerge, the writing and reading must happen in a cycle.</strong> More broadly, for us to develop ideas about anything, we need to take take inputs and reflect on those, then take further inputs in an iterative fashion.</p><p>The typical method for taking notes is to collect all the interesting ideas from a book or text and store them somewhere, digitally or not. This form of note taking is inadequate for developing ideas iteratively, as we’ll see shortly.</p><h4><a href="https://www.samxsmith.com/zettelkasten"><strong>Continue reading the full post at samxsmith.com…</strong></a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=59d6308a0a0d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Principles by Ray Dalio]]></title>
            <link>https://samxsmith.medium.com/principles-by-ray-dalio-bdc35416a0?source=rss-2e2e04c49552------2</link>
            <guid isPermaLink="false">https://medium.com/p/bdc35416a0</guid>
            <category><![CDATA[books]]></category>
            <category><![CDATA[principles]]></category>
            <category><![CDATA[book-review]]></category>
            <dc:creator><![CDATA[Sam x Smith]]></dc:creator>
            <pubDate>Sun, 07 Feb 2021 19:20:05 GMT</pubDate>
            <atom:updated>2021-04-30T19:54:46.274Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://www.samxsmith.com/principles-ray-dalio"><em>Written and published for samxsmith.com</em></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*owxEoVXnsZLOhMLVvaRAPA.png" /></figure><p>I don’t lack drive, but I spend most of the time with the sensation that I’m spinning on a merry-go-round, going fast but round in circles, getting nowhere. Life lacks an evident grand plan or central narrative. <strong>Taking steps every day, well intentioned steps, it’s difficult to be sure that they are all in the right direction.</strong></p><h3>Key Takeaways</h3><ul><li><a href="https://www.samxsmith.com/principles-ray-dalio#developPrinciples">Develop principles for each of the kinds of situation you experience in life</a></li><li><a href="https://www.samxsmith.com/principles-ray-dalio#selfAwareness">Self awareness is vital for catching defensive patterns that prevent you from getting to the truth</a></li><li><a href="https://www.samxsmith.com/principles-ray-dalio#expectedValue">Expected-value calculations help you to assess risk &amp; reward, and clarify the parameters to any decision</a></li><li><a href="https://www.samxsmith.com/principles-ray-dalio#focusOnTheProblem">Focus on the problem and the solution will usually take care of itself</a></li></ul><p>This book has been on my reading list since I first heard that Dalio had published it in 2018, but I reached for it now because I was facing a tough decision, between career options. Perhaps subconsciously I was hoping that one of the book’s principles would unlock the right decision for me. That didn’t quite happen, but <strong>the book is filled with a number of fantastic heuristics and tactics for making decisions</strong>.</p><p>The book is split into 3 parts. First, we are walked through in broad strokes the life of Ray Dalio, from New York kid to hedge fund billionaire. Throughout this section, alongside Dalio’s story, he explains the development of his principles and how they contributed to his successes. I will make no attempt to retell the story of Dalio’s life, and you should turn to the book for that albeit brief tale.</p><p>The second and third sections are dense with Dalio’s own principles for life and then work. Each principle is broken down and its rationale explained. It is not recommended that you simply copy his principles, although you could. Rather, <strong>the intention of the book is that you will follow his example and develop your own, based on your priorities and values</strong>.</p><p>I will discuss some of his principles, and you can find them all on his website, but the focus of the review will be on some of the broader ideas that Dalio posits for enjoying a successful life and career. Many of these are worth adopting, and some are worth calling out for the opposite reason, in my view.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/196/1*1vbHtxvPb6gZg06GQjsqsg.jpeg" /><figcaption>Principles by Ray Dalio — cover art</figcaption></figure><h3>The Punch Line</h3><p><strong>It is very rare that a book has more than a single grand thread</strong>, and <em>Principles</em> is no exception. So in the interest of your time, let’s jump straight to the essence of the book, before going over some of the other interesting ideas with a finer toothed comb.</p><p>We are emotional creatures, and that can make decision making difficult. It’s hard to separate sentimental attachments or evolutionary defensiveness from the logical brain. We should, Dalio asserts, <strong>tune ourselves to the frequency of the logical brain</strong>. As I will discuss later, separation may be worthwhile, but <strong>I believe that there is value in understanding those more instinctive reactions</strong> as well.</p><p>With our internal radio listening to logical signals, Dalio provides the main argument of the book. <strong>The cardinality of situations we face through our lives is relatively small.</strong> Most situations are “one of those”. We can begin to categorise the sorts of situations that we face regularly, and from that develop a playbook for handling them. As time goes on, we can use experience and outcomes to refine that set of rules. This approach and the principles developed are the core idea of the book.</p><p>Once I had grasped that message, which you could certainly gain from a Youtube video or review such as this, it is tempting to stop reading. That temptation almost won me over, but I’m glad that it didn’t, because there are <strong>other equally interesting gems hidden in the weeds of the book</strong>, that I discovered and was keen to dig up.</p><h4><a href="https://www.samxsmith.com/principles-ray-dalio">Continue reading the full post at samxsmith.com…</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bdc35416a0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Promises in Express.js: APIs & Testing]]></title>
            <link>https://samxsmith.medium.com/promises-in-express-js-apis-testing-dd0243163d57?source=rss-2e2e04c49552------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd0243163d57</guid>
            <category><![CDATA[asyncawait]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[async-functions]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[promises]]></category>
            <dc:creator><![CDATA[Sam x Smith]]></dc:creator>
            <pubDate>Sun, 26 Nov 2017 22:29:41 GMT</pubDate>
            <atom:updated>2024-07-24T19:20:08.555Z</atom:updated>
            <content:encoded><![CDATA[<p>Check out my email 📩 newsletter for engineers that care about delivery, business impact, and career growth ➡️ <a href="http://bit.ly/dev-dispatch">http://bit.ly/dev-dispatch</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3KqeJ4RWYRHeK783D2KOSg.jpeg" /></figure><p>I’d always held my async preferences, using callbacks &amp; other fixes as a badge of honour: no promises for me I would gloat with pride. Idiot. Promises are great in reality — in fact for a modern Node/Express application, they’re tantamount to essential.</p><p>The problem to be solved is that of asynchronous/async operations. That is, in simple terms, when an operation or function begins executing but for whatever reason has some delay before completion. Examples of this include a http request such as AJAX requests, and setTimeout functions. These operations begin, and then end when the response returns or when the timer ends. While the computer waits for these operations to complete, it moves on busying itself with the next lines of code. Good you say, keep it busy, but this causes a significant challenge — any code dependent on previous async code might be run before that async code is complete, meaning errors. See:</p><pre>var data = makeAsyncRequest();<br>console.log(&quot;Data is &quot; + data); // Data is undefined</pre><p>The above occurs because the asynchronous request, for example an AJAX/HTTP request, hasn’t returned a response yet. The request is still out there in the world somewhere talking to other computers. In the meantime the computer moves on and tries to console.log the data variable, which as yet has been assigned no value. What a dilemma huh! Thankfully, are a few solutions we can look over.</p><h3>1) Callbacks</h3><p>A callback function is a function supplied as an argument to another function which is executed when the async operation completes. This is common in JavaScript. For example:</p><pre>fs.readFile(&quot;file.name&quot;, function(err, data){ //callback<br>   if(err) throw err;<br>   console.log(data);<br>})</pre><p>Callbacks work generally, but they aren’t always convenient. If you’re using express for example, and you want to call a module, and then another one after that, and maybe one after that, all dependent on one another, you’re going to end up passing callback inside callback inside callback. Messy.</p><p>This is known as callback hell (see below), where we end up with function in function in function. It’s ugly, it requires many many indentations, and really it is defeating the point of building reusable modules if custom use requires this kind of parameter to be passed to the first function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*cf4xUeKhK1e5565GU1sHXQ.jpeg" /><figcaption>Callback HELL</figcaption></figure><p>Let it be said that callbacks have their place, and they are very useful for a lot of JavaScript tasks, but they are far from idea in these layered scenarios.</p><h3>2) Middleware Modules</h3><p>Using Express.js, we have another option: using middleware. Express middleware accepts 3 arguments, req, res, next . Next is a callback automatically passed into every middleware module, therefore we can achieve the effect of the callback solution without the messy indents.</p><p>Therefore, we can make an async request with one middleware, and only once that request responds we save that data in req.something, call next() and move onto the next middleware to deal with the fetched data.</p><p>This works. And its tidier than callback hell. But there are a few issues which make this an inadvisable approach to dealing with async issues.</p><ul><li>req becomes a dumping ground for data. req is a stream designed for carrying data about the http request which triggered it.</li><li>Because the functions require data to be placed in req and then used in the following middleware, it makes each module virtually non-reusable, defeating the point of modules at all.</li><li>It’s simply poor practice to mix controllers (routes and their middlewares) with models (interacting with databases etc — async operations). It also makes unit testing near impossible.</li></ul><p>No luck here then. Middleware isn’t the answer.</p><h3>Promises &amp; Await: The answer to our async woes</h3><p>We want our async operations to behave just like synchronous operations. But we also don’t want our code to pause, waiting for the return of an asynchronous operation. The solution: promises.</p><p>A promise is an object. It represents the eventual completion of your asynchronous operation. An async function can return a promise, to which we can then attach .then , which essentially acts as an event listener for when the async function completes.</p><p>Here’s how you make use of promises:</p><pre>var asyncRequest = new Promise(function(resolve, reject){<br>  return setTimeout(function(){<br>      resolve(&quot;Here&#39;s your data&quot;);<br>    }, 3000);<br>    reject(&quot;Error&quot;)<br>})</pre><p>A promise is create with the Promise constructor. The constructor accepts one argument, a function which takes resolve &amp; reject as parameters. Once your data has been returned, you can call resolve, passing in the data you want to work with later. If there is an error, call reject instead.</p><p>Calling either function concludes the promise, and triggers the .then or .catch handlers. As mentioned, these are event handlers which respond to a concluding promise.</p><pre>makeAsyncRequest.then(function(val){<br>  console.log(val) <br>}, function(val){<br>  throw val;<br>})</pre><pre>// the above and below have the same effect</pre><pre>makeAsyncRequest.then(function(val){<br>  console.log(val) <br>}).catch(function(val){<br>  throw val;<br>})</pre><p>.then accepts two parameters, first a function called if the promise calls resolve() , &amp; second a function called should the promise call reject() . Alternatively, you can use .catch to catch reject() calls as below.</p><p>The functions passed to then and catch each accept one argument, which will populate as the argument passed to resolve or reject respectively. Thus, the below would also work:</p><pre>makeAsyncRequest.then(console.log).catch(function(val){<br>  throw val;<br>})</pre><p>That’s great. Let’s look at how this might work with Express.</p><p>Let’s say we receive a request to send some data, which we will pull and filter. Our route might look like this:</p><pre>app.get(&quot;/getdata&quot;, function(req, res){  <br>   pullData().then(function(data){<br>      return filterByYear(data);<br>   }).then(function(filteredData){<br>      res.json(filteredData);<br>   })<br>})</pre><p>Assuming that pullData() &amp; filterByYear() return promises, we have chained together .then calls to allow us to execute multiple async operations, one after the other.</p><p>Now we’re getting there. The above looks much nicer; its purpose is clear &amp; we could scale this up, calling any number of async functions without never-ending indentation or sacrificing reusability.</p><p>Fantastic. But we can do even better.</p><h3>Using Await</h3><p>Chaining then functions is great, and a very powerful way of conducting async operations and relying on that data. But now, we have an even more convenient method for working asynchronously, allowing improved control &amp; freedom.</p><p>The await keyword can be used to indicate that the function that follows will be returning a promise, which should be awaited before executing any other dependent code. await can only be used inside an async function .</p><pre>app.get(&quot;/getdata&quot;, async function(req, res){  <br>   var data = await pullData();<br>   var filteredData = await filterByYear(data);<br>   res.json(filteredData);<br>})</pre><p>The benefit of await is that async code can look exactly like synchronous JavaScript. Look how neat this code is. Without zooming in on async &amp; await keywords, you’d hardly notice that this wasn’t normal code. Again, provided that the pullData &amp; filteredData functions return promises, any function reliant on an awaited function will not be executed until the function’s promise has resolved.</p><p>This allows for neat, reusable modularity &amp; incredible clarity.</p><h3>Unit Testing Async Modules</h3><p>With await , unit testing async modules in Mocha/Chai is simple, and there’s no need to call done() . Simply make the function passed to it an async function, and await the module response, before using expect .</p><pre>describe(&quot;getData&quot;, function(){ <br>   it(&quot;Data should be 101 indices long&quot;, async function(){<br>       var data = await getData(testData);<br>       expect(data.length).to.equal(101); <br>   });<br>});</pre><h3>Et voila…</h3><p>An unsophisticated explanation of promises &amp; their use in Express routes, at your service. For any errors &amp; additions, please use the comments to point them out.</p><p>Promises &amp; await/async functionality has changed Node.js applications more than any other introduction to the platform, in my opinion, and it’s hard to remember what we ever did before them!</p><p>Enjoy.</p><p>Check out my email 📩 newsletter for engineers that care about delivery, business impact, and career growth ➡️ <a href="http://bit.ly/dev-dispatch">http://bit.ly/dev-dispatch</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd0243163d57" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>