<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Olafur Palsson on Medium]]></title>
        <description><![CDATA[Stories by Olafur Palsson on Medium]]></description>
        <link>https://medium.com/@olafur-palsson?source=rss-44510d70b566------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*gtJiTs-vOB8crXNjSbBGZw.png</url>
            <title>Stories by Olafur Palsson on Medium</title>
            <link>https://medium.com/@olafur-palsson?source=rss-44510d70b566------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 06:12:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@olafur-palsson/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[AI and formal emails]]></title>
            <link>https://olafur-palsson.medium.com/ai-and-formal-emails-88d5a401577a?source=rss-44510d70b566------2</link>
            <guid isPermaLink="false">https://medium.com/p/88d5a401577a</guid>
            <category><![CDATA[formal-communication]]></category>
            <category><![CDATA[email]]></category>
            <category><![CDATA[communication]]></category>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Olafur Palsson]]></dc:creator>
            <pubDate>Fri, 21 Jul 2023 09:31:56 GMT</pubDate>
            <atom:updated>2023-07-21T09:36:06.386Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve been thinking about the future of emailing and AI and I feel as if one specific future is almost guaranteed.</p><h3>AI for writing emails</h3><p>Writing an email involves a bit of risk, especially if you are in a particular mood for example. Whether or not you come off as too passive, do not highlight your issues enough or come off as too rude is all up to you and that’s not necessarily the best way.</p><p>Let’s say that instead of writing the email we use ChatGPT and we write this:</p><blockquote>Hi, <br>This assignment is completely borked, I could have done it way faster but the my a**hole coworker took up all the time by talking about his cat and I never wanted a cubicle so bad in my life. All the ceremony around completing a task and the micromanagement made it into a hellscape where I couldn’t get anything done and so the project is behind schedule. I thought I would give you a heads up on that. <br>John</blockquote><p>By putting “Write this as a formal email:” above and feeding it to ChatGPT it translates to the following. (Reading the email is not necessary of course, but you’re welcome to.</p><blockquote>Subject: Concerns Regarding Project Assignment</blockquote><blockquote>Dear [Recipient’s Name],</blockquote><blockquote>I hope this email finds you well. I am writing to bring to your attention some concerns I have encountered while working on the recent project assignment.</blockquote><blockquote>Firstly, I must express my frustration with the current state of the assignment. The completion process has been significantly hindered due to unforeseen circumstances, particularly regarding time management. Unfortunately, a coworker of mine has been very talkative during work hours, often diverting my focus away from the task at hand. As a result, I found myself unable to make the progress I had anticipated, and this has contributed to a delay in the project timeline.</blockquote><blockquote>Moreover, the excessive emphasis on ceremonial aspects and micromanagement within the project has created a challenging work environment. This excessive bureaucracy and oversight have made it difficult for me to efficiently execute my responsibilities. I must admit that this experience has been quite challenging, and I have never felt such a strong desire for a private workspace before.</blockquote><blockquote>I felt it was crucial to provide you with this information as soon as possible, to ensure that you are aware of the current situation. I am determined to resolve these issues promptly and get the project back on track. If there is any assistance or guidance you can provide to facilitate the process, I would greatly appreciate it.</blockquote><blockquote>Thank you for your understanding and attention to this matter. I look forward to discussing potential solutions and the necessary adjustments that can be made to improve the workflow.</blockquote><blockquote>Sincerely,<br>John</blockquote><h3>AI for reading emails</h3><p>So that email ChatGPT wrote generally outlines the issues and adds all the regular fluff that people have to do to write a formal email. It’s definitely preferable to the original text in a formal setting, although when writing to close coworkers you might prefer the original of course.</p><p>I personally just get tired from looking at all that text.</p><p>So I ask ChatGPT to summarize it by adding “Summarize the following:” above the email and feeding the AI the whole email. We get:</p><blockquote>Summary: The sender is expressing concerns about the recent project assignment. They mention that unforeseen circumstances, particularly a talkative coworker, have hindered their progress and delayed the project timeline. They also highlight the excessive emphasis on ceremonial aspects and micromanagement, which has created a challenging work environment. The sender seeks assistance and guidance to resolve these issues promptly and improve the workflow.</blockquote><p>You can also adjust it to use vocabulary from a particular generation, I’m a millenial but I’d have more fun reading something with “Summarize the following by using Gen Z vocabulary”:</p><blockquote>Hey [Recipient’s Name],<br>What’s up? I hope you’re doing well. I just wanted to drop you an email about some concerns I’ve got with the recent project assignment.<br>First off, I’m seriously frustrated with how things are going. The whole completion process has been a total mess, thanks to unexpected stuff, especially poor time management. One of my coworkers won’t stop chatting during work hours, and it’s totally messing up my focus on the actual task. So you can guess, progress is not going as planned, and the project timeline is way off track now.<br>And let’s talk about the project itself — there’s way too much focus on the formal and ceremonial aspects. Plus, the micromanagement is driving me crazy. Seriously, it’s so tough to get anything done with all this red tape and oversight. I never thought I’d want a private workspace so badly, but here we are.<br>I felt it was crucial to get this to you ASAP, so you’re in the loop about what’s happening. I’m all in to fix these issues pronto and get the project back on the right path. If you’ve got any advice or can help me out with this, that’d be awesome.<br>Thanks for understanding and taking this seriously. Let’s chat about potential solutions and making some changes to improve the workflow.<br>Catch you later,<br>John</blockquote><h3>Summary</h3><p>One generation from now I’m pretty sure that most people will stop writing formal emails at all since the alternative just simply takes time. Miscommunication is still a minor issue but arguably less than before. This approach will be able to save a lot of time on writing formal emails and thus lower cost for a corporation. Formal emails have always been a costly verbal protocol written with specific language and in my humble opinion could be removed without any major drawbacks.</p><p>Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=88d5a401577a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Typing basic types with Typescript]]></title>
            <link>https://itnext.io/typing-basic-types-with-typescript-84288aa38b7c?source=rss-44510d70b566------2</link>
            <guid isPermaLink="false">https://medium.com/p/84288aa38b7c</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[typescript-4]]></category>
            <dc:creator><![CDATA[Olafur Palsson]]></dc:creator>
            <pubDate>Tue, 07 Sep 2021 13:27:42 GMT</pubDate>
            <atom:updated>2021-09-08T10:07:32.628Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oyMFqbKT3ykY6euVJsKIEg.png" /></figure><p>So here’s an issue. We have strings and we have ISOStrings and ids .</p><ol><li>We don’t want to be able to assign any string to a field that has ISOString but ISOString should be assignable to string</li><li>We don’t want an id of one data type to be assignable to an id of another data type.</li></ol><h3>1: Template literal types</h3><p>Template literal types have been a part of Typescript since 4.1. Now we can specify a string that fulfills a template.</p><pre>type Hello&lt;Greeted extends string&gt; = `Hello, ${Greeted}!`<br>type HelloWorld = Hello&lt;&#39;World&#39;&gt;<br>const hello1: HelloWorld = &#39;Hello, World!&#39;<br>const hello2: HelloWorld = &#39;Hello, Oli!&#39; // error</pre><p>This way we can define an ISOString by using ${number} . Be careful though since the resulting type will be a Union type of <em>too many</em> fields if you do it “properly”. Here’s how we would create a type for ISOStrings:</p><pre>type PaddedNumber = `${&#39;0&#39; | &#39;&#39;}${number}`<br>type ISODate = `${number}-${PaddedNumber}-${PaddedNumber}`<br>type ISOTime = `${PaddedNumber}:${PaddedNumber}:${PaddedNumber}`<br>export type ISOString = `${ISODate}T${ISOTime}Z`</pre><h3>2: Branding</h3><h4>Conventional branding</h4><p>So far people have used some sort of “Branding” approach to having an id not assignable to another id . For example:</p><pre>interface UserBrand { type: &#39;User&#39; }<br>type UserId = string &amp; UserBrand</pre><pre>interface ArticleBrand { type: &#39;Article&#39; }<br>type ArticleId = string &amp; ArticleBrand</pre><p>now when we…</p><pre>const userId: UserId = user.id // ok<br>const articleId: ArticleId = userId // error</pre><p>…with a great benefit to our type-checking. This approach does cause issues when we do this though.</p><pre>const userId: UserId = &#39;user-id&#39; // error<br>const userId2: UserId = &#39;user-id&#39; as UserId // casting is ok</pre><h4>Alternative 1: Branding that allows assigning basic types</h4><p>So here’s a solution from <a href="https://spin.atomicobject.com/2018/01/15/typescript-flexible-nominal-typing/">Drew Colthorp’s article</a> on Opaque Types (in his article “Flavoring”) by using this interface we create a union types with string instead that are not inter-assignable</p><pre>interface OpaqueType&lt;OpaqueT&gt; {<br>  _type?: OpaqueT;<br>}<br>export type Opaque&lt;T, OpaqueT&gt; = T &amp; OpaqueType&lt;OpaqueT&gt;;</pre><p>Now if we change our id types to…</p><pre>type UserId = Opaque&lt;string, &quot;User”&gt;<br>type ArticleId = Opaque&lt;number, &quot;Article&quot;&gt;</pre><p>we now get this effect:</p><pre>const userId: UserId = &#39;user-id&#39; // ok<br>const articleId: ArticleId = &#39;article-id // ok<br>const userId2: UserId = articleId // error</pre><h4>Using “unique symbol”</h4><p>To conserve a single source of truth with branding and to make sure that two brands can never be the same using unique symbol can handle those cases. As an example we can create two ISOString brands like so:</p><pre>type ISOString = string &amp; {readonly ISOString: unique symbol}<br>type ISOString2 = string &amp; {readonly ISOString: unique symbol}<br>let isoString1: ISOString = &#39;isostring&#39; as ISOString // ok<br>let isoString2: ISOString2 = &#39;isostring2&#39; as ISOString2 // ok<br>isoString1 = isoString2 // error</pre><p>You can likewise instead of making an Opaque type with string literals you can brand it with a unique symbol instead.</p><pre>type ISOString = Opaque&lt;string, { readonly T: unique symbol }&gt;<br>type ISOString2 = Opaque&lt;string, { readonly T: unique symbol }&gt;<br>const isostring: ISOString = &#39;isostring&#39;<br>let alsoIsostring: ISOString2 = &#39;isostring&#39;<br>alsoIsostring = isostring // error</pre><p>The difference is subtle. Let’s say two people create the same brand with the same signature then with unique symbol they’ll will not be interchangeable. The bigger the codebase the more you’ll have to know that you’re importing the correct CommentId or type for example.</p><h4>When should you use which?</h4><p>That, of course, depends on your needs.</p><ul><li>If you want a built-in string validation then use a Template Literal</li><li>If you want to make sure that people don’t mix ids or strings of different formats then use some sort of branding.</li><li>If you need both, then use both.</li></ul><p>And that’s all for now, happy coding!</p><h4>Appendix: Book reccomendations</h4><p>These books have allowed me to leapfrog a couple of years of experience, and it could do the same for you.<br>* <a href="https://amzn.to/3z083SU">Clean Code by Robert C. Martin</a><br>* <a href="https://amzn.to/2UyrEdS">Clean Architecture by Robert C. Martin</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=84288aa38b7c" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/typing-basic-types-with-typescript-84288aa38b7c">Typing basic types with Typescript</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Easiest guide to .bashrc]]></title>
            <link>https://itnext.io/easiest-guide-to-bashrc-7ad0063d37eb?source=rss-44510d70b566------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ad0063d37eb</guid>
            <category><![CDATA[bash]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Olafur Palsson]]></dc:creator>
            <pubDate>Sun, 07 Feb 2021 12:10:38 GMT</pubDate>
            <atom:updated>2021-08-19T11:24:59.826Z</atom:updated>
            <content:encoded><![CDATA[<h3>Easiest guide to .bashrc</h3><p>My journey with .bashrc files has been hectic at best. Digesting the syntax and logic of how a bash program is structured has always been an issue. I hope this will make people’s lives a bit easier and make bash a bit more straight forward. That being said, I love bash. There are countless cases that I’ve had a long sequence of terminal commands that need to be gotten <em>just right</em>. People say that bash is like a hammer and everything looks like a nail. In this case it <em>is</em> a nail.</p><p>To religious people regarding bash convention. Yes, I break them, this is my personal convention. I consider bash a personal journey where you express what you want your computer to do in a way that’s easiest for yourself and nobody else.</p><h3>Contents</h3><p>In this guide, we’ll explore a couple of concepts. We’ll not cover the prompt itself as these have probably one of the worst syntaxes that I’m aware of. I happily leave these to some online templates that there are plenty of.</p><p>What we’ll cover:</p><ul><li>Basic bash syntax</li><li>Expressions (and environment variables)</li><li>Strings</li><li>Multi-file .bashrc</li><li>Automation</li></ul><p>What we’ll <strong>not</strong> cover:</p><ul><li>Shell tools such as du , sed , awk etc. Those are outside the scope of this article</li><li>The prompt (oli-TM1701 10:36 ~ $ in my case)</li></ul><h3>Syntax</h3><p>Bash has a peculiar syntax which is not common in most of the modern programming languages. Do not mistake it though, in it’s oddities lies a lot of power and conciseness if written a clean way.</p><h4>Functions</h4><p>I’d like to start off with a basic function since they’re the building block of every program, and surprisingly, the most missing in most shell scripts I see. We simply print the arguments of the function.</p><pre>print_args() {<br>  echo $0<br>  echo $1<br>  echo $2<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/425/1*tmyIHr0it2Xasr_GCmZEQQ.png" /><figcaption>Output</figcaption></figure><p>Note that $0 is the program executing the command, then arguments are listed as $1 , $2and so on. We can then create some basic local variables like so.</p><pre>print_args() {<br>  local first=$1<br>  echo $first<br>}</pre><p>Note if you have a space between first , = and $1 <strong>the assignment won’t work. </strong>Now for the next confusing part…</p><h4>Return values from functions</h4><p>If you thought that you could get a return value from a function by using the return statement like in most languages I don’t blame you. It’s just that bash does things a bit differently. <strong>The</strong> return <strong>statement is only for return codes</strong>. Which, for those of you who remember C or related languages is an integer . That doesn’t mean it’s not useful though. Here’s an example using the very common &amp;&amp; operator to concatenate bash operations.</p><pre>passes() {<br>  return 0<br>}</pre><pre>fails () {<br>  return 1<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/478/1*U20x_m0prnxkkFXrE1zx1A.png" /><figcaption>Output</figcaption></figure><p>By now you should be wondering “How do we get return values then?”. The answer is the stdout as we’ll see in the next section.</p><h4>Evaluating expressions</h4><p>Expressions are completely <strong>vital</strong> to any clean bash script but, like everything else in bash the syntax is not the best. This brings us to one of the core principles of bash. If you can see it in the console you can put it in a variable. Essentially making the basic printing of a variable with echo equivalent to an <em>expression</em> instead of a <em>procedure</em>. That was a small brain-bender for me when learning bash but alas, that’s how things are done. Here are a couple of examples:</p><p>Using the $(expression) operator.</p><pre>cool_string() {<br>  echo &quot;$1 is cool&quot;<br>}</pre><pre>very_cool_string() {<br>  echo &quot;$(cool_string Oli), very cool in fact.&quot;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*YS4STn8M6sR1GjCbNkq2nQ.png" /><figcaption>Output</figcaption></figure><p>Now we have a couple of tools to do something a bit more fancy. Let’s take a look at the eval command. eval simple runs whatever is passed it as you would have typed it into the terminal directly. Here’s a fun example where we create a function that creates environment variables for no reason:</p><pre>var() {<br>  eval &quot;export $1=\&quot;$2\&quot;&quot;<br>}</pre><p>If you don’t know the export command then it’s a way to assign environment variables to your shell session.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/479/1*RcE0AIEiB4h2v6vDUNZpMw.png" /><figcaption>Output</figcaption></figure><h4>Strings</h4><p>So now we’re up to the point where attentive readers realize that everything about bash comes down to having strings, executing them and/or converting them to a different strings. Now it should start to become clear why there are so many tools to manipulate strings on Linux such as sed , awk , grep etc. We can literally just get a feed of strings, manipulate them into a bash command and execute them and it’s <strong>lightning fast</strong>!</p><p>Let’s do some string templating like we’ve been using above.</p><pre>date_strings() {<br>  local date_arg=&quot;next Fri&quot;<br>  echo &#39;date --date=&quot;$date_arg&quot;&#39;<br>  echo &quot;date --date=&#39;$date_arg&#39;&quot;<br>  echo `date --date=&quot;$date_arg&quot;`<br>  echo $(date --date=&quot;$date_arg&quot;)<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/342/1*OQC8emb0nm92TgD41Qzxkw.png" /><figcaption>Output</figcaption></figure><p>&#39; : Is the what you see is what you get (WYSIWYG) way to do strings.</p><p>&quot; : Is the string templating. Just like the f&#39;template {variable}&#39; in python or `template ${variable}` in javascript. In this case the curlies {} are simply normal variables.</p><p>` : Is the same as $(expression) . Which might look confusing at first since it’s not really a string or string template but a function call / expression evaluation.</p><h4>Conditionals</h4><p>If you were hoping this one was intuitive then I’m sorry again. Conditionals are kinda funky especially under the hood. Let’s start by explaining a program called [ (yes, a program).</p><p>It takes in arguments and flags like [ arg1 -flag arg2 ] with space between them. This is why we get this hilarious error when we type [&quot;arg1&quot; into the terminal since it’s not a syntax error.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/288/1*3i26-Vm0T_xY5jG6q29C0w.png" /></figure><p>Now let’s use our prior knowledge to look at the conditionals. Since we know that [ is a program, and program has a return value (0 if it’s all good, otherwise an error-code, like 1). Let’s run the [ program with a couple of arguments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/1*9h5EzxcgeuDgGeXMl809DQ.png" /></figure><p>It’s time to take a look at the if statement in bash . We’ll be using the -f flag which means “does this file exist?” and use it to write an import function for no reason. We’ll also be using the . to load our file. To see what flags you can use check <a href="https://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html">this page</a> out, the -z is particularly helpful. :)</p><pre>import() {<br>  local suffix=&#39;.bashrc&#39;<br>  local file_name=&quot;$1$suffix&quot;<br>  if [ -f $file_name ]<br>  then<br>    . $file_name<br>  else<br>    echo &quot;ImportError: $file_name&quot;<br>  fi<br>}</pre><p>Now we’ll try loading our ~/.bashrc and a file called something.bashrc which does not exist.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/403/1*VFFTtBcxH5ETjKreYpBIpg.png" /><figcaption>Output</figcaption></figure><p>There is also another program for conditionals creatively called [[ which has very similar syntax but a different effect. In some cases it’s a simpler comparison.</p><h4>Multi-file .bashrc</h4><p>Well, with the tools above and the . to specify a file to load as another .bashrc you can pretty much do it yourself already. :)</p><h4>Backing it up to .git</h4><p>Just remember to do so, it’s important.</p><ul><li>Have your ~/.bashrc as empty as possible.</li><li>Specify an environment variable to your folder of .bashrc files.</li><li>Load an index.bashrc or __init__.bashrc if you will that loads the rest.</li><li>???</li><li>Profit.</li></ul><h3>Automation</h3><p>So now you have most of the tools needed to create small functions for your bashrc , give it a try and create some very basic functions. Using the syntax from above you can automate anything from a searching your bash history with…</p><pre>search_history() {<br>  history | grep $1<br>}</pre><p>to building and signing an android apk. Remember though, it’s just like everything else: Nothing beats practice.</p><p>Thanks for reading.</p><h4>Further reading</h4><p>5 hours of trial and error can save whole minutes of reading the docs.<br>* <a href="https://linux.die.net/man/1/bash">Bash docs (accessible also in the terminal via </a>man bash<a href="https://linux.die.net/man/1/bash"> )</a></p><p>These books have allowed me to leapfrog a couple of years of experience.<br>* <a href="https://amzn.to/3z083SU">Clean Code by Robert C. Martin</a><br>* <a href="https://amzn.to/2UyrEdS">Clean Architecture by Robert C. Martin</a></p><p>— — Edits to this article — — <br>1. Through the power of the internet the errors in my article were exposed and I updated the article with a bit more accurate information such as using local variables.</p><p>2. Added my favorite programming books to the article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ad0063d37eb" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/easiest-guide-to-bashrc-7ad0063d37eb">Easiest guide to .bashrc</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Programming architecture as a feudal system]]></title>
            <link>https://medium.com/programming-explained-using-analogies/programming-architecture-as-a-feudal-system-67a2361dfb74?source=rss-44510d70b566------2</link>
            <guid isPermaLink="false">https://medium.com/p/67a2361dfb74</guid>
            <dc:creator><![CDATA[Olafur Palsson]]></dc:creator>
            <pubDate>Sun, 04 Oct 2020 16:40:00 GMT</pubDate>
            <atom:updated>2020-10-04T16:40:00.229Z</atom:updated>
            <content:encoded><![CDATA[<p>You might or might not have thought of the hierarchical nature of programs has a lot of similarities of how people act in large systems. I’m going to make the argument that feudal systems are an example of good software architecture.</p><p>In this article a person is a file, an interface is a method of communication</p><h3>The King</h3><p>Imagine you’re a king. You can ask for anything you want as long as your kingdom is able to provide it. You are so powerful that you can, in theory, control every single thing in your kingdom if you wanted to. A king would never do that and for a simple reason, there is no time.</p><p>Now let’s see this as a program. We have a king, it the main() function of your program or a special use-case for the application. If you have experienced a whole package that’s a one big main() function and thought it was bad architecture you’d be right, it absolutely is. There could be many hard to find errors simply because the function is <em>busy</em>. It can’t do that one thing it needs to do in an efficient manner so when we need to fix it we can read it for a minute, find out if there is the bug there, and then leave and go on with our work. This brings us to our first principle:</p><blockquote>Kings are lazy</blockquote><p>In other words a king can’t be bothered with telling the baker to make bread. Just like a king doesn’t tell his wine maker how to make the wine, the main function shouldn’t tell the a foreign API what http-method it’s using (unless it’s literally the only thing it does). This brings us two the second principle:</p><blockquote>Kings use simple orders</blockquote><p>When you’re a king, you have access to the most qualified people, if you don’t like them you can get rid of them and get new ones. Let’s say you need wine, what do you do as a king? Simple, you ask a guy to bring you a wine, he brings you wine in holdable a cup. The fact that the cup is holdable is crucial, but what type it is is not. Holdable is an interface that the servant and the King share making delivering wine simple and that’s exactly why interfaces are so crucial. They simplify the way things interact. Due to “Kings use simple orders” this is advantageous. Let’s say that the wine guy tries to poison the king with Errors and it needs to be rewritten or updated, does the king care? No, of course not, he just cares that he can ask his servant, his servant brings him wine in a holdable thing. Principle:</p><blockquote>Kings never need to change their orders</blockquote><p>Which is a direct result of using interfaces.</p><h3>The council</h3><p>The council has your advisors and people who execute your orders. To manage your kingdom as long as your council is good you can use your council as a remote control for the whole kingdom. The council for a king functions the same as lib folders, they should serve you everything on a silver platter. Each folder inside a lib folder is a councilor that you pass commands to. So let’s say that there is something the king needs some functionality, should the king have the new code? No. The king asks his councilors anyway, the councilors should just figure it out. That’s the same reason why in programming we should leave calculations to a Calculator and sending emails to a EmailSender .</p><h3>The hierarchy</h3><p>So now we understand the kings viewpoint. Should we just make a couple of 10k line lib councilors then to keep the king happy? No, that’ll drown the councilors in work. The councilors need their men, and those men need orders, and those orders need interfaces so they can stop caring about who those people are. As a rule of thumb, if something is hard to migrate to a rewrite in a different file you’re doing something wrong. In other terms:</p><blockquote>Anything with lower control should be replaceable</blockquote><p>This is also known as dependencies. You want to depend on the interface of the order instead of person executing the order. If a king can only order a single person to make his bread and that person dies the king stops getting bread. It would be like <em>that person’s death telling the king he can’t eat bread. </em>Which would break and obvious rule for any king:</p><blockquote>A servant doesn’t tell the king what he can or can’t do</blockquote><p>Note that the servant can still tell the king <em>what he himself can or can’t do.</em></p><h3>The order</h3><p>The order is simply an execution of the kings use-case. It’s paramount that the servant does it efficiently and fast without any fluff or having to manually create a wooden cup.</p><pre># Cup implements Holdable and Drinkable<br>def get_wine() -&gt; Cup[Wine]:<br>    conversation = jim_the_wine_guy.conversation()<br>    wine = conversation.get_wine_bottle(type=&#39;any&#39;)<br>    wine_cup = Cup(liquid=wine.pour())<br>    return wine_cup</pre><p>Which we can then give to the king, his way of doing things is different.</p><pre>def drink_some_wine():<br>    wine = servant.get_wine()<br>    hand = DrinkingHand(wine)<br>    hand.drink()</pre><h3>The next level below</h3><p>I hope that while reading this you realized that this way of handling and/or issuing orders is the same for a count and a king even though a count serves a king. Which is the same as in programming, architecture principles don’t change between layers of abstraction. So next time you are programming try asking yourself “Should this function be bothered with running these procedures or is below it’s status in the hierarchy of control?”. Have fun and happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=67a2361dfb74" width="1" height="1" alt=""><hr><p><a href="https://medium.com/programming-explained-using-analogies/programming-architecture-as-a-feudal-system-67a2361dfb74">Programming architecture as a feudal system</a> was originally published in <a href="https://medium.com/programming-explained-using-analogies">Programming with analogies</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>