<?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: Karine Babajanyan</title>
    <description>The latest articles on DEV Community by Karine Babajanyan (@karine_babajanyan_97236c4).</description>
    <link>https://dev.to/karine_babajanyan_97236c4</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%2F4241086%2F1c23ffc8-b083-4297-8f08-a87ecade53cb.jpg</url>
      <title>DEV Community: Karine Babajanyan</title>
      <link>https://dev.to/karine_babajanyan_97236c4</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/karine_babajanyan_97236c4"/>
    <language>en</language>
    <item>
      <title>Physics in Code #1: Schrödinger's Cat and "It Works on My Machine"</title>
      <dc:creator>Karine Babajanyan</dc:creator>
      <pubDate>Thu, 12 Nov 2026 13:38:02 +0000</pubDate>
      <link>https://dev.to/karine_babajanyan_97236c4/physics-in-code-1-schrodingers-cat-and-it-works-on-my-machine-4c58</link>
      <guid>https://dev.to/karine_babajanyan_97236c4/physics-in-code-1-schrodingers-cat-and-it-works-on-my-machine-4c58</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;"But it works on my machine!"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Every developer has said this at least once. 😄 I think physics can explain it.&lt;/p&gt;

&lt;p&gt;There is a phrase I really like, from my C++ lecturer at university:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Programming is the interpretation of our daily life in a programming language.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Our daily life follows the laws of physics. So physics and programming both describe the same real world, and we can compare them. This is the first post in a series. In each post, I take one idea from physics and connect it to one lesson from programming.&lt;/p&gt;

&lt;h2&gt;
  
  
  The physics: a cat in a box
&lt;/h2&gt;

&lt;p&gt;In 1935, the physicist Erwin Schrödinger described a thought experiment. A cat is in a closed box with a mechanism that may kill it, or may not. Until someone opens the box, we can't know what happened. In a way, the cat is &lt;strong&gt;alive and dead at the same time&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Only when we &lt;strong&gt;look&lt;/strong&gt; inside the box do we get one clear answer: alive or dead.&lt;/p&gt;

&lt;p&gt;Fun fact: Schrödinger didn't really think cats work like this. He wanted to show how strange quantum ideas sound when we use them for everyday things. But in software, this strange situation is very real.&lt;/p&gt;

&lt;h2&gt;
  
  
  The programming: code in a box
&lt;/h2&gt;

&lt;p&gt;You write a new feature. The tests pass on your laptop. You are sure it works.&lt;/p&gt;

&lt;p&gt;Then the code goes to the server, to staging, or to a teammate's laptop, and it breaks.&lt;/p&gt;

&lt;p&gt;Until code runs in its real environment, it is like the cat: &lt;strong&gt;working and broken at the same time&lt;/strong&gt;. We only find out when we "open the box", when we run it in the place where it really lives.&lt;/p&gt;

&lt;p&gt;Why does this happen? Because the result depends not only on the code, but also on the &lt;strong&gt;environment&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;different OS, Node.js, or library versions&lt;/li&gt;
&lt;li&gt;missing config or environment variables&lt;/li&gt;
&lt;li&gt;different data, timezone, or language settings&lt;/li&gt;
&lt;li&gt;network access and permissions that you don't have on your laptop&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  A simple example: a missing environment variable
&lt;/h2&gt;

&lt;p&gt;The app reads the API address from a &lt;code&gt;.env&lt;/code&gt; file:&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;function&lt;/span&gt; &lt;span class="nf"&gt;getUsersUrl&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="k"&gt;return&lt;/span&gt; &lt;span class="sb"&gt;`${process.env.API_URL}/users`&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;p&gt;The same code gives different results on two machines:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Machine&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;My laptop (has &lt;code&gt;.env&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;https://api.myshop.com/users&lt;/code&gt; 🐱 alive&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Server (no &lt;code&gt;.env&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;undefined/users&lt;/code&gt; 💀 dead&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The server has no &lt;code&gt;.env&lt;/code&gt; file, so &lt;code&gt;API_URL&lt;/code&gt; is &lt;code&gt;undefined&lt;/code&gt;. Nothing crashes. The app just calls the wrong address without any error, and we find out later, maybe from a user.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix: open the box early
&lt;/h2&gt;

&lt;p&gt;First, check the variable. If it is missing, stop with a clear message:&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;function&lt;/span&gt; &lt;span class="nf"&gt;getUsersUrl&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="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;API_URL&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"API_URL is not set. Add it to your .env file."&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="k"&gt;return&lt;/span&gt; &lt;span class="sb"&gt;`${process.env.API_URL}/users`&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;p&gt;Now we see the problem on the server right away:&lt;/p&gt;

&lt;p&gt;​&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Error: API_URL is not set. Add it to your .env file.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The developer finds the "dead cat" on the first run, not the customer.&lt;/p&gt;

&lt;p&gt;In a real project, it is even better to check all the variables &lt;strong&gt;once, when the app starts&lt;/strong&gt;. Also, keep a &lt;code&gt;.env.example&lt;/code&gt; file in the repository, so everyone knows which variables the app needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  More ways to open the box early
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Docker&lt;/strong&gt;: dev and production use the same image, so the environment is the same.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lock files&lt;/strong&gt;: commit &lt;code&gt;package-lock.json&lt;/code&gt;, so everyone installs the same library versions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check config at startup&lt;/strong&gt;: stop early with a clear message, like in the example.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CI similar to production&lt;/strong&gt;: run your tests in an environment that looks like the real one.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Real test data&lt;/strong&gt;: test with real cases, not only the easy ones.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sometimes the box is production itself. That's why good &lt;strong&gt;logs and monitoring&lt;/strong&gt; are important. They let you look inside the box without breaking anything.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it yourself
&lt;/h2&gt;

&lt;p&gt;The example code is on GitHub: &lt;a href="https://github.com/karinebabajanyan/physics-in-code" rel="noopener noreferrer"&gt;physics-in-code&lt;/a&gt; (folder &lt;code&gt;01-schrodingers-cat&lt;/code&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  Takeaway
&lt;/h2&gt;

&lt;p&gt;"It works on my machine" is true. It just means you have opened only one box.&lt;/p&gt;

&lt;p&gt;Make the environment a part of your code: know what your code needs, check it early, and stop with a clear message if something is missing.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Have you ever had a "Schrödinger bug", a bug that appeared only after you opened the box? Tell me in the comments.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Next in the series: Inertia and legacy code.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>beginners</category>
      <category>physics</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
