<?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 Jim Thomason on Medium]]></title>
        <description><![CDATA[Stories by Jim Thomason on Medium]]></description>
        <link>https://medium.com/@thomasoniii?source=rss-72a47e2393d5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*1b3f1YD_vFvtU3jh</url>
            <title>Stories by Jim Thomason on Medium</title>
            <link>https://medium.com/@thomasoniii?source=rss-72a47e2393d5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 17:31:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@thomasoniii/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[Should I scope creep a new feature?]]></title>
            <link>https://medium.com/@thomasoniii/should-i-scope-creep-a-new-feature-bef6975dcdd1?source=rss-72a47e2393d5------2</link>
            <guid isPermaLink="false">https://medium.com/p/bef6975dcdd1</guid>
            <category><![CDATA[new-features]]></category>
            <category><![CDATA[feature-engineering]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[developer]]></category>
            <dc:creator><![CDATA[Jim Thomason]]></dc:creator>
            <pubDate>Fri, 19 Sep 2025 22:27:00 GMT</pubDate>
            <atom:updated>2025-09-19T22:27:00.898Z</atom:updated>
            <content:encoded><![CDATA[<p>As developers, we always want to add new stuff. Solve the new problem. Refactor the new pattern. Create the new doodad. And this is always traded off against time and budget constraints and your looming PM who just wants their feature now <em>now</em> <strong>NOW</strong>.</p><p>So I’m going to give you a quick and simple framework to follow to help you determine if you should write it. It’s simple — features fall into 3 buckets.</p><h4>Bucket #1 — A feature that was requested.</h4><p>This one’s easy. Write it. This is in your jira ticket, talked about in your standup, the bane of your PM’s existence. Promises have been made and customers are waiting for it. Write this one.</p><p>But, of course, the trick is that your feature may not <em>entirely</em> fit into this bucket — because if you just tweak the design a <em>little</em> bit you can build this other thing as well. Maybe you’ll implement a more abstract architecture or maybe you’ll add in some new option that wasn’t requested or maybe you’ll refactor something else along the way. That’s where the next two buckets come in.</p><p>(it’s also possible that it’s a feature that you <em>should not </em>implement for some reason. It’s a bad design or counter to what the users would actually want or will cause problems down the line. By all means push back on that, but stopping requested work is a different topic and I’m trying not to scope creep my article)</p><h4>Bucket #2 — A feature that you will use <em>right now.</em></h4><p>Absolutely implement these.</p><p>“You” and “use” are a little handwavy here.</p><ul><li>Maybe this is a refactor that will immediately reduce developer pain in some manner.</li><li>Maybe this is a new feature that your users will love and your PM salivates over the second she hears about it.</li><li>Maybe this is a new way to implement the feature that opens up doors to other things that you want to implement in 3 months.</li><li>Maybe this is a feature that was on the roadmap for 3 months from now, but with some modifications, you realized that you can add it now.</li></ul><p>It doesn’t matter. The point is that someone will use it immediately.</p><p>Now, to be clear — I’m not talking about those scope creeps where you suddenly push off the entire feature for 6 months while you implement some awesome new framework. It’s gotta be something that’s close to scope of what you’re working on and won’t extend the deadline by too much (let’s say maybe 20%, so that a one week feature might take an extra day, but that’s just a rough estimate). You can’t use this to justify major size scope creep no matter how awesome it is.</p><p>You <em>might</em> be able to use the immediate use test to justify getting a major long term feature into the roadmap now, but you should never try to shoehorn it in. We’re just talking small things.</p><h4>Bucket #3 — A feature that looks cool, but no one needs right now.</h4><p>Don’t implement these. Ever. This is the path to madness.</p><p>Because you don’t know what you’re going to need in a month or 3 months or 6 months. Sure, you have the roadmap, but that’s always a fluid document and maybe you’ll pivot next week.</p><p>If you’re thinking about building in architectural paths to make it easy to implement a theoretical thing that you don’t know if you need, then the only test is will it fall into Bucket #2.</p><p>The litmus for this is, if you tell someone, “If I build abc functionality, then it will enable us to build xyz later.” and they say “We absolutely need to do xyz, but I don’t know when we can get to it.” Then <em>implement it</em>. That has passed the immediacy test—if you could build it right now, you would. It’s only delayed due to (resources, time constraints, staffing, whatever). If the roadblocks weren’t there, you’d build it. Build those things, even if it’s kind of a theoretical item.</p><p>But the items that strictly fall into “Wouldn’t it be cool if we could…?” and no one can really articular the use case and no one is sure if it’d make the developers lives easier and no one knows how to sell it to the clients and the clients wouldn’t know how to use it anyway…then don’t build it.</p><p>Sure, it’s always the case that 6 months down the line you may realize you needed the thing and you have to go back and implement it (sometimes with some pain!) but that’s the price you pay. Otherwise you’re spending time and effort to build and maintain something that’s never used.</p><p>If you have the opportunity to make small scale tweaks to allow the <em>possibility</em> of the Whizbang Feature with minimal pain to implement it, while <em>simultaneously</em> causing minimal pain in the present to what you’re working on, then sure. Otherwise, no dice.</p><p>To sum up:</p><ul><li>Build the stuff you’re asked for.</li><li>If it’s not going to extend the deadline too far, and somebody is going to use it immediately, then scope creep and build the new thing.</li><li>If you’re not sure who’s going to use it or when, then don’t build it (though you can maybe plan a little bit for it, if there’s enough murmuring interest).</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bef6975dcdd1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Don’t worry: Elon Musk no longer has your data]]></title>
            <link>https://medium.com/@thomasoniii/dont-worry-elon-musk-no-longer-has-your-data-2f8ecda2701f?source=rss-72a47e2393d5------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f8ecda2701f</guid>
            <category><![CDATA[political-satire]]></category>
            <category><![CDATA[satire]]></category>
            <category><![CDATA[funny]]></category>
            <category><![CDATA[humor]]></category>
            <category><![CDATA[parody]]></category>
            <dc:creator><![CDATA[Jim Thomason]]></dc:creator>
            <pubDate>Wed, 12 Feb 2025 20:45:43 GMT</pubDate>
            <atom:updated>2025-02-18T16:32:14.205Z</atom:updated>
            <content:encoded><![CDATA[<p>In a totally legitimate press conference at the Capitol today, which some will nonetheless dismiss as mere satire, Senator Susan Collins (Q-Anon, ME) addressed media concerns that Elon Musk’s DOGE has exfiltrated sensitive user data from the Treasury Department.</p><p>“After U.S. District Judge Paul A. Engelmayer issued a <a href="https://www.npr.org/2025/02/08/g-s1-47350/states-sue-to-stop-doge-accessing-personal-data">preliminary injunction</a> barring DOGE from accessing Treasury Department Records, there was concern that Elon Musk might not have complied with the order or otherwise attempted to ‘keep’ the data. I assure you that this is not the case.</p><p>“No less than President Musk himself came to my office today. He had one of those little portable computers they have nowadays. I don’t really know how they work, but he assured me that it had all the data on it. It’s just incredible what you can do with these things nowadays! I thanked him for his service in inventing such a useful device for the American people and was amazed at the number of jobs he expects its manufacture to create here in Maine!</p><p>“He explained that all of the data is right here on that little box, and he had me watch while he typed in ‘DELETE ALL GOVERNMENT DATA FROM COMPUTER’. It took a few minutes, but then he told me that all of the data was gone now.</p><p>“Further, since he was aware of the gravity of the situation, he allowed me to take a photograph of the computer monitor so that I could share the photographic evidence with the American people. This is a man at the absolute top of government power who was willing to risk personal information on his computer machine being photographed just to prove that he had complied, simply because he wants your trust.</p><p>“I tried to photograph it with my Minolta, but my staffer Janet reminded me that it might be difficult to get the film developed nowadays, which is something I’ve never quite understood. Fortunately, she has one of those newer portable telephones with a camera built right into it and she took a photo of it for me. It’s amazing the gadget and gizmos that these tech people like High Lord Musk come up with! I am sharing the photograph with you all here as proof.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*whP2shJCH7i9du3b9NiLIw.jpeg" /><figcaption>Actual photograph of an actual computer screen</figcaption></figure><p>“Finally, His Exhalted Muskness apologized for overstepping his bounds and seemed genuinely rattled by the whole event. I’m quite confident that it was a wake up call to him and he’s learned his lesson and that there won’t be any further misunderstandings going forward. No further inquiry on the subject should be be necessary, and I consider the matter to be closed.</p><p>“Thank you for your understanding during this difficult time of governmental transition into Fascist Theocracy.”</p><p>Senator Collins then attempted to leave via a Tesla Cyber Truck, but she was unable to find the door handle.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f8ecda2701f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Donald Trump is a coward. William Henry Harrison was our bravest president]]></title>
            <link>https://medium.com/@thomasoniii/donald-trump-is-a-coward-william-henry-harrison-was-our-bravest-president-67d507065c7c?source=rss-72a47e2393d5------2</link>
            <guid isPermaLink="false">https://medium.com/p/67d507065c7c</guid>
            <category><![CDATA[politics]]></category>
            <category><![CDATA[president]]></category>
            <category><![CDATA[satire]]></category>
            <dc:creator><![CDATA[Jim Thomason]]></dc:creator>
            <pubDate>Mon, 20 Jan 2025 14:17:37 GMT</pubDate>
            <atom:updated>2025-01-20T14:22:33.256Z</atom:updated>
            <content:encoded><![CDATA[<p>Today Donald Trump will be inaugurated as our 47th president, becoming the oldest president at time of taking the oath, and doing so while snug and warm inside the Capital Rotunda.</p><p>But I don’t want to talk about him — I instead want to write about our ninth president: William Henry Harrison.</p><p>Harrison was <em>also</em> the oldest president at the time of his inauguration, when he was 68 years and 23 days old. There was a lot of concern and hand wringing about his age, but did this concern Old Tippecanoe? No, it did not.</p><p>Instead, he rose to the occasion and proceeded to take the oath of office outside on a cold and wet Fourth of March, 1841. He didn’t let a little weather stop him or his loving crowds (probably the largest crowds at an inauguration, but we don’t have really accurate records from back then) from seeing him take the oath.</p><p>He didn’t even need to wear a coat or a hat or gloves. He was a real man’s man.</p><p>Further cementing his prowess as an orator and the right man to lead the Union, Harrison went on to deliver an 8,445 word speech that took him over two hours to read, even though Daniel Webster had already edited it down slightly for length.</p><p>And to this day, 184 years later, we still talk about William Henry Harrison giving that long speech on that cold day, and the courage and fortitude of the event. He didn’t let his age stop him from standing in the cold, wet rain for 2 hours and giving his public what they wanted.</p><p>I’m shocked that Donald Trump would allow for anything less. Standing in the Rotunda? Probably wearing a snuggie? Like some sort of a baby? Is this the image he wants to present?</p><p>No. I assure you, it is not.</p><p>So I for one call upon President-Elect Trump to follow William Henry Harrison’s example and hold his inauguration outside, as is tradition.</p><p>And then, if we’re all lucky, everyone will continue to talk about Trump’s inauguration today for the next 184 years as well.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=67d507065c7c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Dictator Is Not Your Friend]]></title>
            <link>https://medium.com/@thomasoniii/the-dictator-is-not-your-friend-d0c619e85e70?source=rss-72a47e2393d5------2</link>
            <guid isPermaLink="false">https://medium.com/p/d0c619e85e70</guid>
            <category><![CDATA[dictatorship]]></category>
            <category><![CDATA[politics]]></category>
            <category><![CDATA[politics-and-elections]]></category>
            <category><![CDATA[politics-and-protest]]></category>
            <dc:creator><![CDATA[Jim Thomason]]></dc:creator>
            <pubDate>Tue, 12 Nov 2024 17:30:15 GMT</pubDate>
            <atom:updated>2024-11-12T17:30:15.929Z</atom:updated>
            <content:encoded><![CDATA[<p>He doesn’t like you at all—never has and never will. It doesn’t matter who you are or who he is.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*PXDunniWtet523-8if0cVg.png" /><figcaption>I asked gemini to give me an image of a dictatorship</figcaption></figure><p>So let’s start with some basic assumptions and work forward.</p><p>You <em>probably</em> don’t like the government. For some definition of “the government” — you don’t like your national government or state or town or school board or home owner’s association. Something. They’re not operating in your interests, they’re not doing what you want, they’re kind of annoying.</p><p>Or even worse—they’re pushing something you’re actively opposed to. Maybe they’re raising your taxes or cutting your benefits or teaching your kids something you don’t want them to know (or not teaching them something you <em>do</em> want them to know).</p><p>I’m sympathetic. All governing bodies are a series of compromises where you may have to put up with some things that you hate, and in exchange for that you get some things that you want. But it’s never going to be perfect and you’re always going to be frustrated about something. Sorry, it’s just how things go.</p><h4>But but but—and here’s the special magic trick about representative government — your government <em>works for you</em>.</h4><p>That means that if you don’t like what’s going on, you can fire them. That’s what elections are <em>supposed</em> to be about. If you’re not getting the results that you want, you kick out your representative and you hire someone who’s promising to give you what you want. Please note that this is subtly different from how most Americans handle elections, where they tend to only focus on the “fire them” part and gloss over the “hire somebody better.” We tend to just opt out because we’re unhappy with our choices. Or maybe we flip to the other party solely because it’s the other party. But we don’t put a lot of emphasis on hiring people to do what we want.</p><p>That’s because a lot of people think that government <em>doesn’t</em> work for them. There’s a foolish assumption that the “government” is some nebulous unaccountable entity that just hovers around in the background doing whatever it wants despite our objections. Government is something we need to endure, not something we can control. It’s them vs us as we just try to survive, but we don’t really have a say in the matter.</p><p>Adding further frustration, even when you have people that you like among your elected officials, there’s always an <em>other</em>. Somebody from the other side that’s thwarting your actions or trying to stop you. It doesn’t matter if you’re trying to give everyone healthcare or deport immigrants, it seems like there’s always someone opposing you. And that slows down what you want and pisses you off and frustrates you and makes you feel like government doesn’t work and you don’t have a say in the matter any way.</p><p>And so The Dictator enters.</p><p>The Dictator is efficient! The Dictator has your needs at heart! The Dictator will get things done! The Dictator will deal with the horrible government! The Dictator loves you!</p><p>The Dictator is lying to you.</p><p>The very best case scenario is that some of your interests overlap with some of the promises that The Dictator is making. And this is very very tempting to listen to and think that you two are so completely aligned and he’d be a great choice, but it’s all for naught.</p><p>The Dictator has never actually mentioned you by name. There isn’t a single promise that he’s made that singles you out. There’s a lot of vague talk and vague promises that sound similar to things that you want, but when you try to nail down specifics they’re tough to see. “Just trust me!” The Dictator yells, “We’re on the same side! Once I’ve taken control I can implement The Plan!”</p><p>And so you vote for The Dictator. And then you have a <em>problem</em>.</p><p>Because there hasn&#39;t been a dictator in all of recorded history that’s actually operating with the needs of the people as their main driver. There’s lip service paid to it. There’s always <em>some</em> amount of overlap between what they’re pushing and the public is buying (in the beginning). But when push comes to shove, you’re at best a useful idiot helping The Dictator get what they want. If you want it too, then that’s great for you! But it’s not really about you.</p><h4>Think about the relationships in your life that are really one sided.</h4><p>Sure, everybody hates something about government. But think about the relationships you’re stuck in that you really have no say about. Things like your employer. You can be angry at your boss all you want, but at the end of the day you need to fall into line and do as you’re told or else you’ll be eliminated. What course of action do you have at that point? Not much, because you entered into a relationship with another side that has all the power.</p><p>Or what about your health insurance? Your employer provides it. Your employer <em>chose</em> it. Don’t like it? Your opinion is noted and promptly forgotten. Because it doesn’t matter. You could absolutely detest them, but they’re still going to be your health insurer because you have no say in the matter. They can raise your rates and deny your coverage and refuse your surgery, and they’ll <em>still</em> <em>be your health insurance.</em></p><p>Why? Because your job wants them to be your health insurance. Maybe they’re getting a “good” rate from the insurer. Maybe they get a kickback. Maybe your boss’s daughter works at the insurer. Who knows? But you can take it or leave it, and that’s only an option if you can afford coverage somewhere else, along with having a source of income outside of your job.</p><p>You may hate your elected officials, but you probably <em>really</em> hate your health insurance. And you <em>really</em> hate your health insurance because you’re locked into it with very few options to get out of it and do something else, not without making other major upheavals in your life that you may be unwilling or unable to do.</p><h4>So why enter another one?</h4><p>And finally, this all simply comes down to this — your elected officials work <em>for you</em>. You can elect the people to institute the policies you want to see, and then we can all argue and quibble about whether enough of us want them to actually enact them.</p><p>But the second you put a dictator in power, you will find that your government doesn’t work for <em>you </em>anymore, it works for <em>him</em>. Dictators are extremely efficient and can get things done and that’s super appealing! I get it! And as long as everything he wants to do aligns with what you want him to do, you’ll have a grand time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*PXDunniWtet523-8if0cVg.png" /></figure><p>Everything won’t align. Something will be out of whack. A neighbor or a relative or you yourself will get hurt or caught up in something. “That’s not what I meant!” you scream as you realize that no qualifiers were made to the promises. You didn’t vote for “I’ll deport everyone except for Bob.”</p><p>Once they’re in power, they’re extremely difficult to get rid of, because they get swept in in a fury of removing the very constraints that force them to work for you, however inefficiently. Once that happens, you work for them. And as much as you love following every decision by your employer and your health insurer, you’ll now get to follow every decision by your government too.</p><p>The one bit of a silver lining is at least that no matter how entrenched a dictator becomes, it’s still easier to get rid of them than to overthrow and dismantle management of a company or get your boss’s boss’s boss to undo some business deal that you don’t care of. But it’s not much easier.</p><p>Buckle up. It’s going to be a rough couple of years as we all figure out the difference between a government that worked for us, that we could have changed so it worked <em>better</em> for us, and a government that works for someone else.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d0c619e85e70" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I completely over-engineered a binary search implementation]]></title>
            <link>https://medium.com/@thomasoniii/how-i-completely-over-engineered-a-binary-search-implementation-7bfa6b75d50e?source=rss-72a47e2393d5------2</link>
            <guid isPermaLink="false">https://medium.com/p/7bfa6b75d50e</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[good-and-bad-design]]></category>
            <category><![CDATA[binary-search]]></category>
            <category><![CDATA[refactoring]]></category>
            <category><![CDATA[software-design]]></category>
            <dc:creator><![CDATA[Jim Thomason]]></dc:creator>
            <pubDate>Fri, 10 Nov 2023 21:35:39 GMT</pubDate>
            <atom:updated>2024-08-06T20:11:43.819Z</atom:updated>
            <content:encoded><![CDATA[<p>This is not <em>really</em> a cautionary tale about building an over engineered solution, more of a case study about how an implementation evolved and nearly devolved into something awful.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HUAdqVKky6qmm90UfPURaw.png" /><figcaption>I asked midjourney to build me an over engineered solution</figcaption></figure><p>So, to start with. I had some data, as many of us programmers frequently do. The specific relevant bit I’m working with right now was a list of formatted date strings in a sorted array. Like this:</p><pre>const sortedDates = [<br>  &quot;2023-08-01&quot;,<br>  &quot;2023-08-07&quot;,<br>  &quot;2023-08-13&quot;,<br>  &quot;2023-09-01&quot;,<br>  &quot;2023-10-01&quot;,<br>  &quot;2023-10-05&quot;,<br>  &quot;2023-10-06&quot;,<br>  &quot;2023-10-11&quot;,<br>  &quot;2023-10-27&quot;,<br>  // etc. You get the idea<br>];</pre><p>These strings were used to key into other data, and I needed to be able to traverse these dates in order. I needed concepts like “next date” and “previous date”, and I also needed reasonably fast random access.</p><p>Far removed from this structure, my processing parameters involved a start date and an end dates — I’d be handed this:</p><pre>[&quot;2023–08–01&quot;, &quot;2023–08–31&quot;]</pre><p>And then need to process it somehow. First good question to ask is, was this the right structure to use? A linked list would give me the previous/next functionality I needed, but it wouldn’t give me fast random access. You’ll also notice that I don’t have a continuous list of all dates in a sequence, so I couldn’t find my date via an index. Maybe I could use some sort of extra layered lookup structure with a linked list and then external keys into individual nodes? That sounded overly complicated.</p><p>Well, I <em>could</em> just iterate through the array until I found the value I wanted…that’s easy, but also very slow. Potentially devastatingly slow as the array got big (for sufficient values of “big”). Maybe I could try to guess about coming in from the start or the end based upon the value I was looking for?</p><p>Sigh. I’d just need to use a binary search.</p><p>Now, to be clear, I have nothing against binary search. It’s a wonderful algorithm and easy to implement (not that I’d needed to implement one in a while). But given the choice, I think it’s always good to take some time considering your data structures. Is there a better way to structure the data that doesn’t <em>require</em> a searching algorithm at all? After some studying and debate, I decided there wasn’t and my sorted array with binary search was the right way to go.</p><p>A little googling to refresh my memory, and I got this knocked out pretty quick. I’m sure you can find a bazillion similar implementations all over the ‘net.</p><pre>export function binarySearch(array, value, incomingOptions = {}) {<br>  // take the incomingOptions array and massage in some default values<br>  // the startIdx is the possible low point in the array to search<br>  // the endIdx is the possible high point in the array<br>  // the comparator is a function that takes two values and returns <br>  // -1, 0, 1, depending upon if the first element is before, equal to<br>  // or after the second.<br>  // standard stuff. `stringComparator` here is just an external function<br>  // that does that comparison on strings.<br>  const options = {<br>    startIdx: 0,<br>    endIdx: array.length - 1,<br>    comparator: stringComparator,<br>    ...incomingOptions,<br>  };<br><br>  const { startIdx, endIdx, comparator } = options;<br><br>  // if the endIdx has overshot the startIdx, then it&#39;s not in the array.<br>  // return -1<br>  if (endIdx &lt; startIdx) {<br>    return -1;<br>  }<br>  const midPoint = Math.floor((startIdx + endIdx) / 2);<br><br>  const comparison = comparator(value, array[midPoint]);<br><br>  // if the value at that point is our search value, we&#39;re done!<br>  // return the index<br>  if (comparison === 0) {<br>    return midPoint;<br>  // otherwise, if it&#39;s less than our value, then search the first half<br>  // of the range<br>  } else if (comparison &lt; 0) {<br>    return binarySearch(array, value, {<br>      ...options,<br>      startIdx: startIdx,<br>      endIdx: midPoint - 1,<br>    });<br>  // and if it&#39;s greater than our value, search the second half of the range<br>  } else if (comparison &gt; 0) {<br>    return binarySearch(array, value, {<br>      ...options,<br>      startIdx: midPoint + 1,<br>      endIdx: endIdx,<br>    });<br>  }<br><br>  // we should never actually reach this<br>  // and my linter was griping about a missing return for some reason.<br>  // so whatever.<br>  return -1;<br>}</pre><p>Standard stuff. Works like a charm, too! Nice and fast, scales well as my array gets bigger, lets me get to my data and…whoops there’s a problem.</p><p>Let’s learn more about the problem I’m dealing with. This is financial transaction information, and we’re dealing with aggregate values right now. So for a given account, our list of sortedDates is the day a transaction occurred against a given account. And that date is a key into a different structure that contains information about the balance on that date.</p><p>The problem at hand here is that it’s a sparse array. Imagine this simplified structure:</p><pre>const sortedDates = [<br>  &#39;2023-10-01&#39;,<br>  &#39;2023-11-01&#39;<br>]<br><br>const balanceByDate = {<br>  &#39;2023-10-01&#39; : 40,<br>  &#39;2023-11-01&#39; : 50<br>}<br><br>function getBalanceOnDate (date) {<br>  return balanceByDate[date] || 0<br>}</pre><p>We can use our binarySearch function defined up above there to easily find that the balance on October 1st is $40. And we can also use it to easily find that the balance on November 1st is $50.</p><p>But what about October 2nd?</p><p>That’s <em>not in the array</em>. So our binary search would return a -1, and our balance is…$0?</p><p>This is, in fact, the whole reason that I populated the stupid sorted sparse array to begin with. I needed to find the balance on a given date, but my structure is only storing the days on which the balance <em>changed</em>.</p><p>But I can still use this sorted dates array to find out my balance on an arbitrary date. The algorithm is easy to say -</p><blockquote>1. Search for a date. If you find it, use it.</blockquote><blockquote>2. If you <em>don’t</em> find the date you want, then take the previous date and use that.</blockquote><p>But how do you implement that? Our binary search function here is only returning two things — the index (if found) or a -1 if <em>not</em> found. That’s not enough information to tell me the prior date. It’s just letting me know that 2023-10-02 isn’t in my array. How do I find the prior value?</p><h3>Take 1 — “closeness”</h3><p>I thought about this a lot and decided to implement a “closeness” function. The closeness function would be another option that gets handed into the incomingOptions of the binarySearch and then used to determine the next closest index, based upon what type of “closeness” we want.</p><p>Even though I only had immediate need for one type (the “before” case, I could immediately think of four versions:</p><ol><li><strong>before—</strong>If the value isn’t in the array, give the index of the value that would precede it.</li><li><strong>after—</strong>If the value isn’t in the array, give the index of the value that would follow it.</li><li><strong>closest—</strong>If the value isn’t in the array, give either the before or after index, whichever one is closest to the value.</li><li><strong>equality</strong>—strictly only return the element itself. If it’s not in there, it’s a -1.</li></ol><p>The only time the closeness function gets called is if the value isn’t in the array. So it’s just a one line change to the binarySearch function:</p><pre>  if (endIdx &lt; startIdx) {<br>    // Don&#39;t just return -1<br>    // return -1<br>    // return whatever the closeness function tells us to. Give that <br>    // function our options.<br>    return checkCloseness(array, value, options);<br>  }</pre><p>The checkCloseness function was also fairly simple. Just a switch statement.</p><pre>// I hate re-typing strings, so I stuffed them into an object in order to <br>// use known variables.<br>//<br>// e.g. typing CLOSENESS.EQUALITY instead of &quot;EQUALITY&quot;<br>export const CLOSENESS = [&quot;EQUALITY&quot;, &quot;BEFORE&quot;, &quot;AFTER&quot;, &quot;CLOSEST&quot;].reduce(<br>  (bucket, key) =&gt; ({ ...bucket, [key]: key }),<br>  {}<br>);<br><br>export function checkCloseness(<br>  array,<br>  value,<br>  {<br>    startIdx,<br>    endIdx,<br>    comparator,<br>    delta = defaultDelta,<br>    closeness = CLOSENESS.EQUALITY,<br>  } = {}<br>) {<br>  switch (closeness) {<br>    // the equality case always returns -1 - we only reach this function if<br>    // we haven&#39;t found the value.<br>    case CLOSENESS.EQUALITY:<br>      return -1;<br>    // at this point, our endIdx &lt; our startIdx - that&#39;s the condition for<br>    // not finding the element as part of binary search.<br>    // so we check to see if the array element at endIdx is less than our value.<br>    // if it is, then it counts as before and we return it.<br>    // if not, then there is nothing in the array before our value and <br>    // we return -1.<br>    //<br>    // that&#39;s for cases like an array of [3,4,5] and we search for 2.<br>    // nothing before 2 is in that array.<br>    case CLOSENESS.BEFORE:<br>      return endIdx &gt;= 0 &amp;&amp; comparator(array[endIdx], value) === -1<br>        ? endIdx<br>        : -1;<br>    case CLOSENESS.AFTER:<br>    // the after case is the same as the before, except we see if the<br>    // element at startIdx is greater than our value. If so, it&#39;s after<br>    // and we return that index.<br>      return startIdx &lt; array.length &amp;&amp; comparator(array[startIdx], value) === 1<br>        ? startIdx<br>        : -1;<br>    case CLOSENESS.CLOSEST: {<br>      // the closest case is a little trickier, because our comparator<br>      // only returns -1, 0, 1. It doesn&#39;t say how close they are.<br>      // Say we have an array of [5, 10] and we were searching for 6.<br>      // 5 is before, we&#39;d return an index of 0.<br>      // 10 is after, so we&#39;d return an index of 1.<br>      // but which one is closer? Our comparator doesn&#39;t tell us.<br>      // So. We hand in a delta function as well. The delta will tell us<br>      // the difference between the two values and give us the closer one.<br>      // So with a delta of (a,b) =&gt; Math.abs(b - a)<br>      // we&#39;d see that endIdx (5) has a delta of 1<br>      // and startIdx (10) has a delta of 4.<br>      // so we&#39;d return endIdx for our result.<br>      if (endIdx &lt; 0 || startIdx &gt;= array.length) {<br>        return -1;<br>      }<br>      const startDelta = delta(array[endIdx], value);<br>      const endDelta = delta(array[startIdx], value);<br>      // if the two values are equal, CLOSEST will prefer the preceding value.<br>      return startDelta &lt; endDelta ? endIdx : startIdx;<br>    }<br>    default:<br>      throw new Error(&quot;Cannot determine closeness w/o delta function&quot;);<br>  }<br>}<br><br>const defaultDelta = () =&gt; {<br>  throw new Error(&quot;Cannot determine closeness w/o delta function&quot;);<br>};</pre><p>You could still call it like this:</p><pre>const array = [1,3,5,7,9]<br>const idx = binarySearch(array, 5); // returns 2</pre><p>But you could also do things like this:</p><pre>const numericComparator = (a, b) =&gt; {<br>  if (a &lt; b) {<br>    return -1;<br>  }<br>  else if (a &gt; b) {<br>    return 1;<br>  }<br>  else {<br>    return 0<br>  }<br>}<br><br>const array = [1,3,5,7,9,15]<br>const idx = binarySearch(<br>  array,<br>  5,<br>  { comparator : numericComparator}<br>); // still returns 2, but w/o using a string comparison.<br><br>const beforeIdx = binarySearch(<br>  array,<br>  4,<br>  { comparator : numericComparator, closeness : CLOSENESS.BEFORE}<br>); // returns 2, since 3 is the element before 4.<br><br>const beforeIdx = binarySearch(<br>  array,<br>  4,<br>  { comparator : numericComparator, closeness : CLOSENESS.AFTER}<br>); // returns 3, since 5 is the element before 4.<br><br>const beforeIdx = binarySearch(<br>  array,<br>  10,<br>  {<br>    comparator : numericComparator,<br>    closeness : CLOSENESS.AFTER,<br>    delta : (a,b) =&gt; Math.abs(b - a)<br>  }<br>); // returns 4, since 9 is the closest element to 10<br><br>const beforeIdx = binarySearch(<br>  array,<br>  13,<br>  {<br>    comparator : numericComparator,<br>    closeness : CLOSENESS.AFTER,<br>    delta : (a,b) =&gt; Math.abs(b - a)<br>  }<br>); // returns 5, since 15 is the closest element to 13</pre><p>And huzzah this works, and in years past I might’ve just stopped at this point and been happy enough. It probably would’ve handled what I needed to throw at it (spoiler: it wouldn’t have), and I could get back to real work on the real algorithm w/o stressing about this little oddity.</p><p>But I wasn’t content with this. The code smelled and it irritated me.</p><h3>Code smells.</h3><p>There are a couple of things that irritate me about this implementation.</p><ol><li>The checkCloseness function uses a hardwired switch statement. What if in the future I come up with some new closeness value I want to search on? Or, even worse, what if I want to have my search function dynamically adjust the closeness? I don’t have any cases for this, mind you. So I was trying to put this out of my head and not build solutions for possible problems that aren’t defined.</li><li>But that third argument annoys me. incomingOptions in binarySearch now accepts: startIdx, endIdx, comparator, closeness, and delta. Those first 3 values are used by binarySearch itself, but the other two are only passed along to an internal function. That felt sloppy and like I was leaking an abstraction. It’s one thing to <a href="https://en.wikipedia.org/wiki/Dependency_injection">inject a dependency</a> into binarySearch, it’s another to do it into one of binarySearch&#39;s internal functions.</li><li>Plus, if I’m <em>already</em> injecting dependencies for checkCloseness, could I also inject the closeness function itself? What if I broke apart that switch statement into a dispatch and had it key against separate functions? Maybe then I could register a new closeness function into this dispatch and get a new key to hand along and solve that issue from Smell #1?</li></ol><p>I debated on this off and on for a few days. Did I really want to go down this route? Did I really <em>like</em> it? Was this going to be worth the effort? I finally decided to try roughing it out and see if I could come up with a different approach.</p><h3>The project goes off the rails.</h3><p>I’ve been a developer for a very long time. I’ve been operating in a senior architect capacity for a long time. I’ve built a lot of systems. Here’s something that I’ve learned about myself, in terms of how I tend to design things:</p><ol><li>My first pass will mostly basically work. It’ll miss some edge cases and maybe be tougher to extend, but it’ll get the job done. That was the earlier implementation.</li><li>My second pass will be <em>bonkers insane</em>. It will be way too complicated to use with a difficult interface and tons of confusing options. No one will want to use it, including myself. You’re gonna see that in a second.</li><li>My third pass is usually pretty solid. Not crazy like the second pass, and not limited like the first. The interface is usually straightforward and tends to be even more powerful than the bananas version. I strive to get to this version ASAP but have yet to figure out a way to consistently do it without passing through <em>bonkers insane.</em></li></ol><p>So. Without further ado.</p><h3>The bonkers insane version.</h3><p>Where to begin. My first thought was that dependency injection. I’m sending in new code to something farther down the chain. Is that actually acceptable? Sure it is! That’s just a <a href="https://en.wikipedia.org/wiki/Factory_method_pattern">factory pattern</a>. We’ve been building OO code for decades that allows this, and functional code can do it too. It’s acceptable.</p><p>Having convinced myself that it wasn’t completely crazy to allow such a thing, I needed to settle on what I didn’t like about it and how to clear it up.</p><ol><li>It’s straightforward to break up the checkCloseness function to call checkEqual, checkBefore, checkAfter, checkClosest functions based upon some dispatch table. That’s a good first step.</li></ol><pre>export function checkClosenessAfter(<br>  array,<br>  value,<br>  { startIdx, comparator } = {}<br>) {<br>  return startIdx &lt; array.length &amp;&amp; comparator(array[startIdx], value) === 1<br>    ? startIdx<br>    : -1;<br>}<br><br>export function checkClosenessBefore(<br>  array,<br>  value,<br>  { endIdx, comparator } = {}<br>) {<br>  return endIdx &gt;= 0 &amp;&amp; comparator(array[endIdx], value) === -1 ? endIdx : -1;<br>}<br><br>export function checkClosenessClosest(<br>  array,<br>  value,<br>  { startIdx, endIdx, delta = defaultDelta } = {}<br>) {<br>  if (endIdx &lt; 0 || startIdx &gt;= array.length) {<br>    return -1;<br>  }<br>  const startDelta = delta(array[endIdx], value);<br>  const endDelta = delta(array[startIdx], value);<br>  // if the two values are equal, CLOSEST will prefer the preceding value.<br>  return startDelta &lt; endDelta ? endIdx : startIdx;<br>}<br><br>export function checkClosenessEquality() {<br>  return -1;<br>}<br><br>// hardwire in our initial dispatch based upon the built ins<br>export const closenessDispatch = {<br>  EQUALITY: checkClosenessEquality,<br>  AFTER: checkClosenessAfter,<br>  BEFORE: checkClosenessBefore,<br>  CLOSEST: checkClosenessClosest,<br>};<br><br>// extract out our list of keys<br>export const CLOSENESS = Object.keys(closenessDispatch).reduce(<br>  (bucket, key) =&gt; ({ ...bucket, [key]: key }),<br>  {}<br>);<br><br>// and provide a way to register new closeness functions, should the need arise<br>export const registerCloseness = (key, func) =&gt; (closenessDispatch[key] = func);</pre><p>Of course, this was actually spread out across 6 different files — with each function in its own file, an index exporting all of them, and the dispatch in a separate table. Nice compartmentalized modular design! 🙄</p><p>Now our checkCloseness function becomes this:</p><pre>export function checkCloseness(array, value, options = {}) {<br>  const closeness = options.closeness || CLOSENESS.EQUALITY;<br>  if (closenessDispatch[closeness]) {<br>    return closenessDispatch[closeness](array, value, options);<br>  }<br><br>  throw new Error(`Cannot check closeness of ${options.closeness}`);<br>}</pre><p>And binarySearch stays as before. This is progress! But…that registration function is a little annoying. Maybe there’s a case where I want to build a new closeness function on the fly. Then I’d need to create it and register it into the dispatch before I can use it. What if it’s a single use item? Maybe I’m determining closeness in some manner for some particular set of data but wouldn’t necessarily re-use it? Then I’ve got a junk method sitting around in my dispatch.</p><p>I could add an unregister function to drop stuff from the dispatch, but that’s kinda going in the wrong direction. It shouldn’t be in there at all. I really should be able to hand in a closeness function with my options. Something like this:</p><pre>export function checkCloseness(array, value, options = {}) {<br>  // use a closenessFunction if it&#39;s been handed in<br>  // or otherwise look it up in the dispatch based on the closeness key.<br>  const closenessFunction = options.closenessFunction ||<br>      closenessDispatch[options.closeness || CLOSENESS.EQUALITY];<br>  if (closenessFunction {<br>    return closenessFunction(array, value, options);<br>  }<br><br>  throw new Error(`Cannot check closeness of ${options.closeness}`);<br>}</pre><p>That’s looking better! Now I can hand in a known default function, register a new function, or hand in a separate function w/o registration. Bliss!</p><h3>Not Bliss.</h3><p>Almost. There’s a potential mismatch pattern here. Once you can hand in a custom external closeness function, then we have the possibility that that function was set up with a different comparator than our binary search is using. What if we use a closeness function designed for integers but our comparator and array are full of string values? It’s not gonna work. ditto with the delta function.</p><p>Plus, it’s just extra confusing — you could be handing in your own custom comparator and delta function, and then have absolutely no idea why your closeness function isn’t working. Maybe you didn’t write the closeness function and are using something off the shelf incorrectly.</p><p>What I needed was a way to force the closeness function to use the right comparator, as well as the right delta function. I needed to generate these things on the fly. Hey! We’re already generating the binarySearch function on the fly as a factory, we can just have that accept a closenessFactory as well!</p><p>Okay, geez. What would that look like? Probably like this, I guess:</p><pre>const generateBinarySearch = (comparator, closenessFactory) =&gt; {<br>  const closenessFunction = closenessFactory(comparator)<br>  return (array, value, options) =&gt; {<br>    // implement binarySearch as normal, except we&#39;ll have this:<br>     if (endIdx &lt; startIdx) {<br>      return checkCloseness(array, value, options);<br>    }<br>  }<br>}</pre><p>This can then be wrappered up to use our closenessDispatch:</p><pre>generateBinarySearchWithDispatch = (comparator, closenessKey) =&gt; {<br>  const closenessFunction = closenessDispatch[closenessKey]<br>  return generateBinarySearch(comparator, closeness)<br>}</pre><p>Wait. That doesn’t work. The closenessDispatch is returning a closeness <em>function, </em>but what we actually want is a closeness <em>factory</em>. Well, we can change that too. It’d be something like this:</p><pre>// I&#39;ll just do one function for demonstration purposes.<br>export function checkClosenessBeforeFactory = (comparator) =&gt; (<br>  array,<br>  value,<br>  { endIdx} = {}<br>) {<br>  return endIdx &gt;= 0 &amp;&amp; comparator(array[endIdx], value) === -1 ? endIdx : -1;<br>}<br><br>//And then we put that into the closenessDispatch:<br>closenessDispatch.BEFORE = checkClosenessBeforeFactory<br><br>generateBinarySearchWithDispatch = (comparator, closenessKey) =&gt; {<br>  const closenessFactory = closenessDispatch[closenessKey]<br>  return generateBinarySearch(comparator, closenessFactory)<br>}</pre><p>Now we’re cooking! This’ll actually work. But it still wasn’t sitting right — the binarySearch still intimately understands closeness. We can work with that though! since we’re only creating binarySearch via a factory, we can separate out into two things in the factory:</p><pre>const generateBinarySearch = comparator, closenessFactory) =&gt; {<br>  const closenessFunction = closenessFactory(comparator)<br><br>  const binarySearch = (array, value) =&gt; {<br>    // hardwire in comparator here as a closure<br>    // ...<br>    // implement binarySearch as normal, except we&#39;ll have this:<br>    // foundIdx is the index we found our value at. In this case, we didn&#39;t<br>    // find it, so it&#39;s -1.<br>    // we need to return the startIdx and endIdx so we can hand those through<br>    // to the closeness function, which isn&#39;t otherwise getting its options.<br>    if (endIdx &lt; startIdx) {<br>      return {foundIdx : -1, endIdx, startIdx}<br>    }<br>    // and also when we do the midPoint comparison:<br>    // and here we DID find the value, so we return the midPoint.<br>    if (comparison === 0) {<br>      return { foundIdx : midPoint, startIdx, endIdx}<br>    }<br>    // ... finish implementation<br>  }<br><br>  // cool! Now return a function that does the work<br>  return (array, value, options) =&gt; {<br>    // find our item<br>    const searchResults = binarySearch(array, value, options)<br><br>    return closeness(searchResults)<br>  }<br><br>}<br><br>// oh! And we&#39;ll need to change our equality function to return the foundIdx.<br>// this will now either be the appropriate index or a -1. We don&#39;t always just<br>// return -1 any more.<br><br>const checkClosenessEquality = ({ foundIdx}) =&gt; foundIdx</pre><p>Of course, there’s another gotcha — and that’s the delta function. We don’t just have a checkClosenessClosest function, we now have a checkClosenessClosestFactory function. And our checkCloseness function didn’t care about the comparator anyway, but it does care about the delta function. Well. Fine. We can fix this with a checkClosenessClosestFactoryFactory function.</p><pre>//This is a function which takes a delta function as an argument.<br>// it then takes a factory function which actually accepts no arguments<br>// that factory function, in turn, then generates our closeness function.<br>const checkClosenessClosestFactoryFactory = (delta) =&gt; () =&gt; (<br>  array,<br>  value,<br>  { startIdx, endIdx } = {}<br>) {<br>  if (endIdx &lt; 0 || startIdx &gt;= array.length) {<br>    return -1;<br>  }<br>  const startDelta = delta(array[endIdx], value);<br>  const endDelta = delta(array[startIdx], value);<br>  // if the two values are equal, CLOSEST will prefer the preceding value.<br>  return startDelta &lt; endDelta ? endIdx : startIdx;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O5BLUPNp1CipcGCPC897zQ.png" /><figcaption>I asked MidJourney for a stack of factories.</figcaption></figure><p>So, with our new implementation, to get a simple binarySearch , all we need to do is this:</p><pre>const binarySearch = getBinarySearch(numericComparator, closenessEqualityFactory)<br><br>const result = binarySearch(array, value)<br><br>//If you want to then search and return the closest index, you&#39;d do this:<br><br>const closestFactory = checkClosenessClosestFactoryFactory(deltaFunction)<br>const binarySearchClosest = getBinarySearch(numericComparator, closestFactory)<br>const closestResult = binarySearch(array, value)</pre><p>There’s a nuisance here in that you can’t just had in a param to the binarySearch to determine the results you want to get like in the original form, and you need to re-generate the functions. But that’s only 4 separate functions per comparator type, and let’s say you have 3 data types (because <em>I do</em>: strings, integers, and dates), so that’s just 12 functions.</p><h3><strong>There’s a word for this kind of architecture.</strong></h3><p>It’s “stupid”.</p><p>This was all crazy. I’m expected to be constantly generating and regenerating functions? I need to build at least 12 different functions just in case I want to access them? And I need what…some sort of external functional dispatch so I can determine which function to use based upon whether I’m looking for an exact match or the closest one before? I thought I was supposed to be making my life easier here?</p><p>In the first rev I could just hand in a fresh argument. I longed for those days.</p><p>What’s the point of building some idealized abstract version of an interface if it’s complicated and awful to use? This sort of implementation would make me sad to use.</p><h3>And there isn’t even enough context provided</h3><p>I finally realized that there’s an underlying flaw in the implementation — and that’s in how it returns the data. Let’s look at an example:</p><pre>const binarySearch = getBinarySearch(numericComparator, beforeClosenessFactory)<br><br>const result = binarySearch([1,3,6], 3)<br>// result is 1<br><br>const result = binarySearch([1,3,6], 4)<br>// result is -also- 1</pre><p>These are straightforward calls that hopefully emphasize the point — with any of these closeness functions other than the default equality check, we don’t actually <em>know</em> if the value is in the array at all. What if you <em>need</em> that information? It ain’t captured here.</p><p>Which means you’d be doing something like doing the search, then checking to see if array[result] === value as a next step to find out if it’s <em>really</em> there anyway. My whole initial use case was that if the element wasn’t in the array, I wanted to fallback to the <em>previous </em>element in the array and use that instead. Not have to do extra checks.</p><p>Plus, that extra check is conditional. You need to do it if you’re using the before closeness, but <em>not</em> the equality closeness. equality always returns the element index or -1 . The other ones you’d need to check. I mean, I guess you <em>can</em> check with the equality value but it’s unnecessary.</p><h3>The Pretty Solid Version</h3><p>I went back to the drawing board. Factory functions taking factories (which may be factory factories) to generate functions to do searches that don’t even return all of the data I need anyway? There’s gotta be a better way!</p><p>I thought about what closeness means and what it <em>could</em> mean. Sure, the user could pass in different functions with different parameters, but they’re all going to end up caring about one of three values:</p><ol><li>The index the element was found at.</li><li>The index before where the element would be found (the next index may or may not be the index of the actual element, depending upon whether it’s there or not)</li><li>The index after where the element would be found.</li></ol><p>At the end of the day, the various different closeness functions were just performing some pretty low impact checks. Usually, at least. before and after would just do another comparison, and closest would do two distance calculations. That’s not too expensive. Could I just…always do them?</p><p>I mean, what if I scrapped this whole concept of closeness entirely. What if instead of handing back a single value, I handed back an object with all of these indexes?</p><p>Then the consuming programmer could choose whatever to do with them — access the index of the value you need. If you want to wrap that up into some convenience function to just give you that value, that’s easy too.</p><p>You’d still use a factory to get the binary search function you need with the right comparator, but you could just hand in the comparator which’ll just be used everywhere. Give it an optional delta function and you can calculate closest as well.</p><p>Let’s wrap it all up into the final version.</p><pre>// our factory will take one of our comparators and a delta function<br>export function getBinarySearchWithComparator(comparator, delta) {<br>  // we&#39;ll return a function that takes an array, value to search for<br>  // and options, as before.<br>  return (array = [], value, options = {}) =&gt; {<br>    // internally, we&#39;ll generate a new binarySearch on the fly as a closure<br>    // with the comparator wired in. The only options we care about are the<br>    // startIdx and endIdx.<br>    // otherwise, this function proceeds as before.<br>    const binarySearchWithIndexes = (<br>      array,<br>      value,<br>      { startIdx = 0, endIdx = array.length - 1 } = options<br>    ) =&gt; {<br>      if (endIdx &lt; startIdx) {<br>        // when we return out, hand along the index our value was found<br>        // at, as well as the index before and after. For the not found<br>        // case, return a -1. For the found case below, return the midpoint<br>        return {<br>          foundIdx: -1,<br>          beforeIdx: endIdx,<br>          afterIdx: startIdx,<br>        };<br>      }<br><br>      // this also fixes another theoretical bug where startIdx + endIdx<br>      // is greater than the max possible number. But you can study that<br>      // on your own.<br>      const midPoint = startIdx + Math.floor((endIdx - startIdx) / 2);<br><br>      const comparison = comparator(value, array[midPoint]);<br><br>      if (comparison === 0) {<br>        return {<br>          foundIdx: midPoint,<br>          // we don&#39;t want to use the startIdx/endIdx here as before/after,<br>          // because those could be far away in the array. One off is perfect.<br>          // We need to bounds check for the cases of short arrays<br>          beforeIdx: Math.max(0, midPoint - 1),<br>          afterIdx: Math.min(array.length - 1, midPoint + 1),<br>        };<br>      } else if (comparison &lt; 0) {<br>        return binarySearchWithIndexes(array, value, {<br>          startIdx: startIdx,<br>          endIdx: midPoint - 1,<br>        });<br>      } else if (comparison &gt; 0) {<br>        return binarySearchWithIndexes(array, value, {<br>          startIdx: midPoint + 1,<br>          endIdx: endIdx,<br>        });<br>      }<br><br>      throw new Error(`Could not binary search: comparison is NaN`);<br>    };<br><br>    // do our binary search to find our proposed found/before/after indexes<br>    const result = binarySearchWithIndexes(array, value);<br><br>    const { foundIdx } = result;<br><br>    // it&#39;s possible the comparator is expensive. Allow the user to bow out<br>    // by handing in a flag to only get the foundIdx w/o further calculations.<br>    if (options.foundIdxOnly) {<br>      return foundIdx;<br>    } else {<br>      // okay in here, the fun begins. We&#39;re going to calculate the before/end/closest indexes.<br><br>      let closestIdx = undefined;<br><br>      if (delta) {<br>        const beforeDelta = delta(array[result.beforeIdx], value);<br>        const afterDelta = delta(array[result.afterIdx], value);<br><br>        // if the two values are equal, CLOSEST will prefer the preceding value.<br>        if (!Number.isNaN(beforeDelta) &amp;&amp; !Number.isNaN(afterDelta)) {<br>          closestIdx =<br>            beforeDelta &lt; afterDelta ? result.beforeIdx : result.afterIdx;<br>        }<br>      }<br><br>      const beforeIdx =<br>        comparator(array[result.beforeIdx], value) === -1<br>          ? result.beforeIdx<br>          : -1;<br><br>      const afterIdx =<br>        comparator(array[result.afterIdx], value) === 1 ? result.afterIdx : -1;<br><br>      return {<br>        foundIdx,<br>        beforeIdx,<br>        afterIdx,<br>        closestIdx,<br>        foundOrBeforeIdx: foundIdx &gt;= 0 ? foundIdx : beforeIdx,<br>        foundOrAfterIdx: foundIdx &gt;= 0 ? foundIdx : afterIdx,<br>      };<br>    }<br>  };<br>}<br><br>export const numericBinarySearch = getBinarySearchWithComparator(<br>  numericComparator,<br>  (a, b) =&gt; Math.abs(b - a)<br>);<br><br>export const stringBinarySearch = getBinarySearchWithComparator(<br>  stringComparator<br>);<br><br>export const dateBinarySearch = getBinarySearchWithComparator(<br>  dateComparator,<br>  deltaDays<br>);</pre><p>And we’re done. You can see that I export out 3 useful functions for myself — to do a binarySearch on numbers, strings, or dates. And I don’t need to change any values I’m handing in or deal with factories to get different values, I just index into the resulting object differently.</p><p>You can see if the value was found by looking to foundIdx . If you explicitly want the index prior, beforeIdx is there. If, like me, you want the index of the value <em>if </em>it is found and the before index <em>if</em> it is not, then foundOrBeforeIdx has you covered. Basically, I can do one single call again, without a lot of setup, and get back all of the data I need.</p><p>Plus, stuff is still super easy to change for needs. Just do it by wrapping the function instead of handing in factories to a god function:</p><pre>const numericBinarySearchBeforeIdx =<br>  (...args) =&gt; numericBinarySearch(...args).beforeIdx<br><br>const numericBinarySearchLeftSideOfArray =<br>  (array, value, options) =&gt; array.slice(0, numericBinarySearch(array, value, options).beforeIdx)</pre><p>And ta da. We’re done. A reasonable interface, easy to use, gives me way more information than a standard binary search. And it only required using up almost all of my free time for a week.</p><p>Maybe I’ll stick this onto npm when I’m done.</p><p>Anyway, I suppose I should add some takeaways:</p><ul><li>Don’t ignore code smells. If a function doesn’t feel right, it probably isn’t.</li><li>Mind your interfaces. If your code is arbitrarily extensible and changeable, but it sucks to do it, then it’s a failure and needs to be re-worked.</li><li>Keep going until you get it right. Sometimes your next version is better. Sometimes it’s worse. But even if your next version doesn’t solve your issues as well as you’d hoped, it’ll still teach you something to put towards your next next version. Don’t give up and go back to the smelly code, you’ll regret it later.</li></ul><h3>Update after deployment</h3><p>I never updated this story, which I really should have.</p><p>Literally <em>three days after I finished all of this</em>, I needed it. All of those extra indexes? I needed 4 of them in my code. And I just…had them. It was ready to go, engineered, documented, robust. I didn’t need to try and shoehorn in any hacks, and I didn’t need to go back and spend the time to do it right. Plus, it vindicated doing it the right way to begin with.</p><p>Not that it always pays off to take the time to produce the super engineered solution in advance. But sometimes (hopefully usually!) your gut instincts pay off nicely.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7bfa6b75d50e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Everything is scarier because we’re lonelier]]></title>
            <link>https://medium.com/@thomasoniii/everything-is-scarier-because-were-lonelier-14ef1954715a?source=rss-72a47e2393d5------2</link>
            <guid isPermaLink="false">https://medium.com/p/14ef1954715a</guid>
            <category><![CDATA[attempts-at-friendliness]]></category>
            <category><![CDATA[loneliness]]></category>
            <category><![CDATA[neighborhoods]]></category>
            <category><![CDATA[neighbors]]></category>
            <dc:creator><![CDATA[Jim Thomason]]></dc:creator>
            <pubDate>Tue, 31 Oct 2023 00:43:43 GMT</pubDate>
            <atom:updated>2023-10-31T00:43:43.462Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AJHDJBnrXx8Aqx5qAgTCdQ.png" /><figcaption>I asked Midjourney for a scary neighborhood</figcaption></figure><p>My wife and I went to the drive-in two nights ago. I <em>love</em> the drive-in. We hadn’t been this year since I had a busy summer and the selection didn’t jump out at me, but I really do try to go a lot. My parents took my sister and I to the local one when we were kids and I really enjoyed it, so I’ve started attending regularly as an adult.</p><p>On the way home, my wife was fooling around on her phone and found a whole bunch of breathless Facebook posts about an out of control party in our neighborhood. Drunk teenagers stumbling around, cops being called (or they weren’t called. Or maybe somebody <em>should</em> call them?). Way too loud. Too many houses involved. Kids running down the streets. Roving groups heading for one of the local parks. Mass hysteria.</p><p>It sounded like the party was on the opposite end of our neighborhood and I was assuming it wouldn’t spill down close to our house, even if teenagers were truly running amuk. I was reasonably content. At the same time, after we got home, two cars came cruising down our street. They turned around at the end, someone got out of one car, ran to the other, and ran back to the first. Then they drove off. It was <em>weird</em>.</p><p>There have been a few incidents of weird and/or unneighborly behavior off and on for a few years. We’ve always had ongoing issues with cars being rifled through. No cars actually broken into, mind you. But if you leave your doors unlocked, somebody’s going to take anything from it that’s not nailed down. That kinda sucks. I mean, yeah, you should just lock your doors. But you also shouldn’t <em>have</em> to. So I’m slightly sympathetic with the people that say they shouldn’t have to lock anything. At the same time, just, lock your doors.</p><p>And I had a political sign stolen from my yard in 2020. There’s been some minor vandalism in the neighborhood. People don’t always pick up after their dogs. There are definitely some people around here that come across as assholes at worst and sketchy at best. It makes me kinda nervous sometimes. You know the drill — is the neighborhood getting dangerous? Should I move out while I still can? Are we safe here?</p><p>But, of course, where would I go? All neighborhoods can have these issues. Some sort of gated community with a high entrance fee? Paying extra for on-site security that’s going to run off The Others if they show up? Dense urban areas with ready police presence or middle-of-nowhere where you’re on your own but likely to be left alone? Everything has problems, but I think everything really has the <em>same</em> problem.</p><h3>I don’t know any of my neighbors.</h3><p>That’s it. That’s the issue. I think that’s <em>everyone’s</em> issue.</p><p>I know that I essentially have my own castle unto myself. I have my house and my yard and my Important Things in it, but I basically just do everything on my own with my family. I know a few of my neighbors by name and by sight, and we wave and exchange small pleasantries from time to time. But I don’t really <em>know</em> any of them. I’ve never really known any of my neighbors since I was an adult.</p><p>I knew more neighbors when I was a kid. People in nearby houses or a few streets down. Mostly my parents knew them. My mom was very sociable, and my dad to a slightly lesser degree. And they came from a different era when it was important to know people and they put in the effort to do it, even if the people they were doing it with didn’t always do the same. The neighbors would participate, if not necessarily reciprocate.</p><p>And I’d go out and play and find neighborhood kids and get invited into their homes and meet their parents. And then my mom would invite them over and we’d have occasional dinners in the evenings where the grownups would talk and the kids would play. Varying degrees over the years as friendships waxed and waned, but it was always there.</p><p>There was a lot of safety in that. For a number of years, we lived in a city without any family or friends. My dad got transferred some place cheaper for the company, so we were on our own. But because of my mom, we were never isolated. It never really felt like we were on our own. Not like I do now.</p><p>Just think about the amount of security you get from knowing your neighbors. Having people in the neighborhood that’d be watching for mischief or keeping an eye on your house for a burglar or a fire. Knowing who your kids are and where they should be. Being aware of a neighborhood party that’s getting out of control and keeping an eye on things.</p><p>I have to assume that just about more than anything, <em>that’s </em>the thing that’s missing when people talk about the good old days. Don’t get me wrong — the economic security would be pretty awesome. But forget all the racism and sexism and homophobia. I’d be far more concerned about my neighbors not being assholes than anything else about them. And if I were to assume I don’t want to associate with someone just because of how they look and not how they act then that’s a poorer reflection of me than them.</p><p>So what do I do? I dunno. I’m a quiet introverted person. I’ve never been great at making friends quickly, and I tend to be more someone that finds some common interest and hyper focuses on it. That’s tough to do starting from nothing with someone you only know due to geography.</p><p>But I can at least acknowledge the concept of <em>wanting </em>to be more sociable and acknowledging the safety and security and general feeling of well being from just knowing the people around you. You’re no longer an island unto yourself, facing the scary world alone. You’re part of a community with common members.</p><p>I think it’d do us all a lot of good to remember that and work towards it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=14ef1954715a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A lack of free will can make you immortal]]></title>
            <link>https://medium.com/@thomasoniii/a-lack-of-free-will-can-make-you-immortal-0109291dcc53?source=rss-72a47e2393d5------2</link>
            <guid isPermaLink="false">https://medium.com/p/0109291dcc53</guid>
            <category><![CDATA[immortality]]></category>
            <category><![CDATA[free-will]]></category>
            <category><![CDATA[nonsense]]></category>
            <category><![CDATA[philosophy]]></category>
            <category><![CDATA[life-after-death]]></category>
            <dc:creator><![CDATA[Jim Thomason]]></dc:creator>
            <pubDate>Fri, 20 Oct 2023 16:04:29 GMT</pubDate>
            <atom:updated>2023-10-20T16:04:29.558Z</atom:updated>
            <content:encoded><![CDATA[<p>Please allow me to wax philosophical.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QKgdb1KTKe9uFaU_y377Hw.png" /><figcaption>I asked Midjourney to imagine “Free Will”</figcaption></figure><p>I read an article today in the LA Times about Robert Sapolsky, who has concluded that free will is an illusion.</p><p><a href="https://www.latimes.com/science/story/2023-10-17/stanford-scientist-robert-sapolskys-decades-of-study-led-him-to-conclude-we-dont-have-free-will-determined-book">Stanford scientist, after decades of study, concludes: We don&#39;t have free will</a></p><p>This kind of claim pops up from time to time — rarely with such a definitive conclusion, but certainly as a topic of conversation. It’s been debated since time immemorial. The question is really simple:</p><ul><li>Am I actually making my own choices?</li><li>Or am I merely a machine that is responding in the only way possible to the billions of years of history that have culminated in this instant when I “make” my decision?</li></ul><p>This stresses a lot of people out.</p><p>There’s always push back — “I do make my own choices!” “I think on my own!” “Of course I have free will!” But at the root of it, it’d be very difficult to be completely sure. Maybe the chemicals swirling in our brains are going to respond in exactly the same way because that’s what all of the prior inputs have forced upon us.</p><blockquote>“Aha!” You exclaim. “But I just changed my mind at the last moment, thus proving free will!”</blockquote><p>Well, yes, but no. Since your “changing” your mind at the last moment was actually pre-ordained and it’s just you experiencing the illusion again.</p><p>Truthfully, at the end of the day it doesn’t really matter — if we can’t discern whether we actually have free will, then the effect is the same. We continue to operate our lives as we were doing before. We either make our choices or merely appear to, but the results are the same so it really doesn’t matter.</p><p>Most people prefer to assume that they <em>have</em> free will since it’s more comforting. But what if there were advantages to <em>not</em> having free will?</p><p>I’m not a religious person. I never have been. I just don’t buy it. This isn’t necessarily to claim that I <em>completely</em> discount the possibility of there being something beyond our existence, just that I’m <em>really certain</em> that any of the nonsense I’ve heard in the past doesn’t cover it. And this isn’t to say that I’m not petrified of death. Just like everyone else, it scares the bejesus out of me. And I try to make my peace with the concept of my own demise or that of my loved ones, but damn it isn’t easy. And I’d be lying if I’d say I was ever completely fine with it. I think the vast majority of people that claim they’re totally fine with it are lying too. It’s cool—whatever you need to get through the day. I’m not going to judge.</p><p>Religion, of course, helps with this because most of them promise some eternal reward (or punishment, if you’re so inclined) waiting for you after we shuffle off our mortal coil. Reuniting with loved ones or pets or meeting The Divine. All to comfort us as our candles are snuffed. Totally fine, I get it. But here’s the cool part — we don’t actually <em>need</em> a pantheon of gods to save us and give eternal life. We could do it ourselves. <em>Especially</em> if we don’t have free will.</p><p>So, how does not thinking for ourselves let us live forever?</p><p>Well, cloning technology is advancing pretty rapidly and is super cool. We’re not doing it on people yet for very valid ethical reasons. But let’s say that at some point in the future we get that straightened out and squared away fairly and actually perfect human cloning technology. And this is the “grown in a vat from a strand of DNA” cloning, not the “Star Trek transporter malfunction duplication” cloning. Meaning, you can end up with a perfect bodily duplicate, but no brain or memories.</p><p>With sufficiently advanced cloning and sufficiently undamaged DNA, you can even use this to bring back the dead. But it’s incomplete. All we’re getting is an empty body of the deceased person but none of their memories or life experiences. You end up with essentially a beautiful corpse.</p><p>Or you let this cloned person grow and develop normally and naturally, but they won’t ever become the person you once were, because they’re living a completely different life and experiencing completely different things.</p><p>But. What if we could take that clone and give it the exact same life experience that the original had?</p><p>This is where that scary sounding lack of free will comes to our advantage.</p><p>Imagine that in the distant future, humanity builds a computer. A gigantic, fabulous, incredible super computer capable of simulating…well, ideally the entire universe. But that’s not going to be quite practical. If we could do our entire galaxy, then perfect. If not, we can probably get by with our solar system.</p><p>A fabulous machine that we feed in the precise starting conditions (at least as best as we can determine) of our solar system and then just…let it run.</p><p>Eventually, over time, this simulation will cool and coalesce the Earth, life will emerge, dinosaurs will evolve and be wiped out, there will be ice ages, rodents, monkeys, people, the pyramids, the Roman Empire, the crusades, the industrial revolution, first powered flight, walking on the moon, and eventually, you sitting right there reading this article as you are now. Or me writing this article as I am right now.</p><p>Without a true free will, we can guarantee that with our identical starting conditions that we’ve created an identical outcome. It’s just we’re all in a simulation replaying what “actually” happened in the “real” universe whoever knows how long ago. We’ve now created an absolute flawless copy of you or your loved one or your beloved pet.</p><p>Next: We let them die in the simulation.</p><p>You might be thinking that’s a cruel thing to do. We could yoink the data out of their brains out at any time and encode it into a new cloned body in the real world, so why go through all the pain? Why force someone with a disease to relive it? Why require a murder victim to go through it again? Unfortunately, it’s a requirement for everyone else. We can’t interfere with the simulation, because to do so would be to affect the simulation and change the results of everything after that. <a href="https://en.wikipedia.org/wiki/Butterfly_effect">The Butterfly Effect</a> screwing everything up.</p><p>But it’s okay! Because once they’re gone, we have a complete record of their whole life as it was to completion. And it’s not affecting anything else anymore. So <em>now</em> we take out that copy, download it into a fresh clone, wake them up and here we are. Now you get an entire additional life to live.</p><p>With “real” free will, this doesn’t work. The simulation can go bonkers all over the map as every person in history can make different decisions and we don’t end up with the exact same events that made you You. But with the illusion of free will, we can extract your copy.</p><p>Here’s the best part — this works for <em>everyone</em>. In the far distant future when we have created such a machine, the people alive wouldn’t actually need it. They already have advanced cloning and the ability to transfer minds, so they can keep themselves going very effectively without worry of death. Yes, there’s always the issue of unexpected death, but you can keep a backup copy of yourself periodically to restore as needed. Or just keep the simulation running alongside the real world to extract a copy if that’s preferrable.</p><p>The point is, those people were fine anyway. Reasonably immortal. All the rest of us are stuck. Except…this fabulous simulation is also perfectly recreating all of our DNA, which was a precursor step to recreating Us. So it provides the opportunity to pull out your DNA, build you a new body, then download your entire mind into it. We wouldn’t need such a fabulous computer to exist <em>today</em> to make use of it. All we need to do is keep from destroying ourselves before such a thing is created. Because once it exists, we can all be pulled out of it.</p><p>I’ll end on one more philosophical conundrum — some of you will protest and say that it isn’t “You” that emerges from the flawless simulation, it’s merely a copy of you. We can deal with that in at least two ways.</p><p>First of all, there’s also the prospect that maybe “You” isn’t actually “You” already. We go to sleep, after all. We lose consciousness and there’s a disconnect. Maybe, at some level, whoever we were yesterday “dies” and completely disappears at the end of the day, and we “wake up” today as a newly disconnected being with merely the <em>memories</em> of being alive yesterday. Creepy, huh?</p><p>But if we can reasonably convince ourselves that we’re still connected to ourselves in days past, then we should be able to reasonably convince ourselves in the future that we’re connected to the “original”.</p><p>And here’s the last, best part to consider — we might already be in this simulation right now. This fabulous computer could be recreating an old universe long since gone, rebuilding all of us to be copies and information to be extracted out upon our own death in this machine. From that perspective, it most certainly is <em>us</em> that wake up in the outside world when we’re done.</p><p>Personally, I’ll definitely take the risk of not “really” having free will if it translates into me (and everyone I care about) being around forever.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0109291dcc53" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Let’s learn about Addison’s Disease]]></title>
            <link>https://medium.com/@thomasoniii/lets-learn-about-addison-s-disease-dd864d95b1f0?source=rss-72a47e2393d5------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd864d95b1f0</guid>
            <category><![CDATA[basset-hound]]></category>
            <category><![CDATA[storytelling]]></category>
            <category><![CDATA[dogs]]></category>
            <category><![CDATA[addisons-disease]]></category>
            <category><![CDATA[veterinary]]></category>
            <dc:creator><![CDATA[Jim Thomason]]></dc:creator>
            <pubDate>Mon, 21 Aug 2023 17:59:27 GMT</pubDate>
            <atom:updated>2023-08-22T12:12:10.863Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uUc5PI9-GN7JFT3ubK8ZXA.jpeg" /></figure><p>This is Poppy. He is a basset hound, and just the bestest dog around.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ewIq5R397xPnGDnK07buJA.jpeg" /></figure><p>We adopted him and his girlfriend Daisy last year. I’ve always had basset hounds, and after losing my last pair in 2021 we were finally ready for more. I contacted the local basset rescue and asked for a social one, since I’d eventually like to have two. I figured we’d get one, get them adjusted, then see about a second in a few months. Instead they called back a week later and said they just had a bonded pair come in and asked if I’d be willing to take two immediately. Since we were only spacing them out for the dogs’ benefit, there was no worries if they were pre-bonded. It’s been a good year!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*anJZsaBN3jCE1_CjLmSS1Q.jpeg" /></figure><p>Up until this past Wednesday when things took a turn.</p><p>I work from home, so I’m with the dogs all day. Poppy was fine all day Wednesday. I went out late afternoon. My wife sent me a few text later saying that he was lethargic and didn’t want to eat his dinner. He was instead laying down next to the dish.</p><p>Some interest in his food from Daisy encouraged him to eat it, but he soon threw it back up. Then he threw up four more times. I came home quickly to take him to our local vet ER.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GlzNzAtbsN1W2w_sPhJwmQ.jpeg" /><figcaption>“He’s lethargic? He’s a basset hound. How can you tell?”</figcaption></figure><p>You can tell. You can always tell when your pets are off. And he was <em>really</em> off.</p><p>The ER was too busy, but they suggested a local urgent care that had opened up the week prior. I was able to get in there quickly. Our initial speculation was that he’d gotten a pill that had been dropped. It mostly fit the symptoms — lethargy, vomiting. The did bloodwork and x-rays and found no blockages. They gave him an anti-nausea injection and some subcutaneous fluids and sent us home. With instructions to monitor him closely and come back in if there was any decrease in his condition.</p><p>I slept downstairs with him and it was an uneventful night.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*HIPhjlsmhwlcbGRv9r4vmQ.jpeg" /></figure><p>The next morning he was still mopey and had a bout of absolutely explosive diarrhea. Pure reddish brown liquid that poured out of him like lava. Like way more than you’d expect to see a dog be able to hold. Wow.</p><p>But at this point, is this just toxicity and him dealing with it? Something worse? We kept a close eye on him. He was getting more lethargic and had another explosive bout in one of the back bedrooms. I pray that you, gentle readers, never have to experience what that stuff smelled like.</p><p>Back to urgent care I go. This is now late morning on Thursday.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o-yWI3olnxx8XQ8XCCUk1w.png" /></figure><p>The vet immediately said that this no longer fit toxicity from the possible single pill he might have gotten and said it’s Acute Hemorrhagic Gastritis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*NfzzEGx9isc0PJCHsBgziw.jpeg" /></figure><p>I don’t know about you all, but that sure sounded really extremely bad to me. I’m not a doctor, though.</p><p>It basically meant that the entire length of his intestines were bleeding. This had several impacts — massive amounts of bloody diarrhea, which was leading to severe dehydration with low blood pressure and tachycardia, as well as the bleeding potentially opening avenue for gut bacteria to get into his bloodstream and cause sepsis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*zdvcLj4o2N6lJXReT9w1hA.jpeg" /></figure><p>Acute hemorrhagic gastritis is more of a symptom than a cause. Any number of things could cause it. Could be bacterial, some sort of injury, weird result from the pill ingestion, addison’s disease. Not sure. Plan was to keep him for the day and give him fluids and antibiotics and see how he does. All goes well, then he comes home later that day.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nd0yh7MiMYhAiOqdahLI0g.jpeg" /><figcaption>Then he could tell Daisy about his exciting adventure at the vet.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*Qe_U4RBY00Y9Wx8Gzwkjkw.jpeg" /></figure><p>The vet called me back about two hours later and said he’s shown no improvement and I need to move him to a veterinary ER. Okay, I say, so head down there now and get him?</p><p>He says “Nope. He’s not stable enough to transfer right now. We need to work on him for a while to try and stabilize him enough to move him.”</p><p>Holy. Shit. He’d walked into the vet the day before. That morning I had to carry him because he didn’t want to move. And now he wasn’t even stable enough to transport? He said he’d call me back around 5 and we’d see where we’re at. I just went down there a little before 5 so I’d be ready to go if necessary.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZzDZrYguLR_hVuii13idaw.jpeg" /><figcaption>Poppy in urgent care when I came to visit</figcaption></figure><p>He didn’t so much as look up when I came in and I doubt he knew I was there. I sat with him a bit as the vet talked. He said he’s pretty confident it’s Addison’s disease, but they don’t have the equipment to test for it. Regardless, he needs round the clock emergency care that they can’t provide, and he’s arranged for me to transfer him into one of the higher grade vet hospitals about 30 minutes away. They were going to give him a steroid shot and off I went.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/561/1*cKxDMhTdEnr14kBWxP2Dbg.jpeg" /></figure><p>I drove and drove and drove. Reached the point when I see signs for the exit. And that’s when the explosive diarrhea came back. Poor guy was covered in the stuff when I had to carry him into the hospital, wiping both of us up as well as I could first. They put him on a cart and wheeled him to the back. Then I got to wait for an hour before talking to someone about plans and then go to the back to say good night to him.</p><p>The vet there was very happy with the work the urgent care did, and said it’ll save them a ton of time and effort. He’s pretty confident it’s Addison’s Disease, and they’ll test for it to confirm. Poppy was in really bad shape, so the prognosis was guarded, but most dogs still tend to respond well to treatment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*NfzzEGx9isc0PJCHsBgziw.jpeg" /></figure><p>Addison’s Disease (<a href="https://en.wikipedia.org/wiki/Addison%27s_disease">https://en.wikipedia.org/wiki/Addison%27s_disease</a>) is an endocrine disorder where your adrenal glands don’t work. Your body doesn’t produce enough cortisol or aldosterone and that’s super bad.</p><p>Now, you may have read some of the breathless posts on the internet about reducing your cortisol or your stress or about how bad it is. But that’s only true in extremis — our bodies still need cortisol, because that’s the hormone that starts to signal that something’s wrong and your body’s defenses need to wake up.</p><p>In Poppy’s case, whatever stressing event happened and his body wigged out. But it didn’t produce cortisol that it needed to properly respond. So things went haywire. Hemorrhage. Bacterial overgrowth. Explosive diarrhea. Here we are.</p><p>This is an Addisonian crisis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*qXKmKUZlKQZ20lYRQvao0g.jpeg" /></figure><p>An Addisonian Crisis (<a href="https://en.wikipedia.org/wiki/Adrenal_crisis">https://en.wikipedia.org/wiki/Adrenal_crisis</a>) is where most cases of Addison’s disease are initially diagnosed (at least in pets).</p><p>It is incredibly scary.</p><p>You have an otherwise healthy animal. This goes just fine until they are 2–5 years old, and then some sort of stressing event happens. It could be anything. Then the adrenal glands say, “Nope! Not today!” everything breaks, and your pet nearly dies.</p><p>Unfortunately, at this point your choices are your pet rapidly painfully shits itself to death or you spend an absolute fortune in emergency veterinary fees. We caught things quickly enough to have the option of the latter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/206/1*wRDBbvZGcogz97WRMhkELg.jpeg" /></figure><p>Addison’s is confirmed through an ACTH stimulation test (<a href="https://en.wikipedia.org/wiki/ACTH_stimulation_test">https://en.wikipedia.org/wiki/ACTH_stimulation_test</a>). Basically, they measure baseline coristol and then wait an hour. If your cortisol is at a normal looking level, you do not have Addison’s. The vet said the low number of normal on the scale was a 2.5 (I don’t know of what), and Poppy’s initial number was too low to be measured.</p><p>Then they inject a microgram of an ACTH drug which should stimulate cortisol production. If your cortisol spikes, you’re good. If it doesn’t, you have Addison’s. His cortisol didn’t budge, so he definitely has Addison’s.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*t4w4kIwVMfNjbXrST-aSUQ.jpeg" /></figure><p>Addisonian crises are extremely bad news requiring immediate serious medical attention.</p><p>But Addison’s itself isn’t terrible. Treatment is a daily steroid pill and a monthly injection and some increased monitoring at the vet. Every vet is different — some want you in 4x/year, some only want annually. Some let you give the injection at home if you’re comfortable, some make you come in for a tech visit. We’ll see what my vet says when I sync up with them on Monday.</p><p>This was all Thursday night. The vet said that he was worried about Poppy’s albumin being too low and that could cause other issues, so he asked if we could do a plasma transfer. His main concern was cost (It’s another $1,000), but mine was outcomes for the dog and I said I’d defer to what’s most beneficial. They started the transfer. Then we just need to wait and see.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0hFnezI57NWHNRVyR0KcAw.jpeg" /></figure><p>Also, everybody kept getting confused on the phone and saying “she” and “her”. We think the name threw them off.</p><p>Poppy is very very obviously a boy dog.</p><p>As a side shout out to my friends in the trans community, considering how annoyed I was getting on the phone when the vet was innocently misgendering my dog, I can’t even imagine how stressful it is being misgendered yourself by some asshat. But I digress.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*onvl7txDs7dUCsfaDRUlkA.jpeg" /></figure><p>Vet calls back Friday morning and he’s doing well! Responding to treatment, slightly more alert. Peeing everywhere (he’s been on a ton of fluids), didn’t want to eat yet. They’re happy with progress but are expecting to keep him another day or two. I say go for it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/955/1*meKeBRSBlNW6hWkCDimMig.jpeg" /></figure><p>Also, as a side note, my god was this expensive. And I don’t have pet insurance.</p><p>I’d had pet insurance about 10 years ago but I canceled it because it was worthless. I’d literally submit a claim for an $800 procedure and they’d reimburse me 73 cents. I sometimes got checks from them less than the cost of the stamp on the envelope.</p><p>So I opted to just put my premiums into a separate fund to save for dog medical expenses. Maybe pet insurance is better enough nowadays that I would’ve come out ahead by having it? Maybe a different provider would’ve been better? I dunno.</p><p>I’m not trying to make a statement on pet insurance, just saying that when I had it it sucked, so I don’t right now. And man this was a serious punch to the wallet.</p><p>So. No more doggy medical crises for a while, please.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*HIKq6iDLCKk3JaDBQ8pYVQ.gif" /></figure><p>We went to visit him Saturday night and he was basically back to his old self. Absolutely ecstatic to see my wife and I and bouncing around giving us kisses and happy whining. Hopping in our laps, and generally acting like our normal dog. Night and day difference from when I brought him in.</p><p>They said he didn’t need to stay over longer and we could take him home then.</p><p>The tech that had been tending to him came in the room to give us the discharge instructions and he ran over to give her a kiss. She commented on how great a dog he is.</p><p>We’ve got a few meds in the short term to finish stabilizing him, and then it’s follow up with our regular vet on Monday for a few short term follow up visits and then set everything up for the long term maintenance. But once he’s squared away from the crisis, it should just be the ongoing hormone replacement meds and he’s otherwise expected to lead a normal happy healthy hound dog life.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0Aa1XSe647Rbyow6HsWRtQ.jpeg" /><figcaption>The author and his dog upon returning home</figcaption></figure><p>Daisy was super excited to see him, which was cute since she’s normally more aloof. He’s absolutely devoted to her, and she tolerates him. But after a few days she obviously missed him too.</p><p>And now…we’re hopefully okay. He’s still not 100%, but he’s very happy at meal times and is taking all of his meds properly. Hopefully will be fully recovered in a few days and then it’s just maintenance in perpetuity to keep him squared away.</p><p>So to all of you pet owners out there — keep an eye on your animals. You’re going to know when something’s off.</p><p>I’m not going to say that you necessarily need to rush your dog off to the vet if they throw up once. But more than once? Or they’re vomiting and lethargic? Or there’s also diarrhea? Get them checked out.</p><p>We 100% would have lost him if he didn’t get treated, and it’s entirely likely we would have lost him even if he had been treated but we had delayed longer. And now it’s just a chronic maintenance issue that should have little-to-no impact, supposedly, as long as his meds are in place.</p><p>I’ll also say that it’s a relief that I was able to (barely) float the costs on this, since the prospect of losing a pet strictly due to expense is awful. Of course, now I also have the ongoing medical expenses for the meds, but that’s for another day.</p><p>I hope this was useful info and gives you some important things to watch for in your pets, as well as some comfort that even if this pops up, it’s usually treatable (if done promptly) and then manageable over the long term.</p><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd864d95b1f0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Save money with an anti-budget]]></title>
            <link>https://medium.com/@thomasoniii/save-money-with-an-anti-budget-aebb405c8dd2?source=rss-72a47e2393d5------2</link>
            <guid isPermaLink="false">https://medium.com/p/aebb405c8dd2</guid>
            <category><![CDATA[budget]]></category>
            <category><![CDATA[financial-planning]]></category>
            <category><![CDATA[saving]]></category>
            <category><![CDATA[financial-freedom]]></category>
            <category><![CDATA[savings-tips]]></category>
            <dc:creator><![CDATA[Jim Thomason]]></dc:creator>
            <pubDate>Thu, 10 Aug 2023 13:19:10 GMT</pubDate>
            <atom:updated>2023-08-10T13:19:10.617Z</atom:updated>
            <content:encoded><![CDATA[<p>This has got to be the weirdest <em>one little trick </em>that I’ve ever come up with to save money.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GJek6QKHTHpLDXDZJkYD-w.png" /><figcaption>via midjourney</figcaption></figure><p>First of all, about me — I love budgeting. I write financial planning software <em>for fun</em>. I’ve got budgets and projections and planning out the wazoo. I know how long it’ll take to pay off my debts, how I’m paying for my groceries this week, and am confident I have cash on hand for the electric bill.</p><p>I do all of this with some fancy software that basically lets me simulate the <a href="https://en.wikipedia.org/wiki/Envelope_system">envelope system</a>. For those of you unfamiliar, it’s super simple — you get all of your money in cash, and then you put the cash into labeled envelopes. “Mortgage”, “Car”, “Dinners out”, “Utilities”, whatever. Then, when the bills come due, you take money out of that envelope to pay them. Out of money? Well, then you’re SOL. No going out to dinner any more until it’s replenished. Or you’re very clearly moving money from one envelope to the other, so it’s obvious how you’re paying it.</p><p>As I said, I do it all in software — I virtually segment my checking account into all the envelopes so I know exactly what’s where. And it works <em>great. </em>I’ve been doing this for more than a decade and never have any problems with cash flow. Well, or I guess at a minimum I <em>know</em> if I’m going to have a problem with cash flow before it becomes a <em>real</em> problem and I can shuffle things between envelopes to compensate.</p><p>One thing I’ve never been <em>super</em> great about is discretionary spending. The stuff I don’t <em>need</em>, but merely <em>want</em>. Because of the way the app works, any money that’s unallocated in some manner is made available for debt repayment. i.e., I over pay on my debts with the money I’m not otherwise doing anything with. And any miscellaneous extra spending comes out of there. It’s basically transparent — I’ll just pay a little less to my credit card this month because I bought a new toy on Amazon or whatever. I’m still pretty well behaved, but it’s not perfect.</p><p>Recently, I decided that I did <em>not</em> want to overpay on my mortgage. I’m locked in at a great rate and I can make more money investing the overage elsewhere. And it’s helped me build up a great emergency fund, which is super important. If I were to overpay my mortgage so it’s paid off faster, then lose my job and be unable to make the payments, the bank will gleefully still take my house. They wouldn’t care if I’m ahead or not. But if I bank the cash myself, I’m covered — job loss just means I dip into my personal funds and continue to pay until I’m back on my feet. Sure, I pay more on the mortgage over time, but it’s offset with personal ROI and piece of mind.</p><p>Anyway, but this then begged the question — <strong>what do I do with that money that I was now keeping?</strong></p><p>I’d already budgeted everything else. This was money that, by definition, was excess to my budget. Sure, I can invest it into various places, but <em>where</em>? I didn’t know what to do with it. #firstworldproblems indeed.</p><p><strong>And here is where I stumbled into the strategy that has worked brilliantly — </strong>I opted to put it into a new envelope called <strong>“unallocated”</strong>. Just a block of cash that I’m going to do <em>something</em> with, I just don’t know what. It’s a pool of money that I can do <em>anything</em> with. It’s a way that I can buy a new computer or a boat or new carpeting or a gift for my dad or a video game…or…or…or…</p><p>And you know what I discovered? I just don’t <em>want</em> to spend it on anything. The way I had it set up before, the spending was still essentially hidden. I ended up paying less to my mortgage, but I was still overpaying and who cares? I was still coming out ahead. Maybe a little <em>less ahead</em> than I could have, but meh.</p><p>But now…if I want to overspend on something else I have to <strong>explicitly pull it out of unallocated </strong>and do something with it. That’s it. The money that is literally flagged as being budgeted for nothing, up for grabs, enjoy yourself. I need to actually use it to enjoy myself. And I don’t want to touch it <strong>at all.</strong></p><p>I think this is how the psychology is working for me — when it’s in that budget, the possibilities are endless. I can buy anything I want <em>tomorrow</em>. That option is always there, since the money isn’t going away. Stocks or CDs or a new coffee maker. A lot of people spend money for fear of it going away. If you don’t buy those new sneakers today, you’ll just have to spend money on a car repair tomorrow. It’s silly, but I get it.</p><p>But it doesn’t apply here — I have a car budget. Taking money out of unallocated just crystalizes it into something concrete. I lose the possibilities and the dreams. I can no longer spend it on <em>anything</em>, it’s already spent on <em>something</em>. <strong>Anything is better than something.</strong></p><p>So I let the money sit and grow and be there for if or when I really need it on something else. Maybe I just need it to be there right now more than anything else, and that’s fine too.</p><p>But who knew that despite all of my careful planning and budgeting and allocating money to funds to ensure that I had enough, that the best way for me to actually save and keep it was to explicitly say that the money was for <strong>nothing</strong>. Because that meant I’d keep it for <strong>everything</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aebb405c8dd2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[T-Mobile Money is great, but not why you think]]></title>
            <link>https://medium.com/@thomasoniii/t-mobile-money-is-great-but-not-why-you-think-bead464e1125?source=rss-72a47e2393d5------2</link>
            <guid isPermaLink="false">https://medium.com/p/bead464e1125</guid>
            <category><![CDATA[finance]]></category>
            <category><![CDATA[interest-rates]]></category>
            <category><![CDATA[t-mobile-money]]></category>
            <category><![CDATA[checking-account]]></category>
            <dc:creator><![CDATA[Jim Thomason]]></dc:creator>
            <pubDate>Mon, 24 Jul 2023 16:10:02 GMT</pubDate>
            <atom:updated>2023-07-24T16:10:02.214Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MNIPLwjp_l-tI_Onkx9Gtg.png" /><figcaption>via midjourney</figcaption></figure><p>I’ll cut right to the chase — T-Mobile Money’s 4% interest rate on your checking account <em>is</em> pretty awesome, but you can probably do way better with rewards on a credit card. I’m also assuming that you’re being responsible and paying off your credit card every month and not carrying a balance, mind you.</p><p>I switched to T-Mobile Money for my banking last year and I’ve been happy with it. I was nervous about leaving my regional bank for them. But then my bank was purchased by another bank, decreasing my loyalty. And they were advertising an absolutely incredible 2.5% APR on my checking account, vs 0% that I had. And also 2.5% on my savings account, vs the 0.01% (not a typo!) I had locally. Staying where I was meant leaving money on the table.</p><p>They also offer a bonus for using your card — 4% APR on the first $4,000 of deposits if you complete 10 debit card transactions in a month. And this 4% rate is <strong>the thing</strong> that everyone focuses on when I tell people I’m a happy customer and recommend trying them. Everyone gushes and fawns over that 4% rate. “Oh it’s so amazing!” “Wow! 4%!” “I should switch too, to get that 4%!”</p><p>And, again, 4% <em>is</em> a really great APR. But it’s only on the first $4,000 and there are better rewards available out there.</p><p>For instance, I also have a Citibank Double Cash card, which offers me 2% back. Now, at first blush, T-Mobile sounds like the superior option, right? I’m getting 4% there (or at least 2.5%) vs only 2% with my credit card. So how can I advocate for it?</p><p>Let’s use a contrived example with easy math. Let’s assume that on an ongoing basis, you keep an average daily $12,000 balance in your checking account (I know, sounds great, right?). And that every month you spend $1,000. And we’ll assume that you break that out over at least 10 transactions so you get the bonus.</p><p>First of all, how much interest are you earning <em>without</em> the bonus? $12,000 over a year at 2.5% yields $300 in interest. Which means that each month you’re pocketing $25. That’s really not bad at all.</p><p>Next, let’s assume you’re doing those 10 transactions monthly and get the 4% APR (on the first $4,000 only!) every month. That means you’ll earn $360 in interest annually ($160 on $4,000 at 4% + $200 on $8,000 at 2.5%). You’ve pocked an extra $60 annually, or an extra $5 monthly. None of this is bad. More money is always better.</p><p>But let’s try the Citi Double Cash Card — you get 2% back on your <em>purchases</em>. And for our simple math example, you’re spending $1,000 monthly. And we’re also assuming you pay off the card and never accrue interest, which is a <em>super</em> important consideration. If you can’t pay off your card every statement, then all of this goes out the window.</p><p>So now you’re using your card and responsibly paying it. You spend $1,000/month and then you get back 2% in rewards for $20. That’s every single month. Multiply that by 12 months in a year and you’ve pocked $240 in rewards. Add that into the $300 in interest from your checking account and you’ve pocketed $540 this year, vs only $360 if you were using that awesome sounding 4% APR that you were so excited about.</p><p>Finally, <em>of course</em> this doesn’t work for everyone. If you can’t keep that card paid off and will be tempted to overspend on it, then don’t do this. If you can’t get a credit card with better rewards, then absolutely stick with the 4% gimmick. If you’re concerned about the morally gray area of sticking stores with higher credit card fees and want to give them slightly lower debit card fees, then definitely focus on that. As with all things in finance, there is no one-size-fits-all answer.</p><p>But don’t just read as far as the great 4% rate and stop reading and think it’s the best deal around — consider your other options.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bead464e1125" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>