<?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 Bill Sourour on Medium]]></title>
        <description><![CDATA[Stories by Bill Sourour on Medium]]></description>
        <link>https://medium.com/@BillSourour?source=rss-7f9c91ba25fb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*J491EYdY78FFq8_f.png</url>
            <title>Stories by Bill Sourour on Medium</title>
            <link>https://medium.com/@BillSourour?source=rss-7f9c91ba25fb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 15 Nov 2026 10:59:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@BillSourour/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[Elegant patterns in modern JavaScript: Ice Factory]]></title>
            <link>https://medium.com/free-code-camp/elegant-patterns-in-modern-javascript-ice-factory-4161859a0eee?source=rss-7f9c91ba25fb------2</link>
            <guid isPermaLink="false">https://medium.com/p/4161859a0eee</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[learning-to-code]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Bill Sourour]]></dc:creator>
            <pubDate>Tue, 13 Mar 2018 18:52:44 GMT</pubDate>
            <atom:updated>2019-01-23T01:19:44.325Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZO7AoQIo9jFTGGUeSsFxuQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/L-sm1B4L1Ns?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Demi DeHerrera</a> on <a href="https://unsplash.com/search/photos/ice-coffee?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>I’ve been working with JavaScript on and off since the late nineties. I didn’t really like it at first, but after the introduction of ES2015 (aka ES6), I began to appreciate JavaScript as an outstanding, dynamic programming language with enormous, expressive power.</p><p>Over time, I’ve adopted several coding patterns that have lead to cleaner, more testable, more expressive code. Now, I am sharing these patterns with you.</p><p>I wrote about the first pattern — “RORO” — in the article below. Don’t worry if you haven’t read it, you can read these in any order.</p><p><a href="https://medium.freecodecamp.org/elegant-patterns-in-modern-javascript-roro-be01e7669cbd">Elegant patterns in modern JavaScript: RORO</a></p><p>Today, I’d like to introduce you to the “Ice Factory” pattern.</p><p>An Ice Factory is just <strong>a function that creates and returns a frozen object</strong>. We’ll unpack that statement in a moment, but first let’s explore why this pattern is so powerful.</p><h3>JavaScript classes are not so classy</h3><p>It often makes sense to group related functions into a single object. For example, in an e-commerce app, we might have a cart object that exposes an addProduct function and a removeProduct function. We could then invoke these functions with cart.addProduct() and cart.removeProduct().</p><p>If you come from a Class-centric, object oriented, programming language like Java or C#, this probably feels quite natural.</p><p>If you’re new to programming — now that you’ve seen a statement like cart.addProduct(). I suspect the idea of grouping together functions under a single object is looking pretty good.</p><p>So how would we create this nice little cart object? Your first instinct with modern JavaScript might be to use a class. Something like:</p><pre>// ShoppingCart.js</pre><pre>export default class ShoppingCart {<br>  constructor({db}) {<br>    this.db = db<br>  }<br>  <br>  addProduct (product) {<br>    this.db.push(product)<br>  }<br>  <br>  empty () {<br>    this.db = []<br>  }</pre><pre>  get products () {<br>    return Object<br>      .freeze([...this.db])<br>  }</pre><pre>  removeProduct (id) {<br>    // remove a product <br>  }</pre><pre>  // other methods</pre><pre>}</pre><pre>// someOtherModule.js</pre><pre>const db = [] <br>const cart = new ShoppingCart({db})<br>cart.addProduct({ <br>  name: &#39;foo&#39;, <br>  price: 9.99<br>})</pre><blockquote><strong><em>Note</em></strong><em>: I’m using an Array for the </em><em>db parameter for simplicity’s sake. In real code this would be something like a </em><a href="http://mongoosejs.com/docs/models.html"><em>Model</em></a><em> or </em><a href="https://reallyshouldblogthis.blogspot.ca/2016/02/writing-pure-javascript-repository.html"><em>Repo</em></a><em> that interacts with an actual database.</em></blockquote><p>Unfortunately — even though this looks nice — classes in JavaScript behave quite differently from what you might expect.</p><p>JavaScript Classes will bite you if you’re not careful.</p><p>For example, objects created using the new keyword are mutable. So, you can actually <strong>re-assign</strong> a method:</p><pre>const db = []<br>const cart = new ShoppingCart({db})</pre><pre>cart.addProduct = () =&gt; &#39;nope!&#39; <br>// <strong>No Error on the line above!</strong></pre><pre>cart.addProduct({ <br>  name: &#39;foo&#39;, <br>  price: 9.99<br>}) // <strong>output: &quot;nope!&quot; FTW?</strong></pre><p>Even worse, objects created using the new keyword inherit the prototype of the class that was used to create them. So, changes to a class’ prototype affect <strong>all</strong> objects created from that class — even if a change is made <strong>after</strong> the object was created!</p><p>Look at this:</p><pre>const cart = new ShoppingCart({db: []})<br>const other = new ShoppingCart({db: []})</pre><pre>ShoppingCart.<strong>prototype<br>  </strong>.addProduct = () =&gt; ‘nope!’<br>// <strong>No Error on the line above!</strong></pre><pre>cart.addProduct({ <br>  name: &#39;foo&#39;, <br>  price: 9.99<br>}) // <strong>output: &quot;nope!&quot;</strong></pre><pre>other.addProduct({ <br>  name: &#39;bar&#39;, <br>  price: 8.88<br>}) // <strong>output: &quot;nope!&quot;</strong></pre><p>Then there&#39;s the fact that this In JavaScript is dynamically bound. So, if we pass around the methods of our cart object, we can lose the reference to this. That’s very counter-intuitive and it can get us into a lot of trouble.</p><p>A common trap is assigning an instance method to an event handler.</p><p>Consider our cart.empty method.</p><pre>empty () {<br>    this.db = []<br>  }</pre><p>If we assign this method directly to the click event of a button on our web page…</p><pre>&lt;button id=&quot;empty&quot;&gt;<br>  Empty cart<br>&lt;/button&gt;</pre><pre>---</pre><pre>document<br>  .querySelector(&#39;#empty&#39;)<br>  .addEventListener(<br>    &#39;click&#39;, <br>    cart.empty<br>  )</pre><p>… when users click the empty button, their cart will remain full.</p><p>It <strong>fails silently </strong>because this will now refer to the button instead of the cart. So, our cart.empty method ends up assigning a new property to our button called db and setting that property to [] instead of affecting the cart object’s db.</p><p>This is the kind of bug that will drive you crazy because there is no error in the console and your common sense will tell you that it should work, but it doesn’t.</p><p>To make it work we have to do:</p><pre>document<br>  .querySelector(&quot;#empty&quot;)<br>  .addEventListener(<br>    &quot;click&quot;, <br>    <strong>() =&gt; cart.empty()</strong><br>  )</pre><p>Or:</p><pre>document<br>  .querySelector(&quot;#empty&quot;)<br>  .addEventListener(<br>    &quot;click&quot;, <br>    <strong>cart.empty.bind(cart)</strong><br>  )</pre><p>I think <a href="https://medium.com/u/5b25bc58c2e">Mattias Petter Johansson</a> <a href="https://youtu.be/ImwrezYhw4w">said it best</a>:</p><blockquote><em>“</em><em>new and </em><em>this [in JavaScript] are some kind of unintuitive, weird, cloud rainbow trap.”</em></blockquote><h3>Ice Factory to the rescue</h3><p>As I said earlier,<strong> an Ice Factory is just a function that creates and returns a frozen object</strong>. With an Ice Factory our shopping cart example looks like this:</p><pre>// makeShoppingCart.js</pre><pre>export default function makeShoppingCart({<br>  db<br>}) {<br>  return Object.freeze({<br>    addProduct,<br>    empty,<br>    getProducts,<br>    removeProduct,<br>    // others<br>  })</pre><pre>  function addProduct (product) {<br>    db.push(product)<br>  }<br>  <br>  function empty () {<br>    db = []<br>  }</pre><pre>  function getProducts () {<br>    return Object<br>      .freeze([...db])<br>  }</pre><pre>  function removeProduct (id) {<br>    // remove a product<br>  }</pre><pre>  // other functions<br>}</pre><pre>// someOtherModule.js</pre><pre>const db = []<br>const cart = makeShoppingCart({ db })<br>cart.addProduct({ <br>  name: &#39;foo&#39;, <br>  price: 9.99<br>})</pre><p>Notice our “weird, cloud rainbow traps” are gone:</p><ul><li><strong>We no longer need </strong><strong>new. </strong><br>We just invoke a plain old JavaScript function to create our cart object.</li><li><strong>We no longer need </strong><strong>this. </strong><br>We can access the db object directly from our member functions.</li><li><strong>Our </strong><strong>cart object is completely immutable. </strong><br>Object.freeze() freezes the cart object so that new properties can’t be added to it, existing properties can’t be removed or changed, and the prototype can’t be changed either. Just remember that Object.freeze() is <strong>shallow</strong>, so if the object we return contains an array or another object we must make sure to Object.freeze() them as well. Also, if you’re using a frozen object outside of an <a href="https://hacks.mozilla.org/2015/08/es6-in-depth-modules/">ES Module</a>, you need to be in <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode">strict mode</a> to make sure that re-assignments cause an error rather than just failing silently.</li></ul><h3>A little privacy please</h3><p>Another advantage of Ice Factories is that they can have private members. For example:</p><pre>function makeThing(spec) {<br>  <strong>const secret = &#39;shhh!&#39;</strong></pre><pre>  return Object.freeze({<br>    doStuff<br>  })</pre><pre>  function doStuff () {<br>    // We can use both spec<br>    // and secret in here <br>  }<br>}</pre><pre><strong>// secret is not accessible out here</strong></pre><pre>const thing = makeThing()<br>thing.secret // undefined</pre><p>This is made possible because of Closures in JavaScript, which you can read more about on <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures">MDN</a>.</p><h3>A little acknowledgement please</h3><p>Although Factory Functions have been around JavaScript forever, the Ice Factory pattern was heavily inspired by some code that <a href="https://en.wikipedia.org/wiki/Douglas_Crockford">Douglas Crockford</a> showed in <a href="https://www.youtube.com/watch?v=rhV6hlL_wMc">this video</a>.</p><p>Here’s Crockford demonstrating object creation with a function he calls “constructor”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KHVORQsCaE5EJFCb9FsfGA.png" /><figcaption>Douglas Crockford demonstrating the code that inspired me.</figcaption></figure><p>My Ice Factory version of the Crockford example above would look like this:</p><pre>function makeSomething({ member }) {<br>  const { other } = makeSomethingElse() <br>  <br>  return Object.freeze({ <br>    other,<br>    method<br>  }) </pre><pre>  function method () {<br>    // code that uses &quot;member&quot;<br>  }<br>}</pre><p>I took advantage of function hoisting to put my return statement near the top, so that readers would have a nice little summary of what’s going on before diving into the details.</p><p>I also used destructuring on the spec parameter. And I renamed the pattern to “Ice Factory” so that it’s more memorable and less easily confused with the constructor function from a JavaScript class. But it’s basically the same thing.</p><p>So, credit where credit is due, thank you Mr. Crockford.</p><blockquote><strong><em>Note:</em></strong><em> It’s probably worth mentioning that Crockford considers function “hoisting” a “bad part” of JavaScript and would likely consider my version heresy. I discussed my feelings on this in a </em><a href="https://medium.freecodecamp.org/constant-confusion-why-i-still-use-javascript-function-statements-984ece0b72fd"><em>previous article</em></a><em> and more specifically, </em><a href="https://medium.com/@BillSourour/thank-you-for-your-thoughtful-response-7542ba5ff94e"><em>this comment</em></a><em>.</em></blockquote><h3>What about inheritance?</h3><p>If we tick along building out our little e-commerce app, we might soon realize that the concept of adding and removing products keeps cropping up again and again all over the place.</p><p>Along with our Shopping Cart, we probably have a Catalog object and an Order object. And all of these probably expose some version of `addProduct` and `removeProduct`.</p><p>We know that duplication is bad, so we’ll eventually be tempted to create something like a Product List object that our cart, catalog, and order can all inherit from.</p><p>But rather than extending our objects by inheriting a Product List, we can instead adopt the timeless principle offered in one of the most influential programming books ever written:</p><blockquote>“Favor object composition over class inheritance.” <br>– Design Patterns: Elements of Reusable Object-Oriented Software.</blockquote><p>In fact, the authors of that book — colloquially known as “The Gang of Four” — go on to say:</p><blockquote>“…our experience is that designers overuse inheritance as a reuse technique, and designs are often made more reusable (and simpler) by depending more on object composition.”</blockquote><p>So, here’s our product list:</p><pre>function makeProductList({ productDb }) {<br>  return Object.freeze({<br>    addProduct,<br>    empty,<br>    getProducts,<br>    removeProduct,<br>    // others<br>  )}<br> <br>  // definitions for <br>  // addProduct, etc…<br>}</pre><p>And here’s our shopping cart:</p><pre>function makeShoppingCart(productList) {<br>  return Object.freeze({<br>    items: productList,<br>    someCartSpecificMethod,<br>    // …<br>)}</pre><pre>function someCartSpecificMethod () {<br>  // code <br>  }<br>}</pre><p>And now we can just inject our Product List into our Shopping Cart, like this:</p><pre><br>const productDb = []<br>const productList = makeProductList({ productDb })</pre><pre>const cart = makeShoppingCart(productList)</pre><p>And use the Product List via the `items` property. Like:</p><pre>cart.items.addProduct()</pre><p>It may be tempting to subsume the entire Product List by incorporating its methods directly into the shopping cart object, like so:</p><pre>function makeShoppingCart({ <br>  addProduct,<br>  empty,<br>  getProducts,<br>  removeProduct,<br>  …others<br>}) {<br>  return Object.freeze({<br>    addProduct,<br>    empty,<br>    getProducts,<br>    removeProduct,<br>    someOtherMethod,<br>    …others<br>)}</pre><pre>function someOtherMethod () {<br>  // code <br>  }<br>}</pre><p>In fact, in an earlier version of this article, I did just that. But then it was pointed out to me that this is a bit dangerous (as explained <a href="https://www.reddit.com/r/programming/comments/5dxq6i/composition_over_inheritance/da8bplv/">here</a>). So, we’re better off sticking with proper object composition.</p><p>Awesome. I’m Sold!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*PfWy93k2QgidbBFVGySgwA.jpeg" /><figcaption>Careful</figcaption></figure><p>Whenever we’re learning something new, especially something as complex as software architecture and design, we tend to want hard and fast rules. We want to hear thing like “<em>always</em> do this” and “ <em>never</em> do that.”</p><p>The longer I spend working with this stuff, the more I realize that there’s no such thing as <em>always</em> and <em>never. </em>It’s about choices and trade-offs.</p><p>Making objects with an Ice Factory is slower and takes up more memory than using a class.</p><p>In the types of use case I’ve described, this won’t matter. Even though they are slower than classes, Ice Factories are still quite fast.</p><p>If you find yourself needing to create hundreds of thousands of objects in one shot, or if you’re in a situation where memory and processing power is at an extreme premium you might need a class instead.</p><p>Just remember, profile your app first and don’t prematurely optimize. Most of the time, object creation is not going to be the bottleneck.</p><p>Despite my earlier rant, Classes are not always terrible. You shouldn’t throw out a framework or library just because it uses classes. In fact, <a href="https://medium.com/u/a3a8af6addc1">Dan Abramov</a> wrote pretty eloquently about this in his article, <a href="https://medium.com/@dan_abramov/how-to-use-classes-and-sleep-at-night-9af8de78ccb4">How to use Classes and Sleep at Night</a>.</p><p>Finally, I need to acknowledge that I’ve made a bunch of opinionated style choices in the code samples I’ve presented to you:</p><ul><li><a href="https://medium.freecodecamp.org/constant-confusion-why-i-still-use-javascript-function-statements-984ece0b72fd">I use function statements instead of function expressions</a>.</li><li>I put my return statement near the top (this is made possible by my use of function statements, see above).</li><li>I name my factory function, makeX instead of createX or buildX or something else.</li><li><a href="https://medium.freecodecamp.org/elegant-patterns-in-modern-javascript-roro-be01e7669cbd">My factory function takes a single, destructured, parameter object</a>.</li><li>I don’t use semi-colons (<a href="https://github.com/twbs/bootstrap/issues/3057">Crockford would also NOT approve of that</a>)</li><li>and so on…</li></ul><p>You may make different style choices, and <a href="https://medium.freecodecamp.org/the-100-correct-coding-style-guide-5b594a1655f0">that’s okay</a>! The style is not the pattern.</p><p>The Ice Factory pattern is just: <strong>use a function to create and return a frozen object</strong>. Exactly how you write that function is up to you.</p><p>If you’ve found this article useful, please smash that applause icon a bunch of times to help spread the word. And if you want to learn more stuff like this, please sign up for my Dev Mastery newsletter below. Thanks!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F83d379%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2F83d379&amp;image=https%3A%2F%2Fe.enpose.co%2F%3Fkey%3DdRXnS9Gplk%26w%3D700%26h%3D425%26url%3Dhttps%253A%252F%252Fupscri.be%252F83d379%252F%253Fenpose&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba63f4086de68ccb7de52b0275f4038a/href">https://medium.com/media/ba63f4086de68ccb7de52b0275f4038a/href</a></iframe><h4>UPDATE 2019: Here’s a video where I use this pattern, a lot!</h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Ffy6-LSE_zjI%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dfy6-LSE_zjI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Ffy6-LSE_zjI%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/bf232eeac84900b9016186e56e6b5ca4/href">https://medium.com/media/bf232eeac84900b9016186e56e6b5ca4/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4161859a0eee" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/elegant-patterns-in-modern-javascript-ice-factory-4161859a0eee">Elegant patterns in modern JavaScript: Ice Factory</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Elegant patterns in modern JavaScript: RORO]]></title>
            <link>https://medium.com/free-code-camp/elegant-patterns-in-modern-javascript-roro-be01e7669cbd?source=rss-7f9c91ba25fb------2</link>
            <guid isPermaLink="false">https://medium.com/p/be01e7669cbd</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[learning-to-code]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Bill Sourour]]></dc:creator>
            <pubDate>Thu, 22 Feb 2018 00:14:11 GMT</pubDate>
            <atom:updated>2018-03-19T17:08:12.666Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8VFNi44ikZ172fiUYz5pGA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/mk7zhx5lFbc?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">wu yi</a> on <a href="https://unsplash.com/search/photos/elegant%20coffee?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>I wrote my first few lines of JavaScript not long after the language was invented. If you told me at the time that I would one day be writing <a href="https://medium.com/search?q=Elegant%20patterns%20in%20JavaScript">a series of articles</a> about <strong>elegant</strong> patterns in JavaScript, I would have laughed you out of the room. I thought of JavaScript as a strange little language that barely even qualified as “real programming.”</p><p>Well, a lot has changed in the 20 years since then. I now see in JavaScript what <a href="https://en.wikipedia.org/wiki/Douglas_Crockford">Douglas Crockford</a> saw when he wrote <em>JavaScript: The Good Parts</em>: “An outstanding, dynamic programming language … with enormous, expressive power.”</p><p>So, without further ado, here is a wonderful little pattern I’ve been using in my code lately. I hope you come to enjoy it as much as I have.</p><blockquote><strong><em>Please note</em></strong><em>: I’m pretty sure I did not invent any of this. Chances are I came across it in other people’s code and eventually adopted it myself.</em></blockquote><h3>Receive an object, return an object (RORO).</h3><p>Most of my functions now accept a single parameter of type object and many of them return or resolve to a value of type object as well.</p><p>Thanks in part to the <em>destructuring</em> feature introduced in ES2015, I’ve found this to be a powerful pattern. I’ve even given it the silly name, “RORO” because… branding? ¯\_(ツ)_/¯</p><blockquote><strong><em>Note: </em></strong><em>Destructuring is one of my favorite features of modern JavaScript. We’re going to be taking advantage of it quite a bit throughout this article, so if you’re not familiar with it, here’s a quick video to get you up to speed.</em></blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F-vR3a11Wzt0%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D-vR3a11Wzt0&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F-vR3a11Wzt0%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/88a40723b9f7edea573f7fc212c168d2/href">https://medium.com/media/88a40723b9f7edea573f7fc212c168d2/href</a></iframe><p>Here are some reasons why you’ll love this pattern:</p><ul><li>Named parameters</li><li>Cleaner default parameters</li><li>Richer return values</li><li>Easy function composition</li></ul><p>Let’s look at each one.</p><h4>Named Parameters</h4><p>Suppose we have a function that returns a list of Users in a given Role and suppose we need to provide an option for including each User’s Contact Info and another option for including Inactive Users, traditionally we might write:</p><pre>function findUsersByRole (<br>  role, <br>  withContactInfo, <br>  includeInactive<br>) {...}</pre><p>A call to this function might then look like:</p><pre>findUsersByRole(<br>  &#39;admin&#39;, <br>  true, <br>  true<br>)</pre><p>Notice how ambiguous those last two parameters are. What does “true, true” refer to?</p><p>What happens if our app almost never needs Contact Info but almost always needs Inactive Users? We have to contend with that middle parameter all the time, even though it’s not really relevant (more on that later).</p><p>In short, this traditional approach leaves us with potentially ambiguous, noisy code that’s harder to understand and trickier to write.</p><p>Let’s see what happens when we receive a single object instead:</p><pre>function findUsersByRole (<strong>{</strong><br>  role,<br>  withContactInfo, <br>  includeInactive<br><strong>}</strong>) {...}</pre><p>Notice our function looks almost identical except that <strong>we’ve put braces around our parameters</strong>. This indicates that instead of receiving three distinct parameters, our function now expects a single object with properties named role, withContactInfo, and includeInactive.</p><p>This works because of a JavaScript feature introduced in ES2015 called <em>Destructuring</em>.</p><p>Now we can call our function like this:</p><pre>findUsersByRole({<br>  role: &#39;admin&#39;, <br>  withContactInfo: true, <br>  includeInactive: true<br>})</pre><p>This is far less ambiguous and a lot easier to read and understand. Plus, omitting or re-ordering our parameters is no longer an issue since they are now the named properties of an object.</p><p>For example, this works:</p><pre>findUsersByRole({<br>  withContactInfo: true,<br>  role: &#39;admin&#39;, <br>  includeInactive: true<br>})</pre><p>And so does this:</p><pre>findUsersByRole({<br>  role: &#39;admin&#39;, <br>  includeInactive: true<br>})</pre><p>This also makes it possible to add new parameters without breaking old code.</p><p>One important note here is that if we want all the parameters to be optional, in other words, if the following is a valid call…</p><pre>findUsersByRole()</pre><p>… we need to set a default value for our parameter object, like so:</p><pre>function findUsersByRole ({<br>  role,<br>  withContactInfo, <br>  includeInactive<br>} <strong>= {}</strong>) {...}</pre><p>An added benefit of using destructuring for our parameter object is that it promotes immutability. When we destructure the object on its way into our function we assign the object’s properties to new variables. Changing the value of those variables will not alter the original object.</p><p>Consider the following:</p><pre>const options = {<br>  role: &#39;Admin&#39;,<br>  includeInactive: true<br>}</pre><pre>findUsersByRole(options)</pre><pre>function findUsersByRole ({<br>  role,<br>  withContactInfo, <br>  includeInactive<br>} <strong>= {}</strong>) {<br>  role = role.toLowerCase()<br>  console.log(role) // &#39;admin&#39;<br>  ...<br>}</pre><pre>console.log(options.role) // &#39;Admin&#39;</pre><p>Even though we change the value of role the value of options.role remains unchanged.</p><blockquote><strong><em>Edit:</em></strong><em> It’s worth noting that destructuring makes a </em><strong><em>shallow</em></strong><em> copy so if any of the properties of our parameter object are of a complex type (e.g. </em><em>array or </em><em>object) changing them would indeed affect the original.</em></blockquote><blockquote><em>(Hat tip to </em><a href="https://medium.com/u/c4d56ab05e68"><em>Yuri Homyakov</em></a><em> for </em><a href="https://medium.com/@yurik1776/hey-bill-569e596030b7"><em>pointing this out</em></a><em>)</em></blockquote><p>So far, so good, yeah?</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FXreQmk7ETCak0%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FXreQmk7ETCak0%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia1.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExZTFxbnduOW05Mnp4bHVnbDhhMWIzN3ViNzZzYmhxaWwwOXF2YnAxeSZlcD12MV9naWZzX2dpZklkJmN0PWc%2FXreQmk7ETCak0%2Fgiphy.gif&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="326" frameborder="0" scrolling="no"><a href="https://medium.com/media/bdff1834dc43b94b4017faebc6e61d88/href">https://medium.com/media/bdff1834dc43b94b4017faebc6e61d88/href</a></iframe><h4>Cleaner Default Parameters</h4><p>With ES2015 JavaScript functions gained the ability to define default parameters. In fact, we recently used a default parameter when we added ={} to the parameter object on our findUsersByRole function above.</p><p>With traditional default parameters, our findUsersByRole function might look like this.</p><pre>function findUsersByRole (<br>  role, <br>  <strong>withContactInfo = true</strong>, <br>  includeInactive<br>) {...}</pre><p>If we want to set includeInactive to true we have to explicitly pass undefined as the value for withContactInfo to preserve the default, like this:</p><pre>findUsersByRole(<br>  &#39;Admin&#39;, <br>  undefined, <br>  true<br>)</pre><p>How hideous is that?</p><p>Compare it to using a parameter object like so:</p><pre>function findUsersByRole ({<br>  role,<br>  <strong>withContactInfo = true</strong>, <br>  includeInactive<br>} = {}) {...}</pre><p>Now we can write…</p><pre>findUsersByRole({<br>  role: ‘Admin’,<br>  includeInactive: true<br>})</pre><p>… and our default value for withContactInfo is preserved.</p><h4>BONUS: Required Parameters</h4><p>How often have you written something like this?</p><pre>function findUsersByRole ({<br>  role, <br>  withContactInfo, <br>  includeInactive<br>} = {}) {<br>  if (role == null) {  <br>    throw Error(...)<br>  }<br>  ...<br>}</pre><blockquote><strong><em>Note:</em></strong><em> We use </em><em>== (double equals) above to test for both </em><em>null and </em><em>undefined with a single statement.</em></blockquote><p>What if I told you that you could use default parameters to validate required parameters instead?</p><p>First, we need to define a requiredParam() function that throws an Error.</p><p>Like this:</p><pre>function requiredParam (param) {<br>  const requiredParamError = new Error(<br>   `Required parameter, &quot;${param}&quot; is missing.`<br>  )</pre><pre>  // preserve original stack trace<br>  if (typeof Error.captureStackTrace === ‘function’) {<br>    Error.captureStackTrace(<br>      requiredParamError, <br>      requiredParam<br>    )<br>  }</pre><pre>  throw requiredParamError<br>}</pre><blockquote><em>I know, I know. requiredParam doesn’t RORO. That’s why I said </em><strong><em>many</em></strong><em> of my functions — not </em><strong><em>all</em></strong><em>.</em></blockquote><p>Now, we can set an invocation of requiredParam as the default value for role, like so:</p><pre>function findUsersByRole ({<br>  role <strong>= requiredParam(&#39;role&#39;)</strong>,<br>  withContactInfo, <br>  includeInactive<br>} = {}) {...}</pre><p>With the above code, if anyone calls findUsersByRole without supplying a role they will get an Error that says Required parameter, “role” is missing.</p><p>Technically, we can use this technique with regular default parameters as well; we don’t necessarily need an object. But this trick was too useful not to mention.</p><h4>Richer Return Values</h4><p>JavaScript functions can only return a single value. If that value is an object it can contain a lot more information.</p><p>Consider a function that saves a User to a database. When that function returns an object it can provide a lot of information to the caller.</p><p>For example, a common pattern is to “upsert” or “merge” data in a save function. Which means, we insert rows into a database table (if they do not already exist) or update them (if they do exist).</p><p>In such cases, it would be handy to know wether the operation performed by our Save function was an INSERT or an UPDATE. It would also be good to get an accurate representation of exactly what was stored in the database, and it would be good to know the status of the operation; did it succeed, is it pending as part of a larger transaction, did it timeout?</p><p>When returning an object, it’s easy to communicate all of this info at once.</p><p>Something like:</p><pre>async saveUser({<br>  upsert = true,<br>  transaction,<br>  ...userInfo<br>}) {<br>  // save to the DB<br>  return {<br>    operation, // e.g &#39;INSERT&#39;<br>    status, // e.g. &#39;Success&#39;<br>    saved: userInfo<br>  }<br>}</pre><p>Technically, the above returns a Promise that resolves to an object but you get the idea.</p><h4>Easy Function Composition</h4><blockquote>“Function composition is the process of combining two or more functions to produce a new function. Composing functions together is like snapping together a series of pipes for our data to flow through.” — <a href="https://medium.com/u/c359511de780">Eric Elliott</a></blockquote><p>We can compose functions together using a pipe function that looks something like this:</p><pre>function pipe(...fns) { <br>  return param =&gt; fns.reduce(<br>    (result, fn) =&gt; fn(result), <br>    param<br>  )<br>}</pre><p>The above function takes a list of functions and returns a function that can apply the list from left to right, starting with a given parameter and then passing the result of each function in the list to the next function in the list.</p><p>Don’t worry if you’re confused, there’s an example below that should clear things up.</p><p>One limitation of this approach is that each function in the list must only receive a single parameter. Luckily, when we RORO that’s not a problem!</p><p>Here’s an example where we have a saveUser function that pipes a userInfo object through 3 separate functions that validate, normalize, and persist the user information in sequence.</p><pre>function saveUser(userInfo) {<br>  return pipe(<br>    validate,<br>    normalize,<br>    persist<br>  )(userInfo)<br>}</pre><p>We can use a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters">rest parameter</a> in our validate, normalize, and persist functions to destructure only the values that each function needs and still pass everything back to the caller.</p><p>Here’s a bit of code to give you the gist of it:</p><pre>function validate({<br>  id,<br>  firstName,<br>  lastName,<br>  email = requiredParam(),<br>  username = requiredParam(),<br>  pass = requiredParam(),<br>  address,<br>  ...rest<br>}) {<br>  // do some validation<br>  return {<br>    id,<br>    firstName,<br>    lastName,<br>    email,<br>    username,<br>    pass,<br>    address,<br>    ...rest<br>  }<br>}</pre><pre>function normalize({<br>  email,<br>  username,<br>  ...rest<br>}) {<br>  // do some normalizing<br>  return {<br>    email,<br>    username,<br>    ...rest<br>  }<br>}</pre><pre>async function persist({<br>  upsert = true,<br>  ...info<br>}) {<br>  // save userInfo to the DB<br>  return {<br>    operation,<br>    status,<br>    saved: info<br>  }<br>}</pre><h4>To RO or not to RO, that is the question.</h4><p>I said at the outset, <strong>most</strong> of my functions receive an object and <strong>many </strong>of them return an object too.</p><p>Like any pattern, RORO should be seen as just another tool in our tool box. We use it in places where it adds value by making a list of parameters more clear and flexible and by making a return value more expressive.</p><p>If you’re writing a function that will only ever need to receive a single parameter, then receiving an object is overkill. Likewise, if you’re writing a function that can communicate a clear and intuitive response to the caller by returning a simple value, there is no need to return an object.</p><p>An example where I almost never RORO is assertion functions. Suppose we have a function isPositiveInteger that checks wether or not a given parameter is a positive integer, such a function likely wouldn’t benefit from RORO at all.</p><p>If you enjoyed this article, please smash the applause icon a bunch of times to help spread the word. And if you want to read more stuff like this, please sign up for my Dev Mastery newsletter below.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F83d379%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2F83d379%2F&amp;image=https%3A%2F%2Fe.enpose.co%2F%3Fkey%3DdRXnS9Gplk%26w%3D700%26h%3D425%26url%3Dhttps%253A%252F%252Fupscri.be%252F83d379%252F%253Fenpose&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/acc7ce8e79ec6264b987f0a6f9798c10/href">https://medium.com/media/acc7ce8e79ec6264b987f0a6f9798c10/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be01e7669cbd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/elegant-patterns-in-modern-javascript-roro-be01e7669cbd">Elegant patterns in modern JavaScript: RORO</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Don’t do it at runtime. Do it at design time.]]></title>
            <link>https://medium.com/free-code-camp/dont-do-it-at-runtime-do-it-at-design-time-c4f59d1775e4?source=rss-7f9c91ba25fb------2</link>
            <guid isPermaLink="false">https://medium.com/p/c4f59d1775e4</guid>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[life-lessons]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[design]]></category>
            <dc:creator><![CDATA[Bill Sourour]]></dc:creator>
            <pubDate>Thu, 04 Jan 2018 14:22:43 GMT</pubDate>
            <atom:updated>2018-01-04T14:22:43.435Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FhSLymQrW0_8FF6UJcYiDQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/9XSLoMlVhYU?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Amanda Flavell</a> on <a href="http://www.unsplash.com/">Unsplash</a></figcaption></figure><p>Long ago a wise old developer gave me a piece of advice that I didn’t fully appreciate until very recently.</p><p>We were in a code review looking at some feature that required the program to output a list of letters from A-Z (think of a list of contacts with a set of buttons that allow you to skip down to names starting with a certain letter — that kind of thing).</p><p>So, along came some young hot-shot. (OK — it was me.) I decided that rather than just hard-coding an array of all the letters, it would be easier to write a for loop that iterated from 65–90, then use the values to generate the letters from their char codes.</p><p>The JavaScript equivalent would be something like:</p><pre>for (let i = 65; i &lt;= 90; i++) {<br>  letters.push(String.fromCharCode(i))<br>}</pre><p>The wise old developer looked at me and asked why I hadn’t just hard-coded the array. It wasn’t as if the alphabet was going to be different from one session to the next. So why bother calculating it every time?</p><p>I was aghast. “You can’t really expect me to hand type every single letter like some child. I am a professional software developer! I have algorithms and data structures, and a math co-processor for heaven’s sake!”</p><p>“Fine,” he said. “Then use them at design-time to generate the array for you, and then copy/paste it into the production code.”</p><p>And then he said this:</p><blockquote>“Avoid doing at runtime what you can do at design time”</blockquote><p>Now, let’s be honest. My little for-loop wasn’t about to bring the application to a grinding halt. And today’s machines would crunch through that code so fast, no one would even notice. But as a general principle, it’s sage advice.</p><p>Too often we write code that transforms rarely-changing data from one format to another on every request.</p><p>Think of all the round-trips to fetch a piece of content from a database that might change once or twice a year, format it, and forward it to the browser, needlessly slowing down our apps.</p><p>This is especially true for sites that are tied to a content management system.</p><p>This is why I think established players like Wordpress, Drupal, and the like will face a credible challenge in the years to come from static site generators like <a href="https://www.gatsbyjs.org/">Gatsby</a>, <a href="https://gohugo.io/">Hugo</a>, or <a href="https://jekyllrb.com/">Jekyll</a> paired with a smooth build process, <a href="https://css-tricks.com/what-is-a-headless-cms/">headless CMS</a>, cheap CDNs, and a fast continuous integration workflow.</p><p>This pattern has been dubbed <a href="https://jamstack.org/">JAMstack</a>, which stands for “JavaScript, APIs and Markup stack.” And the <a href="https://jamstack.org/examples/">results are quite impressive</a>.</p><p>The wise old developer’s advice echoes in my ears: “Avoid doing at run-time what you can do at design time.” And as time has worn on, I’ve realized that this piece of advice has far-reaching implications. Not just for software development, but for life too.</p><p>Recently, I’ve been reading a great book called <a href="https://www.principles.com/">“Principles: Work and Life” by Ray Dalio</a>. A central theme of the book is that there are far fewer <em>types</em> of problem than there are <em>actual</em> problems. So if you do the work ahead of time and figure out how you would approach a particular type of problem you’re likely to face, then when it does arrive, you’ll be far better equipped to deal with it.</p><p>In essence, you can make better decisions more quickly by sorting out your approach to different problem types at “design time”, when you’re calmly reflecting on life, instead of at “runtime”, when you’re faced with an actual problem in the moment and panicking.</p><p>Dalio implemented this technique by cataloging his approaches as a set of principles. He even went so far as to codify his decision-making process into a set of computer algorithms that he could test against vast amounts of historical data.</p><p>Given that he’s a multi-billionaire who runs a very successful investment company, I’d say it’s worked out.</p><p>In fact, <a href="https://www.nytimes.com/2016/02/23/business/dealbook/a-new-breed-of-trader-on-wall-street-coders-with-a-phd.html">Wall Street is starting to hire more computer programmers than stock traders</a>. So if you had any doubts that you chose the right profession, there’s more proof that software is eating the world.</p><p>I shared my own advice and lessons-learned in a recent interview on the Developer On Fire podcast which you can listen to <a href="https://dev.to/developeronfire/episode-299--bill-sourour--paying-it-forward">here</a>.</p><p><a href="https://dev.to/developeronfire/episode-299--bill-sourour--paying-it-forward">Episode 299 | Bill Sourour - Paying It Forward</a></p><p>You can learn more about JAMstack at Jamstack.org</p><p><a href="http://www.jamstack.org/">JAMstack | JavaScript, APIs, and Markup</a></p><p>There’s also a nice round-up of static site generators on the Netlify blog at:</p><p><a href="https://www.netlify.com/blog/2017/05/25/top-ten-static-site-generators-of-2017/">Top Ten Static Site Generators of 2017 | Netlify</a></p><p>And here’s an article about a specific stack that I recently reviewed and recommended which uses a combination of Gatsby, Contentful, Netlify, and Algolia as an alternative to a traditional CMS for a documentation site:</p><p><a href="https://www.gatsbyjs.org/blog/2017-12-06-gatsby-plus-contentful-plus-netlify/">Gatsby + Contentful + Netlify (and Algolia)</a></p><p>This post originally appeared in the <strong>Dev Mastery Newsletter</strong> which I send out regularly to thousands of developers all over the world. Sign up below to get more content like this sent straight to your inbox.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F83d379%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2F83d379%2F&amp;image=https%3A%2F%2Fe.enpose.co%2F%3Fkey%3DdRXnS9Gplk%26w%3D700%26h%3D425%26url%3Dhttps%253A%252F%252Fupscri.be%252F83d379%252F%253Fenpose&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/acc7ce8e79ec6264b987f0a6f9798c10/href">https://medium.com/media/acc7ce8e79ec6264b987f0a6f9798c10/href</a></iframe><p>If you enjoyed reading this, please help spread the word by smashing that applause icon a bunch of times. Thanks in advance!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c4f59d1775e4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/dont-do-it-at-runtime-do-it-at-design-time-c4f59d1775e4">Don’t do it at runtime. Do it at design time.</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Trustworthy Coder’s Pledge]]></title>
            <link>https://medium.com/@BillSourour/the-trustworthy-coders-pledge-aa5ba046c5aa?source=rss-7f9c91ba25fb------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa5ba046c5aa</guid>
            <category><![CDATA[ethics]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Bill Sourour]]></dc:creator>
            <pubDate>Mon, 09 Oct 2017 06:16:13 GMT</pubDate>
            <atom:updated>2017-10-09T13:52:21.341Z</atom:updated>
            <content:encoded><![CDATA[<p>I do hereby pledge to only produce trustworthy software that respects its users.</p><p>Such software will:</p><ul><li>be transparent, honest, and accountable in all user communication;</li><li>function exactly as described;</li><li>seek explicit user consent prior to collecting any user information; including both user-provided information and information collected from a user’s device or through integration with other services;</li><li>seek explicit user consent prior to sharing any and all user information;</li><li>use clear and plain language when seeking user consent;</li><li>describe in clear and plain language what user information is collected and how;</li><li>describe in clear and plain language where, when, and how any user information will be used;</li><li>make it easy for users to withdraw consent at any time;</li><li>make any user-generated content available for download by the user who generated it, free of charge, any time, with no restrictions;</li><li>clearly identify any advertising or sponsored content;</li><li>provide a simple, easy-to-use, and easy-to-find mechanism for users to opt out of any advertising or marketing;</li><li>completely delete any and all user information upon request by the user; and,</li><li>clearly and explicitly disclose any and all potential conflicts of interest including both conflicts that may arise through commercial interests and conflicts that may arise through political affiliation.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa5ba046c5aa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Putting comments in code: the good, the bad, and the ugly.]]></title>
            <link>https://medium.com/free-code-camp/code-comments-the-good-the-bad-and-the-ugly-be9cc65fbf83?source=rss-7f9c91ba25fb------2</link>
            <guid isPermaLink="false">https://medium.com/p/be9cc65fbf83</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[learning-to-code]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Bill Sourour]]></dc:creator>
            <pubDate>Thu, 20 Apr 2017 11:05:45 GMT</pubDate>
            <atom:updated>2017-12-22T15:05:05.247Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ddM-OL7PF36NZ6QYCa95bQ.jpeg" /><figcaption>Clint Eastwood in</figcaption></figure><p>Stop me if you’ve heard this one before…</p><blockquote>“Good code is self-documenting.”</blockquote><p>In 20+ years of writing code for a living, this is the one phrase I’ve heard the most.</p><p>It’s <em>cliché.</em></p><p>And like many clichés, it has a kernel of truth to it. But this truth has been so abused that most people who utter the phrase have no idea what it really means.</p><p>Is it true? <strong>Yes</strong>.</p><p>Does it mean you should never comment your code? <strong>No</strong>.</p><p>In this article we’ll look at the good, the bad, and the ugly when it comes to commenting your code.</p><p>For starters, there are really two different types of code comments. I call them <strong>documentation comments</strong> and <strong>clarification comments</strong>.</p><h3>Documentation Comments</h3><p>Documentation comments are intended for anyone who is likely to consume your source code, but not likely to read through it. If you are building a library or framework that other developers will use, you need some form of API documentation.</p><p>The further removed from the source code your API documentation is, the more likely it is to become outdated or inaccurate over time. A good strategy to mitigate this is to embed the documentation directly into the code and then use a tool to extract it.</p><p>Here’s an example of a documentation comment from a popular JavaScript library called <a href="https://lodash.com/">Lodash</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/47143a7aa1ec51cd56f7530c242fd938/href">https://medium.com/media/47143a7aa1ec51cd56f7530c242fd938/href</a></iframe><p>If you <a href="https://lodash.com/docs/#countBy">compare these comments to their online documentation</a>, you’ll see it’s an exact match.</p><p>If you write documentation comments you should ensure that they follow a consistent standard and that they are easily distinguishable from any inline clarification comments you may also want to add. Some popular and well supported standards and tools include <a href="http://usejsdoc.org/">JSDoc</a> for JavaScript, <a href="https://github.com/dotnet/docfx">DocFx</a> for dotNet, and <a href="http://www.oracle.com/technetwork/java/javase/documentation/index-jsp-135444.html">JavaDoc</a> for Java.</p><p>The downside of these kinds of comments is that they can make your code very “noisy” and harder to read for anyone who is actively involved in maintaining it. The good news is that most code editors support “code folding” which allows us to collapse the comments so we can focus on the code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/1*o9d-IZKFtlHf4ycY_n4H2Q.gif" /><figcaption>Collapsing comments with code folding in Visual Studio Code.</figcaption></figure><h3>Clarification comments</h3><p>Clarification comments are intended for anyone (including your future self) who may need to maintain, refactor, or extend your code.</p><p>Often, a clarification comment is a code smell. It tells you that your code is too complex. You should strive to remove clarification comments and simplify the code instead because, “good code is self-documenting.”</p><p>Here’s an <a href="http://stackoverflow.com/a/766363">example</a> of a bad — though very entertaining — clarification comment.</p><pre>/* <br> * Replaces with spaces <br> * the braces in cases <br> * where braces in places <br> * cause stasis.<br>**/ <br>$str = str_replace(array(&quot;\{&quot;,&quot;\}&quot;),&quot; &quot;,$str);</pre><p>Rather than decorating a slightly confusing statement with a clever rhyme — in <em>amphibrach dimeter</em>, no less — the author would have been far better off spending time on a function that makes the code itself easier to read and understand. Maybe a function named, removeCurlyBraces called from another function named sanitizeInput?</p><p>Don’t get me wrong, there are times — especially when you are slogging through a crushing workload — where injecting a bit of humor can be good for the soul. But when you write a funny comment to make up for bad code, it actually makes people less likely to refactor and fix the code later.</p><p>Do you really want to be the one responsible for robbing all future coders of the joy of reading that clever little rhyme? Most coders would chuckle and move on, ignoring the code smell.</p><p>There are also times when you come across a comment that is redundant. If the code is already simple and obvious, there’s no need to add a comment.</p><p>Like, don’t do this nonsense:</p><pre>/*<br>set the value of the age integer to 32<br>*/<br>int age = 32;</pre><p>Still, there are times when no matter what you do to the code itself, a clarification comment is still warranted.</p><p>Usually this happens when you need to add some context to a non-intuitive solution.</p><p>Here’s a good example from Lodash:</p><pre>function addSetEntry(set, value) {   <br>  /* <br>   Don&#39;t return `set.add` because it&#39;s not chainable in IE 11.<br>  */  <br>  set.add(value);    <br>  return set;  <br>}</pre><p>There are also times when — after a lot of thought and experimentation — it turns out that the seemingly naive solution to a problem is actually the best. In those scenarios it is almost inevitable that some other coder will come around thinking they are much smarter than you are and start messing with the code, only to discover that your way was the best way all along.</p><p>Sometimes that other coder is your future self.</p><p>In those cases, it’s best to save everyone the time and embarrassment and leave a comment.</p><p>The <a href="http://stackoverflow.com/a/482129">following mock-comment</a> captures this scenario perfectly:</p><pre>/**<br>Dear maintainer:<br> <br>Once you are done trying to &#39;optimize&#39; this routine,<br>and have realized what a terrible mistake that was,<br>please increment the following counter as a warning<br>to the next guy:<br> <br>total_hours_wasted_here = 42<br>**/</pre><p>Again, the above is more about being funny than being helpful. But you SHOULD leave a comment warning others not to pursue some seemingly obvious “better solution,” if you’ve already tried and rejected it. And when you do, the comment should specify what solution you tried and why you decided against it.</p><p>Here’s a simple example in JavaScript:</p><pre>/* <br>don&#39;t use the global isFinite() because it returns true for null values<br>*/<br>Number.isFinite(value)</pre><h3>The Ugly</h3><p>So, we’ve looked at the good and the bad, but what about the ugly?</p><p>Unfortunately, there are times in any job where you’ll find yourself frustrated and when you write code for a living, it can be tempting to vent that frustration in code comments.</p><p>Work with enough code bases and you’ll come across comments that range from cynical and depressing to dark and mean spirited.</p><p>Things like the <a href="http://stackoverflow.com/a/185550">seemingly harmless</a>…</p><pre>/*<br>This code sucks, you know it and I know it.  <br>Move on and call me an idiot later.<br>*/</pre><p>…to the <a href="http://stackoverflow.com/a/184673">downright mean</a></p><pre>/* <br>Class used to workaround Richard being a f***ing idiot<br>*/</pre><p>These things may seem funny or may help release a bit of frustration in the moment, but when they make it into production code they end up making the coder who wrote them and their employer look unprofessional and bitter.</p><p>Don&#39;t do this.</p><p>If you enjoyed this article, please smash the applause icon a bunch of times to help spread the word. And if you want to read more stuff like this, please sign up for my weekly Dev Mastery newsletter below.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fb1334e%3Fas_embed%3Dtrue&amp;url=https%3A%2F%2Fupscri.be%2Fb1334e%2F&amp;image=https%3A%2F%2Fupscri.be%2Fmedia%2Fform.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/67131bcad3c891bf55a10320d8ab7372/href">https://medium.com/media/67131bcad3c891bf55a10320d8ab7372/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be9cc65fbf83" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/code-comments-the-good-the-bad-and-the-ugly-be9cc65fbf83">Putting comments in code: the good, the bad, and the ugly.</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The 100% Correct Coding Style Guide]]></title>
            <link>https://medium.com/free-code-camp/the-100-correct-coding-style-guide-5b594a1655f0?source=rss-7f9c91ba25fb------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b594a1655f0</guid>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[life-lessons]]></category>
            <category><![CDATA[startup]]></category>
            <dc:creator><![CDATA[Bill Sourour]]></dc:creator>
            <pubDate>Mon, 03 Apr 2017 15:12:49 GMT</pubDate>
            <atom:updated>2017-08-24T13:36:13.498Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ui3btuK36fzFikOB4pM2-Q.jpeg" /><figcaption><a href="https://commons.wikimedia.org/wiki/File:Slava_Zaitsev_fashion_show-2.jpg">Photo credit</a></figcaption></figure><p>Tabs or spaces? Curly brace on the same line or a new line? 80 character width or 120?</p><p>Coders love to argue about this kind of stuff. The tabs vs. spaces debate even made it into a <a href="https://youtu.be/SsoOG6ZeyUI">famous episode of the HBO show <em>Silicon Valley</em></a>.</p><p><strong>Well in this article, I will finally give you the definitive answers you seek.</strong></p><p>Early in my career, I engaged in all kinds of holy wars. I would read some article about why a particular convention was correct, while another was totally wrong. I would get right up there on my high and mighty horse and proclaim to anyone who would listen that they were wrong and I was right.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D4D49LH0OiKqZ-TvBA3pjw.png" /></figure><p>It took me years to find the right answers but I’ve finally done it and it turns out the answer is…</p><p><strong>These things don’t matter.</strong></p><p>Consistency matters. Readability matters. Arguing and stressing about one convention over another matters not.</p><p>Over the past 20+ years, I’ve followed every imaginable trend. I’ve followed the different conventions of different languages. None of it has impacted my bug count or made my code any more efficient.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/426/1*bNP7DQt6uNDUQ5VLkrm2sQ.png" /><figcaption>This is just sillyness. Still funny though.</figcaption></figure><p>Don’t get me wrong, clean-looking, well-formatted code will be easier to change and maintain over time, and that’s a good thing.</p><p>There’s also nothing wrong with wanting your code to look beautiful. But too often, this is used to justify what essentially boils down to procrastination.</p><p>We procrastinate like this because coding is hard. Things can get complicated in a hurry and we — especially those of us who may be new to this level of complexity — can become intimidated by this complexity and grow insecure about our ability to tame it.</p><p>It’s much safer to argue over trivial things. Our perceived incompetence is less likely to be exposed that way.</p><p>The phenomena of debating trivialities to avoid hard problems is so common that there are a number of popular theories that describe it.</p><p>One of the most popular is <em>Parkinson’s Law of Triviality</em> which states that members of an organization give disproportionate weight to trivial issues.</p><p>In illustrating this law, Parkinson used the fictional example of a committee whose job it was to approve plans for a new nuclear plant, but who spent the majority of their time arguing over what materials to use for the staff bike shed. They neglected the proposed design of the plant itself, which was a far more important but also far more complex issue.</p><p>Because of the reference to a bike shed in this canonical example, Danish developer, Poul-Henning Kamp later coined the term “bike shed effect” or simply “bike shedding” to describe it.</p><p>If you work in software development — and especially if you hang out with other coders on social media — you’re likely to come across some form of bike-shedding almost daily.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cpx_vedKi38oTYApll_QUA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OZhe8TfRqdSN8BPh8E2Euw.jpeg" /><figcaption>Say what you will, but I think grey is a lovely color for a bike shed.</figcaption></figure><p>If you find yourself getting into an unusually heated debate with your fellow coders, online or in-person, it’s probably also worth remembering <em>Sayre’s Law</em>…</p><blockquote>“In any dispute the intensity of feeling is inversely proportional to the value of the issues at stake.”</blockquote><p>As a consultant, I bounce from client to client, and each one has their own rules and conventions. I decided long ago that the only way for me to succeed was to let go of the trivialities and focus on the hard problems. When it comes to coding standards, I take what I get and I don’t get upset.</p><p>If you happen to find yourself in a position to pick your own style guide, I recommend that you ask yourself these two simple questions:</p><ol><li>Is there tooling that will automatically apply the style rules to my code with little to no intervention from me?</li><li>Are the tools and underlying styles actively maintained and/or used by reputable organizations?</li></ol><p>If you can answer “yes” to both of those questions, then you’re good to go. Simple as that.</p><p>Here are some options that fit the bill for some of today’s more popular web languages:</p><p><a href="https://github.com/dotnet/codeformatter"><strong>DotNet Code Formatter</strong></a></p><p><a href="https://github.com/google/google-java-format"><strong>Java: Google-Java-Format</strong></a></p><p><a href="https://standardjs.com/"><strong>Javascript Standard Style</strong></a><strong> (N.B. this is a product name, not an actual, official JavaScript standard)</strong></p><p><a href="http://cs.sensiolabs.org/"><strong>PHP Coding Standards Fixe</strong>r</a></p><p><a href="https://github.com/google/yapf/"><strong>Python: Google’s YAPF</strong></a></p><p><a href="http://rubocop.readthedocs.io/en/latest/"><strong>Ruby: Rubocop</strong></a></p><p>If you enjoyed this article, please smash the clap icon at the bottom of this post repeatedly to help spread the word. And if you want to read more stuff like this, please sign up for my weekly Dev Mastery newsletter below.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fb1334e%3Fas_embed%3Dtrue&amp;url=https%3A%2F%2Fupscri.be%2Fb1334e%2F&amp;image=https%3A%2F%2Fupscri.be%2Fmedia%2Fform.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/67131bcad3c891bf55a10320d8ab7372/href">https://medium.com/media/67131bcad3c891bf55a10320d8ab7372/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b594a1655f0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/the-100-correct-coding-style-guide-5b594a1655f0">The 100% Correct Coding Style Guide</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Technical Debt]]></title>
            <link>https://medium.com/on-writing-code/technical-debt-61651300e82?source=rss-7f9c91ba25fb------2</link>
            <guid isPermaLink="false">https://medium.com/p/61651300e82</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Bill Sourour]]></dc:creator>
            <pubDate>Sun, 01 Jan 2017 05:04:26 GMT</pubDate>
            <atom:updated>2017-01-04T14:16:13.660Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E-0AJpOE9B-6_CP78RHk3w.jpeg" /></figure><p>Have you ever shipped a system completely free of technical debt? An application where no corners were cut and no compromises were made in service of deadline or budget? Small personal projects aside, over a 20+ year career, I have never seen such an application in a professional setting.</p><blockquote><strong>Author’s Note:</strong> This post is an excerpt from my weekly <a href="https://devmastery.com/">Dev Mastery newsletter</a>. It was originally sent to Dev Mastery subscribers on December 8, 2016.</blockquote><p>Check out this article from Tech Crunch about strategically planning your technical debt so that it can be managed and leveraged for maximum benefit.</p><p><a href="https://techcrunch.com/2016/12/04/how-to-make-debt-pay/">How to make debt pay</a></p><p>The article makes some good points, but the author is clearly from a software product company background. There’s no question that it’s hard to convince a product manager to invest in a specific project dedicated to resolving technical debt, especially when that investment won’t result in any new features that the average customer might immediately notice. But at least at a software company there is some vague understanding of the business risk of technical debt. This understanding is much harder to find at agencies, consultancies, and in large enterprises.</p><p>If you’re not in a software company, it’s almost impossible to get anyone to approve some specific future project aimed specifically at eliminating technical debt. You have to pad your estimates for fixes or new features so that you can go back and clean a bit of your mess. And you have to be extremely careful about the kind of messes you make to begin with.</p><p>Speaking of cleaning messes, refactoring is an important skill for any developer. I’ve written about my approach to this before in…</p><p><a href="https://medium.freecodecamp.com/conquer-legacy-code-f9e23a6ab758">How to conquer legacy code</a></p><p>Martin Fowler also maintains a good listing of common refactoring techniques that I often use as a reference…</p><p><a href="http://refactoring.com/catalog/">catalog</a></p><p>The five I use the most are:</p><ul><li><a href="http://refactoring.com/catalog/replaceExceptionWithTest.html">Replace an exception with a test</a></li><li><a href="http://refactoring.com/catalog/introduceAssertion.html">Replace assumptions with assertions</a></li><li><a href="http://refactoring.com/catalog/decomposeConditional.html">Decompose a conditional</a></li><li><a href="http://refactoring.com/catalog/consolidateConditionalExpression.html">Consolidate multiple conditional expressions</a></li><li><a href="http://refactoring.com/catalog/replaceConstructorWithFactoryMethod.html">Replace a constructor with a factory method</a></li></ul><p>The post you just read was originally sent to Dev Mastery newsletter subscribers on December 8, 2016. I send out stuff like this every week. Sign up below to get in on the action.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fb1334e%3Fas_embed%3Dtrue&amp;url=https%3A%2F%2Fupscri.be%2Fb1334e%2F&amp;image=https%3A%2F%2Fupscri.be%2Fmedia%2Fform.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/67131bcad3c891bf55a10320d8ab7372/href">https://medium.com/media/67131bcad3c891bf55a10320d8ab7372/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=61651300e82" width="1" height="1" alt=""><hr><p><a href="https://medium.com/on-writing-code/technical-debt-61651300e82">Technical Debt</a> was originally published in <a href="https://medium.com/on-writing-code">Dev Mastery</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Top 5 Developer Links of 2016]]></title>
            <link>https://medium.com/on-writing-code/top-5-links-of-2016-for-developers-280b12575f47?source=rss-7f9c91ba25fb------2</link>
            <guid isPermaLink="false">https://medium.com/p/280b12575f47</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[2016]]></category>
            <dc:creator><![CDATA[Bill Sourour]]></dc:creator>
            <pubDate>Wed, 21 Dec 2016 15:04:36 GMT</pubDate>
            <atom:updated>2016-12-25T17:26:46.496Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rkMf9fzCr1uj-IFlUM709Q.jpeg" /></figure><p>I’ve shared some pretty awesome links and resources through the <a href="https://devmastery.com/">Dev Mastery newsletter</a> this year. Here are my top 5 favourites.</p><h4>#5 — <a href="https://www.youtube.com/watch?v=yCBUsd52a3s">My Dog Taught Me to Code by Dave Thomas</a></h4><p>Here is a video where the inimitable “Pragmatic Dave” Thomas shouts at you for almost an hour with really amazing advice that will help you improve your code. If you’re impatient, just skip to <a href="https://www.youtube.com/watch?v=yCBUsd52a3s&amp;feature=youtu.be&amp;t=4m52s">4:52</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FyCBUsd52a3s%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DyCBUsd52a3s&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FyCBUsd52a3s%2Fhqdefault.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/3619540cd2846737ca7329dd24d5b175/href">https://medium.com/media/3619540cd2846737ca7329dd24d5b175/href</a></iframe><h4>#4 — <a href="https://www.confluent.io/blog/turning-the-database-inside-out-with-apache-samza/">Turning the Database Inside Out</a></h4><p>Martin Klepmann makes the following provocative statement and provides a fascinating alternative model for Databases whose time I think has come.</p><blockquote>“Databases are global, shared, mutable state. That’s the way it has been since the 1960s, and no amount of NoSQL has changed that. However, most self-respecting developers have got rid of mutable global variables in their code long ago. So why do we tolerate databases as they are?” — Martin Klepmann</blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FfU9hR3kiOK0%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DfU9hR3kiOK0&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FfU9hR3kiOK0%2Fhqdefault.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/889005089e7dd6a0fa06fc8bc5df16d6/href">https://medium.com/media/889005089e7dd6a0fa06fc8bc5df16d6/href</a></iframe><p>If you’d rather read than watch, <a href="https://www.confluent.io/blog/turning-the-database-inside-out-with-apache-samza/">click here</a> for the transcript.</p><h4>#3 —<a href="http://algo-visualizer.jasonpark.me/"> Algorithm Visualizer by Jason Park</a></h4><p>This amazing little web app let’s you play with some of the most common programming algorithms in JavaScript. Very cool.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sPPNesX3Z49QXCSHy4YgVw.png" /><figcaption><a href="http://algo-visualizer.jasonpark.me/#path=backtracking/knight&#39;s_tour/basic">Algorithm Visualizer by Jason Park</a></figcaption></figure><h4>#2 — <a href="https://www.prod.facebook.com/notes/kent-beck/mastering-programming/1184427814923414">Mastering Programming by Kent Beck</a></h4><p>Kent Beck shares all the “ways effective programmers get the most out of their precious 3e9 seconds on the planet.”</p><blockquote>“The journeyman learns to solve bigger problems by solving more problems at once. The master learns to solve even bigger problems than that by solving fewer problems at once.” — Kent Beck</blockquote><h4>#1 — <a href="https://youtu.be/ecIWPzGEbFc">The Future of Programming by Bob Martin</a></h4><p>In this highly engaging and massively important talk, programming legend “Uncle Bob” Martin lays out the history of our profession and talks about what’s next. This is the talk that inspired me to share my story about <a href="https://medium.freecodecamp.com/the-code-im-still-ashamed-of-e4c021dff55e#.2lgmwvw96">the code I’m still ashamed of</a>. It’s definitely worth your time.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FecIWPzGEbFc%3Ffeature%3Doembed&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DecIWPzGEbFc&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FecIWPzGEbFc%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/ad7ec14d6f2fa216bf2d55e0ab3268b1/href">https://medium.com/media/ad7ec14d6f2fa216bf2d55e0ab3268b1/href</a></iframe><p>On April 30, 2016 I sent out my first newsletter to 22 enthusiastic developers. Nine months later, my last newsletter of 2016 is going out to over 12,800 developers all around the world.</p><p>Use the form below to join them and get great stuff like this in your inbox every week.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fb1334e%3Fas_embed%3Dtrue&amp;url=https%3A%2F%2Fupscri.be%2Fb1334e%2F&amp;image=https%3A%2F%2Fupscri.be%2Fmedia%2Fform.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/67131bcad3c891bf55a10320d8ab7372/href">https://medium.com/media/67131bcad3c891bf55a10320d8ab7372/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=280b12575f47" width="1" height="1" alt=""><hr><p><a href="https://medium.com/on-writing-code/top-5-links-of-2016-for-developers-280b12575f47">Top 5 Developer Links of 2016</a> was originally published in <a href="https://medium.com/on-writing-code">Dev Mastery</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I hate servers]]></title>
            <link>https://medium.com/on-writing-code/i-hate-servers-68334f3de41c?source=rss-7f9c91ba25fb------2</link>
            <guid isPermaLink="false">https://medium.com/p/68334f3de41c</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Bill Sourour]]></dc:creator>
            <pubDate>Wed, 14 Dec 2016 04:38:57 GMT</pubDate>
            <atom:updated>2016-12-14T04:38:57.048Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*YeR2LdHDLgL-D5Pia4HmJA.jpeg" /></figure><p>Have you heard of serverless architecture? Have you experimented with it? I have and I’m a big fan.</p><p>Serverless architecture lets you concentrate on code and not have to worry about anything else. Your logic just runs in this ephemeral, stateless container that comes and goes on demand. All the big cloud companies now support this; Amazon has AWS Lambda, Azure has Azure Functions, and Google has Google Cloud Functions.</p><blockquote><strong>Author’s Note:</strong> This post is an excerpt from my weekly Dev Mastery newsletter. It was originally sent to Dev Mastery subscribers on December 1, 2016.</blockquote><p>One of the most thorough and balanced articles on the subject comes from Mike Roberts on Martin Fowler’s blog. Link below…</p><p><a href="http://martinfowler.com/articles/serverless.html">Serverless Architectures</a></p><p>Personally, I’ve experimented with a setup that includes Amazon S3 as a static host for the front end, and then AWS Lambda combined with API Gateway to handle the back end. When the budget is tight and you’re not dealing with critical security and privacy concerns, I’ve found this to be an excellent option.</p><p>I was an early adopter so I had to figure things out for myself using the documentation provided by AWS. Since then, the AWS blog has posted an article that describes how to do something very similar to what I set up for my client. It’s a good practical walk-through.</p><p><a href="https://aws.amazon.com/blogs/compute/microservices-without-the-servers/">Microservices without the Servers</a></p><p>There’s also a product called <a href="https://serverless.com/">Serverless</a> that I have played with and seems to be maturing nicely. It abstracts away some of the configuration and setup steps when working with the AWS stack. I didn’t end up using it on client work because it was still in very early beta. But if you just want to quickly try out serverless architecture, it’s worth playing with. It’s free and pretty easy to use.</p><p>I haven’t tried Microsoft or Google’s offering yet, so I can’t speak to them. If you’ve had experience or know of good resources, let me know.</p><p>The last thing I’ll leave you with is a fun little distraction from the New York Times website that has nothing to do with serverless architecture. It’s a neat little game where you try to beat Usain Bolt’s reaction time (I like it best on mobile). If you’re new to web development and are looking for an interesting little learning project, try building a clone of this game. It will teach you about timers and the Audio API. It’s also a great time waster. My best score was 0.126.</p><p><a href="http://www.nytimes.com/interactive/2016/08/13/sports/olympics/can-you-beat-usain-bolt-out-of-the-blocks.html">Can You Beat Usain Bolt Out of the Blocks?</a></p><p>The post you just read was originally sent to Dev Mastery newsletter subscribers on December 1, 2016. I send out stuff like this every week. Sign up below to get in on the action.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fb1334e%3Fas_embed%3Dtrue&amp;url=https%3A%2F%2Fupscri.be%2Fb1334e%2F&amp;image=https%3A%2F%2Fupscri.be%2Fmedia%2Fform.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/67131bcad3c891bf55a10320d8ab7372/href">https://medium.com/media/67131bcad3c891bf55a10320d8ab7372/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=68334f3de41c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/on-writing-code/i-hate-servers-68334f3de41c">I hate servers</a> was originally published in <a href="https://medium.com/on-writing-code">Dev Mastery</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OMG PHP WTF?!]]></title>
            <link>https://medium.com/on-writing-code/omg-php-wtf-bf763b170dca?source=rss-7f9c91ba25fb------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf763b170dca</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[design]]></category>
            <category><![CDATA[php]]></category>
            <dc:creator><![CDATA[Bill Sourour]]></dc:creator>
            <pubDate>Fri, 09 Dec 2016 16:52:43 GMT</pubDate>
            <atom:updated>2016-12-09T16:58:56.529Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V6Tt4M7qfnlwdhI_GhgXEQ.jpeg" /></figure><p>I have to make an embarrassing confession…</p><p>Many years ago (around 2002) I built a website in PHP. It was for a — now defunct — theatre company and included some basic functionality like a calendar and some lightweight content management features in a custom admin module I built. It was a small side project that I took on, in part, to learn PHP.</p><p>I came away from that experience thinking PHP was a steaming pile of garbage and I would tell anyone that would listen to me how terrible I thought PHP was. Here’s the embarrassing part; despite trashing PHP up and down, some of the websites and tools I use the most are PHP-based. This includes Wikipedia and Facebook. It also includes Wordpress, which is my number 1 recommendation when people ask me how they can create a website quickly with zero skills and almost no budget.</p><blockquote><strong>Author’s Note:</strong> This post is an excerpt from my weekly <a href="https://upscri.be/b1334e/">Dev Mastery newsletter</a>. It was originally sent to Dev Mastery subscribers on October 19, 2016.</blockquote><p>Now I’ve come to find out that Slack — another tool I use every day — is built with PHP. A slack engineer by the name of <a href="https://medium.com/u/1369469155e5">Keith Adams</a> published a story on Medium that I think is worth a serious look. Link below…</p><p><a href="https://slack.engineering/taking-php-seriously-cf7a60065329">Taking PHP Seriously</a></p><p>On a less embarrassing and more humbling note. I was honoured recently to be included in a <a href="https://medium.freecodecamp.com/code-briefing-my-favorite-stories-from-our-first-year-on-medium-dbb4d4b68fde#.jugkxd7g7">list</a> of Free Code Camp co-founder, <a href="https://medium.com/u/17756313f41a">Quincy Larson</a>’s <a href="https://medium.freecodecamp.com/code-briefing-my-favorite-stories-from-our-first-year-on-medium-dbb4d4b68fde#.jugkxd7g7">favourite stories of the year</a>. I can’t say enough good about Quincy and his team and all the amazing things they are doing for burgeoning developers and for non-profits. Not to mention the stellar quality of their Medium publication.</p><p>I always look forward to reading their latest posts. Here are some of my recent favourites…</p><ul><li><a href="https://medium.freecodecamp.com/i-reviewed-fifty-portfolios-on-reddit-and-this-is-what-i-learned-e5d2b43150bc">What I learned from reviewing 50 portfolios on Reddit in 3 crazy days.</a></li><li><a href="https://medium.freecodecamp.com/javascript-fatigue-fatigue-66ffb619f6ce">JavaScript Fatigue Fatigue</a></li><li><a href="https://medium.freecodecamp.com/what-does-it-mean-when-code-is-easy-to-reason-about-4e6f63eb386f">What does it mean when code is “easy to reason about”?</a></li></ul><p>The post you just read was originally sent to Dev Mastery newsletter subscribers on October 19, 2016. I send out stuff like this every week. Sign up below to get in on the action.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fb1334e%3Fas_embed%3Dtrue&amp;url=https%3A%2F%2Fupscri.be%2Fb1334e%2F&amp;image=https%3A%2F%2Fupscri.be%2Fmedia%2Fform.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/67131bcad3c891bf55a10320d8ab7372/href">https://medium.com/media/67131bcad3c891bf55a10320d8ab7372/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf763b170dca" width="1" height="1" alt=""><hr><p><a href="https://medium.com/on-writing-code/omg-php-wtf-bf763b170dca">OMG PHP WTF?!</a> was originally published in <a href="https://medium.com/on-writing-code">Dev Mastery</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>