<?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 Olivier De Meulder on Medium]]></title>
        <description><![CDATA[Stories by Olivier De Meulder on Medium]]></description>
        <link>https://medium.com/@odemeulder?source=rss-555725a03e9c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*XKZOuFond22cn_mM.jpeg</url>
            <title>Stories by Olivier De Meulder on Medium</title>
            <link>https://medium.com/@odemeulder?source=rss-555725a03e9c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 15 Nov 2026 11:45:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@odemeulder/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[AWS Key Management System (KMS)]]></title>
            <link>https://medium.com/@odemeulder/aws-key-management-system-kms-7fefb0502788?source=rss-555725a03e9c------2</link>
            <guid isPermaLink="false">https://medium.com/p/7fefb0502788</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Olivier De Meulder]]></dc:creator>
            <pubDate>Sat, 30 Jun 2018 13:33:42 GMT</pubDate>
            <atom:updated>2018-06-30T13:38:13.861Z</atom:updated>
            <content:encoded><![CDATA[<h4>How to encrypt and decrypt something with AWS KMS</h4><p>This going to be a little more technical. Basically I am documenting a problem I was trying to research for myself. It is a very basic intro do encrypting and decrypting a file using AWS KMS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PcTu-jNSmwxr82jdEEGtiQ.jpeg" /></figure><h4>Encrypt</h4><p>Let’s start with a single file we want to encrypt.</p><pre>echo ‘Hello, Olivier’ &gt; message.txt</pre><p>Now we are ready to encrypt this message. I will assume that you already created a KMS key and have an ARN for said key. The command ( aws kms encrypt ) takes two mandatory arguments plaintext and key_id.</p><pre>aws kms encrypt --plaintext file://message.txt --key-id arn:aws:kms:us-east-1:xxxxxxxx:key/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx</pre><p>This will return something like this:</p><pre>{<br>    &quot;CiphertextBlob&quot;: &quot;AQICAHgfMmH9u+060sH9MFBcUp3+puJthvFVikjor5isqUM3YQGJBIw/P9nY0K5scZh+OPGgAAAAbDBqBgkqhkiG9w0BBwagXTBbAgEAMFYGCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMh5PtPbfeWUobrdcbAgEQgCnmiRqRGyslnEQHIwpeN6mevKKWdpErlx2wK6v5IPqnXXWL5X0cEAasGw==&quot;,<br>    &quot;KeyId&quot;: &quot;arn:aws:kms:us-east-1:572028816325:key/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx&quot;<br>}</pre><p>We are really interested in the CiphertextBlob, so you can extract it like so and store it in a new file.</p><pre>aws kms encrypt --plaintext file://message.txt --key-id arn:aws:kms:us-east-1:xxxxxxxx:key/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx --output text --query CiphertextBlob &gt; message.encrypted.base64</pre><p>If you know a little unix, you know that &gt; message.encrypted.base4 means that the output of the previous command will be redirected to a new file in this case.</p><p>An astute reader may have noticed that I named the file with a .base64 extension, that is because by default the result of the encryption will be base64 encoded. For KMS to be able to <em>decrypt</em> this, the file must be decoded, as follows:</p><pre>base64 --decode message.encrypted.base64 &gt; message.encrypted</pre><p>You could have done all of the above in one go, using the following command.</p><pre>aws kms encrypt --plaintext file://message.txt --key-id arn:aws:kms:us-east-1:xxxxxxxx:key/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx --output text --query CiphertextBlob | base64 --decode &gt; message.encrypted</pre><p>If you check your current folder now you will find the following files:</p><ul><li>message.txt — your original file</li><li>message.encrypted.base64 — the encrypted version encoded in base64</li><li>message.encrypted — the encrypted version</li></ul><h4>Decrypt</h4><p>To decrypt, we basically have to do the reverse, sort of.</p><p>Step one is to decrypt. The command ( aws kms decrypt ) takes two mandatory arguments ciphertext-blob.</p><pre>aws kms decrypt --ciphertext-blob fileb://message.encrypted</pre><p>Note the b in fileb://. Also, no need to specify the key. As long as you are in your account AWS knows which key to use to decode your message.</p><p>The output of the command above will be something like:</p><pre>{<br>    &quot;KeyId&quot;: &quot;arn:aws:kms:us-east-1:xxxxxxx:key/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx&quot;,<br>    &quot;Plaintext&quot;: &quot;MjgxMSXNb2JyaXNvbgo=&quot;<br>}</pre><p>Of course, we are only interested in the plain text. So let’s modify the command above to extract what you need. And let’s store that in its own file, so we can see what we are doing.</p><pre>aws kms decrypt --ciphertext-blob fileb://message.encrypted --output text --query Plaintext &gt; message.decrypted.base64</pre><p>If view the content of your output file cat message.decrypted.base64, you will see that it still not the original text that was in our file.</p><p>One more thing to do … base64 decoding.</p><pre>base64 --decode message.decrypted.base64 &gt; message.decrypted</pre><pre>cat message.decrypted<br>Hello, Olivier</pre><p>Alleluia. We encrypted and decrypted a message.</p><h4>Going further</h4><p>What is the use in encrypting Hello, Olivier? We recently had to store a private key in AWS. We used this technique to encrypt the private key, prior to uploading it.</p><p>Can you think of any other use cases?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7fefb0502788" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Scrum, Swarm, Sprint — How to Take the Agile Process and Make it Your Own]]></title>
            <link>https://open.nytimes.com/scrum-swarm-sprint-how-to-take-the-agile-process-and-make-it-your-own-b6416793ff7e?source=rss-555725a03e9c------2</link>
            <guid isPermaLink="false">https://medium.com/p/b6416793ff7e</guid>
            <category><![CDATA[code]]></category>
            <category><![CDATA[scrum]]></category>
            <category><![CDATA[work]]></category>
            <category><![CDATA[process]]></category>
            <category><![CDATA[agile]]></category>
            <dc:creator><![CDATA[Olivier De Meulder]]></dc:creator>
            <pubDate>Wed, 21 Mar 2018 14:25:27 GMT</pubDate>
            <atom:updated>2018-04-26T20:10:45.218Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r9pPUjx0YNb6A0ZzDoQMpQ.jpeg" /><figcaption>Illustrations by Tim Peacock</figcaption></figure><p>Like many technology organizations, Customer Care Technology, my team at The New York Times, uses scrum as our main process. To plan our sprints, we would go through the backlog, pick stories and assign a story to each of our six engineers, who would then work hard to get their story done. Because of unforeseen roadblocks, the stories would often get pushed to the next sprint or we would work together on a story to finish it before the end of the sprint. The problem with this process was that by the time we realized we needed to work together, it was often too late in the sprint.</p><p>Recently, we started working together, or swarming, for our entire sprints and only taking on a small number of stories at a time. Swarming is not a new concept; Many agile teams often swarm on a story to finish it before moving on to a new story. We took the definition of swarming and made it or own: We don’t just swarm to finish what has already been started, we swarm as soon as we start something new<strong>. </strong>And we’ve become more productive and collaborative as a result.</p><h3>How we got here</h3><p>A few months ago, the head of our department had a meeting with our team to encourage us to try a new way of working. As an engineering organization, it is important to focus on the right metrics, so we often focus on utilization or efficiency. However the more important metric is throughput: How much value can we deliver to the business and how quickly can we achieve this?</p><p>Translate this to scrum. Focusing on reducing the amount of inventory (work in progress) we have at any given time means we can execute faster. Working on fewer stories at one time means we can finish more, faster.</p><p>To understand how this works in practice, imagine this sprint scenario: We start with one story (let’s call this Story One), but Story One gets blocked by an external dependency, so we move on to the next story (we’ll call this Story Two). We have more work in progress. Because we started on Story Two late in the sprint, it is not done by the end of the sprint. During the next sprint planning we identify three new high priority stories (Stories Three, Four and Five). Now there is even more work in progress.</p><p>At this point, the dependency that blocked Story One is resolved, so we switch gears to work on Story One again. But when our product manager asks us when we can get to Story Six, we have to finish stories one through five first. Increased work in progress hinders throughput. It takes longer and longer to get anything done.</p><p>The head of our department suggested that instead of assigning one story to each engineer, multiple engineers should work simultaneously on one story. Thus we would have less inventory, less waste and increased throughput.</p><p>At our first sprint planning meeting where we were going to swarm for an entire sprint, we divided the team into subteams and took on only two or three stories. When my subteam met for the first time, we looked at each other and scratched our heads; Trying to figure out how to divide the work was awkward.</p><p>The idea behind swarming is to divide a story into smaller tasks that can be done in parallel, but sometimes it can be hard to divide the work because the tasks can end up being very interdependent and even overlap.</p><p>Different stories will require different solutions. Here are some of the ways we tackled this.</p><h3>Techniques for Swarming</h3><h4>Divide by functionality</h4><p>This may be the easiest and most logical one. If the story is, “Display a list of transactions, and for each transaction, there should be a ‘delete’ button to delete that transaction,” one engineer could work on displaying the list, while another could work on the ‘delete’ aspect.</p><p>Another example, if the story is, “build new functionality that should only show up under certain circumstances,” one engineer could start working on the conditional display of the feature, while another engineer works on the feature itself. It is probably the most natural way of dividing up work, but everyone would still need to work closely together to coordinate the touchpoints between the two tasks.</p><h4>Divide by front-end and back-end work</h4><p>This is pretty obvious as well and is an easy way to divide work. Very often an engineer can start working on the UI, while another can work on the back-end. Again, working closely together is key. Agree on the contract that will bind the front-end and back-end first before you start working.</p><h4>Pair program</h4><p>Two engineers work together on one machine: one person is the driver and one person is the navigator. The driver writes the code and the navigator sets the direction, observes and reviews. The benefits of pair programming are well documented: fewer bugs, shared knowledge, more efficient problem solving. As part of our effort to swarm, we have done our share of pair programming as well. Especially for more thorny issues or complicated features, it has proven quite valuable.</p><h4>Test-driven development</h4><p>If you practice true test driven development, you’re supposed to write the test first, see it fail and subsequently write the feature. In our version of swarming, one engineer starts writing component tests and/or integration tests, while the other one works on the underlying functionality.</p><h4>Integrating QA in the development process</h4><p>We have gotten much better about integrating QA in our development process. We used to loop QA in after our code was pushed to the master branch, which was clunky. Now our QA engineers will identify and create a test plan as soon as we begin working on a new story. As initial development nears completion, an engineer and a QA engineer will run through test scenarios together on our local machines.</p><p>The QA engineer may notice something that we had not thought of, or something that was missed in development, and at that point it is easy to remedy and fix. When the QA engineer likes what they see, we merge the branch into master and QA can verify it again on the dev server.</p><p>The way we are doing QA now has been a huge revelation to me and has had a major impact on our team. Because QA is more involved with the coding earlier on in the process, we have been able to develop features much faster. Bugs and unforeseen features are discovered earlier in the process and can be handled immediately.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L8j5Dijq0vHCCtHUnsHg8g.jpeg" /><figcaption>Illustration by Tim Peacock</figcaption></figure><h4><strong>Intense planning and coordination</strong></h4><p>In order to make sprint-length swarming work, you need planning and more planning. We typically have a story lead who meets with the members of the team and together, they break the story into subtasks in the way that makes the most sense. It is a collective planning effort. At that point we also agree on the contracts between the various subtasks. We also rely on the story lead to perform any needed coordination as we move along with the development.</p><p>It is often believed that scrum involves less (project) planning, but we all know that this is not true. When you swarm, you need even more planning.</p><h3>Takeaways</h3><p>After “swarming” for a few sprints, we started to get the hang of it. But ultimately, we are increasing throughput, which means we are completing features faster and delivering more.</p><p>There are some other benefits as well.</p><p>Few problems in this world don’t benefit from increased communication and software development is no exception. We talk about how to divide up the work, and we stay in close contact while we’re working because our projects often overlap. This means we can identify issues or roadblocks early in the sprint and correct accordingly.</p><p>I would also argue that increased communication leads to better software design decisions. We often have a healthy debate about the best way to tackle problems, and we probably wouldn’t have these conversations if we worked independently</p><p>By working closely together and discussing new features, we inevitably learn from each other: we learn about our specific domains, about the application we’re working on and general software building best practices.</p><p>All in all, this has been a very positive experience for our team and I encourage everyone to try it. If you have any questions, feel free to reach out.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b6416793ff7e" width="1" height="1" alt=""><hr><p><a href="https://open.nytimes.com/scrum-swarm-sprint-how-to-take-the-agile-process-and-make-it-your-own-b6416793ff7e">Scrum, Swarm, Sprint — How to Take the Agile Process and Make it Your Own</a> was originally published in <a href="https://open.nytimes.com/">NYT Open</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[2018 Web Development Predictions]]></title>
            <link>https://medium.com/hackernoon/2018-web-development-predictions-b170a9268d9a?source=rss-555725a03e9c------2</link>
            <guid isPermaLink="false">https://medium.com/p/b170a9268d9a</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[microsoft]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Olivier De Meulder]]></dc:creator>
            <pubDate>Thu, 04 Jan 2018 03:27:35 GMT</pubDate>
            <atom:updated>2019-05-13T06:50:38.333Z</atom:updated>
            <content:encoded><![CDATA[<p>Are these really predictions, or merely stuff I intend to really learn this year? Wishful thinking maybe?</p><h3>Frontend</h3><p>This is an easy one. <a href="https://hackernoon.com/tagged/react">React</a> had a meteoric rise in 2017, effectively overtaking Angular as the most popular front-end framework. Will there beanother framework that overtakes React? Looks like Vue.js is the new kid on the block. My prediction: <strong>React</strong> will continue to be the lingua franca of the front-end. Many developers love React. I just don’t see why developers would leave React in droves.</p><h3>Backend</h3><p>A few years ago Node.js made a big splash, but is now plateauing a bit. Ruby on Rails is no longer the coolest kid. Corporate still does Java. Php is still around. Python is gaining popularity, because of machine <a href="https://hackernoon.com/tagged/learning">learning</a> and because it’s fun. And by extension we’re seeing Django getting a new boost. But 2018 is the year of .NET’s explosion. Microsoft open sourced its framework a few years ago. <strong>.NET</strong> core 2.0 came out last year, and it is cross-platform. Developers are going to realize that it is no longer M$FT but that Satya Nadella really turned the company around. C# is a powerful language, there is a huge eco-system, you don’t have to use Visual Studio, you can do back-end, web, mobile apps, libraries, you can run it on linux or on your mac. Watch this space.</p><h3>Infrastructure</h3><p>Will 2018 be the year that <em>Serverless</em> becomes all the talk? Maybe, … but I don’t see an immediate mass adoption of cloud functions. My advice to developers: be prepared to learn <strong>DevOps, deployment pipelines and container orchestration services</strong>. Docker containers have been around for a while, Kubernetes was first released in 2014. It’s the way of the future. Amazon and Netflix were maybe pioneers in the space of microservices and the ‘you build it, you run it’ model. But now many companies — big and small — have caught on. It’s ready for the masses. See many legacy system being converted to containers. See hobbyists embrace it. One caveat, it’s a steep learning curve and there is a lot to learn. My prediction: someone will develop a tool or app to make deployment and container orchestration much more seamless and it will take off.</p><h3>Tying it all together</h3><p>My last prediction is pretty easy too, encompassing front-end and back-end. Rest has been around for too long without major innovation and is ripe for the taking. Enter <strong>GraphQL</strong>. I predict a majority of job listings for software engineers and web developers will list GraphQL as required. And as usual in the recruiting world, they will want to see 3–5 years of experience. (Facebook released GraphQL in 2015 :-)</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fdde502%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2Fhackernoon%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href">https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b170a9268d9a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/2018-web-development-predictions-b170a9268d9a">2018 Web Development Predictions</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I never understood JavaScript closures]]></title>
            <link>https://medium.com/dailyjs/i-never-understood-javascript-closures-9663703368e8?source=rss-555725a03e9c------2</link>
            <guid isPermaLink="false">https://medium.com/p/9663703368e8</guid>
            <category><![CDATA[closure]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Olivier De Meulder]]></dc:creator>
            <pubDate>Thu, 07 Sep 2017 12:38:59 GMT</pubDate>
            <atom:updated>2017-10-31T02:30:06.242Z</atom:updated>
            <content:encoded><![CDATA[<h4>Until someone explained it to me like this …</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*1vMy563vz6LA_67VrzeT9g.png" /></figure><p>As the title states, JavaScript closures have always been a bit of a mystery to me. I have <a href="https://medium.freecodecamp.org/lets-learn-javascript-closures-66feb44f6a44">read</a> <a href="https://medium.freecodecamp.org/whats-a-javascript-closure-in-plain-english-please-6a1fc1d2ff1c">multiple</a> <a href="https://en.wikipedia.org/wiki/Closure_(computer_programming)">articles</a>, I have used closures in my work, sometimes I even used a closure without realizing I was using a closure.</p><p>Recently I went to a talk where someone really explained it in a way it finally clicked for me. I’ll try to take this approach to explain closures in this article. Let me give credit to the great folks at <a href="https://www.codesmith.io/">CodeSmith </a>and their <em>JavaScript The Hard Parts</em> series.</p><h4>Before we start</h4><p>Some concepts are important to grok before you can grok closures. One of them is the <em>execution context</em>.</p><p><a href="http://davidshariff.com/blog/what-is-the-execution-context-in-javascript/">This article</a> has a very good primer on Execution Context. To quote the article:</p><blockquote>When code is run in JavaScript, the environment in which it is executed is very important, and is evaluated as 1 of the following:</blockquote><blockquote><strong>Global code</strong> — The default environment where your code is executed for the first time.</blockquote><blockquote><strong>Function code</strong> — Whenever the flow of execution enters a function body.</blockquote><blockquote>(…)</blockquote><blockquote>(…), let’s think of the term execution context as the environment / scope the current code is being evaluated in.</blockquote><p>In other words, as we start the program, we start in the global execution context. Some variables are declared within the global execution context. We call these global variables. When the program calls a function, what happens? A few steps:</p><ol><li>JavaScript creates a new execution context, a local execution context</li><li>That local execution context will have its own set of variables, these variables will be local to that execution context.</li><li>The new execution context is thrown onto the <em>execution stack</em>. Think of the execution stack as a mechanism to keep track of where the program is in its execution</li></ol><p>When does the function end? When it encounters a return statement or it encounters a closing bracket }. When a function ends, the following happens:</p><ol><li>The local execution contexts pops off the execution stack</li><li>The functions sends the return value back to the calling context. The calling context is the execution context that called this function, it could be the global execution context or another local execution context. It is up to the calling execution context to deal with the return value at that point. The returned value could be an object, an array, a function, a boolean, anything really. If the function has no return statement, undefined is returned.</li><li>The local execution context is destroyed. This is important. Destroyed. All the variables that were declared within the local execution context are erased. They are no longer available. That’s why they’re called local variables.</li></ol><h4>A very basic example</h4><p>Before we get to closures, let’s take a look at the following piece of code. It seems very straightforward, anybody reading this article probably knows exactly what it does.</p><pre>1: let a = 3<br>2: function addTwo(x) {<br>3:   let ret = x + 2<br>4:   return ret<br>5: }<br>6: let b = addTwo(a)<br>7: console.log(b)</pre><p>In order to understand how the JavaScript engine really works, let’s break this down in great detail.</p><ol><li>On line 1 we declare a new variable a in the global execution context and assign it the number 3.</li><li>Next it gets tricky. Lines 2 through 5 are really together. What happens here? We declare a new variable named addTwo in the global execution context. And what do we assign to it? A function definition. Whatever is between the two brackets { } is assigned to addTwo. The code inside the function is not evaluated, not executed, just stored into a variable for future use.</li><li>So now we’re at line 6. It looks simple, but there is much to unpack here. First we declare a new variable in the global execution context and label it b. As soon as a variable is declared it has the value of undefined.</li><li>Next, still on line 6, we see an assignment operator. We are getting ready to assign a new value to the variable b. Next we see a function being called. When you see a variable followed by round brackets (…), that’s the signal that a function is being called. Flash forward, every function returns something (either a value, an object or undefined). Whatever is returned from the function will be assigned to variable b.</li><li>But first we need to call the function labeled addTwo. JavaScript will go and look in its <em>global</em> execution context memory for a variable named addTwo. Oh, it found one, it was defined in step 2 (or lines 2–5). And lo and behold variable addTwo contains a function definition. Note that the variable a is passed as an argument to the function. JavaScript searches for a variable a in its <em>global</em> execution context memory, finds it, finds that its value is 3 and passes the number 3 as an argument to the function. Ready to execute the function.</li><li>Now the execution context will switch. A new local execution context is created, let’s name it the ‘addTwo execution context’. The execution context is pushed onto the call stack. What is the first thing we do in the local execution context?</li><li>You may be tempted to say, “A new variable ret is declared in the <em>local</em> execution context”. That is not the answer. The correct answer is, we need to look at the parameters of the function first. A new variable x is declared in the local execution context. And since the value 3 was passed as an argument, the variable x is assigned the number 3.</li><li>The next step is: A new variable ret is declared in the <em>local</em> execution context. Its value is set to undefined. (line 3)</li><li>Still line 3, an addition needs to be performed. First we need the value of x. JavaScript will look for a variable x. It will look in the local execution context first. And it found one, the value is 3. And the second operand is the number2. The result of the addition (5) is assigned to the variable ret.</li><li>Line 4. We return the content of the variable ret. Another lookup in the <em>local</em> execution context. ret contains the value 5. The function returns the number 5. And the function ends.</li><li>Lines 4–5. The function ends. The local execution context is destroyed. The variables x and ret are wiped out. They no longer exist. The context is popped of the call stack and the return value is returned to the calling context. In this case the calling context is the global execution context, because the function addTwo was called from the global execution context.</li><li>Now we pick up where we left off in step 4. The returned value (number 5) gets assigned to the variable b. We are still at line 6 of the little program.</li><li>I am not going into detail, but in line 7, the content of variable b gets printed in the console. In our example the number 5.</li></ol><p>That was a very long winded explanation for a very simple program, and we haven’t even touched upon closures yet. We will get there I promise. But first we need to take another detour or two.</p><h4>Lexical scope.</h4><p>We need to understand some aspects of lexical scope. Take a look at the following example.</p><pre>1: let val1 = 2<br>2: function multiplyThis(n) {<br>3:   let ret = n * val1<br>4:   return ret<br>5: }<br>6: let multiplied = multiplyThis(6)<br>7: console.log(&#39;example of scope:&#39;, multiplied)</pre><p>The idea here is that we have variables in the local execution context and variables in the global execution context. One intricacy of JavaScript is how it looks for variables. If it can’t find a variable in its <em>local</em> execution context, it will look for it in <em>its</em> calling context. And if not found there in <em>its</em> calling context. Repeatedly, until it is looking in the <em>global</em> execution context. (And if it does not find it there, it’s undefined). Follow along with the example above, it will clarify it. If you understand how scope works, you can skip this.</p><ol><li>Declare a new variable val1 in the global execution context and assign it the number 2.</li><li>Lines 2–5. Declare a new variable multiplyThis and assign it a function definition.</li><li>Line 6. Declare a new variable multiplied in the global execution context.</li><li>Retrieve the variable multiplyThis from the global execution context memory and execute it as a function. Pass the number 6 as argument.</li><li>New function call = new execution context. Create a new local execution context.</li><li>In the local execution context, declare a variable n and assign it the number 6.</li><li>Line 3. In the local execution context, declare a variable ret.</li><li>Line 3 (continued). Perform an multiplication with two operands; the content of the variables n and val1. Look up the variable n in the local execution context. We declared it in step 6. Its content is the number 6. Look up the variable val1 in the local execution context. The local execution context does not have a variable labeled val1. Let’s check the calling context. The calling context is the global execution context. Let’s look for val1 in the global execution context. Oh yes, it’s there. It was defined in step 1. The value is the number 2.</li><li>Line 3 (continued). Multiply the two operands and assign it to the ret variable. 6 * 2 = 12. ret is now 12.</li><li>Return the ret variable. The local execution context is destroyed, along with its variables ret and n. The variable val1 is not destroyed, as it was part of the global execution context.</li><li>Back to line 6. In the calling context, the number 12 is assigned to the multiplied variable.</li><li>Finally on line 7, we show the value of the multiplied variable in the console.</li></ol><p>So in this example, we need to remember that a function has access to variables that are defined in its calling context. The formal name of this phenomenon is the lexical scope.</p><h4>A function that returns a function</h4><p>In the first example the function addTwo returns a number. Remember from earlier that a function can return anything. Let’s look at an example of a function that returns a function, as this is essential to understand closures. Here is the example that we are going to analyze.</p><pre> 1: let val = 7<br> 2: function createAdder() {<br> 3:   function addNumbers(a, b) {<br> 4:     let ret = a + b<br> 5:     return ret<br> 6:   }<br> 7:   return addNumbers<br> 8: }<br> 9: let adder = createAdder()<br>10: let sum = adder(val, 8)<br>11: console.log(&#39;example of function returning a function: &#39;, sum)</pre><p>Let’s go back to the step-by-step breakdown.</p><ol><li>Line 1. We declare a variable val in the global execution context and assign the number 7 to that variable.</li><li>Lines 2–8. We declare a variable named createAdder in the global execution context and we assign a function definition to it. Lines 3 to 7 describe said function definition. As before, at this point, we are not jumping into that function. We just store the function definition into that variable (createAdder).</li><li>Line 9. We declare a new variable, named adder, in the global execution context. Temporarily, undefined is assigned to adder.</li><li>Still line 9. We see the brackets (); we need to execute or call a function. Let’s query the global execution context’s memory and look for a variable named createAdder. It was created in step 2. Ok, let’s call it.</li><li>Calling a function. Now we’re at line 2. A new local execution context is created. We can create local variables in the new execution context. The engine adds the new context to the call stack. The function has no arguments, let’s jump right into the body of it.</li><li>Still lines 3–6. We have a new function declaration. We create a variable addNumbers in the local execution context. This important. addNumbers exists only in the local execution context. We store a function definition in the local variable named addNumbers.</li><li>Now we’re at line 7. We return the content of the variable addNumbers. The engine looks for a variable named addNumbers and finds it. It’s a function definition. Fine, a function can return anything, including a function definition. So we return the definition of addNumbers. Anything between the brackets on lines 4 and 5 makes up the function definition. We also remove the local execution context from the call stack.</li><li>Upon return, the local execution context is destroyed. The addNumbers variable is no more. The function definition still exists though, it is returned from the function and it is assigned to the variable adder; that is the variable we created in step 3.</li><li>Now we’re at line 10. We define a new variable sum in the global execution context. Temporary assignment is undefined.</li><li>We need to execute a function next. Which function? The function that is defined in the variable named adder. We look it up in the global execution context, and sure enough we find it. It’s a function that takes two parameters.</li><li>Let’s retrieve the two parameters, so we can call the function and pass the correct arguments. The first one is the variable val, which we defined in step 1, it represents the number 7, and the second one is the number 8.</li><li>Now we have to execute that function. The function definition is outlined lines 3–5. A new local execution context is created. Within the local context two new variables are created: a and b. They are respectively assigned the values 7 and 8, as those were the arguments we passed to the function in the previous step.</li><li>Line 4. A new variable is declared, named ret. It is declared in the local execution context.</li><li>Line 4. An addition is performed, where we add the content of variable a and the content of variable b. The result of the addition (15) is assigned to the ret variable.</li><li>The ret variable is returned from that function. The local execution context is destroyed, it is removed from the call stack, the variables a, b and ret no longer exist.</li><li>The returned value is assigned to the sum variable we defined in step 9.</li><li>We print out the value of sum to the console.</li></ol><p>As expected the console will print 15. We really go through a bunch of hoops here. I am trying to illustrate a few points here. First, a function definition can be stored in a variable, the function definition is invisible to the program until it gets called. Second, every time a function gets called, a local execution context is (temporarily) created. That execution context vanishes when the function is done. A function is done when it encounters return or the closing bracket }.</p><h4>Finally, a closure</h4><p>Take a look a the next code and try to figure out what will happen.</p><pre> 1: function createCounter() {<br> 2:   let counter = 0<br> 3:   const myFunction = function() {<br> 4:     counter = counter + 1<br> 5:     return counter<br> 6:   }<br> 7:   return myFunction<br> 8: }<br> 9: const increment = createCounter()<br>10: const c1 = increment()<br>11: const c2 = increment()<br>12: const c3 = increment()<br>13: console.log(&#39;example increment&#39;, c1, c2, c3)</pre><p>Now that we got the hang of it from the previous two examples, let’s zip through the execution of this, as we expect it to run.</p><ol><li>Lines 1–8. We create a new variable createCounter in the global execution context and it get’s assigned function definition.</li><li>Line 9. We declare a new variable named increment in the global execution context..</li><li>Line 9 again. We need call the createCounter function and assign its returned value to the increment variable.</li><li>Lines 1–8 . Calling the function. Creating new local execution context.</li><li>Line 2. Within the local execution context, declare a new variable named counter. Number 0 is assigned to counter.</li><li>Line 3–6. Declaring new variable named myFunction. The variable is declared in the local execution context. The content of the variable is yet another function definition. As defined in lines 4 and 5.</li><li>Line 7. Returning the content of the myFunction variable. Local execution context is deleted. myFunction and counter no longer exist. Control is returned to the calling context.</li><li>Line 9. In the calling context, the global execution context, the value returned by createCounter is assigned to increment. The variable increment now contains a function definition. The function definition that was returned by createCounter. It is no longer labeled myFunction, but it is the same definition. Within the global context, it is labeledincrement.</li><li>Line 10. Declare a new variable (c1).</li><li>Line 10 (continued). Look up the variable increment, it’s a function, call it. It contains the function definition returned from earlier, as defined in lines 4–5.</li><li>Create a new execution context. There are no parameters. Start execution the function.</li><li>Line 4. counter = counter + 1. Look up the value counter in the local execution context. We just created that context and never declare any local variables. Let’s look in the global execution context. No variable labeled counter here. Javascript will evaluate this as counter = undefined + 1, declare a new local variable labeled counter and assign it the number 1, as undefined is sort of 0.</li><li>Line 5. We return the content of counter, or the number 1. We destroy the local execution context, and the counter variable.</li><li>Back to line 10. The returned value (1) gets assigned to c1.</li><li>Line 11. We repeat steps 10–14, c2 gets assigned 1 also.</li><li>Line 12. We repeat steps 10–14, c3 gets assigned 1 also.</li><li>Line 13. We log the content of variables c1, c2 and c3.</li></ol><p>Try this out for yourself and see what happens. You’ll notice that it is not logging 1, 1, and 1 as you may expect from my explanation above. Instead it is logging 1, 2 and 3. So what gives?</p><p>Somehow, the increment function remembers that counter value. How is that working?</p><p>Is counter part of the global execution context? Try console.log(counter) and you’ll get undefined. So that’s not it.</p><p>Maybe, when you call increment, somehow it goes back to the the function where it was created (createCounter)? How would that even work? The variable increment contains the function definition, not where it came from. So that’s not it.</p><p>So there must be another mechanism. <strong>The Closure.</strong> We finally got to it, the missing piece.</p><p>Here is how it works. Whenever you declare a new function and assign it to a variable, you store the function definition, <em>as well as a closure</em>. The closure contains all the variables that are in scope at the time of creation of the function. It is analogous to a backpack. A function definition comes with a little backpack. And in its pack it stores all the variables that were in scope at the time that the function definition was created.</p><p>So our explanation above was <em>all wrong</em>, let’s try it again, but correctly this time.</p><pre>1: function createCounter() {<br> 2:   let counter = 0<br> 3:   const myFunction = function() {<br> 4:     counter = counter + 1<br> 5:     return counter<br> 6:   }<br> 7:   return myFunction<br> 8: }<br> 9: const increment = createCounter()<br>10: const c1 = increment()<br>11: const c2 = increment()<br>12: const c3 = increment()<br>13: console.log(&#39;example increment&#39;, c1, c2, c3)</pre><ol><li>Lines 1–8. We create a new variable createCounter in the global execution context and it get’s assigned function definition. Same as above.</li><li>Line 9. We declare a new variable named increment in the global execution context. Same as above.</li><li>Line 9 again. We need call the createCounter function and assign its returned value to the increment variable. Same as above.</li><li>Lines 1–8 . Calling the function. Creating new local execution context. Same as above.</li><li>Line 2. Within the local execution context, declare a new variable named counter. Number 0 is assigned to counter. Same as above.</li><li>Line 3–6. Declaring new variable named myFunction. The variable is declared in the local execution context. The content of the variable is yet another function definition. As defined in lines 4 and 5. Now we also create a <em>closure</em> and include it as part of the function definition. The closure contains the variables that are in scope, in this case the variable counter (with the value of 0).</li><li>Line 7. Returning the content of the myFunction variable. Local execution context is deleted. myFunction and counter no longer exist. Control is returned to the calling context. So we are returning the function definition <em>and its closure</em>, the backpack with the variables that were in scope when it was created.</li><li>Line 9. In the calling context, the global execution context, the value returned by createCounter is assigned to increment. The variable increment now contains a function definition (and closure). The function definition that was returned by createCounter. It is no longer labeled myFunction, but it is the same definition. Within the global context, it is called increment.</li><li>Line 10. Declare a new variable (c1).</li><li>Line 10 (continued). Look up the variable increment, it’s a function, call it. It contains the function definition returned from earlier, as defined in lines 4–5. (and it also has a backpack with variables)</li><li>Create a new execution context. There are no parameters. Start execution the function.</li><li>Line 4. counter = counter + 1. We need to look for the variable counter. Before we look in the <em>local</em> or <em>global</em> execution context, let’s look in our backpack. Let’s check the closure. Lo and behold, the closure contains a variable named counter, its value is 0. After the expression on line 4, its value is set to 1. And it is stored in the backpack again. The closure now contains the variable counter with a value of 1.</li><li>Line 5. We return the content of counter, or the number 1. We destroy the local execution context.</li><li>Back to line 10. The returned value (1) gets assigned to c1.</li><li>Line 11. We repeat steps 10–14. This time, when we look at our closure, we see that the counter variable has a value of 1. It was set in step 12 or line 4 of the program. Its value gets incremented and stored as 2 in the closure of the increment function. And c2 gets assigned 2.</li><li>Line 12. We repeat steps 10–14, c3 gets assigned 3.</li><li>Line 13. We log the content of variables c1, c2 and c3.</li></ol><p>So now we understand how this works. The key to remember is that when a function gets declared, it contains a function definition and a closure. The closure is a collection of all the variables in scope at the time of creation of the function.</p><p>You may ask, does any function has a closure, even functions created in the global scope? The answer is yes. Functions created in the global scope create a closure. But since these functions were created in the global scope, they have access to all the variables in the global scope. And the closure concept is not really relevant.</p><p>When a function returns a function, that is when the concept of closures becomes more relevant. The returned function has access to variables that are not in the global scope, but they solely exist in its closure.</p><h4>Not so trivial closures</h4><p>Sometimes closures show up when you don’t even notice it. You may have seen an example of what we call partial application. Like in the following code.</p><pre>let c = 4<br>const addX = x =&gt; n =&gt; n + x<br>const addThree = addX(3)<br>let d = addThree(c)<br>console.log(&#39;example partial application&#39;, d)</pre><p>In case the arrow function throws you off, here is the equivalent.</p><pre>let c = 4<br>function addX(x) {<br>  return function(n) {<br>     return n + x<br>  }<br>}<br>const addThree = addX(3)<br>let d = addThree(c)<br>console.log(&#39;example partial application&#39;, d)</pre><p>We declare a generic adder function addX that takes one parameter (x) and returns another function.</p><p>The returned function also takes one parameter and adds it to the variable x.</p><p>The variable x is part of the closure. When the variable addThree gets declared in the local context, it is assigned a function definition and a closure. The closure contains the variable x.</p><p>So now when addThree is called and executed, it has access to the variable x from its closure and the variable n which was passed as an argument and is able to return the sum.</p><p>In this example the console will print the number 7.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZrJKJqBsksWd-8uKM9OvgA.png" /></figure><h4>Conclusion</h4><p>The way I will always remember closures is through <strong>the backpack analogy</strong>. When a function gets created and passed around or returned from another function, it carries a backpack with it. And in the backpack are all the variables that were in scope when the function was declared.</p><blockquote><em>If you enjoyed reading this, don’t forget the applause. 👏</em> <br>Thank you.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9663703368e8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dailyjs/i-never-understood-javascript-closures-9663703368e8">I never understood JavaScript closures</a> was originally published in <a href="https://medium.com/dailyjs">DailyJS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I Promise you a Miracle]]></title>
            <link>https://medium.com/hackernoon/i-promise-you-a-miracle-396301751c4b?source=rss-555725a03e9c------2</link>
            <guid isPermaLink="false">https://medium.com/p/396301751c4b</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[promises]]></category>
            <dc:creator><![CDATA[Olivier De Meulder]]></dc:creator>
            <pubDate>Tue, 05 Sep 2017 19:37:12 GMT</pubDate>
            <atom:updated>2019-05-13T06:50:41.621Z</atom:updated>
            <content:encoded><![CDATA[<h4>I am rolling my own JavaScript promise.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*e2gbdD2YoTUoNJhocvdI3g.png" /></figure><p>Sometimes, when you really want to understand something, it’s worth trying to build it yourself. That is what I do with promises in this article. I am trying to build a very basic ‘Promise’.</p><h4>At first there were callbacks …</h4><p>Let’s begin with the basics, before anybody heard of promises, we had callbacks. Take a look at the following snippet.</p><pre>const testUrl = &#39;<a href="https://api.github.com/users/odemeulder">https://api.github.com/users/odemeulder</a>&#39;<br>const fetchData = (url, callback) =&gt; {<br>  let xhr = new XMLHttpRequest()<br>  xhr.onreadystatechange = () =&gt; {<br>    if (xhr.readyState == 200 ) { <br>      callback(xhr.responseText)<br>    }<br>  }<br>  xhr.open(url)<br>  xhr.send()<br>}<br>fetchData(testUrl, response =&gt; console.log(response) )</pre><p>What does it do? It creates a very simple<a href="https://hackernoon.com/tagged/function"> function</a> that takes a url, reads it using the XMLHttpRequest and allows a callback function to do something with the result. And in the last line, we call our new function; as a callback we provide a function that prints out the response. Very simple. If you are not familiar with XMLHttpRequest, don’t fret, it is not important to understand for the rest of the article. Just know that it is the object that the browser provides to <a href="https://hackernoon.com/tagged/javascript">JavaScript</a> to perform http requests. It is an asynchronous function, it takes a callback when the onreadystatechange event fires.</p><h4>What does a promise look like?</h4><p>Before diving into writing our own promise, let’s see what the end result should look like. What is the call signature?</p><pre>function fetchDataReturningPromise(url) {<br>  // what happens here?<br>}</pre><pre>function functionWithDelay(arg) {<br>  // what happens here?<br>}</pre><pre>fetchDataReturningPromise(url).then(response =&gt; console.log(response))<br>// or<br>functionWithDelay(arg1).then(performFollowUpOperation)<br>// or<br>functionWithDelay(arg1).then((resolvedValue) =&gt;<br>  PerformFollowUpOperation(resolvedValue))</pre><p>What do we have here? Let’s focus on the third example.</p><p>We have a function with a delay; something inside the function makes an asynchronous call. It could be a timeout, an http request, a database call.</p><p>That function returns ‘something’. That something has a then method, so ‘something’ must be an object. In fact ‘something’ will be a function.</p><p>The then function takes one argument, in the form of a function or a callback. And the callback passed into the then function does not get executed until functionWithDelay is done. In our third example the function we pass to then is labeled performFollowUpOperation. Note that performFollowUpOperation takes one argument (resolvedValue) and that argument is provided by functionWithDelay. Lots to unpack here. Pause, and re-read previous paragraph (if you’d like to).</p><p>In summary:</p><ol><li>Define a function with a next function.</li></ol><p>2. Define a function with a delay that returns a function with a next function (functionWithDelay)</p><p>3. The function with a next function needs to take another function as an argument. That follow-up function cannot be executed until the function with delay is done. (performFollowUpOperation)</p><p>4. The function with delay must somehow pass a value to the follow-up function.</p><p>So now we need to fill in functionWithDelay, first we need to define that thing that has a next function.</p><h4>First naieve attempt</h4><p>Let’s make a first attempt.</p><pre> 1: function FunctionWithAThenFunction() {<br> 2:  this.then = function (followUpFunction) {<br> 3:     followUpFunction()<br> 4:   }<br> 5: }</pre><pre> 6: function functionWithDelay(param1) {<br> 7:   let xhr = new XMLHttpRequest()<br> 8:   xhr.onreadystatechange = () =&gt; {<br> 9:     if (xhr.readyState == 200) callback(xhr.responseText)<br>10:   }<br>11:   xhr.open(param1)<br>12:   xhr.send()<br>13:   return new FunctionWithAThenFunction()<br>14: }</pre><p>All right, we have a function with a then function. Our functionWithDelay returns a function with a then function. But. What is callback on line 9? Somehow that followUpFunction should end up in the callback. That is not happening. Therefor, the followUpFunction is going to execute right away and not wait until functionWithDelay is done.</p><p>How do we get that followUpFunction to be callback?</p><h4>Second attempt</h4><p>Let’s take a look at functionWithDelay. What is characteristic about a function with a delay? Or what is characteristic about asynchronous functions? They will often take a callback in some way. So let’s try to re-write that function as accepting a callback, such that we can access that callback easily.</p><p>And then let’s rewrite our FunctionWithAThenFunction and let it accept an function, more specifically an asynchronous function with callback.</p><pre>1: function FunctionWithAThenFunction(aFnWithDelayAndACallback){<br> 2:   let nextThingToDo<br> 3:   this.then = function ( followUpFunction) {<br> 4:     nextThingToDo = followUpFunction<br> 5:   }<br> 6:   aFnWithDelayAndACallback( nextThingToDo )<br> 7: }<br> 8: function functionWithDelay(param1) {<br> 9:   const httpRequestWithCallback = function (callback) {<br>10:     let xhr = XMLHttpRequest()<br>11:     xhr.onreadystatechange = () =&gt; {<br>12:       if (xhr.readyState == 200) callback(xhr.responseText)<br>13:     }<br>14:     xhr.open(param1)<br>15:     xhr.send()<br>16:   }<br>17:   return new FunctionWithAThenFunction(httpRequestWithCallback)<br>18: }<br>19: functionWithDelay(&#39;some argument&#39;).then(console.log)</pre><p>Lines 1–7 define our FunctionWithAThenFunction. That is the function that will be returned by the function with a delay. And it expects a function as an argument. More specifically a function with a callback. The then function then sets the callback in a local variable (nextThingToDo). And that function really does one thing and that is to call the function with the callback, in our example the function labeled aFnWithDelayAndACallback.</p><p>Lines 8–18 define our functionWithDelay. In our example the function that does an http request and returns something with a then function. And that something with a then function is a new instance of FunctionWithAThenFunction. It looks a little different than what we did above. We create a new local temporary function named httpRequestWithCallback, which accepts a callback argument and wraps the entire XMLHttpRequest code from the prior examples. That new local function is then passed as an argument to FunctionWithAThenFunction.</p><p>Now, if you try to run this (line 19), it will still not accomplish what we are trying to do. If you follow along, you will see that nextThingToDo is undefined as we are calling it before we get a chance to assign it a value. We are missing one thing and that is some kind of status.</p><h4>Third Attempt</h4><p>Let’s add a variable that keeps track of the status of execution.</p><pre>1: function FunctionWithAThenFunction(aFnWithDelayAndACallback){<br> 2:   let nextThingToDo<br> 3:   let status = &#39;pending&#39;<br> 4:   this.then = function ( followUpFunction) {<br> 5:     if (status === &#39;pending&#39;) {<br> 6:       nextThingToDo = followUpFunction<br> 7:     }<br> 8:     else {<br> 9:       followUpFunction()<br>10:     }<br>11:   }<br>12:   aFnWithDelayAndACallback( (newValue) =&gt; { <br>13:      status = &#39;resolved&#39;<br>14:      nextThingToDo(newValue)<br>15:   })<br>16: }<br>17: function functionWithDelay(param1) {<br>18:   const httpRequestWithCallback = function (callback) {<br>19:     let xhr = XMLHttpRequest()<br>20:     xhr.onreadystatechange = () =&gt; {<br>21:       if (xhr.readyState == 200) callback(xhr.responseText)<br>22:     }<br>23:     xhr.open(param1)<br>24:     xhr.send()<br>25:   }<br>26:   return new FunctionWithAThenFunction(httpRequestWithCallback)<br>27: }<br>28: functionWithDelay(&#39;some argument&#39;).then(console.log)</pre><p>You see that we declare a status variable (line 3). This way we cover all of our basis. If then is called before the main function is done, we store the followUpFunction in a variable, if not we can safely execute it. But it does not have the value from the main function. Let’s fix that.</p><pre>1: function FunctionWithAThenFunction(aFnWithDelayAndACallback){<br> 2:   let nextThingToDo, value<br> 3:   let status = &#39;pending&#39;<br> 4:   this.then = function ( followUpFunction) {<br> 5:     if (status === &#39;pending&#39;) {<br> 6:       nextThingToDo = followUpFunction<br> 7:     }<br> 8:     else {<br> 9:       followUpFunction(value)<br>10:     }<br>11:   }<br>12:   aFnWithDelayAndACallback( (newValue) =&gt; { <br>13:      status = &#39;resolved&#39;<br>14:      value = newValue<br>15:      nextThingToDo(newValue)<br>16:   })<br>17: }<br>18: function functionWithDelay(param1) {<br>19:   const httpRequestWithCallback = function (callback) {<br>20:     let xhr = XMLHttpRequest()<br>21:     xhr.onreadystatechange = () =&gt; {<br>22:       if (xhr.readyState == 200) callback(xhr.responseText)<br>23:     }<br>24:     xhr.open(param1)<br>25:     xhr.send()<br>26:   }<br>27:   return new FunctionWithAThenFunction(httpRequestWithCallback)<br>28: }<br>29: functionWithDelay(&#39;some argument&#39;).then(console.log)</pre><p>Here we declare a new local variable named value. (line 2) When we resolve the main function we set that value. So it can be passed as a parameter to followUpFunction on line 9.</p><p>Speaking of resolving, let’s add re-write this for clarity. No change in functionality with the previous sample.</p><pre>1: function FunctionWithAThenFunction(aFnWithDelayAndACallback){<br> 2:   let nextThingToDo, value<br> 3:   let status = &#39;pending&#39;<br> 4:   this.then = function ( followUpFunction) {<br> 5:     if (status === &#39;pending&#39;) {<br> 6:       nextThingToDo = followUpFunction<br> 7:     }<br> 8:     else {<br> 9:       followUpFunction(value)<br>10:     }<br>11:   }<br>12:   const resolve = newValue =&gt; {<br>13:     value = newValue<br>14:     status = &#39;resolved&#39;<br>15:     if (nextThingToDo) nextThingToDo(newValue)<br>16:   }<br>17:   aFnWithDelayAndACallback(resolve)<br>17: }<br>18: function functionWithDelay(param1) {<br>19:   const httpRequestWithCallback = function (callback) {<br>20:     let xhr = XMLHttpRequest()<br>21:     xhr.onreadystatechange = () =&gt; {<br>22:       if (xhr.readyState == 200) callback(xhr.responseText)<br>23:     }<br>24:     xhr.open(param1)<br>25:     xhr.send()<br>26:   }<br>27:   return new FunctionWithAThenFunction(httpRequestWithCallback)<br>28: }<br>29: functionWithDelay(&#39;some argument&#39;).then(console.log)</pre><p>Here we introduce the local resolve function for clarity on lines 12–16. It is subsequently called on line 17.</p><h4>Putting it all together</h4><p>We’ve come a long way. Let’s re-write the last example one more time and change the function names a little bit.</p><ul><li>FunctionWithAThenFunction becomes Promise</li><li>functionWithDelay becomes fetchData</li><li>httpRequestWithCallback becomes httpRequest</li><li>aFnWithDelayAndACallback becoms fn</li></ul><pre>function Promise(fn){<br>   let nextThingToDo, value<br>   let status = &#39;pending&#39;<br>   this.then = function ( callback ) {<br>     if (status === &#39;pending&#39;) {<br>       nextThingToDo = callback<br>     }<br>     else {<br>       callback(value)<br>     }<br>   }<br>   const resolve = newValue =&gt; {<br>     value = newValue<br>     status = &#39;resolved&#39;<br>     if (nextThingToDo) nextThingToDo(newValue)<br>   }<br>   fn(resolve)<br> }<br>function fetchData(url) {<br>  const httpRequest = function (callback) {<br>    let xhr = XMLHttpRequest()<br>    xhr.onreadystatechange = () =&gt; {<br>      if (xhr.readyState == 200) callback(xhr.responseText)<br>    }<br>    xhr.open(url)<br>    xhr.send()<br>  }<br>  return new Promise(httpRequest)<br>}</pre><pre>const testUrl = &#39;<a href="https://api.github.com/users/odemeulder">https://api.github.com/users/odemeulder</a>&#39;<br>fetchData(testUrl).then(console.log)</pre><p>The Promise code can now be used in other functions. Let’s say you wanted to have a function similar to setTimeout that returned a promise. Let’s call the function Wait and it would accept a delay time in milliseconds.</p><pre>function Wait(milliSeconds) {<br>  const fn = (callback) =&gt; setTimeout(callback, milliSeconds)<br>  return new Promise(fn)<br>}<br>Wait(5000).then(() =&gt; console.log(&#39;we waited 5 seconds&#39;))</pre><p>Or let’s say you want to use the httpRequest example in Node. In Node XmlHttpRequest won’t work because that is an object provided by the browser, you’d have to use Node’s built in https module.</p><pre>const https = require(&#39;https&#39;)<br>const testUrl = &#39;<a href="https://api.github.com/users/odemeulder">https://api.github.com/users/odemeulder</a>&#39;<br>function fetchDataForNode(url) {<br>  const fn = callback =&gt; {<br>    const options = {<br>      url: url,<br>      headers: { &#39;User-Agent&#39;: &#39;request&#39; }<br>    }<br>    https.get(options, response =&gt; {<br>      let ret<br>      response.on(&#39;data&#39;, chunk =&gt; ret += chunk)<br>      response.on(&#39;end&#39;, () =&gt; callback(ret))<br>    })<br>  return new Promise(fn)<br>}<br>fetchDataForNode(testUrl).then(console.log)</pre><p>Again, don’t fret over the technicalities of how https.get works in node. The important part is: create a function that takes a callback and wraps an asynchronous call, and pass that function to your Promise constructor.</p><h4>Next Steps</h4><p>There is obviously much more to a promise than what we just outlined. This article is long enough already. But here are some improvements / additions.</p><p>One thing is that the then function should return a new promise. That allows you to chain promises. doSomething().then(somethingElse).then(aThirdThing)</p><p>And the other big thing that we did not go into is error handling. Our Promise function should also implement a catch function. That function would take a function as a parameter and that function would be called in case of any errors.</p><h4>Conclusion</h4><p>We created a very basic Promise object, and I showed you three examples of how to create a function that returns a promise (fetchData for browser http requests, fetchDataForNode for http requests in Node and wait). In each case, you create a function that accepts a callback, create a new Promise function and pass the function as callback.</p><p>I welcome any feedback as well as applause.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fdde502%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2Fhackernoon%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href">https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=396301751c4b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/i-promise-you-a-miracle-396301751c4b">I Promise you a Miracle</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Higher Order Functions: Behind the Scenes]]></title>
            <link>https://medium.com/hackernoon/higher-order-functions-behind-the-scenes-5853179cfd9c?source=rss-555725a03e9c------2</link>
            <guid isPermaLink="false">https://medium.com/p/5853179cfd9c</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[higher-order-function]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Olivier De Meulder]]></dc:creator>
            <pubDate>Sun, 27 Aug 2017 03:45:46 GMT</pubDate>
            <atom:updated>2019-05-13T06:50:41.794Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*0klm8TN3bY1pa_CmeNBuCw.png" /></figure><p>This post is NOT a post to show you how to use forEach, map, filter and reduce, <a href="https://hackernoon.com/tagged/nor">NOR</a> is it a post showing the benefits of higher order functions. There are plenty of <a href="https://medium.com/humans-create-software/a-dirt-simple-introduction-to-higher-order-functions-in-javascript-b33bf9e19056">other</a> <a href="https://medium.com/javascript-scene/higher-order-functions-composing-software-5365cf2cbe99">articles</a> <a href="https://medium.com/functional-javascript/higher-order-functions-78084829fff4">that</a> <a href="https://medium.freecodecamp.org/higher-order-functions-in-javascript-d9101f9cf528">do</a> that.</p><p>When I want to understand a basic concept, I like to try to <em>implement it myself</em>, even if it is a very basic version. People learn in different ways, this works for me. So let me take you on this journey as I try to create my own forEach, map, reduce and filter functions in <a href="https://hackernoon.com/tagged/javascript">JavaScript</a>.</p><h4>myForEach</h4><p>In order to disambiguate from the built-in forEach, let’s call my new function myForEach.</p><p>First thing to do is to look at the call signature. So, the forEach function you know does something like this:</p><pre>let arr = [ 1, 2, 3, 4 ]</pre><pre>// log each item of the array<br>arr.forEach(console.log)</pre><pre>// double each item of the array and log it to the console<br>arr.forEach((val) =&gt; console.log(val * 2))</pre><p>We’re sort of looking for a function that takes two parameters, an array and callback function. The callback function could be a function definition or an anonymous function. And what we want this to do is to iterate over each item in the array and call the callback on that item. So let’s give it a shot.</p><pre>function myForEach(arr, callback) {<br>  for (let i = 0; i &lt; arr.length; i++) {<br>    callback(arr[i])<br>  }<br>}</pre><pre>let arr = [ 1, 2, 3, 4 ]</pre><pre>// log each item of the array<br>myForEach(arr, console.log)</pre><pre>// double each item of the array and log it to the console<br>myForEach(arr, val =&gt; console.log(val * 2))</pre><p>Seems simple enough and it works. But … but … it’s not exactly the same. If you try arr.myForEach(console.log), you get TypeError: arr.myForEach is not a function. That is because we declared myForEach as a global function. And really, it should be part of the prototype of the Array object. Note the purpose of this article is not to explain how prototypical inheritance works. In order to achieve what we want, we need to do this as follows.</p><pre>Array.prototype.myForEach = (callback) =&gt; {<br>  for (let i = 0; i &lt; this.length; i++) {<br>    callback(arr[i])<br>  }<br>}</pre><pre>// log each item of the array<br>arr.myForEach(console.log)</pre><p>When I tried running the code above, nothing happened. What is wrong?</p><p>Trying to get to fancy with arrow functions. Arrow functions don’t have their own this or arguments binding. So when I call this inside the function definition, it does not refer to the Array object itself, as I naively expected. Here is the correct way to do it. This <a href="https://stackoverflow.com/questions/34361379/arrow-function-vs-function-declaration-expressions-are-they-equivalent-exch">StackOverflow post</a> has the explanation.</p><pre>Array.prototype.myForEach = function (callback) {<br>  for (let i = 0; i &lt; arr.length; i++) {<br>    callback(arr[i])<br>  }<br>}</pre><pre>// log each item of the array<br>arr.myForEach(console.log)</pre><p>Beautiful. Now that we have the mechanics down, we can move on to the other higher order functions.</p><h4>myMap</h4><p>The signature is as follows. Imagine we have an array of numbers, and want to get an array of the squares of these numbers.</p><pre>let arr = [ 1, 2, 3, 4 ]</pre><pre>let arrNew = arr.map(val =&gt; val * val)</pre><pre>// or <br>const squareNumber = n =&gt; n * n<br>let arrNew2 = arr.map(squareNumber)</pre><pre>console.log(arrNew)<br>// outputs [ 1, 4, 9, 16 ]</pre><p>So we we apply to an array: a function that takes a callback, and returns a new array. The callback is a function that takes an input value and usually transforms that input value into something else.</p><pre>Array.prototype.myMap = function(callback) {  <br>  let ret = []<br>  for (var i = 0; i &lt; this.length; i++) {<br>    let newVal = callback(this[i])<br>    ret.push(newVal)<br>  }<br>  return ret<br>}</pre><p>We iterate through the array (represented by this), apply the callback function, and push the resulting value onto a new array. And subsequently return that new array.</p><p>We could write this more succinctly using our new myForEach function.</p><pre>Array.prototype.myMap = function(callback) {  <br>  let ret = []<br>  this.myForEach(val =&gt; ret.push(callback(val)))<br>  return ret<br>}</pre><p>Moving on.</p><h4>myFilter</h4><p>By now we’re starting to get the hang of it. Here is the filter call signature.</p><pre>let people = [ <br>  { &#39;name&#39;: &#39;Bob&#39;, &#39;age&#39;: 70 },<br>  { &#39;name&#39;: &#39;Sue&#39;, &#39;age&#39;: 30 },<br>  { &#39;name&#39;: &#39;Joe&#39;, &#39;age&#39;: 18 } ]</pre><pre>let youngPeople = people.filter( person =&gt; person.age &lt; 69 )<br>// returns array with two objects.<br>//  [ { &#39;name&#39;: &#39;Sue&#39;, &#39;age&#39;: 30 },<br>//  { &#39;name&#39;: &#39;Joe&#39;, &#39;age&#39;: 18 } ]</pre><pre>// or<br>const isYoung = person =&gt; person.age &lt; 59<br>let youngPeople = people.filter(isYoung)</pre><p>So the filter expects a callback which returns a true or false, also referred to as a predicate. The function returns a new array. Based on our experience we can quickly whip this up.</p><pre>Array.prototype.myFilter = function(callback) {<br>  let ret = []<br>  this.myForEach( (val) =&gt; {<br>    if (callback(val) === true) ret.push(val)<br>  }<br>  return ret<br>}</pre><p>Pretty straight forward. Note I could have written if (callback(val)) instead of if (callback(val) === true), but I did this to emphasize that we expect the callback to return true or false.</p><h4>myReduce</h4><p>The reduce function is a little more complex to grok. The <a href="http://3rd hour-143">textbook</a> example of reduce is to sum elements of an array. This is what it would look like.</p><pre>let arr = [ 1, 2, 3, 4 ]</pre><pre>let sum = arr.reduce( (acc, val) =&gt; acc + val )</pre><pre>console.log(sum)<br>// prints out 10</pre><p>The callback takes two arguments, the first one is often referred to as the accumulator, and the second one is the value of a particular item of the array. In this example, the accumulator keeps a running total, and with each iteration over the array, its value is added to the accumulator. And at the end the accumulator contains the value we are trying to get.</p><p>This is what the function looks like in its most basic form.</p><pre>Array.prototype.myReduce = function (callback) {<br>  let ret<br>  this.myForEach( val =&gt; {<br>    if (ret === undefined) ret = val<br>    else ret = callback(ret, val)<br>  }<br>  return ret<br>}</pre><p>It’s a little trickier than the other higher order functions we defined above. Note how we need to check of ret is undefined or not. This brings up another point. The JavaScript reduce function lets you specify an initial value. That’s not hard to add to our function. We just add an init parameter to the function definition and set the ret variable to init initially.</p><pre>Array.prototype.myReduce = function (callback, init) {<br>  let ret = init<br>  this.myForEach( val =&gt; {<br>    if (ret === undefined) ret = val<br>    else ret = callback(ret, val)<br>  }<br>  return ret<br>}</pre><pre>const sumTwoValues = (a, b) =&gt; a + b</pre><pre>let sum = arr.myReduce( sumTwoValues , 0 ) // added 0 as an argument for initial value.</pre><pre>console.log(sum)<br>// prints 10</pre><h4>Improvements</h4><p>For each of the functions above, we could make it such that we include the index of the array element in the callback signature and make it available in the callback. This should allow us to do the following for example.</p><pre>var arr = [ 1, 2, 3, 4, 5, 6 ]</pre><pre>arr.forEach( (val, idx) =&gt; { if (idx % 2 === 0) console.log(val) }<br>// prints the value of every other item in the array.</pre><pre>arr.map( (val, idx) =&gt; idx % 2 === 0 ? val * 2 : val * 3 )<br>// create a new array where every even item has been doubled and every odd item has been trippled</pre><pre>arr.map( (val, idx) =&gt; idx == 0) <br>// return an array with only the first item </pre><p>The implementation is quite easy. In our myForEach function, we pass the value and the index to the callback. And since we use myForEach in all the other functions, we can easily include the index in the callback call.</p><pre>Array.prototype.myForEach = function(callback) {<br>  for (var i = 0; i &lt; this.length; i++) {<br>    callback(this[i], i)<br>  }<br>}</pre><pre>Array.prototype.myMap = function(callback) {<br>  let ret = []<br>  this.myForEach((val, idx) =&gt; ret.push(callback(val, idx)))<br>  return ret<br>}</pre><pre>Array.prototype.myFilter = function(callback) {<br>  let ret = []<br>  this.myForEach((val, idx) =&gt; { if (callback(val, idx)) ret.push(val)} )<br>  return ret<br>}</pre><pre>Array.prototype.myReduce = function(callback, init) {<br>  let ret = init<br>  this.myForEach( ( val, idx ) =&gt; {<br>    if (ret === undefined) ret = val<br>    else ret = callback(ret, val, idx)<br>  })<br>  return ret<br>}</pre><p>One more thing we should do is some error checking. For instance we should make sure that the callback is a function. We should check that the array is not null.</p><pre>Array.prototype.myForEach = function(callback) {<br>  if (this == null) {<br>    throw new TypeError(&#39;array is null&#39;)<br>  }<br>  if (typeof callback !== &#39;function&#39;) {<br>      throw new TypeError(callback + &#39; is not a function&#39;<br>  }<br>  for (var i = 0; i &lt; this.length; i++) {<br>    callback(this[i], i)<br>  }<br>}</pre><pre>Array.prototype.myMap = function(callback) {<br>  if (this == null) {<br>    throw new TypeError(&#39;array is null&#39;)<br>  }<br>  if (typeof callback !== &#39;function&#39;) {<br>      throw new TypeError(callback + &#39; is not a function&#39;<br>  }<br>  let ret = []<br>  this.myForEach((val, idx) =&gt; ret.push(callback(val, idx)))<br>  return ret<br>}</pre><pre>Array.prototype.myFilter = function(callback) {<br>    if (this == null) {<br>    throw new TypeError(&#39;array is null&#39;)<br>  }<br>  if (typeof callback !== &#39;function&#39;) {<br>      throw new TypeError(callback + &#39; is not a function&#39;<br>  }<br>  let ret = []<br>  this.myForEach((val, idx) =&gt; { if (callback(val, idx)) ret.push(val)} )<br>  return ret<br>}</pre><pre>Array.prototype.myReduce = function(callback, init) {<br>  if (this == null) {<br>    throw new TypeError(&#39;array is null&#39;)<br>  }<br>  if (typeof callback !== &#39;function&#39;) {<br>      throw new TypeError(callback + &#39; is not a function&#39;<br>  }<br>  let ret = init<br>  this.myForEach( ( val, idx ) =&gt; {<br>    if (ret === undefined) ret = val<br>    else ret = callback(ret, val, idx)<br>  })<br>  return ret<br>}</pre><p>That’s the end. The actual Javascript forEach, map, filter and reduce functions are a more complex. But by coding this base implementations, you may better understand how they work under the hood.</p><p>If you’ve enjoyed it, send me some love and click the heart below.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fdde502%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2Fhackernoon%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href">https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5853179cfd9c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/higher-order-functions-behind-the-scenes-5853179cfd9c">Higher Order Functions: Behind the Scenes</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fire the entire leadership team]]></title>
            <link>https://medium.com/extra-extra/fire-the-entire-leadership-team-43da7dee3f3c?source=rss-555725a03e9c------2</link>
            <guid isPermaLink="false">https://medium.com/p/43da7dee3f3c</guid>
            <category><![CDATA[politics]]></category>
            <category><![CDATA[government]]></category>
            <category><![CDATA[cabinet]]></category>
            <category><![CDATA[leadership]]></category>
            <category><![CDATA[c-suite]]></category>
            <dc:creator><![CDATA[Olivier De Meulder]]></dc:creator>
            <pubDate>Sat, 26 Aug 2017 23:15:00 GMT</pubDate>
            <atom:updated>2017-09-05T13:39:30.379Z</atom:updated>
            <content:encoded><![CDATA[<p>Take a Fortune 500 company. Let’s say Apple or Exxon or Walmart. Apple has about 100,000 employees, Walmart over 2 million employees. Such a company must have a bureaucracy, a set of systems and procedures, a reporting structure to make all their employees work in tandem towards a common goal. Ultimately the goal of a corporation is to make money. Generally speaking, the CEO, the other executives and the board lay out a vision to achieve that goal.</p><p>A corporation is run by a Chief Executive Officers and other C-level officers that report to him: Chief Financial Officer, Chief Operations Officer, Chief Marketing Officer, Chief Technical Officer. Sometimes, a company is so big, that the corporation is organized around different business units. In that case, each business unit has it’s own CEO, COO, CFO, … It may have different names, but let’s refer to the CEO and all the people that report to him as the Executive Team.</p><p>Now imagine that a catastrophe hits.</p><p>The CEO and it’s entire Executive Team are all involved in a major scandal. And not only them, but also all the people that report to directly to them. So let’s say we have a CEO and 10 members of the Executive Team. And each of these people have 10 people that report directly to them. So we’re talking a hypothetical 111 people. All of them, every single one is involved in the scandal. And. They. All. Get. Fired.</p><p>No one left at the top.</p><p>The board jumps in and they quickly, within months, replace (almost) every vacant position. Since they don’t want anybody that was involved with the previous leadership team, every position is filled with someone coming from the outside.</p><p>In the beginning it’s quite chaotic. After a year, every position is filled. People get used to the new leadership. The new leadership makes mistakes. Because 1. Everybody makes mistakes and 2. They’re new at this. But they learn from their mistakes. They get better at what they do. And finally after 3 or 4 years, some sense of normalcy returns.</p><p>And now imagine, that this same pattern would repeat itself like clockwork every 4 years. Every four years, the entire leadership of the corporation is fired and replaced with new blood.</p><p>How could a corporation function like that? Could it even?</p><p>And now you probably get what I am trying to get at. This is what we do with our government. It’s especially interesting to see at the federal government.</p><p>Every four years (or 8 years) we have a new president, new cabinet secretaries and new deputy cabinet secretaries. They all get appointed from outside the agency that they’re appointed to. Sometimes the vision of the government or agency totally changes.</p><p>And note that the federal government is way bigger than a Fortune 500 corporation.</p><p>So how can it function? The fact that he government functions at all is probably a small miracle, considering what I outlined above.</p><p>I thought about this and came to this conclusion. In the beginning I wrote “Such a company must have a bureaucracy, a set of systems and procedures, a reporting structure to make all their employees work in tandem towards a common goal.” I the case of government the reporting structure changes fundamentally every 4 years and the common goal may change as well. So all that is left are the bureaucracy and the systems and procedures. The proverbial red tape is all that keeps the government running.</p><p>Not sure where I am trying to go with this story. I just thought it was an interesting thought experiment. Imagine a major corporation or organization, whose leadership team gets eviscerated every four years. That organization is running the country.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=43da7dee3f3c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/extra-extra/fire-the-entire-leadership-team-43da7dee3f3c">Fire the entire leadership team</a> was originally published in <a href="https://medium.com/extra-extra">Extra Newsfeed</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>