<?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 Mike Rourke on Medium]]></title>
        <description><![CDATA[Stories by Mike Rourke on Medium]]></description>
        <link>https://medium.com/@mikerourke?source=rss-72847384ec32------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Nn9hsWWmx7rjrGIg_dmqnQ.jpeg</url>
            <title>Stories by Mike Rourke on Medium</title>
            <link>https://medium.com/@mikerourke?source=rss-72847384ec32------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 16:52:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mikerourke/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[Effective Refactoring: Part 4]]></title>
            <link>https://medium.com/@mikerourke/effective-refactoring-part-4-e9b8a202d440?source=rss-72847384ec32------2</link>
            <guid isPermaLink="false">https://medium.com/p/e9b8a202d440</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[refactoring]]></category>
            <dc:creator><![CDATA[Mike Rourke]]></dc:creator>
            <pubDate>Tue, 13 Mar 2018 15:31:02 GMT</pubDate>
            <atom:updated>2019-12-14T23:06:35.187Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wkFcTU2uBThIW_yNS8j1YA.png" /><figcaption>Git Icon by <a href="https://twitter.com/jasonlong">Jason Long</a> / <a href="https://creativecommons.org/licenses/by/3.0/deed.en">CC BY 3.0</a></figcaption></figure><h4>Rewriting the Code</h4><p><em>This is the final part of a 4 part series on effective refactoring.</em></p><ul><li><a href="https://medium.com/@mikerourke/effective-refactoring-part-1-d923a2b42065"><em>Part 1: Asking the Right Questions Before You Get Started</em></a></li><li><a href="https://medium.com/@mikerourke/https-medium-com-mikerourke-effective-refactoring-part-2-7ed215ff581c"><em>Part 2: Formulating a Plan</em></a></li><li><a href="https://medium.com/@mikerourke/effective-refactoring-part-3-d4b8972046e9"><em>Part 3: The Imperative Role of Tests</em></a></li><li><strong><em>Part 4: Rewriting the Code</em></strong></li></ul><p>You put together a plan, selected a task to work on, wrote the tests, and now you’re ready to clean up some code. It’s about time! You’ll be tempted to open up a file and start changing variable names, or clean up the contents of a folder that have been driving you nuts. Before you start digging into the codebase, however, there are a few concepts you should familiarize yourself with to ensure the refactoring goes smoothly.</p><p>In the final part of this series, I’m going to cover some of the common pitfalls that you may encounter over the course of a rewrite. I’ll also present techniques for expediting some of the more tedious tasks. I <strong>won’t</strong> be covering the specific mechanics, definitions, or processes associated with refactoring; if you’re interested in learning more about that topic, check out these great resources:</p><ul><li><a href="https://martinfowler.com/books/refactoring.html">Refactoring: Improving the Design of Existing Code</a> by Martin Fowler</li><li><a href="https://www.amazon.com/Refactoring-Patterns-Joshua-Kerievsky/dp/0321213351">Refactoring to Patterns</a> by Joshua Kerievsky</li><li><a href="https://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882">Clean Code: A Handbook of Agile Software Craftsmanship</a> by Robert C. Martin</li></ul><h3>Identify Opportunities to Automate</h3><p>There’s a <strong>very</strong> good chance that you’ll have some project tasks that will be tedious. One of the biggest culprits I encountered was <em>moving files</em>. For example, the application I refactored had the Redux actions, reducers, and selectors in their own separate folders. One of my project tasks was to group the Redux files by module (e.g. appActions.js, appReducer.js, and appSelectors.js). I could have run a git mv command to move /actions/app.js to /redux/app/appActions.js, then do the same for /reducers/app.js and /selectors/app.js, but that only takes care of the app module. There were 11 modules in this project, so I’d have to type out 33 git mv commands just for the Redux elements. You may have to run git mv 150 more times to get the React containers and components in the right folder location!</p><p>You’ll find that this situation can quickly become untenable. Rather than type out all those commands, I wrote a script to do it for me using JavaScript and Node.js:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/19a73ad2681ae540f96e7f32969422c4/href">https://medium.com/media/19a73ad2681ae540f96e7f32969422c4/href</a></iframe><p>You can either go into the files and update the relative paths after running the script, or you can write a script to update the paths using string manipulation. Automation can get pretty fancy, but know when to draw the line: it wouldn’t make sense to spend 20 hours writing a script to save one hour of manual work. Most codebases are unique and have specific structures, which means you probably won’t be able to reuse these scripts.</p><h3>Commit Often</h3><p>Making significant changes to a file or set of files can break your app and cause tests to fail. This is to be expected. If you’ve made a bunch of changes and everything works, <em>commit the changes</em>. If you’ve only made a few minor updates and everything still works, <em>commit the changes</em>. Making commits is cheap. Here are some metrics for the app I refactored:</p><ul><li><strong>1,747</strong> commits</li><li><strong>378</strong> closed pull requests</li><li><strong>42,017</strong> total lines of text across <strong>169</strong> Jest snapshot files</li><li><strong>13,555</strong> total lines of text across <strong>181</strong> test files</li><li><strong>24,261</strong> total lines of text across <strong>2</strong> fixture files (responses.js and state.js)</li><li><strong>16,685</strong> total lines of text across <strong>198</strong> JavaScript files</li><li><strong>3,823</strong> total lines of text across <strong>111</strong> Sass files</li></ul><p>That’s <strong>76,080</strong> lines of code across <strong>659</strong> files, and the repository size is only <strong>10MB</strong>. Make all the commits you want — git can handle it. You can always <a href="https://davidwalsh.name/squash-commits-git">squash them later</a> if you want to clean up your history. I urge you to commit as frequently as possible; when refactoring a large app you’ll very quickly realize how difficult it can be to track down small, breaking issues.</p><p>Imaging making changes to 10 files, verifying your app still works, and feeling generally happy with the code. You decide not to commit your changes, and after another half-hour of refactoring you break something. You can either spend 3 hours tracking down the bug or just discard all of your changes and start from scratch. Since you didn’t commit the changes to those 10 files, you lost perfectly good code!</p><p>I’m not saying it’s impossible to determine if you need to reset those files, but why waste time and energy when you <strong>know</strong> you can jump back to the last commit and go from there. Try to limit the changes on commits to only a few files at a time, and commit often so you have reliable “save points” to fall back on.</p><h3>Avoid Temptation</h3><p>Avoid the urge to clean up code that’s out of the scope of the task at hand. This is one of the most difficult aspects of refactoring. Let’s say you were working on task called Standardize Redux Selector Names<strong> </strong>that involved updating the names of the selectors to ensure all of them were prepended with the word select. As a relatively simple task with low risk and well-defined scope, it should go smoothly; you just need to update the selector names (along with any files that reference these selectors) to accommodate the change (and don’t forget about the tests!)</p><p>Let’s say you come across a selector that’s using <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign">Object.assign()</a>, and one of your future tasks is to update the code to utilize some of the newer ESNext features like the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax">spread syntax</a>. You may be tempted to update that code, but don’t!</p><p>It is imperative that you don’t deviate from the current task. Even the most trivial change can set you on the wrong path. Even though the concept of a <a href="https://en.wikipedia.org/wiki/Slippery_slope">slippery slope</a> is a logical fallacy, a less hyperbolic situation will often occur. You start changing Object.assign() statements and before you know it, 4 hours has elapsed and you’ve only updated 2 selector names!</p><p>As I progressed through my refactoring tasks, I became much less susceptible to this type of behavior. I added a // REFACTOR: Fix this later comment in the code and checked my project to ensure I had a task to cover the change, then I moved on.</p><h3>Be Methodical with Pull Requests</h3><p>Pull requests are an excellent tool in refactoring projects for a number of reasons, they:</p><ul><li>provide a record of changes that correspond with a project task,</li><li>define a rollback point if new bugs are introduced,</li><li>enable peers to review your code and look for potential bugs, and</li><li>offer the opportunity to explain why you made certain changes</li></ul><p>If you spend a large chunk of time cleaning up a section of the codebase, it can be difficult to step back and evaluate the quality of your changes. Pull requests give your colleagues the opportunity to review your changes and determine whether they add value and improve the existing code.</p><p>When you’re submitting pull requests, be as descriptive as possible in the summary. Put together a template and include it in your repository. If you’re using GitHub, this <a href="https://help.github.com/articles/creating-a-pull-request-template-for-your-repository/">template will be pulled in automatically</a> for new PRs. Try to include a title, high-level description, a section for important notes, and a bulleted list of changes. The list of changes doesn’t have to be extensive and wordy, but it should cover important changes that reviewers should focus on.</p><p>One metric that you need to be cognizant of is the quantity of changes associated with a pull request. Try to limit the amount of changes to +/-500 lines of code. Adding Jest snapshot files can easily add thousands of lines to a pull request, so be sure to include a note about this in the summary. If you can’t minimize the quantity of changes, strive to reduce the complexity. If you’re just reordering import statements, exceeding 2,000 lines of code is acceptable as long as the changes are not overly complex. Try to isolate that change in a single PR and ensure that you describe the nature of the change in the summary. It helps to include a bold note at the beginning of the summary with something like “No logic changes were made”<strong> </strong>so the reviewer has proper context.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/338/1*SbdQja8V4kL__F8VbqS5EQ.png" /><figcaption>Try not to be this guy (me, that guy is me)</figcaption></figure><p>By writing descriptive summaries in your pull requests and ensuring that the scope of changes corresponds to the project tasks, you’ll make life much easier for reviewers. I’ll admit that I wasn’t always able to follow my own advice (I still owe some of my coworkers a lunch or 10), but I made sure I responded to inquiries and addressed concerns quickly.</p><h3>Wrap Up</h3><p>That’s it for the refactoring series! I hope the collective nuggets of wisdom I presented will contribute to the success of your refactoring project. Refactoring isn’t as simple as rearranging files or renaming functions in your codebase, but if you <a href="https://labnotes.panderalabs.com/https-medium-com-mikerourke-effective-refactoring-part-2-7ed215ff581c">put together a solid plan</a>, adhere to that plan, and update regularly then you’ll be off to a good start. <a href="https://labnotes.panderalabs.com/effective-refactoring-part-3-d4b8972046e9">Having a robust testing infrastructure</a> will give you the confidence to make changes without breaking any functionality.</p><p>In terms of execution, automate as much as you can, commit often, and avoid temptation. Pull requests are an excellent documentation and review tool, so ensure they’re detailed and limited in scope. In case you were wondering, here are the results of my refactoring project:</p><ul><li><strong>40</strong> tasks completed</li><li><strong>12</strong> tasks pending</li><li><strong>1</strong> Jira bug logged (directly related to the refactor)</li><li><strong>1,473 </strong>tests written across <strong>181</strong> test suites (<strong>737</strong> of which were snapshot tests)</li><li><strong>108,450</strong> lines added and <strong>44,241</strong> lines removed</li><li><strong>38</strong> pull requests</li><li><strong>99.84%</strong> Statement coverage</li><li><strong>95.07%</strong> Branch coverage</li></ul><p>The lines added and removed don’t really mean much, as most of them represented file moves, snapshots, and the test fixture files. The high test coverage should be taken with a grain of salt as well: I’m ignoring some of the chart components because it’s difficult to test the HTML &lt;canvas&gt;. I added several features and fixed miscellaneous bugs over the course of the refactoring, and having high test coverage caught several potential issues before they could be included in the release. Overall, I’d say the rewrite was <strong>definitely</strong> worth the effort.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e9b8a202d440" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Effective Refactoring: Part 3]]></title>
            <link>https://medium.com/@mikerourke/effective-refactoring-part-3-d4b8972046e9?source=rss-72847384ec32------2</link>
            <guid isPermaLink="false">https://medium.com/p/d4b8972046e9</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[refactoring]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Mike Rourke]]></dc:creator>
            <pubDate>Fri, 02 Feb 2018 19:24:20 GMT</pubDate>
            <atom:updated>2019-12-14T23:06:02.208Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mdl4w6uU5uyYsFjkyo8j4Q.png" /></figure><h4>The Imperative Role of Tests</h4><p><em>This is the third part of a 4 part series on effective refactoring.</em></p><ul><li><a href="https://medium.com/@mikerourke/effective-refactoring-part-1-d923a2b42065"><em>Part 1: Asking the Right Questions Before You Get Started</em></a></li><li><a href="https://medium.com/@mikerourke/https-medium-com-mikerourke-effective-refactoring-part-2-7ed215ff581c"><em>Part 2: Formulating a Plan</em></a></li><li><strong><em>Part 3: The Imperative Role of Tests</em></strong></li><li><a href="https://medium.com/@mikerourke/effective-refactoring-part-4-e9b8a202d440"><em>Part 4: Rewriting the Code</em></a></li></ul><blockquote>If you don’t like testing your product, most likely your customers won’t like to test it either.</blockquote><p>Read any book or article on software testing and most of them will mention, at some point, that developers aren’t crazy about writing tests. I’m not going to debate the accuracy of that statement, but I am reminded of a quote from Ralph Waldo Emerson:</p><blockquote>Your actions speak so loudly, I can not hear what you are saying.</blockquote><p>If you write tests and appreciate their worth, your application will have a lot of tests, plain and simple. <strong>If the goal of your refactoring project is to fail spectacularly, don’t write any tests</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*6t4bAXWcLPsHDdqqfBPcFw.png" /><figcaption>No tests.</figcaption></figure><p>Tests will alleviate one of the main stressors of refactoring: the possibility of breaking the application. Let’s face it, no developer is perfect and no tool is completely error proof. Throughout the course of rewriting code, you may <em>accidentally</em> delete a line or <em>purposefully</em> remove some logic that seemed unnecessary. If you’re making a significant amount of changes to a file, these breaking changes might go unnoticed. <strong>Tests will always notice.</strong></p><p>In Part 3 of this series, I will walk you through the process of setting up an effective testing infrastructure. I’m using <a href="https://facebook.github.io/jest/">Jest</a> and <a href="http://airbnb.io/enzyme/">Enzyme</a> because getting up and running is relatively quick. I recommend reading the following articles for configuring these libraries in a React/Redux app.</p><ul><li><a href="https://hackernoon.com/implementing-basic-component-tests-using-jest-and-enzyme-d1d8788d627a">Implementing basic Component tests using Jest and Enzyme</a></li><li><a href="https://www.sitepoint.com/test-react-components-jest/">How to Test React Components Using Jest</a></li></ul><p>For the purposes of this article, I don’t want to dive too deep into the setup and configuration. One of the first steps to building a solid testing foundation is setting up a source of reliable mock data. Let’s get started!</p><h3>Setting Up Mock Data</h3><p>If you’re working with an existing application, you have the advantage of knowing the shape of existing data and how it’s used. In most cases, the API is refined and may only require minor tweaks as new features are being added. For the application I refactored, I created two files with data: one with the API responses and one with a populated Redux state. It may take a little legwork and a lot of copying and pasting to create these files, but it only needs to be done once.</p><p>Having these data files serves two important purposes. The first and obvious one is that many of the elements you’ll be testing will display or manipulate data in some way. The second is the ability to quickly reference the shape of the data to determine the most effective tests to write and why they may be failing.</p><p>Storing the state and API responses may not always be feasible if the data is sensitive. If that’s the case you can use a library like <a href="https://www.npmjs.com/package/json-schema-faker">json-schema-faker</a> with <a href="https://www.npmjs.com/package/faker">faker</a> or <a href="https://www.npmjs.com/package/chance">chance</a> to generate random data. These libraries allow you to use a seed to generate the same data repeatedly, but I’d recommend that you generate the data once and save the generated data in the repo, rather than use a seed to generate data every time you run your tests. I stored my files in a __fixtures__ directory next to my Redux files (actions, reducers, selectors). The folder structure looks like this:</p><pre>/src<br>  /components<br>  /constants<br>  /containers<br>  /redux<br><strong>    /__fixtures__<br>      /state.js<br>      /responses.js</strong><br>    /app<br>      /appActions.js<br>      /appReducer.js<br>      /appSelectors.js<br>  /...</pre><p>The easiest way to get the entire shape of the Redux state is to use the <a href="https://chrome.google.com/webstore/detail/redux-devtools/lmhkpmbekcpmknklioeibfkpmmfibljd?hl=en">Redux DevTools</a> extension, select the <strong>Raw</strong> tab from the state view, copy everything, and paste it in a JavaScript file with a module.exports statement. I would advise only taking a small chunk of the records from state and API responses to reduce the size of the Jest snapshots. Use you best judgement when determining how many records you feel is suitable to retain. If one of the API responses returns an array of 400 records, you could definitely eliminate a significant percentage of those and still write effective tests.</p><p>Having valid data is imperative to preventing regression errors. If the data isn’t representative of what the application consumes, no amount of tests will ensure the success of the refactor.</p><p>Now that you have the data ready to go, it’s time to move onto the next step: establishing a standard format and style guide for tests.</p><h3>Standardizing Your Tests</h3><p>You’ll end up writing a great deal of tests over the course of a refactoring project. When I first started writing tests, I was relatively new to testing in general. My tests were disjointed, the wording was different between files, and the structure of the tests with regard to describe blocks varied even when testing two very similar components.</p><p>I’ve found that establishing a testing standard made writing them much easier by reducing cognitive load needed to ensure I was writing quality tests. The presence of, and adherence to, a standard is more important than the minute details. You’re free to put together something that works best for you, but there a few guidelines you should follow.</p><h4>Determine Where Test Files Will Go</h4><p>Some people prefer to mirror the src/ directory and place their test files there. Maybe you prefer to name your test files with a .spec.js extension, while others prefer .test.js. Regardless of what you choose, be consistent. The <a href="https://facebook.github.io/jest/docs/en/configuration.html">default Jest configuration</a> specifies that you co-locate your tests in a __tests__ directory and use .test.js for the file extension, so that’s the route I chose. Once you decide on a standard, add it to the README so anyone else working on the app in the future will follow suit.</p><h4>Establish a Format</h4><p>You should establish a format/structure for each context being tested (i.e. React components, Redux selectors, etc). For example, every React component and container test file I created has a setup function at the top of the file that looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2406c0f85984b0a25b10000416c46388/href">https://medium.com/media/2406c0f85984b0a25b10000416c46388/href</a></iframe><p>This made it much easier to test my components without having to write a lot of extra boilerplate. I also set up a specific describe block structure for React components.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a6a00d316f022f65657c780a9f2644b2/href">https://medium.com/media/a6a00d316f022f65657c780a9f2644b2/href</a></iframe><p>I do something similar with Redux actions, reducers, and selectors. I use <a href="https://www.jetbrains.com/help/webstorm/creating-and-editing-file-templates.html">WebStorm’s File Templates</a> feature to quickly create the test files depending on what I’m testing. Your editor most likely supports snippets or file templates, so I would advise creating templates to ensure you adhere to the standard. It helps to include a brief overview of this in the README file for posterity.</p><h3>Writing Tests</h3><p>Now it’s time to get down to brass tacks. If you’re not familiar with writing tests, it can be daunting to figure out the best course of action. You might be asking yourself a lot of questions:</p><ul><li>Where do I start?</li><li>What should I be testing?</li><li>How will I know if I’ve written enough tests to prevent bugs?</li></ul><p>There’s no definitive “right” answer to these questions, but the methodology I followed throughout the course of my project produced successful results.</p><h4>Where Do I Start?</h4><p>In <a href="https://medium.com/@mikerourke/https-medium-com-mikerourke-effective-refactoring-part-2-7ed215ff581c">Part 2 of this series</a>, I stressed the importance of having a plan. If you put together a course of action, determining where to start writing tests should be simple. Let’s say you’re starting on a task to refactor the Redux actions, reducer, and selectors for the UI state. You’ve got the state data ready to go, so writing tests should be relatively straightforward. You’ll need a library like <a href="https://github.com/arnaudbenard/redux-mock-store">redux-mock-store</a> to mock out the state to test actions. I lean pretty heavily on snapshots for testing the reducers and selectors, even if a selector only returns a string or boolean value.</p><p><strong>Make sure you write all of the tests before you change any code</strong>. Some of your tests will probably fail after you’ve refactored the code. The failed test will indicate if the failure was due to a deliberate change or an accidental one. Snapshots are invaluable in this regard. It’s easy to miss a field or misspell an object key, and seeing this in the diff will make rectifying the issue trivial.</p><p><strong>Only write tests for the parts of the code you are refactoring and any code directly affected by the changes</strong>. Trying to write tests for the entire application before starting the refactor will lead to burnout and frustration. Chasing down the dependencies and writing tests to cover all your bases can be frustrating, but will give you valuable insight into the codebase and present additional opportunities for refactoring. Add or update your project to reflect these opportunities, otherwise you could forget them and follow the wrong path.</p><h4>What Should I Test?</h4><p>When you’re just getting started, the easiest and relatively reliable way to determine what to test is code coverage. Jest has code coverage built in, and you can generate an HTML report with the coverage percentage and what parts of the code aren’t currently being covered by tests. <strong>Line</strong> coverage makes you feel good about yourself, but <strong>branch</strong> coverage is what you’ll want to focus on. If you want a detailed explanation of the difference between coverage types, check out <a href="http://jasonrudolph.com/blog/2008/06/10/a-brief-discussion-of-code-coverage-types/">this article by Jason Rudolph</a>. I’ll talk about why code coverage isn’t the single source of truth in the next section, but it’s a great tool to get you on the right track and keep you motivated.</p><h4>How Will I Know When I’ve Done Enough?</h4><p>This one is a little trickier to answer. When I was first getting started, I used Jest’s code coverage as gospel. As time went on and my experience grew, I found that this isn’t necessarily the best course of action. Coverage is an excellent tool for evaluating which sections of your code are (or are not) being tested. If you have an if statement in a function, and the else condition isn’t being covered by a test, the coverage report will point that out. It’s nice to see a high percentage and a lot of green on the report or in the terminal, but just writing tests to get into the green won’t prevent bugs.</p><p>The articles and books that have been written about writing good tests are numerous and opinionated. I like to look through a function a few times to make sure I understand the logic, then write tests that deliberately try to break it. What if a field is missing from an API response? What happens if the response is null?</p><p>For example, let’s say there’s a selector that sums up the budget allocated for each salesman in a specific district. The sales manager that runs that district has a total available budget. The total available budget should always be higher than the total allocated budget. What happens when it’s not? Is there an if statement that covers that? Reading the code and writing the tests will often make you think of situations like that. Code coverage is just going to tell you that the function is covered.</p><h3>Wrap Up</h3><p>At the risk of sounding like a broken record, I’d like to reiterate how important tests are to successfully refactoring a codebase without breaking existing functionality. Some things are going to fall through the cracks, but a leaky faucet is much easier (and cheaper) to fix than a burst pipe. If you start with reliable mock data, a good standard, and write the tests alongside the code you’re refactoring, the process should go relatively smoothly. There are many challenges you will encounter in a rewrite, but a good test suite will instill the confidence needed to overcome them.</p><p>If you’ve got a good testing framework setup and you wrote tests for the code you’re refactoring, it’s finally time to start changing the code! In the <a href="https://medium.com/@mikerourke/effective-refactoring-part-4-e9b8a202d440">next part of the series</a>, I’ll be covering tip, tricks, and some of the pitfalls that go along with a rewrite.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d4b8972046e9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Effective Refactoring: Part 2]]></title>
            <link>https://medium.com/@mikerourke/https-medium-com-mikerourke-effective-refactoring-part-2-7ed215ff581c?source=rss-72847384ec32------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ed215ff581c</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[refactoring]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Mike Rourke]]></dc:creator>
            <pubDate>Mon, 11 Dec 2017 16:41:01 GMT</pubDate>
            <atom:updated>2019-12-14T23:04:37.392Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oEhvOBecY0dWSt0Psy2QIw.png" /></figure><h4>Formulating a Plan</h4><p><em>This is the second part of a 4 part series on effective refactoring.</em></p><ul><li><a href="https://medium.com/@mikerourke/effective-refactoring-part-1-d923a2b42065"><em>Part 1: Asking the Right Questions Before You Get Started</em></a></li><li><strong><em>Part 2: Formulating a Plan</em></strong></li><li><a href="https://medium.com/@mikerourke/effective-refactoring-part-3-d4b8972046e9"><em>Part 3: The Imperative Role of Tests</em></a></li><li><a href="https://medium.com/@mikerourke/effective-refactoring-part-4-e9b8a202d440"><em>Part 4: Rewriting the Code</em></a></li></ul><h3>The Planning Phase</h3><blockquote>If you fail to plan, you are planning to fail.</blockquote><p>Benjamin Franklin (supposedly) said that. Once you’ve decided to refactor an application, your first instinct will be to start digging into the code and cleaning it up. However, <strong>without a plan, you are almost guaranteed catastrophe</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*_JwLRgx5H1A9_J4l0ocV5Q.png" /><figcaption>She didn’t have a plan</figcaption></figure><p>You don’t even want to touch the code until you have established what needs to be done, and what can be done within the available time and budget. The point of refactoring is to benefit the team and maximize the value of the code. If some portions of the code are a little messy but functional, there isn’t much point in refactoring them. We’ll discuss prioritization later, but at the very least you should identify the potential value up front.</p><p>The sections below outline some steps you should follow to ensure your project starts out on the right foot. Even if your refactoring project is relatively small, I still recommend that you use these techniques.</p><h4>Pick a Project Management Tool</h4><p>Regardless of the scope of refactoring, you’re going to need a tool to track your progress. I’m a big fan of <a href="https://trello.com/">Trello</a>. Its <a href="https://en.wikipedia.org/wiki/Kanban_(development)">Kanban</a> style of project management lends itself well to projects like these, but use whatever tool you’re comfortable with. You’ll need a tool that allows you to order and group tasks with the ability to add comments and descriptions. The ability to add attachments and create labels/tags are also nice features, but aren’t required.</p><p>For my project, I created a Trello board with the following list names for tracking tasks:</p><ul><li>Backlog</li><li>Next Up</li><li>In Progress</li><li>Pull Request</li><li>Closed</li></ul><p>I also created <a href="https://blog.trello.com/taco-tuesdays-learning-to-love-labels">labels</a> to indicate if a task involved a React component, a Redux element (i.e. actions, reducers, or selectors), or a configuration aspect of the application. If you’re a visual person like me, adding colored labels provides a way to quickly determine the nature of a task without reading the title or description. For example, I created a task to upgrade <a href="https://webpack.js.org/">webpack</a> from 1.0 to 3.0 and applied the Configuration label with a specific color to quickly identify it on the board. Now that you’ve got your project management system setup, it’s time to start breaking down the work into manageable chunks.</p><h4>Find Logical Contexts</h4><p>If the codebase is large, it can be daunting to determine how to proceed. Rather than try to think of the hundreds of tasks that need to be added to the project plan, it’s more effective to deconstruct the application down to modules or <strong>contexts</strong>. Contexts represent sections of code that may fall within a specific business entity or configuration aspect of the application. This process can be challenging, especially in a disorganized codebase. But even a rough breakdown will get you on the the right track. Digging in and determining how you can split things up provides the added advantage of helping you become more familiar with the codebase.</p><p>In many cases, you can extrapolate the contexts based on the nature of the application. For example, a scheduling app for a dentist’s office could be broken down into the following contexts:</p><ul><li>Patients</li><li>Appointments</li><li>Navigation</li><li>Dental records</li><li>User management</li></ul><p>The tricky part here is getting the granularity right. For the application I was working on, I determined the contexts based on the API calls and existing Redux reducers. I ended up with a <strong>user</strong> context, a <strong>super user</strong> context (for administrative actions), an <strong>app</strong> context (for UI state), and several others.</p><p><em>Note: Don’t get too hung up on finding the perfect contexts, the purpose of this step is to simplify the task creation process.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/1*g2DyLxHGFloKzmpXAvZnCw.png" /></figure><h4>Create Tasks</h4><p>You need to create tasks will well-defined scope. <strong>Think about scope in terms of pull requests</strong>. You don’t want to submit PRs with 5,000 lines of code changes, but submitting 5,000 PRs with 2 changes is just as ineffective.</p><p>As an example, one of the goals of my refactoring project was to transition from the <a href="https://foundation.zurb.com/">Foundation</a> framework to <a href="https://react.semantic-ui.com/introduction">Semantic UI React</a> and implement <a href="https://github.com/css-modules/css-modules">CSS Modules</a>. I originally created a single task to represent this change until I realized the amount of work that it would entail.</p><p>There were almost 100 React components that needed to be updated. However, I didn’t want to create 100 tasks in Trello to represent each individual component. In this situation, my defined contexts came in handy. First, I created tasks to refactor the Redux-connected container components within each context. Next, I looked through the shared /components directory and grouped them by category (form controls, charts, etc). Finally, I created separate tasks to refactor each group of shared components. Here’s a screenshot of my board with some examples:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/1*z0QPYg_R-Luy7djMuO9C9w.png" /><figcaption>Trello Project Board</figcaption></figure><p><strong>You also need to consider the implications of your changes breaking the application.</strong> If you need to revert it back to an older version, do you really want to have to dig through a massive PR to figure out what caused the bug? I only made this mistake once, and it was incredibly frustrating. I ended up just scrapping most of my changes and trying again with smaller chunks.</p><h4>Order Tasks (if you want)</h4><p>If you want to establish some criteria for prioritizing or ordering the tasks, that’s up to you. If you established a <strong>well-defined scope</strong> for each task, it shouldn’t matter which order you complete them. I tended to work on groups of tasks associated with certain functionality, like Redux elements or API management, but that wasn’t deliberately planned. I would recommend tackling some of the low-hanging fruit (low effort, high impact tasks) when you first get started to keep your motivation up.</p><h4>Keep Your Plan Up to Date</h4><p>Understand and accept that you won’t get the planning 100% correct when you first put it together. You may have made some assumptions about the code when you first formulated the plan that turned out to be wrong when you started digging into it. Adjust your course, but don’t let your plan go stale, make sure you update it and document the reasons for the change. If you end up performing a refactoring task on the fly that isn’t in the plan, add it to the plan and mark it complete. I know this sounds tedious, but it will pay off in the end.</p><h3>Wrap Up</h3><p>Planning the project doesn’t have to be daunting, but it does have to be done. The benefits of a rewritten codebase are often intangible and difficult to measure. Having a detailed plan provides an audit trail and an invaluable resource for other developers that may have to pick up where you left off. In <a href="https://medium.com/@mikerourke/effective-refactoring-part-3-d4b8972046e9">part 3 of this series</a>, I discuss the importance of testing and cover how to set up a robust testing framework.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ed215ff581c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Effective Refactoring: Part 1]]></title>
            <link>https://medium.com/@mikerourke/effective-refactoring-part-1-d923a2b42065?source=rss-72847384ec32------2</link>
            <guid isPermaLink="false">https://medium.com/p/d923a2b42065</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[refactoring]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Mike Rourke]]></dc:creator>
            <pubDate>Tue, 05 Dec 2017 16:38:59 GMT</pubDate>
            <atom:updated>2019-12-14T23:03:48.038Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*-2TAWob-SQv68pJV9idf_g.png" /></figure><h4>Asking the Right Questions Before You Get Started</h4><p><em>This is the first part of a 4 part series on effective refactoring.</em></p><ul><li><strong><em>Part 1: Asking the Right Questions Before You Get Started</em></strong></li><li><a href="https://medium.com/@mikerourke/https-medium-com-mikerourke-effective-refactoring-part-2-7ed215ff581c"><em>Part 2: Formulating a Plan</em></a></li><li><a href="https://medium.com/@mikerourke/effective-refactoring-part-3-d4b8972046e9"><em>Part 3: The Imperative Role of Tests</em></a></li><li><a href="https://medium.com/@mikerourke/effective-refactoring-part-4-e9b8a202d440"><em>Part 4: Rewriting the Code</em></a></li></ul><blockquote>Refactoring is the process of changing a software system in such a way that it does not alter the external behavior of the code yet improves its internal structure. It is a disciplined way to clean up code that minimizes the chances of introducing bugs. In essence when you refactor you are improving the design of the code after it has been written.</blockquote><p>Martin Fowler provided this definition in one of the quintessential books on the subject: <a href="https://www.safaribooksonline.com/library/view/refactoring-improving-the/0201485672/"><em>Refactoring: Improving the Design of Existing Code</em></a>. If you haven’t read this book and you’re interested in learning more about refactoring, I highly recommend it.</p><p>Over the years, I’ve completed refactoring projects of varying sizes. I’ve always enjoyed the sense of satisfaction I get from rewriting code to be cleaner (or at least cleaner by my standards).</p><p>I’ve done my due diligence on the subject. I’ve read several books on refactoring and did plenty of research on the web. Most of these resources describe <strong>techniques</strong> and <strong>general considerations</strong>. They specify conditions under which you should extract, move, rename, or encapsulate, but something is always missing. For lack of a better term, let’s call this the <em>refactoring guidance</em><strong> </strong>problem. It’s hard to find good answers to common questions:</p><ul><li>Where do I start?</li><li>How do I manage changes and not break the production application?</li><li>How do I implement new features during the refactor?</li><li><strong>How do I avoid catastrophe?</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*Boxys9-aHz7jqVbftNVbFg.png" /><figcaption>It could happen</figcaption></figure><p>I recently took on a substantial refactoring project for a sales budget management and analytics application that was built using React and Redux. The app was about 13,000 lines of code spread across 300 files. There were a few tests written to ensure the React components were rendering correctly, but <a href="http://istqbexamcertification.com/what-is-statement-coverage-advantages-and-disadvantages/">statement coverage</a> was only at 1.82%. I had been working regularly with the codebase, so I knew what had to be updated to adhere to our current coding standards. Here’s the list of goals I ended up with:</p><ul><li>Update folder structure to centralize Redux files (actions, reducers, selectors)</li><li>Convert <a href="https://foundation.zurb.com/">Foundation</a> framework to <a href="https://react.semantic-ui.com/introduction">Semantic UI React</a></li><li>Implement <a href="https://github.com/css-modules/css-modules">CSS Modules</a></li><li>Upgrade to <a href="https://webpack.js.org/">webpack 3</a></li><li>Replace <a href="https://api.jquery.com/category/ajax/">jQuery</a> with <a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API">Fetch</a> for handling HTTP requests (using <a href="https://www.npmjs.com/package/whatwg-fetch">polyfill</a>)</li><li>Remove unnecessary abstractions and dead code</li><li>Install and configure the <a href="https://facebook.github.io/jest/">Jest</a> testing framework and write unit tests</li></ul><p>I was able to accomplish these goals, but not without learning a few things the hard way. With the experience I’ve gained over the course of several projects, I feel that I can provide some valuable guidance that goes beyond techniques and general considerations.</p><p>In Part 1 of this series, I will review some of the questions you should ask yourself before you decide to take on a major refactoring project. As an aside, this article is geared towards <strong>projects</strong> <strong>with the</strong> <strong>specific goal of refactoring</strong>. Throughout the course of normal development, I recommend that you adhere to <a href="http://programmer.97things.oreilly.com/wiki/index.php/The_Boy_Scout_Rule">Uncle Bob’s Boy Scout Rule</a> when you’re adding features or fixing bugs.</p><h3>Before You Start</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/483/1*iByBCM0uUrm--dTIRS5GGw.png" /></figure><h4>First, ask yourself, should I refactor this?</h4><p>I cannot stress the importance of this question. Most programmers I know love to write clean, elegant code. Unfortunately, the real world isn’t elegant and it sure as hell isn’t clean: deadlines and shifting requirements are just the start of your problems.</p><p>You may look at a large codebase and feel the overwhelming urge to do a rewrite. You <strong><em>should</em></strong> consider refactoring if you’re able to answer “yes” to any of these questions:</p><ul><li>Is there significant technical debt that’s on the cusp of becoming a huge problem?</li><li>Is it difficult to add new features?</li><li>Does making a minor change in one section of the codebase break unrelated functionality in another part of the application?</li><li>Are you using outdated dependencies that have security or performance issues?</li><li>In the case of JavaScript, is it ES5 syntax that can be enhanced with some of the new language features like <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions">arrow functions</a> and <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment">destructuring</a>?</li></ul><p>Rather than just diving right in, I recommend discussing it with some of your peers. Getting the opinion of a senior engineer who has been around the block a few times could make the decision to refactor much easier. They may be able to elaborate on why the code was written a certain way or provide some valuable insights that affect your opinion. An experienced engineer might caution you against attempting to refactor due to a failed attempt in the past. In some cases, it might not be worth the effort.</p><h4>Next, ask yourself, can I refactor this?</h4><p>Now you’re faced with the next roadblock: determining if the refactor is even feasible. When asking yourself <em>can I refactor this?</em>, the <strong>“can”</strong> represents any number of limiting factors.</p><ul><li>Can I refactor this given my <strong>current skill set</strong>?</li><li>Can I refactor this given my <strong>availability</strong>?</li><li>Can I refactor this while also <strong>adding new features</strong>?</li><li>Can I refactor this given the <strong>available</strong> <strong>budget</strong>?</li></ul><p>If you <strong>can’t</strong> answer yes to all those questions, you’re asking for trouble. In my case, there was an opportunity to do some cleanup and I took advantage of it. I had support from engineering and approval from the product owner. Especially in a consulting environment, product management approval is imperative because they work directly with the client and manage the budget. If you try doing this under the radar or take on more than you’re comfortable with, you will end up backed into a corner.</p><h4>Finally, ask yourself, do I want to refactor this?</h4><p>This question may seem preposterous considering you’ve gotten this far into the article, but it is something you want to ask yourself nonetheless. If you’ve been assigned this project at work and you wish to remain employed, you’ll have to skip this question. However, if you’re taking the initiative, it’s important to be realistic.</p><p>Understand that a rewrite can be a massive undertaking that can be incredibly stressful and demanding, especially if there’s a strict budget or schedule. There may be some stigma associated with the project, so you may find yourself having to answer the same questions:</p><ul><li><em>Why wasn’t the code written the right way in the first place?</em></li><li><em>If the application works fine, why mess with it?</em></li><li><em>It can’t be that bad, haven’t you been able to add new features?</em></li><li><em>Does this add value to the business?</em></li></ul><p>Dealing with this negativity and confusion can be disheartening, which can make refactoring feel like a thankless task. It becomes even more problematic if some existing functionality breaks as a result of a rewrite (we’ll go over that in a later post). Despite the downsides, a refactor can be a valuable investment of time. Cleaning up the codebase while adding good unit tests will ensure that features are easier to add and regression bugs are less likely to occur.</p><h3>Wrap Up</h3><p>Due diligence is required for seeing a refactoring project through to successful completion. If you don’t think it <strong>can</strong> or <strong>should</strong> be done, it’ll be doomed from the start.</p><p>Now that you’ve decided (and are able to) move forward with your refactor, the next thing you’ll need is a plan. In <a href="https://medium.com/@mikerourke/https-medium-com-mikerourke-effective-refactoring-part-2-7ed215ff581c">part 2 of this series</a>, I’ll cover the planning phase and how to get started.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d923a2b42065" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learning How to Learn WebAssembly]]></title>
            <link>https://medium.com/pandera-labs/learning-how-to-learn-webassembly-7743663ed4d0?source=rss-72847384ec32------2</link>
            <guid isPermaLink="false">https://medium.com/p/7743663ed4d0</guid>
            <category><![CDATA[pandera-labs-tech-talk]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[webassembly]]></category>
            <dc:creator><![CDATA[Mike Rourke]]></dc:creator>
            <pubDate>Mon, 21 Aug 2017 14:25:32 GMT</pubDate>
            <atom:updated>2018-12-28T16:09:22.174Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*Xyu4bi_LCqzU4f0wJIrSgA.jpeg" /><figcaption><a href="https://www.redbubble.com/people/slumber86/works/25388719-webassembly-logo-and-text"><em>Image Source</em></a></figcaption></figure><p><em>If you’re interested in WebAssembly and want to learn more, check out the book I wrote for Packt:</em></p><p><a href="https://www.packtpub.com/web-development/learn-webassembly">Learn WebAssembly - PDF eBook | Now just $5</a></p><p>WebAssembly is no joke. It took me two damn years to get a single star on one of my GitHub repositories. It’s an npm package that had over 900 downloads last month. I created a repository as a placeholder for an npm package using WebAssembly, and it got 4 stars…in 14 hours! If you’re like me, you’re probably intrigued by this new technology, but have no idea where to start.</p><p>Rather than write a post about what WebAssembly can do or how neat it is (which it is), I’m going to try to provide a course of action you can follow to get up and running.</p><p>Before I get into the meat and potatoes, I should probably provide a little of my background. I’m a JavaScript developer who wrote a lot of VBA code, so the underlying technologies were just as new to me as they may be to you. Let’s get started!</p><h3>Step 1: Understand the Technology</h3><p>It’s probably a good idea to familiarize yourself with some of the higher level concepts before you start writing any code. There’s a great series of articles that Lin Clark from Mozilla wrote called <a href="https://hacks.mozilla.org/2017/02/a-cartoon-intro-to-webassembly/">A cartoon intro to WebAssembly</a>. Honestly, if that’s all you read, you’ll be in pretty good shape.</p><p>If you want to go a little deeper, you’ll find that the dates for explanatory blog posts and articles are all over the map. This is a problem because the standard has been evolving over the last few years and some of this information might be outdated. I would highly recommend going to the official site, <a href="http://webassembly.org/">WebAssembly.org</a>, and poking around. The <a href="http://webassembly.org/getting-started/developers-guide/">Getting Started</a> section is helpful and the spec is available for download, although its 157 pages and can be overwhelming.</p><p>If you’re sick of reading about it, and want to get down to brass tacks, you’ll need to install the toolchain. Let’s get crackin’!</p><h3>Step 2: Install the Toolchain</h3><p>Before I get into the installation steps, I wanted to point out an alternative: If you just want to play around with WebAssembly without committing to installing a bunch of stuff on your computer, you can actually get pretty far with <a href="https://wasdk.github.io/WasmFiddle/">WasmFiddle</a>. The main caveat being that each time you make a code change, you’ll have to download a new .wasm file and drop it in a directory.</p><p>If you want to go all in, great! There’s a few things you’ll need to install to start creating WebAssembly modules. <a href="http://webassembly.org/getting-started/developers-guide/">This page</a> has more details about what you’ll need, but here’s the quick breakdown:</p><ul><li><a href="https://git-scm.com/downloads">Git</a></li><li><a href="https://cmake.org/download/">CMake</a></li><li>Host system compiler (GCC, Xcode, or Visual Studio 2015)</li><li><a href="https://www.python.org/downloads/">Python 2.7.x</a></li><li><a href="https://kripken.github.io/emscripten-site/docs/getting_started/downloads.html">Emscripten SDK</a> (emsdk)</li></ul><p>For the <strong>Emscripten SDK</strong>, I’m using a Mac, so I downloaded the <a href="https://s3.amazonaws.com/mozilla-games/emscripten/releases/emsdk-portable.tar.gz"><strong>Emscripten SDK for Linux and OS X</strong></a>. I extracted it into the path ~/Tooling/emsdk (I dropped the -portable). It’s a pretty easy setup, just follow the directions in the <a href="https://kripken.github.io/emscripten-site/docs/getting_started/downloads.html#windows-osx-and-linux-installing-the-portable-sdk">installation section</a>.</p><p>I don’t want to get into the details of what Emscripten is or how it’s related to WebAssembly. I’ll just say it’s a LLVM-to-JavaScript compiler that can also generate WebAssembly modules.</p><p><em>Note: I added the environment variables generated when running the </em>source ./emsdk_env.sh<em> command to my </em>PATH<em> in my </em>exports.zsh<em> (if you use </em><strong>bash</strong><em>, you would add them to your </em>.bash_profile<em>) so I could run the compile commands without the </em>./<em> (</em>emcc<em> instead of </em>./emcc<em>). The gist below shows what gets exported.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0dc31a03e98195c2a9f7235c56ac549c/href">https://medium.com/media/0dc31a03e98195c2a9f7235c56ac549c/href</a></iframe><h3>Step 3: Get the Development Tooling</h3><p>There’s a whole bunch of options available for development tooling. You need an editor or IDE that supports C or C++. There’s a good chance that the editor you‘re already using will work. I personally use <a href="https://www.jetbrains.com/clion/">CLion</a> because I’m a JetBrains guy, but you can use <a href="https://code.visualstudio.com/">Visual Studio Code</a>, <a href="https://www.visualstudio.com/">Visual Studio</a> (Windows), <a href="https://developer.apple.com/xcode/">Xcode</a> (Mac), and many others.</p><p><em>Note: If you decide to use CLion, you need to create a </em>CMakeLists.txt<em> file with some pretty basic information that goes in the root folder path of your project. The gist below represents a simple CMake configuration.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6fc5ef08096c98aa8756a48859ccd4a5/href">https://medium.com/media/6fc5ef08096c98aa8756a48859ccd4a5/href</a></iframe><h3>Step 4: Learn C or C++</h3><p>This is probably the most time-consuming part. You’ll need to learn C, C++, or Rust. If you have a Pluralsight membership, there’s a <a href="https://www.pluralsight.com/paths/c-plus-plus">great learning path for C++</a>, but you’re looking at a 47 hour commitment. Pluralsight also has a couple of C courses (I haven’t watched them, but I’m sure they’re solid). There’s a wealth of free resources on the web to learn either one, given their level of maturity. Here’s a few I found that are a good place to start:</p><ul><li><a href="http://www.learn-c.org/">Learn C</a></li><li><a href="https://learncodethehardway.org/c/">Learn C the Hard Way</a></li><li><a href="https://www.learn-cpp.org/">Learn C++</a></li><li><a href="http://www.cprogramming.com/">C and C++ Programming</a></li></ul><p><a href="http://www.learn-c.org/">Learn C</a> and <a href="https://www.learn-cpp.org/">Learn C++</a> are pretty nifty because they have interactive tutorials, so you can run the code right in the browser. If you decide to go the C++ route, <a href="http://www.gregcons.com/kateblog/">Kate Gregory</a> does an awesome job at teaching the language. She’s the author for several of the Pluralsight courses in the C++ learning path mentioned above. Rust is another great option that works well with WebAssembly. It’s a relatively new language, so the training material available online isn’t as abundant as C or C++. There’s a <a href="https://app.pluralsight.com/library/courses/rust-fundamentals">Rust Fundamentals</a> course on Pluralsight and Udemy offers a <a href="https://www.udemy.com/rust-lang/">Rust training course</a> for a very reasonable price. I also found <a href="https://hackr.io/tutorials/learn-rust">this list on hackr.io</a> with training material available from various sources.</p><h3>Step 5: Learn WebAssembly</h3><p>This was probably one of the trickiest parts for me. There’s a lot of blog posts and tutorials out there to get you up and running, but they don’t get too deep into the underlying technology (or they get way too deep). I would highly recommend the <a href="https://egghead.io/courses/get-started-using-webassembly-wasm">Getting Started Using WebAssembly</a> course by Guy Bedford on egghead.io. If you’re serious about WebAssembly, the $40 you pay for an egghead membership is well worth the cost.</p><p>A one-stop shop of great resources is <a href="https://github.com/mbasso/awesome-wasm/blob/master/README.md">Awesome wasm repo on GitHub</a>. There’s an incredibly comprehensive list of articles, tooling, walkthroughs, etc.</p><p>If you’re a JavaScript developer that’s familiar with Node.js, I put together a <a href="https://github.com/mikerourke/webassembly-boilerplate">simple boilerplate project on GitHub</a> that demonstrates how to integrate .wasm files with JavaScript. If you want to test it out, you’ll need to have Node.js 8 installed.</p><h3>Wrap Up</h3><p>Getting started with WebAssembly is no trivial task. I’ve been researching and playing around with it for almost two months and I feel like I’ve barely scratched the surface. It’s impossible to predict the future (especially the future of the web), but I believe learning WebAssembly will be a beneficial investment of time.</p><p>You can also look at it this way: Even if WebAssembly gets scrapped, you can still get a job as a C++ programmer 😀.</p><p><em>At Pandera Labs, we’re always exploring new ways to build products and iterate on our engineering processes, and we value sharing our findings with the broader community as our company and our technology evolve together. To reach out directly about the topic of this article or to discuss our offerings, visit us at </em><a href="http://panderalabs.com/"><em>panderalabs.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7743663ed4d0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/pandera-labs/learning-how-to-learn-webassembly-7743663ed4d0">Learning How to Learn WebAssembly</a> was originally published in <a href="https://medium.com/pandera-labs">Pandera Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>