<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Puran Joshi on Medium]]></title>
        <description><![CDATA[Stories by Puran Joshi on Medium]]></description>
        <link>https://medium.com/@puran.joshi307?source=rss-969ac0a00925------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ct1TY9aKKHyXr3gjVyhrsg.jpeg</url>
            <title>Stories by Puran Joshi on Medium</title>
            <link>https://medium.com/@puran.joshi307?source=rss-969ac0a00925------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 06:16:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@puran.joshi307/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[We Keep Fixing the Symptom]]></title>
            <link>https://medium.com/@puran.joshi307/we-keep-fixing-the-symptom-dd6955c1cdc5?source=rss-969ac0a00925------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd6955c1cdc5</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[incident-management]]></category>
            <category><![CDATA[symptoms]]></category>
            <category><![CDATA[root-cause-analysis]]></category>
            <dc:creator><![CDATA[Puran Joshi]]></dc:creator>
            <pubDate>Thu, 22 Oct 2026 16:32:48 GMT</pubDate>
            <atom:updated>2026-10-22T16:32:48.546Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lpy38NSIceNBi6Q35dO7YQ.png" /><figcaption>The dashboard looks fine, but the system underneath is still leaking</figcaption></figure><p><em>What a student tragedy in India taught me about the incidents we handle in engineering</em></p><p>I recently read about Kota, a city in Rajasthan, India, known as a hub for coaching programs for national entrance exams. Over the years, many students living there alone, under intense pressure, have died by suicide. Reports describe authorities responding by changing hostel fixtures to reduce the risk of harm in those spaces.</p><p>I’m not an expert in mental health, and I don’t want to write about this topic as if I were. But the story stayed with me, because it describes a pattern I see every week in engineering.</p><h3>The fix that works, and the fix that isn’t enough</h3><p>Researchers who study suicide have a name for one approach: means restriction. The idea is simple. When a harmful method is easy to access, and a person is in acute distress, removing that access can create a gap in which the crisis passes.</p><p>The evidence for this is strong. In the UK, the switch from coal gas to natural gas in the 1960s and 70s removed a common method of suicide, and deaths fell. Researchers Ronald Clarke and David Lester documented this in their work on closing the routes to suicide. In Sri Lanka, restricting access to highly toxic pesticides was followed by a significant drop in suicide deaths.</p><p>Some people did turn to other methods in those cases. But the overall numbers went down, and that is the outcome that matters.</p><p>So this isn’t a story about a bad fix. It’s a story about a fix that buys time and saves lives, while the deeper problem is still there. Distress, pressure, isolation, and a lack of support don’t go away because a fixture changed. A safer environment is a necessary step. It is not the whole answer.</p><h3>Engineering has the same shape</h3><p>Now look at how we handle incidents.</p><p>An alert fires too often, so we raise the threshold. The alert stops, and the dashboard looks calm. The service is still flaky.</p><p>A request fails intermittently, so we add a retry. Latency gets worse, the failures are hidden, and nobody goes looking for the race condition.</p><p>A customer complains about a slow page, so we add a cache. The page loads fast in our tests. The underlying query still scans a table it shouldn’t.</p><p>None of these fixes is wrong on its own. Sometimes you need the threshold, the retry, or the cache to stop the bleeding. The problem is what happens next. The symptom disappears from our view, the ticket gets closed, and the cause keeps producing new symptoms somewhere else.</p><p>We have a long history of this in the wider world too. In colonial Hanoi, the city paid for every rat tail brought in. People began breeding rats to collect the bounty, and the rat population grew. The bounty targeted the count, not the sanitation and food waste that let rats thrive. In Flint, Michigan, residents received filters and bottled water for a long time after a change in the city’s water source. The underlying problem, pipe corrosion and lead leaching, was a different and harder fix, and the symptom-level response kept people going while the cause stayed in place.</p><h3>A few questions I now ask in incident reviews</h3><p>When I’m in a postmortem, I try to slow down before we close the action items. A few questions help:</p><ul><li>What did this fix make invisible, and who notices now?</li><li>If this symptom comes back in a different form next month, what would it look like?</li><li>Are we fixing the thing that failed, or the thing that was most annoying this week?</li><li>Who owns the cause, and is it on the roadmap, or only in a comment?</li><li>Did we remove a risk, or did we just move it?</li></ul><p>These questions don’t mean you should avoid quick mitigations. Stopping the bleeding is the right first move. The question is whether we follow up.</p><h3>Stopping the bleeding is not the same as healing</h3><p>Every good on-call engineer knows the difference between mitigation and resolution. Rolling back a bad deploy, shedding load, or disabling a feature flag is often exactly right at 3 a.m. But a postmortem that ends with “mitigated” and no root-cause work is a postmortem that will be read again later, probably in a worse incident.</p><p>The same goes for people. A safer environment can keep someone alive through the worst hours. What helps them stay well is the slower work: reducing unhealthy pressure, making support easy to reach, noticing distress early, and taking it seriously when people ask for help.</p><h3>What I’d take from this</h3><p>If you lead a team, or you’re the one who gets called when things break, you probably already feel this tension. There is always pressure to make the problem stop looking like a problem. Sometimes that’s the right call. But it should come with a second question that stays open until someone answers it: what’s actually causing this?</p><p>Fixing the symptom buys time. Fixing the cause is what keeps the incident from coming back.</p><blockquote>If you or someone you know is struggling, you don’t have to handle it alone. In India, Tele-MANAS is available at 14416 or 1–800–891–4416. If you’re elsewhere, your local emergency number or a crisis line in your country can help.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd6955c1cdc5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tech Debt is a Loan: Borrow Wisely, Build Faster]]></title>
            <link>https://medium.com/@puran.joshi307/tech-debt-is-a-loan-borrow-wisely-build-faster-7dd302f9b501?source=rss-969ac0a00925------2</link>
            <guid isPermaLink="false">https://medium.com/p/7dd302f9b501</guid>
            <category><![CDATA[tech-debt]]></category>
            <category><![CDATA[future-self]]></category>
            <category><![CDATA[overengineering]]></category>
            <category><![CDATA[lean-engineering]]></category>
            <dc:creator><![CDATA[Puran Joshi]]></dc:creator>
            <pubDate>Sun, 10 Aug 2025 08:55:14 GMT</pubDate>
            <atom:updated>2025-08-10T08:55:14.857Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Be the CFO of your codebase: borrow when it’s worth it, pay it back before it owns you</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Ba_GTSjDhq4poUNUMyWOQ.png" /><figcaption>Loan from future self</figcaption></figure><p><strong>Spoiler alert:</strong> Tech debt is not the villain you think it is. Sometimes it is the hero that gets you to the finish line faster.</p><p>It was long, long ago, at the end of the second decade into the new millennium.</p><p>We were a small company with the heart of a startup, but we were recently bought by a big tech giant. Our work was exciting. We helped people use their reward points to buy travel products like flights, hotels, cars and activities.</p><p>One day we had a big meeting. This meeting would decide what the engineers worked on for the next few months.</p><h3>The Big Idea</h3><p>We decided to build a shopping cart. The goal was simple. Customers could add any travel product into one basket and check out together. No need to buy flights, hotels, and experiences one by one.</p><p>The idea was good. But then we got ambitious. We planned to make it work for every product type from day one. We designed it to be future proof and ready for scale before we had even launched it.</p><p>It was no longer just a cart. It became a big, complex travel checkout platform.</p><h3>Three Months Later</h3><p>After months of planning, designing, and talking about architecture, the requirements had changed.</p><p>The contracts we had with partners were different now. The way products could be bought together had also changed.</p><p>We had two choices.</p><ul><li>We could throw away months of work and start again.</li><li>we could add workarounds and try to adjust the system to fit the new rules.</li></ul><p>Neither felt right.</p><h3>Watching From the Outside</h3><p>My team was now tasked with integrating these products into this big system, and as we continued to look into ways to integrate, we realised it was like</p><blockquote>we had built a Ferrari when what we needed now was a scooter.</blockquote><p>The team was not careless. In fact, they were too careful. They did not want to take on any tech debt because they thought it was bad. Every shortcut was treated like a mistake.</p><p>But here’s what I realised: avoiding tech debt completely is like never taking a loan in life. Yes, you never pay interest, but you also miss opportunities. It might be difficult to buy a house today if you don’t take a home loan, and you might miss a good opportunity.</p><h3>The Loan We Should Have Taken</h3><p>If I look at that project as a loan, it becomes clear.</p><p><strong>Principal</strong>: a simple cart for the products we had at that time.<br><strong>Interest rate</strong>: some extra work later to add new product categories.<br><strong>Repayment date</strong>: when our contracts and product rules were stable.</p><p>We did not take that loan. Instead, we tried to pay for perfection up front. And perfection demands payment even before you know the full cost.</p><h3>What I Learned</h3><p>Tech debt is not bad. Unplanned tech debt is bad.</p><p>A small, low-interest loan can be a smart choice. Architectural debt is like a high-interest home loan. It is fine if you will stay in the same home for many years. But it is risky if you are not sure where you will be in the future.</p><p>If we had taken a little debt at the start, we could have built a simple cart, shipped faster, learned sooner, and adapted more easily.</p><h3>My Three Questions Today</h3><p>Now, whenever I am in a meeting about a new system, I ask myself:</p><ul><li>What is the interest rate for this decision?</li><li>When will we pay it back?</li><li>If the rules change in three months, will I regret not borrowing?</li></ul><p>Sometimes the best engineering choice is not the cleanest code. It is the one that delivers value now, adapts later, and still keeps us moving forward.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7dd302f9b501" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[You Might Be Writing Documentation the Wrong Way]]></title>
            <link>https://medium.com/@puran.joshi307/tailoring-documentation-for-different-audiences-9f942b748977?source=rss-969ac0a00925------2</link>
            <guid isPermaLink="false">https://medium.com/p/9f942b748977</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[documentation]]></category>
            <dc:creator><![CDATA[Puran Joshi]]></dc:creator>
            <pubDate>Thu, 04 Jul 2024 23:25:05 GMT</pubDate>
            <atom:updated>2024-07-10T04:39:06.520Z</atom:updated>
            <content:encoded><![CDATA[<h3>Documentation myths debunked</h3><figure><img alt="Tailoring Documentation" src="https://cdn-images-1.medium.com/max/512/1*vVFOOQp3GAyPUlaFw5sl2Q.jpeg" /></figure><h4>Overview</h4><p>In the past, I have experienced many challenges with the documentation approach. In most fast-growing organizations, documentation is often the last thing we care about, and even if we do document, we never give emphasis to the audience for those documents. As a result, documentation gets spread across different tools, making it difficult to maintain and access. Additionally, sometimes documents intended for non-technical stakeholders contain too much technical jargon, making it difficult for them to understand the content. If this were not enough, we found that documents often get lost or are not well-maintained. Based on these seemingly simple issues, I believe it is important for us to understand the needs of different audiences and tailor our documents accordingly.</p><blockquote>It is important to note that while documentation is important, the team should always prioritise delivering working code that meets the needs of the customer, as per the value of the Agile Manifesto around “Working code over comprehensive documentation”. By being pragmatic about what needs to be documented and sharing ownership within the team on who maintains which document type, the team can ensure that documentation is focused on the most important information and is not a burden on the development process.</blockquote><h4>Recommendation</h4><p>In my experience, creating documentation that meets the needs of different audiences can be a challenge, but it’s essential for ensuring that stakeholders understand and use the system effectively. Here are some approaches that I’ve found to be effective:</p><ol><li><strong>High-level diagrams in Wiki tools like Confluence</strong>: I created diagrams that provide an overview of the system architecture and how the components interact with each other on Confluence, the tool we were using. These diagrams were perfect for non-technical stakeholders who needed to understand the system at a high level without getting bogged down in technical details.</li><li><strong>OpenAPI/Swagger specs hosted on the web</strong>: I made the documentation that describes the API and how it can be used by external stakeholders available over internet. This was not only helpful for non-technical stakeholders to understand the capabilities of the system but also made the life of external stakeholders easy while integrating with our system.</li><li><strong>Low-level diagrams close to the code: </strong>In my experience, while debugging an issue, one thing that I always missed were the low-level diagrams like sequence diagrams. If I had these, I can guarantee you I would have saved hundreds of hours trying to understand the flow first before I could dig into the issue. By placing this documentation close to the code, it’s easy to keep it up-to-date and ensure that it remains accurate.</li><li><strong>Unit tests and integration tests: </strong>Finally, my favourite topic — writing tests that describe the expected behaviour of the code. I can ensure that if the code is well-documented using unit tests, future changes to the code can never break existing functionality. These tests can be used to verify that the code is working as intended and to provide detailed technical information about how the code works.</li></ol><p>By using these approaches, I’ve been able to tailor my documentation to meet the needs of different audiences and ensure that stakeholders understand and use the system effectively. With engaging and useful documentation, stakeholders feel more confident in their understanding of the system and more empowered to use it effectively.</p><h4>Conclusion</h4><blockquote>Tailoring documentation to meet the needs of different audiences can help stakeholders understand and use the system effectively. While there are potential risks and challenges associated with implementing the proposed approach, these can be mitigated by establishing clear documentation practices and guidelines, being pragmatic about what needs to be documented, and involving stakeholders in the process.</blockquote><h4>Let’s grow together</h4><blockquote>Please do share in the comments if you have faced a similar issue and what approach you took.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9f942b748977" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[You should never be wrong, but you shouldn’t always be right.]]></title>
            <link>https://medium.com/@puran.joshi307/you-cant-always-be-wrong-but-you-shouldn-t-always-be-right-7ac4aa155f95?source=rss-969ac0a00925------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ac4aa155f95</guid>
            <category><![CDATA[balance]]></category>
            <category><![CDATA[humility]]></category>
            <category><![CDATA[leadership]]></category>
            <category><![CDATA[openness]]></category>
            <category><![CDATA[adaptability]]></category>
            <dc:creator><![CDATA[Puran Joshi]]></dc:creator>
            <pubDate>Wed, 22 Nov 2023 19:03:38 GMT</pubDate>
            <atom:updated>2026-03-02T09:45:27.008Z</atom:updated>
            <content:encoded><![CDATA[<p>Importance of openness, humility, and adaptability for a leader</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2zdtvfMT5BN8cM1UZrVdDQ.png" /><figcaption>Right or Wrong</figcaption></figure><h3>Confused?</h3><p>The first time I heard this line, I was confused.</p><p>In engineering, we are trained to be right, to prove things, to show data. So when someone said, “you should never be wrong, but you shouldn’t always be right”, it felt like a contradiction. For some time I kept thinking about it, and honestly I didn’t know how to apply it in real work.</p><p>Over the years, specially when I started taking more Staff Engineer kind of responsibilities, this sentence started showing up in real situations. Incidents, architecture discussions, cross-squad alignment, and those moments where everyone is waiting for a decision and nobody wants to commit. That’s where I slowly started understanding what this line is trying to say.</p><h3>You should never be wrong</h3><p>For me, this is not about being perfect. It’s more about not leaving the team in confusion. In many situations, if nobody makes a call, the team gets stuck. People keep discussing same options again and again, and then work slows down, and everyone starts doing different things because the direction is not clear.</p><p>I saw this very clearly during incidents. You never have full info, and waiting for 100% certainty is not realistic. Someone needs to take ownership, pick a direction based on what we know, and communicate it clearly so team can move together. Same in architecture work also, you can always explore one more option, but at some point you decide and you support that decision. When I do that, it builds trust, because people feel safe that we are moving in one direction and there is a reason behind it.</p><h3>You shouldn’t always be right</h3><p>This part was actually harder for me. When I started owning more things, I sometimes held my position too strongly. Not because I wanted to win, but because I thought leadership means you should be consistent and sure. But systems have a way to teach you humility. New data comes, edge cases show up, production reality hits, and sometimes the person who is disagreeing is not blocking, they are actually helping to protect the system.</p><p>If I become too attached to being right, people stop challenging. Reviews become quiet. Concerns come late. And then issues come back in worst possible time. I learnt that it’s better when disagreement happens early, in a safe way, and then we adjust based on what we learn. Changing mind with new facts is not weakness, it is just good engineering.</p><h3>Conclusion</h3><blockquote>So now when I think about this sentence, I see it as balance. I want to be confident enough to make a call and create clarity, specially when others are blocked and waiting. But I also want to be open enough to listen, to take other perspectives seriously, and to change direction when the facts change.</blockquote><blockquote>For engineers, I feel leadership is not about always being the smartest person in the room. It’s about helping the room move forward together, and helping the system improve over time. That’s my take on it today, and I’m curious how you all see it.</blockquote><p><em>Looking forward to your comments and discussions!!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ac4aa155f95" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Try-Catch Traps: Avoiding Business Logic Pitfalls]]></title>
            <link>https://medium.com/@puran.joshi307/try-catch-traps-avoiding-business-logic-pitfalls-d492b18ffa1a?source=rss-969ac0a00925------2</link>
            <guid isPermaLink="false">https://medium.com/p/d492b18ffa1a</guid>
            <category><![CDATA[try-catch]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[common-mistakes]]></category>
            <category><![CDATA[clean-code]]></category>
            <dc:creator><![CDATA[Puran Joshi]]></dc:creator>
            <pubDate>Sat, 18 Nov 2023 17:22:14 GMT</pubDate>
            <atom:updated>2023-11-18T17:32:58.023Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*FVGEobNDvDlbPR5a_jZHNA.gif" /><figcaption>Try-catch traps</figcaption></figure><h3>Overview</h3><p>You might be wondering why I am writing such a basic article. After all, it’s common knowledge that we should avoid using try-catch for business logic. However, I have observed instances where people still practice this. In this article, I am sharing my thoughts on why I believe you should avoid doing this, focusing on the aspects of performance and code readability.</p><h4>Try-catch Traps</h4><p>Its like stumbling upon a hidden party in your code — the whole try-catch situation for business logic. You might think it’s all good, but there’s a catch (pun intended). Imagine this behind-the-scenes: creating exception objects, searching for catch blocks — it’s a performance hassle, especially if exceptions are thrown like confetti. And then there’s the code vibe. Relying too much on try-catch turns your code into a maze, especially with those nested structures. It’s like trying to navigate a dark room full of obstacles.</p><p>So, while it’s not exactly a coding sin, it’s more of a “proceed with caution” scenario. Ever found yourself in this coding party?</p><h4>Example</h4><p>Here is an example code that uses try-catch blocks for business logic:</p><pre>fun complexBusinessLogic() {<br>    try {<br>        step1()<br>        try {<br>            step2()<br>            try {<br>                step3()<br>                // ... more steps<br>            } catch (e3: SomeException) {<br>                handleException(e3, &quot;Error in step3&quot;)<br>            }<br>        } catch (e2: AnotherException) {<br>            handleException(e2, &quot;Error in step2&quot;)<br>        }<br>    } catch (e1: Exception) {<br>        handleException(e1, &quot;Error in step1&quot;)<br>    }<br>}<br><br>fun handleException(e: Exception, message: String) {<br>    println(&quot;$message: ${e.message}&quot;)<br>}</pre><p>In this example, each part of the business plan is put into a try-catch block. If something goes wrong, it’s caught and sorted out. But, here’s the deal: the more steps you add, the trickier it gets. The code becomes a bit of a puzzle, and that might slow things down. Keep it straightforward.</p><p>A simpler version of this might look like this:</p><pre>fun simplifiedBusinessLogic() {<br>    try {<br>        step1()<br>        step2()<br>        step3()<br>        // ... more steps<br>    } catch (e: Exception) {<br>        handleException(e, &quot;Error in business logic&quot;)<br>    }<br>}<br><br>fun handleException(e: Exception, message: String) {<br>    println(&quot;$message: ${e.message}&quot;)<br>}</pre><p>Now, we’ve simplified the try-catch blocks and put all the exception handling in one place. It makes the code cleaner and easier to manage. This just goes to show how things can get tangled up if you go overboard with try-catch blocks, especially when you end up with these nested structures. Keep it simple, right?</p><h4>Join the Conversation</h4><blockquote>I’ve shared my perspective on why using try-catch for business logic might not be the best practice, considering performance and code readability. However, I’m keen to hear from you! If you have experiences or scenarios where you think this advice might not hold true, or if you have alternative insights, I encourage you to share your thoughts. Let’s spark a conversation and learn from each other’s perspectives. After all, the beauty of our field lies in the diverse approaches we bring to problem-solving. Looking forward to your comments and discussions!!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d492b18ffa1a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Asymmetric Encryption]]></title>
            <link>https://medium.com/@puran.joshi307/private-public-key-pair-e43c34aaf82e?source=rss-969ac0a00925------2</link>
            <guid isPermaLink="false">https://medium.com/p/e43c34aaf82e</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[online-security]]></category>
            <category><![CDATA[asymmetric-encryption]]></category>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[decryption]]></category>
            <dc:creator><![CDATA[Puran Joshi]]></dc:creator>
            <pubDate>Sun, 13 Aug 2023 21:13:52 GMT</pubDate>
            <atom:updated>2023-08-15T05:42:21.527Z</atom:updated>
            <content:encoded><![CDATA[<p>Understanding Encryption: Learning About Asymmetric Encryption for Better Online Security</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uBFaGYr7sjxdr2BtNLlXlg.png" /><figcaption>Asymmetric Encryption</figcaption></figure><h3>Audience</h3><p>I’ve written this article in an effort to share my knowledge with fellow engineers interested in cybersecurity using Asymmetric Encryption. This article explains how these key pairs function behind the scenes and their practical use-cases.</p><h3>Overview</h3><p>In this article,</p><ol><li>I’ll start by discussing why this technique is better than using a single key shared between two parties.</li></ol><p>2. Then, I’ll guide you through the process of generating the key pair using a sample code.</p><p>3. Finally, I’ll explore some real-life use cases where this technique can be applied.</p><p>But before we dug deep lets know what is <strong>Asymmetric encryption</strong> using public and private key pairs</p><h3>Asymmetric encryption</h3><p>Asymmetric encryption, also known as public-private key encryption, is a smart way of securing messages. Imagine having a pair of keys — one is the public key, and the other is the private key. I use my private key to lock up my messages, making them safe and unreadable to others. Then, anyone with my public key can unlock and read those messages.</p><p>This approach is like having a padlock that only my private key can open. And the neat thing is, even if someone knows my public key, they can’t reverse-engineer it to figure out my private key. It’s like magic math that keeps our conversations private and secure.</p><p>With this system, I can also digitally “sign” messages using my private key, showing that they really come from me. Others can verify this signature using my public key, ensuring the message hasn’t been tampered with and that it genuinely originates from the sender.</p><p>So, asymmetric encryption is all about this clever dance between two keys — one to lock, the other to unlock. It’s a key player in the world of online security.</p><h4>Advantages</h4><ol><li><strong>Enhanced Key Distribution:</strong> Asymmetric encryption mitigates the risk associated with sharing the same key among parties. It employs separate keys for encryption and decryption, bolstering security.</li><li><strong>Scalability and Complexity Management:</strong> As networks grow larger with numerous users Asymmetric encryption utilises a pair of mathematically related keys, eliminating the need for widespread key distribution and easing the scalability process.</li><li><strong>Built-in Authentication:</strong> Asymmetric encryption inherently incorporates mechanisms to verify the sender’s identity and ensure message integrity.</li><li><strong>Multiple Use-Cases:</strong> Asymmetric encryption extends its utility beyond data encryption, proving effective for secure key exchange tasks. Asymmetric encryption excels in establishing secure connections and facilitating safe information sharing.</li><li><strong>Long-Term Security and Adaptability:</strong> Asymmetric encryption allows the generation of new key pairs as needed, adapting to evolving security landscapes and ensuring sustained protection.</li></ol><h3>Symmetric encryption</h3><p>Alternative options to asymmetric encryption are symmetric encryption (using the same key for both parties)</p><p>Symmetric encryption is like having a single key that I use both to lock and unlock a treasure chest of messages. Just like my house key works for both locking and unlocking the door, this encryption method relies on a shared secret key for both scrambling and unscrambling messages.</p><p>When I want to send a secret message, I use this shared key to scramble up the words. To read the message, the recipient uses the same key to unscramble it. It’s like a secret code that only we both know.</p><h4><strong>Advantages</strong></h4><ol><li><strong>Speed:</strong> Symmetric encryption are generally faster than asymmetric encryption because of fewer complex calculations.</li><li><strong>Simplicity:</strong> The process is simpler since the same key is used for both encryption and decryption, making it easier to implement and manage.</li><li><strong>Efficiency:</strong> Symmetric encryption is efficient for encrypting large amounts of data, making it suitable for tasks like file encryption.</li><li><strong>Resource-friendly: </strong>It requires less computational power, which can be beneficial for resource-constrained devices and systems.</li><li><strong>Security:</strong> When properly managed and used for short-term purposes, symmetric encryption can provide strong security.</li></ol><p>Hence, looking into these strength I hope you can easily decide which one you want to use based on your use-case.</p><h3>Private-Public Key Generation</h3><p>Here’s a simplified example of RSA key pair generation using small numbers for illustration purposes:</p><ol><li><strong>Choose Two Prime Numbers: </strong>Let’s pick two small prime numbers: p = 11 and q = 17.</li><li><strong>Calculate N:</strong> Compute N = p * q = 11 * 17 = 187.</li><li><strong>Compute φ(N): </strong>φ(N) = (p — 1) * (q — 1) = 10 * 16 = 160.</li><li><strong>Select Public Exponent E:</strong> Choose E = 7. Since 7 and 160 are co-prime (they have no common factors other than 1), this is a valid choice.</li><li><strong>Calculate Private Exponent D:</strong> Compute D such that (E * D) % φ(N) = 1. In this case, D = 23 because (7 * 23) % 160 = 1.</li><li><strong>Public Key: </strong>Your public key is (N, E) = (187, 7).</li><li><strong>Private Key:</strong> Your private key is (N, D) = (187, 23).</li></ol><p>Now, let’s use these keys for encryption and decryption:</p><ul><li><strong>Encryption</strong>: If you want to send a message, convert the message into a numerical value (using a suitable scheme) and raise it to the power of E (7 in this case) and take the remainder when divided by N (187). This cipher-text can be sent securely.</li><li><strong>Decryption</strong>: The recipient uses the private key (N, D) to raise the cipher-text to the power of D (23) and takes the remainder when divided by N (187). This process retrieves the original numerical value, which can then be converted back to the original message.</li></ul><blockquote><strong>Note:</strong> Larger the prime numbers the number more secure is your encryption key, However, this would require more computational power for doing encryption and decryption</blockquote><h3>Use-cases</h3><p>Here are some of the use-cases where I found we are using asymmetric encryptions to its strength</p><ol><li><strong>Secure Communication:</strong> You can use it to build a secure online communication, including emails, messaging apps, and sensitive data exchanges, ensuring that only authorised recipients can access the information.</li><li><strong>Digital Signatures:</strong> Digital signatures verify the authenticity of digital documents, contracts, and transactions, assuring that they haven’t been altered and are from a trusted source.</li><li><strong>Online Transactions:</strong> Asymmetric encryption safeguards online financial transactions, such as credit card payments, by encrypting sensitive payment information during transmission.</li><li><strong>Authentication: </strong>This plays an important role in user authentication, allowing individuals to securely log in to websites and systems with strong encryption methods.</li><li><strong>Certificate Authorities:</strong> Asymmetric encryption is used in SSL/TLS certificates, ensuring secure connections between websites and users, and validating the legitimacy of websites.</li><li><strong>VPN and Remote Access:</strong> Virtual Private Networks (VPNs) use asymmetric encryption to establish secure connections for remote workers, protecting sensitive data transmission.</li><li><strong>Blockchain:</strong> Asymmetric encryption is integral to blockchain technology, providing secure digital signatures and encryption for transactions and blocks in the chain.</li><li><strong>Password Reset: </strong>Asymmetric encryption helps securely reset passwords by encrypting temporary reset links or codes, preventing unauthorised access to account recovery.</li></ol><h3>References</h3><p>Some references of RFCs where you can read more about it</p><ul><li>RFC 2313: This RFC outlines PKCS #1: RSA Encryption Version 1.5.</li><li>RFC 3447: This RFC updates PKCS #1 to Version 2.1, specifically for RSA encryption.</li><li>RFC 5280: This RFC defines X.509 Public Key Infrastructure (PKI) Certificates.</li><li>RFC 5652: This RFC specifies Cryptographic Message Syntax (CMS), which can be used with asymmetric encryption for secure messages.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e43c34aaf82e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[2-factor Authentication using TOTP]]></title>
            <link>https://medium.com/@puran.joshi307/2-factor-authentication-using-totp-a9f1ff1e0b1a?source=rss-969ac0a00925------2</link>
            <guid isPermaLink="false">https://medium.com/p/a9f1ff1e0b1a</guid>
            <category><![CDATA[mfa]]></category>
            <category><![CDATA[2fa]]></category>
            <category><![CDATA[totp]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[otp-verification]]></category>
            <dc:creator><![CDATA[Puran Joshi]]></dc:creator>
            <pubDate>Tue, 11 Jul 2023 22:56:20 GMT</pubDate>
            <atom:updated>2023-07-13T21:32:21.747Z</atom:updated>
            <content:encoded><![CDATA[<p>Strengthening online security using TOTP</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zxLNmoYb9k5sHSXMacu-dQ.png" /></figure><h3>Audience</h3><p>Anyone who wants to enhance the security of their online application, or any technology enthusiasts who want to understand the technical aspect of the two-factor authentication using TOTP.</p><h3>Overview</h3><p>In this article, I aim to provide insights into the concept of two-factor authentication, its significance in enhancing security, and a comprehensive explanation of the Time-Based One-Time Password (TOTP) algorithm. Additionally, I will showcase a sample implementation to offer a practical understanding of how TOTP works.</p><h3>What is 2FA (two-factor authentication)?</h3><p>In the digital world today, we’re seeing a sharp increase in websites losing user data to cyberattacks. These attacks are becoming more advanced, leaving companies exposed and unable to defend against them. It’s not just a matter of trust being broken; organisations of all sizes, from big companies to small businesses and non-profits, suffer serious financial and reputational damage. It’s clear that old security systems can’t keep up with these new threats. We need to take action and strengthen our defenses to protect both data and trust.</p><p>2-Factor Authentication (2FA) adds an extra layer of security to make sure that only the right people can access an online account. Here’s how it works: When you log in, you enter your username and password like usual. But instead of getting in right away, you’ll need to provide another piece of information. This can fall into three categories:</p><ol><li><strong>Something you know</strong>: Some piece of information that only you should know, like a PIN, a password, answers to secret questions, etc…</li><li><strong>Something you have</strong>: This means having a physical item, like a device that could generates token, credit card, etc...</li><li><strong>Something you are</strong>: This means something unique about you like your bio-metics, eye scan, etc...</li></ol><p>By using 2FA with these different factors, we can make it much harder for unauthorised people to get into our accounts and keep our information safe.</p><h3>What is TOTP?</h3><p>In simple terms, Time-Based One-Time Password (TOTP) belongs to the “Something you have” category of 2FA. It means that TOTP relies on something physical that you possess, like your smartphone or a special token. These devices generate unique passwords that change over time. This extra step makes it harder for bad guys to get into your account because they would need both your regular password and the constantly changing special password from your device.</p><p><a href="https://datatracker.ietf.org/doc/html/rfc6238"><strong>RFC 6238</strong></a> defines the technical specifications and guidelines for implementing TOTP as a time-based authentication mechanism. This document outlines the algorithm, encoding, and validation process for generating and verifying one-time passwords based on a shared secret key and the current time.</p><h3>Implementing TOTP</h3><p>Here’s the algorithm for Time-Based One-Time Password (TOTP) based on RFC 6238:</p><ol><li><strong>Set up a shared secret key: </strong>The user and the server establish a shared secret key. This key is securely exchanged or generated during the initial setup.</li><li><strong>Determine the current time:</strong> Obtain the current time in Unix time format, which is the number of seconds elapsed since January 1, 1970 (UTC).</li><li><strong>Generate a counter value:</strong> Divide the current time by a predefined time interval (typically 30 seconds) to obtain a counter value. This ensures that the counter value changes at regular intervals.</li><li><strong>Convert the counter to an 8-byte array:</strong> Represent the counter value as an 8-byte array using big-endian byte order.</li><li><strong>Apply the HMAC-SHA1 algorithm:</strong> Use the shared secret key as the HMAC-SHA1 algorithm key to hash the counter value. This produces a 20-byte hash value.</li><li><strong>Dynamic Truncation:</strong> Take the last 4 bytes of the hash value (specifically, the 31st to 34th bytes) as an offset. Perform a bitwise AND operation with a binary mask to obtain a 4-byte dynamic truncation value.</li><li><strong>Apply a specific encoding:</strong> Convert the dynamic truncation value to a human-readable format. This can be done by taking the 4-byte value modulo 10^d, where “d” is the desired number of digits (typically 6).</li><li><strong>Format the result:</strong> Pad the resulting value with leading zeros if needed to achieve the desired number of digits.</li></ol><p>The resulting value is the TOTP, which is a time-based one-time password that can be used for authentication. This algorithm ensures that the TOTP is generated based on the shared secret key, the current time, and a consistent hashing process, allowing for secure and synchronised authentication between the user and the server.</p><h4>Sequence Diagram</h4><p><strong>1. Registration flow</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SNd7uG4qOKe8kkAndX_xlQ.png" /><figcaption>TOTP Registration Flow</figcaption></figure><p><strong>2. OTP Validation flow</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*22Iw-E3yypRaSZopmQrLOg.png" /><figcaption>OTP Validation Flow</figcaption></figure><h4>Sample Code</h4><p>Below is a sample code that would generate an TOTP based on current timestamp and shared secret.</p><pre>fun generateTOTP(sharedSecret: ByteArray): String {<br>    val timeStep = 30 // Time step in seconds<br>    val digits = 6 // Number of digits in the generated TOTP<br><br>    val counter = Instant.now().epochSecond / timeStep<br>    val counterBytes = ByteBuffer.allocate(8).putLong(counter).array()<br><br>    val hmacKey = SecretKeySpec(sharedSecret, &quot;HmacSHA1&quot;)<br>    val hmac = Mac.getInstance(&quot;HmacSHA1&quot;)<br>    hmac.init(hmacKey)<br><br>    val hash = hmac.doFinal(counterBytes)<br>    val offset = hash[hash.size - 1].toInt() and 0x0F<br><br>    val truncatedHash = (hash[offset].toInt() and 0x7F shl 24) or<br>            (hash[offset + 1].toInt() and 0xFF shl 16) or<br>            (hash[offset + 2].toInt() and 0xFF shl 8) or<br>            (hash[offset + 3].toInt() and 0xFF)<br><br>    val otp = truncatedHash % Math.pow(10.0, digits.toDouble()).toInt()<br>    return otp.toString().padStart(digits, &#39;0&#39;)<br>}</pre><h4>Considerations and Best Practices</h4><p><strong>Secure Key Storage: </strong>The shared secret key must be securely stored to prevent unauthorised access.</p><p><strong>User Education:</strong> Users should be educated about the importance of protecting their TOTP secrets, avoiding phishing attacks, and enabling account recovery mechanisms.</p><h4>Time Synchronisation</h4><p>Handling the time difference between the server and client device is an important consideration for TOTP to ensure synchronisation. <br>Which can be addressed by using any one of these steps:</p><ol><li><strong>Time drift tolerance:</strong> TOTP typically allows for a certain degree of time drift between the server and the client device. This tolerance accounts for minor variations in clock times. A commonly used value is ±1 time step, where a time step is the interval at which TOTP changes (e.g., 30 seconds).</li><li><strong>Time synchronisation:</strong> It’s crucial to ensure that the server and client device are using synchronised time sources. Both should rely on accurate time references, such as Network Time Protocol (NTP) or a similar mechanism, to minimise the time difference between them.</li><li><strong>Time correction on the client:</strong> In situations where there is a significant time difference between the server and client device, the client can adjust its clock by fetching the server’s time through a secure time synchronisation protocol or by using the server’s time as a reference during the TOTP generation process.</li><li><strong>Server-side validation window:</strong> The server can maintain a validation window that allows TOTP codes generated within a certain time period to be accepted. For example, if the server’s time is ahead of the client’s time, it can validate TOTP codes generated within the previous time step.</li></ol><p>By considering these factors and implementing appropriate time synchronisation measures, the time difference between the server and client device can be effectively managed to ensure the successful verification of TOTP codes.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9f1ff1e0b1a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TDD with CoPilot]]></title>
            <link>https://medium.com/@puran.joshi307/tdd-with-copilot-f227cbc67c10?source=rss-969ac0a00925------2</link>
            <guid isPermaLink="false">https://medium.com/p/f227cbc67c10</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[co-pilot]]></category>
            <category><![CDATA[tdd]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Puran Joshi]]></dc:creator>
            <pubDate>Fri, 30 Jun 2023 06:41:27 GMT</pubDate>
            <atom:updated>2023-06-30T12:32:47.224Z</atom:updated>
            <content:encoded><![CDATA[<p>Coding along side AI</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fJyeJI-F3lAQspLi-BMeYA.png" /></figure><h3>Audience</h3><p>Software engineers who are interested in Test-Driven Development (TDD) and seeking to improve their efficiency, as well as those who dislike composing repetitive and standard code.</p><h3>Overview</h3><p>Before we start I wanted to mention that I will not delve deeply into Test-Driven Development (TDD) since I assume that you are already familiar with it. However, if you are not familiar with TDD, I recommend listening to Uncle Bob’s explanation of the concept.</p><p>My main objective is to demonstrate how CoPilot can be utilised during software development using the Test-Driven Development (TDD) approach.</p><p>But before we go into this topic let me introduce you to coPilot.</p><h3>CoPilot</h3><p>CoPilot is a powerful code editor extension that provides AI-powered code suggestions and autocompletion, making it an excellent tool for streamlining Test-Driven Development (TDD) and enhancing productivity. It is a paid tool that needs to be purchased separately.</p><p>Some of the features of coPilot are</p><ul><li>AI-powered code suggestions and autocompletion</li><li>Support for multiple programming languages, including Python, JavaScript, TypeScript, Ruby, and more</li><li>Customisable code snippets and templates for faster coding</li><li>Real-time collaboration with other developers using Live Share</li><li>Code analysis and error detection to help catch mistakes early</li><li>Integration with popular code editors, including IntelliJ, Visual Studio Code and Atom</li></ul><p>Please note just like any machine learning model, coPilot has been trained on a vast amount of open-source code available on the internet. The model has been trained to recognise patterns in code and generate suggestions based on those patterns. As you keep writing code using CoPilot, the tool continues to learn and improve its suggestions. This means that over time, CoPilot becomes more accurate and can provide you more relevant suggestions. Additionally, CoPilot allows you to provide feedback on its suggestions, which can further improve the accuracy of its machine learning model.</p><p>Let’s take a look at a demonstration of how CoPilot can assist me during the coding process.</p><h3>Demonstration</h3><h4><strong>Problem Statement</strong></h4><p>I want to write a URL shortening service that allows users to shorten long URLs into short and easy-to-remember links.</p><p><strong>Note</strong> - The video aims to demonstrate a pragmatic approach to writing controllers using Test-Driven Development (TDD) with the assistance of CoPilot’s code suggestion feature</p><p><a href="https://youtu.be/CHRhDPMUy5Y">Youtube link to see live demonstration</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FCHRhDPMUy5Y%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DCHRhDPMUy5Y&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FCHRhDPMUy5Y%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/e1a3983b9ebc125ca4cdcce71a2a0adc/href">https://medium.com/media/e1a3983b9ebc125ca4cdcce71a2a0adc/href</a></iframe><h4>Highlights</h4><ol><li>coPilot has the ability to suggest test code based on the name of the test method, as shown below.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h7n3-FAN-JRW3x820rI63g.png" /></figure><p>2. Also, helps you with writing the code to fix it</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7PlSxe6DcIVK-tBtZfED6g.png" /></figure><p>3. Just start writing the mock and it will help you complete them</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v70oij4Z8rrjk476BvGxYQ.png" /></figure><p>4. Furthermore, coPilot can provide suggestions on your next potential test scenario.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mT9mC-KZ1k2YlxZXEbB09w.png" /></figure><p>However if you want to look at the source code feel free to checkout this <a href="https://github.com/PuranJoshi/shortify">GitHub Link</a></p><blockquote>While CoPilot is a relatively new tool and has room for improvement, it has already proven to be beneficial in increasing my productivity by at least a certain percentage.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f227cbc67c10" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How: A try-catch block works]]></title>
            <link>https://medium.com/@puran.joshi307/how-it-works-try-catch-61e90b18140a?source=rss-969ac0a00925------2</link>
            <guid isPermaLink="false">https://medium.com/p/61e90b18140a</guid>
            <category><![CDATA[exception-handling]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[try-catch]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[show]]></category>
            <dc:creator><![CDATA[Puran Joshi]]></dc:creator>
            <pubDate>Tue, 13 Jun 2023 07:54:06 GMT</pubDate>
            <atom:updated>2023-06-13T08:09:29.826Z</atom:updated>
            <content:encoded><![CDATA[<p>Understanding the working of a try-catch block</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*42wgDSAx-nOoIymnAspVPA.png" /><figcaption>try-catch</figcaption></figure><h4>Audience</h4><p>Engineers who are keen in learning the internal working of the try-catch block for most programming language</p><h4>Overview</h4><p>This article will provide an understanding of how try-catch blocks handle exceptions thrown by a program. To illustrate this concept, we will focus on one of the most common exceptions encountered during the early stages of a programming career.</p><h4>Try-catch block working</h4><p>Suppose you have written the following code sample and enclosed it within a try-catch block to manage a custom exception, which we will refer to as an ArithmeticException for the time being.</p><pre>try {<br>    val result = numerator / denominator <br>} catch (e: ArithmeticException) {<br>    // Handle the divide by zero exception<br>    // ...<br>}</pre><p>Now when a program encounters an arithmeticException (suppose divide by zero), it will typically follow a series of steps to handle this exception. Here’s how these steps might look:</p><ol><li>When a program tries to divide a number by zero, it realises that this is not possible and throws an error message called an exception.</li><li>The program creates a exception object to represent the error message, which contains information about what went wrong.</li><li>The program keeps track of where it was in the code when the error occurred, so it can go back to that point later.</li><li>The program looks for a special section of code called a catch block that knows how to handle the error message.</li><li>If the program finds a catch block that can handle the error message, it runs that code to deal with the problem.</li><li>After the catch block has finished running, the program goes back to where it was in the code before the error occurred.</li><li>If the program can’t find a catch block that can handle the error message, it may show an error message to the user and stop running.</li><li>If there is a special section of code called a finally block, it runs after the catch block to clean up any resources that were being used.</li><li>Once the finally block has finished running, the program goes back to where it was in the code before the error occurred.</li><li>The program may also free up any memory that was being used by the error message, so it doesn’t take up unnecessary space in the computer’s memory.</li></ol><p>Overall, when a divide by zero exception occurs, the program will follow a series of steps to handle the exception and prevent it from causing the program to crash or behave unpredictably. By using exception handling mechanisms like try-catch blocks, programs can gracefully handle unexpected errors and prevent them from causing serious problems.</p><blockquote>NOTE: the specific implementation of exception handling may vary between programming languages and environments.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=61e90b18140a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Code Refactoring Techniques for Clean Code]]></title>
            <link>https://medium.com/@puran.joshi307/code-refactoring-techniques-for-clean-code-615ee0c6a4bf?source=rss-969ac0a00925------2</link>
            <guid isPermaLink="false">https://medium.com/p/615ee0c6a4bf</guid>
            <category><![CDATA[coding-style]]></category>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[code-refactoring]]></category>
            <category><![CDATA[code-review]]></category>
            <category><![CDATA[code-readability]]></category>
            <dc:creator><![CDATA[Puran Joshi]]></dc:creator>
            <pubDate>Fri, 09 Jun 2023 08:28:26 GMT</pubDate>
            <atom:updated>2023-06-09T09:01:26.421Z</atom:updated>
            <content:encoded><![CDATA[<p>Code Refactoring: Simplify, Streamline, and Shine</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r4jX_vgGfEDDkPnBHhFHqw.png" /></figure><h4>Audience</h4><p>Software Engineers, product managers who are concerned about code quality, maintainability and scalability of your application.</p><h4>Overview</h4><p>I want to share my experience with code refactoring and answer some basic questions about it. I’ll explain why, when, and how we can practice code refactoring. Towards the end of the article, I’ll dive into a refactoring strategy that you can use in your own projects. So, if you’re interested in improving your code and making it easier to maintain, keep reading!</p><h4><strong><em>Experience</em></strong></h4><p>When I first started my career, I used to think that conducting code reviews was enough to maintain code quality. I never considered scalability and maintainability while reviewing the code.</p><p>However, as time passed and I had to add new features or extend the code, I found it difficult to incorporate changes. This often resulted in code smells and, at times, even bugs on the production environment.</p><p>Having worked as a code writer in various organisations for over a decade, I can confidently say that incorporating code-refactoring practices in your daily work routine can make a significant difference in your career. It can help you achieve great heights and take your skills to the next level.</p><p>Now moving back to basic question around code-refactoring</p><h4><strong><em>Why we need to refactor?</em></strong></h4><p><em>In simple words below are the reasons why you should make code refactoring as an integral part of your development workflow</em></p><ol><li>Enhances code quality and reduces code-smells</li><li>Peers find it easy to read and understand</li><li>Codebase becomes easy to scale and adapt</li><li>Reduces technical debt, and keeps the code maintainable</li><li>Minimises future development risks</li><li><strong>S</strong>treamlines algorithms, and</li><li>Improves data structures for better overall performance and efficiency.</li></ol><blockquote>“Please don’t treat refactor as one time event”</blockquote><h4>When to refactor code?</h4><ol><li>Code Reviews</li><li>Bug Fixing</li><li>New Feature Implementation</li><li>Performance Optimisation</li><li>Removing Technical Debt</li></ol><blockquote>“I am not advocating dedicating 100% of your time into refactoring but having a balance between writing new code and refactoring. In short try to follow a boy-scout rule.”</blockquote><h4>How to perform refactor?</h4><p>Some techniques I used for performing code refactor are</p><ol><li>Extracting a piece of code into a separate method</li><li>Rename my variables, method or class names to reflect their purpose</li><li>Grouping methods or properties into appropriate classes</li><li>Simplifying complex conditional logic by combining multiple conditions</li><li>Replacing nested if-else conditions with early returns or guard clauses</li><li>Replacing hard-coded numbers with named constants</li><li>Dividing long methods into smaller more focused methods</li><li>Extracting duplicate code into reusable methods</li><li>Learning and applying well known design patterns like factory, strategy patterns</li><li>Encapsulating related parameters into a single object to simplify method signature</li></ol><blockquote>“These are just a few examples of refactoring techniques that I use to improve code quality and maintainability. Each of these technique addresses specific code smells or design issues and contributes towards writing clean, readable, and maintainable code.”</blockquote><h4>Refactoring Tools and Strategies</h4><p>Lastly, I would like to draw your attention to some tools and strategies that you can utilise to assist you with your refactoring process.</p><p><strong>Refactoring Tools:</strong></p><ol><li>Integrated Development Environments (IDEs) provide built-in refactoring tools that assist developers in automatically applying common refactoring.</li><li>Code analysis tools help identify potential code smells and suggest refactoring based on predefined rulesets.</li><li>Many programming languages and frameworks have dedicated plugins or libraries that offer automated refactoring capabilities. For example, ReSharper for C#, PyCharm for Python, and RuboCop for Ruby.</li></ol><p><strong>Refactoring Strategies:</strong></p><ol><li>Test-Driven Refactoring</li><li>Incremental Refactoring</li><li>Peer Reviews and Pair Programming</li><li>Version Control System to track and manage refactoring changes</li></ol><h4><strong>Conclusion</strong></h4><p><em>In conclusion, regular code refactoring is a vital practice for maintaining a healthy and sustainable codebase. By continuously improving the structure, readability, and maintainability of our code. Moreover, it empowers us to work more efficiently, collaborate effectively, and adapt to changing requirements with ease. Embracing code refactoring as an ongoing process fosters a culture of craftsmanship, continuous improvement, and long-term success in software development endeavours.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=615ee0c6a4bf" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>