<?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: Alson Garbuja</title>
    <description>The latest articles on DEV Community by Alson Garbuja (@alsongarbuja).</description>
    <link>https://dev.to/alsongarbuja</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%2F1458783%2F7c9ecbe1-1b6c-4bda-9719-af80ddc545fd.jpeg</url>
      <title>DEV Community: Alson Garbuja</title>
      <link>https://dev.to/alsongarbuja</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/alsongarbuja"/>
    <language>en</language>
    <item>
      <title>How Git manages to stay lean and fast ⚡?</title>
      <dc:creator>Alson Garbuja</dc:creator>
      <pubDate>Wed, 04 Mar 2026 08:34:19 +0000</pubDate>
      <link>https://dev.to/alsongarbuja/how-git-manages-to-stay-lean-and-fast--23c2</link>
      <guid>https://dev.to/alsongarbuja/how-git-manages-to-stay-lean-and-fast--23c2</guid>
      <description>&lt;p&gt;You launch a project, initialize Git, stage your changes, and commit. Boom. Just like that, you have version control—a permanent, searchable history of your work.&lt;/p&gt;

&lt;p&gt;As the project scales into something massive, the need for experimentation grows. You decide to build a complex new feature, so you spin up a branch. Bam. In seconds, you have a parallel sandbox where you can break things, fix them, and evolve your code without ever touching the stability of your main build.&lt;/p&gt;

&lt;p&gt;Yes, that is the power of Git. It is fast, efficient and stays leans even when your project is huge and complex.&lt;/p&gt;

&lt;p&gt;In this post, I will try to explain the behind the scene of how git manages to do it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Chapter 0: The three areas
&lt;/h3&gt;

&lt;p&gt;Imagine you are launching a new project. To ensure every move is recorded and the chaos of multiple contributors is kept at bay, you reach for a foundation: you initialize &lt;strong&gt;Git&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Git works by dividing your project into 3 distinct areas, &lt;strong&gt;Working, Staging, History/Snapshot.&lt;/strong&gt; &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%2Fto93anvjjxk1dg4gbzxh.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%2Fto93anvjjxk1dg4gbzxh.png" alt="The 3 areas of GIT: working, staging and snapshot" width="800" height="390"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Working area:&lt;/strong&gt; This is the area where you actually work and make changes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Staging area:&lt;/strong&gt; This area holds the changed and added files from the project.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Snapshot area:&lt;/strong&gt; Finally this area holds the history/snapshot of each commits.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So you make changes to the project and ready to use the power of GIT.&lt;/p&gt;

&lt;h3&gt;
  
  
  Chapter 1: Staging
&lt;/h3&gt;

&lt;p&gt;As soon as you stage your changes &lt;code&gt;(git add)&lt;/code&gt;, Git compresses the file content using &lt;strong&gt;zlib&lt;/strong&gt; and generates a &lt;strong&gt;SHA-1 hash&lt;/strong&gt;.&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%2Fnu2jodmqpzyef0ub3vxb.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%2Fnu2jodmqpzyef0ub3vxb.png" alt="Git compressing and generating SHA1 hash" width="800" height="230"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Why generate a hash instead of simply copying the changes to history? This hash acts as a unique digital fingerprint, enabling a superpower known as "&lt;strong&gt;deduplication&lt;/strong&gt;". Because the SHA-1 hash is derived strictly from the file's content, identical content always produces the identical hash.&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%2Fpk7523u8ttrca7t83mcz.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%2Fpk7523u8ttrca7t83mcz.png" alt="Same file in multiple location pointing to same SHA hash blob" width="800" height="291"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hence if you have the same file content across multiple locations in your project, Git doesn't store multiple copies of the data. Instead, it stores the compressed object once and simply points every instance to that same SHA-1 hash, saving a massive amount of storage space.&lt;/p&gt;

&lt;p&gt;To tie everything together, Git creates a mapping file known as the index &lt;code&gt;(located inside the .git directory)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Think of the index as the "staging map." It creates a direct link between your familiar file paths and the newly generated, compressed SHA-1 blobs. Instead of Git searching through your entire folder structure every time, it refers to this lean binary file to know exactly which version of a file belongs where.&lt;/p&gt;

&lt;p&gt;This index is the secret bridge that allows Git to track your workspace changes in real-time and prepare them for the final commit without any overhead.&lt;/p&gt;

&lt;h3&gt;
  
  
  Chapter 2: Commiting
&lt;/h3&gt;

&lt;p&gt;With your changes staged and ready for the history books, it’s time to secure them. You execute the command: &lt;code&gt;git commit -m "Your message"&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Under the hood, Git first validates the changes by looking at the difference between hashes from previous commit to new one. Then it extracts the authors metadata. Finally, Git creates a &lt;strong&gt;commit object&lt;/strong&gt;. This small text file contains the essentials: a unique commit ID, a pointer to the parent commit (linking it to the previous history), the author’s metadata, a timestamp, and your message. Compresses it and saves it.&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%2Fn9a9wvurjtr28nodn206.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%2Fn9a9wvurjtr28nodn206.png" alt="Git commit data structure" width="800" height="496"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Because Git has already compressed your files and generated their SHA-1 hashes during the staging phase, the "heavy lifting" is already done. Creating a commit is simply a matter of recording this new metadata and linking it to the existing chain. Your project's state is now officially captured as a permanent, lightweight snapshot in Git’s history.&lt;/p&gt;

&lt;h2&gt;
  
  
  Chapter 3: The tree
&lt;/h2&gt;

&lt;p&gt;Beyond just file blobs and commit objects, Git organizes your project using a &lt;strong&gt;Tree structure&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Think of a Tree object as a virtual directory. Each node in this tree stores essential metadata: the file mode (permissions), the type (is it a "blob" or another "tree"?), the SHA-1 hash, and the filename.&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%2Fqdi3jg0jzvuri52j55ue.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%2Fqdi3jg0jzvuri52j55ue.png" alt="A node in tree structure in git" width="800" height="344"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This hierarchical design is the secret to Git’s efficiency. When you modify a single file, Git doesn't need to rebuild your entire project structure. It simply traverses the shortest path to that specific leaf node. It updates only the affected nodes along that path while leaving the rest of the tree untouched, pointing back to the existing, unchanged hashes. &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%2Fqh6woawvxb737rf70iyy.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%2Fqh6woawvxb737rf70iyy.png" alt="Git tree structure for efficiency" width="800" height="781"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This surgical precision is exactly why staging and committing remain lightning-fast, regardless of how many thousands of files your project contains.&lt;/p&gt;

&lt;h2&gt;
  
  
  Chapter 4: Branch
&lt;/h2&gt;

&lt;p&gt;Your project has grown massive and complex, but a radical new idea strikes. You want to experiment without breaking your stable build. This is where Git reveals its true power: &lt;strong&gt;Branches&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;You might worry that such a huge project would make branching a slow, storage-heavy nightmare. Yet, the moment you run &lt;code&gt;git branch "branch-name"&lt;/code&gt;, the new branch appears instantly. You switch over, and in seconds, your entire workspace shifts.&lt;/p&gt;

&lt;p&gt;How is this possible? It lies in Git’s architectural genius. Instead of duplicating your entire history or copying files into a new folder, Git simply creates a &lt;strong&gt;41-byte text file&lt;/strong&gt;. This tiny file acts as a pointer, containing nothing more than the SHA-1 commit hash of the branch's tip.&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%2Fq3i50yr8n9tlv5j91hk0.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%2Fq3i50yr8n9tlv5j91hk0.png" alt="41 bytes size text file for branch in git" width="800" height="196"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Whenever you create a new commit, delete one, or roll back, Git doesn't move mountains; it just updates the hash inside that small text file. Since the chain of commit history is already linked through parent pointers, Git only needs to know the "head" of the chain to give you access to the entire timeline.&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%2Fy5u9iix5kc38lxu4g24y.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%2Fy5u9iix5kc38lxu4g24y.png" alt="Chain of commit for branching and history in GIT" width="800" height="220"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You might wonder: how does Git know which branch you are currently using? The answer is equally elegant. Inside the &lt;strong&gt;.git directory&lt;/strong&gt;, a file named &lt;strong&gt;HEAD&lt;/strong&gt; acts as a master pointer. It contains a simple reference to the branch file you are currently checked out to. That is it—simple, efficient, and lightning-fast. This is the power of world-class software architecture at work.&lt;/p&gt;

&lt;h2&gt;
  
  
  Chapter 5: The Reflog
&lt;/h2&gt;

&lt;p&gt;We have covered the genius architecture that makes Git efficient, fast, and lean. Now, let’s look at its ultimate safety net: the Reflog.&lt;/p&gt;

&lt;p&gt;Stored within the &lt;code&gt;logs&lt;/code&gt; folder inside your &lt;code&gt;.git directory&lt;/code&gt;, the &lt;strong&gt;Reference Log (or reflog)&lt;/strong&gt; is a chronological record of every single move you’ve made in your local repository. By default, it tracks your actions for 90 days—even those that aren't part of a formal branch history.&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%2Fdqsei7e05b3hfmm4qv30.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%2Fdqsei7e05b3hfmm4qv30.png" alt="Reflog file in git" width="800" height="496"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you accidentally perform a hard reset to an unknown commit or "lose" work during a messy rebase, Git still has your back. By running git reflog, you can see the history of your HEAD pointer, find the hash of the commit right before the chaos happened, and restore your project instantly with &lt;code&gt;git reset --hard [hash]&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;It is the ultimate "undo" button, proving that Git's design isn't just about speed—it’s about absolute data integrity.&lt;/p&gt;

&lt;p&gt;Well there you have it. How Git manages to stay lean, fast and efficient even when our projects gets complex and massive. If you have any questions then feel free to comment and let me know if there is any mistakes.&lt;/p&gt;

&lt;p&gt;References:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://git-scm.com/" rel="noopener noreferrer"&gt;https://git-scm.com/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://lnkd.in/gRZkXenx" rel="noopener noreferrer"&gt;https://lnkd.in/gRZkXenx&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>git</category>
      <category>efficiency</category>
      <category>softwareengineering</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Idempotent: What does this means?</title>
      <dc:creator>Alson Garbuja</dc:creator>
      <pubDate>Fri, 25 Oct 2024 14:48:39 +0000</pubDate>
      <link>https://dev.to/alsongarbuja/idempotent-what-does-this-means-264i</link>
      <guid>https://dev.to/alsongarbuja/idempotent-what-does-this-means-264i</guid>
      <description>&lt;p&gt;Welcome back to our series, Now You Know! Last time, we explored the concept of the &lt;strong&gt;Virtual DOM&lt;/strong&gt; and how React leverages it to update and render components efficiently.&lt;/p&gt;

&lt;p&gt;Today, we’re diving into a mathematical and programming concept: &lt;strong&gt;idempotence.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you find this helpful, like, share with friends, and comment on topics you’d like us to cover next. Let’s get started!&lt;/p&gt;

&lt;p&gt;According to &lt;em&gt;Wikipedia&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Idempotence is the property of certain operations in mathematics and computer science whereby they can be applied multiple times without changing the result beyond the initial application.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But what exactly is an idempotent operation, and why should we care about it? Let’s dig in.&lt;/p&gt;

&lt;h2&gt;
  
  
  Idempotent operation
&lt;/h2&gt;

&lt;p&gt;An idempotent operation is one that can be performed repeatedly with the same result every time. In other words, running it multiple times yields the same outcome as if it were only run once.&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%2F9anf0cvz33zl92oy0jwv.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%2F9anf0cvz33zl92oy0jwv.png" alt="Example of an Idempotent multiplicaiton operation" width="632" height="278"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the example above, we see a simple multiplication operation with two parameters, 2 and 2, producing a result: &lt;em&gt;“The answer is 4.”&lt;/em&gt; No matter how many times this operation runs, the result will always be the same.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why care about Idempotence?
&lt;/h2&gt;

&lt;p&gt;Now that you understand idempotent operations, you might wonder why they matter. After all, you’ve likely written many functions that behave in such way. But understanding idempotence is crucial, it brings consistency and reliability to the system.&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%2Fux9s008mtq6x5fs40nip.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%2Fux9s008mtq6x5fs40nip.png" alt="Advantages of Idempotence" width="768" height="206"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Especially in areas such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Database operations&lt;/strong&gt;: Making database operations such as writes and updates idempotent ensures repeated operation doesnot change the stored data unexpectedly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;API design&lt;/strong&gt;: With idempotent API endpoints we can be sure unintended consequences do not occur in repeated calls.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Network requests&lt;/strong&gt;: Retrying failed request calls becomes safer, since we know the operations are idempotent and will not produce unwanted results.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Idempotent&lt;/strong&gt; is not just property but a foundational principal that ensures we build resilient and predictable system.&lt;/p&gt;

&lt;h2&gt;
  
  
  Examples of Idempotent operation
&lt;/h2&gt;

&lt;p&gt;Some examples of where Idempotent operation can be used are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;API endpoints&lt;/strong&gt;: &lt;em&gt;GET&lt;/em&gt; endpoints in &lt;strong&gt;REST APIs&lt;/strong&gt; are Idempotent in nature. No matter how many times we call a &lt;em&gt;GET&lt;/em&gt; resource from the server, the server will always return the data in the format specified and data present in the database.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Transaction operations&lt;/strong&gt;: Transaction of money from one account to another account is one of the most used operation around the globe and they must be created as Idempotent operation since we don't want customers getting charged extra for honest mistake like &lt;em&gt;network latency&lt;/em&gt;, &lt;em&gt;lack of system knowledge&lt;/em&gt; or &lt;em&gt;poorly designed system&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Similary it can be helpful in many situations where predictability and reliablity of the system is priority.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cavaets
&lt;/h2&gt;

&lt;p&gt;While Idempotent offers stability and produces resilient systems, not all operations must be Idempotent. Some cavaets to keep in mind are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Not always applicable&lt;/strong&gt;: Not all operations/functions can be Idempotent. Operation such as &lt;strong&gt;Increment/Decrement operation&lt;/strong&gt; cannot be made Idempotent with out extra handling and probably should not be made Idempotent either since we need different result in each calls.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Complexity in implementation&lt;/strong&gt;: Making certain operations idempotent may introduce extra complexity. For example when retrying transaction operation we need to ensure the customer isn't charged multiple times which requires sophisticated handling of the overall transaction operation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Performance overhead&lt;/strong&gt;: Implementing idempotence, especially in distributed system will add extra steps(such as tracking state, checking for duplicate datas), which might impact performance.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;To wrap up, idempotence is a foundational concept that allows us to design operations that are predictable, resilient, and ultimately contribute to building reliable systems. It plays a key role in fields like &lt;em&gt;API design, database transactions, and network requests&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;But with every concepts of programming and life, idempotence is not with its limitation and should not be used overly.&lt;/p&gt;

&lt;p&gt;Just like with the Virtual DOM, after reading this, I hope I can say, Now you know! If you found this helpful, feel free to share it and let us know what you’d like covered next. Until then—happy coding!&lt;/p&gt;

</description>
      <category>programming</category>
    </item>
    <item>
      <title>Virtual DOM: Technque behind React's quick DOM updates.</title>
      <dc:creator>Alson Garbuja</dc:creator>
      <pubDate>Mon, 21 Oct 2024 11:41:17 +0000</pubDate>
      <link>https://dev.to/alsongarbuja/virtual-dom-technque-behind-reacts-quick-dom-updates-10k6</link>
      <guid>https://dev.to/alsongarbuja/virtual-dom-technque-behind-reacts-quick-dom-updates-10k6</guid>
      <description>&lt;p&gt;Hello everyone, I’m excited to kick off a new series of posts where I’ll try to explain various concepts from the programming world. We’ll cover everything from terms like idempotent and idiomatic to more specific concepts related to libraries and frameworks. And today, we’ll dive into one such topic — &lt;strong&gt;Virtual DOM&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If you find this helpful, don’t forget to &lt;strong&gt;Like, Share, and Comment&lt;/strong&gt; about which topics you’d like me to cover next. Let’s not waste any more time and jump straight into the &lt;strong&gt;Virtual DOM!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; Before we continue, it's important to understand that the concept of a Virtual DOM is not exclusive to React. Other JavaScript frontend libraries, like Vue, also use it to enhance rendering performance.&lt;/p&gt;

&lt;h2&gt;
  
  
  DOM
&lt;/h2&gt;

&lt;p&gt;The DOM (Document Object Model) is a tree-like representation of an HTML document (or webpage/web application) using nodes or objects. The DOM was designed so that frontend libraries and frameworks &lt;strong&gt;(javascript)&lt;/strong&gt; can interact with and manipulate the document programmatically via its API.&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%2Fwzzb84jk3c12f9fqn00m.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%2Fwzzb84jk3c12f9fqn00m.png" alt="DOM representation example" width="800" height="486"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Virtual DOM
&lt;/h2&gt;

&lt;p&gt;While the DOM provides an efficient way to manipulate a document through its API, performance can become an issue when there are thousands of elements on the screen. This is because &lt;strong&gt;updates in the DOM often involve destroying and recreating entire subtrees.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is where the &lt;strong&gt;Virtual DOM&lt;/strong&gt; comes into play. The Virtual DOM is a lightweight, in-memory representation of the Real DOM, allowing for fast and efficient synchronization of changes to the actual DOM — a process known as &lt;strong&gt;Reconciliation.&lt;/strong&gt;&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%2Fok64gl1t6ybupyw5dbhv.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%2Fok64gl1t6ybupyw5dbhv.png" alt="Real DOM and Virtual DOM" width="800" height="732"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The key things to remember here are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The Virtual DOM is a &lt;strong&gt;lightweight version of the Real DOM&lt;/strong&gt;, meaning it doesn't have all the properties of the Real DOM, which makes it more efficient to work with.&lt;/li&gt;
&lt;li&gt;The Virtual DOM exists &lt;strong&gt;in memory&lt;/strong&gt;, allowing for faster and more efficient manipulation before the changes are applied to the Real DOM.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;With this in mind, JavaScript libraries that use the DOM API create their own Virtual DOM and manipulate it. They update the Real DOM only when necessary, and even then, with minimal operations.&lt;/p&gt;

&lt;h2&gt;
  
  
  How is virtual DOM handled in React??
&lt;/h2&gt;

&lt;p&gt;React JS is a popular library  developed by Facebook for building user interfaces. Due to its simplicity it has gain massive popularity and used in many modern web projects.&lt;/p&gt;

&lt;p&gt;Like many other JS frontend libraries, React uses the concept of a Virtual DOM to efficiently manage re-renders and updates in an application.&lt;/p&gt;

&lt;p&gt;React uses a &lt;strong&gt;diffing algorithm&lt;/strong&gt; alongside a &lt;strong&gt;reconciliation technique&lt;/strong&gt; to optimize this process. (Specifically, the &lt;strong&gt;ReactDOM library&lt;/strong&gt; handles this behind the scenes.)&lt;/p&gt;

&lt;p&gt;Lets break it down step by step:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;React component's &lt;strong&gt;render()&lt;/strong&gt; function&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The render() function of react component first create the &lt;strong&gt;React Element/Virtual DOM&lt;/strong&gt; with the &lt;strong&gt;JSX&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;It contains lightweight version of Real DOM counterpart and extra properties such as &lt;em&gt;$$typeof&lt;/em&gt;, &lt;em&gt;props&lt;/em&gt;, to facilitate efficient diffing.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Diffing algorithm&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Whenever a React component is updated, a new Virtual DOM is created, and the diffing process begins. This is an &lt;strong&gt;O(n) heuristic algorithm&lt;/strong&gt; based on two key assumptions.

&lt;ol&gt;
&lt;li&gt;Different types of elements produces different trees.&lt;/li&gt;
&lt;li&gt;A key prop can be used to track which child elements remain consistent between renders.&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;/li&gt;

&lt;/ol&gt;

&lt;p&gt;2.1. &lt;strong&gt;Steps in diffing algorithm&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When the algorithm encounters &lt;strong&gt;two different types of DOM element&lt;/strong&gt;: it will tear down the old Virtual DOM and create a new one from scratch based on the new element's specifications.&lt;/li&gt;
&lt;li&gt;When React encounters &lt;strong&gt;same types of DOM element&lt;/strong&gt;:  it preserves the old DOM object and only updates the changed attributes.&lt;/li&gt;
&lt;li&gt;For &lt;strong&gt;React elements of the same type&lt;/strong&gt;, React keeps the old DOM object intact and supplies updated props.&lt;/li&gt;
&lt;li&gt;When handling &lt;strong&gt;child elements&lt;/strong&gt;, React iterates through both sets of children (old virtual DOM tree and newly created tree), making updates where differences exist.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;2.2. &lt;strong&gt;Why use keys?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As mentioned in the last point, the diffing algorithm iterates through child lists and makes changes where necessary. If you don’t use keys in a list of children, performance might suffer, and you could encounter unexpected behavior.&lt;/p&gt;

&lt;p&gt;Let's see example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt; // old list
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;apple&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;pineapple&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt; // new list
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;apple&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;pineapple&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;grape&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above scenario the algorithm can actually efficiently handle the modification. It looks at each index child and finds &lt;code&gt;&amp;lt;li&amp;gt;apple&amp;lt;/li&amp;gt; &amp;amp;&amp;amp; &amp;lt;li&amp;gt;pineapple&amp;lt;/li&amp;gt;&lt;/code&gt; is same in both list and does nothing to them while &lt;code&gt;&amp;lt;li&amp;gt;grape&amp;lt;/li&amp;gt;&lt;/code&gt; is only present in new list hence adds one to the old list.&lt;/p&gt;

&lt;p&gt;But say, we want to add the &lt;code&gt;&amp;lt;li&amp;gt;grape&amp;lt;/li&amp;gt;&lt;/code&gt; at the beginning.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt; // old list
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;apple&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;pineapple&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt; // new list
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;grape&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;apple&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;pineapple&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here the performance of the algorithm will decrease as it sees &lt;code&gt;&amp;lt;li&amp;gt;grape&amp;lt;/li&amp;gt;&lt;/code&gt; inplace of &lt;code&gt;&amp;lt;li&amp;gt;apple&amp;lt;/li&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;li&amp;gt;apple&amp;lt;/li&amp;gt;&lt;/code&gt; inplace of &lt;code&gt;&amp;lt;li&amp;gt;pineapple&amp;lt;/li&amp;gt;&lt;/code&gt; and a new &lt;code&gt;&amp;lt;li&amp;gt;pineapple&amp;lt;/li&amp;gt;&lt;/code&gt; in the last position. Thus recreating all the elements from strach.&lt;/p&gt;

&lt;p&gt;To solve this performance bottleneck, React team employees the use of &lt;code&gt;Key&lt;/code&gt; which is an &lt;strong&gt;unique id&lt;/strong&gt; attached to the list child items that can be used by the algorithm to determine if the item can be left intact and just reorder the position or needs to be recreated.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt; // old list
  &lt;span class="nt"&gt;&amp;lt;li&lt;/span&gt; &lt;span class="na"&gt;key=&lt;/span&gt;&lt;span class="s"&gt;"a.fruit45"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;apple&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&lt;/span&gt; &lt;span class="na"&gt;key=&lt;/span&gt;&lt;span class="s"&gt;"p.fruit90"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;pineapple&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt; // new list
  &lt;span class="nt"&gt;&amp;lt;li&lt;/span&gt; &lt;span class="na"&gt;key=&lt;/span&gt;&lt;span class="s"&gt;"g.fruit20"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;grape&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&lt;/span&gt; &lt;span class="na"&gt;key=&lt;/span&gt;&lt;span class="s"&gt;"a.fruit45"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;apple&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&lt;/span&gt; &lt;span class="na"&gt;key=&lt;/span&gt;&lt;span class="s"&gt;"p.fruit90"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;pineapple&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now react can use the &lt;code&gt;Key&lt;/code&gt; attributes and only reposition the non updated child items while adding the new child item.&lt;/p&gt;

&lt;p&gt;3) ReactDOM's &lt;strong&gt;render()&lt;/strong&gt; function&lt;/p&gt;

&lt;p&gt;Finally the ReactDOM's &lt;em&gt;render()&lt;/em&gt; function is called, which reconciles the differences between the new Virtual DOM and the Real DOM. This results in minimal operations needed to re-render the HTML efficiently.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this article, we’ve explored the Virtual DOM, a technique used by many frontend libraries to handle data and element changes efficiently with minimal DOM operations. We also looked at how React specifically uses a diffing and reconciliation process to optimize updates.&lt;/p&gt;

&lt;p&gt;I hope this post helped you better understand how the Virtual DOM works. Even if you were familiar with the concept, I hope &lt;strong&gt;Now you know&lt;/strong&gt; what is Virtual DOM and how it contributes in creating optimized frontend environment.&lt;/p&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Reusability: A magic potion or curse in disguise</title>
      <dc:creator>Alson Garbuja</dc:creator>
      <pubDate>Thu, 10 Oct 2024 07:40:22 +0000</pubDate>
      <link>https://dev.to/alsongarbuja/reusability-a-magic-potion-or-curse-in-disguise-4eaj</link>
      <guid>https://dev.to/alsongarbuja/reusability-a-magic-potion-or-curse-in-disguise-4eaj</guid>
      <description>&lt;p&gt;Reusability is a common term in programming, known for its benefits. But is it really as helpful as people say, or is it just an overused concept? In this article, we’ll explore what reusability truly means and whether it’s the hero people claim or just another fancy over used software term.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Reusability?
&lt;/h2&gt;

&lt;p&gt;Keeping it simple. Reusability in software engineering refers to the idea of creating components or functions that can be reused in the future. In simple terms reusability is like making a handy tool out of your broom  in order to clean tight corners of your room then instead of taking it apart you keep it intact so that you can use it next time you clean your room.&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%2F6g03jibtudd9t1wvl892.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%2F6g03jibtudd9t1wvl892.png" alt="Illustration demonstrating reusability with concept of same box used in multiple places" width="800" height="488"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Benefits: What makes it a hero!
&lt;/h2&gt;

&lt;p&gt;Reusability offers several benefits in the programming world, including:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Eliminates code duplication:&lt;/strong&gt; By reusing code, we can avoid having duplicate code in our codebase.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Single source of truth:&lt;/strong&gt; Since the same code is used in multiple places, we have a central location to check and fix any errors.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reduces code size:&lt;/strong&gt; Along with cutting down on duplicate code, reusability also helps minimize the overall number of lines in the codebase.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In addition to these, there are many other advantages we can gain by applying the concept of reusability in our projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Examples of applying reusability
&lt;/h2&gt;

&lt;p&gt;Now, let's look at some examples of how to apply the concept of reusability. For this demonstration, I'll be using the &lt;em&gt;React&lt;/em&gt; library, though this concept can be applied to any programming language.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reusable component/Widget/UI&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;PhoneTile&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;avatar&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"px-2 py-4 rounded-md bg-white shadow-md text-black"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"flex gap-4 items-center"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;avatar&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;alt&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;`profile pic of &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"w-12 h-12 rounded-full object-cover"&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;a&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;`tel:&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;a&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;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%2Fmo5oe60lerri1krvgfpp.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%2Fmo5oe60lerri1krvgfpp.png" alt="A react component showing user name and their avatar" width="582" height="215"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the example above, we've created a &lt;code&gt;PhoneTile&lt;/code&gt; component, which can be placed in a separate file and reused across different parts of the project. To use it in various components, all you need to do is pass the necessary &lt;code&gt;props&lt;/code&gt;, which are name, number, and avatar.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reusing functions&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;apiCaller&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;method&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;method&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Content-Type&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;application/json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;payload&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;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;options&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;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// considering your error is present in the message key&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&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;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Or you can throw it and handle it elsewhere&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;We've created a function called &lt;code&gt;apiCaller&lt;/code&gt; that takes a &lt;code&gt;url&lt;/code&gt;, &lt;code&gt;method&lt;/code&gt;, and an optional &lt;code&gt;payload&lt;/code&gt; to fetch data or log errors using the &lt;code&gt;fetch API&lt;/code&gt;. By defining this function as a separate &lt;code&gt;global function&lt;/code&gt;, we can reuse it throughout our project for various tasks, like fetching user data, updating user information, and more.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reusable constants&lt;/strong&gt;&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="kr"&gt;enum&lt;/span&gt; &lt;span class="nx"&gt;Direction&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;Up&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;Down&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;Left&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;Right&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;We can also apply reusability when defining constants in our program. For instance, I've created an &lt;code&gt;enum&lt;/code&gt; called &lt;em&gt;Direction&lt;/em&gt; in &lt;strong&gt;TypeScript&lt;/strong&gt;, with four values ranging from 1 to 4 &lt;em&gt;(Note: the values can be any numbers we specify)&lt;/em&gt;. Instead of using the number values which are difficult to remember, we can use the more inuitive and understandable labels &lt;em&gt;Up, Down, Left and Right&lt;/em&gt;. These values can then be reused anywhere in our codebase, improving readability and reducing errors.&lt;/p&gt;

&lt;h2&gt;
  
  
  Potential danger lurking behind the scenes
&lt;/h2&gt;

&lt;p&gt;So far, we’ve discussed the positive aspects of reusability, and it’s clear that it offers many advantages for writing cleaner and more efficient code. However, what many, especially beginners, may not realize is that reusability also comes with certain disadvantages.&lt;/p&gt;

&lt;p&gt;Let's look at those disadvantages one by one.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Correctly spelling reusability:&lt;/strong&gt; The frustration i had while attempting to spell reusability and instead typed &lt;code&gt;resuability&lt;/code&gt; is unmatched. Just joking here, jokes apart below are the real disadvantages listed.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Over reuse
&lt;/h3&gt;

&lt;p&gt;While reusability is excellent for reducing code and making it cleaner, it doesn’t automatically guarantee maintainable code. Returning to our analogy of the broom tool—which we created to clean tight corners efficiently—if we try to use the same tool to clean regular floors or rooftops, it could lead to issues. &lt;/p&gt;

&lt;p&gt;Similarly, if we use the &lt;code&gt;PhoneTile&lt;/code&gt; component to represent a &lt;strong&gt;contact folder&lt;/strong&gt; by adding optional &lt;code&gt;isFolder&lt;/code&gt; and &lt;code&gt;onClick&lt;/code&gt; props, and also reuse it to display an &lt;strong&gt;email list&lt;/strong&gt;, we might start facing problems. While reusability is great, stretching a component beyond its original purpose can make the code harder to maintain and understand, potentially leading to confusion and bugs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;PhoneTile&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;avatar&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;isFolder&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;mail&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"px-2 py-4 rounded-md bg-white shadow-md text-black"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"flex gap-4 items-center"&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;onClick&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;isFolder&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;FolderIcon&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;avatar&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;alt&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;`profile pic of &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"w-12 h-12 rounded-full object-cover"&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;a&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt;&lt;span class="s2"&gt;`tel:&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;mail&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt;&lt;span class="s2"&gt;`mailto:&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;mail&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;a&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;mail&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;MailIcon&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;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%2F5dkxinqihz0ittinkuwx.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%2F5dkxinqihz0ittinkuwx.png" alt="list of react components showing user name and their avatar" width="567" height="344"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we can see, the code begins to get messy. While we may reduce code duplication and write less code, the overall developer experience deteriorates. It becomes much harder to maintain and manage this kind of code over time, leading to increased complexity and confusion.&lt;/p&gt;

&lt;h3&gt;
  
  
  Difficulty in testing
&lt;/h3&gt;

&lt;p&gt;Another problem that will surface up when over reusing or not correclty implementing reusability is the difficulty while testing.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Unit testing&lt;/code&gt; is a crucial step in the software development process, and used to test different components or functions in a unit level. Hence excessive reliance on a single component to accommodate various functionality can make it nearly impossible to test each case separately&lt;/p&gt;

&lt;p&gt;Here is an example of how the unit test for well-designed component and poorly created reusable component might look like. &lt;em&gt;(NOTE: I am using jest along with testing library)&lt;/em&gt;&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="c1"&gt;// Proper reused component unit testing&lt;/span&gt;
&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Check if phonetile shows correct info&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;PhoneTile&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Alson&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;1234567890&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;avatar&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://api.dicebear.com/9.x/bottts-neutral/svg?seed=Alson&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;screen&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getByRole&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;a&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;toHaveTextContent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1234567890&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Poorly reused component unit testing&lt;/span&gt;
&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Check if phonetile shows correct info&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;PhoneTile&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Alson&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;1234567890&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;avatar&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://avatar.com/alson.png&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;screen&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getByRole&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;a&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;toHaveTextContent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1234567890&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="c1"&gt;// We have to test for different types again which defeats the purpose of unit testing&lt;/span&gt;
  &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;PhoneTile&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Families&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;isFolder&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;navigateToFamiliesList&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;)
&lt;/span&gt;  &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;screen&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getByRole&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;a&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;toHaveTextContent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Families&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Reusability, like many software concepts, is neither an absolute hero nor a complete villain. Its effectiveness largely depends on how developers implement and leverage it. Ultimately, reusability can be a powerful asset or a source of complexity, based on the choices made during development.&lt;/p&gt;

&lt;p&gt;Here are some of the questions and steps for beginners to filter out if they need to make any component/function/constant or block of code reusable or not.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Do not over complicate the reusable blocks of code by over reusing (over engineering) it. Have one block of code handle only one function.&lt;/li&gt;
&lt;li&gt;Reuse any component/function/constants if and only if, it is needed to be reused again in an &lt;code&gt;Idompotent&lt;/code&gt; manner.&lt;/li&gt;
&lt;li&gt;Divide and conqure can be applied in cases where we need to reuse some block of codes for different functionality. By futher dividing parts of reused codes into smaller reusable codes.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>softwaredevelopment</category>
      <category>coding</category>
      <category>code</category>
    </item>
    <item>
      <title>Staying motivated in development world</title>
      <dc:creator>Alson Garbuja</dc:creator>
      <pubDate>Fri, 03 May 2024 08:15:44 +0000</pubDate>
      <link>https://dev.to/thankadigital/staying-motivated-in-development-world-1913</link>
      <guid>https://dev.to/thankadigital/staying-motivated-in-development-world-1913</guid>
      <description>&lt;p&gt;Developers have it rough, and I understand it is not easy to be a developer, especially when met with unrealistic deadlines, bugs, code breaks, and threats from AI nowadays.&lt;br&gt;
Needless to say, it is really difficult to stay motivated as a developer sometimes.&lt;/p&gt;

&lt;p&gt;Here are some tricks I personally use to stay motivated in my work as well as on personal projects.&lt;/p&gt;

&lt;h3&gt;
  
  
  Break the problem
&lt;/h3&gt;

&lt;p&gt;One of the fundamental concepts in programming is breaking a bigger problem into smaller chunks that can be solved one after another. Instead of trying to solve a big problem at once, why not take a step back for a moment and break that problem into smaller problems?&lt;br&gt;
A big goal in front of you to finish by a certain deadline will be much harder to tackle than having smaller and more realistic goals to be finished at the same time.&lt;/p&gt;

&lt;h3&gt;
  
  
  Join communities
&lt;/h3&gt;

&lt;p&gt;What can't be done alone can only be done with a team. While working independently can hone your skills, working in a team when needed will help you boost your skills by 10X.&lt;br&gt;
It takes less time to debug and find solutions; you can gain perspective from different developers (from different viewpoints) to find the optimal solution.&lt;br&gt;
Join virtual or physical communities with developers of like mind and similar skill sets. They will help you stay motivated.&lt;/p&gt;

&lt;h3&gt;
  
  
  Find your passion
&lt;/h3&gt;

&lt;p&gt;It sounds obvious, and you might have heard it from thousands of developers. When I say find your passion, I mean "the thing" that first got you into programming. Go back to your roots and do some personal, fun, and bite-sized projects to get yourself the adrenaline that you first got when you started. For me, it was game development that I wanted to do, and ultimately I ended up doing programming. So when I get frustrated with all the errors and bugs, I just take my time off from that and work on personal game projects to keep me motivated.&lt;/p&gt;

&lt;h3&gt;
  
  
  Take some well-needed rest.
&lt;/h3&gt;

&lt;p&gt;It is one of the most effective ways to stay motivated and also a way to have a long-lasting career in not only the development world but every other aspect of life. We are humans, not machines; we get tired and anxious over repetitive tasks. So in order to not get tired and anxious, you should take some rest and get yourself some fresh air.&lt;br&gt;
Go somewhere cozy, watch something fun, or do some sports; just get out of your chair and do anything new. Refresh your brain, come back, and look at the problem from a different perspective.&lt;/p&gt;

&lt;p&gt;I hope these tips and tricks will come in handy in keeping you motivated and creating amazing products.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Happy developing&lt;/em&gt; 👨‍💻&lt;/p&gt;

</description>
      <category>motivation</category>
      <category>development</category>
      <category>developer</category>
    </item>
  </channel>
</rss>
