<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mike Boyle on Medium]]></title>
        <description><![CDATA[Stories by Mike Boyle on Medium]]></description>
        <link>https://medium.com/@mikesboyle?source=rss-7166a529a2b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*tWCY3JDBH3XgAhdnOEj-6g.jpeg</url>
            <title>Stories by Mike Boyle on Medium</title>
            <link>https://medium.com/@mikesboyle?source=rss-7166a529a2b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 05:08:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mikesboyle/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Predicting Citibike bottlenecks with max flow network analysis]]></title>
            <link>https://mikesboyle.medium.com/predicting-citibike-bottlenecks-with-max-flow-network-analysis-d52aa1b68013?source=rss-7166a529a2b------2</link>
            <guid isPermaLink="false">https://medium.com/p/d52aa1b68013</guid>
            <category><![CDATA[commuting]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[nyc]]></category>
            <category><![CDATA[data-analysis]]></category>
            <dc:creator><![CDATA[Mike Boyle]]></dc:creator>
            <pubDate>Sat, 20 Sep 2025 14:53:51 GMT</pubDate>
            <atom:updated>2025-09-23T17:18:58.127Z</atom:updated>
            <content:encoded><![CDATA[<p>Every morning, thousands of New Yorkers depend on Citibike to get to work. Too many of them show up late because they wasted time scrambling to find a working bike or circling from block to block in search of an open dock. Here’s how network analysis can predict and prevent these headaches.</p><h3>The problem</h3><p>Citibike’s 2,200+ stations face a classic operations challenge. Morning commuting creates massive imbalances. Some stations empty out (no bikes) while others overflow (no docks). A problem at one station can then cascade to nearby stations as increasingly desperate commuters hunt for docks and bikes.</p><p>The challenge is, which stations matter most? We need to predict and prioritize the stations that are most likely to hamper the morning commute. That means finding meaningful patterns in the data.</p><h3>The solution: network flow analysis</h3><p>We can model Citibike commuting as a <strong>flow network</strong>. This is the same mathematical model used to optimize Internet traffic, power grids, and airline routes. In a flow network, each route (a one-way trip from station A to station B) has traffic volume and a maximum <strong>capacity</strong> that this volume cannot exceed. Network analysis algorithms can show us which parts of a flow network are <strong>critical</strong> (reducing their capacity hurts the entire network) and which are <strong>bottlenecks</strong> (increasing their capacity helps the overall flow of commuters).</p><p>Using these max flow algorithms, along with PageRank analysis, we can identify exactly which stations have the biggest impact on network-wide performance. Instead of guessing where to focus resources, we can predict and prioritize. This means maintenance teams can focus on a small number of critical stations rather than treating all 2,200+ equally, and bike rebalancing efforts can target the specific routes that prevent network-wide cascades.</p><p>This approach has an advantage over simply prioritizing the high traffic stations, which are not necessarily critical or bottleneck stations. It is also more helpful than chasing after every broken dock or bike; that effort may be wasted on equipment that isn’t critical to maintaining the overall flow.</p><h3>Key findings</h3><p>The analysis of morning commute data (7–11 am weekday trips) from May through July of 2025 reveals some interesting patterns:</p><h4>Network structure</h4><ul><li>Only ~800 stations out of 2,200+ actually matter for commuting</li><li>~1,600 distinct routes carry significant traffic</li><li>Clear hubs form around train stations (Bedford L, Penn Station) and bike infrastructure (Hudson River Greenway)</li></ul><h4><strong>Station categories</strong></h4><ul><li>128 critical/bottleneck stations identified through max flow analysis</li><li>~500 stations are pure origins (zero incoming trips) or destinations (zero outgoing trips)</li><li>Major bidirectional hubs handle massive flows in both directions</li></ul><h4><strong>Top priority stations (by PageRank)</strong></h4><ol><li>9 Ave &amp; W 33 St, Manhattan</li><li>S 2 St &amp; Kent Ave, Brooklyn</li><li>E 47 St &amp; Park Ave, Manhattan</li><li>E 44 St &amp; Lexington Ave, Manhattan</li><li>Plaza St West &amp; Flatbush Ave, Brooklyn</li></ol><p>These five stations represent the highest-impact targets for optimization. A problem at any of these points can cascade through hundreds of commuter routes. Fixing a dock or deploying bike valets to one of these stations will give you the most bang for your buck.</p><p>This visualization shows critical stations (orange) and dual critical/bottleneck stations (blue), sized by PageRank importance. (Note that PageRank values are all scaled by 100 to make them easier to interpret and compare.)</p><figure><img alt="Bubble map of critical and/or bottleneck Citibike stations in NYC, sized by PageRank" src="https://cdn-images-1.medium.com/max/1024/1*PdrTNHm869vDpuPrPTH0eQ.png" /></figure><h3>Building the solution</h3><p>One of the challenges I faced was adapting traditional network flow algorithms for a real-world transportation system with multiple sources and sinks.</p><h4><strong>Constructing the commuter network</strong></h4><p>Using publicly available data from Citibike, I filtered 90 days of trip data to isolate morning commute trips (weekdays, 7–11 am). I aggregated the trip data by starting and ending station to find the most common commuter routes. I also removed noise by requiring 100+ trips per route in Manhattan, 50+ elsewhere. This revealed a commuter network dramatically different from the full Citibike system. This network includes only about one-third of all stations. It’s also more concentrated, with clear directional patterns.</p><p>Here’s what the filtered commuter network looks like. Line thickness represents trip volume. You can see that there are many huge destination stations near subway and train stations in Manhattan, Brooklyn, and Queens.</p><figure><img alt="Connection map showing distinct one-way routes between Citibike stations in New York City, taken from recent commuter data" src="https://cdn-images-1.medium.com/max/1024/1*nwIkE7pTDA_Qdjluh1IkVQ.png" /></figure><p>Real-world transportation data also comes with significant quality challenges. I implemented validation rules to identify and filter geographic outliers, impossible trip durations, and stations with inconsistent names or ids. I also wrote transformations to reconstruct, validate, deduplicate, and standardize information about stations that appeared in the trip logs but not in the station data sources. This preprocessing was essential since reliable operational decisions require clean, validated data.</p><h4>Algorithm adaptation</h4><p>It’s easy to see how the commuter network can be represented as a graph data structure, with stations as nodes and point-to-point routes as directed edges. However, standard max flow algorithms like Edmonds-Karp require that the input graph has a single <strong>source</strong> node from which all trips start, and a single <strong>sink</strong> node where all trips end. The morning commute network does not fit this pattern, as it has hundreds of source and sink nodes. Another problem is that max flow algorithms assume that that the capacity limits exist on the edges (the routes) rather than the nodes (the stations). That is not a good match for the commute network, where the capacity of New York City streets is not really the issue. The issue of interest is <em>station</em> capacity.</p><p>Fortunately, there are standard approaches for dealing with both of these issues. First, I added a single “super source” node and a single “super sink” node to the commute graph, with infinite-capacity edges going from the super source to the actual source nodes of the network, and from the actual sink nodes to the super sink. This makes our graph meet the input requirements of the standard algorithms.</p><p>To focus on station capacity rather than route capacity, I split each station into an “in” and “out” node, connected by an additional edge with a capacity equal to the number of docks at the station. If the algorithm finds that one of these “internal” edges is a critical or bottleneck edge, then the station itself is a critical or bottleneck <em>node</em>. Why? Because this edge is nothing but a representation of the station’s capacity. Increasing or decreasing the capacity of the edge is exactly the same as increasing or decreasing the capacity of the station.</p><h4>Prioritization challenge</h4><p>The algorithm identified 128 critical or bottleneck stations. That’s still too many for an operations team to handle all at once. To help prioritize them, I used PageRank to rank them by importance, applying the same logic Google uses for websites. That is, a station is important if it receives trips from other important stations. This produced an intuitive top-5 list that matches operational experience.</p><h4>Technical considerations</h4><p>This analysis requires specialized graph algorithms that can’t be expressed in SQL. To make this work, I built a hybrid pipeline. I use dbt to filter and aggregate trip data to form the commuter network. Next, a Python process loads this network into memory, runs the analysis, and writes the results back to the BigQuery data warehouse. The whole pipeline is triggered and orchestrated using Airflow. Airflow also orchestrates the data ingestion and transformation pipelines for trip and station data that feed into this analysis.</p><p>Overall, this architecture processes about 5 million monthly trips for pennies per month on BigQuery, and can be efficiently scaled to bring in data from other transportation modes or data sources. At the current scale (~800 stations, ~1,600 edges), the network analysis runs comfortably on a single container. Larger networks would require Spark or some other form of flexible distributed compute.</p><p>I invite you to <a href="https://github.com/mikeboyle/citibike-pipeline">check out my repo on GitHub</a> for more details on how it all works. You can also view the latest analysis results in <a href="https://lookerstudio.google.com/s/gC08Uei7vvo">this interactive Looker dashboard</a>.</p><h3>Real-world applications</h3><p>At this point you may be wondering, “OK great, you remembered your algorithms from school, but how does this actually help anyone?”</p><p>First, <strong>operations teams</strong> can use this analysis to make effective decisions about resource allocation. For example, at any given time there will be many broken docks across 2,200+ stations. They can’t all be fixed at once, and this analysis provides a helpful way to choose which ones to tackle first. Ignore the docks that aren’t in critical stations, and prioritize the rest by PageRank.</p><p>Next, <strong>capacity planning</strong> can be more data driven. Instead of adding docks everywhere or relying on anecdotal evidence, target the bottleneck stations where additional capacity raises the flow of the overall network. Again, the PageRank score is a good proxy for deciding which stations to give the most attention to.</p><p>This analysis can also help the <strong>bike valet and bike angel</strong> teams choose which stations to go to in order to maintain or increase commuter flow. Bike valets can increase incoming capacity by receiving bikes even when the docks are full, and bike angels can bring bikes back to critical or bottleneck stations that have emptied out.</p><p>For <strong>management and policy makers</strong>, this analysis translates into clear budget priorities. Investing in the top 5 stations can prevent thousands of hours of daily commuter delays citywide. The PageRank visualizations help policy makers understand resource allocation without needing to understand the underlying algorithms.</p><p><strong>Future applications</strong> include real-time monitoring (alert when critical stations approach capacity), seasonal analysis (how do patterns change in the winter?), and expansion planning (where should new stations go to optimize the network?). The methodology generalizes to any transportation network with capacity constraints and directional flow patterns.</p><h3>Wrapping up</h3><p>This approach captures something fundamental about urban mobility. Commuting creates predictable flow patterns with natural bottlenecks and pressure points. Whether you’re optimizing bike shares, bus routes, delivery truck routes, e-scooter deployment, or traffic signals, the same mathematical framework applies.</p><p>For operations teams, this transforms resource allocation from reactive to proactive. Instead of fixing everything everywhere, focus on the stations that matter most to network-wide performance. The math tells you where to look first.</p><p>For Citibike commuters, I hope this analysis gets you to your job on time. Maybe the data can give you an edge when you plan your next commute!</p><h4><strong>Want to explore the data yourself?</strong></h4><p>Check out the <a href="https://lookerstudio.google.com/s/gC08Uei7vvo">interactive dashboard</a> to see how your neighborhood stations rank, or dive into the <a href="https://github.com/mikeboyle/citibike-pipeline">full implementation on GitHub</a> to adapt this approach for your own transportation network.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d52aa1b68013" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Solving the NYT Spelling Bee in time linear to the solution size]]></title>
            <link>https://mikesboyle.medium.com/solving-the-nyt-spelling-bee-in-time-linear-to-the-solution-size-32745204d974?source=rss-7166a529a2b------2</link>
            <guid isPermaLink="false">https://medium.com/p/32745204d974</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[games]]></category>
            <category><![CDATA[new-york-times]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[spelling-bee]]></category>
            <dc:creator><![CDATA[Mike Boyle]]></dc:creator>
            <pubDate>Sat, 17 May 2025 22:03:21 GMT</pubDate>
            <atom:updated>2025-05-18T20:13:21.970Z</atom:updated>
            <content:encoded><![CDATA[<p>I love the New York Times games. My day starts with Wordle and ends with the crossword. The puzzle I enjoy the most is <a href="https://www.nytimes.com/puzzles/spelling-bee">Spelling Bee</a>, so naturally I decided to ruin my own fun by writing an algorithm to solve it.</p><p>This post isn’t meant to give you some code to copy-paste, but rather to walk through some of the approaches I considered before I wrote any code at all. It can help a lot to think through approaches before diving into code.</p><h3>How do you play Spelling Bee?</h3><p>Each day, the game gives you seven letters: one center letter (in gold below), and six outer letters. You have to find words that can be formed by the given letters. Each word must be at least 4 letters long and contain the center letter. You can use as many letters as you want, and you can use a letter as many times as you want. The goal is to find all the possible words.</p><figure><img alt="Example game board from the New York Times spelling bee, with central letter L and peripheral letters A, E, N, T, I, Z" src="https://cdn-images-1.medium.com/max/381/1*Nxi1-de4LrDEXY8hZcH-Tw.png" /></figure><p>For example, for the game in the picture, TELL is a word in the solution. So are LITE and TALENT and ALELLE. However, LIT, LIE, and ALE are not valid because they are too short. TAINT and ZITI are not valid because they do not have the center letter, L. Some words seem valid but don’t count because they aren’t in the Times’ official word list, which is not accessible to players. Examples of these are ITALIAN, ZELLE, and ELLIE.</p><h3>Algorithm design: a few approaches</h3><p>When I started thinking about how to design an algorithm to solve the game, a few approaches came to mind. For all of these, assume we have access to a <strong>word list</strong>. Maybe not the New York Times’ official word list, but definitely <a href="https://github.com/wordnik/wordlist/blob/main/wordlist-20210729.txt">a big list of words like this one</a>. Here are the different approaches I thought of:</p><ol><li>For each possible letter sequence of length 4, 5, 6, … check if the sequence is in the word list, uses only letters from today’s game board, and uses the center letter.</li><li>For each letter sequence of length 4, 5, 6, … <em>which uses only letters from today’s game and includes the center letter</em>, check if the sequence is in the word list.</li><li>For each word in the word list, check if the word includes the center letter and every letter in the word is a center or outer letter.</li></ol><h3>Identifying the search spaces</h3><p>Here is a stunning graphical illustration of the sets of strings these approaches would iterate through.</p><figure><img alt="Venn diagram showing the oval ALL LETTER SEQUENCES, which contains the ovals ALL LETTER SEQUENCES IN TODAY’S GAME, WORD LIST, and SOLUTION WORDS. The ovals ALL LETTER SEQUENCES IN TODAY’S game and WORD LIST intersect, and SOLUTION WORDS lies in the intersection." src="https://cdn-images-1.medium.com/max/1024/1*Ih3TNDld-ipOxjnex6NGaA.png" /></figure><p>Approach 1 would consider every possible letter sequence of length 4, 5, 6, … up to some limit. As you can see in the illustration, that is the largest set of strings. It contains our entire word list, because words are letter sequences. It also contains the set of valid letter sequences we can make from the center and outer letters in the current game. It also contains the solution words. You can also see that there must be some intersection between the word list and today’s letter sequences. Finally, the set of solution words lies in that intersection.</p><p>This picture shows us a couple of things. First, there is the general point that many algorithm problems, including this one, involve going through a <strong>search space</strong> (a set of things) in order to find a solution subset. Another example of a search space problem is binary search. The search space is a sorted list of numbers, and we need to find the target (a specific number). This is also how a classic problem like <a href="https://leetcode.com/problems/two-sum/description/">Two Sum</a> works: Given an array of numbers, out of all the possible pairs of numbers we can make (our search space), which pairs add up to the given target?</p><p>Second, to find an efficient solution to this type of problem, we need to understand the possible search spaces and how to use them best. Good solutions know how to work with a smaller search space from the start, or how to cut down the search space more quickly (this is what binary search does), or how to make each iteration in the search more efficient (as in using a hash table with Two Sum).</p><p>Here we have three possible search spaces to work with. Which ones are feasibly small enough? Which ones let us cut down the space more efficiently or allow search operations to be more efficient?</p><p>With these questions in mind, we can definitely reject approach 1, which was:</p><blockquote>For each possible letter sequence of length 4, 5, 6, … check if the sequence is in the word list, uses only letters from today’s game board, and uses the center letter.</blockquote><p>Not only does this approach use the largest search space, which is bad enough, it also has to do three different things for each letter sequence. So it has to do more iterations than approaches 2 and 3, and each iteration is less efficient than in the other approaches.</p><p>What about approaches 2 and 3? Approach 2‘s search space is every letter sequence we can make from the current game. Approach 3’s search space is the word list. Which is bigger? I deliberately made the ovals the same size in the Venn diagram. This is to emphasize that we shouldn’t just go with our gut on this, even though in this case your gut is probably right.</p><p>Let’s start with the search space for approach 2: all the letter sequences we can make for the current game. Consider the set of letter sequences of length 4 that we can make for the current game. How many are there? We can calculate this with the <a href="https://artofproblemsolving.com/wiki/index.php?title=Complementary_counting">complementary counting method</a>, which is a fancy way to say that we do the following. First, calculate how many letter sequences of length 4 we can make. There are seven letters in the game, so that’s 7⁴. This number includes sequences that have 0, 1, 2, 3, and 4 occurrences of the center letter. A letter sequence must include the center letter, though. So, from that number, we want to subtract the number of sequences that have 0 occurrences of the center letter. How many of <em>those</em> are there? That’s the number of 4 letter sequences where the center letter is never used, which is 6⁴. So altogether there are 7⁴ — 6⁴ letter sequences of length 4.</p><p>More generally, for a letter sequence of length <em>k</em>, there are 7^k — 6^k possible sequences. So the total number of sequences looks like (7^4 — 6^4) + (7^5-6^5) + (7^6-6^6) + ... until we decide to stop. Maybe we stop at k=10. Maybe k=20. Maybe we set k as the length of the longest word in the word list. No matter when we stop, this is a very large number, in fact an <em>exponentially large</em> number. If we go up to 10, there are 256,994,905 letter sequences to check. If we go up to 12, there are more than 13 billion.</p><p>That is much larger than the size of a word list. For example, <a href="https://en.wikipedia.org/wiki/List_of_dictionaries_by_number_of_words">the English Wikitionary has about 800,000 entries</a>. Therefore, since approaches 2 and 3 both do about the same amount of work per iteration (check if a sequence is in the word list or check if a word uses the center and outer letters), we should also reject approach 2. That leaves approach 3, searching the word list.</p><h3>Preprocessing and querying</h3><p>The algorithm for approach 3 might be something like this:</p><pre>for each word in the word list:<br><br>  - let letters = the distinct letters used in the word<br><br>  - if the center letter is not in letters, skip this word<br><br>  - if any letter in letters is not a center or outer letter, skip<br><br>  - if we get this far, add this word to the list of solution words</pre><p>There are some optimizations we can add, such as immediately skipping words that are shorter than 4 letters, or bailing out of a word’s iteration as soon as we find more than 7 distinct letters. Even so, in the worst case, the runtime here is O(W * L) where W is the number of words in the list, and L is the average length of each word. (Think of W * L as the total number of characters in the word list.)</p><p>The good news is: This is not exponential! This is feasible!</p><p>But can we do better? Yes!</p><p>In its current form, this algorithm will do O(W * L) work to solve today’s Spelling Bee. Then tomorrow, it will do O(W * L) work again. Same thing the next day. However, a lot of this is the same work we’re doing again and again, specifically finding the distinct letters used in each word. This work is exactly the same for every day’s game, because the word list never changes. This work does not change based on the letters of the current game.</p><p>To avoid this repeated work, we need <em>a better word list</em>. We could do all of that work up front, before trying to solve any game, and then save it all into a new list, or perhaps a lookup table or JSON file like this:</p><pre>{<br>  &quot;aardvark&quot;: &quot;ADKRV&quot;,<br>  &quot;bonobo&quot;: &quot;BNO&quot;,<br>  &quot;noob&quot;: &quot;BNO&quot;,<br>  ...<br>  &quot;ziti&quot;: &quot;ITZ&quot;,<br>}</pre><p>This <em>preprocessing</em> still takes O(W * L) time, but we only do it once. Once it’s done, we can just reuse this file each time we want to solve the day’s game, without repeating this work. We can also bake some optimizations into the preprocessing, like discarding words that are too short or have more than 7 distinct letters.</p><p>After that, solving the day’s game just needs a <em>query function</em> like this:</p><pre>for each word in the wordList:<br>  // Look up the precomputed distinct letters in constant time!<br>  - let letters = wordList[word]<br>  <br>  - if the center letter is not in letters, skip this word<br><br>  - if any letter in letters is not a center or outer letter, skip<br><br>  - if we get this far, add this word to the list of solution words</pre><p>This query function takes O(1) time to look up the distinct letters. Assuming we do the optimizations in the preprocessing, there are at most 7 distinct letters. So searching for the center letter is O(7) = O(1) and checking that each distinct letter is in the set of game letters is also O(7) = O(1). So altogether our query function now takes O(W * 1) = O(W)time instead of O(W * L).</p><p>That’s linear in the size of the word list! Great success!</p><p>But can we do better? Yes!</p><h3>Flipping the dictionary</h3><p>Recall that we preprocessed the word list into a dictionary like this:</p><pre>{<br>  &quot;aardvark&quot;: &quot;ADKRV&quot;,<br>  &quot;bonobo&quot;: &quot;BNO&quot;,<br>  &quot;noob&quot;: &quot;BNO&quot;,<br>  ...<br>  &quot;ziti&quot;: &quot;ITZ&quot;,<br>}</pre><p>Notice how “bonobo” and “noob” both use the same letter set: BNO. So do other words like “boon” and “bonbon.” If you think about this with some other words you know, you’ll probably agree that this is very common.</p><p>Now consider this. What if, in our preprocessing, we flipped the dictionary as shown below? What could we gain from this?</p><pre>{<br>  &quot;ADKRV&quot;: [&quot;aardvark&quot;],<br>  &quot;BNO&quot;: [&quot;boon&quot;, &quot;bonbon&quot;, &quot;bonobo&quot;, &quot;noob&quot;, ... ],<br>  &quot;ITZ&quot;: [&quot;ziti&quot;],<br>  &quot;AELT&quot;: [&quot;elate&quot;, &quot;late&quot;, &quot;latte&quot;, &quot;tale&quot;, &quot;teal&quot;, &quot;tattletale&quot;, ... ],<br>  ...<br>}</pre><p>In this dictionary, each key is a letter set (represented as a string), and each value is a list of words that can be formed by using every letter in that letter set at least once (and only letters from that set). Similar to before, we can also make sure in the preprocessing that every letter set / key has at most 7 letters, and that every list contains only words with a length of at least 4.</p><p>How does this help us? Consider our board again:</p><figure><img alt="Example game board from the New York Times spelling bee, with central letter L and peripheral letters A, E, N, T, I, Z" src="https://cdn-images-1.medium.com/max/381/1*Nxi1-de4LrDEXY8hZcH-Tw.png" /></figure><p>Suppose we want to find all the “pangrams,” which are words that use every letter in the board at least once. We can just look up AEILNTZ in our table. That single lookup would give us a list of all the pangrams in constant time.</p><p>And we don’t have to stop there. We could find all the words that use every letter except N with a single lookup of the letter combination AEILTZ. Or all the words that use L, E, and A by looking up AEL.</p><p>In fact, we can systematically find every letter combination of length 2, 3, 4, … up to 7 that includes the center letter. Each time, we go to our dictionary and look up the words that can be formed with that combination of letters. We add those words to a list.</p><p>At the end, <em>we will have a complete solution</em>!</p><p>Take time to prove to yourself that this works. Imagine the set of solution words for today’s game. Each one of those words is formed from some combination of letters in the game. Therefore, if we systematically check every possible letter combination, we will find all the possible words.</p><p>The algorithm might look like this:</p><pre>For every combination of game letters<br>that is length &gt;= 2 and includes the center letter:<br>  <br>  - sort the letter combination and convert to a string<br>  - look up the string key in our dictionary, getting a list of words<br>  - add each word in the list to the set of solution words</pre><h3>But you said letter sequences were bad!</h3><p>That’s true. Letter <em>sequences</em> are bad because they make for an exponentially large search space. But here we’re talking about letter <em>combinations</em>. The difference between a combination and a sequence is that sequences care about order, and combinations don’t. As an example, ABC, ACB, BAC, and BCA are all considered different sequences, but they count for just one combination: ABC. Our sequences also included ones with duplicated letters like AAA or ABB, but our combinations use each letter at most once. All of that means that there will be a lot fewer combinations than sequences.</p><p>There’s another key difference between the previous approaches and the one I’m selling you now. Before, we had to consider letter sequences of length 4, 5, 6, … up to who knows how long. There’s no clear limit and as the length goes higher, the size of the search space rises exponentially. On the other hand, this solution considers combinations with a clear limit. We want combinations of length 2, 3, 4, 5, 6, and 7.</p><p>All of this means that this new search space is small. Like, <em>really</em> small. Let’s break down just how small.</p><p>How many combinations of length 7 can we make from the letters in the game? Well, there are only 7 letters in any game, so that’s easy. We have to include all the letters, so there’s only one combination.</p><p>How many combinations of length 6? Well, first, we would have to include the center letter. That leaves 5 more letters to choose. There are no duplicate elements in a combination, so we have to choose them from the remaining 6 numbers. You can work out that there are 6 ways to do this.</p><p>You may recognize this as the “n choose k” calculation from statistics class. For each combination length <em>k = </em>2, 3, …, 7, we have to include the center letter. Then we can make 6 choose k — 1 combinations of the remaining letters.</p><p>Here’s how the math works out for each combination length. I used an online <a href="https://www.hackmath.net/en/calculator/n-choose-k">n choose k calculator</a> to do this:</p><ul><li>Length 2: 6 choose 1 = 6</li><li>Length 3: 6 choose 2 = 15</li><li>Length 4: 6 choose 3 = 20</li><li>Length 5: 6 choose 4 = 15</li><li>Length 6: 6 choose 5 = 6</li><li>Length 7: 6 choose 6 = 1</li><li><strong>Total number of combinations: 6 + 15 + 20 + 15 + 6 + 1 = 63</strong></li></ul><p>So with this new approach, we go from a search space that had <em>billions</em> of elements to a search space with <em>only 63</em> elements to consider.</p><h3>Runtime analysis</h3><p>Recall our new query algorithm:</p><pre>For every combination of game letters<br>that is length &gt;= 2 and includes the center letter:<br>  <br>  - sort the letter combination and convert to a string<br>  - look up the string key in our dictionary, getting a list of words<br>  - add each word in the list to the set of solution words</pre><p>There are only 63 combinations, so the loop runs 63 times. At each iteration we:</p><ul><li><em>Sort the letter combination.</em> The max combination length is 7 letters, so this is O(7 log 7) = O(1)</li><li><em>Convert to a string</em>. This takes time O(7) = O(1).</li><li><em>Look up the string as a key in the dictionary</em>. This is also O(1).</li><li><em>Add each word in the list to the solution</em>. The runtime varies with the list length.</li></ul><p>Accounting for that last step is tricky, but let’s say S is the number of words in the solution set when we’re done. Across all of the iterations, we will use a total of O(S) time to add those words to the solution. We’ll account for this time in a separate term rather than multiply it by the number of iterations.</p><p>Overall, then, we can say the runtime is O(63) + O(S) which simplifies to O(S), where S is the size of the solution.</p><p>A downside here is that on days when the solution has many words, the algorithm will take longer to run. However, because Spelling Bee solutions tend to have fewer than 100 words, this is a much better runtime than the previous approach of iterating over several hundred thousand word list entries.</p><h3>Full algorithm and implementation</h3><p>Here’s the pseudocode for the complete solution.</p><p><strong>Preprocessing algorithm</strong></p><p>Assume that wordList is a list of English words that is a superset of the New York Times word list. One example might be this awesome word list from Wordnik: <a href="https://github.com/wordnik/wordlist/blob/main/wordlist-20210729.txt">https://github.com/wordnik/wordlist/blob/main/wordlist-20210729.txt</a>. At the start of preprocessing, we’ve somehow read this list into memory, or we are reading it in word by word.</p><p>First, we do a one time preprocessing calculation to produce a dictionary of letter combinations to words:</p><pre>// Preprocessing: Runtime: O(W * L)<br>// where W = length of words in wordList<br>// and L = average length of a wordList<br><br>Input: the wordList<br>Output: preprocessed dictionary mapping letter sets to lists of words<br>formed from those sets<br><br>Create an empty dictionary, D<br><br>For each word in wordList:<br>  <br>  - if word length &lt; 4, skip this word<br><br>  - let letters = the distinct letters in the word<br><br>  - if length of letters &gt; 7, skip this word<br><br>  - sort letters alphabetically in place<br><br>  - if letters (after sorting) is already a key in D,<br>    append the word to the list at D[letters]<br><br>  - else if letters is not already a key, D[letters] = [word]<br><br>Return D or write it to a file, whatever works.</pre><p><strong>Query algorithm</strong></p><p>Assume that we have read in the dictionary D from above into memory and our query algorithm has access to it.</p><pre>// Query algorithm: Runtime: O(S)<br>// where S is the size of the solution list<br><br>Input: one center letter and a list of 6 outer letters<br>Output: a list of solution words<br><br>Create an empty list, call it L<br><br>For i &lt;- 1 to 6(inclusive): // number of outer letters to include<br>  For each combination of outer letters of length i:<br>    - Append the center letter to the combination<br>    - Sort the combination<br>    - Look up the combination in dictionary D<br>    - If the combination is a key in D, <br>      copy each word in D[combination] to L<br>  <br>Return L</pre><p><strong>Implementation</strong></p><p>I’ll leave that for you to do. If you’re using Python, you could use itertools.combinations() to generate the combinations of outer letters.</p><p><strong>Gotchas and problems</strong></p><p>Finding a good word list and fine-tuning it is key to making this actually work. If the word list is too big, it will produce solutions with answers that should be valid but aren’t accepted by the game. If the word list isn’t broad enough, it won’t include words that are in the Times’ word list, and the solutions will be incomplete.</p><p>But you didn’t really want an algorithm that solved everything perfectly right out of the box, did you? That would take away all the fun!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=32745204d974" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I helped dozens of people vote for the first time in NYC. It’s way too confusing.]]></title>
            <link>https://mikesboyle.medium.com/i-helped-dozens-of-people-vote-for-the-first-time-in-nyc-its-way-too-confusing-52569259ed5c?source=rss-7166a529a2b------2</link>
            <guid isPermaLink="false">https://medium.com/p/52569259ed5c</guid>
            <category><![CDATA[ux]]></category>
            <category><![CDATA[nyc]]></category>
            <category><![CDATA[ux-research]]></category>
            <category><![CDATA[design]]></category>
            <category><![CDATA[election-2020]]></category>
            <dc:creator><![CDATA[Mike Boyle]]></dc:creator>
            <pubDate>Thu, 05 Nov 2020 16:05:00 GMT</pubDate>
            <atom:updated>2020-11-05T19:02:10.306Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E8eJ3gTKHzVBIcV2m-jiWg.jpeg" /></figure><p>On Election Day 2020, I was a poll worker in Jackson Heights, Queens, a place that is often called <a href="https://www.courant.com/featured/sns-nyt-jackson-heights-virtual-tour-20200828-nmjkawgisfbx3mlhxml45qidki-story.html">the world’s most culturally diverse neighborhood</a>. It was an eye opening experience. I had never realized how needlessly confusing the voting process is, especially for new voters.</p><p>My exact job title was “privacy booth inspector.” In practice, that title is kind of an oxymoron. As soon as a voter got confused, they would beckon me into the booth to show me (against my protests) their half-completed ballot with all sorts of questions on how to fill it in correctly.</p><p>There were a lot of confused voters. The first person I interacted with, at 6:00 a.m., was an elderly immigrant who was voting for the first time in his entire life. I found this incredibly heartwarming and was so thrilled to help.</p><p>That was 6:00 a.m. By 8:00, it was clear that just about everybody I was going to see today was an elderly immigrant voting for the first time in their life. It was still a heartwarming experience, but it was now mixed with irritation at the New York City Board of Elections for designing an incomprehensible voting process with no clear instructions.</p><p>The most common points of confusion for voters:</p><p><strong>1. How do I choose a candidate?</strong></p><p>In New York, voters fill in a bubble over the candidate’s name, similar to taking a Scantron test. But the voters did not see the bubble or understand its purpose. The cultural context is missing; many of these folks have never taken a Scantron test. It’s also very hard to explain how to fill in a bubble without actually filling it in for them (which obviously I cannot and did not do). There are no instructions on the ballot, nor signs anywhere in the polling place, that show what a completed ballot looks like.</p><p><strong>2. Why does Candidate X’s name appear 2 or more times for the same race?</strong></p><p>The Conservative Party, Working Families Party, and other minor parties in New York tend to nominate the major party candidate for the same office. The result is that Trump and Biden each appeared twice on the ballot. In other races, the same candidate appeared as many as <em>four times</em> in the same row.</p><p>I get why this is, but it’s incredibly confusing and really hard to explain. Voters were filling every bubble for their candidate, which can lead to problems scanning the ballot and force them to start over with a new ballot. That’s a real problem because in New York, a voter only gets four chances to correctly mark their ballot. After that, they need to appear before a judge to get permission to continue trying to vote. That is obviously a major barrier.</p><p><strong>3. Where do I choose my party?</strong></p><p>Many voters had the idea that they could come in, check a single box for party X, and leave. Other places design ballots like this, but not New York.</p><p><strong>4. Why is there no place to mark my vote for Vice President?</strong></p><p>I think the ballot does state that the vote will be for President and Vice President, but only in the tiniest font size.</p><p><strong>5. How do I complete the folder?</strong></p><p>New York ballots are handed to the voter in a cardboard privacy sleeve that we collect after scanning the ballot and then reuse for the next voter. Many folks assumed that the privacy folder was the actual ballot and were surprised to discover a paper ballot inside the folder.</p><p><strong>6. How do I vote for judges?</strong></p><p>New York has these confusing elections for judges where you are supposed to pick “any nine” names from a bizarre matrix of about 20 candidates. Some names are repeated in the same row or scattered over several rows and columns. Some cells are mysteriously blank. And if a voter wanted to try to learn more about these candidates, well, too bad: Almost none of them has taken the trouble to put up even a simple Facebook page. And what does that mean, <em>any nine</em>? Must I choose nine or can I choose eight? Can I fill in more than one bubble in a row, something not allowed on the other side of the ballot?</p><p><strong>7. Do I have to vote in every race?</strong></p><p>Voters were very worried that their vote would not count if they skipped a race. This question came up a lot when when they got to the judicial elections. They were very happy to skip those. And in fact, when <a href="https://nyenr.elections.ny.gov/">the results</a> came in for our judicial election, the top vote-getter, with more than four times the votes of any other candidate, was “Blank”.</p><p><strong>8. Where do I sign my ballot?</strong></p><p>Voters really wanted to sign their ballot. Many were visibly upset at the idea that unsigned ballots would be scanned and counted. They worried that maybe the whole process was corrupt.</p><p><strong>9. What is the “I Voted!” sticker for?</strong></p><p>This was the most interesting and surprising one for me. The first-time voters found the “I Voted!” sticker baffling. It was handed to them at the same time as their ballot, so they reasonably assumed that the sticker was an important part of the ballot marking and scanning process. They wanted to know things like: Where do I place the sticker on my ballot? Is the sticker used to seal the privacy envelope? Do I have to present this to an official to verify my identity? They looked at me like I was crazy when I explained it was a present we gave them just for fun so they could show off on Instagram.</p><p>There’s an easy solution to this problem: Hand out the sticker <em>only after</em> the voter is finished. Some polling places do this, but it’s worth noting that <a href="https://vote.nyc/sites/default/files/pdf/poll_workers/Basic_Poll_Worker_Manual_2020-2021.pdf">New York City’s Basic Poll Worker Manual</a> specifically requires us to hand out the sticker at the same time as we give the voter their ballot.</p><p>Although I do not work in the UX field, my very long day at the polls definitely awakened my inner UX researcher. I am pretty sure I’ll never do this again, but I was glad to be part of it. All I had to do was work a 17 hour day starting at 5:00 a.m.!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=52569259ed5c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Acing Your First Whiteboard Interview: One Winning Strategy You Should Know]]></title>
            <link>https://mikesboyle.medium.com/acing-your-first-whiteboard-interview-one-winning-strategy-you-should-know-8420e37d5ca?source=rss-7166a529a2b------2</link>
            <guid isPermaLink="false">https://medium.com/p/8420e37d5ca</guid>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[whiteboarding]]></category>
            <dc:creator><![CDATA[Mike Boyle]]></dc:creator>
            <pubDate>Sun, 14 Jul 2019 20:45:01 GMT</pubDate>
            <atom:updated>2019-07-14T21:16:32.157Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’re searching for your first job as a programmer, you’re probably already preparing for whiteboard interviews in these two ways:</p><ul><li>Learning about data structures: linked lists, stacks, queues, trees, etc.</li><li>Practicing behavioral strategies: asking clarifying questions, planning the solution in pseudocode, considering edge cases, etc.</li></ul><p>That’s all great, but of course when you get to the whiteboard interview you also want to, you know, <strong>solve the problem</strong>.</p><p>Here is a technique you can use to solve a lot of the whiteboard problems you’ll see as an entry-level candidate. You should practice this technique until you can do it in your sleep.</p><p><strong>The technique:</strong> Put an array into a hash map</p><p><strong>What it’s good for:</strong> Accumulating or counting the elements in a list or string</p><p><strong>Example questions:</strong></p><ul><li><em>Find the n most frequent words in a text</em></li><li><em>Find all of the letters in a string that appear only once</em></li><li><em>Given a list of customer orders, find the customer who spent the most money</em></li></ul><p><strong>Pro tip: </strong>Figure out what you’re going to do with the hash map (and how!) before you write any code.</p><p>These questions require you to go through a list of things and count them, or total them up. Hash maps are perfect for this. Each array element is a key in the map, and the key’s value is the number of times the element appears in the array, or the running total for that element.</p><p>Here’s how we do the first question: Find the n most frequent words in a list. This is in JavaScript. You should practice writing this code in your preferred language until you know it cold.</p><pre>// Find the n most frequent words in a list<br>const mostFrequent = (list, n) =&gt; {</pre><pre>  // put array into map: memorize how to do this<br>  const counter = {};<br>  list.forEach( word =&gt; {<br>    if (counter[word]) {<br>      counter[word]++;<br>    } else {<br>      counter[word] = 1;<br>    }<br>  });</pre><pre>  // sort the keys of the map by frequency, descending order<br>  const wordsSortedByCount = Object.keys(counter).sort(<br>    (a, b) =&gt; counter[b] - counter[a]<br>  );</pre><pre>  // finally, return the first n words in the sorted list of keys<br>  return wordsSortedByCount.slice(0, n);<br>};</pre><p>So what is happening here?</p><p>To start, we create a function, mostFrequent, that take two arguments: list is the array of words and n is the number of words we want to return.</p><p>Now, the question is about the most frequent words, so we want to count all of the words. To do this, we create a <strong>counter map</strong> to store key-value pairs of words and frequencies. First we create an empty object counter. This is our counter. Then we go through the words in list. If the word is already a key in counter, then we increment the count by one. If the word is not a key in counter, we add it as a key and set its value to one.</p><p>Let’s walk through that with an example. Let’s say list is this array:</p><pre>[&#39;hello&#39;, &#39;cool&#39;, &#39;cool&#39;, &#39;friend&#39;, &#39;hello&#39;, &#39;cool&#39;]</pre><p>When we start iterating through the list, counter is an empty object: {}.<br>The first item in the list is &#39;hello&#39;, so we assign &#39;hello&#39; to the variable word. Is &#39;hello&#39; in our counter? We call counter[word] to find out. If word is a key in counter, this will return a value like 1, 3, 50, etc. In this case, it is not a key, so counter[word] returns undefined. Undefined is falsey in JavaScript, so if (counter[word]) evaluates to false. That means we go into the else block: counter[word] = 1. We add &#39;hello&#39; as a key in counter and set its value to 1. Now counter looks like this:</p><pre>{ hello: 1 }</pre><p>Next, we go through the forEach loop again and examine the next item in the list, &#39;cool&#39;. We set our variable word to &#39;cool&#39;. Again, we check if &#39;cool&#39; is a key. It isn’t, so we add it to counter, which now looks like this:</p><pre>{ hello: 1, cool: 1 }</pre><p>We iterate again. The next element is &#39;cool&#39;. NOW is &#39;cool&#39; a key in counter? Yes, it is. When we call counter[&#39;cool&#39;], the result will be 1. This means we go through the first block of the if-else and increment the value of counter[&#39;cool&#39;]. So counter now looks like this:</p><pre> { hello: 1, cool: 2 }</pre><p>If this code isn’t 100% clear to you, work through the rest of the example list and notice how counter changes. By the end of the list, counter should be:</p><pre>{ hello: 2, cool: 3, friend: 1 }</pre><p>Please make sure you completely understand what this code is doing. Practice on paper or on your computer until you have convinced yourself that it works and you are confident you can write this code yourself.</p><p>(Some of you may be thinking, “Can’t I use Array.prototype.reduce for this?” You sure can! I am not going to talk about that because it is tricky code that is easy to get wrong on the whiteboard. The simpler code above will be fine for the whiteboard. But if you want to use reduce, go for it.)</p><p>OK, so now you have a counter. Next, you have to do something with it. In our example we have to sort the keys by their values. This is a common next step.</p><p>Why do we sort the keys? Why not just return the first n keys in the map?</p><p>You need to understand that <strong>the keys in a hash map are not ordered</strong>. Object.keys(counter) will not give you the keys in any predictable order. It may or may not be the order in which the keys were added. It may or may not be ordered by the values of the keys. It may or may not be the alphabetical order of the keys. This is true for the built-in hash map types in JavaScript, Ruby, Python, Java, etc. Unless you are using a specific library that implements ordered operations, you should assume that maps are <strong>unordered</strong>.</p><p>If you need guaranteed order, you need an array. So we make an array of the keys in counter, then we sort that array by the values of the keys.</p><p>Let’s digest what that means. Right now we have a counter map:</p><pre>{ hello: 2, cool: 3, friend: 1 }</pre><p>This map contains all of the distinct words in our original list and the number of times each word appears in the list. Our function needs to return the n most frequent words, so we need to order these words from most to least frequent. For our example, that means we want this result:</p><pre>[&#39;cool&#39;, &#39;hello&#39;, &#39;friend&#39;]</pre><p>Our counter says that &#39;cool&#39; is the most frequent word in our list (3 times). So in our result array, &#39;cool&#39; should be first. &#39;hello&#39; appeared the second-most number of times (2), so it should be second. Finally &#39;friend&#39; appeared the fewest number of times (1), so it should be last.</p><p>Let’s take a closer look at the code that gets us this result:</p><pre>const wordsSortedByCount = Object.keys(counter).sort( <br>  (a, b) =&gt; counter[b] — counter[a]<br>);</pre><p>When we call this code, our counter object looks like this:</p><pre>{ hello: 2, cool: 3, friend: 1 }</pre><p>First we call Object.keys(counter), which gets us an array of the keys in counter. This array might be [&#39;hello&#39;, &#39;friend&#39;, &#39;cool&#39;]. Or it could be [&#39;cool&#39;, &#39;hello&#39;, &#39;friend&#39;] or [&#39;friend&#39;, &#39;hello&#39;, &#39;cool&#39;], etc. We cannot reliably predict the order in which Object.keys will find the keys.</p><p>Whatever the order of the array, we then call the array&#39;s built-in sort method. So the code now is sort of like:</p><pre>[‘hello’, ‘friend’, ‘cool’].sort(<br>  (a, b) =&gt; counter[b] — counter[a]<br>)</pre><p>As you can see, Array.prototype.sort takes a callback function that tells sort how to compare the elements in the array. The callback takes two array elements, a and b, and the callback’s return value tells sort which element should come first. The rules for this callback are very specific:</p><ul><li>If a should come first, return a <strong>negative</strong> number.</li><li>If b should come first, return a <strong>positive</strong> number.</li><li>If a and b are equal return 0.</li></ul><p>Let’s say sort is comparing the first two elements, &#39;hello&#39; and &#39;friend&#39;. In the callback, a is &#39;hello&#39; and b is &#39;friend&#39;. The callback returns counter[b] — counter[a]. In other words, counter[&#39;friend&#39;] — counter[&#39;hello&#39;]. That’s the frequency of &#39;friend&#39; minus the frequency of &#39;hello&#39;, which evaluates to 1 — 2, which equals -1. That’s a negative number, so sort will put a &#39;hello&#39; before b &#39;friend&#39;.</p><p>Let’s compare the second and third elements, &#39;friend&#39; and &#39;cool&#39;. In the callback, a is &#39;friend&#39; and b is &#39;cool&#39;. counter[&#39;friend&#39;] is 1 and counter[&#39;cool&#39;] is 3. So our callback returns counter[b] — counter[a], or counter[&#39;cool&#39;] — counter[&#39;friend&#39;]. That’s 3–1, which is a positive number. So b should come before a. The sort function will change the order of the elements in the array so that &#39;cool&#39; is before &#39;friend&#39;.</p><p>If you aren’t convinced yet about sort and its callback, try working out how the callback would compare the first and third elements, &#39;hello&#39; and &#39;cool&#39;. Which would come first and why?</p><p>Once you’ve done that, you will agree the result of this sort will be:</p><pre>[&#39;cool&#39;, &#39;hello&#39;, &#39;friend&#39;]</pre><p>This makes sense because we know that &#39;cool&#39; appeared in the list three times, &#39;hello&#39; was in the list twice, and &#39;friend&#39; was in the list only one time. We have now sorted the words in the original list by their frequency, from most to least.</p><p>All we have to do now is return the first n elements in this sorted array. In JavaScript we do this by calling wordsSortedByCount.slice(0, n).</p><p>That’s a lot to digest, so I want to leave you with some action items:</p><ol><li>Write your own solution to the question we just did. Try not to refer to my example code.</li><li>Solve the rest of the example questions from the beginning of this post. Solve them by turning an array into a hash map and analyzing the hash map in some way.</li><li>Think of three more example problems you could solve with this technique, then solve them.</li><li>Do at least three of the problems from memory on paper or on a whiteboard.</li><li>Repeat 1–4 until you are confident you will remember how to turn an array into a hash map, and how to sort a hash map’s keys by its values.</li></ol><p>You really do need to both learn AND memorize this, so that you can use it on the whiteboard without breaking a sweat.</p><p>Questions or thoughts? Please leave a comment!</p><p>Stay tuned for more valuable whiteboard techniques to learn and remember.</p><p>Good luck with your interviews! You’ve got this!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8420e37d5ca" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is good code? Two myths to avoid]]></title>
            <link>https://mikesboyle.medium.com/what-is-good-code-two-myths-to-avoid-3a43c2d97e90?source=rss-7166a529a2b------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a43c2d97e90</guid>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Mike Boyle]]></dc:creator>
            <pubDate>Sat, 30 Mar 2019 23:09:06 GMT</pubDate>
            <atom:updated>2019-03-31T02:06:33.992Z</atom:updated>
            <content:encoded><![CDATA[<p>When I was looking for my first job as an engineer, I had some cringeworthy ideas about what made good code. I struggled a lot to write code in a dense and obscure style that I hoped would look “professional” and “advanced.” In hindsight, it was just weird and bad and no one liked it.</p><p>If you are preparing for your first interview or coding challenge and you’re also worried that people expect you to write extra fancy expert-looking code, I have good news for you. You don’t have to!</p><h3>But first: What IS good code?</h3><p>Engineers always fight about this, but I think most people would agree that good code is:</p><ul><li>easy to read and understand</li><li>easy to reuse, extend, and change</li><li>well-tested or easy to test</li><li>free of repetition and unnecessary complications</li></ul><p>There are many ways to meet those standards, but it will probably be much harder if you get caught up in the myths below, like I did.</p><h3><strong><em>Myth 1:</em></strong><em> Good code is short</em></h3><p>I believed that the best algorithm was the shortest one. This idea of mine was reinforced by struggling with coding problems on sites like codewars and then seeing that other users had submitted one-line solutions. What was wrong with me? Why was I writing 10 lines when other people needed only one?</p><p>I remember spending a painful night refactoring my project to make everything a one-liner. I turned all my if-else statements into densely nested ternaries. I replaced all of my variable names with single characters. I Googled a bunch of other Ruby golf tricks that I have forgotten and will not share here. And of course <em>it all had to fit on one line. </em>After all of that, you would have had no idea what my code was doing. But it was short!</p><p>There is a difference between short code and simple code. Simple code is good. It avoids doing unnecessary things, and it avoids repeating itself. It has fewer things that can go wrong and it’s easier to work with. That is what makes it good, not its length.</p><h3><strong><em>Myth 2:</em></strong><em> Good code is fancy code.</em></h3><p>I thought that good code had to use the newest and most advanced concepts. Whatever is cutting-edge, complicated, or obscure in your language or framework —hooks, monads, concurrency, procs, metaprogramming— well, <em>that’s</em> what I thought “good” code used.</p><p>I don’t think I fully realized that this was a myth until I was working a while and had the chance to interview other candidates. Then it was clear that the fancy stuff wasn’t what the interview panel wanted.</p><p>For example, at a past job we asked candidates to write a function that found the largest product of two items in an array of numbers. One candidate tried to do the multiplication with bitwise operators.</p><p>Now, that is certainly fancy code, but is it good code? I would say no. It makes the code harder to read and work with, and you get no benefit in exchange. Maybe bitwise arithmetic is faster, but how likely is it that <em>arithmetic</em> is the bottleneck in this algorithm? And even if it’s faster, it probably does not improve the time complexity, which is all that matters in an interview.</p><p>Sometimes the fancy tool is exactly the thing you need to solve the problem. In those cases, you should do the fancy thing. But doing the fancy thing for its own sake won’t help you. It only makes your interviewer think you do not know what good code is, or that you cannot clearly assess the pros and cons of the tools you choose.</p><h3>Tips for writing good code</h3><p>In general, and especially interviews and code challenges, you could try a process like this:</p><ol><li>Make sure you understand the task and have a plan for solving the problem.</li><li>Choose the right tools for the task. This is where you can show off your knowledge of fancy things <em>without having to use them</em>. You can explain why Fancy Tool X isn’t the right choice for the task compared to Basic Tool Y.</li><li>Try to write code that works at all. Be sure to say that you know you are writing something naive or brute-force.</li><li>Write out some test cases, including edge cases, and explain why your code handles them correctly.</li><li>Now try to optimize your code for time and space complexity.</li><li>Only now should you worry about your code’s style. Your goals should be to clean up the code for <em>simplicity</em> and <em>readability.</em></li></ol><p>Above all, don’t waste any time being down on yourself over coding myths. You will do better without them!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a43c2d97e90" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Four Dirty Words of Software Engineering]]></title>
            <link>https://mikesboyle.medium.com/the-four-dirty-words-of-software-engineering-fbbfe936e74c?source=rss-7166a529a2b------2</link>
            <guid isPermaLink="false">https://medium.com/p/fbbfe936e74c</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[developer]]></category>
            <dc:creator><![CDATA[Mike Boyle]]></dc:creator>
            <pubDate>Sun, 27 Jan 2019 15:59:14 GMT</pubDate>
            <atom:updated>2019-01-28T00:44:07.471Z</atom:updated>
            <content:encoded><![CDATA[<p>Your team probably won’t care if you drop the f bomb in every other sentence. But the words below are way worse, and using them carelessly on a team of software developers can provoke unintended offense, anxiety, and regrets.</p><h3>“just”</h3><p><strong>Typical use: </strong><em>“I know how to build it! </em><strong><em>Just</em></strong><em> rename table A in the database and move column Y to table B.”</em></p><p><strong>Why it’s a dirty word:</strong> You are deciding that a task should be quick and easy before discussing and understanding its true scope and complexity. If this is a task that you are going to do personally, you are setting yourself up for failure. What if it turns out to be hard? If you say “just” about a task that other people are doing, you set <em>them</em> up to fail.</p><p>People like to use this word right after they have thought of a solution that might work, or when they have only a “high-level” (read: vague) understanding of the work to be done. At a high enough level, everything seems easy: rocket science is “just” arithmetic, diamonds are formed “just” by applying pressure to carbon, etc.</p><p><strong>What you can say instead:</strong> <em>“One possible solution is to…”</em></p><h3>“actually”</h3><p><strong>Typical use:</strong></p><p>Person A:<em> “We parse the URL here.”</em></p><p>Person B: <em>“</em><strong><em>Actually</em></strong><em>, that’s a URI, not a URL.”</em></p><p><strong>Why it’s a dirty word:</strong> Live fact-checking your colleagues rarely adds anything of value to the conversation. Who cares if it is a URL or a URI at this moment? What impact does this have on the goals of the discussion?</p><p>Fact checking others with a smug <em>well, actually</em> only makes it more irritating. Also, this is only my personal experience, but it seems to me that the information following an <em>actually</em> turns out to be correct only half the time.</p><p>Sometimes it is necessary to clarify or correct something to move a discussion forward in a productive way. In that case, you should try to correct the information in a respectful and humble way that seeks first to understand.</p><p><strong>What you can say instead: </strong>“<em>Did I hear correctly that you said URL there? My understanding is that this is a URI. That could affect how we build this. Is there something I’ve misunderstood?</em>”</p><h3><strong>“bug”</strong></h3><p><strong>Typical use:</strong> <em>“@here I caught a </em><strong><em>bug</em></strong><em> on the login page! If login fails, it should say that your username was right but your password was wrong.”</em></p><p><strong>Why it’s a dirty word: </strong>There’s an aura of blame around the word <em>bug</em> that often makes it counterproductive. People dig into defensive postures instead of pitching in together to address an issue. It is worse when people are triumphant or self-righteous about finding a bug, or when they broadcast their discovery to an inappropriately wide audience.</p><p>I also really want to say here that over the years I have been told about many “bugs” that are not really bugs. Sometimes a “bug” is really a feature request. Or it may be an intentionally built feature that someone dislikes. It may be behavior that has only emerged because of changes made in some other far-flung part of the system by an entirely different team.</p><p>When we talk about bugs, what we usually mean is that the system did something we didn’t expect. Maybe the system is broken, or maybe the team has conflicting ideas about what to expect. Except in obvious cases (the site is down, the page crashes), it is better to frame the discussion in terms of what we observe vs. what we expected.</p><p><strong>What you can say instead: </strong><em>“When I failed to log in, I got a vague error message. I expected the error message to say if the problem was with my username or with my password. Was this an intentional decision and how did we agree on this?”</em></p><h3>“yeah yeah yeah”</h3><p><strong>Typical use:</strong></p><p>Person A: “<em>The problem is this service doesn’t have access to the user’s — ”</em></p><p>Person B: “<em>Yeah yeah yeah, I got it.”</em></p><p><strong>Why it’s a dirty word:</strong> When we believe that we already understand something that another person has only begun to start to say, we spit out a barrage of <em>yeah</em> until the other person stops talking. It is a compact way of saying both <em>shut up</em> and <em>f*ck you</em>.</p><p>What was Person A trying to advise us about, or warn us about, or maybe even suggest as a brilliant solution? We’ll never know. Even worse, Person A will be more reluctant to say anything next time around.</p><p><strong>What you can say instead:</strong> Literally nothing. Let the person finish.</p><p>One last point. What if you realize you’ve said one of the dirty words? Does this mean you are a horrible person? No! Of course not. No one is ever going to be perfect all of the time. You can say something like, “Whoops, I probably could have phrased that better. What I meant was…”</p><p>What are some other dirty words in tech? What should we say instead?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fbbfe936e74c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[It’s Not What You Know; It’s What You Don’t Know You Don’t Know]]></title>
            <link>https://mikesboyle.medium.com/its-not-what-you-know-it-s-what-you-know-you-don-t-know-7f991327fed5?source=rss-7166a529a2b------2</link>
            <guid isPermaLink="false">https://medium.com/p/7f991327fed5</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Mike Boyle]]></dc:creator>
            <pubDate>Sat, 05 Jan 2019 01:19:47 GMT</pubDate>
            <atom:updated>2019-01-05T02:08:06.289Z</atom:updated>
            <content:encoded><![CDATA[<p>When I started out as a developer, I was awed and intimidated by the experienced engineers around me, who all seemed to know so much about programming. They definitely knew a lot more than me, but here’s a secret: They actually didn’t know that much.</p><p>Nobody knows that much. <a href="https://en.wikipedia.org/wiki/There_are_known_knowns">To paraphrase Donald Rumsfeld</a>, in software engineering there are three kinds of knowledge:</p><ul><li>things you know you know</li><li>things you know you don’t know</li><li>things you don’t know you don’t know</li></ul><p>No matter how experienced you are, the things you know are vastly outnumbered by the things you do not know. And of all the things you do not know, the vast majority are things you’re oblivious to: ideas you didn’t even know existed, questions you wouldn’t have thought to ask, and, of course, stuff you <em>think</em> that you know, but you’re actually wrong about.</p><p>You definitely know a lot of things already, but in the long run, what you already know is never enough to do your job. This is true whether you’re a bootcamp student or a senior staff engineer. In a way, it is<em> more</em> true for senior staff engineers, because they are asked so often to deal with problems that nobody else has figured out yet.</p><p>What makes these engineers good isn’t that they always already know the answer. They don’t always know. The secret is that <strong>they are efficient at discovering the things they didn’t know they didn’t know</strong>, and then learning those things.</p><p>This skill manifests itself in lots of ways. They seem to know just what to Google for to solve the problem. They can jump into an unfamiliar system and quickly identify the cause of an error or alert. They can propose a better solution to your problem just by asking a few questions. When you pair with them, everything seems effortless and obvious.</p><p>This was not clear to me when I was starting out. I could see the huge gap between what other people knew and what I knew, and I assumed the only way to be like them was to frantically study lots of random things — anything and everything, really. I would despair on a daily basis over not knowing what in the world Apache Mesos was, or how git worked under the hood, or how to use sed, or how to balance a binary search tree, or which http response code meant “I’m a teapot,” or a thousand other things. I didn’t actually need to know any of that to do my tickets. I just wanted to have the knowledge stored in my brain so that I could be someone who always already knew things, just like the developers around me.</p><p>Meanwhile, and luckily, I did have lots of tickets that I had no idea how to do. I had hours and hours to look at code that <em>should</em> work, but didn’t, and ponder what I could be missing. There was <em>something</em> I needed to learn. What was it? Day after day, ticket after ticket, I slowly became aware that <em>there were tons of things that I didn’t know I didn’t know.</em> The trick is to figure out what those things are!</p><p>You have probably had similar thoughts while working on your own tickets. I’m sure you also have experienced discovering something that you didn’t know you didn’t know, and learning from it. Maybe you have asked yourself questions like:</p><ul><li>“I wonder if this method takes an optional parameter that will do what I’m trying to accomplish…”</li><li>“Maybe the second argument in Array.prototype.splice actually isn’t an array index after all?”</li><li>“Could this Ruby variable actually be a method call?”</li><li>“Is it possible that the customer’s order isn’t being persisted in UTC?”</li></ul><p>You can probably think of lots of “aha!” moments like this in your own work. You suddenly knew just what to look up to get unstuck. It occurred to you that someone else’s code might not really do what it seemed to do. You realized that what you thought you knew about something was actually wrong.</p><p>You probably have opportunities every day to intentionally and consciously hone the skill of discovering what you don’t know you don’t know. You can do this by asking yourself questions like:</p><ul><li>“What do I need to learn in order to solve this problem?”</li><li>“What am I assuming about how this code works? Am I right?”</li><li>“How is this problem different than similar ones I’ve solved in the past?”</li><li>“Why would this work in language X but not in language Y?”</li><li>“What do the docs say about this thing that I can’t get to work?”</li><li>“I’m positive I know what this does. But what if I’m wrong?”</li></ul><p>The more you work on this, the faster you’ll get at filling the gaps in your knowledge that need the most attention. You will become a better engineer, not just because you know more things, but because you are better at figuring out on the fly what you need to learn.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f991327fed5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>