<?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 Paul Marinaro on Medium]]></title>
        <description><![CDATA[Stories by Paul Marinaro on Medium]]></description>
        <link>https://medium.com/@paulmarinaro?source=rss-58d103767d53------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*a1f3iqmusiiRUqpnOqZ83A.jpeg</url>
            <title>Stories by Paul Marinaro on Medium</title>
            <link>https://medium.com/@paulmarinaro?source=rss-58d103767d53------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 11:34:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@paulmarinaro/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[REpresentational State Transfer]]></title>
            <link>https://medium.com/@paulmarinaro/representational-state-transfer-c8a8c897a3e2?source=rss-58d103767d53------2</link>
            <guid isPermaLink="false">https://medium.com/p/c8a8c897a3e2</guid>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Paul Marinaro]]></dc:creator>
            <pubDate>Sun, 15 Jul 2018 18:56:25 GMT</pubDate>
            <atom:updated>2018-07-15T18:56:25.242Z</atom:updated>
            <content:encoded><![CDATA[<h4>REST</h4><h4>History</h4><p>Roy Fielding defined REST in his 2000 PhD dissertation at UC Irvine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*dQ9Bo-mSBjeb9b1S34Xu_Q.jpeg" /><figcaption>Roy Fielding speaking at <a href="https://en.wikipedia.org/wiki/O%27Reilly_Open_Source_Convention">OSCON</a> 2008.</figcaption></figure><h4>What is REST?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*z-5kRyhfEDDAU-iM7fZ29g.png" /></figure><p>REST can be thought of as a kind of contract for how clients should interact with URLs (Uniform Resource Locators) and an interface construction pattern for server applications.</p><h3>Principles of REST</h3><p>There are four main principles that define the REST pattern.</p><h4>Use HTTP methods explicitly</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/430/1*8Bk0Y6yIyhNOEI4ck8Q5kg.png" /></figure><p>HTTP methods, such as GET and POST are verbs that describe actions to b performed on a resource.</p><h4>Be stateless</h4><p>A sessions state should exist on the client, not the server. A server should not track the state of a client. Each request from the client to the server should be independent and contain all the information necessary to service the request.</p><h4>Provide resources (descriptive URLs)</h4><p>URLs should be descriptive and logical. The name of the URL should describe what it should be used for. A URL is a location of a resource. This includes the domain name (address of the server) and the endpoint (path to the resource). For example, the URL pets.com/dogs, might describe a collection of dogs that a client could GET (retrieve) data from or POST (add) a dog to that collection.</p><h4>Define format for data exchange</h4><p>Lastly, the format for the data to be exchanged between client and server should be pre-defined. Generally, this data is in the JSON or XML format.</p><h4>HTTP Methods &amp; URL Endpoints</h4><p>Here is an example of how HTTP methods might be used on some URL endpoints.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/789/1*Gn-kdi45px1WsmrKgUjz7g.png" /></figure><p>Notice that different HTTP verbs can be used on the same API endpoint to different effects. A GET request to /users might retrieve a list of users, while a POST request to /users might add a new user to the list. Each HTTP verb (method) and URL combo has a specific meaning.</p><h4>A JavaScript example</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/159/1*oMeKXGr-EavA7Ws-SZ_n_A.png" /><figcaption>Raw HTTP POST request</figcaption></figure><p>Here is a raw HTTP POST request to pets.com/dogs, where the intention is to add a dog to the resource named ‘fido,’ who has an age of 3.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/343/1*ZMC3IeWrNbS-l4ihrymKdA.png" /><figcaption>Server handling a POST request</figcaption></figure><p>Here is an example of an Express server handling that POST request. The POST request to the endpoint /dogs, takes the name and age from the body of the request and instantiates a new dog model (using the Backbone framework). The new dog is saved (perhaps to a database) and the response (res) is given.</p><h4>RESTful APIs</h4><p>An API (Application Programming Interface) is a server that defines how to interact with it using HTTP requests. The term Restful API simply refers to an interface that conforms to the REST pattern.</p><h4>Why REST?</h4><p>The REST pattern encapsulates the best practices and most successful characteristics of the web: URL addressable resources, the HTTP protocol (and HTTP methods), and the request-response cycle (make a request — receive a response — display the response). Agreement on this REST architectural style by developers, has led to faster performance and greater reliability of web sites.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c8a8c897a3e2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pomander, the ESLinter]]></title>
            <link>https://medium.com/@paulmarinaro/pomander-the-eslinter-ed6132e0dce7?source=rss-58d103767d53------2</link>
            <guid isPermaLink="false">https://medium.com/p/ed6132e0dce7</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Paul Marinaro]]></dc:creator>
            <pubDate>Mon, 09 Jul 2018 03:01:34 GMT</pubDate>
            <atom:updated>2018-07-09T03:03:54.763Z</atom:updated>
            <content:encoded><![CDATA[<p>Why is it sniffing your code?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/140/1*OcwHf2l_CrswD3Qy7AczzQ.png" /></figure><p>Pomander is a pre-commit linter from Hack Reactor Labs.</p><p>Pomander uses a pre-commit hook to run staged JavaScript files through ESLint before each commit. ESLint is a popular linter that checks your code for syntax and style errors.</p><p>So, why is it called Pomander, and why does it sniff your code?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/253/1*QMisGVS7dStDCQ43iCDDEg.jpeg" /><figcaption>Venetian woman with a pomander</figcaption></figure><p>A pomander, from the french <em>pomme d’ambre</em>, i.e. apple of amber, is a ball or perforated container scented with perfumes. The pomander was either worn or carried in a vase, of the same name, as a protection against infection in times of pestilence or merely as a useful article to modify bad smells.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*tswYz0uM2AWyaQEnZPBpuw.jpeg" /></figure><p>Often made of gold or silver, the spherical pomanders could be worn on a neck-chain or belt, attached by a chain to a ring and held in the hand, or made into cape buttons or rosary beads.</p><p>Back to the world of JavaScript…</p><h4>System Requirements</h4><p>Pomander, the ESLint add-on, requires a working copy of npm, the package manager that comes bundled with Node.js.</p><p>Using npm, install ESLint:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/244/1*EzXQ1XJvr57b2kXwBl5heQ.png" /></figure><h4>Installation</h4><p>Within a git repository, run the following command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/911/1*JsQv_L5DHAf57-a1FDr5dg.png" /></figure><h4>Usage</h4><p>Pomander will run before each git commit, checking for syntax errors. If there are any syntax errors, the commit will fail and you will need to fix any errors before you try to commit again.</p><p>If, however, you’d like to skip Pomander, you can commit with the ‘no verify’ option:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/165/1*UX3_Ckv_GOk1le1XEJQ9Tg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/120/1*CL5M3Vw1uvKvA7HsH03lEQ.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ed6132e0dce7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[B-tree]]></title>
            <link>https://medium.com/@paulmarinaro/b-tree-f10b20b5d622?source=rss-58d103767d53------2</link>
            <guid isPermaLink="false">https://medium.com/p/f10b20b5d622</guid>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Paul Marinaro]]></dc:creator>
            <pubDate>Mon, 02 Jul 2018 02:44:26 GMT</pubDate>
            <atom:updated>2018-07-02T02:45:42.722Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/214/1*Gxdx2dDLZsBD3aJgSOCaLA.jpeg" /></figure><h4>What is a B-tree?</h4><p>A B-tree is type of tree data structure that can be used for storage systems that read and write large blocks of data, such as discs, databases, and filesystems.</p><p>What is a tree data structure?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/347/1*h3koGce0YA7XP_xuAcZisg.png" /><figcaption>When thinking about a tree data structure, it is more helpful to visualize an upside-down tree.</figcaption></figure><h4>Tree Data Structure</h4><ul><li>organizational structure for the storage and retrieval of data</li><li>each node has value (e.g. 5) and children (e.g. 4)</li><li>lower values go the left</li><li>higher values go the right</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/314/1*q2bsVT9TDnEukhp6b5t56Q.png" /><figcaption>binary search tree</figcaption></figure><h4>Binary Search Tree</h4><ul><li>balanced</li><li>Time complexity for search, insert, and delete operations: 0(log n) (i.e. logarithmic)</li><li>each node can have a maximum of 2 children</li></ul><p>The time complexity is improved by only having to search half the tree. For example, if we wanted to know if the tree included the value 10, we would start at the root (5), and since 10 is greater than 5, we would go to the right, to the node of value 9. Since 10 is also greater than 9, we would look to the right again, but since there is no node there, we already know, in two steps, that there is no value of 10 in our tree.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/487/1*MeqA_X0LWFgBhdPRAaVdlg.png" /><figcaption>unbalanced binary search tree</figcaption></figure><h4>Binary Search Tree</h4><ul><li>unbalanced</li><li>Time complexity for search, insert, and delete operations: 0(n) (i.e. linear)</li></ul><p>In this case we lose our improved time complexity.</p><p>Let’s use the same example as above. If we wanted to find out if there was a node with a value of 10, starting at the root (3), we’d have to check every node through 9, before we could determine that there was no value of 10.</p><p>This a big problem, because we want to maintain our improved logarithmic time complexity.</p><h4>What’s the solution?</h4><p>The solution is self-balancing trees, and one such tree is called a B-tree.</p><h4>B-tree</h4><h4>What is a B-tree?</h4><ul><li>self-balancing tree data structure</li><li>keeps data sorted</li><li>allows searches, insertions, and deletions in logarithmic time</li></ul><p>Fun fact:</p><ul><li>what the ‘B’ stands for has never been established</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*O8xRWd7E3tw3HaQzijnxWg.png" /><figcaption>B-tree example</figcaption></figure><p>Here’s an example of a B-tree. One major difference between a Binary Search Tree and a B-tree is that the B-tree can have more than 2 children, and each node can store multiple values, called keys.</p><h4>Rules for B-tree’s</h4><ul><li>For a B-tree of order <em>m</em>, every node has at most <em>m</em> children.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*xEROA_TiGYBr0bKnzE4FQg.png" /><figcaption>B-tree of order 5, each node can have a maximum of 5 children</figcaption></figure><ul><li>A non-leaf node with k children contains k-1 keys</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/549/1*nZKC24SYvI8fcoMtByTQWQ.png" /><figcaption>non-leaf (root) node has 3 children, and therefore 2 keys</figcaption></figure><ul><li>root has at least two children if it’s not a leaf node</li></ul><p>Here’s a link to a great visualizer to see how a B-tree works:</p><p><a href="https://www.cs.usfca.edu/~galles/visualization/BTree.html">B-Tree Visualization</a></p><h4>JavaScript code example</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/425/1*6lBCv4HYVuSJ9DhCamqASA.png" /><figcaption>A B-Tree node</figcaption></figure><h4>Inserting into a B-tree</h4><ol><li>Find leaf where value should go</li><li>Insert the value into leaf, then sort</li><li>If overflow:</li></ol><ul><li>push median value to parent</li><li>split node into left (smaller values) and right (larger values)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/553/1*6S8526kmRtvxNBflb9snYQ.png" /><figcaption>B-tree insert method</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/546/1*wDbJElHQCOwLKypGCZ-aAQ.png" /><figcaption>B-tree search method</figcaption></figure><h4>Conclusion</h4><p>For search, insert, and delete operations, the B-tree is always 0(log n) time complexity.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f10b20b5d622" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Higher Order Functions]]></title>
            <link>https://medium.com/@paulmarinaro/higher-order-functions-7508642c7839?source=rss-58d103767d53------2</link>
            <guid isPermaLink="false">https://medium.com/p/7508642c7839</guid>
            <category><![CDATA[functional-programming]]></category>
            <dc:creator><![CDATA[Paul Marinaro]]></dc:creator>
            <pubDate>Mon, 25 Jun 2018 02:41:48 GMT</pubDate>
            <atom:updated>2018-06-25T02:43:44.248Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Why should we use them?</strong></p><p>In JavaScript, functions are values, and functions can be as assigned as variables.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/268/1*njM-I95qPLZrP6J9J1BpjA.png" /></figure><p>This allows us to do some really cool things, like pass functions into other functions, Higher Order Functions.</p><h4>Higher Order Functions, Definition:</h4><p>Higher Order Functions can either:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/359/1*HWpq8tmxFSowN3i7712l5g.png" /><figcaption>The forEach Higher Order Function takes the l =&gt; console.log(l) function as an argument</figcaption></figure><ul><li>take another function as an argument</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/359/1*oAAVxtrDC-jc8oCvLmTjdQ.png" /><figcaption>The Higher Order Function ‘greaterThan’ returns an anonymous function as a result</figcaption></figure><ul><li>OR, return a function as a result</li></ul><h4>Examples of Higher Order Functions:</h4><ul><li>map</li><li>filter</li><li>reduce</li></ul><p>many functions from the underscore library:</p><ul><li>_.each</li><li>_.reject</li><li>_.uniq</li><li>_.every</li><li>_.some</li></ul><h4>Why use Higher Order Functions?</h4><p>Ok, so now that we know what Higher Order Functions are, why should we use them?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*jzWLDJoBieiSkMbIyBnHZw.png" /></figure><p>Well, when we don’t use Higher Order Functions, our program code can sometimes get unnecessarily large in size.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WKBFxGNzm7e7eRcihLaXZQ.jpeg" /></figure><p>There is often a correlation between an unnecessarily large program size and complexity. The larger the program, often the greater the complexity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*BfNK5fvcjdRkpZ22PXIZhQ.jpeg" /></figure><p>The greater the complexity, the greater the possibility for confusion of other programmers you may be working with, or even for your future self (trying to remember the logic of your code).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*kgoX4I8vjBNy0kPgggdkBw.jpeg" /></figure><p>And, confusion on the part of programmers often leads to bugs in our software.</p><h4>Reasons to use Higher Order Functions</h4><ul><li>less code</li><li>less bugs (because your code will be easier to reason about)</li><li>less time (because you can re-use more code)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/461/1*4SP3NCQMAqyBvlWxfU7_Iw.png" /></figure><p>In this example, I show two ways of finding the names of all the pets in the ‘pets’ array. On line 3, I use map, a Higher Order Function that iterates through all the items of an array and returns a new array with all the pet’s names. Notice that this is accomplished in one line of code that is very easy to reason about: Map over ‘pets’ and for each ‘pet’, return the pet’s name. Contrast this method, with line 5 through 8: I create a for loop to iterate over the ‘pets’ array and push each pet’s name into a ‘names’ array. Both methods achieve the same result, but the first method (on line 3) is the more elegant solution, with less code, less potential for bugs, and it took less time to write.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7508642c7839" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Asynchronous Code]]></title>
            <link>https://medium.com/@paulmarinaro/asynchronous-code-28a5925cc47d?source=rss-58d103767d53------2</link>
            <guid isPermaLink="false">https://medium.com/p/28a5925cc47d</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Paul Marinaro]]></dc:creator>
            <pubDate>Sun, 27 May 2018 19:53:10 GMT</pubDate>
            <atom:updated>2018-05-27T19:53:10.509Z</atom:updated>
            <content:encoded><![CDATA[<p>JavaScript is a single-threaded coding language, meaning that only one operation can be carried out at a time. This could really slow things down if any operation took a long time to complete, so JavaScript utilizes asynchronous code. While the program is waiting for an event that will happen at some future point in time, JavaScript puts that event aside and listens for when it is actually triggered. In the meantime, JavaScript will continue running other code until that event finally gets triggered, at which point it will get slated to be executed. This process revolves around the event loop that continually runs in the background, doing internal upkeep, queuing events to be invoked, and dequeuing/executing them off the list. When the asynchronous code if finally completed, a callback function can be used to continue on from where the code left off. Otherwise, JavaScript would have skipped ahead to the next part in the code, potentially out of the intended order of actions.</p><h4>Examples of asynchronous operations</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/225/1*rBf89N7g1Tx0qKqYbTpIsg.jpeg" /><figcaption>A timer</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/359/1*mCaDDC7xi91WgqDeb3OOnA.png" /><figcaption>Display an alert box after 3 seconds (3000 milliseconds):</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/225/1*pTChMBXQZkigPDtffh3K4g.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/403/1*2hl1N5l0Apa1X6VCAIip4Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*xwKZ_f66C2DgjTS8ArbsoA.jpeg" /><figcaption>Click events (JavaScript doesn’t know when they’re going to happen), Change the text of a &lt;div&gt; element using an AJAX request:</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/456/1*Io8wvPAKe6xeq86KiZVDlA.png" /></figure><h4>Get Total Word Count example</h4><p>In this example, we are calculating the sum of the words from two files. <em>fs</em> is the file system API module. The function <em>getWordCount</em> takes the location of a file, <em>filepath, </em>and calls <em>fs.readFile </em>on it, which asynchronously reads the entire contents of that file. Each word of that <em>data</em> is separated into an array, the length of which, <em>wordCount</em>, is the number of words in the file. After these asynchronous operations, the <em>callback </em>is called on that <em>wordCount</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/1*xMjyRz2ymCxGyW6_14-ogA.png" /></figure><p>The function<em> getTotalWordCount </em>calls our previous function <em>getWordCount</em> in succession on the location of each of the files, <em>filePathOne </em>and <em>filePathTwo</em>. The resulting <em>wordCount </em>returned each time is added to the <em>totalWordCount. </em>Again, after all asynchronous operations have completed, a <em>callback</em> is called on the result of our <em>totalWordCount</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*OljLMNyGkgCBBfZgNQf2LQ.png" /><figcaption>an example of callback hell</figcaption></figure><p>As you can see from the previous example, chaining multiple functions together that require a callback to execute can lead to a long call stack that would be difficult to debug. This is often referred to as “callback hell.”</p><h4>Advantages of asynchronous code</h4><ul><li>Do work while waiting for other work to happen</li></ul><p>The code can keep running and executing other functions, while waiting for the asynchronous function(s) to finish.</p><ul><li>Improve UI experience</li></ul><p>Users would experience serious lag if they had to wait for long asynchronous functions to finish before executing any other code.</p><h4>Disadvantages of asynchronous code</h4><ul><li>Only one action can run at a time, async actions can mess up timings of slated actions</li><li>Callback Hell: debugging call stack nightmare</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28a5925cc47d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Backbone: MVC Architecture]]></title>
            <link>https://medium.com/@paulmarinaro/backbone-mvc-architecture-b108d7d4bb0b?source=rss-58d103767d53------2</link>
            <guid isPermaLink="false">https://medium.com/p/b108d7d4bb0b</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Paul Marinaro]]></dc:creator>
            <pubDate>Mon, 21 May 2018 01:52:16 GMT</pubDate>
            <atom:updated>2018-05-21T01:59:12.985Z</atom:updated>
            <content:encoded><![CDATA[<p>In software development, MVC stands for model-view-controller, a proposal for how to organize code in a user-facing application.</p><p>In Backbone, the “C” might be said to actually stand for the collection constructor (which will be explained in greater detail below), as there are no controllers in Backbone.</p><p>Backbone is an MV* (*whatever) framework that provides structure to client-side JavaScript applications. Backbone is lightweight and unopinionated, allowing for flexibility in implementation.</p><p>The three constructors of Backbone are it’s model, view, and collection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/1*JHaUjdOdpKy0OJ_4wkrBgg.png" /></figure><h4>Model</h4><p>The model orchestrates all data and business logic. It emits change events for its connected views to re-render when data changes and it loads and saves from the server.</p><h4>View</h4><p>The view listens for changes and renders UI. It handles user input and interactivity and sends the captured input to the model. View acts as the controller in Backbone.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*ptu_QQFrbhUGX7OdkPUOxQ.png" /></figure><h4>Collections</h4><p>Collections handle a group of related models. They listen for changes in all of their models and provide helper functions. They also load and save new models on the server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*ltG287yZRlKyV9LMMpoFiw.png" /></figure><h4>Example: <em>Siskel’s Movie Rater</em></h4><p>To illustrate the MVC constructors of Backbone, let us examine a simple application, <em>Siskel’s Movie Rater. </em>This application sorts movies by title, year, rating, or likes. The user can click on the thumbs up button to register a like/dislike of each individual movie.</p><p>In this example each individual movie is a <strong>model</strong> with title, year, rating, like properties, and a toggleLike function.</p><p>The Movies <strong>collection</strong> listens for changes to any of the movies, and can sort them with its sortByField function.</p><p>The <strong>views,</strong> MoviesView and MovieView, render the images of the list of movies and listen for any user inputs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/855/1*nkThgWAHClQvPtUFlSNq3A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/313/1*e_AcMhN0KRHeHAxMzLMrUg.png" /></figure><h4>Model: Movie</h4><p>Each individual movie has a Movie model that manages it’s data attributes, in this case the <strong>defaults</strong> property “like.” The model will trigger a <em>change</em> event when “like” is modified.</p><p>Backbone uses the .extend method for subclassing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/415/1*Vb7L8_PrpYN4cwptquZfLw.png" /></figure><h4>Collection: Movies</h4><p>Movies is a <strong>collection</strong> of Movie <strong>models</strong>. It has an <strong>initialize</strong> property that listens for a change in “like” for each Movie model. It’s sortByField method sorts each movie by the field (title, year, rating, or likes) chosen by the user in the AppView.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/307/1*Aa8J2TPH9e9TKzvZdYwKPA.png" /></figure><h4>View: AppView</h4><p>AppView listens for a user input click on one of the input fields (title, year, rating, or likes) and with it’s handleClick method, calls the Movies <strong>collection</strong> sortByField method, which sorts the each Movie <strong>model</strong>.</p><p>When AppView’s render method is called, it instantiates MoviesView which renders the <strong>collection</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/603/1*sSaek2E6HdfdyJOPA78VpQ.png" /></figure><h4>View: MovieView</h4><p>MovieView is the <strong>view</strong> for each Movie <strong>model</strong>, with a template for how each will render to the Document Object Model (DOM). MovieView initializes to listen for changes to it’s corresponding <strong>model</strong>’s “like” property, and will re-render it’s thumbs-up button image into a thumbs-down image if the button is clicked. The events handler calls handleClick on such an event.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/402/1*K6syBamvIEfwrNxqWy2lvQ.png" /></figure><h4>View: MoviesView</h4><p>MoviesView initializes to listen for “sort” changes, calling it’s render method to first, clear the current list of movies shown, then iterate through the <strong>collection</strong>, calling the renderMovie method on each individual movie. The renderMovie method instantiates a new MovieView for each movie and appends each to the DOM.</p><h4>Why do we use Backbone?</h4><p>Backbone is a deeply rooted legacy code framework that is used all over the place on the internet. A lot of companies still use it today, so as software developers, we’d best learn it.</p><h4>Backbone Pros:</h4><p>As an unopinionated framework, Backbone gives developers flexibility in their implementations. There is not just one right way to do things.</p><p>Backbone is lightweight, using very little memory.</p><p>In Backbone, when a model changes, the associated views update themselves. There is no need to search for a specific element id on the DOM.</p><h4>Backbone Cons:</h4><p>Backbone is not a popular framework for the purposes of starting new projects. In comparison to other frameworks, Backbone doesn’t write as much code for you, so productivity may be lessened.</p><p>Backbone’s unopinionated nature may lead to unclear architecture choices.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b108d7d4bb0b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pseudoclassical Instantiation and Subclassing]]></title>
            <link>https://medium.com/@paulmarinaro/pseudoclassical-instantiation-and-subclassing-b72795fb3b44?source=rss-58d103767d53------2</link>
            <guid isPermaLink="false">https://medium.com/p/b72795fb3b44</guid>
            <dc:creator><![CDATA[Paul Marinaro]]></dc:creator>
            <pubDate>Mon, 14 May 2018 13:35:29 GMT</pubDate>
            <atom:updated>2018-05-14T13:59:25.740Z</atom:updated>
            <content:encoded><![CDATA[<h4>One pattern for creating new<em> </em>instances of objects</h4><p>In order to better understand these concepts, let’s break down our subject piece by piece.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*caif5NVmbyaUDeMtOtNy9Q.jpeg" /></figure><h4>Pseudoclassical</h4><p>The Pseudoclassical style in JavaScript mimics the class-based languages (like Java and C++). JavaScript does not provide a class implementation per se. The <em>class </em>keyword added in ES6 is actually just syntactical sugar. JavaScript is still just a prototype-based language.</p><h4>Instantiation</h4><p>Creating a <em>new</em> instance of an object with a constructor function, using the <em>new </em>keyword</p><h4>Subclassing</h4><p>Inheritance in JavaScript through objects. Each object has a property which holds a link to another object, called its <strong>prototype. </strong>That <strong>prototype </strong>object has a prototype of its own, and so on until an object is reached with null as its prototype. This is called the <strong>prototype chain.</strong></p><h4>Example</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/280/1*CP3p_9bzEDbMyxEIKSFa7g.jpeg" /></figure><p>In this example, we have a constructor function that makes instances of Horse. Horse has a name property and a method added to it’s prototype. Our Horse will be the superclass that our later creation will inherit properties and methods from.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/96ee0f3e01c66718dd3f2448933dd944/href">https://medium.com/media/96ee0f3e01c66718dd3f2448933dd944/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/1*Nmw5HqKteocbBY5g_DNnuw.jpeg" /></figure><p>Our subclass, FlyingHorse, inherits Horse’s name property and augments it’s method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c04bb57563606c936810938fbf7e1318/href">https://medium.com/media/c04bb57563606c936810938fbf7e1318/href</a></iframe><h4>Real world application</h4><p><strong>Google Closure</strong></p><p>Closure is a set of individual JavaScript tools that are designed to help developers build complex web applications, and is used by Gmail, Google Maps, and Google Docs. Closure’s inheritance structure is implemented in the Pseudoclassical style.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/1*gPpLyrA1H9zLacZvtV3NAA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b72795fb3b44" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Structures: Queue & Stack]]></title>
            <link>https://medium.com/@paulmarinaro/data-structures-queue-stack-1f5dad5e324f?source=rss-58d103767d53------2</link>
            <guid isPermaLink="false">https://medium.com/p/1f5dad5e324f</guid>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[stack]]></category>
            <category><![CDATA[queue]]></category>
            <dc:creator><![CDATA[Paul Marinaro]]></dc:creator>
            <pubDate>Wed, 02 May 2018 01:01:51 GMT</pubDate>
            <atom:updated>2018-05-03T03:42:11.898Z</atom:updated>
            <content:encoded><![CDATA[<p>In computer science, a <strong>data structure</strong> is a particular way of organizing and storing data in a computer so that it can be accessed and modified efficiently. More precisely, a data structure is a collection of data values, the relationships among them, and the functions or operations that can be applied to the data.</p><h3>Queue</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/326/1*2sqDjOjrNXXLQMKX-cULGA.jpeg" /></figure><p>A <strong>queue</strong> is a particular kind of abstract data type or collection in which the items in the collection are kept in order and only added to the rear terminal position, known as <em>enqueue,</em> and removed from the front terminal position, known as <em>dequeue</em>.</p><p>A queue works like a line for your favorite taco stand — people enter at the end of the queue and leave from the front (<em>FIFO</em>: first in, first out).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*Zb9XZDEBuHcZkBaoCyJ78Q.png" /><figcaption>Representation of a <a href="https://en.wikipedia.org/wiki/FIFO_(computing_and_electronics)">FIFO</a> (first in, first out) queue</figcaption></figure><h4>Implementation</h4><p>Here is an example of a <strong>queue </strong>function in JavaScript that follows the Pseudoclassical Instantiation Style:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3239f369a52fc498ea312459d4b4b1e6/href">https://medium.com/media/3239f369a52fc498ea312459d4b4b1e6/href</a></iframe><h3>Stack</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/183/1*paPYE56ctgzhH-6lUnm7Kw.jpeg" /></figure><p><em>A </em><strong>stack</strong> is an abstract data type that serves as a collection of elements, with two principal operations:</p><ul><li><strong>push</strong>, which adds an element to the collection, and</li><li><strong>pop</strong>, which removes the most recently added element that was not yet removed.</li></ul><p>A stack works like a stack of books — books are added and removed from the the top of the stack (<em>LIFO</em>: last in, first out).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/0*Qipb8A8FzaKVcptN.png" /><figcaption>Simple representation of a stack runtime with <em>push</em> and <em>pop </em>operations.</figcaption></figure><h4>Implementation</h4><p>Here is an example of a <strong>stack</strong> function in JavaScript that follows the Pseudoclassical Instantiation Style:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3feaabbdc8b3f1b5f503ee33ec65cc6/href">https://medium.com/media/e3feaabbdc8b3f1b5f503ee33ec65cc6/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1f5dad5e324f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>