<?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 James Flight on Medium]]></title>
        <description><![CDATA[Stories by James Flight on Medium]]></description>
        <link>https://medium.com/@jamesflight?source=rss-84f920c387b2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*qzHvIsghBdcqBZ1bCrlHww.jpeg</url>
            <title>Stories by James Flight on Medium</title>
            <link>https://medium.com/@jamesflight?source=rss-84f920c387b2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 17:24:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jamesflight/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[Technical debt and the prisoner’s dilemma — or how game theory can affect your software team’s…]]></title>
            <link>https://medium.com/hackernoon/game-theoretical-reasons-software-projects-fail-the-prisoners-dilemma-reputational-damage-and-4129c6bdf0eb?source=rss-84f920c387b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/4129c6bdf0eb</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[technical-debt]]></category>
            <category><![CDATA[software]]></category>
            <category><![CDATA[software-architecture]]></category>
            <dc:creator><![CDATA[James Flight]]></dc:creator>
            <pubDate>Sun, 27 May 2018 16:28:01 GMT</pubDate>
            <atom:updated>2018-07-28T14:21:47.880Z</atom:updated>
            <content:encoded><![CDATA[<h3>Technical debt and the prisoner’s dilemma — or how game theory can affect your software team’s success</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kFvvbeBwIMmUom5cGmn8ug.jpeg" /><figcaption>Four software engineers lined up for the crime of missed deadlines and a poorly functioning product. Who is to blame? It’s all of them, but not for the reason you think (and they had little choice in the matter…)</figcaption></figure><p>Johnny is a terrific developer. He cares deeply about his craft and believes it is his ethical duty to write the best code he can. He knows his bread and butter languages inside and out, always tries to research and follow best practices, and spends his evenings reading technical books to expand his knowledge.</p><p>But Johnny has a problem. He has been working for the last week on a small component of a larger software system for Drivl, the tech startup he works for. He had thought his solution was very clever indeed when he’d come up with it at the beginning of the sprint, but he has only now realised that he might have been mistaken. A small pang of anxiety runs down his spine, and he feels his palms begin to sweat slightly. Johnny has noticed a flaw in his technical approach that won’t cause immediate problems if included in next week’s release, but he knows that if the code continues to run, it will result in performance degradation and maintainability problems for his team over the long term. He pauses typing, furrows his brow, and begins to ponder to himself.</p><p>“The sprint will be over tomorrow evening”, he thinks. “But I know I’ll need at least a couple of extra days to refactor the code into something more workable.”</p><p>He has a choice. His first option is to confess he was wrong, however this will delay the release and inevitably harm both his reputation and the reputation of his team within the company. It will have to be explained to the higher ups, who are unlikely to understand, as the problem is really quite technical. The team have already missed a few deadlines and the last thing they need is another stain on their reputation.</p><p>The other choice is to stay silent, let the code deploy, and allow the can to be kicked down the road.</p><p>“I guess I have no choice”, he thought to himself. “I’ll try to make sure I have time to fix this in the next sprint.” Unfortunately, for whatever reason, this never happens…</p><p>In the story, what Johnny doesn’t realise is that he is the ‘prisoner’ in an iteration of the classic game theory problem the ‘prisoner’s dilemma’.</p><h4>What is the ‘prisoner’s dilemma’?</h4><blockquote>The prisoner’s dilemma is a paradox in decision analysis in which two individuals acting in their own self-interest pursue a course of action that does not result in the ideal outcome. The typical prisoner’s dilemma is set up in such a way that both parties choose to protect themselves at the expense of the other participant. As a result of following a purely logical thought process, both participants find themselves in a worse state than if they had cooperated with each other in the decision-making process.</blockquote><blockquote><a href="https://www.investopedia.com/terms/p/prisoners-dilemma.asp"><strong>Investopedia.com</strong></a></blockquote><p>The prisoner’s dilemma tends to show up a lot in day to day life on various macro and micro scales. It is why<a href="http://www.baselpeaceoffice.org/sites/default/files/imce/articles/News/nuclear_prisoners_dillemma.pdf"> unilateral nuclear disarmament is difficult</a>, why <a href="https://en.wikipedia.org/wiki/Prisoner%27s_dilemma#In_animals">vampire bats engage in reciprocal food exchange</a>, and why when it snows for one and a half days in the UK, <a href="https://www.express.co.uk/news/weather/925310/UK-snow-weather-forecast-panic-buying-supermarket-food">shops completely sell out of bread for no particularly good reason.</a></p><p>The ‘pure’ example of the prisoner’s dilemma is as follows:</p><blockquote>Two members of a criminal gang are arrested and imprisoned. Each prisoner is in solitary confinement with no means of communicating with the other. The prosecutors lack sufficient evidence to convict the pair on the principal charge. They hope to get both sentenced to a year in prison on a lesser charge. Simultaneously, the prosecutors offer each prisoner a bargain. Each prisoner is given the opportunity either to: betray the other by testifying that the other committed the crime, or to cooperate with the other by remaining silent. The offer is:</blockquote><blockquote>If A and B each betray the other, each of them serves 2 years in prison</blockquote><blockquote>If A betrays B but B remains silent, A will be set free and B will serve 3 years in prison (and vice versa)</blockquote><blockquote>If A and B both remain silent, both of them will only serve 1 year in prison (on the lesser charge)</blockquote><blockquote><a href="https://en.wikipedia.org/wiki/Prisoner&#39;s_dilemma"><strong>Wikipedia.com</strong></a></blockquote><p>Because betrayal offers a greater reward than cooperation and cooperation carries the risk of betrayal from the other, two purely rational actors will always betray each other.</p><p>The most important fact to realise about the dilemma is that people are <em>forced into defection by the logic of the setup, </em>not because of any bad intention. If they want to minimise their losses, they must defect, because a misjudged attempt at cooperation will cost them more.</p><p>The same dilemma can arise amongst groups of more than two people as is the case for Johnny in my story above. This is known as an ‘n-person’ prisoner’s dilemma.</p><p>In Johnny’s story, cooperation takes the form of transparency around technical debt, and calling it out to colleagues early so that it is visible and can be fixed either immediately or strategically. Defection involves an individual hiding technical debt and carrying on as if it doesn’t exist because of pressure to deliver on time and the misguided equating of incompetence with the need for iterated problem solving.</p><p>Unfortunately, after many iterations, if tech debt is introduced and not fixed, issues with the codebase will inevitably start to pile up to unmanageable levels even though this is not desirable for anyone involved.</p><p>Johnny is subject to a particular set of rules, and he has to ‘strategise’ his way through in a way that is least objectionable to his circumstance. In a setup that incurs reputational damage for confession of technical debt, it is in his interests to defect. In fact, for Johnny, it is a ‘dominant strategy’.</p><h4>Dominant strategies</h4><p>In game theory, a ‘dominant strategy’ is when one strategy results carries equal or better outcomes for an individual player, no matter what strategy the other players use. A prominent feature of the prisoner’s dilemma is that the dominant strategy for the individual player results in a bad outcome for everyone, when played by everyone.</p><p>To illustrate how this applies in Johnny’s case, the following decision matrix shows a representation of payoffs and resulting codebase quality for the individual vs the group, depending on strategies taken. The punishments are intended to be representative in a working environment that enables reputational damage when an individual commits technical debt into the codebase (this could take a variety of forms e.g. accusations of incompetencey, or shaming for causing the team to miss a deadline).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/763/1*p7zfUw6j_z9hczOUvHzsCQ.png" /></figure><p>In the diagram, defection (not owning up to technical debt) receives little punishment for the individual <em>in all circumstances</em>, whereas confessing tech debt sometimes carries a very high penalty, and never carries a penalty with a better reward than when not confessing. Rational actors will always play their dominant strategies where they exist, and in this case, the dominant strategy for the individual is the bottom row. The resulting equilibrium is the bottom right square: a poor quality codebase.</p><h4><strong>Can’t we just stay in the bottom left box?</strong></h4><p>Technically, things aren’t too bad if the team manages to stay in a situation something like the bottom left box (most people aren’t owning up to tech debt introduced, but maybe a couple of them still are sometimes). However, this position is unstable, because once enough people notice the occasional defections they will start to wonder why they should confess and take reputational damage while others are clearly not, and the situation quickly devolves into something close to the bottom right box.</p><h4><strong>The dilemma can’t be solved by hiring </strong>team members with a ‘hero mentality’<strong> or more ‘skill’</strong></h4><p>You may find some ‘heroes’ who are willing to put their own interests aside, and confess the tech debt they think needs to be fixed in all circumstances. However, this is stressful for them and unsustainable over the long term. If the ‘heroes’ come to realise that their efforts are in vain, and that no cultural change is in sight despite the reputational damage they are taking, they are liable to leave for other jobs.</p><p>The skill of the team is also irrelevant, because there are plenty of perfectly remissable reasons why even a skilled team member might introduce technical debt that are indistinguishable from mistakes to a non-technical stakeholder. To name a few:</p><ul><li>There is a mismatch between past design and future requirements that causes an old technical solution to become unfit for purpose, and the team member has to find an imperfect workaround solution</li><li>An almost unforeseeable edge case limitation of a technology choice is only discovered after everything has been deployed to production and is under load</li><li>The problem under scrutiny has far reaching performance implications that only become known about while the work is being carried out</li><li>A requirements addition that only becomes known about at the last minute happens to significantly change the way the problem has to be solved from a technical perspective on a system already under active development</li><li>The team member makes a genuine, unintentional mistake, as we all do sometimes</li></ul><h3>Solving the dilemma</h3><p>The culture and process of your company can be thought of as a set of rules to a game that will affect the strategies taken by the individual players (the employees).</p><h4>Changing the rules of the game</h4><p>The most optimal outcome for both the business and the engineering team consists of either solving technical debt as soon as it arises, or making it transparent so that it can be managed judiciously and kept at a agreeable level. To enable this, the company will have to structure the rules of the game to ensure that the dominant strategy for individual players is to confess to inferior technical decisions.</p><p>There are two logical options for achieving this:</p><ol><li>Make the punishment for defection worse than the punishment for cooperation</li><li>Prevent reputational damage upon introduction of technical debt</li></ol><p>Solution 1 is unfortunately not very plausible. Defection punishment only works if punishment is swift, obvious and accurate. This is not possible in a software engineering culture, because technical debt is easy to hide, at least initially. Often bad technical decisions will not be known about even by those that made them until a significant time after they have been made, and are often difficult to pin down to an individual choice.</p><p>Solution 2 is the most likely candidate for success, although it is still not easy. It is likely that most successful software engineering cultures have some level of safeguards in place to prevent reputational damage.</p><p>There is not a one size fits all way to implement this, but here are some suggestions:</p><ul><li>Ensure that the company culture and ethos involves the idea that mistakes are part of building great products, and are a learning exercise (fail fast and LEAN are good examples of this)</li><li>Ensure that everyone in the business expects changes to project scope to be frequent, and that everyone expects that changes to scope will require refactoring due to the mismatch between past and future requirements (this is a kind of technical debt)</li><li>Be careful with deadlines. They can make punishment for drawing attention to one’s own mistakes swift and obvious in a defection filled environment, more clearly defining the negative payoff for unilateral cooperation. Ensure that everyone in the organisation expects the enforcement of hard deadlines to result in technical debt that will have to be confessed and cleaned up blame free afterwards</li><li>Consider deploying features behind <a href="https://martinfowler.com/articles/feature-toggles.html">feature toggles</a> so that features can be left out of releases if they are unexpectedly not ready due to needing to rework technical decisions</li><li>If you are already in a defection filled environment, ease off on deadline enforcement until everyone is ‘cooperating’</li></ul><h4>Psychological <strong>safety</strong> is key</h4><p>My argument here is not inconsistent with the findings of google re:work’s two year study of 180 teams that found that <a href="https://rework.withgoogle.com/blog/five-keys-to-a-successful-google-team/">the most important cultural property of successful team is “psychological safety”</a>.</p><p>Google define a team as being psychologically safe when “team members feel safe to take risks and be vulnerable in front of each other”. In their words:</p><blockquote>Turns out, we’re all reluctant to engage in behaviors that could negatively influence how others perceive our competence, awareness, and positivity. Although this kind of self-protection is a natural strategy in the workplace, it is detrimental to effective teamwork. On the flip side, the safer team members feel with one another, the more likely they are to admit mistakes, to partner, and to take on new roles. And it affects pretty much every important dimension we look at for employees.</blockquote><blockquote><strong>Julia Rozovsky, Analyst, Google People Operations</strong></blockquote><h4>A reason to be hopeful</h4><blockquote>In reality, humans display a systemic bias towards cooperative behavior in this and similar games despite what is predicted by simple models of “rational” self-interested action.</blockquote><blockquote><a href="https://en.wikipedia.org/wiki/Prisoner%27s_dilemma">Wikipedia.com</a></blockquote><p>The prisoner’s dilemma arises when <em>rational actors</em> play their best strategies. However, people are not rational actors. Sometimes, we may be driven by human nature to benevolently act against our own self interest when faced with a prisoner’s dilemma. Conceivably this could mean that there is hope when trying to turn even the most toxic of workplace prisoner’s dilemmas around. People don’t really want to to be self interested cowards, and will try not to be if given the opportunity. It’s just that sometimes they are faced with payoffs that are so bad, that they feel that they can’t.</p><p>The key takeaway here is that you should watch out for the unintended game theoretical side effects of your process, because perfectly well meaning people might cause you serious headaches if you make them follow a set of rules where their best strategy for self preservation facilitates a bad outcome for everyone. Normally, no one wants this bad outcome, so change the rules of the game and it doesn’t have to happen that way.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4129c6bdf0eb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/game-theoretical-reasons-software-projects-fail-the-prisoners-dilemma-reputational-damage-and-4129c6bdf0eb">Technical debt and the prisoner’s dilemma — or how game theory can affect your software team’s…</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Critical thinking in software development, the word ‘should’, and why you shouldn’t listen to…]]></title>
            <link>https://medium.com/hackernoon/critical-thinking-in-software-development-the-word-should-and-why-you-shouldn-t-listen-to-563090144331?source=rss-84f920c387b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/563090144331</guid>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[critical-thinking]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[domain-driven-design]]></category>
            <dc:creator><![CDATA[James Flight]]></dc:creator>
            <pubDate>Mon, 29 Jan 2018 17:49:39 GMT</pubDate>
            <atom:updated>2018-01-29T20:25:31.366Z</atom:updated>
            <content:encoded><![CDATA[<h3>Critical thinking in software development, the word ‘should’, and why you shouldn’t listen to Martin Fowler</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*abG1YN2CsDkkMObTtTaQnw.jpeg" /><figcaption>Three typical developers debating software architecture</figcaption></figure><p>Before I begin, I’ll just point out that I’m not actually going to argue that you should never listen to Martin Fowler. That was a trick, I’ve probably been reading too much click-bait.</p><p>That being said, consider the following conversation:</p><p><strong>Engineer 1:</strong> “We should use <strong><em>architecture/design pattern X </em></strong>to build our new project”</p><p><strong>Engineer 2:</strong> “Should we? Why?”</p><p><strong>Engineer 1:</strong> Because <strong><em>architecture/design pattern X </em></strong>is really powerful. It’s the way software <em>should </em>be built.”</p><p><strong>Engineer 2:</strong> “That doesn’t sound like good reasoning. What are the benefits for <em>us</em>?”</p><p><strong>Engineer 1:</strong> “It solves <strong><em>problem we don’t have Y</em></strong><em>.</em></p><p><strong>Engineer 2:</strong> “Do I really need to explain what was wrong with that sentence?”</p><p><strong>Engineer 1:</strong> But <strong><em>household name company Z </em></strong>used it to build their <strong><em>system that in no way resembles ours</em></strong>.”</p><p><strong>Engineer 2:</strong> “Really??”</p><p><strong>Engineer 1: </strong>“But Martin Fowler said it was good in a blog post once. It is definitely the way things are done these days.”</p><p>Continue ad nauseum...</p><p>I’ve noticed myself having slightly less exaggerated variants of this conversation throughout my time as a software engineer. The sad truth is that at some point or another, most of us have been both engineer 1 and engineer 2; I know I have.</p><p>The problem is, that although the illogicality in the discussion above is obvious, these styles of pernicious arguments when combined with the right irrational attachment to an idea, charisma, authority, or rhetorical skill, can actually be quite convincing.</p><p>Leading or following someone up the garden path towards a bad design decision is a lot easier than people might generally think. As a result, as engineers we always need to be on our toes when it comes to critical thinking and be aware of the kind of good and bad arguments that might crop up when we need to make decisions.</p><p>Below are four of my personal favourite logical fallacies and cognitive biases that can appear in software engineering discussions, with examples based on conversations I have had.</p><h3>Common logical fallacies and cognitive biases in software design decisions</h3><h4>1. Argument from authority</h4><blockquote>Using an authority as evidence in your argument when the authority is not really an authority on the facts relevant to the argument. As the audience, allowing an irrelevant authority to add credibility to the claim being made.</blockquote><blockquote><a href="https://www.logicallyfallacious.com/"><strong>logicallyfallacious.com</strong></a></blockquote><p>Martin Fowler says domain driven design is good on his blog, let’s use that. DHH says TDD is dead. Troy Hunt says don’t take security advice from psychics (actually, I’d probably <em>always</em> listen to this one…).</p><p>I don’t mean to say that these authority figures don’t know what they are talking about, they certainly do. It is just that the <em>facts relevant to the argument are the technical and domain details of the project in question</em>, not the abstract discussion of the generic application of solutions offered by the experts. Abstract discussions about best practices are interesting and informative inputs to your problem solving process, but are only indirectly relevant. Martin Fowler does not know your technical or business problems.</p><h4>Example: Let’s use Domain Driven Design because well known expert software developer Martin Fowler advocates it on his blog.</h4><p>If you are unaware: domain driven design is a software development approach for modelling your business domain in your code and creating a shared language between tech staff and business experts.</p><p>Martin Fowler clearly evangelises domain driven techniques on his blog and he sure knows his stuff, so choosing it for your project must be a no-brainer right?</p><p>This might be the case, but a good problem solving process will need to consider other factors than the expertise of the person recommending the approach. For example, for domain driven design you would probably want to ask the following:</p><ul><li>The techniques are a solution to the problem of creating reliable <em>business rules heavy</em> software. Does your app fall into this category?</li><li>There will be a learning overhead (all your team must understand the underlying concepts). Do you have time for this?</li><li>Code overhead: there is much more boilerplate (domain models, factories, repositories etc.) required than in conventional CRUD style apps. Would adding this additional code be worth the extra time?</li></ul><p>If the answers to these questions are “no”, then it may well be the case that adopting this approach will cause more problems than it solves. There is no way that citing an authority as an advocate is going to answer these questions for you and therefore doing so should not be weighted as an important factor in the discussion.</p><p><strong>Example 2: Let’s use micro-services because Netflix, Uber and Soundcloud do.</strong></p><p>Many household name companies make heavy use of micro-service architectures, a point that any dogmatic micro-services enthusiast will beat you over the head with at any given opportunity. The implication is that because this pattern has been used at multiple large successful organisations like Netflix, it follows that micro-services are all sunshine and rainbows and anyone who has any sense should jump straight on the bandwagon. This is a dangerous non-sequitur.</p><p>For Example, Netflix happens to have a product that lends itself to the benefits of micro-services, while being hit by few of the drawbacks. They are a business where throughput and availability are everything. They will know and understand their domain boundaries well, and concerns like eventual consistency and the drawbacks of managing complex deployments are not a problem. They also are likely to see benefits from teams being able to work on services in isolation. Many of these benefits do not apply to most businesses (especially startups). Netflix are the exception, not the rule.</p><p>The traditional monolithic architecture, which despite getting a bad name in recent years, has served many businesses well for a long time and <a href="http://www.ben-morris.com/whats-so-bad-about-monoliths-anyway/">does not necessarily mean that you cannot scale effectively</a>. There may be no need to reinvent the wheel.</p><h4>2. No True Scotsman</h4><blockquote>The <strong>No True Scotsman</strong> (<strong>NTS</strong>) fallacy is a logical fallacy that occurs when a debater defines a group such that every group member possess some quality. For example, it is common to argue that “all members of [my religion] are fundamentally good”, and then to abandon all bad individuals as “not true [my-religion]-people”.</blockquote><blockquote><strong>rationalwiki.org</strong></blockquote><p>A common form of this argument in software development is as follows:</p><blockquote>It ‘should’ be done this way because it is the ‘correct’ way to do it and any exceptions to this are not true instances of the ‘way’.</blockquote><p>You might recognise these:</p><ul><li>“Good code-bases <em>always </em>have 80% test coverage (my one doesn’t though because it’s just a prototype)”.</li><li>“A<em>ll </em>good developers follow TDD (apart from this controller I am writing, as it is requires a lot of mocks due to external dependencies)”.</li></ul><p><strong>Example: Good code should always be DRY.</strong></p><p>“Do not repeat yourself” seems like a perfectly logical principle to apply across the board. What could be the downside to only writing code once rather than twice?</p><p>When you actually give it some thought though, you realise that there are already many exceptions to the “good code should be DRY” rule that you follow everyday — for example, just take a look at pretty much any implementation of a MVC controller method. You will probably immediately see repetitions in calls to validation and view rendering logic across similar controller methods. Even the notion of keeping one method per route when pages are virtually identical is very anti-dry and boiler-platy, but we (rightly) don’t feel the need to refactor and remove this kind of repetition, as we know it would not be useful to do so.</p><p>Here, we are likely to invoke our ‘no true Scotsman’ mentality and say that these instances are ‘not true instances of repetition’, because code fragments just ‘happen’ to be the same, and that we need to ‘keep flexibility’ for code changes in the future.</p><p>Rather than thinking this way perhaps the need for exceptions is evidence that <a href="https://hackernoon.com/this-is-not-the-dry-you-are-looking-for-a316ed3f445f?source=email-84f920c387b2-1515491607861-digest.reader------2-3&amp;sectionName=recommended">the original ‘always be DRY’ premise is flawed (or at least misunderstood)</a>.</p><h4><strong>3. Wishful thinking (confirmation bias)</strong></h4><blockquote>When the desire for something to be true is used in place of/or as evidence for the truthfulness of the claim.</blockquote><blockquote><strong>logicalfallacies.info</strong></blockquote><p><strong>Example: This large code-base we’ve inherited is written in foo-script, we should rewrite it in our preferred language, bar-lang, because that language is better.</strong></p><p>A proponent of this idea might cite arguments along the lines of the following:</p><ul><li>bar-lang has static typing, so we will see less errors in production.</li><li>Our team is already more familiar with bar-lang.</li><li>I’ve been talking to my friends who also know bar-lang, and they agree that foo-script is well known for being a bad language.</li></ul><p>These arguments seem good on their own, but the desire for the claim to be true might overlook much stronger arguments against the idea, such as:</p><ul><li>A rewrite of a large project will require a huge amount of effort and time, most likely with unpredictable timescales.</li><li>The project already works in its current form (even if it is in a way that the proponent of bar-lang would consider objectionable) and a rewrite adds no additional business value. The value created compared to time spent would be atrociously poor.</li></ul><p>An often accurate actuality of web development is that the majority of the common n-tier stacks are actually pretty mature and are more than up to the task of producing maintainable, performant and reliable software. As a result, the reality of whether you end up with a clean, easily maintainable code base or a nightmare horror show of spaghetti nonsense has a lot more to do with code architecture decisions and the skill of the developers involved. Only in very business specific cases is the choice of language going to be the primary cause of issues and the idea that a complete rewrite in a new language will be productive is almost certainly ‘wishful thinking’.</p><h4>4. Appeal to novelty</h4><blockquote>Claiming that something that is new or modern is superior to the status quo, based exclusively on its newness.</blockquote><blockquote><strong>logicalfallacies.info</strong></blockquote><p>Otherwise known as ‘shiny things’ syndrome:</p><blockquote>“I saw [library, AWS offering, or architecture] on hacker news today; it looks awesome, let’s use that.”</blockquote><h4>Example: “I’ve been learning Docker and Kubernetes in my spare time. I like them very much, and we should deploy our app using them, because they are the new industry standard way that businesses are deploying their apps.”</h4><p>There can be no doubt that Docker and Kubernetes are fantastic tools, but the fact that they are new and becoming accepted as an industry standard does not necessarily mean you should adopt them. The statement above is a weak argument on its own. This is because it is another example of an area where there are much more important and heavily weighted considerations:</p><ul><li>Assuming they don’t already have experience, your team is now going to have to learn both Docker and Kubernetes. Is it worth it compared to simpler approaches?</li><li>When you make new hires in the future have you considered that you are either going to have to teach them, or require them to know this already?</li><li>There are certainly much simpler ways of deploying software than using this strategy. Are you sure want to commit the time and resources to this?</li><li>Are you able to empirically demonstrate that you are likely to see enough benefits from the switch to the new technology to compensate for the costs of the above points?</li></ul><p>Again, if the answers are “no”, perhaps this needs more detailed consideration. It seems like an endemic number of developers, particularly skilled ones, have a tendency to get bored with what they are currently doing and like opportunities to stretch their wings and try out new and different things. It is always worth being very aware that this may cloud their judgement when making key decisions. It is worth remembering that often the simplest solutions are the best.</p><p>This is of course not to say that any of the propositions in the above examples are bad in all cases, in fact, many of them are great solutions to the specific problems that they were designed to solve. The point is that if you are making considerations to your architecture and code choices, do not allow logically fallacious claims and cognitive biases to slip into the mix, and stick to the facts of whether the proposed solution actually matches the problems you have. This is done through careful, nonpartisan consideration of the merits and drawbacks in all cases.</p><p><a href="https://yourlogicalfallacyis.com/">Use critical thinking to avoid logical fallacies</a>. Don’t claim your tech ‘should’ be any particular way. And don’t just blindly copy Martin Fowler.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=563090144331" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/critical-thinking-in-software-development-the-word-should-and-why-you-shouldn-t-listen-to-563090144331">Critical thinking in software development, the word ‘should’, and why you shouldn’t listen to…</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using RxJS to handle HTTP requests]]></title>
            <link>https://medium.com/hackernoon/using-rxjs-to-handle-http-requests-what-ive-learned-4640aaf4646c?source=rss-84f920c387b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/4640aaf4646c</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[rxjs]]></category>
            <dc:creator><![CDATA[James Flight]]></dc:creator>
            <pubDate>Fri, 25 Nov 2016 07:42:22 GMT</pubDate>
            <atom:updated>2017-07-14T13:26:51.533Z</atom:updated>
            <content:encoded><![CDATA[<p>When I first started learning RxJS, I could instinctively see that observable streams offered all kinds of possibilities in solving many of the problems I encountered day to day in front end web application development. I’d already been using the flux architecture for a while, and had been blown away by the clarity of organisational structure and separation of concerns it brought to my web apps. I’d read that RxJS could do the same, and was keen to learn about how. The elegant handling of HTTP requests seemed like the obvious starting point for this learning journey.</p><p>However, I quickly became frustrated at how little information I could find in one place regarding good practices around this topic (error handling in particular), and had to find out most things piecemeal though reading around, a lot of browsing Stackoverflow and Github issue threads, and personal experimentation. This article serves as a catalogue for what I have learned so far.</p><p>I’m going to explain some handy ways of doing the following:</p><ul><li>Creating observable streams from HTTP requests</li><li>Handling HTTP error responses</li><li>The elegant handling of out of order HTTP request completion</li><li>Throttling user input</li><li>Some bonus extra tips an tricks</li></ul><p>I’m going to assume some knowledge of the absolute basics of creating and subscribing to observables, as this is easy to <a href="https://www.sitepoint.com/functional-reactive-programming-rxjs/">find online</a>, and is where I was at when I started experimenting with RxJS and HTTP requests.</p><h3>The Example App</h3><p>To demonstrate all of these techniques we’ll create a example mini app that consumes g<a href="https://api.github.com/users/jamesflight">ithub user api</a>. It will enable the user to type a github username in a box and if valid, display their avatar underneath. I’ll use many variations of the app to demonstrate the different ways of using RxJS. To keep things simple the app only uses RxJS, bootstrap and a little bit of jQuery to glue the page together.</p><p>Note: the github user api, has a rather pathetic rate limit of 60 requests per hour if used unauthenticated. So if you get too trigger happy with the examples, they might stop working for a bit.</p><h4>The Setup</h4><p>To kick us off, let’s create a text input, and create an observable from its ‘keyup’ event.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fjamesflight%2Fembed%2Fpreview%2FZpZqPz%3Fheight%3D600%26amp%3Bslug-hash%3DZpZqPz%26amp%3Bdefault-tabs%3Dhtml%2Cresult%26amp%3Bhost%3Dhttp%253A%252F%252Fcodepen.io%26amp%3Bembed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2Fjamesflight%2Fpen%2FZpZqPz&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F827809.ZpZqPz.small.83e105c7-1c6d-45ab-8f89-1a570e148b46.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/4ffdf8bb92af2578d00818cba714964e/href">https://medium.com/media/4ffdf8bb92af2578d00818cba714964e/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/427f7c449521b8cddac2527e963746ae/href">https://medium.com/media/427f7c449521b8cddac2527e963746ae/href</a></iframe><p>Type in the box and hit the search button to see an alert containing the text input value. Notice the extra map chained after the fromEvent observable. This enables us to map the current input value of search input box to our userClicksSearchButton observable, replacing the default event object that would normally be emitted.</p><h3>Handling an HTTP request</h3><p>OK, we now have an observable we can work with that will emit the user’s input when they hit the search button. To fire off our HTTP request, we’re going to create an observable stream we can subscribe to using our userClicksSearchButton as a source:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fjamesflight%2Fembed%2Fpreview%2FxEqyZV%3Fheight%3D600%26amp%3Bslug-hash%3DxEqyZV%26amp%3Bdefault-tabs%3Dhtml%2Cresult%26amp%3Bhost%3Dhttp%253A%252F%252Fcodepen.io%26amp%3Bembed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2Fjamesflight%2Fpen%2FxEqyZV&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F827809.xEqyZV.small.bed8999b-492a-4fb3-b517-356b6245bbf4.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/901f83d76a732cccf0bf26b1642d3116/href">https://medium.com/media/901f83d76a732cccf0bf26b1642d3116/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/44bc0f6d4676415c6afd2e3dd9c9fc1c/href">https://medium.com/media/44bc0f6d4676415c6afd2e3dd9c9fc1c/href</a></iframe><p>Have a go at typing your github username into the box and hitting search, you should see your avatar appear underneath. Be aware that currently, if you search for an invalid user name, it will break the app. Don’t worry about this right now; we’ll sort that out in a bit.</p><p>We have chained flatMap after our first observable, subscribed tothe resulting observable, and writen some of the received data to the DOM.</p><p>We have carried out the request using a standard jQuery get, which we have wrapped in RxJS’ helpful fromPromise to turn it into an observable.</p><h4><strong>FlatMap</strong></h4><p>Take a look at the use of `flatMap` in the example. I must admit, when I first looked at a few examples of this kind of thing, it confused the hell out of me. At first glance it looks like we should just be able to call map like we did for the click event, after all, we’ve already converted the promise into an observable by calling fromPromise right?</p><p>In actual fact, what fromPromise returns is an observable stream <em>of promises</em>, not a stream of the objects that the promise would emit when it resolves. flatMap allows us to flatten all of those promise resolutions into a single observable stream, and when we subscribe to it, we get just the response object that jQuery would originally emitted on then().</p><h3>Handling Errors</h3><p>Earlier I mentioned that the app currently breaks if you search for a invalid user name (try searching for some gibberish followed by something perfectly valid). This obviously sucks, and initially, it is not at all obvious why this is happening. To understand why, let’s look at the order of events that takes place as the promise resolves:</p><ol><li>HTTP request completes, and jQuery rejects the promise (because it’s a 404)</li><li>The observable created by fromPromise throws an error, as this is how it reacts to a rejected promise</li><li>The error goes uncaught, and hence gets thrown again in the parent flatMap observable.</li><li>The flatMap observable will no longer emit because after an observable stream has thrown an error, it is terminated.</li></ol><p>This has the unintended side effect of making our search button useless every time we get an error response. This isn’t very good, so how can we deal with this problem?</p><p>Here’s the app again, but this time with error handling:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fjamesflight%2Fembed%2Fpreview%2FamJARO%3Fheight%3D600%26amp%3Bslug-hash%3DamJARO%26amp%3Bdefault-tabs%3Djs%2Cresult%26amp%3Bhost%3Dhttp%253A%252F%252Fcodepen.io%26amp%3Bembed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2Fjamesflight%2Fpen%2FamJARO&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F827809.amJARO.small.fcdf6112-de62-4df3-9089-2e055c49840c.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/829bea6e0c3f9779665eefefabbecd72/href">https://medium.com/media/829bea6e0c3f9779665eefefabbecd72/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/49f0f35b44b530ce95aac0ef7ce4ff6c/href">https://medium.com/media/49f0f35b44b530ce95aac0ef7ce4ff6c/href</a></iframe><p>Now, we catch and handle the error before it travels upstream, and replace the observable with an empty completed one that will get flattened in it’s place. For this we use the handy Rx.Observable.empty().</p><h3>Handling out of order requests</h3><p>Let’s alter the example a bit. Suppose instead of clicking a button to search, we want the user to be able to type into the box, and have their search be carried out as they type. For this we will need to replace the userClicksSearchButton observable with a userTypesInSearchBox observable like so:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fjamesflight%2Fembed%2Fpreview%2FdpvQqZ%3Fheight%3D600%26amp%3Bslug-hash%3DdpvQqZ%26amp%3Bdefault-tabs%3Djs%2Cresult%26amp%3Bhost%3Dhttp%253A%252F%252Fcodepen.io%26amp%3Bembed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2Fjamesflight%2Fpen%2FdpvQqZ&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F827809.dpvQqZ.small.9e771f5f-e26f-4ae3-8073-8c933963729e.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/f5ba148016aa40272c9ed2df93d23ab7/href">https://medium.com/media/f5ba148016aa40272c9ed2df93d23ab7/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/58afc238050c3174b9682247a7df4530/href">https://medium.com/media/58afc238050c3174b9682247a7df4530/href</a></iframe><p>We now find that because each of our requests are fired in quick succession, we can no longer guarantee that they will complete in the order they were initiated. This could cause our searches to result in a non matching avatar being displayed underneath. This isn’t great, so to solve this problem, we will use concatMap.</p><h4>ConcatMap</h4><p>concatMap is a lot like flatMap except it will preserve the order of the source emissions, even if the observable it is flattening emits in a different order. For example, if I search for ‘Elle’, and immediately afterwards for ‘Ellen’, and the ‘Ellen’ request happens to complete first, concatMap will wait until the ‘Elle’ request has completed, before emitting both results in immediate succession in the order ‘Elle’ ‘Ellen’.</p><p>Here’s the code, amended to use ‘concatMap’.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fjamesflight%2Fembed%2Fpreview%2FJRWZwr%3Fheight%3D600%26amp%3Bslug-hash%3DJRWZwr%26amp%3Bdefault-tabs%3Dhtml%2Cresult%26amp%3Bhost%3Dhttp%253A%252F%252Fcodepen.io%26amp%3Bembed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2Fjamesflight%2Fpen%2FJRWZwr&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F827809.JRWZwr.small.940ff941-bdc2-4015-9d9a-792d5e197abd.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/225dec8af892df5d18a1e60b8172e6a1/href">https://medium.com/media/225dec8af892df5d18a1e60b8172e6a1/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7a53b0743238bf5cfcf66e52fece71c1/href">https://medium.com/media/7a53b0743238bf5cfcf66e52fece71c1/href</a></iframe><p><strong>Edit:</strong> I’ve just learned that we could also use switchMap for this. This provides the added advantage of cancelling the underlying redundant http request if necessary.</p><h3>Throttling user input</h3><p>At the moment, our app fires a request every single time the user types a letter into the box. This seems like overkill, given that the user isn’t really interested in seeing a result until they’ve typed at least several letters into the box. Why hammer the server when it add nothing to the user experience? Using RxJS, we can ease this problem with a simple extra function call to ‘debounce’.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fjamesflight%2Fembed%2Fpreview%2FQKkXra%3Fheight%3D600%26amp%3Bslug-hash%3DQKkXra%26amp%3Bdefault-tabs%3Djs%2Cresult%26amp%3Bhost%3Dhttp%253A%252F%252Fcodepen.io%26amp%3Bembed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2Fjamesflight%2Fpen%2FQKkXra&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F827809.QKkXra.small.37e50694-253d-45bd-bac3-2d019edf3ebd.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/e5a48b7f75314282b7342f7abd1fbebe/href">https://medium.com/media/e5a48b7f75314282b7342f7abd1fbebe/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c870627d7f227d341fa1b561606fe9f4/href">https://medium.com/media/c870627d7f227d341fa1b561606fe9f4/href</a></iframe><p>In this example, it’s worth looking in the network tab of the console window as you type in the box to see that many fewer requests are sent than in the previous example.</p><h4>Debounce</h4><p>‘Debounce’ accepts a number parameter that represents the number of milliseconds the observable should wait after the previous emission before emitting again. After the time has elapsed, the observable will emit the last emission from within the time period only, ignoring any others. I’ve found this to be very helpful for live text based search features.</p><p>Note: if you need it to emit the opposite, i.e. the first emission from within the time period, you can use the throttle method instead.</p><h3><strong>Extra tips and tricks</strong></h3><p>The above techniques will handle most HTTP request use cases, but there are some other cool things you can do to ease some of the pain that comes from asynchronous request handling:</p><h4>Take</h4><p>Sometimes, you’re only interested in the first 1, 2 or n user interactions. For these situations RxJS provides the ‘take’ method. In our search button example, lets say we wanted to only show the first valid result:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fjamesflight%2Fembed%2Fpreview%2FEgdyOa%3Fheight%3D600%26amp%3Bslug-hash%3DEgdyOa%26amp%3Bdefault-tabs%3Djs%2Cresult%26amp%3Bhost%3Dhttp%253A%252F%252Fcodepen.io%26amp%3Bembed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2Fjamesflight%2Fpen%2FEgdyOa&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F827809.EgdyOa.small.d894a426-2759-42a3-a25b-fff6201be56c.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/f4e70bd64e316e64148cfafe9c82a104/href">https://medium.com/media/f4e70bd64e316e64148cfafe9c82a104/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe2822c1a02c9042c10de88dd15da937/href">https://medium.com/media/fe2822c1a02c9042c10de88dd15da937/href</a></iframe><p>Now, the first search performed will work, but anything subsequently typed into the box will be ignored.</p><h4>Filter</h4><p>Sometimes we want to filter out certain observable emissions based on a condition. To demonstrate, let’s use filter to make our text search example ignore searches until they are at least 5 characters long:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fjamesflight%2Fembed%2Fpreview%2FdpgXAN%3Fheight%3D600%26amp%3Bslug-hash%3DdpgXAN%26amp%3Bdefault-tabs%3Djs%2Cresult%26amp%3Bhost%3Dhttp%253A%252F%252Fcodepen.io%26amp%3Bembed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2Fjamesflight%2Fpen%2FdpgXAN&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F827809.dpgXAN.small.92abddfd-42d8-4c0a-88f9-89813a916847.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/26638368168ad144ff3ab13be1f84687/href">https://medium.com/media/26638368168ad144ff3ab13be1f84687/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6f9f60df7ca86e0ccb0c96b1ff1930d6/href">https://medium.com/media/6f9f60df7ca86e0ccb0c96b1ff1930d6/href</a></iframe><h4>Merge</h4><p>Sometimes, it is useful to merge more than one observable into a single observable. To demonstrate, let’s use merge to give our search app two inputs which you can search by typing into either one:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fjamesflight%2Fembed%2Fpreview%2FrrqExv%3Fheight%3D600%26amp%3Bslug-hash%3DrrqExv%26amp%3Bdefault-tabs%3Djs%2Cresult%26amp%3Bhost%3Dhttp%253A%252F%252Fcodepen.io%26amp%3Bembed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2Fjamesflight%2Fpen%2FrrqExv&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F827809.rrqExv.small.e7eb0d92-8e33-462b-8aeb-54ab538f47d4.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/10f2878d1fc244bbcd2f69ff16ee8480/href">https://medium.com/media/10f2878d1fc244bbcd2f69ff16ee8480/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/319a63437f0e51d81dda4fce402dc530/href">https://medium.com/media/319a63437f0e51d81dda4fce402dc530/href</a></iframe><h4>Keeping data for later</h4><p>A potential issue with all of the examples above is that when we are in the latter stages of the observable stream, after the request has completed, we’ve lost the reference to the original payload (in this case, our search term text). We can get around this bundling the original payload in with the response payload while we still have access to it via lexical scoping. For example, let’s say we wanted to write the search term to the page again as a part of the render function:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fjamesflight%2Fembed%2Fpreview%2FYGBLmV%3Fheight%3D600%26amp%3Bslug-hash%3DYGBLmV%26amp%3Bdefault-tabs%3Djs%2Cresult%26amp%3Bhost%3Dhttp%253A%252F%252Fcodepen.io%26amp%3Bembed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2Fjamesflight%2Fpen%2FYGBLmV&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F827809.YGBLmV.small.dd713651-c485-44fd-9a3c-f6f76fac595b.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/e8890d4fd2148ca8c996e78d068fa4bf/href">https://medium.com/media/e8890d4fd2148ca8c996e78d068fa4bf/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3ef3b50ed3eface6781a52e497f3b1af/href">https://medium.com/media/3ef3b50ed3eface6781a52e497f3b1af/href</a></iframe><h4>Combine latest</h4><p>One of the best features of RxJS is how easy it is to combine multiple streams into one. To demonstrate, let’s adapt our example to carry out two searches and allow the user to compare the resulting avatars next to each other, but only after both searches have a result:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fjamesflight%2Fembed%2Fpreview%2FNRJpoy%3Fheight%3D600%26amp%3Bslug-hash%3DNRJpoy%26amp%3Bdefault-tabs%3Dhtml%2Cresult%26amp%3Bhost%3Dhttp%253A%252F%252Fcodepen.io%26amp%3Bembed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2Fjamesflight%2Fpen%2FNRJpoy%3Feditors%3D1010&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F827809.NRJpoy.small.70ee2fb3-3ad8-4322-bb51-665d23440849.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/a50919f537091119d3c4557618475323/href">https://medium.com/media/a50919f537091119d3c4557618475323/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/39ac0ba0ca73ea035117c3ac99b351cb/href">https://medium.com/media/39ac0ba0ca73ea035117c3ac99b351cb/href</a></iframe><h3>What next?</h3><p>There are many ways to get the most out of the power of RxJS to handle HTTP requests, and we’ve touched upon a few of these. However, the RxJS API is a complex beast and we’ve only scratched the surface on the many different ways RxJS methods can do cool stuff with HTTP streams. Once you’ve got your head round a few, it’s well worth checking out the <a href="https://github.com/Reactive-Extensions/RxJS/blob/master/doc/libraries/main/rx.complete.md">docs</a> to experiment with a few more that might help out in more specific use cases.</p><figure><a href="http://bit.ly/HackernoonFB"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0hqOaABQ7XGPT-OYNgiUBg.png" /></a></figure><figure><a href="https://goo.gl/k7XYbx"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vgw1jkA6hgnvwzTsfMlnpg.png" /></a></figure><figure><a href="https://goo.gl/4ofytp"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gKBpq1ruUi0FVK2UM_I4tQ.png" /></a></figure><blockquote><a href="http://bit.ly/Hackernoon">Hacker Noon</a> is how hackers start their afternoons. We’re a part of the <a href="http://bit.ly/atAMIatAMI">@AMI</a> family. We are now <a href="http://bit.ly/hackernoonsubmission">accepting submissions</a> and happy to <a href="/service/mailto:partners@amipublications.com">discuss advertising &amp; sponsorship</a> opportunities.</blockquote><blockquote>If you enjoyed this story, we recommend reading our <a href="http://bit.ly/hackernoonlatestt">latest tech stories</a> and <a href="https://hackernoon.com/trending">trending tech stories</a>. Until next time, don’t take the realities of the world for granted!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*35tCjoPcvq6LbB3I6Wegqw.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4640aaf4646c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/using-rxjs-to-handle-http-requests-what-ive-learned-4640aaf4646c">Using RxJS to handle HTTP requests</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>