<?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"><channel><title><![CDATA[dereklawless.ie RSS feed]]></title><description><![CDATA[Personal website of Derek Lawless.]]></description><link>https://www.dereklawless.ie</link><generator>GatsbyJS</generator><lastBuildDate>Thu, 03 Apr 2025 13:04:39 GMT</lastBuildDate><item><title><![CDATA[Towards Effective Standups]]></title><description><![CDATA[A guide I wrote for the Scrum development team in my previous startup and intended to foster actual team self-organisation vs. top-down…]]></description><link>https://www.dereklawless.ie/towards-effective-standups/</link><guid isPermaLink="false">https://www.dereklawless.ie/towards-effective-standups/</guid><pubDate>Thu, 03 Apr 2025 00:00:00 GMT</pubDate><content:encoded>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;A guide I wrote for the &lt;a href=&quot;https://www.scrum.org/resources/what-scrum-team&quot;&gt;Scrum development team&lt;/a&gt; in my previous startup and intended to foster actual team self-organisation vs. top-down Scrum.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Perhaps too dogmatic in places it is presented here for posterity if not value.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;strong&gt;A sprint backlog is made up of PBIs (Product Backlog Items) plus a delivery plan&lt;/strong&gt; (Sub Tasks &amp;#x26; Estimates). The team will focus on delivering an increment of “Done” for every PBI based upon this delivery plan.&lt;/p&gt;
&lt;p&gt;The daily standup is an “informal mini planning event” to ensure the team understands what is planned for the next 24 hour period of delivery (of the plan).&lt;/p&gt;
&lt;p&gt;To understand the remaining sub tasks to deliver the aforementioned plan, the current state of the sprint must be known - hence why the team members inform each other of what they worked on in the previous 24 hours and ensure Jira remains up to date.&lt;/p&gt;
&lt;p&gt;It also provides the following additional benefits:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A method of cross-checking progress with team members;&lt;/li&gt;
&lt;li&gt;An accountability mechanism that has each team member accountable to other team members for their responsibilities;&lt;/li&gt;
&lt;li&gt;A visible demonstration of the ability of the team to self-manage their project responsibilities.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Standup format&lt;/h2&gt;
&lt;p&gt;Answers to the following 3 questions only please:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;What task(s) did you work on/accomplish yesterday?
- Keep brief - the focus should be on what the team are planning for today&lt;/li&gt;
&lt;li&gt;What task(s) do you plan to work on/accomplish today?&lt;/li&gt;
&lt;li&gt;What issues are currently preventing progress?&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;Guidelines&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;These guidelines are not dogma&lt;/strong&gt; - the Scrum team can decide what works best for them. All suggestions are welcomed.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Remember the standup is not a formal reporting meeting&lt;/strong&gt;, nor is the team reporting to the scrum master (or other project stakeholders) - no minutes will be sent out.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;To reiterate, it is an “informal mini planning event” for the team’s next 24 hour delivery period and not a solutioning workshop - no new ideas and no multitasking.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Jira should be updated prior to the standup for the previous 24 hours period - no updating should occur in the standup (for this period).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Try to stick to the questions at all times (except whereby the team has agreed to change).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Everyone should be on time and prepared.&lt;/strong&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The last person on the call will be responsible for commencing the standup conversations. Further the scrum master is not required to host the call (it is not a reporting meeting); in his/her absence the team should continue to have the standup.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Time limits may be enforced for conversations. Anyone in the team can insist on moving a conversation out of the standup - remember updates should be applicable to everyone.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Non team members (i.e. participants not responsible for delivery of sprint backlog) are welcome to the standup but do not have a formal speaking role.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The team is self organising&lt;/strong&gt;, hence the Scrum team members are responsible for proactively ensuring the blocking issues are addressed/removed. Further the standup is not the sole means of communication - team members should not wait until the next stand-up to raise/resolve blocking issues.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;</content:encoded></item><item><title><![CDATA[Downloading Lambda layer versions using the AWS CLI]]></title><description><![CDATA[The packaged .zip for a Lambda layer can be downloaded using the AWS console (appropriate IAM permissions notwithstanding) - as long as you…]]></description><link>https://www.dereklawless.ie/downloading-lambda-layers-versions-using-the-aws-cli/</link><guid isPermaLink="false">https://www.dereklawless.ie/downloading-lambda-layers-versions-using-the-aws-cli/</guid><pubDate>Thu, 16 Jun 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;The packaged .zip for a &lt;a href=&quot;https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html&quot;&gt;Lambda layer&lt;/a&gt; can be downloaded using the AWS console (appropriate IAM permissions notwithstanding) - as long as you have access to the host AWS account of course.&lt;/p&gt;
&lt;p&gt;If the Lambda layer originates in a &lt;em&gt;different AWS account&lt;/em&gt; you don’t have console access to, &lt;strong&gt;you will need to use the AWS CLI&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Why would you want or need to do this though?&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;As with any third party dependency it makes sense to examine it rather than simply trusting it to be benign in nature&lt;/li&gt;
&lt;li&gt;You want to override the layer’s behaviour in a specific way (i.e. by merging a later layer) and need to examine its implementation&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Fortunately, the &lt;code class=&quot;language-text&quot;&gt;aws lambda&lt;/code&gt; CLI provides two useful options - one for downloading a layer version by name, the other by its &lt;a href=&quot;https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html&quot;&gt;ARN&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;Downloading a Lambda layer version by name&lt;/h2&gt;
&lt;p&gt;To download version 99 of a Lambda layer called &lt;code class=&quot;language-text&quot;&gt;acme-corp-lambda-layer&lt;/code&gt; using its name, use the &lt;code class=&quot;language-text&quot;&gt;get-layer-version&lt;/code&gt; option:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token assign-left variable&quot;&gt;URL&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token variable&quot;&gt;&lt;span class=&quot;token variable&quot;&gt;$(&lt;/span&gt;aws lambda get-layer-version --layer-name ars:aws:lambda:$AWS_REGION:$AWS_ACME_CORP_ACCOUNT:layer:acme-corp-lambda-layer --version-number:99 &lt;span class=&quot;token parameter variable&quot;&gt;--query&lt;/span&gt; Content.Location &lt;span class=&quot;token parameter variable&quot;&gt;--output&lt;/span&gt; text&lt;span class=&quot;token variable&quot;&gt;)&lt;/span&gt;&lt;/span&gt;

&lt;span class=&quot;token function&quot;&gt;curl&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$URL&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-o&lt;/span&gt; acme-corp-lambda-layer.zip&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;Downloading a Lambda layer version by ARN&lt;/h2&gt;
&lt;p&gt;If you want to download version 99 of of the layer using its ARN instead, use &lt;code class=&quot;language-text&quot;&gt;get-layer-version-by-arn&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token assign-left variable&quot;&gt;URL&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token variable&quot;&gt;&lt;span class=&quot;token variable&quot;&gt;$(&lt;/span&gt;aws lambda get-layer-version-by-arn &lt;span class=&quot;token parameter variable&quot;&gt;--arn&lt;/span&gt; arn:aws:lambda:$AWS_REGION:$AWS_ACME_CORP_ACCOUNT:layer:my-lambda-layer:99 &lt;span class=&quot;token parameter variable&quot;&gt;--query&lt;/span&gt; Content.Location &lt;span class=&quot;token parameter variable&quot;&gt;--output&lt;/span&gt; text&lt;span class=&quot;token variable&quot;&gt;)&lt;/span&gt;&lt;/span&gt;

&lt;span class=&quot;token function&quot;&gt;curl&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$URL&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-o&lt;/span&gt; acme-corp-lambda-layer.zip&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</content:encoded></item><item><title><![CDATA[Conditionally tagging resources in CloudFormation]]></title><description><![CDATA[While tagging resources in CloudFormation is straightforward, conditionally tagging them is a little non-obvious and requires use of…]]></description><link>https://www.dereklawless.ie/conditionally-tagging-resources-in-cloudformation/</link><guid isPermaLink="false">https://www.dereklawless.ie/conditionally-tagging-resources-in-cloudformation/</guid><pubDate>Wed, 27 Apr 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;While tagging resources in CloudFormation is straightforward, &lt;em&gt;conditionally tagging&lt;/em&gt; them is a little non-obvious and requires use of &lt;a href=&quot;https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/conditions-section-structure.html&quot;&gt;conditions&lt;/a&gt;.&lt;/p&gt;
&lt;h1&gt;Use case: tagging a release version&lt;/h1&gt;
&lt;p&gt;I wanted the ability to conditionally tag a Secrets Manager secret with a release version when the secret was deployed into production. For lower environments, I didn’t care / want to specify a release version.&lt;/p&gt;
&lt;p&gt;First, we define a parameter that will contain the release version:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;Parameters&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
	&lt;span class=&quot;token key atrule&quot;&gt;ReleaseVersion&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
		&lt;span class=&quot;token key atrule&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; String
		&lt;span class=&quot;token key atrule&quot;&gt;Description&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; The release version e.g. 1.2.3
		&lt;span class=&quot;token key atrule&quot;&gt;Default&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;&apos;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Next, we define a condition to easily check whether a non-default value was provided for the parameter:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;Conditions&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
	&lt;span class=&quot;token key atrule&quot;&gt;HasNoReleaseVersion&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
		&lt;span class=&quot;token tag&quot;&gt;!Equals&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;!Ref&lt;/span&gt; ReleaseVersion&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;&apos;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Finally, we tie it all together on the resource by conditionally setting the &lt;code class=&quot;language-text&quot;&gt;release&lt;/code&gt; tag depending on the evaluation of &lt;code class=&quot;language-text&quot;&gt;HasNoReleaseVersion&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;Resources&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
	&lt;span class=&quot;token key atrule&quot;&gt;MySecret&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
		&lt;span class=&quot;token key atrule&quot;&gt;Properties&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
			&lt;span class=&quot;token key atrule&quot;&gt;Tags&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
				&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;Fn::If&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
					&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; HasNoReleaseVersion
					&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token tag&quot;&gt;!Ref&lt;/span&gt; AWS&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;NoValue
					&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;Key&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; release
					&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;Value&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token tag&quot;&gt;!Ref&lt;/span&gt; ReleaseVersion&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The &lt;code class=&quot;language-text&quot;&gt;AWS::NoValue&lt;/code&gt; &lt;a href=&quot;https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/pseudo-parameter-reference.html&quot;&gt;pseudo parameter&lt;/a&gt; will ensure the tag is not created unless a non-default value for the release version was provided.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[The unknown Type in TypeScript]]></title><description><![CDATA[Introduced in TypeScript 3.0, the  type exists to provide a type-safe counterpart to the  type. To understand why this was considered a…]]></description><link>https://www.dereklawless.ie/the-unknown-type-in-typescript/</link><guid isPermaLink="false">https://www.dereklawless.ie/the-unknown-type-in-typescript/</guid><pubDate>Wed, 21 Apr 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Introduced in &lt;a href=&quot;https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-0.html#new-unknown-top-type&quot;&gt;TypeScript 3.0&lt;/a&gt;, the &lt;code class=&quot;language-text&quot;&gt;unknown&lt;/code&gt; type exists to provide a type-safe counterpart to the &lt;code class=&quot;language-text&quot;&gt;any&lt;/code&gt; type. To understand why this was considered a necessary or desirable addition to TypeScript, we need to revisit &lt;code class=&quot;language-text&quot;&gt;any&lt;/code&gt; and why its use can be problematic.&lt;/p&gt;
&lt;h2&gt;The &lt;code class=&quot;language-text&quot;&gt;any&lt;/code&gt; type&lt;/h2&gt;
&lt;p&gt;The &lt;code class=&quot;language-text&quot;&gt;any&lt;/code&gt; type has been in TypeScript since its initial release and represents all possible &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures&quot;&gt;JavaScript values&lt;/a&gt; (making it a &lt;a href=&quot;https://en.wikipedia.org/wiki/Top_type&quot;&gt;top type&lt;/a&gt; of the type system).&lt;/p&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;any&lt;/code&gt; can be problematic because of its flexibility - it allows typing to be circumvented:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;typescript&quot;&gt;&lt;pre class=&quot;language-typescript&quot;&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// TypeScript&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; value&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// Any value can be assigned to an &apos;any&apos; type:&lt;/span&gt;
value &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
value &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
value &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Hello world&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
value &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
value &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
value &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
value &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;undefined&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
value &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Date&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;now&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
value &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Error&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
value &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;Symbol&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;// ...&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// No check on use:&lt;/span&gt;
value &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; value&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
value&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
value&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;foo&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;bar&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;baz&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;// ...&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;While convenient, &lt;code class=&quot;language-text&quot;&gt;any&lt;/code&gt; undoubtedly increases the risk of errors or unexpected behaviour sneaking into code simply by negating one of the primary benefits of using TypeScript in the first instance - strong typing.&lt;/p&gt;
&lt;h2&gt;The &lt;code class=&quot;language-text&quot;&gt;unknown&lt;/code&gt; type&lt;/h2&gt;
&lt;p&gt;The &lt;code class=&quot;language-text&quot;&gt;unknown&lt;/code&gt; type is less permissive than &lt;code class=&quot;language-text&quot;&gt;any&lt;/code&gt;. While any value is assignable an &lt;code class=&quot;language-text&quot;&gt;unknown&lt;/code&gt; can only be assigned to itself (or to&lt;code class=&quot;language-text&quot;&gt;any&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;Revisiting the previous example:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;typescript&quot;&gt;&lt;pre class=&quot;language-typescript&quot;&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// TypeScript&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; value&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;unknown&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// Any value can be assigned to an &apos;unknown&apos; type:&lt;/span&gt;
value &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
value &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
value &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Hello world&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
value &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
value &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
value &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
value &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;undefined&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
value &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Date&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;now&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
value &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Error&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
value &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;Symbol&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;// ...&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// An &apos;unknown&apos; type can be assigned to &apos;any&apos; or &apos;unknown&apos;:&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; toAny&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;any&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; value&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; toUnknown&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;unknown&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; value&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// Assignments to other types will fail:&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; toBoolean&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;boolean&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; value&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; toString&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; value&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;// ...&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;Narrowing and asserting&lt;/h3&gt;
&lt;p&gt;Operations cannot be performed on an &lt;code class=&quot;language-text&quot;&gt;unknown&lt;/code&gt; type without first &lt;a href=&quot;https://www.typescriptlang.org/docs/handbook/2/narrowing.html&quot;&gt;narrowing&lt;/a&gt; to a more specific type or asserting:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;typescript&quot;&gt;&lt;pre class=&quot;language-typescript&quot;&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// TypeScript&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; value&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;unknown&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// Operations including the following will error:&lt;/span&gt;
value&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
value&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;foo&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;bar&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;baz&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;// ...&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;One method of narrowing is with the &lt;code class=&quot;language-text&quot;&gt;typeof&lt;/code&gt; operator:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;typescript&quot;&gt;&lt;pre class=&quot;language-typescript&quot;&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// TypeScript&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; value&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;unknown&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;hello world&apos;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;typeof&lt;/span&gt; value &lt;span class=&quot;token operator&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;string&apos;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token comment&quot;&gt;// Narrowed to a string type, can safely call &apos;toUpperCase()&apos;&lt;/span&gt;
	&lt;span class=&quot;token builtin&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;value&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;toUpperCase&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Types can be asserted using the &lt;code class=&quot;language-text&quot;&gt;as&lt;/code&gt; operator:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;typescript&quot;&gt;&lt;pre class=&quot;language-typescript&quot;&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// TypeScript&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; value1&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;unknown&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;hello world&apos;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; value2&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;unknown&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token builtin&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;value1 &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;toUpperCase&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Ok&lt;/span&gt;
&lt;span class=&quot;token builtin&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;value2 &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;toUpperCase&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Error&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;span role=&quot;img&quot; aria-label=&quot;bell&quot;&gt;🔔&lt;/span&gt; Type assertions should be used with caution as they may result in expected run-time issues.&lt;/p&gt;
&lt;h3&gt;Unions and intersections&lt;/h3&gt;
&lt;p&gt;In a &lt;a href=&quot;https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#union-types&quot;&gt;union&lt;/a&gt;, an &lt;code class=&quot;language-text&quot;&gt;unknown&lt;/code&gt; absorbs everything else (the exception to this rule is a union with &lt;code class=&quot;language-text&quot;&gt;any&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;With an &lt;a href=&quot;https://www.typescriptlang.org/docs/handbook/2/objects.html#intersection-types&quot;&gt;intersection&lt;/a&gt;, the converse applies - that is, other types will subsume the &lt;code class=&quot;language-text&quot;&gt;unknown&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;typescript&quot;&gt;&lt;pre class=&quot;language-typescript&quot;&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// TypeScript&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// Unions:&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;union1&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;unknown&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;union2&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;unknown&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;undefined&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;union3&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;unknown&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;boolean&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;union4&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;unknown&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;union5&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;unknown&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;union6&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;unknown&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;undefined&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;boolean&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;// ...&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;unionN&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;unknown&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// any&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// Intersections:&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;intersection1&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;unknown&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;intersection2&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;unknown&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;undefined&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;intersection3&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;unknown&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;boolean&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;intersection4&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;unknown&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;intersection5&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;unknown&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;intersection6&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;unknown&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// never&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;// ...&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;intersectionN&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;unknown&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// any&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;When to use &lt;code class=&quot;language-text&quot;&gt;unknown&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;Wherever possible specify an explicit type and avoid using &lt;code class=&quot;language-text&quot;&gt;any&lt;/code&gt; or &lt;code class=&quot;language-text&quot;&gt;unknown&lt;/code&gt;. Explicitly specifying types allows you to take advantage of TypeScript’s compile-time checking, provides a more explicit contract (something especially important for library writers to consider), and should result in fewer run-time issues.&lt;/p&gt;
&lt;p&gt;Where this is not possible, prefer &lt;code class=&quot;language-text&quot;&gt;unknown&lt;/code&gt; over &lt;code class=&quot;language-text&quot;&gt;any&lt;/code&gt; as its characteristics require more deliberate and thoughtful use.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Nemawashi]]></title><description><![CDATA[Photo by Emma Gossett Literally translating as “to go around the roots”, Nemawashi (根回し) historically described the farming activity of…]]></description><link>https://www.dereklawless.ie/nemawashi/</link><guid isPermaLink="false">https://www.dereklawless.ie/nemawashi/</guid><pubDate>Thu, 21 Jan 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 640px; &quot;
    &gt;
      &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 75%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAAPABQDASIAAhEBAxEB/8QAFwABAQEBAAAAAAAAAAAAAAAAAgAEBf/EABUBAQEAAAAAAAAAAAAAAAAAAAEC/9oADAMBAAIQAxAAAAHlPQIXCD//xAAZEAACAwEAAAAAAAAAAAAAAAAAEQECIRL/2gAIAQEAAQUCRWrIwnlaOT//xAAVEQEBAAAAAAAAAAAAAAAAAAAAEf/aAAgBAwEBPwGI/8QAFREBAQAAAAAAAAAAAAAAAAAAEBH/2gAIAQIBAT8Bp//EABoQAAICAwAAAAAAAAAAAAAAAAAQAREhMTL/2gAIAQEABj8CWzmLML//xAAcEAEAAgEFAAAAAAAAAAAAAAABABEhMVFhcYH/2gAIAQEAAT8hOQkY+ygrCVWGjoDWybzP/9oADAMBAAIAAwAAABAkH//EABYRAQEBAAAAAAAAAAAAAAAAAAEAEf/aAAgBAwEBPxBRav/EABcRAAMBAAAAAAAAAAAAAAAAAAABESH/2gAIAQIBAT8Q0iM//8QAGxABAAMBAQEBAAAAAAAAAAAAAQARITFRsdH/2gAIAQEAAT8Qod9y4h1yivCXBxeH2OuFWVRDSF3BWe1HHZ9A/J//2Q==&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;img
        class=&quot;gatsby-resp-image-image&quot;
        alt=&quot;Banyan tree in Hawai’i&quot;
        title=&quot;&quot;
        src=&quot;/static/b0639bd30d5def903f71a46ce95a7454/c08c5/emma-gossett-B645igbiKCw-unsplash.jpg&quot;
        srcset=&quot;/static/b0639bd30d5def903f71a46ce95a7454/0913d/emma-gossett-B645igbiKCw-unsplash.jpg 160w,
/static/b0639bd30d5def903f71a46ce95a7454/cb69c/emma-gossett-B645igbiKCw-unsplash.jpg 320w,
/static/b0639bd30d5def903f71a46ce95a7454/c08c5/emma-gossett-B645igbiKCw-unsplash.jpg 640w&quot;
        sizes=&quot;(max-width: 640px) 100vw, 640px&quot;
        style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
        loading=&quot;lazy&quot;
        decoding=&quot;async&quot;
      /&gt;
    &lt;/span&gt;
Photo by &lt;a href=&quot;https://unsplash.com/@emmagossett&quot;&gt;Emma Gossett&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Literally translating as “to go around the roots”, &lt;a href=&quot;https://en.wikipedia.org/wiki/Nemawashi&quot;&gt;Nemawashi&lt;/a&gt; (根回し) historically described the farming activity of transplanting a tree from one location to another. Before transplanting, the tree’s roots are dug around and soil from the new location is introduced. This allows the tree to acclimate to its new environment prior to being moved, increasing its chances of survival.&lt;/p&gt;
&lt;p&gt;In modern times, Nemawashi describes a process of laying the foundation for a proposal by first seeking consensus inside and outside the team informally - allowing others to give their opinions and contribute - before formally presenting the proposal. This increases the probability of the proposal being accepted and ultimately executed upon.&lt;/p&gt;
&lt;p&gt;Although widespread in Japanese business, Nemawashi is perhaps most recognisable outside Japan as one of the 13 pillars of the &lt;a href=&quot;https://www.toyotauk.com/how-we-manufacture/glossary.html&quot;&gt;Toyota Production System&lt;/a&gt; (from which &lt;a href=&quot;https://www.lean.org/WhatsLean/&quot;&gt;Lean&lt;/a&gt; was partly derived).&lt;/p&gt;
&lt;h2&gt;Nemawashi and software development&lt;/h2&gt;
&lt;p&gt;Conversation about Nemawashi typically centres around the application of Lean to classical business activities and manufacturing. However, it’s also a technique that software development teams can make effective use of.&lt;/p&gt;
&lt;h3&gt;Getting buy-in&lt;/h3&gt;
&lt;p&gt;Consider a significant architectural change to an existing software system e.g. moving from a monolithic architecture to a microservices-based one.&lt;/p&gt;
&lt;p&gt;An architect can dictate a design to the development team, handing it off to be implemented according to her vision or she can practice Nemawashi.&lt;/p&gt;
&lt;p&gt;Nemawashi does not mean the architecture will be compromised as a result of design by committee, quite the opposite. By allowing the development team to examine the proposed new architecture in detail before architecture sign-off and provide their inputs and insights, buy-in amongst team members will be increased.&lt;/p&gt;
&lt;p&gt;On a software development project of any complexity having a development team operating beyond the role of reluctant implementor can be a critical factor in maximising the probability of success.&lt;/p&gt;
&lt;h3&gt;Building consensus&lt;/h3&gt;
&lt;p&gt;Proposals may be organisationally or politically sensitive for a variety of reasons.&lt;/p&gt;
&lt;p&gt;A proposal to move from manual infrastructure management on a project to &lt;a href=&quot;https://en.wikipedia.org/wiki/Infrastructure_as_code&quot;&gt;Infrastructure as Code&lt;/a&gt; (IaC) might be viewed with a mix of suspicion, concern, and derision by an existing infrastructure team. Although there may be an element of self-preservation on the part of the infrastructure team, their views should not be dismissed as entirely unfounded.&lt;/p&gt;
&lt;p&gt;Here, Nemawashi can be leveraged to build consensus with the infrastructure team - acclimating them to the proposal through positive engagement, assuaging their concerns, being open to feedback, and so on.&lt;/p&gt;
&lt;h3&gt;The goal&lt;/h3&gt;
&lt;blockquote&gt;
&lt;p&gt;The goal is to see your proposal succeed.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Nemawashi provides a method for achieving this, recognising that by building consensus and offering inclusivity the art of persuasion is made easier.&lt;/p&gt;
&lt;p&gt;Nemawashi is somewhat orthogonal to the model of traditional software team ‘leadership’, where forcefulness is viewed as a positive attribute and celebrated. (There can be little doubt this is partly because the software development industry is wholly under-representative of society.)&lt;/p&gt;
&lt;p&gt;As development teams diversify - bringing new perspectives, approaches, and viewpoints - methods such as Nemawashi may become more prevalent and, I believe, recognised as a key attribute of high-performance software development teams.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Year in review]]></title><description><![CDATA[Photo by Juan Rumimpunu 2020  Career Many software development contractors I’ve worked with are poor at the business of it - not in their…]]></description><link>https://www.dereklawless.ie/year-in-review/</link><guid isPermaLink="false">https://www.dereklawless.ie/year-in-review/</guid><pubDate>Wed, 13 Jan 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 640px; &quot;
    &gt;
      &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 66.875%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAANABQDASIAAhEBAxEB/8QAFwABAAMAAAAAAAAAAAAAAAAAAAIDBP/EABUBAQEAAAAAAAAAAAAAAAAAAAED/9oADAMBAAIQAxAAAAHPEglIf//EABoQAQADAAMAAAAAAAAAAAAAAAEAAhEhIjL/2gAIAQEAAQUCAZnYMh5Ja3P/xAAWEQEBAQAAAAAAAAAAAAAAAAAAARH/2gAIAQMBAT8BjX//xAAWEQEBAQAAAAAAAAAAAAAAAAAAIUH/2gAIAQIBAT8BxX//xAAVEAEBAAAAAAAAAAAAAAAAAAAgQf/aAAgBAQAGPwKL/8QAGhAAAwEBAQEAAAAAAAAAAAAAAAERMSFBYf/aAAgBAQABPyGA+GJFSUp4uHwRGrYRwf/aAAwDAQACAAMAAAAQH+//xAAVEQEBAAAAAAAAAAAAAAAAAAAhEP/aAAgBAwEBPxAMf//EABgRAQADAQAAAAAAAAAAAAAAAAEAESEx/9oACAECAQE/EL2rCxyf/8QAGxABAQACAwEAAAAAAAAAAAAAAREAMSFRYUH/2gAIAQEAAT8QdKk39AN+Y2UKN3puQJIVWuIA0q7PHCKE4rvjFhLx3n//2Q==&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;img
        class=&quot;gatsby-resp-image-image&quot;
        alt=&quot;Monkey in Monkey Forest Bali, Indonesia&quot;
        title=&quot;&quot;
        src=&quot;/static/dfd635023d9d5260b1479b0a569235a5/c08c5/juan-rumimpunu-nLXOatvTaLo-unsplash.jpg&quot;
        srcset=&quot;/static/dfd635023d9d5260b1479b0a569235a5/0913d/juan-rumimpunu-nLXOatvTaLo-unsplash.jpg 160w,
/static/dfd635023d9d5260b1479b0a569235a5/cb69c/juan-rumimpunu-nLXOatvTaLo-unsplash.jpg 320w,
/static/dfd635023d9d5260b1479b0a569235a5/c08c5/juan-rumimpunu-nLXOatvTaLo-unsplash.jpg 640w&quot;
        sizes=&quot;(max-width: 640px) 100vw, 640px&quot;
        style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
        loading=&quot;lazy&quot;
        decoding=&quot;async&quot;
      /&gt;
    &lt;/span&gt;
Photo by &lt;a href=&quot;https://unsplash.com/@earbiscuits&quot;&gt;Juan Rumimpunu&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;2020&lt;/h2&gt;
&lt;p&gt;&lt;span role=&quot;img&quot; aria-label=&quot;face screaming in fear&quot;&gt;😱&lt;/span&gt;&lt;/p&gt;
&lt;h2&gt;Career&lt;/h2&gt;
&lt;p&gt;Many software development contractors I’ve worked with are poor at the business of it - not in their technical abilities, more because they’re individuals who care deeply about refining their craft and advancing software engineering. Admirable goals but ones that can be difficult to reconcile with roles where throughput of code is (typically) the primary metric of interest to a temporary employer who wants a problem solved yesterday.&lt;/p&gt;
&lt;p&gt;I found myself at a crossroads professionally with my level of dissatisfaction increasing as 2020 dragged interminably on. Working as a ‘senior’ software engineer on a rolling contract, I was performing my assigned role well but felt capable of contributing much more and eager for change.&lt;/p&gt;
&lt;p&gt;In September an opportunity to manage an engineering team presented itself once again. I jumped at the chance to get back to a role to where I could affect change, evangelise the role of engineering in product design, and foster a quality-focused engineering culture.&lt;/p&gt;
&lt;h2&gt;Website&lt;/h2&gt;
&lt;p&gt;For many years I specialised in frontend development and &lt;abbr title=&quot;User Experience&quot;&gt;UX&lt;/abbr&gt;. Naturally, I failed to maintain a dedicated web presence of my own, it had felt too much of a &lt;a href=&quot;https://www.dictionary.com/browse/busman-s-holiday&quot;&gt;busman’s holiday&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The impetus for this website was primarily to encourage me to write more - something I find enjoyable but rarely set aside time for. Having stepped away from frontend development a couple of years ago, it was also enjoyable to tentatively come back to it.&lt;/p&gt;
&lt;p&gt;Another reason for this website is to give me a starting point for cultivating my personal brand (I apologise in advance). You should always &lt;a href=&quot;https://hanselman.com/blog/your-words-are-wasted&quot;&gt;own your own words&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;Design thinking&lt;/h2&gt;
&lt;p&gt;I began a &lt;a href=&quot;https://iadt.ie/courses/design-thinking/&quot;&gt;Certificate in Design Thinking&lt;/a&gt; third level course on a part-time basis in late 2019, and was awarded the accreditation in September 2020.&lt;/p&gt;
&lt;p&gt;The techniques I learned on the course would have been incredibly useful when I was the CTO in a startup and trying to find that elusive product-market fit, but more on this another day.&lt;/p&gt;
&lt;h2&gt;Certifications&lt;/h2&gt;
&lt;p&gt;Being fortunate enough to work from home most of the year afforded me with additional free time that is otherwise spent commuting. I decided to use some of this time to focus on improving my marketability should the need arise - something which felt proactive given the situation that was unfolding globally.&lt;/p&gt;
&lt;p&gt;I remain sceptical of the value placed on certifications in the software industry and believe they are no substitute for actual experience or, indeed, aptitude and inquisitiveness. More problematically, certifications can involve significant financial outlay and may constitute yet another obstacle to a more inclusive industry.&lt;/p&gt;
&lt;p&gt;However, given I earn my living primarily from consulting they can be undeniably useful to possess and structured learning can lay the groundwork for developing deeper understanding.&lt;/p&gt;
&lt;p&gt;I set myself the goal of attaining two certifications by the end of the year.&lt;/p&gt;
&lt;p&gt;In August I sat and passed the &lt;a href=&quot;https://www.youracclaim.com/badges/c485758d-8fe7-4431-aefa-79fd4b6d842d&quot;&gt;AWS Certified Solutions Architect – Associate&lt;/a&gt; exam. As my daily work involves designing and developing serverless architectures on AWS it was the logical choice to complete first.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://www.opengroup.org/togaf&quot;&gt;TOGAF&lt;/a&gt; certification was something I considered many times (more so when I was working in banking) but always deferred for one reason or another. In December after periodic and then concentrated study I sat and passed the &lt;a href=&quot;https://www.youracclaim.com/badges/78f60ec9-3aca-4411-9831-82b674cc890e&quot;&gt;TOGAF® 9 Certified&lt;/a&gt; exam.&lt;/p&gt;
&lt;hr&gt;
&lt;h2&gt;2021&lt;/h2&gt;
&lt;p&gt;Professionally, I intend to be less &lt;a href=&quot;https://www.hanselman.com/blog/dark-matter-developers-the-unseen-99&quot;&gt;dark matter&lt;/a&gt; this year. How that will manifest I’m not fully sure yet although I have some ideas for interesting projects and other collaborative things.&lt;/p&gt;
&lt;p&gt;On this website I intend to write more about topics of specific interest to me - revisiting my previous life in a startup, the characteristics of high-performing teams and individuals, the confluence between design and development, cloud, computing history, and so on.&lt;/p&gt;
&lt;p&gt;Further certifications are likely, but as the mood takes me. I think rebalancing after-work hours in favour of other interests will be more conducive to maintaining positive mental health given everything happening in the world.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Binary Search]]></title><description><![CDATA[A binary search employs a divide and conquer strategy to find the position of a target value in a sorted list. A binary search is also known…]]></description><link>https://www.dereklawless.ie/binary-search/</link><guid isPermaLink="false">https://www.dereklawless.ie/binary-search/</guid><pubDate>Sat, 21 Nov 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;A &lt;a href=&quot;https://en.wikipedia.org/wiki/Binary_search_algorithm&quot;&gt;binary search&lt;/a&gt; employs a divide and conquer strategy to find the position of a target value in a sorted list. A binary search is also known as a half-interval search, logarithmic search, or binary chop.&lt;/p&gt;
&lt;p&gt;For binary search to work the &lt;strong&gt;list must be sorted&lt;/strong&gt; (sorting is a discussion for another time).&lt;/p&gt;
&lt;p&gt;Given a sorted list from which we want to find the number &lt;code class=&quot;language-text&quot;&gt;35&lt;/code&gt;:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;Binary search&quot; role=&quot;img&quot; src=&quot;/4d9ecf2b70de19a44b7a00adf494f9d2/binary-search-1.svg&quot;&gt;&lt;/p&gt;
&lt;p&gt;Begin by splitting the list into two halves, disregarding the half that is less than, or greater than, &lt;code class=&quot;language-text&quot;&gt;35&lt;/code&gt;:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;Binary search&quot; role=&quot;img&quot; src=&quot;/19eb6cdd26e6b496ca0addd7a608ee2d/binary-search-2.svg&quot;&gt;&lt;/p&gt;
&lt;p&gt;Split the remaining half into two — again disregarding the half that is less than, or greater than, &lt;code class=&quot;language-text&quot;&gt;35&lt;/code&gt;:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;Binary search&quot; role=&quot;img&quot; src=&quot;/a714c9ebf0096a74677499adc4fe3226/binary-search-3.svg&quot;&gt;&lt;/p&gt;
&lt;p&gt;Repeating again finds &lt;code class=&quot;language-text&quot;&gt;35&lt;/code&gt; at position &lt;code class=&quot;language-text&quot;&gt;5&lt;/code&gt; in the list:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;Binary search&quot; role=&quot;img&quot; src=&quot;/fbd687703ad663759f351f20cf7a8fad/binary-search-4.svg&quot;&gt;&lt;/p&gt;
&lt;h2&gt;Complexity&lt;/h2&gt;
&lt;p&gt;&lt;span role=&quot;img&quot; aria-label=&quot;bell&quot;&gt;🔔&lt;/span&gt; Complexity is considered in terms of worst case.&lt;/p&gt;
&lt;h3&gt;Time&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Notes&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Θ(log n)&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3&gt;Space&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Notes&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Θ(1)&lt;/td&gt;
&lt;td&gt;Requires three pointers to the list elements, regardless of list size&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2&gt;An implementation&lt;/h2&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;typescript&quot;&gt;&lt;pre class=&quot;language-typescript&quot;&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// TypeScript&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;interface&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;IBinarySearchResult&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	position&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token generic-function&quot;&gt;&lt;span class=&quot;token function&quot;&gt;binarySearch&lt;/span&gt;&lt;span class=&quot;token generic class-name&quot;&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;values&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; target&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; IBinarySearchResult &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; low &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; high &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; values&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;length &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

	&lt;span class=&quot;token keyword&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;low &lt;span class=&quot;token operator&quot;&gt;&amp;lt;=&lt;/span&gt; high&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; middle &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Math&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;floor&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;low &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; high&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;values&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;middle&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;===&lt;/span&gt; target&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
				position&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; middle&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
			&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;target &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; values&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;middle&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
			high &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; middle &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
			low &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; middle &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		position&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;A recursive alternative&lt;/h3&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;typescript&quot;&gt;&lt;pre class=&quot;language-typescript&quot;&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// TypeScript&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token generic-function&quot;&gt;&lt;span class=&quot;token function&quot;&gt;binarySearchRecursive&lt;/span&gt;&lt;span class=&quot;token generic class-name&quot;&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
	values&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
	target&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
	low&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
	high&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; values&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;length &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; IBinarySearchResult &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;

	&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;low &lt;span class=&quot;token operator&quot;&gt;&amp;lt;=&lt;/span&gt; high&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; middle &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Math&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;floor&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;low &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; high&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;values&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;middle&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;===&lt;/span&gt; target&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
				position&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; middle&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
			&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;target &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; values&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;middle&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;binarySearchRecursive&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;values&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; target&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; low&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; middle &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;binarySearchRecursive&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;values&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; target&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; middle &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; high&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		position&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/dereklawless/algorithms-and-data-structures-katas/tree/master/src/algorithms/searching/binary-search&quot;&gt;Code on Github&lt;/a&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Sieve of Eratosthenes]]></title><description><![CDATA[The Sieve of Eratosthenes is an ancient algorithm for discovering primes in a consecutive sequence of natural numbers. Given a consecutive…]]></description><link>https://www.dereklawless.ie/sieve-of-eratosthenes/</link><guid isPermaLink="false">https://www.dereklawless.ie/sieve-of-eratosthenes/</guid><pubDate>Sat, 07 Nov 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;The &lt;a href=&quot;https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes&quot;&gt;Sieve of Eratosthenes&lt;/a&gt; is an ancient algorithm for discovering primes in a consecutive sequence of natural numbers.&lt;/p&gt;
&lt;p&gt;Given a consecutive sequence of natural numbers such as:&lt;/p&gt;
&lt;pre class=&quot;language-&quot;&gt;2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20&lt;/pre&gt;
&lt;p&gt;Starting with &lt;code class=&quot;language-text&quot;&gt;2&lt;/code&gt; (&lt;code class=&quot;language-text&quot;&gt;0&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;1&lt;/code&gt; are not prime), eliminate every subsequent second number:&lt;/p&gt;
&lt;pre class=&quot;language-&quot;&gt;2, 3, &lt;del&gt;4&lt;/del&gt;, 5, &lt;dek&gt;6&lt;/del&gt;, 7, &lt;del&gt;8&lt;/del&gt;, 9, &lt;del&gt;10&lt;/del&gt;, 11, &lt;del&gt;12&lt;/del&gt;, 13, &lt;del&gt;14&lt;/del&gt;, 15, &lt;del&gt;16&lt;/del&gt;, 17, &lt;del&gt;18&lt;/del&gt;, 19, &lt;del&gt;20&lt;/del&gt;&lt;/pre&gt;
&lt;p&gt;Starting with &lt;code class=&quot;language-text&quot;&gt;3&lt;/code&gt;, eliminate every third number:&lt;/p&gt;
&lt;pre class=&quot;language-&quot;&gt;2, 3, &lt;del&gt;4&lt;/del&gt;, 5, &lt;deL&gt;6&lt;/del&gt;, 7, &lt;del&gt;8&lt;/del&gt;, &lt;del&gt;9&lt;/del&gt;, &lt;del&gt;10&lt;/del&gt;, 11, &lt;del&gt;12&lt;/del&gt;, 13, &lt;del&gt;14&lt;/del&gt;, &lt;del&gt;15&lt;/del&gt;, &lt;del&gt;16&lt;/del&gt;, 17, &lt;del&gt;18&lt;/del&gt;, 19, &lt;del&gt;20&lt;/del&gt;&lt;/pre&gt;
&lt;p&gt;Repeat the process, each time starting with the next smallest number in the sequence that has not been eliminated. When the limit of the sequence is reached the numbers remaining are the primes:&lt;/p&gt;
&lt;pre class=&quot;language-&quot;&gt;2, 3, 5, 7, 11, 13, 17, 19&lt;/pre&gt;
&lt;h2&gt;An implementation&lt;/h2&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;typescript&quot;&gt;&lt;pre class=&quot;language-typescript&quot;&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// TypeScript&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;SieveOfEratosthenes&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;findPrimes&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;upperBound&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; sieve &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token builtin&quot;&gt;Array&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;upperBound &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;fill&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

		&lt;span class=&quot;token comment&quot;&gt;// 0 and 1 are not prime by definition.&lt;/span&gt;
		sieve&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		sieve&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

		&lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; i &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;i &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; i&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;=&lt;/span&gt; upperBound&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; i&lt;span class=&quot;token operator&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;sieve&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
				&lt;span class=&quot;token comment&quot;&gt;// The number is not a prime, therefore its multiples will also not be primes.&lt;/span&gt;
				&lt;span class=&quot;token keyword&quot;&gt;continue&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

			&lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; multiplier &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;multiplier &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; i&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;=&lt;/span&gt; upperBound&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; multiplier&lt;span class=&quot;token operator&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
				&lt;span class=&quot;token comment&quot;&gt;// A multiple of a prime is not a prime.&lt;/span&gt;
				sieve&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;multiplier &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; i&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
		&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

		&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; primes&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; i &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; i &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; upperBound&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; i&lt;span class=&quot;token operator&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;sieve&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
				primes&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;i&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
		&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

		&lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; primes&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// Test&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; SieveOfEratosthenes &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;../sieve-of-eratosthenes&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token function&quot;&gt;describe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;SieveOfEratosthenes&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token function&quot;&gt;it&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;is exported&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token function&quot;&gt;expect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;SieveOfEratosthenes&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;toBeDefined&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

	&lt;span class=&quot;token function&quot;&gt;describe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;findPrimes()&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token function&quot;&gt;it&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;returns all prime numbers in a given bound set&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; knownPrimes &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;11&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;13&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;17&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;19&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;23&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;29&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;37&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;41&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;43&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;47&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

			&lt;span class=&quot;token function&quot;&gt;expect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;SieveOfEratosthenes&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;findPrimes&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;toEqual&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;knownPrimes&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/dereklawless/algorithms-and-data-structures-katas/tree/master/src/algorithms/prime-numbers&quot;&gt;Code on Github&lt;/a&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Fallacies of Distributed Computing: 8. The network is homogeneous]]></title><description><![CDATA[The fallacies of distributed computing are a set of assertions describing false assumptions made about distributed systems. L. Peter Deutsch…]]></description><link>https://www.dereklawless.ie/fallacies-of-distributed-computing-8-the-network-is-homogeneous/</link><guid isPermaLink="false">https://www.dereklawless.ie/fallacies-of-distributed-computing-8-the-network-is-homogeneous/</guid><pubDate>Tue, 30 Jun 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;a href=&quot;https://web.archive.org/web/20171107014323/http://blog.fogcreek.com/eight-fallacies-of-distributed-computing-tech-talk/&quot;&gt;The fallacies of distributed computing&lt;/a&gt; are a set of assertions describing false assumptions made about distributed systems.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/L._Peter_Deutsch&quot;&gt;L. Peter Deutsch&lt;/a&gt; drafted the first 7 fallacies in 1994, with the 8&lt;sup&gt;th&lt;/sup&gt; added by &lt;a href=&quot;https://en.wikipedia.org/wiki/James_Gosling&quot;&gt;James Gosling&lt;/a&gt; in 1997.&lt;/p&gt;
&lt;p&gt;The 8 fallacies are:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-1-the-network-is-reliable&quot;&gt;The network is reliable&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-2-latency-is-zero&quot;&gt;Latency is zero&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-3-bandwidth-is-infinite&quot;&gt;Bandwidth is infinite&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-4-the-network-is-secure&quot;&gt;The network is secure&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-5-topology-doesnt-change&quot;&gt;Topology doesn’t change&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-6-there-is-one-administrator&quot;&gt;There is one administrator&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-7-transport-cost-is-zero&quot;&gt;Transport cost is zero&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-8-the-network-is-homogeneous&quot;&gt;The network is homogeneous&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;8. The network is homogeneous&lt;/h2&gt;
&lt;h3&gt;The problem&lt;/h3&gt;
&lt;p&gt;Networks typically must support a wide variety of connected clients — from desktop-class machines to mobile and &lt;abbr title=&quot;Internet of Things&quot;&gt;IoT&lt;/abbr&gt; devices. These devices and the applications running on them may not be interoperable and a variety of standards-based and proprietary protocols and data formats may be in use.&lt;/p&gt;
&lt;p&gt;The network is not homogenous, it is heterogenous.&lt;/p&gt;
&lt;h3&gt;Solutions&lt;/h3&gt;
&lt;p&gt;Interoperability is key.&lt;/p&gt;
&lt;p&gt;Where possible, avoid applications that use proprietary protocols in favour of those leveraging standards-based ones. Favour data formats that enable interoperability e.g. JSON or XML over binary formats (&lt;a href=&quot;/fallacies-of-distributed-computing-7-transport-cost-is-zero&quot;&gt;fallacy 7&lt;/a&gt; aside) and architectures such as &lt;abbr title=&quot;REpresentational State Transfer&quot;&gt;REST&lt;/abbr&gt; or web services, particularly when integrating with third-party services.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Fallacies of Distributed Computing: 7. Transport cost is zero]]></title><description><![CDATA[The fallacies of distributed computing are a set of assertions describing false assumptions made about distributed systems. L. Peter Deutsch…]]></description><link>https://www.dereklawless.ie/fallacies-of-distributed-computing-7-transport-cost-is-zero/</link><guid isPermaLink="false">https://www.dereklawless.ie/fallacies-of-distributed-computing-7-transport-cost-is-zero/</guid><pubDate>Mon, 29 Jun 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;a href=&quot;https://web.archive.org/web/20171107014323/http://blog.fogcreek.com/eight-fallacies-of-distributed-computing-tech-talk/&quot;&gt;The fallacies of distributed computing&lt;/a&gt; are a set of assertions describing false assumptions made about distributed systems.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/L._Peter_Deutsch&quot;&gt;L. Peter Deutsch&lt;/a&gt; drafted the first 7 fallacies in 1994, with the 8&lt;sup&gt;th&lt;/sup&gt; added by &lt;a href=&quot;https://en.wikipedia.org/wiki/James_Gosling&quot;&gt;James Gosling&lt;/a&gt; in 1997.&lt;/p&gt;
&lt;p&gt;The 8 fallacies are:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-1-the-network-is-reliable&quot;&gt;The network is reliable&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-2-latency-is-zero&quot;&gt;Latency is zero&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-3-bandwidth-is-infinite&quot;&gt;Bandwidth is infinite&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-4-the-network-is-secure&quot;&gt;The network is secure&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-5-topology-doesnt-change&quot;&gt;Topology doesn’t change&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-6-there-is-one-administrator&quot;&gt;There is one administrator&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-7-transport-cost-is-zero&quot;&gt;Transport cost is zero&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-8-the-network-is-homogeneous&quot;&gt;The network is homogeneous&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;7. Transport cost is zero&lt;/h2&gt;
&lt;h3&gt;The problem&lt;/h3&gt;
&lt;p&gt;Whereas the &lt;a href=&quot;/fallacies-of-distributed-computing-2-latency-is-zero&quot;&gt;second fallacy&lt;/a&gt; relates to the time taken to transport data over a network, the seventh fallacy relates to the resources required to do so.&lt;/p&gt;
&lt;h4&gt;Marshalling&lt;/h4&gt;
&lt;p&gt;There is a resource (and resultant latency) cost in marshalling data between the application layer (&lt;a href=&quot;https://en.wikipedia.org/wiki/OSI_model#Layer_7:_Application_Layer&quot;&gt;Layer 7&lt;/a&gt; on the OSI Reference Model) and transport layer (&lt;a href=&quot;https://en.wikipedia.org/wiki/OSI_model#Layer_4:_Transport_Layer&quot;&gt;Layer 4&lt;/a&gt;) in order to send it over the network. While this may be an abstract concern where a system is deployed on own hardware, in a cloud computing context where resource utilisation equals money, it can be a more concrete concern.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Computing time costs money.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4&gt;Infrastructure&lt;/h4&gt;
&lt;p&gt;The infrastructure used to set up and run the system will incur initial and ongoing costs — for on-premises systems these may include the cost of physical hardware such as servers, switches, and routers to the salaries of the network operators who will hopefully manage everything.&lt;/p&gt;
&lt;p&gt;For cloud computing, while physical hardware costs will of course not be a factor of concern, you will pay a premium for the resources you utilise.&lt;/p&gt;
&lt;h3&gt;Solutions&lt;/h3&gt;
&lt;p&gt;While the cost of infrastructure is mostly outside your control, optimising its use is within your domain. Reducing the time spent marshalling data between Layers 7 and 4 may be significant, depending on the functionality provided by the system. For example, the cost of transport for systems providing audio and video streaming, telephony, or realtime collaboration features can be brought closer to zero by leveraging an optimised data format e.g. &lt;a href=&quot;https://developers.google.com/protocol-buffers&quot;&gt;protocol buffers&lt;/a&gt; vs. opting for JSON or XML.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Fallacies of Distributed Computing: 6. There is one administrator]]></title><description><![CDATA[The fallacies of distributed computing are a set of assertions describing false assumptions made about distributed systems. L. Peter Deutsch…]]></description><link>https://www.dereklawless.ie/fallacies-of-distributed-computing-6-there-is-one-administrator/</link><guid isPermaLink="false">https://www.dereklawless.ie/fallacies-of-distributed-computing-6-there-is-one-administrator/</guid><pubDate>Thu, 25 Jun 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;a href=&quot;https://web.archive.org/web/20171107014323/http://blog.fogcreek.com/eight-fallacies-of-distributed-computing-tech-talk/&quot;&gt;The fallacies of distributed computing&lt;/a&gt; are a set of assertions describing false assumptions made about distributed systems.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/L._Peter_Deutsch&quot;&gt;L. Peter Deutsch&lt;/a&gt; drafted the first 7 fallacies in 1994, with the 8&lt;sup&gt;th&lt;/sup&gt; added by &lt;a href=&quot;https://en.wikipedia.org/wiki/James_Gosling&quot;&gt;James Gosling&lt;/a&gt; in 1997.&lt;/p&gt;
&lt;p&gt;The 8 fallacies are:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-1-the-network-is-reliable&quot;&gt;The network is reliable&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-2-latency-is-zero&quot;&gt;Latency is zero&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-3-bandwidth-is-infinite&quot;&gt;Bandwidth is infinite&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-4-the-network-is-secure&quot;&gt;The network is secure&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-5-topology-doesnt-change&quot;&gt;Topology doesn’t change&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-6-there-is-one-administrator&quot;&gt;There is one administrator&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-7-transport-cost-is-zero&quot;&gt;Transport cost is zero&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-8-the-network-is-homogeneous&quot;&gt;The network is homogeneous&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;6. There is one administrator&lt;/h2&gt;
&lt;h3&gt;The problem&lt;/h3&gt;
&lt;p&gt;If your system is self-contained and deployed into environments you fully control and manage there may indeed be only one administrator.&lt;/p&gt;
&lt;p&gt;However, it is more likely that any non-trivial system will depend on one or more in-house or third-party services for its operation and be deployed into environments you do not completely control or that differ from each other in any number of ways e.g. operating system and/or application framework versions, security patching policies, &lt;abbr title=&quot;User Access Control&quot;&gt;UAC&lt;/abbr&gt;, shared resources, firewall rules, etc.&lt;/p&gt;
&lt;p&gt;Multiple in-house teams may be involved to deploy and support the system, with each operating outside the processes governing that system’s development. Third-party services — their availability, compatibility, and development cadence — will typically exist outside your control.&lt;/p&gt;
&lt;h3&gt;Solutions&lt;/h3&gt;
&lt;h4&gt;Infrastructure as Code&lt;/h4&gt;
&lt;p&gt;Where possible, automate the provisioning and configuration of the environments into which deployments are made.  &lt;a href=&quot;https://en.wikipedia.org/wiki/Infrastructure_as_code&quot;&gt;Infrastructure as Code&lt;/a&gt; (or &lt;abbr title=&quot;Infrastructure as Code&quot;&gt;IaC&lt;/abbr&gt;) is a core element of DevOps, with infrastructure modelled in code (or &lt;abbr title=&quot;Domain Specific Language&quot;&gt;DSL&lt;/abbr&gt;-as-template form) — versus manually managed — and are governed by the same quality processes as application source code e.g. revisioned using source control, unit tested, etc.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Ideally, regard &lt;abbr&gt;IaC&lt;/abbr&gt; as a core competency — that is, embed DevOps capabilities in your development teams.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4&gt;Logging and monitoring&lt;/h4&gt;
&lt;p&gt;Diagnosing issues can be non-trivial at the best of times and particularly complex for distributed systems. To gain better visibility into the behaviour of a distributed system ensure that centralised logging, metrics, and tracing (the &lt;a href=&quot;https://www.oreilly.com/library/view/distributed-systems-observability/9781492033431/ch04.html&quot;&gt;Three Pillars of Observability&lt;/a&gt;) have been considered as key aspects of the system’s design.&lt;/p&gt;
&lt;h4&gt;Decoupling&lt;/h4&gt;
&lt;p&gt;Ensuring appopriate decoupling between system components allows for greater resiliency in the event of either planned (system upgrades) or unplanned (service failure) downtime.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Introducing queuing (with appropriate retry policies, exponential backoff, and &lt;abbr title=&quot;Dead Letter Queues&quot;&gt;DLQs&lt;/abbr&gt;) is one method of achieving decoupling.&lt;/p&gt;
&lt;/blockquote&gt;</content:encoded></item><item><title><![CDATA[Queues]]></title><description><![CDATA[A Queue is a linear data structure (i.e. its elements form a sequence) and can be modified by the addition of elements at one end of the…]]></description><link>https://www.dereklawless.ie/queues/</link><guid isPermaLink="false">https://www.dereklawless.ie/queues/</guid><pubDate>Wed, 03 Jun 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;A &lt;a href=&quot;https://en.wikipedia.org/wiki/Queue_(abstract_data_type)&quot;&gt;Queue&lt;/a&gt; is a linear data structure (i.e. its elements form a sequence) and can be modified by the addition of elements at one end of the sequence and removal from the other end. A queue is a &lt;abbr title=&quot;First In, First Out&quot;&gt;FIFO&lt;/abbr&gt; (First In, First Out) data structure.&lt;/p&gt;
&lt;p&gt;The queue data structure works in exactly the same way as its real life analogue — the first element in the queue is automatically at the front, with subsequent elements forming in line behind their precedent.&lt;/p&gt;
&lt;p&gt;Queues can be used to control access to shared system resources e.g. a printer queue managing access to a printer on a first come, first served basis. Queues can also feature in any architecture involving asynchronicity e.g. purchasing event tickets online.&lt;/p&gt;
&lt;p&gt;Typically, a queue implementation will provide at least three operations — &lt;code class=&quot;language-text&quot;&gt;enqueue&lt;/code&gt;, &lt;code class=&quot;language-text&quot;&gt;dequeue&lt;/code&gt;, and &lt;code class=&quot;language-text&quot;&gt;peek&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Enqueuing and dequeuing can be visualised at follows:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;Queue enqueue and dequeue&quot; role=&quot;img&quot; src=&quot;/598dda08b8d182be57deb773e94026b6/queue.svg&quot;&gt;&lt;/p&gt;
&lt;h2&gt;Complexity&lt;/h2&gt;
&lt;p&gt;&lt;span role=&quot;img&quot; aria-label=&quot;bell&quot;&gt;🔔&lt;/span&gt; Complexity is considered in terms of worst case.&lt;/p&gt;
&lt;h3&gt;Time&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Insertion&lt;/th&gt;
&lt;th&gt;Removal&lt;/th&gt;
&lt;th&gt;Retrieval&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Θ(1)&lt;/td&gt;
&lt;td&gt;Θ(1)&lt;/td&gt;
&lt;td&gt;Θ(n)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3&gt;Space&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Notes&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Θ(n)&lt;/td&gt;
&lt;td&gt;The elements in the queue&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2&gt;An implementation&lt;/h2&gt;
&lt;p&gt;Here we’re using an array as a backing store for simplicity (although you can of course use a different approach such as a &lt;a href=&quot;/linked-lists-revisited/&quot;&gt;doubly linked list&lt;/a&gt; which can provide enqueing and dequeing in Θ(1) time).&lt;/p&gt;
&lt;p&gt;Define a &lt;code class=&quot;language-text&quot;&gt;Queue&amp;lt;T&gt;&lt;/code&gt; class with the following methods:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;dequeue&lt;/code&gt; - dequeues an element, removing it from the queue&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;enqueue&lt;/code&gt; - enqueues an element, adding it to the queue&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;isEmpty&lt;/code&gt; - determines whether the queue is empty&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;length&lt;/code&gt; - returns the number of elements in the queue&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;peek&lt;/code&gt; - returns the front element in the queue without dequeuing it&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;typescript&quot;&gt;&lt;pre class=&quot;language-typescript&quot;&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// TypeScript&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Queue&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;private&lt;/span&gt; elements&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

	&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;constructor&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;elements &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token builtin&quot;&gt;Array&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;dequeue&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;undefined&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;elements&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;length &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;elements&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;pop&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;undefined&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;enqueue&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;element&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;elements&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;unshift&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;element&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;isEmpty&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;boolean&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;elements&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;length &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;elements&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;length&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;peek&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;undefined&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;isEmpty&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;?&lt;/span&gt;
			&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;elements&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;elements&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;length &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt;
			&lt;span class=&quot;token keyword&quot;&gt;undefined&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/dereklawless/algorithms-and-data-structures-katas/tree/master/src/data-structures/queues&quot;&gt;Code on Github&lt;/a&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Stacks]]></title><description><![CDATA[A Stack is  a linear data structure (i.e. its elements form a sequence) where operations are performed at the ‘top’ of the stack. The order…]]></description><link>https://www.dereklawless.ie/stacks/</link><guid isPermaLink="false">https://www.dereklawless.ie/stacks/</guid><pubDate>Thu, 28 May 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;A &lt;a href=&quot;https://en.wikipedia.org/wiki/Stack_(abstract_data_type)&quot;&gt;Stack&lt;/a&gt; is  a linear data structure (i.e. its elements form a sequence) where operations are performed at the ‘top’ of the stack. The order may be &lt;abbr title=&quot;First In, First Out&quot;&gt;FIFO&lt;/abbr&gt; (First In, First Out) or more commonly &lt;abbr title=&quot;Last In, First Out&quot;&gt;LIFO&lt;/abbr&gt; (Last In, First Out).&lt;/p&gt;
&lt;p&gt;An analogue in real life is a stack of plates — with a FIFO approach, you take a plate from the bottom of the pile whereas with a LIFO approach you take a plate from the top.&lt;/p&gt;
&lt;p&gt;The stack data structure has a multitude of uses, an obvious one is your browser history (a &lt;abbr&gt;LIFO&lt;/abbr&gt; stack). Typically, a stack implementation will provide at least three operations — &lt;code class=&quot;language-text&quot;&gt;push&lt;/code&gt;, &lt;code class=&quot;language-text&quot;&gt;pop&lt;/code&gt;, and &lt;code class=&quot;language-text&quot;&gt;peek&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Pushing onto the stack can be visualised at follows:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;Stack push&quot; role=&quot;img&quot; src=&quot;/525aab937846f6f972f2ea64f03cb429/stack-push.svg&quot;&gt;&lt;/p&gt;
&lt;p&gt;Popping from the stack can be visualised at follows:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;Stack pop&quot; role=&quot;img&quot; src=&quot;/f5e3309c7487c71d79d1fc14a0ad28fb/stack-pop.svg&quot;&gt;&lt;/p&gt;
&lt;h2&gt;Complexity&lt;/h2&gt;
&lt;p&gt;&lt;span role=&quot;img&quot; aria-label=&quot;bell&quot;&gt;🔔&lt;/span&gt; Complexity is considered in terms of worst case.&lt;/p&gt;
&lt;h3&gt;Time&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Insertion&lt;/th&gt;
&lt;th&gt;Removal&lt;/th&gt;
&lt;th&gt;Retrieval&lt;/th&gt;
&lt;th&gt;Notes&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Θ(1)&lt;/td&gt;
&lt;td&gt;Θ(1)&lt;/td&gt;
&lt;td&gt;Θ(1)&lt;/td&gt;
&lt;td&gt;Retrieval Θ(1) if popping, otherwise Θ(n) to locate&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3&gt;Space&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Notes&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Θ(n)&lt;/td&gt;
&lt;td&gt;The elements in the stack&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2&gt;A &lt;abbr&gt;LIFO&lt;/abbr&gt; implementation&lt;/h2&gt;
&lt;p&gt;Here we’re using an array as a backing store for simplicity (although you can of course use a different approach such as a &lt;a href=&quot;/linked-lists/&quot;&gt;linked list&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;Define a &lt;code class=&quot;language-text&quot;&gt;Stack&amp;lt;T&gt;&lt;/code&gt; class with the following methods:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;isEmpty&lt;/code&gt; - determines whether the stack has elements&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;length&lt;/code&gt; - returns the number of elements on the stack&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;peek&lt;/code&gt; - returns the top element from the stack without popping it&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;pop&lt;/code&gt; - pops from the stack&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;push&lt;/code&gt; - pushes onto the stack&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;typescript&quot;&gt;&lt;pre class=&quot;language-typescript&quot;&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// TypeScript&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Stack&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;private&lt;/span&gt; elements&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

	&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;constructor&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;elements &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token builtin&quot;&gt;Array&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;isEmpty&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;boolean&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;elements&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;length &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;elements&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;length&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;peek&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;elements&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;elements&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;length &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;pop&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;elements&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;length &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;elements&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;pop&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;item&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;elements&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;item&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/dereklawless/algorithms-and-data-structures-katas/tree/master/src/data-structures/stacks&quot;&gt;Code on Github&lt;/a&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Linked Lists, revisited]]></title><description><![CDATA[In a previous post I discussed the linked list data structure, how linked lists differ from arrays, and provided a sample implementation of…]]></description><link>https://www.dereklawless.ie/linked-lists-revisited/</link><guid isPermaLink="false">https://www.dereklawless.ie/linked-lists-revisited/</guid><pubDate>Tue, 26 May 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;In a &lt;a href=&quot;/linked-lists/&quot;&gt;previous post&lt;/a&gt; I discussed the linked list data structure, how linked lists differ from arrays, and provided a sample implementation of singly linked list.&lt;/p&gt;
&lt;p&gt;Recall that a singly linked list allows nodes to be traversed in one direction:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;Singly linked list&quot; role=&quot;img&quot; src=&quot;/53f2077ebb233942d83d4f19b4805075/singly-linked-list.svg&quot;&gt;&lt;/p&gt;
&lt;p&gt;What if we want to be able to traverse the list in either direction? Presented with that requirement we can use a &lt;strong&gt;doubly linked list&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Doubly_linked_list&quot;&gt;Doubly linked lists&lt;/a&gt; are a variant of linked lists that enable node traversal in either direction. While they do use more memory than singly linked listed (two pointers per node vs. one), they allow for easier node insertion and removal.&lt;/p&gt;
&lt;p&gt;A doubly linked list can be visualised at follows:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;Doubly linked list&quot; role=&quot;img&quot; src=&quot;/69953f9e0a2917802bcd72f6842a0038/doubly-linked-list.svg&quot;&gt;&lt;/p&gt;
&lt;h2&gt;An implementation of a doubly linked list&lt;/h2&gt;
&lt;p&gt;As before, define a class to encapsulate a node. Here, our &lt;code class=&quot;language-text&quot;&gt;LinkedListNode&lt;/code&gt; can hold a value of type &lt;code class=&quot;language-text&quot;&gt;T&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;typescript&quot;&gt;&lt;pre class=&quot;language-typescript&quot;&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;LinkedListNode&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; next&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; LinkedListNode&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; previous&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; LinkedListNode&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

	&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;constructor&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;readonly&lt;/span&gt; value&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; LinkedListNode&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Note the addition of a &lt;code class=&quot;language-text&quot;&gt;previous&lt;/code&gt; property — this will be used to link a node to the previous node in the list (or be assigned &lt;code class=&quot;language-text&quot;&gt;null&lt;/code&gt; if the current node is the ‘head’).&lt;/p&gt;
&lt;p&gt;The &lt;code class=&quot;language-text&quot;&gt;LinkedList&amp;lt;T&gt;&lt;/code&gt; class specification remains the same:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;add&lt;/code&gt; - adds a node to the list&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;addFirst&lt;/code&gt; - adds a node to the beginning of the list&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;addLast&lt;/code&gt; - adds a node to the end of the list&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;interator&lt;/code&gt; - interates the list (implemented here as a JavaScript iterator for extra interview points)&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;removeAt&lt;/code&gt; - removes the node at the specified index&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;typescript&quot;&gt;&lt;pre class=&quot;language-typescript&quot;&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// TypeScript&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; LinkedListNode &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;./linked-list-node&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;DoublyLinkedList&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; head&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; LinkedListNode&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; tail&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; LinkedListNode&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

	&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;constructor&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;value&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addLast&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;value&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;addFirst&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;value&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; node &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;LinkedListNode&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;value&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

		&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; originalHeadNode &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;head&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;head &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; node&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

		&lt;span class=&quot;token comment&quot;&gt;// Link the nodes.&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;head&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;next &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; originalHeadNode&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		originalHeadNode&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;previous &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;head&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

		&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;tail&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;token comment&quot;&gt;// There is one node in the list, set the tail node to the head.&lt;/span&gt;
			&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;tail &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;head&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;addLast&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;value&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; node &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;LinkedListNode&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;value&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

		&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;head&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;head &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; node&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;tail&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;token comment&quot;&gt;// Link the nodes.&lt;/span&gt;
			&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;tail&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;next &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; node&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
			node&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;previous &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;tail&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
		&lt;span class=&quot;token comment&quot;&gt;// Set the new tail.&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;tail &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; node&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;iterator&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; node &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;head&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;node&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;token keyword&quot;&gt;yield&lt;/span&gt; node&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;value&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
			node &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; node&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;next&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;removeAt&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;index&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; node &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;head&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; i &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

		&lt;span class=&quot;token keyword&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;node &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; i&lt;span class=&quot;token operator&quot;&gt;++&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; index&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
			node &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; node&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;next&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

		&lt;span class=&quot;token comment&quot;&gt;// Bounds checking.&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;index &lt;span class=&quot;token operator&quot;&gt;&gt;=&lt;/span&gt; i&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

		&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;node&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;previous&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;head &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; node&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;next&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
			node&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;previous&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;next &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; node&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;next&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
			node&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;next&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;previous &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; node&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;previous&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;next&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; DoublyLinkedList&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/dereklawless/algorithms-and-data-structures-katas/tree/master/src/data-structures/linked-lists&quot;&gt;Code on Github&lt;/a&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Fallacies of Distributed Computing: 5. Topology doesn't change]]></title><description><![CDATA[The fallacies of distributed computing are a set of assertions describing false assumptions made about distributed systems. L. Peter Deutsch…]]></description><link>https://www.dereklawless.ie/fallacies-of-distributed-computing-5-topology-doesnt-change/</link><guid isPermaLink="false">https://www.dereklawless.ie/fallacies-of-distributed-computing-5-topology-doesnt-change/</guid><pubDate>Mon, 25 May 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;a href=&quot;https://web.archive.org/web/20171107014323/http://blog.fogcreek.com/eight-fallacies-of-distributed-computing-tech-talk/&quot;&gt;The fallacies of distributed computing&lt;/a&gt; are a set of assertions describing false assumptions made about distributed systems.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/L._Peter_Deutsch&quot;&gt;L. Peter Deutsch&lt;/a&gt; drafted the first 7 fallacies in 1994, with the 8&lt;sup&gt;th&lt;/sup&gt; added by &lt;a href=&quot;https://en.wikipedia.org/wiki/James_Gosling&quot;&gt;James Gosling&lt;/a&gt; in 1997.&lt;/p&gt;
&lt;p&gt;The 8 fallacies are:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-1-the-network-is-reliable&quot;&gt;The network is reliable&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-2-latency-is-zero&quot;&gt;Latency is zero&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-3-bandwidth-is-infinite&quot;&gt;Bandwidth is infinite&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-4-the-network-is-secure&quot;&gt;The network is secure&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-5-topology-doesnt-change&quot;&gt;Topology doesn’t change&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-6-there-is-one-administrator&quot;&gt;There is one administrator&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-7-transport-cost-is-zero&quot;&gt;Transport cost is zero&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-8-the-network-is-homogeneous&quot;&gt;The network is homogeneous&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;5. Topology doesn’t change&lt;/h2&gt;
&lt;h3&gt;The problem&lt;/h3&gt;
&lt;p&gt;Network topology is volatile:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Environments may have differing network requirements — from quickly spun up development environments through to production environments supporting high availability, resiliency, and redundancy&lt;/li&gt;
&lt;li&gt;Firewall rules are likely to change in response to security concerns or application requirements&lt;/li&gt;
&lt;li&gt;Services may be introduced (e.g. federated authentication) or deprecated, changing network topology&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The topology of the network is typically outside your control. Servers may be added or retired, network services may be upgraded or deprecated, planned and unplanned outages may occur.&lt;/p&gt;
&lt;p&gt;In cloud computing scenarios — where elasticity is typically a key motivation for adoption — network topology will mutate in response to load and utilisation.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Network topology changes constantly.&lt;/strong&gt;&lt;/p&gt;
&lt;h3&gt;Solutions&lt;/h3&gt;
&lt;p&gt;Given that network toplogy is indeed volatile, there are two broad approaches that can be taken to buffer against topology changes.&lt;/p&gt;
&lt;h4&gt;Abstract network specifics&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Avoid referencing IP addresses directly, instead using &lt;abbr title=&quot;Domain Name System&quot;&gt;DNS&lt;/abbr&gt; hostnames to reference resources&lt;/li&gt;
&lt;li&gt;Consider using a &lt;a href=&quot;https://microservices.io/patterns/server-side-discovery.html&quot;&gt;service discovery pattern&lt;/a&gt; for Microservice architectures&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;Design for failure&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Design your architecture to avoid irreplaceability, assume any server may fail&lt;/li&gt;
&lt;li&gt;Introduce &lt;a href=&quot;https://en.wikipedia.org/wiki/Chaos_engineering&quot;&gt;chaos engineering&lt;/a&gt; and test for system behaviour under infrastructure, network, and application failures&lt;/li&gt;
&lt;/ul&gt;</content:encoded></item><item><title><![CDATA[Fallacies of Distributed Computing: 4. The network is secure]]></title><description><![CDATA[The fallacies of distributed computing are a set of assertions describing false assumptions made about distributed systems. L. Peter Deutsch…]]></description><link>https://www.dereklawless.ie/fallacies-of-distributed-computing-4-the-network-is-secure/</link><guid isPermaLink="false">https://www.dereklawless.ie/fallacies-of-distributed-computing-4-the-network-is-secure/</guid><pubDate>Tue, 19 May 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;a href=&quot;https://web.archive.org/web/20171107014323/http://blog.fogcreek.com/eight-fallacies-of-distributed-computing-tech-talk/&quot;&gt;The fallacies of distributed computing&lt;/a&gt; are a set of assertions describing false assumptions made about distributed systems.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/L._Peter_Deutsch&quot;&gt;L. Peter Deutsch&lt;/a&gt; drafted the first 7 fallacies in 1994, with the 8&lt;sup&gt;th&lt;/sup&gt; added by &lt;a href=&quot;https://en.wikipedia.org/wiki/James_Gosling&quot;&gt;James Gosling&lt;/a&gt; in 1997.&lt;/p&gt;
&lt;p&gt;The 8 fallacies are:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-1-the-network-is-reliable&quot;&gt;The network is reliable&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-2-latency-is-zero&quot;&gt;Latency is zero&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-3-bandwidth-is-infinite&quot;&gt;Bandwidth is infinite&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-4-the-network-is-secure&quot;&gt;The network is secure&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-5-topology-doesnt-change&quot;&gt;Topology doesn’t change&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-6-there-is-one-administrator&quot;&gt;There is one administrator&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-7-transport-cost-is-zero&quot;&gt;Transport cost is zero&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-8-the-network-is-homogeneous&quot;&gt;The network is homogeneous&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;4. The network is secure&lt;/h2&gt;
&lt;h3&gt;The problem&lt;/h3&gt;
&lt;p&gt;Your ecommerce website is accessible over HTTPS only, you rest easy knowing that all communication between your customers and your website is securely encrypted.&lt;/p&gt;
&lt;p&gt;However, some of the scripts embedded in your website for gathering customer analytics are using HTTP. Also, that third party service you call privately from your own API to validate customer addresses works over HTTP because HTTPS was judged to be “too expensive” in a dim and distant past.&lt;/p&gt;
&lt;p&gt;In April 2014 the &lt;a href=&quot;https://heartbleed.com/&quot;&gt;Heartbleed&lt;/a&gt; vulnerability was made public. The SSL standard includes a heartbeat option, which allows one party communicating over an SSL connection to send a short message to the other party to check if they are available.&lt;/p&gt;
&lt;p&gt;Heartbleed was a buffer over-read exploit on OpenSSL servers - by sending malformed hearbeat requests that weren’t validated by OpenSSL using bounds-checking, attackers were able to trick OpenSSL into returning random bits of memory from the server -  even for failed connections. Because these bits of memory were often near the code authenticating users, it was possible to obtain authenticated user data just by pinging the server.&lt;/p&gt;
&lt;p&gt;A cursory browse of the &lt;a href=&quot;https://haveibeenpwned.com/&quot;&gt;have i been pwned?&lt;/a&gt; website reveals millions of user details that have been exposed by attackers exploiting vulnerabilities like Heartbleed, poorly configured application stacks, unsecured databases, and so on.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The network is not secure.&lt;/strong&gt;&lt;/p&gt;
&lt;h3&gt;Solutions&lt;/h3&gt;
&lt;p&gt;Security should be built into the DNA of a system, not bolted onto it. As a quality attribute, it should be considered at the network, infrastructure, and application layers.&lt;/p&gt;
&lt;p&gt;Data produced and consumed by the system should be identified and classified according to its nature (e.g. &lt;a href=&quot;https://en.wikipedia.org/wiki/Personal_data&quot;&gt;PII&lt;/a&gt;) and associated risk of exposure.&lt;/p&gt;
&lt;p&gt;The Open Web Application Security Project (OWASP) maintain a &lt;a href=&quot;https://owasp.org/www-project-top-ten/&quot;&gt;top ten list&lt;/a&gt; of web application security risks. These can be considered as part of a broader &lt;a href=&quot;https://owasp.org/www-community/Application_Threat_Modeling&quot;&gt;threat modeling practice&lt;/a&gt; and (in some cases) evaluated on an automated basis.&lt;/p&gt;
&lt;p&gt;Ultimately, the only truly secure system is one which cannot be observed or interacted with in any way by human or other means. As such, ensuring the security of a system based on identified risks and their probability while still meeting business goals in a timely fashion is frequently a non-trivial exercise.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Linked Lists]]></title><description><![CDATA[Linked lists. The interview topic every software developer will be quizzed on at some point in their career. Historically, this was perhaps…]]></description><link>https://www.dereklawless.ie/linked-lists/</link><guid isPermaLink="false">https://www.dereklawless.ie/linked-lists/</guid><pubDate>Tue, 12 May 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Linked_list&quot;&gt;Linked lists&lt;/a&gt;. The interview topic every software developer will be quizzed on at some point in their career.&lt;/p&gt;
&lt;p&gt;Historically, this was perhaps because linked lists conveyed knowledge of pointers and memory allocation and usage in languages like C on the part of the interviewee. Available memory was also at a premium on the constrained systems of the past and efficient use of resources was not only desirable, but frequently critical.&lt;/p&gt;
&lt;p&gt;While many of us work with higher-level languages such as Java and C# (managed runtimes) or JavaScript (intepreted), knowledge of data structures for efficiently storing and retrieving data in memory is still entirely useful to possess.&lt;/p&gt;
&lt;h2&gt;What about arrays?&lt;/h2&gt;
&lt;p&gt;Consider the main characteristics of arrays:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Allocated a contiguous block of memory&lt;/li&gt;
&lt;li&gt;Cannot be resized&lt;sup&gt;*&lt;/sup&gt;&lt;/li&gt;
&lt;li&gt;Accessing an array element is Θ(1)&lt;/li&gt;
&lt;li&gt;Insertion or removal of array elements is Θ(n)&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;
&lt;p&gt;Strings are perhaps the most common example of fixed size arrays in use (this is why strings are considered immutable).&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;* While many languages provide dynamic arrays, these are constructs that wrap arrays and allow resizing by allocating a new contiguous block of memory behind the scenes and copying the original array contents across.&lt;/p&gt;
&lt;h2&gt;Linked lists&lt;/h2&gt;
&lt;p&gt;Linked lists differ from arrays in that they can utilise non-contiguous blocks of memory, with each data element (or ‘node’) pointing to the next in the list. Characteristics include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Memory allocation can be non-contiguous&lt;/li&gt;
&lt;li&gt;Can be easily resized, there is no copy penalty&lt;/li&gt;
&lt;li&gt;Accessing a node is Θ(n)&lt;/li&gt;
&lt;li&gt;Insertion or removal of nodes is Θ(1)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;While accessing a node is Θ(n) as the list must be traversed, insertion and removal are Θ(1). Given it is frequently impossible to know how the ‘correct’ amount of memory to reserve for data in advance, linked lists offer greater efficiency in terms of memory (re)allocation.&lt;/p&gt;
&lt;p&gt;&lt;span role=&quot;img&quot; aria-label=&quot;bell&quot;&gt;🔔&lt;/span&gt; &lt;strong&gt;Remember, use the data structure that is more appropriate for your circumstance.&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;An implementation of a singly linked list&lt;/h2&gt;
&lt;p&gt;A singly linked list allows traversal of nodes in one direction, and can be visualised as follows:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;Singly linked list&quot; role=&quot;img&quot; src=&quot;/53f2077ebb233942d83d4f19b4805075/singly-linked-list.svg&quot;&gt;&lt;/p&gt;
&lt;p&gt;First, define a class to encapsulate a node. Here, our &lt;code class=&quot;language-text&quot;&gt;LinkedListNode&lt;/code&gt; can hold a value of type &lt;code class=&quot;language-text&quot;&gt;T&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;typescript&quot;&gt;&lt;pre class=&quot;language-typescript&quot;&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// TypeScript&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;LinkedListNode&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; next&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; LinkedListNode&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

	&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;constructor&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;readonly&lt;/span&gt; value&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; LinkedListNode&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The &lt;code class=&quot;language-text&quot;&gt;next&lt;/code&gt; property is the mechanism we can use to link one node to another.&lt;/p&gt;
&lt;p&gt;Next, define a &lt;code class=&quot;language-text&quot;&gt;LinkedList&amp;lt;T&gt;&lt;/code&gt; class with methods for manipulating and traversing the list:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;add&lt;/code&gt; - adds a node to the list&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;addFirst&lt;/code&gt; - adds a node to the beginning of the list&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;addLast&lt;/code&gt; - adds a node to the end of the list&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;interator&lt;/code&gt; - interates the list (implemented here as a JavaScript iterator for extra interview points)&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;removeAt&lt;/code&gt; - removes the node at the specified index&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;typescript&quot;&gt;&lt;pre class=&quot;language-typescript&quot;&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// TypeScript&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; LinkedListNode &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;./linked-list-node&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;SinglyLinkedList&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; head&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; LinkedListNode&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; tail&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; LinkedListNode&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

	&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;constructor&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;value&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addLast&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;value&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;addFirst&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;value&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; node &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;LinkedListNode&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;value&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

		&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; originalHeadNode &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;head&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;head &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; node&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

		&lt;span class=&quot;token comment&quot;&gt;// Insert the rest of the list behind the head.&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;head&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;next &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; originalHeadNode&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

		&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;tail&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;token comment&quot;&gt;// There is one node in the list, set the tail to the head.&lt;/span&gt;
			&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;tail &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;head&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;addLast&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;value&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; node &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;LinkedListNode&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;value&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

		&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;head&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;head &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; node&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;tail&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;tail&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;next &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; node&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
		&lt;span class=&quot;token comment&quot;&gt;// Set the new tail.&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;tail &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; node&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;iterator&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; node &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;head&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;node&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;token keyword&quot;&gt;yield&lt;/span&gt; node&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;value&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
			node &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; node&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;next&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;removeAt&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;index&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; previous&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; LinkedListNode&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; node &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;head&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; i &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

		&lt;span class=&quot;token keyword&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;node &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; i&lt;span class=&quot;token operator&quot;&gt;++&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; index&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
			previous &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; node&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
			node &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; node&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;next&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

		&lt;span class=&quot;token comment&quot;&gt;// Bounds checking.&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;index &lt;span class=&quot;token operator&quot;&gt;&gt;=&lt;/span&gt; i&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

		&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;previous&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;head &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; node&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;next&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
			previous&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;next &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; node&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;next&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; SinglyLinkedList&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/dereklawless/algorithms-and-data-structures-katas/tree/master/src/data-structures/linked-lists&quot;&gt;Code on Github&lt;/a&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Fallacies of Distributed Computing: 3. Bandwidth is infinite]]></title><description><![CDATA[The fallacies of distributed computing are a set of assertions describing false assumptions made about distributed systems. L. Peter Deutsch…]]></description><link>https://www.dereklawless.ie/fallacies-of-distributed-computing-3-bandwidth-is-infinite/</link><guid isPermaLink="false">https://www.dereklawless.ie/fallacies-of-distributed-computing-3-bandwidth-is-infinite/</guid><pubDate>Tue, 05 May 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;a href=&quot;https://web.archive.org/web/20171107014323/http://blog.fogcreek.com/eight-fallacies-of-distributed-computing-tech-talk/&quot;&gt;The fallacies of distributed computing&lt;/a&gt; are a set of assertions describing false assumptions made about distributed systems.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/L._Peter_Deutsch&quot;&gt;L. Peter Deutsch&lt;/a&gt; drafted the first 7 fallacies in 1994, with the 8&lt;sup&gt;th&lt;/sup&gt; added by &lt;a href=&quot;https://en.wikipedia.org/wiki/James_Gosling&quot;&gt;James Gosling&lt;/a&gt; in 1997.&lt;/p&gt;
&lt;p&gt;The 8 fallacies are:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-1-the-network-is-reliable&quot;&gt;The network is reliable&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-2-latency-is-zero&quot;&gt;Latency is zero&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-3-bandwidth-is-infinite&quot;&gt;Bandwidth is infinite&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-4-the-network-is-secure&quot;&gt;The network is secure&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-5-topology-doesnt-change&quot;&gt;Topology doesn’t change&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-6-there-is-one-administrator&quot;&gt;There is one administrator&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-7-transport-cost-is-zero&quot;&gt;Transport cost is zero&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-8-the-network-is-homogeneous&quot;&gt;The network is homogeneous&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;3. Bandwidth is infinite&lt;/h2&gt;
&lt;h3&gt;The problem&lt;/h3&gt;
&lt;p&gt;Bandwidth is the capacity of a network to transmit data over a period of time. While &lt;a href=&quot;https://www.nngroup.com/articles/law-of-bandwidth/&quot;&gt;bandwidth has increased significantly&lt;/a&gt; over the past few decades, it is not infinite.&lt;/p&gt;
&lt;p&gt;Users may not be fortunate enough to enjoy reliable, high-bandwidth network connections or may experience highly-variable connectivity at times e.g. when using mobile networks. Further, as bandwidth-in-general has increased, so has the requirement to support large volumes of data such as audio and video streams.&lt;/p&gt;
&lt;h3&gt;Solutions&lt;/h3&gt;
&lt;p&gt;Although latency is ultimately a physics problem, bandwidth issues can be ameliorated by throwing more capacity at the problem. However, this can be a financially expensive approach with an upper-bound and may not be applicable to every usage scenario.&lt;/p&gt;
&lt;p&gt;In terms of system design, architectural approaches such as &lt;a href=&quot;https://docs.microsoft.com/en-us/azure/architecture/patterns/cqrs&quot;&gt;CQRS&lt;/a&gt; coupled with a clear understanding of user journeys can assist when optimising data payloads and in establishing the resultant bandwidth requirements.&lt;/p&gt;
&lt;p&gt;Recall that one solution to the &lt;a href=&quot;/fallacies-of-distributed-computing-2-latency-is-zero&quot;&gt;Latency is zero&lt;/a&gt; fallacy is to transmit more data upfront, thus reducing the number of network requests required. This introduces a &lt;strong&gt;potential tension&lt;/strong&gt; with solutions for fallacy 3 given that bandwidth reductions will require less data be sent over a network. Finding the correct balance between the two requires an appropriate level of demand modelling and knowledge of how the system will be used.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Fallacies of Distributed Computing: 2. Latency is zero]]></title><description><![CDATA[The fallacies of distributed computing are a set of assertions describing false assumptions made about distributed systems. L. Peter Deutsch…]]></description><link>https://www.dereklawless.ie/fallacies-of-distributed-computing-2-latency-is-zero/</link><guid isPermaLink="false">https://www.dereklawless.ie/fallacies-of-distributed-computing-2-latency-is-zero/</guid><pubDate>Wed, 22 Apr 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;a href=&quot;https://web.archive.org/web/20171107014323/http://blog.fogcreek.com/eight-fallacies-of-distributed-computing-tech-talk/&quot;&gt;The fallacies of distributed computing&lt;/a&gt; are a set of assertions describing false assumptions made about distributed systems.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/L._Peter_Deutsch&quot;&gt;L. Peter Deutsch&lt;/a&gt; drafted the first 7 fallacies in 1994, with the 8&lt;sup&gt;th&lt;/sup&gt; added by &lt;a href=&quot;https://en.wikipedia.org/wiki/James_Gosling&quot;&gt;James Gosling&lt;/a&gt; in 1997.&lt;/p&gt;
&lt;p&gt;The 8 fallacies are:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-1-the-network-is-reliable&quot;&gt;The network is reliable&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-2-latency-is-zero&quot;&gt;Latency is zero&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-3-bandwidth-is-infinite&quot;&gt;Bandwidth is infinite&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-4-the-network-is-secure&quot;&gt;The network is secure&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-5-topology-doesnt-change&quot;&gt;Topology doesn’t change&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-6-there-is-one-administrator&quot;&gt;There is one administrator&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-7-transport-cost-is-zero&quot;&gt;Transport cost is zero&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-8-the-network-is-homogeneous&quot;&gt;The network is homogeneous&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;2. Latency is zero&lt;/h2&gt;
&lt;h3&gt;The problem&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Latency_(engineering)&quot;&gt;Latency&lt;/a&gt; is defined as the time interval between a stimulus and the corresponding response. In network terms, it’s the amount of time required to move data from one location to another. &lt;strong&gt;Network traffic is not instant.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;At one time remote objects were seen as a desirable design objective, encapsulating local or remote implementation details and allowing for so-called network transparency. For example:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;csharp&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// C#&lt;/span&gt;
&lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt;&lt;/span&gt; user &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token constructor-invocation class-name&quot;&gt;User&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
user&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Password &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Password1&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The above operation may simply set the password on a &lt;code class=&quot;language-text&quot;&gt;User&lt;/code&gt; instance in memory or it may also initiate one or more remote calls to update a user password in a database, the implications are opaque.&lt;/p&gt;
&lt;p&gt;Thankfully, the use of remote objects is, by and large, frowned upon these days in favour of other techniques such as &lt;abbr title=&quot;Data Transfer Objects&quot;&gt;DTOs&lt;/abbr&gt; which provide greater transparency. (It is always worth formalising the segregation of local and remote calls through effective application of appropriate design patterns.)&lt;/p&gt;
&lt;p&gt;One technique frequently used with &lt;abbr title=&quot;Object Relational Mapping&quot;&gt;ORM&lt;/abbr&gt; technologies is deferred, or lazy, loading. With deferred loading, data is retrieved only when needed rather than prefetched.&lt;/p&gt;
&lt;p&gt;A typical example might entail retrieving the orders and order line items associated with a customer account:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;csharp&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// C#&lt;/span&gt;
&lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt;&lt;/span&gt; svc &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token constructor-invocation class-name&quot;&gt;OrderService&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt;&lt;/span&gt; orders &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; svc&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;GetOrdersForCustomer&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Returns an IQueryable&amp;lt;Order&gt;, deferred&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;foreach&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt;&lt;/span&gt; order &lt;span class=&quot;token keyword&quot;&gt;in&lt;/span&gt; orders&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;ToList&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Enumerated, call&lt;/span&gt;
	&lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt;&lt;/span&gt; items &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; order&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;GetItems&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Returns an IQueryable&amp;lt;OrderLineItem&gt;, deferred&lt;/span&gt;
	&lt;span class=&quot;token comment&quot;&gt;// ...&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Here, rather than fetching all the customer orders and associated line items in one call, the orders will be fetched when enumerated with the corresponding order line items also fetched on first use. This is a classic example of an unintended &lt;code class=&quot;language-text&quot;&gt;SELECT N + 1&lt;/code&gt; query, resulting in multiple remote calls to the database or service providing the data.&lt;/p&gt;
&lt;h3&gt;Solutions&lt;/h3&gt;
&lt;h4&gt;Reduce the number of remote calls&lt;/h4&gt;
&lt;p&gt;Given each remote call made will be several orders of magnitude slower than a local equivalent, you should design with the objective of optimising the number of remote calls. One way to achieve this by designing payloads to &lt;strong&gt;include all the data you might need&lt;/strong&gt; to support a particular use case, removing the likelihood (or need) of additional remote calls to fetch data at more granular levels.&lt;/p&gt;
&lt;h4&gt;Locate the data closer to the client&lt;/h4&gt;
&lt;p&gt;As latency is ultimately a physics problem, locating data closer to the geographic location of the client will facilitate reduced latency (all other network factors being equal). All public cloud infrastructure providers such as &lt;abbr title=&quot;Amazon Web Services&quot;&gt;AWS&lt;/abbr&gt;, Azure, or &lt;abbr title=&quot;Google Cloud Platform&quot;&gt;GCP&lt;/abbr&gt; support deployment into multiple availability zones.&lt;/p&gt;
&lt;h4&gt;Caching&lt;/h4&gt;
&lt;p&gt;Caching should also be implemented wherever possible to reduce unnecessary remote calls.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Fallacies of Distributed Computing: 1. The network is reliable]]></title><description><![CDATA[The fallacies of distributed computing are a set of assertions describing false assumptions made about distributed systems. L. Peter Deutsch…]]></description><link>https://www.dereklawless.ie/fallacies-of-distributed-computing-1-the-network-is-reliable/</link><guid isPermaLink="false">https://www.dereklawless.ie/fallacies-of-distributed-computing-1-the-network-is-reliable/</guid><pubDate>Mon, 20 Apr 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;a href=&quot;https://web.archive.org/web/20171107014323/http://blog.fogcreek.com/eight-fallacies-of-distributed-computing-tech-talk/&quot;&gt;The fallacies of distributed computing&lt;/a&gt; are a set of assertions describing false assumptions made about distributed systems.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/L._Peter_Deutsch&quot;&gt;L. Peter Deutsch&lt;/a&gt; drafted the first 7 fallacies in 1994, with the 8&lt;sup&gt;th&lt;/sup&gt; added by &lt;a href=&quot;https://en.wikipedia.org/wiki/James_Gosling&quot;&gt;James Gosling&lt;/a&gt; in 1997.&lt;/p&gt;
&lt;p&gt;The 8 fallacies are:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-1-the-network-is-reliable&quot;&gt;The network is reliable&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-2-latency-is-zero&quot;&gt;Latency is zero&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-3-bandwidth-is-infinite&quot;&gt;Bandwidth is infinite&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-4-the-network-is-secure&quot;&gt;The network is secure&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-5-topology-doesnt-change&quot;&gt;Topology doesn’t change&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-6-there-is-one-administrator&quot;&gt;There is one administrator&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-7-transport-cost-is-zero&quot;&gt;Transport cost is zero&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/fallacies-of-distributed-computing-8-the-network-is-homogeneous&quot;&gt;The network is homogeneous&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;1. The network is reliable&lt;/h2&gt;
&lt;h3&gt;The problem&lt;/h3&gt;
&lt;p&gt;Many systems are interconnected in nature, that is to say in normal execution they may make calls to other systems over one or more networks to satisfy functionality requirements.&lt;/p&gt;
&lt;p&gt;In any tiered architecture the underlying process and mechanism of communication will be (hopefully) abstracted away - for example taking a payment on behalf of a customer may be as straightforward as calling a method like so:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;csharp&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt;&lt;/span&gt; svc &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token constructor-invocation class-name&quot;&gt;PaymentService&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
svc&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;TakePayment&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;paymentRequest&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This level of abstraction is both useful and desirable, however it does tend to pre-dispose our view towards success. What happens when an underlying network call to a third-party payments processor fails with e.g an HTTP timeout exception?&lt;/p&gt;
&lt;p&gt;Depending on &lt;em&gt;when&lt;/em&gt; and &lt;em&gt;how&lt;/em&gt; such an error occurs, the request may be retryable without adverse side effect(s). However, for any retry to be deterministic in the affirmative the system must be indempotent. Without indempotence, retrying the above request &lt;em&gt;N times&lt;/em&gt; may result in the customer being charged &lt;em&gt;N times&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;A network may be unreliable for any number of reasons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A software issue&lt;/li&gt;
&lt;li&gt;A hardware issue&lt;/li&gt;
&lt;li&gt;A security issue&lt;/li&gt;
&lt;li&gt;An environmental issue&lt;/li&gt;
&lt;li&gt;A bad actor e.g. a &lt;em&gt;Denial of Service&lt;/em&gt; attack&lt;/li&gt;
&lt;li&gt;A combination of any or all of the above&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A system architected for resiliance and correctness must consider the above factors in its design.&lt;/p&gt;
&lt;h3&gt;A solution&lt;/h3&gt;
&lt;p&gt;To mitigate network unreliability, a &lt;strong&gt;Retry and Acknowledgement&lt;/strong&gt; design can be leveraged using a queuing system.&lt;/p&gt;
&lt;p&gt;Queuing systems typically implement a pattern known as &lt;em&gt;Store and Forward&lt;/em&gt; - they store the message locally and then forward it to the recipient(s). If forwarding fails, the queuing system will retry automatically. If failure persists past a specified number of attempts, the message will be moved to a &lt;a href=&quot;https://en.wikipedia.org/wiki/Dead_letter_queue&quot;&gt;Dead Letter Queue&lt;/a&gt;. The message is considered undelivered until the queue receives an acknowledgement of receipt from the recipient.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Implementing queuing requires moving from a synchronous request/response centric model to an ansychronous one. This is - typically - not a trivial excercise in a system of any complexity and may require re-evaluation of other aspects of your system, not least user experience.&lt;/p&gt;
&lt;/blockquote&gt;</content:encoded></item><item><title><![CDATA[Union Types in TypeScript]]></title><description><![CDATA[Consider the following contrived lunchbox example: In the example above,  accepts an , allowing a caller greater flexibility when adding…]]></description><link>https://www.dereklawless.ie/union-types-in-typescript/</link><guid isPermaLink="false">https://www.dereklawless.ie/union-types-in-typescript/</guid><pubDate>Tue, 17 Mar 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Consider the following contrived lunchbox example:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;typescript&quot;&gt;&lt;pre class=&quot;language-typescript&quot;&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Apple&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token function&quot;&gt;eat&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token builtin&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;Eating an apple.&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Sandwich&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token function&quot;&gt;eat&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token builtin&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;Eating a sandwich.&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;ChocolateBar&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token function&quot;&gt;eat&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token builtin&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;Eating a chocolate bar.&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; lunchbox&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; addToLunchbox &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;item&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	lunchbox&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;item&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; getFromLunchbox &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;any&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; lunchbox&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;pop&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Treat the lunchbox as a stack for simplicity&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In the example above, &lt;code class=&quot;language-text&quot;&gt;addToLunchbox()&lt;/code&gt; accepts an &lt;code class=&quot;language-text&quot;&gt;item: any&lt;/code&gt;, allowing a caller greater flexibility when adding items to the lunchbox:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;typescript&quot;&gt;&lt;pre class=&quot;language-typescript&quot;&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;span class=&quot;token function&quot;&gt;addToLunchbox&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Apple&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token function&quot;&gt;getFromLunchbox&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;eat&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// &quot;Eating an apple.&quot;&lt;/span&gt;

&lt;span class=&quot;token function&quot;&gt;addToLunchbox&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Sandwich&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token function&quot;&gt;getFromLunchbox&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;eat&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// &quot;Eating a sandwich.&quot;&lt;/span&gt;

&lt;span class=&quot;token function&quot;&gt;addToLunchbox&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;ChocolateBar&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token function&quot;&gt;getFromLunchbox&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;eat&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// &quot;Eating a chocolate bar.&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;However, the loose typing also allows for unintended use:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;typescript&quot;&gt;&lt;pre class=&quot;language-typescript&quot;&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Brick&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token function&quot;&gt;addToLunchbox&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Brick&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token function&quot;&gt;getFromLunchbox&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;eat&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Error!&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You can of course tighten up contracts by introducing a base class, say, &lt;code class=&quot;language-text&quot;&gt;Food&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;typescript&quot;&gt;&lt;pre class=&quot;language-typescript&quot;&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;abstract&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Food&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;abstract&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;eat&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;void&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Apple&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Food&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; addToLunchbox &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;food&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Food&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; getFromLunchbox &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Food &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;As long as &lt;code class=&quot;language-text&quot;&gt;Brick&lt;/code&gt; doesn’t extend &lt;code class=&quot;language-text&quot;&gt;Food&lt;/code&gt; the problem appears to be solved. However, there will be cases where the strategy breaks down e.g. we want to allow liquid to be added:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;typescript&quot;&gt;&lt;pre class=&quot;language-typescript&quot;&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Water&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Food&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Really?&lt;/span&gt;
	&lt;span class=&quot;token function&quot;&gt;drink&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token builtin&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;Drinking water.&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;While it’s obviously incorrect for &lt;code class=&quot;language-text&quot;&gt;Water&lt;/code&gt; to extend &lt;code class=&quot;language-text&quot;&gt;Food&lt;/code&gt;, the temptation is real in order to quickly dig yourself out of a hole vs. having to modify the existing function contracts. Alternatively, you may consider replacing &lt;code class=&quot;language-text&quot;&gt;Food&lt;/code&gt; with a more generic base class providing both &lt;code class=&quot;language-text&quot;&gt;eat()&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;drink()&lt;/code&gt; methods.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Both solutions are poor in terms of program design, understandability, testability, and numerous other quality metrics.&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;A better way to solve this problem is to use &lt;strong&gt;union types&lt;/strong&gt;. A union type describes a value that can be one of several types.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Let’s modify both &lt;code class=&quot;language-text&quot;&gt;addToLunchbox()&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;getFromLunchbox()&lt;/code&gt; to accept either &lt;code class=&quot;language-text&quot;&gt;Food&lt;/code&gt; or &lt;code class=&quot;language-text&quot;&gt;Water&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;typescript&quot;&gt;&lt;pre class=&quot;language-typescript&quot;&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; addToLunchbox &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;item&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Food &lt;span class=&quot;token operator&quot;&gt;|&lt;/span&gt; Water&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	lunchbox&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;item&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;getFromLunchbox&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Food &lt;span class=&quot;token operator&quot;&gt;|&lt;/span&gt; Water &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; lunchbox&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;pop&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token function&quot;&gt;addToLunchbox&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;ChocolateBar&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token function&quot;&gt;addToLunchbox&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Water&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token function&quot;&gt;addToLunchbox&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Brick&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Error!&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;With union types you can specify two or more types that can be accepted as arguments to, or returned from, a method. Note that it is still the responsibility of the caller to interpret the returned value correctly.&lt;/p&gt;
&lt;h2&gt;Errors&lt;/h2&gt;
&lt;p&gt;You may be considering including error types when specifying return types e.g.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;typescript&quot;&gt;&lt;pre class=&quot;language-typescript&quot;&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;EmptyLunchboxError&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Error&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; getFromLunchbox &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Food &lt;span class=&quot;token operator&quot;&gt;|&lt;/span&gt; Water &lt;span class=&quot;token operator&quot;&gt;|&lt;/span&gt; EmptyLunchboxError &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You should avoid doing this, particularly when &lt;em&gt;throwing an error&lt;/em&gt; - throwing represents an exceptional state in your program execution outside of normal program flow.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Enums in TypeScript]]></title><description><![CDATA[Enumerations are user-defined types consisting of named values (members) that behave as constants. They’re useful when you want to define a…]]></description><link>https://www.dereklawless.ie/enums-in-typescript/</link><guid isPermaLink="false">https://www.dereklawless.ie/enums-in-typescript/</guid><pubDate>Fri, 28 Feb 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Enumerated_type&quot;&gt;Enumerations&lt;/a&gt; are user-defined types consisting of named values (members) that behave as constants. They’re useful when you want to define a type consisting of a restricted set of values, for example the colours of the rainbow.&lt;/p&gt;
&lt;h2&gt;Numeric enums&lt;/h2&gt;
&lt;p&gt;By default, numeric enums start at zero and increment by 1 for each subsequent member:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;typescript&quot;&gt;&lt;pre class=&quot;language-typescript&quot;&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;enum&lt;/span&gt; Volume &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	Low&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
	Medium&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
	High
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token builtin&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;Volume&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Low&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;    &lt;span class=&quot;token comment&quot;&gt;// 0&lt;/span&gt;
&lt;span class=&quot;token builtin&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;Volume&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Medium&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// 1&lt;/span&gt;
&lt;span class=&quot;token builtin&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;Volume&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;High&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;   &lt;span class=&quot;token comment&quot;&gt;// 2&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You can change this if you wish and either start with a non-zero value or explictly assign values to members:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;typescript&quot;&gt;&lt;pre class=&quot;language-typescript&quot;&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;enum&lt;/span&gt; StoryPoints &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	Zero &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
	One &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
	Two &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
	Three &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
	Five &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
	Eight &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
	Thirteen &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;13&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token builtin&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;StoryPoints&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Eight&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// 8&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Numeric enums can be &lt;a href=&quot;https://www.typescriptlang.org/docs/handbook/enums.html#reverse-mappings&quot;&gt;reverse mapped&lt;/a&gt;, in other words you can use the numeric value to retrieve the associated member:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;typescript&quot;&gt;&lt;pre class=&quot;language-typescript&quot;&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;span class=&quot;token builtin&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;StoryPoints&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Three&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;hr&gt;
&lt;h2&gt;String enums&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-4.html#string-enums&quot;&gt;TypeScript version 2.4&lt;/a&gt; introduced support for string initialisers in enums. This can be useful for defining a restricted set of string values:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;typescript&quot;&gt;&lt;pre class=&quot;language-typescript&quot;&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;enum&lt;/span&gt; MimeTypes &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token constant&quot;&gt;CSV&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;text/csv&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
	&lt;span class=&quot;token constant&quot;&gt;HTML&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;text/html&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
	&lt;span class=&quot;token constant&quot;&gt;JSON&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;application/json&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
	&lt;span class=&quot;token constant&quot;&gt;XML&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;application/xml&quot;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token builtin&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;MimeTypes&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// application/json&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;As the release notes state, you cannot reverse map a string-based enum:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;typescript&quot;&gt;&lt;pre class=&quot;language-typescript&quot;&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;span class=&quot;token builtin&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;MimeTypes&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;application/xml&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Error!&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;hr&gt;
&lt;h2&gt;Bitwise enums&lt;/h2&gt;
&lt;p&gt;Bitwise enums (also known as Flag enums) are useful when you want flexbility in combining enum members to represent new values. One such use might be where you want to elevate or remove file access permissions:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;typescript&quot;&gt;&lt;pre class=&quot;language-typescript&quot;&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;enum&lt;/span&gt; FileAccess &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	None &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
	Read &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;  &lt;span class=&quot;token comment&quot;&gt;// Can also be expressed as Read = 1&lt;/span&gt;
	Write &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Can also be expressed as Write = 2&lt;/span&gt;
	Delete &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Can also be expressed as Delete = 4&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;While the &lt;code class=&quot;language-text&quot;&gt;FileAccess&lt;/code&gt; enum could be defined with explicit members for every combination, as that number increases the approach quickly becomes impractical.&lt;/p&gt;
&lt;p&gt;As you may have noticed from the above example, for bitwise enums use values that are powers of 2 (2&lt;sup&gt;^&lt;/sup&gt;0, 2&lt;sup&gt;^&lt;/sup&gt;1, 2&lt;sup&gt;^&lt;/sup&gt;2, 2&lt;sup&gt;^&lt;/sup&gt;3, and so on).&lt;/p&gt;
&lt;p&gt;And in action:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;typescript&quot;&gt;&lt;pre class=&quot;language-typescript&quot;&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; access &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; FileAccess&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;None&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token builtin&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;access&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// 0&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// Elevate to Read access&lt;/span&gt;
access &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; FileAccess&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Read&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token builtin&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;access&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// 1&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// Elevate to Read and Write access&lt;/span&gt;
access &lt;span class=&quot;token operator&quot;&gt;|=&lt;/span&gt; FileAccess&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Write&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token builtin&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;access&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// 3&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// Elevate to Read, Write, and Delete access&lt;/span&gt;
access &lt;span class=&quot;token operator&quot;&gt;|=&lt;/span&gt; FileAccess&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Delete&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token builtin&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;access&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// 7&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// Remove Delete access&lt;/span&gt;
access &lt;span class=&quot;token operator&quot;&gt;&amp;amp;=&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;~&lt;/span&gt;FileAccess&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Delete&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token builtin&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;access&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// 3&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// Evaluating incorrectly&lt;/span&gt;
&lt;span class=&quot;token builtin&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;access &lt;span class=&quot;token operator&quot;&gt;===&lt;/span&gt; FileAccess&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Read&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// false&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// Evaluating correctly&lt;/span&gt;
&lt;span class=&quot;token builtin&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;FileAccess&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Read &lt;span class=&quot;token operator&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;access &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&lt;/span&gt; FileAccess&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Read&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// true&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Note the &lt;code class=&quot;language-text&quot;&gt;|=&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;&amp;amp;= ~&lt;/code&gt; operators. The &lt;code class=&quot;language-text&quot;&gt;|=&lt;/code&gt; operator allows to perserve any existing assigned value(s) - using &lt;code class=&quot;language-text&quot;&gt;=&lt;/code&gt; alone will overwrite. The &lt;code class=&quot;language-text&quot;&gt;&amp;amp;= ~&lt;/code&gt; operator allows you to remove one or more assigned values.&lt;/p&gt;
&lt;hr&gt;
&lt;h2&gt;&lt;code class=&quot;language-text&quot;&gt;const&lt;/code&gt; enums&lt;/h2&gt;
&lt;p&gt;If you wish to avoid the overhead of the generated code and additional indirection, you can use a &lt;code class=&quot;language-text&quot;&gt;const&lt;/code&gt; enum:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;typescript&quot;&gt;&lt;pre class=&quot;language-typescript&quot;&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;enum&lt;/span&gt; Rainbow &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Note the const modifier&lt;/span&gt;
	&lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;With a &lt;code class=&quot;language-text&quot;&gt;const&lt;/code&gt; enum, &lt;strong&gt;the values are inlined with each use&lt;/strong&gt;. Note that only constant enum expressions can be used, you cannot use computed values as in this contrived example:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;typescript&quot;&gt;&lt;pre class=&quot;language-typescript&quot;&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;enum&lt;/span&gt; StoryPoints &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	Zero &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
	One &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
	Two &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
	Three &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; One &lt;span class=&quot;token operator&quot;&gt;|&lt;/span&gt; Two&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
	Five &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;.....&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Error!&lt;/span&gt;
	Eight &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
	Thirteen &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;13&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</content:encoded></item><item><title><![CDATA[Tales from the computing frontier]]></title><description><![CDATA[I’ve always enjoyed reading about computing history, particularly tales of computing pioneers and I continue to regard Englebart, Kay…]]></description><link>https://www.dereklawless.ie/tales-from-the-computer-frontier/</link><guid isPermaLink="false">https://www.dereklawless.ie/tales-from-the-computer-frontier/</guid><pubDate>Sun, 23 Feb 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;I’ve always enjoyed reading about computing history, particularly tales of computing pioneers and I continue to regard Englebart, Kay, Shannon, Wozniak and others with awe. The books below are some of my favourites and ones I eagerly recommend to friends and colleagues.&lt;/p&gt;
&lt;p&gt;(Links go to &lt;a href=&quot;https://www.kennys.ie/&quot;&gt;kennys.ie&lt;/a&gt; but are referral-free.)&lt;/p&gt;
&lt;h2&gt;&lt;a href=&quot;https://www.kennys.ie/shop/the-soul-of-a-new-machine&quot;&gt;The Soul of a New Machine&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 332px; &quot;
    &gt;
      &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 150.625%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAAeABQDASIAAhEBAxEB/8QAGAABAQEBAQAAAAAAAAAAAAAAAQADAgT/xAAYAQADAQEAAAAAAAAAAAAAAAABAgMABP/aAAwDAQACEAMQAAABRzF2Jhd475vJNPo//8QAGxAAAgIDAQAAAAAAAAAAAAAAAQIAERASIjH/2gAIAQEAAQUC2WMoEJa9bErBHNRvMf/EABgRAQEAAwAAAAAAAAAAAAAAAAARISIx/9oACAEDAQE/AeNVyr//xAAZEQADAQEBAAAAAAAAAAAAAAAAAQIREhP/2gAIAQIBAT8Blcmop4elH//EAB4QAAEEAgMBAAAAAAAAAAAAAAABAhEhEDESQWGB/9oACAEBAAY/AuMWVspI+knZtw24Eb7hBMf/xAAfEAEAAgICAgMAAAAAAAAAAAABABEhMUGBEFFhofH/2gAIAQEAAT8hqPe3DBI2uPSnwIOvgiXebXMv+stwwJvqBtOTaRTxPox34//aAAwDAQACAAMAAAAQDDpO/8QAHREAAwAABwAAAAAAAAAAAAAAAAERITFBcbHR8P/aAAgBAwEBPxBRqnkbeextK9qOcIf/xAAZEQADAAMAAAAAAAAAAAAAAAAAAREQMWH/2gAIAQIBAT8QVTmzgNhrF//EAB4QAQEAAgICAwAAAAAAAAAAAAERACExUYGRQdHw/9oACAEBAAE/EFRWxxPd5yQEakee8BArXQvrJKVYVm7O5gGCgvJMaa8R9MKGyLAyViSO4CORcQoTzilaj6a+MPD+046k6z//2Q==&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;img
        class=&quot;gatsby-resp-image-image&quot;
        alt=&quot;Soul of a New Machine book cover&quot;
        title=&quot;&quot;
        src=&quot;/static/60ebaa4e9c24d7da3e2c50c72874d3f7/71bac/soul-of-a-new-machine.jpg&quot;
        srcset=&quot;/static/60ebaa4e9c24d7da3e2c50c72874d3f7/0913d/soul-of-a-new-machine.jpg 160w,
/static/60ebaa4e9c24d7da3e2c50c72874d3f7/cb69c/soul-of-a-new-machine.jpg 320w,
/static/60ebaa4e9c24d7da3e2c50c72874d3f7/71bac/soul-of-a-new-machine.jpg 332w&quot;
        sizes=&quot;(max-width: 332px) 100vw, 332px&quot;
        style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
        loading=&quot;lazy&quot;
        decoding=&quot;async&quot;
      /&gt;
    &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;A Pulitzer prize winner, &lt;em&gt;The Soul of a New Machine&lt;/em&gt; tells the story of an engineering team at &lt;a href=&quot;https://en.wikipedia.org/wiki/Data_General&quot;&gt;Data General&lt;/a&gt; and their efforts to design a next-generation minicomputer (the &lt;a href=&quot;https://en.wikipedia.org/wiki/Data_General_Eclipse_MV/8000&quot;&gt;Eclipse MV/8000&lt;/a&gt;) against almost insurmountable odds. Led by the enigmatic Tom West, the team run a skunkworks project (codenamed ‘Eagle’) as a Plan B to keep pace with Digital Equipment Corporation’s offerings should the favoured Data General project (‘Fountainhead’) fail.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Soul of a New Machine&lt;/em&gt; is a thrilling read, expertly told. It conjures a perhaps-romanticised tale of an engineering team pouring their very being into a project, willing it to completion in a cauldron of invention and creation.&lt;/p&gt;
&lt;p&gt;I was a young, inexperienced software engineer when I first read &lt;em&gt;Soul of a New Machine&lt;/em&gt; and it had an enormous effect on me. It galvanised me to seek out others who also viewed software engineering as craft and to work on projects that amounted to more than their constituent bytes. Revisiting it now with wiser eyes, I can of course see the negative aspects of projects like Eagle more clearly.&lt;/p&gt;
&lt;hr&gt;
&lt;h2&gt;&lt;a href=&quot;https://www.kennys.ie/computing/hackers-heroes-of-the-computer-revolution-25th-anniversary-edition-levy-steven-9781449388393&quot;&gt;Hackers: Heroes of the Computer Revolution&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 332px; &quot;
    &gt;
      &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 154.375%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAAfABQDASIAAhEBAxEB/8QAGAAAAwEBAAAAAAAAAAAAAAAAAAECBAX/xAAVAQEBAAAAAAAAAAAAAAAAAAABAP/aAAwDAQACEAMQAAAB5c6nGAsm3FBIxf/EABwQAAMAAgMBAAAAAAAAAAAAAAABAgMQERIhMf/aAAgBAQABBQL0fIyc1pPNZb7WtNHzf//EABQRAQAAAAAAAAAAAAAAAAAAACD/2gAIAQMBAT8BH//EABQRAQAAAAAAAAAAAAAAAAAAACD/2gAIAQIBAT8BH//EABoQAAICAwAAAAAAAAAAAAAAAAARAeEQIEH/2gAIAQEABj8CorCYmTM93//EABoQAQADAQEBAAAAAAAAAAAAAAEAESExEFH/2gAIAQEAAT8hQHIoarYteygglVVRZB+y6nENc7EHSIg+ME8//9oADAMBAAIAAwAAABC3xvD/xAAUEQEAAAAAAAAAAAAAAAAAAAAg/9oACAEDAQE/EB//xAAUEQEAAAAAAAAAAAAAAAAAAAAg/9oACAECAQE/EB//xAAeEAEBAAIDAAMBAAAAAAAAAAABEQAhMUFhUXGBkf/aAAgBAQABPxAGMqCXkPGC5PwY6xLUCa0TBZAAhokl/MV8CAyCH88zkirHbilRPTBqF8ZAw+8SmPBvJt78cVe8/9k=&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;img
        class=&quot;gatsby-resp-image-image&quot;
        alt=&quot;Hackers book cover&quot;
        title=&quot;&quot;
        src=&quot;/static/471f7b4953e89696e1bb3a2405bf864d/71bac/hackers.jpg&quot;
        srcset=&quot;/static/471f7b4953e89696e1bb3a2405bf864d/0913d/hackers.jpg 160w,
/static/471f7b4953e89696e1bb3a2405bf864d/cb69c/hackers.jpg 320w,
/static/471f7b4953e89696e1bb3a2405bf864d/71bac/hackers.jpg 332w&quot;
        sizes=&quot;(max-width: 332px) 100vw, 332px&quot;
        style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
        loading=&quot;lazy&quot;
        decoding=&quot;async&quot;
      /&gt;
    &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Told in three parts, &lt;em&gt;Hackers&lt;/em&gt; chronicles hackerdom from the 1950s through to the early 1980s.&lt;/p&gt;
&lt;p&gt;As a child of 1980s personal computing and gaming the third part of the book, &lt;em&gt;Game Hackers&lt;/em&gt;, resonates most for me (although all parts are excellent).&lt;/p&gt;
&lt;p&gt;Ken and Roberta Williams found &lt;a href=&quot;https://en.wikipedia.org/wiki/Sierra_Entertainment&quot;&gt;Sierra On-Line&lt;/a&gt; and enjoy meteoric rise developing and publishing games for the &lt;a href=&quot;https://en.wikipedia.org/wiki/Apple_II&quot;&gt;Apple II&lt;/a&gt; and &lt;a href=&quot;https://en.wikipedia.org/wiki/Atari_8-bit_family&quot;&gt;Atari 8-bits&lt;/a&gt;, ultimately winning a legal battle with Atari over Pac-Man that leaves Williams with an uncertain victory. Game developer John Harris (&lt;a href=&quot;https://dadgum.com/halcyon/BOOK/HARRIS.HTM&quot;&gt;who considers his portrayal inaccurate&lt;/a&gt;) features prominently as the archetypal game hacker, weaving magic on his beloved Atari 800.&lt;/p&gt;
&lt;p&gt;If hardware engineers like Steve Wozniak or early game programmers like Harris approach rock star status in your eyes you’ll enjoy &lt;em&gt;Hackers&lt;/em&gt; greatly.&lt;/p&gt;
&lt;hr&gt;
&lt;h2&gt;&lt;a href=&quot;https://www.kennys.ie/history/the-americas/the-idea-factory&quot;&gt;The Idea Factory: Bell Labs and the Great Age of American Innovation&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 332px; &quot;
    &gt;
      &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 153.12500000000003%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAAfABQDASIAAhEBAxEB/8QAGQAAAgMBAAAAAAAAAAAAAAAAAAIBAwQF/8QAFgEBAQEAAAAAAAAAAAAAAAAAAAIB/9oADAMBAAIQAxAAAAHtw2ZOgBojpG2kFP/EABsQAAMAAgMAAAAAAAAAAAAAAAECEQAxEBIh/9oACAEBAAEFAja5gQ+MKuJo8Lo29Ti6/8QAFhEBAQEAAAAAAAAAAAAAAAAAARAR/9oACAEDAQE/AVyYT//EABYRAQEBAAAAAAAAAAAAAAAAAAEAEP/aAAgBAgEBPwHEYv/EABgQAAMBAQAAAAAAAAAAAAAAAAAQQSGR/9oACAEBAAY/AlqnVSqEX//EAB4QAAMAAgIDAQAAAAAAAAAAAAABESExUWFBgZHw/9oACAEBAAE/IWQPRLelRzeq7xDEJVmEnRnWb8Ol6XYj5+EUsqK3B2fmhGsp6P/aAAwDAQACAAMAAAAQmD5M/8QAFxEAAwEAAAAAAAAAAAAAAAAAAAERMf/aAAgBAwEBPxBoTqpTWSH/xAAXEQEBAQEAAAAAAAAAAAAAAAABACEx/9oACAECAQE/EBDso8kOQQ2//8QAHhABAAMAAgMBAQAAAAAAAAAAAQARITFBYXGRsfD/2gAIAQEAAT8QwF14IKMvb6nUTHBFvBHYHIC0RqhcsoSnt+xp0J4KDaDdCfCO9+yB0k32B+Q9Vj0LZpxhz+srRLfWif/Z&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;img
        class=&quot;gatsby-resp-image-image&quot;
        alt=&quot;The Idea Factory book cover&quot;
        title=&quot;&quot;
        src=&quot;/static/fc5a70ead3537259481c55c59f0b8980/71bac/the-idea-factory.jpg&quot;
        srcset=&quot;/static/fc5a70ead3537259481c55c59f0b8980/0913d/the-idea-factory.jpg 160w,
/static/fc5a70ead3537259481c55c59f0b8980/cb69c/the-idea-factory.jpg 320w,
/static/fc5a70ead3537259481c55c59f0b8980/71bac/the-idea-factory.jpg 332w&quot;
        sizes=&quot;(max-width: 332px) 100vw, 332px&quot;
        style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
        loading=&quot;lazy&quot;
        decoding=&quot;async&quot;
      /&gt;
    &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;The legacy of &lt;a href=&quot;https://en.wikipedia.org/wiki/Bell_Labs&quot;&gt;Bell Labs&lt;/a&gt; is staggering. The birthplace of research and technologies that shaped the 20&lt;sup&gt;th&lt;/sup&gt; century and continue to shape the 21&lt;sup&gt;st&lt;/sup&gt; - transatlantic communication, the transistor, the laser, the communications satellite, UNIX, the C programming language… its importance cannot be overstated.&lt;/p&gt;
&lt;p&gt;A comprehensive account of Bell Labs from its foundation through to its decline in the 1980s following the breakup of AT&amp;#x26;T, &lt;em&gt;The Idea Factory&lt;/em&gt; - while necessarily brief in places - superbly documents some of the extraordinary individuals who worked there and the contributions they made:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Claude_Shannon&quot;&gt;Claude Shannon&lt;/a&gt;, father of Information Theory&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/John_R._Pierce&quot;&gt;John R. Pierce&lt;/a&gt;, co-inventor of pulse code modulation and considered one of the fathers of communication satellites&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/William_Shockley&quot;&gt;William Shockley&lt;/a&gt;, co-inventor of the transistor (whose legacy has been tarnished by his repellent views on Eugenics)&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Shannon, Pierce, and Shockley were giants of their field, and &lt;em&gt;The Idea Factory&lt;/em&gt; explains why. That they worked collectively at the same research laboratory is mind blowing.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Docker spring cleaning]]></title><description><![CDATA[When using Docker you may find over time that disk space is being consumed rapidly by ophan images and/or volumes. These commands were…]]></description><link>https://www.dereklawless.ie/docker-spring-cleaning/</link><guid isPermaLink="false">https://www.dereklawless.ie/docker-spring-cleaning/</guid><pubDate>Fri, 21 Feb 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;When using Docker you may find over time that disk space is being consumed rapidly by ophan images and/or volumes.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;These commands were tested with Docker running on Ubuntu, your mileage with Docker on Windows or macOS may vary.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;To find out how much disk space Docker is consuming type the following command in your terminal:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token function&quot;&gt;docker&lt;/span&gt; system &lt;span class=&quot;token parameter variable&quot;&gt;-df&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This will give you an overview of what resources are being used.&lt;/p&gt;
&lt;p&gt;There are a number of ways to clean up unwanted Docker artifacts and reclaim disk space using your terminal, a few of which are outlined below.&lt;/p&gt;
&lt;h2&gt;Deleting exited containers&lt;/h2&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token function&quot;&gt;docker&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rm&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-v&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;&lt;span class=&quot;token variable&quot;&gt;$(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;docker&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;ps&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-a&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-q&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-f&lt;/span&gt; &lt;span class=&quot;token assign-left variable&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;exited&lt;span class=&quot;token variable&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;Removing unwanted ‘dangling’ images&lt;/h2&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token function&quot;&gt;docker&lt;/span&gt; rmi &lt;span class=&quot;token variable&quot;&gt;&lt;span class=&quot;token variable&quot;&gt;$(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;docker&lt;/span&gt; images &lt;span class=&quot;token parameter variable&quot;&gt;-f&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;dangling=true&quot;&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-q&lt;/span&gt;&lt;span class=&quot;token variable&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;Deleting unwanted volumes&lt;/h2&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token function&quot;&gt;docker&lt;/span&gt; volume &lt;span class=&quot;token function&quot;&gt;rm&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;&lt;span class=&quot;token variable&quot;&gt;$(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;docker&lt;/span&gt; volume &lt;span class=&quot;token function&quot;&gt;ls&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-qf&lt;/span&gt; &lt;span class=&quot;token assign-left variable&quot;&gt;dangling&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;true&lt;span class=&quot;token variable&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;Pruning&lt;/h2&gt;
&lt;p&gt;With Docker v1.25 or later you can accomplish the above with the &lt;a href=&quot;https://docs.docker.com/engine/reference/commandline/system_prune/&quot;&gt;prune&lt;/a&gt; command:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token function&quot;&gt;docker&lt;/span&gt; system prune&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;To remove all unused images (vs. just ‘dangling’ ones), include the &lt;code class=&quot;language-text&quot;&gt;-a&lt;/code&gt; switch:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token function&quot;&gt;docker&lt;/span&gt; system prune &lt;span class=&quot;token parameter variable&quot;&gt;-a&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;Automating spring cleaning&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/clockworksoul/docker-gc-cron&quot;&gt;docker-gc-cron&lt;/a&gt; is an excellent Docker container provided by Spotify that can be used to automatically clean up unused containers and images.&lt;/p&gt;
&lt;p&gt;You may want to consider modifying the default &lt;code class=&quot;language-text&quot;&gt;docker-compose.yml&lt;/code&gt; file provided with configuration values more appropriate to your needs e.g.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;# Set the grace period&lt;/span&gt;
- &lt;span class=&quot;token assign-left variable&quot;&gt;GRACE_PERIOD_SECONDS&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;43200&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;# 12 hours&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;# Commenting out will reset the log output to UTC&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;# - TZ=America/New_York&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</content:encoded></item><item><title><![CDATA[Partial Types in TypeScript]]></title><description><![CDATA[The  utility type (added in TypeScript 2.1) allows you to take an existing type and make all of its properties optional. This can help in…]]></description><link>https://www.dereklawless.ie/partial-types-in-typescript/</link><guid isPermaLink="false">https://www.dereklawless.ie/partial-types-in-typescript/</guid><pubDate>Wed, 05 Feb 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;The &lt;code class=&quot;language-text&quot;&gt;Partial&amp;lt;T&gt;&lt;/code&gt; utility type (added in &lt;a href=&quot;https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-1.html#mapped-types&quot;&gt;TypeScript 2.1&lt;/a&gt;) allows you to take an existing type and make all of its properties optional. This can help in situations where you want to have some flexibility without removing strictness across the board.&lt;/p&gt;
&lt;p&gt;Consider the following interface:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;typescript&quot;&gt;&lt;pre class=&quot;language-typescript&quot;&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;interface&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;ChocolateBar&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;readonly&lt;/span&gt; manufacturer&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;readonly&lt;/span&gt; name&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;readonly&lt;/span&gt; price&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Money&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;As specified, all properties of &lt;code class=&quot;language-text&quot;&gt;ChocolateBar&lt;/code&gt; are required for the interface contract to be satisfied. (Incidentally, don’t use the &lt;code class=&quot;language-text&quot;&gt;Number&lt;/code&gt; type for monetary values - &lt;a href=&quot;https://martinfowler.com/eaaCatalog/money.html&quot;&gt;introduce a type&lt;/a&gt;.)&lt;/p&gt;
&lt;p&gt;Inevitably, there will occasions where strictness like this can make life awkward. What if you want to be able to selectively update the values of a chocolate bar? Well, you might write something along the lines of:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;typescript&quot;&gt;&lt;pre class=&quot;language-typescript&quot;&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;interface&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;KeyValuePair&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;readonly&lt;/span&gt; key&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;readonly&lt;/span&gt; value&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;updateChocolateBar&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;bar&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; ChocolateBar&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; props&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; KeyValuePair&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; ChocolateBar &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	props&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;forEach&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; key&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; value &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; bar&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;key&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; value&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; bar&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;While this may be sufficient, each &lt;code class=&quot;language-text&quot;&gt;KeyValuePair&lt;/code&gt; is ambiguous e.g. &lt;code class=&quot;language-text&quot;&gt;{ &quot;paws&quot;: 4 }&lt;/code&gt; is perfectly valid. Ambiguous code is more difficult to reason about, test, and maintain.&lt;/p&gt;
&lt;p&gt;A better approach is to use a Partial type:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;typescript&quot;&gt;&lt;pre class=&quot;language-typescript&quot;&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;interface&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;KeyValuePair&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;readonly&lt;/span&gt; key&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;readonly&lt;/span&gt; value&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;updateChocolateBar&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;bar&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; ChocolateBar&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; props&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Partial&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;ChocolateBar&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; ChocolateBar &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;bar&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;props &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Here, &lt;code class=&quot;language-text&quot;&gt;Partial&amp;lt;ChocolateBar&gt;&lt;/code&gt; creates a type with all properties of &lt;code class=&quot;language-text&quot;&gt;ChocolateBar&lt;/code&gt; set to optional, effectively producing:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;typescript&quot;&gt;&lt;pre class=&quot;language-typescript&quot;&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;interface&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;ChocolateBar&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;readonly&lt;/span&gt; manufacturer&lt;span class=&quot;token operator&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;readonly&lt;/span&gt; name&lt;span class=&quot;token operator&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;readonly&lt;/span&gt; price&lt;span class=&quot;token operator&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Money&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Why is this approach superior?&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The &lt;code class=&quot;language-text&quot;&gt;ChocolateBar&lt;/code&gt; contract is only altered for this &lt;em&gt;specific case&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;updateChocolateBar()&lt;/code&gt; communicates its own contract more effectively, is less ambiguous in use, and straightforward to test&lt;/li&gt;
&lt;/ol&gt;</content:encoded></item><item><title><![CDATA[Maintenance pages in NGINX without reload]]></title><description><![CDATA[Configuring a maintenance page in NGINX is quite straightforward and, if configured correctly, allows for live toggling on and off without…]]></description><link>https://www.dereklawless.ie/maintenance-pages-in-nginx-without-reload/</link><guid isPermaLink="false">https://www.dereklawless.ie/maintenance-pages-in-nginx-without-reload/</guid><pubDate>Sun, 02 Feb 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Configuring a maintenance page in NGINX is quite straightforward and, if configured correctly, allows for live toggling on and off without requiring the NGINX instance to be reloaded or restarted.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;nginx&quot;&gt;&lt;pre class=&quot;language-nginx&quot;&gt;&lt;code class=&quot;language-nginx&quot;&gt;&lt;span class=&quot;token directive&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;location&lt;/span&gt; /&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token comment&quot;&gt;# Check for the existence of an enabled maintenance page&lt;/span&gt;
	&lt;span class=&quot;token directive&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; (-f&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;PATH&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;/&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;TO&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;/maintenance-page/index-on.html) &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token directive&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;503&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;token comment&quot;&gt;# Include the rest of this location&apos;s configuration as normal&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token directive&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;location&lt;/span&gt; /maintenance-page&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token directive&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;root&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;PATH&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;/&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;TO&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;/&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;MAINTENANCE_PAGE_PARENT_FOLDER&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;# Serve out the maintenance page for 503, 504 errors.&lt;/span&gt;
&lt;span class=&quot;token directive&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;error_page&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;503&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;504&lt;/span&gt; /maintenance-page/index-on.html&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;For each inbound request matched by this location, NGINX will check for the existence of an &lt;code class=&quot;language-text&quot;&gt;index-on.html&lt;/code&gt; page - if found, it will be served with an &lt;code class=&quot;language-text&quot;&gt;HTTP 503&lt;/code&gt; status code.&lt;/p&gt;
&lt;p&gt;To toggle the maintenance page on or off, &lt;em&gt;simply rename the maintenance page&lt;/em&gt;:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token builtin class-name&quot;&gt;cd&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token environment constant&quot;&gt;PATH&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;/&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;TO&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;/maintenance-page
&lt;span class=&quot;token function&quot;&gt;mv&lt;/span&gt; index-off.html index-on.html&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token builtin class-name&quot;&gt;cd&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token environment constant&quot;&gt;PATH&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;/&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;TO&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;/maintenance-page
&lt;span class=&quot;token function&quot;&gt;mv&lt;/span&gt; index-on.html index-off.html&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</content:encoded></item><item><title><![CDATA[Null coalescing in TypeScript]]></title><description><![CDATA[The null coalescing operator has been a long requested feature in TypeScript. Indeed, when I began using TypeScript a few years ago, I…]]></description><link>https://www.dereklawless.ie/null-coalescing-in-typescript/</link><guid isPermaLink="false">https://www.dereklawless.ie/null-coalescing-in-typescript/</guid><pubDate>Fri, 31 Jan 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;The &lt;a href=&quot;https://en.wikipedia.org/wiki/Null_coalescing_operator&quot;&gt;null coalescing operator&lt;/a&gt; has been a long requested feature in TypeScript. Indeed, when I began using TypeScript a few years ago, I assumed it was available and was suprised to find this wasn’t the case.&lt;/p&gt;
&lt;p&gt;Null coalescing remained unsupported until recently  because the TypeScript team (rightly) wanted to mantain compatibility with any eventual &lt;a href=&quot;https://tc39.es/&quot;&gt;TC39&lt;/a&gt; decisions regarding implementation and semantics.&lt;/p&gt;
&lt;p&gt;Given the &lt;a href=&quot;https://github.com/tc39/proposal-nullish-coalescing&quot;&gt;ECMAScript proposal is now at stage 4&lt;/a&gt;, the TypeScript team have responded by adding support for the &lt;code class=&quot;language-text&quot;&gt;??&lt;/code&gt; operator in &lt;a href=&quot;https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#nullish-coalescing&quot;&gt;TypeScript version 3.7&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The null coalescing operator is useful when you want to use a &lt;em&gt;‘default’&lt;/em&gt; value in an expression. In TypeScript and JavaScript you will find the following pattern regularly used:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;javascript&quot;&gt;&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; a &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; b &lt;span class=&quot;token operator&quot;&gt;||&lt;/span&gt; c&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;While this appears to achieve the same end (and in many cases, will) the logical OR operator (&lt;code class=&quot;language-text&quot;&gt;||&lt;/code&gt;) applies for any &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Glossary/Falsy&quot;&gt;falsy&lt;/a&gt; value i.e. &lt;code class=&quot;language-text&quot;&gt;null&lt;/code&gt;, &lt;code class=&quot;language-text&quot;&gt;undefined&lt;/code&gt;, &lt;code class=&quot;language-text&quot;&gt;&quot;&quot;&lt;/code&gt;, &lt;code class=&quot;language-text&quot;&gt;0&lt;/code&gt;, &lt;code class=&quot;language-text&quot;&gt;NaN&lt;/code&gt;, &lt;code class=&quot;language-text&quot;&gt;false&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;javascript&quot;&gt;&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; b &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; c &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;42&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; a &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; b &lt;span class=&quot;token operator&quot;&gt;||&lt;/span&gt; c&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;a&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// 42&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The null coalescing operator (&lt;code class=&quot;language-text&quot;&gt;??&lt;/code&gt;) is more strict; it only applies where the value is &lt;code class=&quot;language-text&quot;&gt;null&lt;/code&gt; or &lt;code class=&quot;language-text&quot;&gt;undefined&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;typescript&quot;&gt;&lt;pre class=&quot;language-typescript&quot;&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; b &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; c &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;42&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; a &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; b &lt;span class=&quot;token operator&quot;&gt;??&lt;/span&gt; c&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token builtin&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;a&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// 0&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This additional strictness can be useful in scenarios where subtle errors may otherwise be introduced due to unintended falsy evaluation i.e. where &lt;code class=&quot;language-text&quot;&gt;0&lt;/code&gt;, &lt;code class=&quot;language-text&quot;&gt;NaN&lt;/code&gt;, or &lt;code class=&quot;language-text&quot;&gt;&quot;&quot;&lt;/code&gt; are valid values in your application data or state.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Renaming properties in a destructuring assignment]]></title><description><![CDATA[Destructuring is one of the more useful language features added in ECMAScript 6 (ES6). Destructuring allows you to unpack values from arrays…]]></description><link>https://www.dereklawless.ie/renaming-properties-in-a-destructuring-assignment/</link><guid isPermaLink="false">https://www.dereklawless.ie/renaming-properties-in-a-destructuring-assignment/</guid><pubDate>Thu, 30 Jan 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment&quot;&gt;Destructuring&lt;/a&gt; is one of the more useful language features added in ECMAScript 6 (ES6). Destructuring allows you to &lt;em&gt;unpack&lt;/em&gt; values from arrays, or properties from objects, into distinct variables.&lt;/p&gt;
&lt;p&gt;Consider the following object:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;javascript&quot;&gt;&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; user &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token literal-property property&quot;&gt;emailAddress&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;billg@microsoft.com&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
	&lt;span class=&quot;token literal-property property&quot;&gt;nickName&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Bill G&quot;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Pre-ES6 you would typically access the object property values directly or assign e.g.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;javascript&quot;&gt;&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt; user&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;nickName &lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt; user&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;emailAddress &lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// &quot;Bill G (billg@microsoft.com)&quot;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; emailAddress &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; user&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;emailAddress
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; nickName &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; user&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;nickName&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt; nickName &lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt; emailAddress &lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// &quot;Bill G (billg@microsoft.com)&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;ES6 introduced destructuring, enabling you to unpack into new variables in one assignment expression:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;javascript&quot;&gt;&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; emailAddress&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; nickName &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; user&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt; nickName &lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt; emailAddress &lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// &quot;Bill G (billg@microsoft.com)&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;One awkward scenario is where you want to destructure an object but the resultant variable(s) already exist in scope. Here, the unpacked variables collide with the function arguments:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;javascript&quot;&gt;&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;getDetails&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;emailAddress&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; user&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Fetch existing details from a database, etc.&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;updateDetails&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;emailAddress&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; nickName&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; emailAddress&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; nickName &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;getDetails&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;emailAddress&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

	console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt; nickName &lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt; emailAddress &lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token function&quot;&gt;updateDetails&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;steveb@microsoft.com&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Steve B&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Uncaught SyntaxError: Identifier &apos;emailAddress&apos; has already been declared&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Fortunately, this scenario was anticipated and &lt;strong&gt;you can rename variables in a destructuring assignment&lt;/strong&gt;:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;javascript&quot;&gt;&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;updateDetails&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;emailAddress&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; nickName&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token literal-property property&quot;&gt;emailAddress&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; currentEmailAddress&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token literal-property property&quot;&gt;nickName&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; currentNickName &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;getDetails&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;emailAddress&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Renaming&lt;/span&gt;

	console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt; nickName &lt;span class=&quot;token operator&quot;&gt;||&lt;/span&gt; currentNickName &lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt; emailAddress &lt;span class=&quot;token operator&quot;&gt;||&lt;/span&gt; currentEmailAddress &lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token function&quot;&gt;updateDetails&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// &quot;Bill G (billg@microsoft.com)&quot;&lt;/span&gt;
&lt;span class=&quot;token function&quot;&gt;updateDetails&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;steveb@microsoft.com&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Steve B&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// &quot;Steve B (steveb@microsoft.com)&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</content:encoded></item><item><title><![CDATA[Securing endpoints in NGINX with Basic Authentication]]></title><description><![CDATA[Let’s begin by stating that Basic Authentication is likely not the authentication method you’re looking for. It has a number of shortcomings…]]></description><link>https://www.dereklawless.ie/securing-nginx-basic-authentication/</link><guid isPermaLink="false">https://www.dereklawless.ie/securing-nginx-basic-authentication/</guid><pubDate>Sun, 26 Jan 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Let’s begin by stating that &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication#Basic_authentication_scheme&quot;&gt;Basic Authentication&lt;/a&gt; is &lt;em&gt;likely&lt;/em&gt; not the authentication method you’re looking for. It has a number of shortcomings, not least of which is it &lt;strong&gt;transmits the password&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Granted, it base64 encodes the username and password first but this is &lt;em&gt;reversible encoding&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Caveats aside, it does still have its uses - perhaps you want to restrict casual access to files or web applications available on your internal network only without the complexities of OAuth, Active Directory integration, or similar.&lt;/p&gt;
&lt;p&gt;To secure endpoints in NGINX using Basic Authentication, follow these steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;On the NGINX host, type the following in your terminal:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;# Substitute {USERNAME} for the one you want to use e.g. &apos;admin&apos;&lt;/span&gt;
&lt;span class=&quot;token builtin class-name&quot;&gt;printf&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;{USERNAME}:&lt;span class=&quot;token variable&quot;&gt;&lt;span class=&quot;token variable&quot;&gt;`&lt;/span&gt;openssl &lt;span class=&quot;token function&quot;&gt;passwd&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-apr1&lt;/span&gt;&lt;span class=&quot;token variable&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token entity&quot; title=&quot;\n&quot;&gt;\n&lt;/span&gt;&quot;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&gt;&gt;&lt;/span&gt; .htpasswd&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Enter an appropriate strength password when prompted. For simplicity, consider creating this file in an appropriate location e.g. &lt;code class=&quot;language-text&quot;&gt;/etc/nginx/sites-available&lt;/code&gt;.&lt;/p&gt;
&lt;ol start=&quot;2&quot;&gt;
&lt;li&gt;Update the NGINX configuration(s) for each endpoint you wish to secure:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;nginx&quot;&gt;&lt;pre class=&quot;language-nginx&quot;&gt;&lt;code class=&quot;language-nginx&quot;&gt;&lt;span class=&quot;token directive&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;location&lt;/span&gt; /&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token comment&quot;&gt;# Display a title on the Basic Authentication browser challenge dialog (if supported)&lt;/span&gt;
	&lt;span class=&quot;token directive&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;auth_basic&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Administration Area&quot;&lt;/span&gt;
	&lt;span class=&quot;token comment&quot;&gt;# The absolute path to the .htpasswd file&lt;/span&gt;
	auth_basic_user_file /etc/nginx/sites-available/.htpasswd&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ol start=&quot;3&quot;&gt;
&lt;li&gt;Ensure the &lt;code class=&quot;language-text&quot;&gt;.htpasswd&lt;/code&gt; file is readable by NGINX workers:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token function&quot;&gt;chmod&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;644&lt;/span&gt; .htpasswd&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ol start=&quot;4&quot;&gt;
&lt;li&gt;Verify the NGINX configuration and reload/restart:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token function&quot;&gt;sudo&lt;/span&gt; nginx &lt;span class=&quot;token parameter variable&quot;&gt;-t&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-c&lt;/span&gt; /etc/nginx/nginx.conf
&lt;span class=&quot;token function&quot;&gt;sudo&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;service&lt;/span&gt; nginx reload&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</content:encoded></item></channel></rss>