<?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: Jay Gurav</title>
    <description>The latest articles on DEV Community by Jay Gurav (@jaymgurav).</description>
    <link>https://dev.to/jaymgurav</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%2F261745%2F30b321cf-467a-40e3-8b83-59ba04d0d2e4.jpeg</url>
      <title>DEV Community: Jay Gurav</title>
      <link>https://dev.to/jaymgurav</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jaymgurav"/>
    <language>en</language>
    <item>
      <title>Single Responsibility Principle</title>
      <dc:creator>Jay Gurav</dc:creator>
      <pubDate>Fri, 15 Aug 2025 07:06:00 +0000</pubDate>
      <link>https://dev.to/jaymgurav/single-responsbility-principlesrp-3gck</link>
      <guid>https://dev.to/jaymgurav/single-responsbility-principlesrp-3gck</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;TL;DR: The Single Responsibility Principle (SRP) states that a module should be responsible to one, and only one, actor — an actor being a stakeholder or user group that may request changes to it. By giving each part of the system a single, well-defined responsibility, SRP improves clarity, cohesion, and maintainability while reducing complexity, avoiding unintended side effects, and producing cleaner, more adaptable software.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Lately I’ve been thinking about how software development is just breaking big, messy problems into smaller, less-messy ones. Then stitching them back together until they kind of resemble a system that does what we need. It's just composition.&lt;/p&gt;

&lt;p&gt;While software development is that, We’re developers not exactly… innocent, we are actors of crime in this process of development. We are chaos wrapped in logic. We bring our quirks, our opinions, our “I’ll just do it this way” moments. And that chaos leaks into the code. Suddenly, a single file is juggling five different concerns because, well, it felt efficient or pleased our fingers at the time. We complicate things by mixing together code that many people care about in many different ways.&lt;/p&gt;

&lt;p&gt;SRP(the Single Responsibility Principle) really comes into focus when you start breaking(decomposing) a problem apart. And when I sat with it for a while, I realized it's less about functions or classes and more about actors. Who cares about this piece of code? Who's impacted when it changes?&lt;/p&gt;

&lt;p&gt;Ironically, being the actors of crime, we’ve even misinterpret the very principle we're trying to follow. We try to apply the rule—and end up misunderstanding it. There's something oddly poetic about that. Feels like a reflection of humanity as a whole.&lt;/p&gt;

&lt;p&gt;More questions than answers right now. Behold.&lt;/p&gt;

&lt;h2&gt;
  
  
  World Interpreted
&lt;/h2&gt;

&lt;p&gt;The term &lt;em&gt;Single Responsibility Principle&lt;/em&gt; itself was coined by Robert Martin—better known in software circles as “Uncle Bob”—and rooted in an older design idea: cohesion.&lt;/p&gt;

&lt;p&gt;Cohesion is about how well the parts of a module fit together. Uncle Bob didn’t invent it—he openly credits Tom DeMarco and Meilir Page-Jones—but he took it somewhere new. He tied cohesion to the forces that make a module change, and in his early definition boiled it down to:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A class should have only one reason to change.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here, responsibility became synonymous with reason for change:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Responsibility = Reason for Change&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Sounds clean, right? A module has one reason to change—good. Michael Feathers echoed the same in &lt;a href="https://archive.org/details/working-effectively-with-legacy-code" rel="noopener noreferrer"&gt;Working Effectively with Legacy Code&lt;/a&gt;, putting it as:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Every class should have a single responsibility: It should have a single purpose in the system, and there should be only one reason to change it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;At first glance, this idea seems straightforward and obvious… until you actually try to define it. What exactly qualifies as a “reason”? Are we talking about technical changes? Business requirements? Design choices? All of them? The line blurs fast.&lt;/p&gt;

&lt;p&gt;To dig deeper into decomposing software, I read one of the works often linked to SRP: Parnas’s On the Criteria To Be Used in Decomposing Systems into Modules. Parnas compares two ways of breaking down systems:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Flowchart-based decomposition: splitting things by the order they happen.&lt;/li&gt;
&lt;li&gt;Information-hiding decomposition: splitting things by design decisions most likely to change later.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Parnas strongly advocates for the second approach — and for good reason arguing that a good system reflects the volatility of its design decisions, not the sequence of its operations. The “why” behind a module should be hidden, revealing only what others actually need. In short -put that choice into a module with an interface infront that hides the implementation details.&lt;/p&gt;

&lt;p&gt;Looping this back to SRP, and you see the connection:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If each module hides the implementation decision (Parnas), and&lt;/li&gt;
&lt;li&gt;If each module equals one responsibility (Martin),
…then modularity and responsibility are basically two ways of looking at the same thing.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The problem? Take it too literally, and you end up with a Frankenstein system—every possible reason for change locked in its own tiny module. You get hundreds of little pieces, all technically “SRP compliant,” but the big picture feels more like shattered glass than elegant architecture. This is not gut-fully convincing of a good system architecture and is clearly undesirable.&lt;/p&gt;

&lt;p&gt;And that’s the tricky part: SRP is easy to explain, easy to nod along to, but maddeningly slippery to implement in the real world. Which is exactly why Uncle Bob eventually clarified his definition—shifting the focus just from the abstract “reasons to change” toward who is driving that change and actor's ownership.&lt;/p&gt;

&lt;p&gt;That’s where SRP gets a lot more interesting—and a lot more useful.&lt;/p&gt;

&lt;h2&gt;
  
  
  Theory, History, and a Shift in Perspective
&lt;/h2&gt;

&lt;p&gt;So, here’s the thing: the way SRP is often explained? It’s not the whole picture. Over time, it’s been oversimplified, misquoted, and trimmed down until it fits neatly into a conference slide—but that’s not where the real depth lives.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"When you write a software module, you want to make sure that when changes are requested, those changes can only originate from a single person, or rather, a single tightly coupled group of people representing a single narrowly defined business function."  &lt;/p&gt;

&lt;p&gt;— &lt;a href="https://blog.cleancoder.com/uncle-bob/2014/05/08/SingleReponsibilityPrinciple.html" rel="noopener noreferrer"&gt;Robert Martin, &lt;em&gt;The Single Responsibility Principle&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is a subtle but important clarification that, It’s not just “a class should have one reason to change” in the abstract—it’s that reason should come from one clearly identifiable source of authority. One person. Or one tightly knit team. A single, well-defined business function.&lt;/p&gt;

&lt;p&gt;Why does that matter? Because software doesn’t just exist in code—it lives in organizations. If two different teams “own” a module, they’ll inevitably pull it in different directions. That’s how you get conflicting priorities, unclear ownership, and a maintenance nightmare.&lt;/p&gt;

&lt;p&gt;Now, pair this again with David Parnas’ technical angle:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If each module hides the implementation decision (Parnas), and&lt;/li&gt;
&lt;li&gt;the decision, reason of change should have one clear owner(Uncle Bob).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Put those together, and you get a richer picture:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Technical modularity keeps changes contained.&lt;/li&gt;
&lt;li&gt;Organizational clarity keeps ownership aligned.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In other words, SRP isn’t just about avoiding vague, multiple “reasons to change.” It’s about ensuring that when change happens, you know exactly who it’s coming from. That combination of design principle and organizational reality is what keeps systems healthy, maintainable, and, honestly, a lot less frustrating.&lt;/p&gt;

&lt;p&gt;Alright—enough theory. Let's take a look at a quick example&lt;/p&gt;

&lt;h2&gt;
  
  
  Fake Real-World Example
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Invoice&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;customer&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;Invoice&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;customer&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;customer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;customer&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;amount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="nf"&gt;calculateTotal&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Tax calculation logic&lt;/span&gt;
        &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;tax&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.15&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;tax&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;saveToDatabase&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Save to DB&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Saving invoice to database..."&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;printInvoice&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Print logic&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Printing invoice for customer: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;customer&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  What's wrong with this code?
&lt;/h3&gt;

&lt;p&gt;This class has &lt;strong&gt;multiple reasons to change&lt;/strong&gt;, each coming from a &lt;strong&gt;different group of people&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;calculateTotal()&lt;/code&gt; → Might change when the &lt;strong&gt;finance team&lt;/strong&gt; updates tax rules.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;saveToDatabase()&lt;/code&gt; → Might change when the &lt;strong&gt;database team&lt;/strong&gt; or &lt;strong&gt;devops&lt;/strong&gt; changes data persistence.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;printInvoice()&lt;/code&gt; → Might change when the &lt;strong&gt;UX/design team&lt;/strong&gt; wants to reformat printed invoices.
Each of these groups could request changes that would all modify this one class — that's exactly what SRP warns against.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Applying SRP: Split by Responsibility and ownership
&lt;/h3&gt;

&lt;h4&gt;
  
  
  1. &lt;code&gt;Invoice&lt;/code&gt; – Owned by &lt;strong&gt;Finance/Accounting&lt;/strong&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Invoice&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;customer&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;Invoice&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;customer&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;customer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;customer&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;amount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;getCustomer&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;customer&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="nf"&gt;getAmount&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="nf"&gt;calculateTotal&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;tax&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.15&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;tax&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2.&lt;code&gt;InvoiceRepository&lt;/code&gt; – Owned by &lt;strong&gt;Database/Infrastructure team&lt;/strong&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;InvoiceRepository&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Invoice&lt;/span&gt; &lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Save invoice to database&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Saving invoice for customer: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getCustomer&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
        &lt;span class="c1"&gt;// Simulate DB save logic...&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3.&lt;code&gt;InvoicePrinter&lt;/code&gt; – Owned by &lt;strong&gt;UX/Design or Docs team&lt;/strong&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;InvoicePrinter&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Invoice&lt;/span&gt; &lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Format and print invoice&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"----- Invoice -----"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Customer: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getCustomer&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Amount: $"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getAmount&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Total with Tax: $"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;calculateTotal&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"-------------------"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  4.Main class (Usage example)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Main&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Invoice&lt;/span&gt; &lt;span class="n"&gt;invoice&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Invoice&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Acme Corp"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;1000.00&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// Business team uses core logic&lt;/span&gt;
        &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;calculateTotal&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

        &lt;span class="c1"&gt;// Infrastructure team persists the invoice&lt;/span&gt;
        &lt;span class="nc"&gt;InvoiceRepository&lt;/span&gt; &lt;span class="n"&gt;repository&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;InvoiceRepository&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="n"&gt;repository&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;save&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// Presentation team handles invoice output&lt;/span&gt;
        &lt;span class="nc"&gt;InvoicePrinter&lt;/span&gt; &lt;span class="n"&gt;printer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;InvoicePrinter&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="n"&gt;printer&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;print&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Summary of Responsibilities
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Class&lt;/th&gt;
&lt;th&gt;Responsibility&lt;/th&gt;
&lt;th&gt;Owned by&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Invoice&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Business rules (tax, etc.)&lt;/td&gt;
&lt;td&gt;Finance team&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;InvoiceRepository&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Persistence (DB logic)&lt;/td&gt;
&lt;td&gt;Infrastructure/DB team&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;InvoicePrinter&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Presentation (formatting)&lt;/td&gt;
&lt;td&gt;UX/Design/Docs team&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;In this setup, each class has one responsibility and one clear owner.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If the finance team decides tax rules need tweaking, they update Invoice—and nothing else.&lt;/li&gt;
&lt;li&gt;If the database schema changes, the infrastructure team touches only InvoiceRepository.&lt;/li&gt;
&lt;li&gt;If the design team wants a prettier invoice layout, they go straight to InvoicePrinter.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;No stepping on each other’s toes. No “just one quick change” that accidentally breaks something unrelated.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why It Delivers Better Code
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;One reason to change by one actor → Clear boundaries between modules.&lt;/li&gt;
&lt;li&gt;Simpler maintenance → Changes happen in isolation, with fewer surprises.&lt;/li&gt;
&lt;li&gt;Readable code → Each class has a tight, obvious purpose.&lt;/li&gt;
&lt;li&gt;Better tests → Smaller, focused modules are easier to test (and trust).&lt;/li&gt;
&lt;li&gt;Loose coupling → One change doesn’t ripple through the whole codebase.&lt;/li&gt;
&lt;li&gt;Organizational alignment → Code ownership mirrors real-world team structures.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;SRP isn’t a one-and-done checklist item you tick during the initial design phase—it’s something to keep an eye on throughout the life of a project.&lt;/p&gt;

&lt;p&gt;If a module starts feeling heavy, juggling unrelated concerns, or attracting change requests from multiple teams, that’s your early warning sign: responsibilities are blurring. That’s the moment to refactor. The payoff? Clearer code, happier maintainers, and teams that can move independently without tripping over each other.&lt;/p&gt;

&lt;p&gt;I hope this article gave you a clearer understanding of the Single Responsibility Principle and its importance in software design. Let’s keep exploring good code together — and stay responsible.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;
&lt;a href="http://www.butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod" rel="noopener noreferrer"&gt;The Principles of OOD&lt;/a&gt; by Robert Martin&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://drive.google.com/file/d/0ByOwmqah_nuGNHEtcU5OekdDMkk/view?resourcekey=0-AbuGpXQzwZcUGExkktKt0g" rel="noopener noreferrer"&gt;The Single Responsibility Principle (2007)&lt;/a&gt; by Robert Martin&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://archive.org/details/working-effectively-with-legacy-code" rel="noopener noreferrer"&gt;Working Effectively with Legacy Code&lt;/a&gt; by Feathers, Michael C&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://dl.acm.org/doi/pdf/10.1145/361598.361623" rel="noopener noreferrer"&gt;On the Criteria To Be Used in Decomposing Systems into Modules&lt;/a&gt; by D.L. Parnas&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://blog.cleancoder.com/uncle-bob/2014/05/08/SingleReponsibilityPrinciple.html" rel="noopener noreferrer"&gt;The Single Responsibility Principle (2014)&lt;/a&gt; by Robert Martin&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://en.wikipedia.org/wiki/Single-responsibility_principle" rel="noopener noreferrer"&gt;Single Responsibility Principle&lt;/a&gt; on Wikipedia&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>java</category>
      <category>oop</category>
      <category>programmingprinciples</category>
      <category>cleancode</category>
    </item>
    <item>
      <title>Functions: Am I pure?</title>
      <dc:creator>Jay Gurav</dc:creator>
      <pubDate>Mon, 28 Jun 2021 15:16:30 +0000</pubDate>
      <link>https://dev.to/jaymgurav/functions-am-i-pure-17h9</link>
      <guid>https://dev.to/jaymgurav/functions-am-i-pure-17h9</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Pure functions are a nice idea—clean, predictable, and easy to &amp;gt;test. But in the messiness of real-world software, things aren't &amp;gt;always so... pure. This is me trying to untangle what purity means &amp;gt;in programming, why functional folks love it, and where it fits (or &amp;gt;doesn't) in the wild. &lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;If you hang around functional programmers long enough, you'll start to notice something: they really love pure functions. Like, really love them. There’s a kind of quiet reverence for these mythical creatures—functions that touch nothing, change nothing, and simply return a result, neat and tidy.&lt;/p&gt;

&lt;p&gt;And honestly? I get it. There’s a kind of elegance to the idea. But I also think that this obsession with purity—what it means, what it gives us—might be part of why functional programming can feel so out of step with how we actually build software.&lt;/p&gt;

&lt;p&gt;Because let’s be real: most of what we build in the real world isn’t all that pure.&lt;/p&gt;

&lt;p&gt;In this post, I’m going to try and unpack what a function actually is, what it means for one to be “pure,” and why that matters—or doesn’t—depending on what you’re doing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Functions, Flashbacks &amp;amp; Functional Programming
&lt;/h2&gt;

&lt;p&gt;Remember that one chapter in high school math—the one with functions and sets and domain-to-range mappings? If your brain just went foggy, don’t worry. Here’s the short version:&lt;/p&gt;

&lt;p&gt;A function is a way to turn an input into an output. That’s it.&lt;/p&gt;

&lt;p&gt;Mathematically, it’s a mapping from a “domain” (input set) to a “co-domain” (output set). Every input gets exactly one output. It’s tidy, predictable, and totally abstract—like a calculator You punch in &lt;code&gt;2 * 2&lt;/code&gt; and you always get &lt;code&gt;4&lt;/code&gt;. No surprises, no mood swings, no hidden dependencies. Just input → output.&lt;/p&gt;

&lt;p&gt;We can represent that kind of function easily in code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;square&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;x&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;Here, the square function takes a number and returns its square. That’s it. No surprises. You give it 2, you get 4. You give it 3, you get 9. Every time.&lt;/p&gt;

&lt;p&gt;But here’s the thing: real software doesn’t live in a vacuum. It runs in messy, complex environments where things are constantly changing, breaking, mutating, and talking to other things. And that’s where this whole “purity” conversation gets a little weird.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Does It Mean for a Function to Be “Pure”?
&lt;/h2&gt;

&lt;p&gt;A pure function is one that behaves like that math example above. Same input, same output, no cheating.&lt;/p&gt;

&lt;p&gt;But most of the time, our functions aren’t just math—they’re opening files, saving things to databases, talking to APIs, mutating DOM elements, throwing errors, logging things, catching exceptions, and so on.&lt;/p&gt;

&lt;p&gt;So let’s slow down and ask: what actually makes a function pure?&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Isolation
&lt;/h3&gt;

&lt;p&gt;A pure function is totally cut off from the world around it. It only knows what you tell it through its arguments. No peeking at global variables, no reaching into your app state, no relying on the system clock or database. It’s like being blindfolded and asked to solve a puzzle with only the pieces in your hands.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A pure function is isolated. What it does is entirely based on the &amp;gt;inputs you give it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  2. No Side Effects
&lt;/h3&gt;

&lt;p&gt;This is the big one. A side effect is anything a function does besides return a value. Examples include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Changing a variable outside the function&lt;/li&gt;
&lt;li&gt;Mutating the input&lt;/li&gt;
&lt;li&gt;Writing to a file or database&lt;/li&gt;
&lt;li&gt;Printing to the console&lt;/li&gt;
&lt;li&gt;Throwing an error&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In other words, side effects are everything that make a function not just a function—but part of a program that’s alive and doing stuff.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A pure function doesn’t change the world. It just gives you an &amp;gt;answer. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  3. Referential Transparency
&lt;/h3&gt;

&lt;p&gt;This is a fancy way of saying: if you replace a function call with its output, nothing breaks.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;double&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;double&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// is exactly the same as:&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you can do that and your program still behaves the same, congrats—your function is referentially transparent.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Referential transparency means your functions are predictable and &amp;gt;interchangeable with their outputs.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;double&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;double&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// is exactly the same as:&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you can do that and your program still behaves the same, congrats—your function is referentially transparent.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Referential transparency means your functions are predictable and &amp;gt;interchangeable with their outputs.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So... What’s the Big Deal?&lt;br&gt;
Pure functions are basically the ideal citizen in functional programming land. They’re predictable, testable, composable, and don’t cause trouble. They’re the kind of functions you want to be friends with—quiet, polite, never unexpectedly crash your program.&lt;/p&gt;

&lt;p&gt;Here’s the cheat sheet:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✅ No side effects&lt;/li&gt;
&lt;li&gt;✅ Input → Output only&lt;/li&gt;
&lt;li&gt;✅ Same input = same output (always)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also, pure functions are idempotent, which means you can call them a million times and get the same result every time. They’re kind of boring that way—in a good way.&lt;/p&gt;

&lt;p&gt;Why Testers Love Them&lt;br&gt;
One of the best parts about pure functions? They're a dream to test.&lt;/p&gt;

&lt;p&gt;When a function doesn’t rely on anything outside itself, you don’t have to mock a bunch of dependencies or set up elaborate test scaffolding. You just give it an input and check the output.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A pure function is a self-contained little logic machine—perfect &amp;gt;for unit tests.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Since they don’t depend on external state, and always return the same thing for the same input, they’re easy to verify, easy to debug, and hard to break.&lt;/p&gt;

&lt;p&gt;Okay, But Where’s the Catch?&lt;br&gt;
All of this sounds great. But remember what I said at the start?&lt;/p&gt;

&lt;p&gt;There’s not a whole lot of “purity” in most real-world applications.&lt;/p&gt;

&lt;p&gt;That’s because most useful programs need to do things. They need to save data, show things to the user, respond to the world. That means side effects. And side effects mean impurity.&lt;/p&gt;

&lt;p&gt;So while pure functions are amazing for logic, you still need a way to connect that logic to the messy, unpredictable world.&lt;/p&gt;

&lt;p&gt;Functional programming languages often solve this by separating the pure stuff from the impure stuff. You push all the messy, side-effect-laden code to the edges, and keep the core of your app clean and pure. This way, most of your logic can still be composed, tested, and reasoned about—even if the app itself still has to talk to a database eventually.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;I’m still figuring this all out, to be honest. The more I explore functional programming, the more I appreciate the beauty of pure functions—and the more I realize how rare they are in practice.&lt;/p&gt;

&lt;p&gt;But they’re worth striving for. Pure functions make your code easier to read, test, and trust. They let you build systems that are more predictable and less prone to surprising behavior. And even if you can’t go full-functional, just nudging your code in a purer direction can bring real benefits.&lt;/p&gt;

&lt;p&gt;So no, not every function has to be pure. But the more you can keep your logic clean, your dependencies explicit, and your code testable—the easier life tends to get.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Purity isn’t about being perfect. It’s about being intentional. &amp;gt;About knowing where the side effects live—and keeping them on a &amp;gt;short leash. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
That’s it for now. I hope this gives you a clearer picture of what pure functions are. Let’s keep learning.&lt;/p&gt;

&lt;p&gt;👉 This blogpost was originally publish at my personal &lt;a href="https://jaygurav.com/articles/01-functions-am-i-pure" rel="noopener noreferrer"&gt;blog site&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Get in touch
&lt;/h3&gt;

&lt;p&gt;Hey, have any suggestions, questions or concerns, You can find me &lt;a href="https://twitter.com/JayMGurav" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;, &lt;a href="https://github.com/jaymgurav/" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; and &lt;a href="https://linkedin.com/in/jaymgurav" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;. Help me make this better drop me a message and I’ll get back to you soon Thanks!🎉&lt;/p&gt;

</description>
      <category>programming</category>
      <category>javascript</category>
      <category>functional</category>
      <category>coding</category>
    </item>
  </channel>
</rss>
