<?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>Forem: Ibim</title>
    <description>The latest articles on Forem by Ibim (@intelgreatnez).</description>
    <link>https://forem.com/intelgreatnez</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F199160%2Fd7e3e64e-a11f-4422-8dda-df91758b889b.jpg</url>
      <title>Forem: Ibim</title>
      <link>https://forem.com/intelgreatnez</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/intelgreatnez"/>
    <language>en</language>
    <item>
      <title>The AI Bubble Is Not About AI</title>
      <dc:creator>Ibim</dc:creator>
      <pubDate>Wed, 31 Dec 2025 08:19:16 +0000</pubDate>
      <link>https://forem.com/intelgreatnez/the-ai-bubble-is-not-about-ai-1bmp</link>
      <guid>https://forem.com/intelgreatnez/the-ai-bubble-is-not-about-ai-1bmp</guid>
      <description>&lt;p&gt;The AI Bubble Is Not About AI, it is about expectations, incentives, and timing&lt;/p&gt;

&lt;p&gt;Everyone in tech seems to agree we are in an AI bubble.&lt;/p&gt;

&lt;p&gt;What people do not agree on is what exactly is inflated, or what happens if it deflates.&lt;/p&gt;

&lt;p&gt;Some believe the technology itself is overhyped. Others believe the infrastructure spending is excessive. Others think the real excess is in company valuations, not capability. And a growing number of developers quietly suspect something else entirely: that expectations have simply raced far ahead of reality.&lt;/p&gt;

&lt;p&gt;The confusion is not accidental. It is a natural side effect of a technology that is genuinely powerful, unevenly useful, and arriving faster than organisations know how to absorb it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bubbles usually form around something real&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The word bubble tends to imply fraud or fantasy. But most historical bubbles formed around technologies that actually mattered.&lt;/p&gt;

&lt;p&gt;Railroads transformed economies.&lt;br&gt;
The internet reshaped communication and commerce.&lt;br&gt;
Cloud computing changed how software is built and deployed.&lt;/p&gt;

&lt;p&gt;In each case, the mistake was not believing the technology was important. The mistake was assuming that importance translated directly into short-term returns for everyone involved.&lt;/p&gt;

&lt;p&gt;AI feels similar.&lt;/p&gt;

&lt;p&gt;There is a real kernel of truth here. The models work. They are improving. They unlock capabilities that did not exist before. But that truth has been wrapped in a level of certainty, urgency, and financial expectation that no complex technology has ever lived up to on the first pass.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Infrastructure optimism versus execution reality&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One of the most striking features of the current AI moment is the scale of infrastructure spending.&lt;/p&gt;

&lt;p&gt;Data centres, GPUs, power grids, and long-term compute commitments are being built on assumptions about future demand that are difficult to verify today. The justification is often that compute is the bottleneck, and that whoever builds fastest will win.&lt;/p&gt;

&lt;p&gt;That may turn out to be true.&lt;/p&gt;

&lt;p&gt;But there is a difference between possible and inevitable.&lt;/p&gt;

&lt;p&gt;Execution risk is not just technical. It is organisational, economic, and human. Even if the models continue to improve, building sustainable businesses around them requires alignment across product design, cost structure, regulation, and actual user behaviour.&lt;/p&gt;

&lt;p&gt;History suggests those things rarely move in lockstep.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AI coding as a microcosm of the bubble&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Nowhere is the gap between expectation and reality clearer than in AI assisted coding.&lt;/p&gt;

&lt;p&gt;On paper, it looks like the perfect use case. Code is structured language. It is expensive to produce. It has clear success criteria. And in isolated tasks, AI tools can be astonishingly effective.&lt;/p&gt;

&lt;p&gt;In practice, many developers report a more complicated experience.&lt;/p&gt;

&lt;p&gt;AI tools excel at:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;boilerplate&lt;/li&gt;
&lt;li&gt;tests&lt;/li&gt;
&lt;li&gt;quick prototypes&lt;/li&gt;
&lt;li&gt;explaining unfamiliar code&lt;/li&gt;
&lt;li&gt;fixing narrowly scoped bugs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;They struggle with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;large codebases&lt;/li&gt;
&lt;li&gt;long-term architectural consistency&lt;/li&gt;
&lt;li&gt;context awareness&lt;/li&gt;
&lt;li&gt;respecting project-specific conventions&lt;/li&gt;
&lt;li&gt;knowing when they are wrong&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This does not make them useless. It makes them situational.&lt;/p&gt;

&lt;p&gt;The problem arises when productivity gains measured in controlled tasks are projected onto entire engineering workflows. The result is disappointment, confusion, and sometimes a quiet sense that something does not add up.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Productivity is harder to measure than we admit&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A recurring pattern in developer feedback is perceived speed versus actual output.&lt;/p&gt;

&lt;p&gt;Many engineers feel faster with AI tools. They move more quickly through tasks. They generate more code. They spend less time staring at a blank file.&lt;/p&gt;

&lt;p&gt;But when measured over weeks or months, the gains are often smaller than expected. Sometimes they even reverse.&lt;/p&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;p&gt;Because software development is not just typing. It is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;reasoning&lt;/li&gt;
&lt;li&gt;debugging&lt;/li&gt;
&lt;li&gt;reviewing&lt;/li&gt;
&lt;li&gt;maintaining&lt;/li&gt;
&lt;li&gt;aligning with other humans&lt;/li&gt;
&lt;li&gt;paying down technical debt&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;AI can accelerate some of these steps. It can also quietly increase the load on others.&lt;/p&gt;

&lt;p&gt;More code still has to be understood. More changes still need review. And code that looks correct but subtly violates a system’s design can be more expensive than code that was written slowly and deliberately.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Technical debt does not disappear, it shifts&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One of the quieter risks in widespread AI assisted coding is the accumulation of technical debt in less obvious forms.&lt;/p&gt;

&lt;p&gt;The code may compile.&lt;br&gt;
The tests may pass.&lt;br&gt;
The bugs may be fewer.&lt;/p&gt;

&lt;p&gt;But complexity can still grow.&lt;/p&gt;

&lt;p&gt;Verbosity increases. Patterns drift. Inconsistencies multiply. And because the output often looks polished, issues can be harder to spot early.&lt;/p&gt;

&lt;p&gt;This is not a flaw unique to AI. It is a familiar problem in software engineering. The difference is scale and speed. AI makes it easier to accumulate debt quickly, especially under pressure.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The cultural amplification effect&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;AI tools do not exist in a vacuum. They amplify the culture they are introduced into.&lt;/p&gt;

&lt;p&gt;In teams with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;strong conventions&lt;/li&gt;
&lt;li&gt;clear architectural principles&lt;/li&gt;
&lt;li&gt;disciplined review processes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;AI can be genuinely powerful.&lt;/p&gt;

&lt;p&gt;In teams without those things, it often magnifies existing problems.&lt;/p&gt;

&lt;p&gt;This is why adoption outcomes vary so widely. The tool is the same. The context is not.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why this still does not mean the bubble is fake&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;None of this implies that AI is a fad.&lt;/p&gt;

&lt;p&gt;It implies that the timeline has been misunderstood.&lt;/p&gt;

&lt;p&gt;AI is not replacing software engineers overnight. It is changing what software engineering looks like, unevenly and gradually. Some workflows will be transformed quickly. Others will resist change for good reasons.&lt;/p&gt;

&lt;p&gt;The danger is not believing in AI.&lt;br&gt;
The danger is believing that belief alone guarantees returns.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A more grounded way to think about the AI moment&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Instead of asking whether we are in an AI bubble, a better question might be:&lt;/p&gt;

&lt;p&gt;Where are expectations being priced as certainty?&lt;/p&gt;

&lt;p&gt;That framing allows for nuance.&lt;/p&gt;

&lt;p&gt;It leaves room for:&lt;/p&gt;

&lt;p&gt;real breakthroughs&lt;/p&gt;

&lt;p&gt;real failures&lt;/p&gt;

&lt;p&gt;uneven impact&lt;/p&gt;

&lt;p&gt;long adjustment periods&lt;/p&gt;

&lt;p&gt;And it reminds us that bubbles do not only burst. Sometimes they deflate slowly, leaving behind infrastructure, knowledge, and capabilities that matter long after the hype fades.&lt;/p&gt;

&lt;p&gt;AI is powerful.&lt;br&gt;
AI is imperfect.&lt;br&gt;
AI is early.&lt;/p&gt;

&lt;p&gt;The tension we are seeing is not between truth and illusion, but between possibility and impatience.&lt;/p&gt;

&lt;p&gt;If there is a bubble, it is not one belief. It is many overlapping assumptions, moving at different speeds, held by people with different incentives.&lt;/p&gt;

&lt;p&gt;Understanding that may be more useful than predicting exactly when anything pops.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>softwareengineering</category>
      <category>aibubble</category>
    </item>
    <item>
      <title>Why push and pop Feel Natural and shift Does Not</title>
      <dc:creator>Ibim</dc:creator>
      <pubDate>Mon, 29 Dec 2025 00:41:50 +0000</pubDate>
      <link>https://forem.com/intelgreatnez/why-push-and-pop-feel-natural-and-shift-does-not-8d3</link>
      <guid>https://forem.com/intelgreatnez/why-push-and-pop-feel-natural-and-shift-does-not-8d3</guid>
      <description>&lt;p&gt;&lt;strong&gt;What JavaScript arrays quietly optimise for&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When I first started working with JavaScript arrays, &lt;code&gt;push&lt;/code&gt; and &lt;code&gt;pop&lt;/code&gt; felt immediately intuitive.&lt;/p&gt;

&lt;p&gt;You add something to the end.&lt;br&gt;
You remove something from the end.&lt;br&gt;
Nothing surprising happens.&lt;/p&gt;

&lt;p&gt;Then I started using &lt;code&gt;shift&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;It did exactly what it promised. It removed the first element. But it always felt heavier. Slower. Slightly uncomfortable in a way that was hard to articulate.&lt;/p&gt;

&lt;p&gt;At first, I assumed that feeling was just intuition without substance.&lt;/p&gt;

&lt;p&gt;It was not.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Arrays look simple until you change the front&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Most of us begin with a very simple mental model of arrays. A neat list of items laid out in order, ready to be modified wherever needed.&lt;/p&gt;

&lt;p&gt;That model mostly works until you start modifying the front of the array.&lt;/p&gt;

&lt;p&gt;This is where an important detail becomes visible:&lt;/p&gt;

&lt;p&gt;JavaScript arrays are optimised for the end, not the beginning.&lt;/p&gt;

&lt;p&gt;Once you understand that, the difference between &lt;code&gt;push&lt;/code&gt;, &lt;code&gt;pop&lt;/code&gt;, and &lt;code&gt;shift&lt;/code&gt; stops feeling arbitrary.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why &lt;code&gt;push&lt;/code&gt; feels effortless&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When you call &lt;code&gt;push&lt;/code&gt;, the engine already knows where the next element belongs.&lt;/p&gt;

&lt;p&gt;There is a clear end.&lt;br&gt;
There is a known length.&lt;br&gt;
Nothing else needs to move.&lt;/p&gt;

&lt;p&gt;The value is added, the length is updated, and execution continues.&lt;/p&gt;

&lt;p&gt;From the runtime’s point of view, this is a cooperative operation. It works with the structure of the array rather than against it.&lt;/p&gt;

&lt;p&gt;That is why &lt;code&gt;push&lt;/code&gt; feels cheap and predictable, even as arrays grow.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why &lt;code&gt;pop&lt;/code&gt; feels just as natural&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Pop&lt;/code&gt; is simply the reverse operation.&lt;/p&gt;

&lt;p&gt;The last element is removed.&lt;br&gt;
The length is reduced.&lt;br&gt;
No reorganisation is required.&lt;/p&gt;

&lt;p&gt;Again, nothing else in the array needs to change.&lt;/p&gt;

&lt;p&gt;Both &lt;code&gt;push&lt;/code&gt; and &lt;code&gt;pop&lt;/code&gt; operate at the boundary of the structure. They touch as little as possible, and that efficiency is reflected in how they feel to use.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why &lt;code&gt;shift&lt;/code&gt; feels different&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Shift&lt;/code&gt; removes the first element.&lt;/p&gt;

&lt;p&gt;On the surface, that sounds just as simple.&lt;/p&gt;

&lt;p&gt;Underneath, it is not.&lt;/p&gt;

&lt;p&gt;Removing the element at index &lt;code&gt;0&lt;/code&gt; means everything else has to move. Every remaining item must be reassigned a new index. What used to be at &lt;code&gt;1&lt;/code&gt; becomes &lt;code&gt;0&lt;/code&gt;. What used to be at &lt;code&gt;2&lt;/code&gt; becomes &lt;code&gt;1&lt;/code&gt;. And so on.&lt;/p&gt;

&lt;p&gt;The array has to be reindexed.&lt;/p&gt;

&lt;p&gt;This is not a quirk. It is a direct consequence of how arrays work and how indexed access is maintained.&lt;/p&gt;

&lt;p&gt;Once you realise this, the discomfort around &lt;code&gt;shift&lt;/code&gt; makes sense. It is asking the engine to do significantly more work.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You can feel cost before you can name it&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You do not need formal performance terminology to notice this difference.&lt;/p&gt;

&lt;p&gt;You feel it when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;arrays grow larger&lt;/li&gt;
&lt;li&gt;operations happen repeatedly&lt;/li&gt;
&lt;li&gt;responsiveness starts to matter&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Operations at the end scale quietly.&lt;br&gt;
Operations at the beginning scale loudly.&lt;/p&gt;

&lt;p&gt;This is one of those cases where understanding begins with experience, not vocabulary. Later, when performance concepts are introduced more formally, they feel familiar because the behaviour has already been observed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Arrays are structured objects, not abstract lists&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Another helpful mental shift is remembering that JavaScript arrays are not abstract containers. They are structured objects with numeric keys and a length contract.&lt;/p&gt;

&lt;p&gt;Each index is a property. Changing the front of the array means changing many properties at once.&lt;/p&gt;

&lt;p&gt;Seen this way, &lt;code&gt;shift&lt;/code&gt; is no longer a sibling of &lt;code&gt;pop&lt;/code&gt;. It is a fundamentally different operation with very different implications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When &lt;code&gt;shift&lt;/code&gt; is still the right choice&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;None of this means &lt;code&gt;shift&lt;/code&gt; is wrong.&lt;/p&gt;

&lt;p&gt;It means it should be used deliberately.&lt;/p&gt;

&lt;p&gt;If:&lt;/p&gt;

&lt;p&gt;the array is small&lt;/p&gt;

&lt;p&gt;the operation is infrequent&lt;/p&gt;

&lt;p&gt;clarity matters more than raw efficiency&lt;/p&gt;

&lt;p&gt;Then &lt;code&gt;shift&lt;/code&gt; is perfectly acceptable.&lt;/p&gt;

&lt;p&gt;Understanding cost is not about avoiding certain methods. It is about choosing them consciously rather than accidentally.&lt;/p&gt;

&lt;p&gt;The real lesson here&lt;/p&gt;

&lt;p&gt;The most important takeaway is not about any specific array method.&lt;/p&gt;

&lt;p&gt;It is about learning to ask a better question.&lt;/p&gt;

&lt;p&gt;Not:&lt;/p&gt;

&lt;p&gt;“Does this work?”&lt;/p&gt;

&lt;p&gt;But:&lt;/p&gt;

&lt;p&gt;“What does this force the runtime to do?”&lt;/p&gt;

&lt;p&gt;That question scales far beyond arrays. It shows up again with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;string manipulation&lt;/li&gt;
&lt;li&gt;object copying&lt;/li&gt;
&lt;li&gt;state updates&lt;/li&gt;
&lt;li&gt;performance issues that only appear under load&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once you start asking it, JavaScript stops feeling unpredictable and starts feeling explainable.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Push&lt;/code&gt; and &lt;code&gt;pop&lt;/code&gt; feel natural because they align with how JavaScript arrays are built to work.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;shift&lt;/code&gt; feels awkward because it asks the structure to fight itself.&lt;/p&gt;

&lt;p&gt;Neither is wrong.&lt;/p&gt;

&lt;p&gt;But understanding why they feel different is one of those small moments where JavaScript stops being a collection of methods and starts being a system you can reason about.&lt;/p&gt;

&lt;p&gt;That is a meaningful learning moment.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>JavaScript Closures: The Quiet Mechanism Running Your Code</title>
      <dc:creator>Ibim</dc:creator>
      <pubDate>Sun, 28 Dec 2025 05:26:44 +0000</pubDate>
      <link>https://forem.com/intelgreatnez/javascript-closures-the-quiet-mechanism-running-your-code-556i</link>
      <guid>https://forem.com/intelgreatnez/javascript-closures-the-quiet-mechanism-running-your-code-556i</guid>
      <description>&lt;p&gt;I avoided closures for longer than I care to admit.&lt;/p&gt;

&lt;p&gt;Not deliberately. I just kept telling myself I understood them because I could repeat the usual line: “a closure is a function that remembers its lexical scope.” That sentence sounds convincing. It is also not enough.&lt;/p&gt;

&lt;p&gt;Closures only really make sense once you stop treating them as a concept to memorise and start seeing them as a behaviour your code exhibits.&lt;/p&gt;

&lt;p&gt;This article is not a definition dump. It is an attempt to explain closures the way they actually show up in real JavaScript code and why they matter far more than most beginners realise.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A closure is not created when you write a function&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is where most explanations subtly mislead people.&lt;/p&gt;

&lt;p&gt;Closures are not created when a function is declared. They emerge when a function is executed and continues to reference variables from an outer scope that would otherwise be gone.&lt;/p&gt;

&lt;p&gt;Consider this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function createCounter() {
  let count = 0;

  return function () {
    count++;
    return count;
  };
}

const counter = createCounter();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At first glance, it looks like ==count== should disappear as soon as ==createCounter== finishes running. But it does not. The inner function still has access to it.&lt;/p&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;p&gt;Because JavaScript does not copy values into functions. It keeps references to the environment in which the function was created.&lt;/p&gt;

&lt;p&gt;That environment, the lexical environment, is what we casually call a closure.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Closures are about memory, not syntax&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One of the most useful mental shifts I made was realising that closures are fundamentally a ==memory model==, not a syntax feature.&lt;/p&gt;

&lt;p&gt;The JavaScript engine keeps variables alive &lt;em&gt;only as long as something can still reach them.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In the example above:&lt;/p&gt;

&lt;p&gt;==count== is still reachable&lt;/p&gt;

&lt;p&gt;therefore it stays in memory&lt;/p&gt;

&lt;p&gt;therefore its value persists between function calls&lt;/p&gt;

&lt;p&gt;That is it. No magic.&lt;/p&gt;

&lt;p&gt;Once you see closures this way, a lot of confusing behaviour suddenly becomes predictable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why closures feel confusing at first&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Closures are hard because they break an intuitive rule many people unconsciously follow:&lt;/p&gt;

&lt;p&gt;“When a function finishes, everything inside it disappears.”&lt;/p&gt;

&lt;p&gt;That rule is mostly true, until it is not.&lt;/p&gt;

&lt;p&gt;Closures are the exception that proves the rule. They force you to think about ==who still has a reference== to what.&lt;/p&gt;

&lt;p&gt;This is also why closures are a common source of bugs, especially in loops.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (var i = 0; i &amp;lt; 3; i++) {
  setTimeout(() =&amp;gt; {
    console.log(i);
  }, 1000);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;People expect ==0, 1, 2==.&lt;/p&gt;

&lt;p&gt;They get ==3, 3, 3==.&lt;/p&gt;

&lt;p&gt;Not because JavaScript is broken, but because all three functions close over the ==same variable==, not three different values.&lt;/p&gt;

&lt;p&gt;Once you understand closures, this behaviour stops being surprising.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Closures are everywhere, even when you do not notice them&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you have ever:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;used ==useState= in React&lt;/li&gt;
&lt;li&gt;written a callback&lt;/li&gt;
&lt;li&gt;used ==setTimeout== or ==setInterval==&lt;/li&gt;
&lt;li&gt;worked with event listeners&lt;/li&gt;
&lt;li&gt;implemented currying or partial application&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;you have already used closures.&lt;/p&gt;

&lt;p&gt;Frameworks lean heavily on closures because they allow state to exist without global variables. That is an enormous design advantage.&lt;/p&gt;

&lt;p&gt;React hooks, for example, rely on closures to “remember” values between renders while still keeping functions pure in appearance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Closures enable encapsulation without classes&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before ES6 classes became popular, closures were one of the main ways to create private state in JavaScript.&lt;/p&gt;

&lt;p&gt;Even today, many developers prefer closures over classes for simple encapsulation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function createBankAccount() {
  let balance = 0;

  return {
    deposit(amount) {
      balance += amount;
    },
    getBalance() {
      return balance;
    }
  };
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, ==balance== is completely inaccessible from the outside. There is no keyword for privacy. The privacy emerges naturally from the closure.&lt;/p&gt;

&lt;p&gt;This pattern still holds up remarkably well.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The downside: closures can keep things alive too long&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Closures are powerful, but they are not free.&lt;/p&gt;

&lt;p&gt;Because closures keep references alive, they can accidentally keep large objects in memory longer than necessary. This is especially relevant in long-running applications like browsers or servers.&lt;/p&gt;

&lt;p&gt;Memory leaks caused by closures are subtle and often misunderstood. The problem is not closures themselves, but forgetting that what you reference stays alive.&lt;/p&gt;

&lt;p&gt;Understanding closures helps you reason about memory usage far better than memorising garbage collection rules.&lt;/p&gt;

&lt;p&gt;A better way to explain closures (in one sentence)&lt;/p&gt;

&lt;p&gt;If I had to explain closures in one sentence now, it would be this:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;A closure is what happens when a function keeps a live connection to variables that existed when it was created.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;That sentence is not poetic, but it is accurate.&lt;/p&gt;

&lt;p&gt;Reading further and deepening your understanding&lt;/p&gt;

&lt;p&gt;If you want to go deeper, here are some genuinely useful directions to explore:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;MDN’s explanation of lexical environments and execution contexts&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Articles that explore JavaScript engine internals (V8 in particular)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Functional programming discussions on closures in Scheme and Lisp&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Academic papers on lexical scoping and environment models (arXiv is useful here)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Closures are not unique to JavaScript. Understanding them well makes learning other languages easier.&lt;/p&gt;

&lt;p&gt;Final thoughts&lt;/p&gt;

&lt;p&gt;Closures are not something you “learn once”.&lt;/p&gt;

&lt;p&gt;They are something you gradually notice more clearly the longer you write JavaScript.&lt;/p&gt;

&lt;p&gt;At some point, they stop being a mysterious interview topic and start becoming a quiet, dependable tool you rely on without thinking.&lt;/p&gt;

&lt;p&gt;And that is usually the sign that you finally understand them.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>JavaScript Closures Took Me a While to Understand and That Is Okay</title>
      <dc:creator>Ibim</dc:creator>
      <pubDate>Sat, 27 Dec 2025 21:19:16 +0000</pubDate>
      <link>https://forem.com/intelgreatnez/javascript-closures-took-me-a-while-to-understand-and-that-is-okay-fna</link>
      <guid>https://forem.com/intelgreatnez/javascript-closures-took-me-a-while-to-understand-and-that-is-okay-fna</guid>
      <description>&lt;p&gt;&lt;strong&gt;A reflection on closures, memory, and behaviour&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For a long time, I told myself I understood JavaScript closures.&lt;/p&gt;

&lt;p&gt;I could repeat the definition. I knew they were related to scope. I had even used them in projects without thinking too much about it. But if I am being honest, none of that meant they truly clicked.&lt;br&gt;
And that is okay.&lt;/p&gt;

&lt;p&gt;Closures are one of those ideas in JavaScript that do not reward memorisation. They reward time, exposure, and the uncomfortable moments where code behaves consistently while completely violating your expectations.&lt;/p&gt;

&lt;p&gt;For me, that moment came in the form of a bug.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The bug that forced me to actually understand closures&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The moment closures finally made sense did not come from documentation. It came from chasing behaviour that felt wrong, even though it was technically correct.&lt;/p&gt;

&lt;p&gt;I was looping over a list and attaching handlers. Nothing clever. Nothing experimental. Just everyday JavaScript.&lt;/p&gt;

&lt;p&gt;But every handler behaved as if it had forgotten which item it belonged to.&lt;/p&gt;

&lt;p&gt;I assumed I had made a mistake. Then I assumed some shared state was being overwritten. I added logs. I rewrote the function. The behaviour did not change.&lt;/p&gt;

&lt;p&gt;Every handler was seeing the same value.&lt;/p&gt;

&lt;p&gt;A simplified version of the problem looked like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (var i = 0; i &amp;lt; 3; i++) {
  setTimeout(() =&amp;gt; {
    console.log(i);
  }, 1000);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I expected to see 0, 1, and 2.&lt;/p&gt;

&lt;p&gt;What I saw was 3, printed three times.&lt;/p&gt;

&lt;p&gt;That was the moment I realised I was not dealing with a logic error. I was dealing with a misunderstanding of how JavaScript remembers things.&lt;/p&gt;

&lt;p&gt;Each callback was not getting its own copy of the value. They were all holding onto the same variable. By the time the function actually ran, that variable had already changed.&lt;/p&gt;

&lt;p&gt;Once I saw that, the behaviour stopped being mysterious. It was predictable. It was even reasonable.&lt;/p&gt;

&lt;p&gt;The bug disappeared the moment I stopped asking why JavaScript was doing this and started asking what the function was still connected to.&lt;/p&gt;

&lt;p&gt;That was the point where closures stopped being a definition and became a mental model.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Closures are about environments, not syntax&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Closures are often introduced as a feature of functions. That framing is convenient, but it is incomplete.&lt;/p&gt;

&lt;p&gt;Closures are not something you turn on by writing functions a certain way. They emerge from how JavaScript manages environments over time.&lt;/p&gt;

&lt;p&gt;When a function is created, it is associated with the environment in which it was defined. That environment contains bindings, not frozen values. When the function later executes, it resolves those bindings by walking outward through its lexical environments.&lt;/p&gt;

&lt;p&gt;A closure exists when that environment remains accessible beyond the lifetime of the original function call.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why closures persist after functions return&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A common misconception is that closures store values. They do not.&lt;/p&gt;

&lt;p&gt;What persists is reachability.&lt;/p&gt;

&lt;p&gt;If a function still has access to a variable, that variable remains reachable. If it remains reachable, it stays alive in memory. Garbage collection does not care where a variable was declared. It only cares whether something can still reach it.&lt;/p&gt;

&lt;p&gt;Once you see closures as a consequence of reachability rather than a special feature, many confusing behaviours stop feeling arbitrary.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Closures explain bugs before they explain features&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Most developers encounter closures through bugs long before they use them deliberately.&lt;/p&gt;

&lt;p&gt;Asynchronous callbacks, event handlers, and timers all expose the same underlying behaviour. Closures capture variables, not moments in time. Multiple functions can close over the same binding. Delayed execution simply makes this visible.&lt;/p&gt;

&lt;p&gt;Understanding this shifts closures from being an interview topic to being a practical debugging tool.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Closures are foundational to encapsulation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before modern class syntax and private fields, closures were the primary way JavaScript achieved encapsulation.&lt;/p&gt;

&lt;p&gt;Even now, they offer something classes cannot always provide cleanly. Privacy without exposure.&lt;/p&gt;

&lt;p&gt;A variable that exists only inside a function scope and is accessed only through returned functions is fundamentally inaccessible from the outside. No keyword is required. The structure enforces it naturally.&lt;/p&gt;

&lt;p&gt;Closures support intentional design by keeping state local and controlled.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Closures and functional composition&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Closures become especially powerful when combined with higher order functions.&lt;/p&gt;

&lt;p&gt;Functions that return functions, partially apply arguments, or generate specialised behaviour all rely on closures. This is not an advanced trick. It is a natural extension of how environments work.&lt;/p&gt;

&lt;p&gt;Once closures stop feeling mysterious, patterns like currying and composition start to feel obvious rather than clever.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The real cost of closures&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Closures are often blamed for performance problems, but that concern is usually misplaced.&lt;/p&gt;

&lt;p&gt;The real cost of closures is responsibility.&lt;/p&gt;

&lt;p&gt;If you close over large objects, DOM nodes, or long lived references unintentionally, you extend their lifetime. That can lead to memory retention that is difficult to spot.&lt;/p&gt;

&lt;p&gt;This is not a reason to avoid closures. It is a reason to understand them well enough to use them deliberately.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A more accurate mental model&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After spending time with closures in real code, the most accurate mental model I have found is this:&lt;/p&gt;

&lt;p&gt;A closure is not something you create.&lt;br&gt;
A closure is something that remains.&lt;/p&gt;

&lt;p&gt;It is the result of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;lexical scoping&lt;/li&gt;
&lt;li&gt;name resolution&lt;/li&gt;
&lt;li&gt;reference reachability&lt;/li&gt;
&lt;li&gt;delayed or repeated execution&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When these conditions align, a closure exists.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why it is okay that closures take time&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Closures sit below the surface of JavaScript. You can write code for years without naming them explicitly. That does not mean you are not using them. It means the language is doing its job.&lt;/p&gt;

&lt;p&gt;Understanding closures deeply requires encountering unexpected behaviour, tracing execution mentally, and thinking about memory rather than just output.&lt;/p&gt;

&lt;p&gt;That is not beginner work.&lt;/p&gt;

&lt;p&gt;If closures took you a while to understand, that is not a failure. It is part of becoming fluent.&lt;/p&gt;

&lt;p&gt;They took me a while too.&lt;/p&gt;

&lt;p&gt;And that is okay.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Further reading&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The ideas in this article were shaped over time by reading and experience. These resources were especially helpful:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;JavaScript from Beginner to Professional. For practical reinforcement of function scope and nested behaviour. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Eloquent JavaScript (4th Edition) by Marijn Haverbeke. For building intuition around nested scope and environments.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Clean Code in JavaScript by James Padolsey. For connecting closures to encapsulation, maintainability, and intentional design.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>learning</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Synthetic Data Is Not About Replacing Reality. It Is About Questioning It.</title>
      <dc:creator>Ibim</dc:creator>
      <pubDate>Sat, 20 Dec 2025 00:23:33 +0000</pubDate>
      <link>https://forem.com/intelgreatnez/synthetic-data-is-not-about-replacing-reality-it-is-about-questioning-it-4m2p</link>
      <guid>https://forem.com/intelgreatnez/synthetic-data-is-not-about-replacing-reality-it-is-about-questioning-it-4m2p</guid>
      <description>&lt;p&gt;There is a quiet moment many of us reach when working with data and machine learning.&lt;/p&gt;

&lt;p&gt;The model performs well.&lt;br&gt;
The metrics look reassuring.&lt;br&gt;
The pipeline feels complete.&lt;/p&gt;

&lt;p&gt;And yet, something does not sit right. Not because the system is broken. But because we are not convinced it is fair.&lt;/p&gt;

&lt;p&gt;This is where synthetic data becomes more than a technical tool.&lt;br&gt;
It becomes a way to ask uncomfortable questions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Hidden Problem With Real World Data&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We often talk about real world data as if it is neutral. It is not.&lt;/p&gt;

&lt;p&gt;Hiring data reflects decades of unequal access to education, employment, and opportunity. Healthcare data reflects who was diagnosed, who was believed, and who was ignored. Behavioural datasets reflect cultural norms and economic pressures.&lt;/p&gt;

&lt;p&gt;When AI systems are trained purely on historical data, they do not learn fairness. They learn patterns. And many of those patterns are shaped by inequality. This is not a philosophical argument. It is a statistical one.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What Synthetic Data Actually Is&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Synthetic data is artificially generated data that mimics the structure and statistical properties of real datasets, without representing real individuals. It is not created for humans to read. It is created for systems to learn from, or to be tested against. This distinction matters.&lt;/p&gt;

&lt;p&gt;Synthetic CVs are not meant to apply for jobs.&lt;br&gt;
Synthetic patient records are not meant to describe real people.&lt;br&gt;
Synthetic handwriting samples are not meant to replace human writing.&lt;/p&gt;

&lt;p&gt;They exist to allow experimentation without harm.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Synthetic Data as a Controlled Lens&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One of the most powerful properties of synthetic data is control. In the real world, you cannot ethically do the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Take a job applicant.&lt;/li&gt;
&lt;li&gt;Change only their name.&lt;/li&gt;
&lt;li&gt;Or their age.&lt;/li&gt;
&lt;li&gt;Or a single line mentioning a disability.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then re-run the application. With synthetic data, you can.&lt;/p&gt;

&lt;p&gt;Research on synthetic CV generation for fairness testing shows how artificial applicant profiles can be created where all variables are held constant except one. This allows researchers and practitioners to observe how automated hiring systems respond to specific demographic changes without involving real candidates or breaching privacy obligations (Saldivar, Gatzioura, Castillo, 2025).&lt;/p&gt;

&lt;p&gt;When outcomes change under these controlled conditions, bias becomes visible. Not as an accusation. But as behaviour.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lessons From Healthcare and Rare Disease Research&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Some of the most mature work on synthetic data comes from healthcare. In rare disease research, data is scarce, sensitive, and heavily regulated. Sharing real patient records is often impossible.&lt;/p&gt;

&lt;p&gt;Research into privacy preserving synthetic data generation shows how generative models can create realistic patient profiles that allow analysis, model training, and collaboration without exposing personal information (Mendes, Barbar, Refaie, 2025).&lt;/p&gt;

&lt;p&gt;But these studies also highlight something important.&lt;/p&gt;

&lt;p&gt;Synthetic data reflects the quality of the data it is generated from. If the original dataset is biased or incomplete, the synthetic data will inherit those weaknesses. This lesson transfers directly to hiring systems. Synthetic data is not automatically fair. It must be designed with intent.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Representation Matters More Than Volume&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Another important insight comes from handwriting recognition research.&lt;/p&gt;

&lt;p&gt;Some languages and writing styles are poorly represented in public datasets. As a result, models perform well for some populations and poorly for others.&lt;/p&gt;

&lt;p&gt;Research on handwriting recognition shows that large scale synthetic datasets are often required to capture enough variation for models to generalise properly, especially when real data is limited (Pham Thach Thanh Truc et al., 2025). The takeaway is simple.&lt;/p&gt;

&lt;p&gt;If certain groups are missing from the data, the system will struggle with them. This applies to CVs, medical records, and any system that interacts with human diversity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What Robotics Teaches Us About Synthetic Worlds&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Robotics offers a useful warning.&lt;/p&gt;

&lt;p&gt;In robotic learning, simulation is widely used because collecting real world data is expensive and slow. However, research on robotic bin packing shows that systems trained only in idealised synthetic environments often fail when deployed in real conditions (Wang et al., 2025).&lt;/p&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;p&gt;Because reality is messy.&lt;/p&gt;

&lt;p&gt;Objects behave unpredictably.&lt;br&gt;
Lighting changes.&lt;br&gt;
Constraints shift.&lt;/p&gt;

&lt;p&gt;The same principle applies to synthetic data used for fairness testing. If synthetic CVs are too clean, too linear, or too idealised, fairness evaluations become misleading. Real careers are rarely neat.&lt;/p&gt;

&lt;p&gt;People change paths.&lt;br&gt;
Take breaks.&lt;br&gt;
Move countries.&lt;br&gt;
Care for others.&lt;/p&gt;

&lt;p&gt;Synthetic data must reflect this complexity if it is to reveal meaningful bias.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Synthetic Data Does Not Eliminate Bias Automatically&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This point is worth stating clearly. Synthetic data does not fix bias on its own. Generative models learn patterns. They do not understand ethics or social context. If historical data encodes inequality, a naive synthetic generator will reproduce it.&lt;/p&gt;

&lt;p&gt;This is why recent research emphasises constraints, validation, and domain knowledge when generating synthetic datasets, particularly in sensitive domains such as healthcare and employment (Mendes et al., 2025).&lt;/p&gt;

&lt;p&gt;Synthetic data is a tool.&lt;br&gt;
Fairness depends on how it is used.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Synthetic Data Forces Honesty&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There is something quietly powerful about synthetic data.&lt;/p&gt;

&lt;p&gt;It removes excuses.&lt;/p&gt;

&lt;p&gt;When systems can be tested under controlled conditions, bias can no longer hide behind noise or complexity.&lt;/p&gt;

&lt;p&gt;If a hiring model behaves unfairly when only one variable is changed, the issue is structural.&lt;/p&gt;

&lt;p&gt;Synthetic data does not accuse.&lt;br&gt;
It reveals.&lt;/p&gt;

&lt;p&gt;And that is precisely why it matters.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Looking Ahead&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Synthetic data is often described as artificial.&lt;/p&gt;

&lt;p&gt;But its impact is real.&lt;/p&gt;

&lt;p&gt;It shapes how we test AI systems.&lt;br&gt;
How we protect privacy.&lt;br&gt;
How we detect bias.&lt;br&gt;
How we imagine fairer alternatives.&lt;/p&gt;

&lt;p&gt;Used carelessly, it can reinforce historical inequality.&lt;br&gt;
Used thoughtfully, it can help us challenge it.&lt;/p&gt;

&lt;p&gt;Synthetic data is not about replacing reality.&lt;/p&gt;

&lt;p&gt;It is about questioning the systems we build from it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;References&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Saldivar, J., Gatzioura, A., Castillo, C. (2025).&lt;br&gt;
Synthetic CVs to Build and Test Fairness-Aware Hiring Tools.&lt;br&gt;
ACM Transactions on Intelligent Systems and Technology.&lt;/p&gt;

&lt;p&gt;Mendes, M., Barbar, F., Refaie, A. (2025).&lt;br&gt;
Synthetic Data Generation: A Privacy-Preserving Approach to Accelerate Rare Disease Research.&lt;br&gt;
Frontiers in Digital Health.&lt;/p&gt;

&lt;p&gt;Pham Thach Thanh Truc et al. (2025).&lt;br&gt;
HTR-ConvText: Leveraging Convolution and Textual Information for Handwritten Text Recognition.&lt;br&gt;
arXiv preprint.&lt;/p&gt;

&lt;p&gt;Wang, Z. et al. (2025).&lt;br&gt;
RoboBPP: Benchmarking Robotic Online Bin Packing with Physics-Based Simulation.&lt;br&gt;
arXiv preprint.&lt;/p&gt;

&lt;p&gt;MIT Technology Review&lt;br&gt;
What synthetic data is and why it matters for AI&lt;br&gt;
&lt;a href="https://www.technologyreview.com" rel="noopener noreferrer"&gt;https://www.technologyreview.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nature News and Comment&lt;br&gt;
How artificial data could help address bias in AI&lt;br&gt;
&lt;a href="https://www.nature.com" rel="noopener noreferrer"&gt;https://www.nature.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;OECD AI Policy Observatory&lt;br&gt;
Fairness, transparency, and accountability in AI&lt;br&gt;
&lt;a href="https://oecd.ai" rel="noopener noreferrer"&gt;https://oecd.ai&lt;/a&gt;&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>machinelearning</category>
      <category>ai</category>
      <category>datascience</category>
    </item>
    <item>
      <title>JavaScript Did not Crash. That Does not Mean It is Fine.</title>
      <dc:creator>Ibim</dc:creator>
      <pubDate>Sat, 01 Nov 2025 20:51:57 +0000</pubDate>
      <link>https://forem.com/intelgreatnez/-javascript-didnt-crash-that-doesnt-mean-its-fine-5cnd</link>
      <guid>https://forem.com/intelgreatnez/-javascript-didnt-crash-that-doesnt-mean-its-fine-5cnd</guid>
      <description>&lt;p&gt;When you first start learning to code, you usually expect two outcomes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1.  It works&lt;/li&gt;
&lt;li&gt;2.  It explodes and tells you what went wrong.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  JavaScript has a secret third option:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;3.  It does something questionable, keeps going, and says nothing.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That quiet behaviour is what I mean when I say: &lt;strong&gt;JavaScript often fails silently&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Your code can be doing the wrong thing, and the language will not always warn you. In this article, I want to show you how that happens, why it happens, and a few habits that help you protect yourself from it.&lt;/p&gt;




&lt;h3&gt;
  
  
  1. JavaScript Will "Fix" Your Types For You
&lt;/h3&gt;

&lt;p&gt;JavaScript is very eager to guess what you meant.&lt;/p&gt;

&lt;p&gt;For example:&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="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;12&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 4&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let us pause there.&lt;/p&gt;

&lt;p&gt;"12" is a string. It is text. In many other languages, doing maths on text would throw an error.&lt;/p&gt;

&lt;p&gt;JavaScript does not throw. It says, basically: “Oh, you probably meant the number 12,” quietly converts the string to a number, and gives you 4.&lt;/p&gt;

&lt;p&gt;No warning. No complaint. It just proceeds.&lt;/p&gt;

&lt;p&gt;Now look at this one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const result2 = "12" + 3;
console.log(result2); // "123"
Same "12", same 3, totally different behaviour.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Why?
&lt;/h3&gt;

&lt;p&gt;With / (division), JavaScript says “this is maths” and does number maths.&lt;/p&gt;

&lt;p&gt;With +, JavaScript says “this might be string joining” and glues them together into "123".&lt;/p&gt;

&lt;p&gt;In other words: the operator you choose can silently change how your data is treated.&lt;/p&gt;

&lt;p&gt;Your program technically "works", but maybe not in the way you thought.&lt;/p&gt;

&lt;p&gt;This automatic behaviour is called type coercion. JavaScript tries to convert things into a type that allows the operation to continue instead of stopping the program.&lt;/p&gt;

&lt;p&gt;This is helpful sometimes. It also means you can ship a logic bug without realising it.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. You Can Create a Global Variable By Accident
&lt;/h3&gt;

&lt;p&gt;Watch this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;accidentalValue = 10;
console.log(accidentalValue); // 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Look closely. There is no &lt;code&gt;let&lt;/code&gt;, no &lt;code&gt;const&lt;/code&gt;, no &lt;code&gt;var&lt;/code&gt;. You never declared &lt;code&gt;accidentalValue&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In many languages, this would immediately throw something like “ReferenceError: variable not defined”.&lt;/p&gt;

&lt;p&gt;In normal (non-strict) JavaScript, it quietly creates a global variable with that name. The code continues.&lt;/p&gt;

&lt;p&gt;So a pure mistake (a typo, or you forgot l`et) becomes part of your program's state.&lt;/p&gt;

&lt;p&gt;That is dangerous because:&lt;/p&gt;

&lt;p&gt;You did not plan for it.&lt;/p&gt;

&lt;p&gt;It can leak into other parts of the code.&lt;/p&gt;

&lt;p&gt;You may not realise where it came from.&lt;/p&gt;

&lt;p&gt;Now compare that to strict mode:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;accidentalValue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// ReferenceError: accidentalValue is not defined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;With "use strict";, JavaScript finally shouts. This is the behaviour most people expect by default, but it is not the default in older or looser code.&lt;/p&gt;

&lt;p&gt;So here is the key point:&lt;br&gt;
Without strict mode, JavaScript sometimes lets you make a mistake quietly and keeps going.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Maths Can Go Wrong Without Throwing an Error
&lt;/h3&gt;

&lt;p&gt;Consider this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function getAverage(numbers) {
  const total = numbers.reduce((sum, n) =&amp;gt; sum + n);
  return total / numbers.length;
}

console.log(getAverage([])); // NaN
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We passed in an empty array.&lt;/p&gt;

&lt;p&gt;Mathematically, “average of nothing” does not make sense. Some languages will force you to handle that case.&lt;/p&gt;

&lt;p&gt;JavaScript does not force you. It just returns &lt;code&gt;NaN&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;NaN&lt;/code&gt; means “Not a Number”, and it is JavaScript’s way of saying “this calculation is not valid”. But it does not throw. The code still runs.&lt;/p&gt;

&lt;p&gt;Now imagine this in an app:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const averageScore = getAverage(userScores);

if (averageScore &amp;gt; 80) {
  unlockBadge();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If &lt;code&gt;averageScore&lt;/code&gt; is &lt;code&gt;NaN&lt;/code&gt;, then &lt;code&gt;averageScore &amp;gt; 80&lt;/code&gt; is always false. So maybe &lt;code&gt;unlockBadge()&lt;/code&gt; never runs, and you are sitting there thinking: “Why is this feature broken?” with no obvious error message.&lt;/p&gt;

&lt;p&gt;So again: not loud, just quietly wrong.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Missing Data Just Becomes &lt;code&gt;undefined&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Let us say you have:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const user = {
  name: "Amina"
};

console.log(user.age); // undefined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;There is no &lt;code&gt;age&lt;/code&gt; on &lt;code&gt;user&lt;/code&gt;. In many languages, asking for something that does not exist would crash or complain loudly.&lt;/p&gt;

&lt;p&gt;JavaScript simply answers: &lt;code&gt;undefined&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;No error. No warning. Just “I do not have that, so here is &lt;code&gt;undefined&lt;/code&gt;.”&lt;/p&gt;

&lt;p&gt;Now here is why that is sneaky:&lt;/p&gt;

&lt;p&gt;If you expected &lt;code&gt;user.age&lt;/code&gt; to be there, you might assume &lt;code&gt;undefined&lt;/code&gt; means “it exists but it's empty”.&lt;/p&gt;

&lt;p&gt;But that is not true. It just is not there at all.&lt;/p&gt;

&lt;p&gt;This is the kind of small difference that can break logic later without an obvious moment where the program shouts “something is wrong”.&lt;/p&gt;

&lt;p&gt;Even worse with typos:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const profile = {
  displayName: "Riya"
};

console.log(profile.dispayName); // undefined (typo!)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You misspelled &lt;code&gt;displayName&lt;/code&gt; as &lt;code&gt;dispayName&lt;/code&gt;. You do not get an error about the typo. You just quietly get &lt;code&gt;undefined&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Then you pass that &lt;code&gt;undefined&lt;/code&gt; around, and the bug is now somewhere else in your code.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Equality Can Lie To You
&lt;/h3&gt;

&lt;p&gt;JavaScript actually has two main equality operators: &lt;code&gt;==&lt;/code&gt; and &lt;code&gt;===&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;They are not the same.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;==&lt;/code&gt; is “loose equality.” It will try to convert values in order to compare them. This sounds friendly. It is also how you get silent bugs like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(false == 0); // true
console.log("" == 0);    // true
console.log("0" == 0);   // true
console.log(null == undefined); // true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Look at the second one.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"" == 0 // true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;An empty string is considered equal to the number zero.&lt;/p&gt;

&lt;p&gt;Now imagine you do this in your code:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const userInput = "";

if (userInput == 0) {
  console.log("User typed zero.");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;That &lt;code&gt;if&lt;/code&gt; block runs, even though the user did not type &lt;code&gt;0&lt;/code&gt;. They typed nothing.&lt;/p&gt;

&lt;p&gt;This is a bug pretending to be valid behaviour.&lt;/p&gt;

&lt;p&gt;Now compare with strict equality:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(false === 0); // false
console.log("" === 0);    // false
console.log("0" === 0);   // false
console.log(null === undefined); // false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;code&gt;===&lt;/code&gt; (triple equals) does not try to convert the values for you. It checks both value and type. This makes weird behaviour much harder to hide.&lt;/p&gt;

&lt;p&gt;So, general rule:&lt;br&gt;
Use &lt;code&gt;===&lt;/code&gt; unless you have a very specific reason not to.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Why Does JavaScript Behave Like This?
&lt;/h3&gt;

&lt;p&gt;Short version: history.&lt;/p&gt;

&lt;p&gt;JavaScript was created in the 1990s to run inside web browsers. It was designed very quickly, and the target user was not a full-time software engineer. It was “let normal people add behaviour to web pages.”&lt;/p&gt;

&lt;p&gt;In that world, if JavaScript crashed hard every time something was off, entire web pages would just break. That would be a terrible experience for people browsing the web.&lt;/p&gt;

&lt;p&gt;So the language leaned toward:&lt;/p&gt;

&lt;p&gt;"Keep the page running."&lt;/p&gt;

&lt;p&gt;"Try to guess what they meant."&lt;/p&gt;

&lt;p&gt;"Do not shout unless you absolutely must."&lt;/p&gt;

&lt;p&gt;Also, early JavaScript did not even have proper exception handling. Exceptions became standard later on (in ECMAScript 3). Before that, failing loudly in a controlled way was not really part of the design.&lt;/p&gt;

&lt;p&gt;Now, years later, a lot of that behaviour is still around. Even if some of it is confusing, you cannot just remove it, because it would instantly break millions of existing websites.&lt;/p&gt;

&lt;p&gt;That is the cost of being the language of the web: every old decision becomes permanent.&lt;/p&gt;

&lt;h3&gt;
  
  
  7. How To Protect Yourself (Practical Tips)
&lt;/h3&gt;

&lt;p&gt;You do not have to memorise the entire JavaScript spec to be safe. You just need a few habits that make silent problems louder.&lt;/p&gt;




&lt;h3&gt;
  
  
  1. Use &lt;code&gt;===&lt;/code&gt; instead of &lt;code&gt;==&lt;/code&gt;
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (userInput === 0) {
  console.log("User typed zero.");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now JavaScript will not do any behind-the-scenes conversion. If the types do not match, it will simply return false.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Use &lt;code&gt;"use strict"&lt;/code&gt;;
&lt;/h3&gt;

&lt;p&gt;At the top of your file or function, write:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
"use strict";

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Ths will force JavaScript to complain when you do dangerous things like create accidental globals.&lt;/p&gt;

&lt;p&gt;Without strict mode:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
accidentalValue = 10; // ReferenceError

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;With strict mode:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
"use strict"
accidentalValue = 10; //ReferenceError

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This is good. You want that error early.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Check numbers that come from user input or division
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const result = someCalculation();

if (!Number.isFinite(result)) {
  console.error("Result is not a normal number:", result);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This catches cases like &lt;code&gt;Infinity&lt;/code&gt;, &lt;code&gt;-Infinity&lt;/code&gt;, and &lt;code&gt;NaN&lt;/code&gt; right away, instead of letting them poison later logic.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Treat &lt;code&gt;undefined&lt;/code&gt; as a signal, not “oh well”
&lt;/h3&gt;

&lt;p&gt;If you expected the data to exist, throw or log where it first goes missing.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (user.age === undefined) {
  console.error("User age is missing, expected a value.");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Make the problem loud on purpose.&lt;/p&gt;




&lt;p&gt;Final Thought&lt;/p&gt;

&lt;p&gt;JavaScript was designed to be friendly and forgiving. It tries very hard not to break the page. That is nice for users.&lt;/p&gt;

&lt;p&gt;But for you, as a developer, that also means this:&lt;br&gt;
Your code can be wrong and keep running.&lt;/p&gt;

&lt;p&gt;This is why debugging JavaScript sometimes feels like guessing in the dark. There is no big red alarm. Just slightly “off” behaviour.&lt;/p&gt;

&lt;p&gt;So any time something feels off, add a &lt;code&gt;console.error(...)&lt;/code&gt; or a guard and make the bug noisy early.&lt;/p&gt;

&lt;p&gt;In JavaScript, silence is not always safety. Sometimes it is the bug.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>programming</category>
    </item>
    <item>
      <title>Imperative versus Declarative in Flutter</title>
      <dc:creator>Ibim</dc:creator>
      <pubDate>Wed, 20 Aug 2025 08:38:06 +0000</pubDate>
      <link>https://forem.com/intelgreatnez/imperative-versus-declarative-in-flutter-3f5n</link>
      <guid>https://forem.com/intelgreatnez/imperative-versus-declarative-in-flutter-3f5n</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftc697jgyeklu8q3xgo54.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftc697jgyeklu8q3xgo54.jpg" alt=" " width="800" height="451"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;There are two common ways to build screens. Imperative code tells the computer exactly what to do, step by step. Declarative code describes what the screen should look like for the current state, and the framework updates it for you. Flutter encourages the declarative way. This post keeps things simple, shows tiny examples, and gives a clear path to try the ideas on your own device.&lt;/p&gt;

&lt;h3&gt;
  
  
  A calm starting point
&lt;/h3&gt;

&lt;p&gt;Imagine a small screen that shows a list of books. There is a loading spinner, and sometimes an error message. On a busy day the old list stays visible under the error card. You fix one path, another breaks. It feels fragile. A change of style can help.&lt;/p&gt;




&lt;h3&gt;
  
  
  Two ways to think
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Imperative: change what already exists. Show the spinner, hide the list, replace the text. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Declarative: say what the &lt;code&gt;screen&lt;/code&gt; should be for this state. If loading, return a spinner. If ready, return a list.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;An everyday picture helps. If a friend asks for directions to your flat:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Imperative sounds like this. Turn left at the bakery, walk past the park, take the third right, press the second buzzer.  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Declarative sounds like this. Number 18, Willow Road, the blue door.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One is a list of steps. The other is the intended result.&lt;/p&gt;




&lt;h3&gt;
  
  
  A small imperative example
&lt;/h3&gt;

&lt;p&gt;This short example is from the classic Android view system. You flip visibility by hand and push data into the list.&lt;/p&gt;

&lt;h3&gt;
  
  
  Kotlin
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Small, imperative example in Kotlin

sealed interface ScreenState
object Loading : ScreenState
data class Ready(val items: List&amp;lt;String&amp;gt;) : ScreenState

fun render(
  state: ScreenState,
  spinner: View,
  list: RecyclerView,
  adapter: ListAdapter&amp;lt;String, *&amp;gt;
) {
  spinner.visibility = if (state is Loading) View.VISIBLE else View.GONE
  list.visibility    = if (state is Ready)   View.VISIBLE else View.GONE

  if (state is Ready) {
    adapter.submitList(state.items)
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is clear when there are only two states. It becomes easy to miss a line when more states appear. That is when yesterday’s content sometimes remains visible. That approach works, but it does not scale well. Let us now see how Flutter encourages a different style.&lt;/p&gt;




&lt;h3&gt;
  
  
  A small declarative example with setState
&lt;/h3&gt;

&lt;p&gt;Now the same idea with Flutter. We describe the whole screen from the current state. There is a single source of truth, the &lt;code&gt;screen&lt;/code&gt; value.&lt;/p&gt;

&lt;p&gt;How to try this now&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;"Create a new Flutter project."&lt;/li&gt;
&lt;li&gt;"Replace &lt;code&gt;lib/main.dart&lt;/code&gt; with the code below."&lt;/li&gt;
&lt;li&gt;"Run the application and tap the button."
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import 'package:flutter/material.dart';

// Two simple states for the screen
enum Screen { loading, ready }

// A tiny value object for books
class Book {
  final String title;
  final String author;
  const Book(this.title, this.author);
}

void main() =&amp;gt; runApp(const MaterialApp(home: BooksDemo()));

class BooksDemo extends StatefulWidget {
  const BooksDemo({super.key});
  @override
  State&amp;lt;BooksDemo&amp;gt; createState() =&amp;gt; _BooksDemoState();
}

class _BooksDemoState extends State&amp;lt;BooksDemo&amp;gt; {
  Screen screen = Screen.loading;
  List&amp;lt;Book&amp;gt; items = const [];

  Future&amp;lt;void&amp;gt; load() async {
    setState(() =&amp;gt; screen = Screen.loading);
    await Future&amp;lt;void&amp;gt;.delayed(const Duration(seconds: 1));
    setState(() {
      items = const [
        Book('Practical Flutter', 'Sara Conte'),
        Book('Patterns for Mobile', 'Leo Ahmed'),
      ];
      screen = Screen.ready;
    });
  }

  @override
  void initState() {
    super.initState();
    load(); // start loading as soon as the screen appears
  }

  @override
  Widget build(BuildContext context) {
    // Describe the whole screen from the current state
    if (screen == Screen.loading) {
      return const Scaffold(
        body: Center(child: CircularProgressIndicator()),
      );
    }

    // Ready state
    return Scaffold(
      appBar: AppBar(title: const Text('Books')),
      body: ListView.builder(
        itemCount: items.length,
        itemBuilder: (_, i) =&amp;gt; ListTile(
          title: Text(items[i].title),
          subtitle: Text('By ${items[i].author}'),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: load,
        child: const Icon(Icons.refresh),
      ),
    );
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;What to notice&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The first thing to notice is that there is no manual show or hide. You are not juggling visibility flags or remembering what was visible before. Instead, you simply describe the tree as it should look right now, and Flutter handles the rebuilding for you.&lt;/p&gt;

&lt;p&gt;Another detail is the absence of leftover state. Because you always return the correct tree for the current value, yesterday’s content does not accidentally leak into today’s frame.&lt;/p&gt;

&lt;p&gt;You might also see that this approach reduces side effects. You are not nudging old widgets into place, you are just returning the correct shape for the moment.&lt;/p&gt;

&lt;p&gt;And finally, it becomes easier to test. You can say: given this state, I expect a spinner. Or: given that state, I expect this text or a certain number of tiles. That clarity is a direct payoff of the declarative style. The key point is that you focus on describing the state, not on hiding or showing parts by hand. With that in mind, let us try a small example where the user taps a switch.&lt;/p&gt;

&lt;h3&gt;
  
  
  A very gentle user input example
&lt;/h3&gt;

&lt;p&gt;Here is a tiny settings screen. It has a dark mode switch. When the switch changes, the app theme changes. No manual updates to labels. No hidden toggles.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import 'package:flutter/material.dart';

void main() =&amp;gt; runApp(const ThemeDemo());

class ThemeDemo extends StatefulWidget {
  const ThemeDemo({super.key});
  @override
  State&amp;lt;ThemeDemo&amp;gt; createState() =&amp;gt; _ThemeDemoState();
}

class _ThemeDemoState extends State&amp;lt;ThemeDemo&amp;gt; {
  bool dark = false;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      themeMode: dark ? ThemeMode.dark : ThemeMode.light,
      theme: ThemeData.light(),
      darkTheme: ThemeData.dark(),
      home: Scaffold(
        appBar: AppBar(title: const Text('Settings')),
        body: ListTile(
          title: const Text('Dark mode'),
          trailing: Switch(
            value: dark,
            onChanged: (v) =&amp;gt; setState(() =&amp;gt; dark = v),
          ),
        ),
      ),
    );
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The widget tree is a clear reflection of state. If &lt;code&gt;dark&lt;/code&gt; is true, the dark theme is used. If it is false, the light theme is used.&lt;/p&gt;




&lt;h3&gt;
  
  
  A simple form that reacts to state
&lt;/h3&gt;

&lt;p&gt;This shows how a small form can feel declarative. The message appears when the name is too short. There is no manual show or hide scattered around.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class NameForm extends StatefulWidget {
  const NameForm({super.key});
  @override
  State&amp;lt;NameForm&amp;gt; createState() =&amp;gt; _NameFormState();
}

class _NameFormState extends State&amp;lt;NameForm&amp;gt; {
  String name = '';

  @override
  Widget build(BuildContext context) {
    final isValid = name.trim().length &amp;gt;= 3;

    return Padding(
      padding: const EdgeInsets.all(16),
      child: Column(mainAxisSize: MainAxisSize.min, children: [
        TextField(
          decoration: const InputDecoration(labelText: 'Your name'),
          onChanged: (v) =&amp;gt; setState(() =&amp;gt; name = v),
        ),
        const SizedBox(height: 8),
        if (!isValid)
          const Text('Please enter at least three characters',
              style: TextStyle(color: Colors.red)),
        const SizedBox(height: 8),
        ElevatedButton(
          onPressed: isValid ? () {} : null,
          child: const Text('Continue'),
        ),
      ]),
    );
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The button enables itself when the state is valid. The error text appears only when needed. Clear and predictable.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Key differences you can feel&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Readability: Declarative code reads like a small list of states. Loading, ready, failed. The intent is visible.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Single source of truth: Keep a single state value. The tree is built from that value. Old values do not leak into new frames.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Fewer side effects: You are not nudging old widgets into shape. You are returning the correct shape for now.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Easier testing: You can say, given this state, I expect a spinner, or this text, or a certain number of tiles.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;When to choose which&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Small, local screens. Use the setState function. It is simple and fine.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Shared or cross screen state. Move state into a small model with Provider or Riverpod.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Many transitions and tricky flows. Consider Bloc for explicit events and clearer steps.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you are unsure, begin with the setState function. When the widget starts to feel busy, lift state into a model. You will feel the difference.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;A gentle way to migrate an old screen&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Write down the states. Loading, empty, ready, failed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create one state value and a single &lt;code&gt;if&lt;/code&gt; or &lt;code&gt;switch&lt;/code&gt; that returns the right body.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Extract small helper widgets for each branch.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Remove old show or hide code one piece at a time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add an explicit empty state if the list can be empty. That small decision prevents confusion later.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is steady work. It pays off quickly.&lt;/p&gt;




&lt;h3&gt;
  
  
  Takeaways you can use today
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Describe the screen from state rather than patching it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Keep a single source of truth.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Start small with the setState function. Lift state into a model when needed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Name states up front. It saves time and reduces accidental drift.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Flutter’s declarative style can feel unusual at first, but once you start, you will likely find your code easier to read, test, and grow. Start small, keep a single source of truth, and let the framework do the heavy lifting.&lt;/p&gt;

&lt;h2&gt;
  
  
  References:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.flutter.dev/get-started/flutter-for/declarative" rel="noopener noreferrer"&gt;Introduction to declarative UI – Flutter Docs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.flutter.dev/get-started/fundamentals/state-management" rel="noopener noreferrer"&gt;State management fundamentals – Flutter Docs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.flutter.dev/data-and-backend/state-mgmt/declarative" rel="noopener noreferrer"&gt;Start thinking declaratively – Flutter Docs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://bloclibrary.dev/" rel="noopener noreferrer"&gt;Bloc State Management Library&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://iainsmith.me/blog/flutter-declarative-ui-toolkit" rel="noopener noreferrer"&gt;Flutter – a modern declarative UI toolkit&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.dhiwise.com/post/declarative-ui-vs-imperative-ui-in-flutter-development" rel="noopener noreferrer"&gt;Declarative UI vs. Imperative UI in Flutter – DhiWise&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.packtpub.com/en-us/product/flutter-design-patterns-and-best-practices-9781801072649" rel="noopener noreferrer"&gt;Flutter Design Patterns and Best Practices – Packt&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Navigating State and Effects in React: A Practical Guide</title>
      <dc:creator>Ibim</dc:creator>
      <pubDate>Wed, 30 Jul 2025 15:02:19 +0000</pubDate>
      <link>https://forem.com/intelgreatnez/navigating-state-and-effects-in-react-a-guide-for-the-intermediate-programmer-3h29</link>
      <guid>https://forem.com/intelgreatnez/navigating-state-and-effects-in-react-a-guide-for-the-intermediate-programmer-3h29</guid>
      <description>&lt;p&gt;Have you ever built a simple counter in React and thought there must be a better way to handle updates and side effects? I certainly have. When I first encountered the use of state and effects in React, it felt a little magical, and at times a bit opaque. In this short guide I will walk you through a hands‑on example that illustrates how state and effects play together, from the perspective of a developer who is not yet an expert but keen to level up.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why State Matters&lt;/strong&gt;&lt;br&gt;
State lets you store values that change over time, for example a score in a game or the number of unread messages. In React you declare state in a function component with a hook. Here is a simple counter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState } from 'react';

function Counter() {
  const [count, setCount] = useState(0);

  function handleClick() {
    setCount(count + 1);
  }

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;p&amp;gt;You clicked {count} times&amp;lt;/p&amp;gt;
      &amp;lt;button onClick={handleClick}&amp;gt;
        Click me
      &amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

export default Counter;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here the effect runs only when the count changes. That small addition demonstrates how React keeps the user interface and external systems in sync.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How It Flows&lt;/strong&gt;&lt;br&gt;
Let us look at a simple sequence diagram so you can picture what happens under the hood. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe963oku02e3xojbj4joi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe963oku02e3xojbj4joi.png" alt=" " width="800" height="474"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That diagram shows the chain of events from a user click to the effect that updates the document title.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Next Steps&lt;/strong&gt;&lt;br&gt;
Give this code a spin. Tinker with the dependency array of the effect hook and see what happens when you omit it or add other variables. Try adding a second effect that logs values to the console.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
