<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: BugExplained</title>
    <description>The latest articles on DEV Community by BugExplained (@bugexplained).</description>
    <link>https://dev.to/bugexplained</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4277056%2Fa12775c0-f3bc-4493-855b-c2c52de74a36.png</url>
      <title>DEV Community: BugExplained</title>
      <link>https://dev.to/bugexplained</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bugexplained"/>
    <language>en</language>
    <item>
      <title>Why Restarting Your Computer Actually Fixes Problems</title>
      <dc:creator>BugExplained</dc:creator>
      <pubDate>Fri, 04 Dec 2026 05:12:07 +0000</pubDate>
      <link>https://dev.to/bugexplained/why-restarting-your-computer-actually-fixes-problems-3od9</link>
      <guid>https://dev.to/bugexplained/why-restarting-your-computer-actually-fixes-problems-3od9</guid>
      <description>&lt;p&gt;You have heard it a thousand times: "have you tried turning it off and on again?" It sounds like a joke, but it works, and the reasons are more interesting than the joke suggests.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Memory leaks accumulate
&lt;/h2&gt;

&lt;p&gt;A program asks the operating system for memory and is supposed to give it back. Many programs forget, or give it back only when they exit. Over days or weeks the leak grows until the machine is swapping to disk and everything crawls. A restart returns all of that memory at once.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. State gets stuck in a bad shape
&lt;/h2&gt;

&lt;p&gt;Long-running software accumulates state: half-open network connections, locks that were never released, threads waiting on something that will never arrive, caches that grew stale. None of these show up as an error you can click away. A fresh boot gives every process a clean slate.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Pending updates only apply on boot
&lt;/h2&gt;

&lt;p&gt;Kernel updates, driver updates, and many security patches replace files that are in use. The installer cannot swap a file that a running process has open, so it stages the change and applies it at the next boot. Until you restart, you are still running the old, possibly vulnerable, code.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Background processes pile up
&lt;/h2&gt;

&lt;p&gt;Browsers, chat apps, and installers leave helper processes behind. Each one holds file handles and a slice of CPU. After a few days, a laptop is running a hundred processes nobody asked for.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Hardware state gets re-initialized
&lt;/h2&gt;

&lt;p&gt;Devices like Wi-Fi cards, USB controllers, and GPUs can end up in a bad state after an error. A driver reload fixes most of them, and a reboot is the blunt but reliable version of that.&lt;/p&gt;

&lt;h2&gt;
  
  
  When a restart does not help
&lt;/h2&gt;

&lt;p&gt;If the problem comes back within minutes of a restart, it is not accumulated state. It is a configuration problem, a failing component, or a bug that triggers on startup. Restarting hides those; it does not fix them. The same applies to "restart fixes it every day" - that pattern usually means a specific program is leaking or a scheduled task is misbehaving.&lt;/p&gt;

&lt;h2&gt;
  
  
  The practical version
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Restart when things feel slow after days of uptime, when updates are pending, or when a device stops working.&lt;/li&gt;
&lt;li&gt;Do not restart to avoid diagnosing a problem that returns immediately.&lt;/li&gt;
&lt;li&gt;On servers, uptime is not a badge of honor. Scheduled reboots are a legitimate maintenance tool.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I made a short video that walks through these five reasons with examples:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=-_NyIlh5f38&amp;amp;utm_source=devto&amp;amp;utm_medium=social" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=-_NyIlh5f38&amp;amp;utm_source=devto&amp;amp;utm_medium=social&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want the same idea from the other side - why clearing state is a debugging technique rather than a superstition - the video is the fastest version.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>productivity</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Why 0.1 + 0.2 = 0.30000000000000004 (and the four fixes that actually work)</title>
      <dc:creator>BugExplained</dc:creator>
      <pubDate>Thu, 03 Dec 2026 05:33:41 +0000</pubDate>
      <link>https://dev.to/bugexplained/why-01-02-030000000000000004-and-the-four-fixes-that-actually-work-2d9</link>
      <guid>https://dev.to/bugexplained/why-01-02-030000000000000004-and-the-four-fixes-that-actually-work-2d9</guid>
      <description>&lt;p&gt;Every JavaScript developer runs into this eventually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="mf"&gt;0.1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.2&lt;/span&gt;            &lt;span class="c1"&gt;// 0.30000000000000004&lt;/span&gt;
&lt;span class="mf"&gt;0.1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.2&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mf"&gt;0.3&lt;/span&gt;    &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It looks like a bug in JavaScript. It is not. It is how binary floating point works in every language that uses IEEE 754 doubles: JavaScript, Python, Java, C#, Go, Ruby, PHP, you name it. Here is what is actually going on, and the four fixes that stop it from biting you in production.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why 0.1 + 0.2 is not 0.3
&lt;/h2&gt;

&lt;p&gt;Computers store numbers in binary. Integers are exact: 1, 2, 3 have a clean binary form. Fractions usually do not.&lt;/p&gt;

&lt;p&gt;In base 10 you cannot write 1/3 exactly. You get 0.333333... forever, and at some point you have to stop writing digits. Base 2 has the same problem, just with different numbers. 0.1 in binary is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0.0001100110011001100110011001100110011...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That pattern repeats forever. A 64-bit float keeps 53 bits of it and rounds the rest away, so the value stored is not 0.1. It is the closest binary fraction to 0.1, off by about 1e-17.&lt;/p&gt;

&lt;p&gt;Do the same with 0.2, add the two approximations, and the small errors add up to something you can see:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="mf"&gt;0.1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.2&lt;/span&gt;  &lt;span class="c1"&gt;// 0.30000000000000004&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The error is tiny in absolute terms, but it is not zero, and &lt;code&gt;===&lt;/code&gt; is exact.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where this actually hurts
&lt;/h2&gt;

&lt;p&gt;Most of the time the error is invisible. It becomes a problem when it meets an exact comparison or a loop:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A total of 19.99 + 4.99 does not equal 24.98, so a discount check silently fails.&lt;/li&gt;
&lt;li&gt;A "sum until 1.0" loop overshoots and never hits its stop condition.&lt;/li&gt;
&lt;li&gt;A test asserting &lt;code&gt;expect(total).toBe(0.3)&lt;/code&gt; fails on a machine where the numbers are computed in a different order.&lt;/li&gt;
&lt;li&gt;IDs or hashes built from float math differ between runs.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Fix 1: compare with a tolerance
&lt;/h2&gt;

&lt;p&gt;Never use &lt;code&gt;===&lt;/code&gt; on computed floats. Compare the distance instead:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;isEqual&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;EPSILON&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Number.EPSILON&lt;/code&gt; is the gap between 1 and the next representable double. That is fine for values around 1, but it is too strict for big numbers, where the gap grows. If you compare money or large quantities, scale the tolerance:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;isClose&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;1e-9&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;rel&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Fix 2: work in integers (cents, not dollars)
&lt;/h2&gt;

&lt;p&gt;If the value is money, store cents. Integer arithmetic is exact up to 2^53, which is more than enough for any invoice:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1999&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// 19.99&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;shipping&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;499&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// 4.99&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;shipping&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// 24.98&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Convert at the edges (parsing input, formatting output) and keep everything integer in between.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fix 3: use a decimal library
&lt;/h2&gt;

&lt;p&gt;When the numbers must be decimal-accurate by definition (prices, tax, interest, invoices), use a decimal type instead of guessing with floats: &lt;code&gt;decimal.js&lt;/code&gt;, &lt;code&gt;big.js&lt;/code&gt;, or &lt;code&gt;bignumber.js&lt;/code&gt;. They are slower, and that is fine, because they are only in the money path.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Decimal&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"decimal.js"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Decimal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"0.1"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;plus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"0.2"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// "0.3"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Fix 4: round only for display
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;toFixed(2)&lt;/code&gt; is for showing a number to a human. It is not a fix. Rounding before comparison or before storing hides the error until someone sums a thousand rows and the totals disagree by a cent.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toFixed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// "0.30" - display only&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The one rule
&lt;/h2&gt;

&lt;p&gt;Floats are fine for measuring things (temperatures, distances, physics). They are wrong for counting money. Pick the representation from what the number means, not from what the language defaults to.&lt;/p&gt;

&lt;p&gt;If you want the 60-second version of this with the machine-level picture, I made a short explainer here: &lt;a href="https://www.youtube.com/watch?v=C6wp0GgISmw" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=C6wp0GgISmw&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
