<?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 Deepak Choudhary on Medium]]></title>
        <description><![CDATA[Stories by Deepak Choudhary on Medium]]></description>
        <link>https://medium.com/@deepakschoudhary?source=rss-b9afaa8107ae------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Y64ly4BKNUtihDT6N1ikyA.jpeg</url>
            <title>Stories by Deepak Choudhary on Medium</title>
            <link>https://medium.com/@deepakschoudhary?source=rss-b9afaa8107ae------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 06:09:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@deepakschoudhary/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[Go Big or Go Home: TypeScript’s Leap to Lightning Speed]]></title>
            <link>https://deepakschoudhary.medium.com/go-big-or-go-home-typescripts-leap-to-lightning-speed-64d153061275?source=rss-b9afaa8107ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/64d153061275</guid>
            <category><![CDATA[microsoft]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[rust-programming-language]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Deepak Choudhary]]></dc:creator>
            <pubDate>Thu, 13 Mar 2025 18:09:54 GMT</pubDate>
            <atom:updated>2025-03-13T18:09:54.345Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PyQ2s-gYFmz3sIELgCKGFA.png" /></figure><blockquote>…we’ve begun work on a native port of the TypeScript compiler and tools. The native implementation will drastically improve editor startup, reduce most build times by 10x, and substantially reduce memory usage.</blockquote><p>Yes, above is an excerpt taken from the latest <a href="https://devblogs.microsoft.com/typescript/typescript-native-port/">post</a> as well as this <a href="https://www.youtube.com/watch?v=pNlq-EVld70&amp;t=12s">YouTube video</a>. Microsoft just announced a monumental movement for TypeScript which solidifies not just their intent on staying in the game for the long haul but also highlights how a brilliant architecture decision can make or break your product.</p><p>In this article we shall deep dive into all questions that may arise in your mind, and I shall do my best to tell you all I can as a developer who has been a fan of both technologies.</p><h4>What is all the fuss about?</h4><p>Microsoft is developing a native TypeScript implementation based on Google’s Go language. The initiative promises dramatic improvements in editor startup speed, build times, and memory usage, making it easier to scale TypeScript to large code bases, Microsoft said. Announced March 11, the plan involves porting the TypeScript compiler, tools, and code base from JavaScript to Go.</p><h4>What is TypeScript?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/121/0*ui8GPWzOsT65rytK.png" /></figure><p>TypeScript for the uninitiated is basically a superset of JavaScript and has been gaining a lot of popularity in the developer community since its introduction in 2012 by Microsoft. TypeScript as per its website is basically, “JavaScript with Syntax for Types”.</p><h4>Why was this “port” needed?</h4><p>As a codebase grows, so does the value of TypeScript itself, but in many cases TypeScript has not been able to scale up to the very largest codebases. Developers working in large projects can experience long load and check times and have to choose between reasonable editor startup time or getting a complete view of their source code.</p><p>The TypeScript compiler (tsc) is currently written in TypeScript which has JavaScript at it’s core. This can produce a limitation when it comes t</p><h4>What is being ported?</h4><p>The following parts are expected to be migrated:</p><ul><li>The command line TypeScript compiler</li><li>The TypeScript language server (which helps editors support TypeScript)</li><li>Tools that use the TypeScript code base</li></ul><h4>Why a port and not a rewrite from scratch?</h4><p>This question is thoroughly answered in this <a href="https://github.com/microsoft/typescript-go/discussions/410">GitHub link</a>. However, I shall sum it up for you in three words, “it saves time”. Yes, a port takes lesser effort on the product company to port than rewrite the product from scratch. It also saves developer’s time who use the product as they do not have to worry about upgrading their versions of the said product. Do not have to worry about new versions not being backwards compatible.</p><h4>Why Go? No better technology in the market?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FfENqmJvSqTe3Azg.png" /></figure><p>When the announcement came out, the developer community seemed to be more divided than ever before. Some were happy with the shift towards Go, some wondering why Rust was not chosen, whereas some still are shocked at Microsoft passing over technologies like Java and C#.</p><p>While all the above mentioned are great, <a href="https://www.linkedin.com/in/ryan-cavanaugh-aa4a37106/">Ryan Cavanaugh</a>, a lead developer of TypeScript, <a href="https://www.reddit.com/r/programming/comments/1j8s40n/comment/mh7n5n0/?utm_source=share&amp;utm_medium=web3x&amp;utm_name=web3xcss&amp;utm_term=1&amp;utm_content=share_button">clarified</a> the stance, admitting that they had anticipated a debate over this. He said that while Rust was considered an option, the ‘key constraint’ was portability, which ensured that the new codebase was algorithmically similar to the current one.</p><blockquote>“Transitioning” to Go was much simpler than “Translating” to Rust</blockquote><h4>What is this project Corsa?</h4><p>This project which aims at revamping the tsc codebase to now use Go.</p><h4>What do these “performance gains” look like? Can it walk the walk?</h4><p>While the final numbers are going to take some time, the good fellows at Microsoft were quick to share some initial findings which can be seen below in the chart. As you can see, the performance gains are something of a dream.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*a4NYEvfKi9QqBhMGayNYKg.png" /><figcaption>Source: <a href="https://devblogs.microsoft.com/typescript/typescript-native-port/">A 10x Faster TypeScript — TypeScript</a></figcaption></figure><h4>What does the future look like now for TypeScript?</h4><p>Well, the current version of TypeScript is 5.8. The JavaScript codebase will continue well into the 6.x series whilst including some breaking changes to align with the native codebase.</p><p>Once the native code base has reached sufficient parity with the JavaScript codebase, it’ll be released as TypeScript 7.0. One thing developers around the globe can rest assured is that both codebases will be available for a long time.</p><h4>Conclusion</h4><p>All being said, this decision highlights a key outtake about how to take architectural decisions when it comes to software. It’s not always about using the latest and greatest tech. It’s about sticking to principles of your technology. Staying true to the nature of your product whilst still being pragmatic in your approach. Rust would have been an excellent option and would have even given a better performance boost but the port to Go was simpler, still gives great performance boosts and is much more intuitive as a codebase. Go along with it’s focus on simplicity and developer experience is something that coincided with TypeScript’s focus on developer experience as well. Microsoft, tech giant who has technologies like the C# too which it could have used too, since it’s inhouse decided to take up a technology coming from the house of Google because that was the best option.</p><p>In my personal opinion, this was a great news to hear, and I look forward to using the new compiler in my projects too once it’s stable (can’t compromise on my products either :P).</p><p>— Deepak Choudhary<br>Phalgun Shukla Chaturdashi, Vikram Samvat 2081</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=64d153061275" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ātmachintan series: Redefining “success” in a highly social world]]></title>
            <link>https://deepakschoudhary.medium.com/%C4%81tmachintan-series-redefining-success-in-a-highly-social-world-977a1a38931f?source=rss-b9afaa8107ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/977a1a38931f</guid>
            <category><![CDATA[societal-pressures]]></category>
            <category><![CDATA[embracing-yourself]]></category>
            <category><![CDATA[introspection]]></category>
            <category><![CDATA[redefining-success]]></category>
            <category><![CDATA[breaking-norms]]></category>
            <dc:creator><![CDATA[Deepak Choudhary]]></dc:creator>
            <pubDate>Mon, 24 Feb 2025 05:04:49 GMT</pubDate>
            <atom:updated>2025-02-24T05:04:49.521Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d_Mm0aStxxwK05F-kWsVhw.jpeg" /></figure><p>Success is a concept that has been debated and redefined countless times throughout history. Despite this, many of us still find ourselves chasing a version of success that is not truly our own. This is because our definitions of what it means to be “successful” often come from societal expectations rather than our personal aspirations and values.</p><h4>The Societal Blueprint of Success</h4><p>From a young age, we are bombarded with messages about what success should look like. Society often equates success with wealth, status, and power. We are told that to be successful, we must achieve high grades, secure prestigious jobs, and accumulate material possessions. These societal benchmarks create a narrow and often unattainable vision of success that can leave many feeling inadequate or unfulfilled.</p><p>However, this societal blueprint of success is not universal. It varies across cultures, communities, and individuals. What one society values as success may be entirely different from another’s perspective. This variability highlights the subjective nature of success and the importance of questioning the definitions imposed upon us.</p><h4>Aspiring for the Greater Good</h4><p>True success, many argue, comes from aspiring for the greater good rather than merely fulfilling societal expectations. This means focusing on contributions that positively impact others and the world around us. Whether it’s through acts of kindness, community service, or innovative solutions to global challenges, success can be found in the pursuit of making a difference.</p><p>Aspiring for the greater good shifts the focus from self-centered achievements to collective well-being. It encourages us to think beyond our personal gains and consider how our actions can benefit others. This perspective not only brings a deeper sense of fulfillment but also fosters a more compassionate and connected society.</p><h4>Small Victories</h4><p>Success can also be found in small, personal victories that may seem insignificant to others but hold great meaning for the individual. For someone who has struggled with stage fright, being able to speak confidently on stage is a monumental achievement. Similarly, for someone who has battled social anxiety, attending a social event and engaging in conversations can be a significant success. For another, learning a new skill or hobby, such as playing a musical instrument or cooking a new recipe, can be a source of immense pride and fulfillment.</p><p>These small achievements are not measured by societal standards but by personal growth and overcoming significant challenges. The journey to these successes involves facing fears, practicing diligently, and gradually building self-assurance. Each step forward, no matter how small, is a testament to resilience and determination. Celebrating these personal milestones is crucial, as they contribute to a sense of accomplishment and self-worth.</p><h4>The Pitfalls of Material Aspirations</h4><p>In contrast, aspiring for a bigger car, a higher salary, or other material possessions can be seen as more animalistic and not at the level of consciousness that humans are capable of achieving. These desires are often driven by basic instincts and societal pressures rather than genuine fulfillment. While there is nothing inherently wrong with wanting financial stability or comfort, making these the primary goals of our lives can lead to a shallow and unfulfilling existence.</p><p>Material aspirations can trap us in a cycle of constant comparison and competition, where our self-worth is tied to external achievements and possessions. This mindset can prevent us from reaching a higher level of consciousness, where we prioritize personal growth, meaningful relationships, and contributions to the greater good.</p><h4>Understanding Failure</h4><p>To redefine success, we must first understand failure. Society often stigmatizes failure, viewing it as a sign of weakness or incompetence. However, failure is an inevitable part of any journey and a crucial component of growth and learning. By reframing failure as a valuable experience rather than a setback, we can develop resilience and a more nuanced understanding of success.</p><p>Failure teaches us important lessons about our strengths, weaknesses, and areas for improvement. It provides opportunities for reflection and self-discovery, helping us to refine our goals and strategies. Embracing failure as a natural and necessary part of life allows us to approach success with a more balanced and realistic mindset.</p><h4>Creating a Personalized Definition of Success</h4><p>Ultimately, success is a deeply personal concept that should be defined by our individual values, passions, and experiences. To create a personalized definition of success, we must first identify what truly matters to us. This involves introspection and a willingness to challenge societal norms and expectations.</p><p>Consider what brings you joy, fulfillment, and a sense of purpose. Reflect on your passions, strengths, and the impact you want to have on the world. By aligning your definition of success with your authentic self, you can pursue goals that are meaningful and satisfying.</p><h4>The Journey of Personal Growth</h4><p>The journey to defining personal success is also a journey of personal growth. It requires us to continuously evaluate and adjust our goals as we evolve. This process of self-discovery and adaptation is essential for achieving a sense of fulfillment and contentment.</p><p>Personal growth involves setting realistic and achievable goals, celebrating small victories, and learning from setbacks. It also means being open to change and willing to take risks. By embracing a growth mindset, we can navigate the challenges and uncertainties of life with confidence and resilience.</p><h4>The Role of Community and Support</h4><p>While success is a personal journey, it is also influenced by the support and encouragement of others. Building a strong network of family, friends, and mentors can provide valuable guidance and motivation. These relationships can help us stay grounded, offer different perspectives, and remind us of our worth beyond societal expectations.</p><p>Community support also plays a crucial role in our ability to contribute to the greater good. By working together and supporting each other’s goals, we can create a positive impact that extends beyond our individual achievements.</p><h4>Conclusion</h4><p>In conclusion, success is not a one-size-fits-all concept dictated by society. It is a personal journey that requires us to aspire for the greater good, understand and embrace failure, and create our own definitions based on our unique values and aspirations. By doing so, we can achieve a more fulfilling and authentic version of success that resonates with who we truly are.</p><p>Success is about finding balance, pursuing what truly matters, and making a positive impact on the world. It is a journey of self-discovery, growth, and connection with others. By redefining success on our own terms, we can lead more meaningful and satisfying lives.</p><p>— Deepak Choudhary<br>Phalgun Krishna Dwadashi, Vikram Samvat 2081</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=977a1a38931f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hindu Itihāsa Series: Your worst enemy]]></title>
            <link>https://deepakschoudhary.medium.com/hindu-itih%C4%81sa-series-your-worst-enemy-1c22a3b24839?source=rss-b9afaa8107ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c22a3b24839</guid>
            <category><![CDATA[confidence]]></category>
            <category><![CDATA[self-improvement]]></category>
            <category><![CDATA[mahabharata]]></category>
            <category><![CDATA[itihasa]]></category>
            <category><![CDATA[dharma]]></category>
            <dc:creator><![CDATA[Deepak Choudhary]]></dc:creator>
            <pubDate>Sat, 25 Jan 2025 14:36:18 GMT</pubDate>
            <atom:updated>2025-01-25T14:36:18.322Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6oAAsmyJEofcrzxY" /><figcaption>Arjuna lifting his G<a href="https://medium.com/@deepakschoudhary/hindu-itih%C4%81sa-series-a-tale-about-jealousy-7e3648bf17cd?source=your_stories_page-------------------------------------">ā</a>ndiva [source: Arjuna: The Warrior Prince (film)]</figcaption></figure><h4>Prologue</h4><p>The kingdom of Aryavarta is under the leadership of Dhritar<a href="https://medium.com/@deepakschoudhary/hindu-itih%C4%81sa-series-a-tale-about-jealousy-7e3648bf17cd?source=your_stories_page-------------------------------------">ā</a>shtra. The princes, both p<a href="https://medium.com/@deepakschoudhary/hindu-itih%C4%81sa-series-a-tale-about-jealousy-7e3648bf17cd?source=your_stories_page-------------------------------------">ā</a>ndavas and kuru had recently come under the tutelage of the great Dron<a href="https://medium.com/@deepakschoudhary/hindu-itih%C4%81sa-series-a-tale-about-jealousy-7e3648bf17cd?source=your_stories_page-------------------------------------">ā</a>ch<a href="https://medium.com/@deepakschoudhary/hindu-itih%C4%81sa-series-a-tale-about-jealousy-7e3648bf17cd?source=your_stories_page-------------------------------------">ā</a>rya. It did not take long for the p<a href="https://medium.com/@deepakschoudhary/hindu-itih%C4%81sa-series-a-tale-about-jealousy-7e3648bf17cd?source=your_stories_page-------------------------------------">ā</a>ndavas to get closer to the teacher as they encompassed all that was considered a behaviour suited for good students. But even among them, Arjuna was who Drona favoured more. This open favouritism is something the kuru princes did not approve of. To Duryodhana, it was like a thorn in his foot on the way to one day ruling this great kingdom. Chakravarti is what they called the kingdom, one whose rule spreads in all eight directions.</p><h4>The story begins</h4><p>Guru Drona openly favored the p<a href="https://medium.com/@deepakschoudhary/hindu-itih%C4%81sa-series-a-tale-about-jealousy-7e3648bf17cd?source=your_stories_page-------------------------------------">ā</a>ndavas and especially Arjuna, his most precious student. A fire burnt in the hearts of Duryodhana, Dush<a href="https://medium.com/@deepakschoudhary/hindu-itih%C4%81sa-series-a-tale-about-jealousy-7e3648bf17cd?source=your_stories_page-------------------------------------">ā</a>shana and Dush<a href="https://medium.com/@deepakschoudhary/hindu-itih%C4%81sa-series-a-tale-about-jealousy-7e3648bf17cd?source=your_stories_page-------------------------------------">ā</a>l<a href="https://medium.com/@deepakschoudhary/hindu-itih%C4%81sa-series-a-tale-about-jealousy-7e3648bf17cd?source=your_stories_page-------------------------------------">ā</a> their only sister. Duryodhana kept wondering to himself about the reason for this favoritism. What was it!! What were these Pandavas doing that Drona saw them as Devat<a href="https://medium.com/@deepakschoudhary/hindu-itih%C4%81sa-series-a-tale-about-jealousy-7e3648bf17cd?source=your_stories_page-------------------------------------">ā</a>s and the Kuru princes as spoilt brats.</p><p>Arjuna on the other hand was like a sponge when it came to learning. His attention wouldn’t waver when the Guru spoke. This was his dedication to his studies. He would wake up early, finish his puja post a bath and start the day of practice with the Guru in the gurukul. While the kuru princes were usually lazy and always cracking jokes amongst themselves, Arjuna made sure to not let any moment go to waste.</p><p>Drona however had a trick up his sleeve. Having finished the day’s activities, the princes were served supper at night in the dining area of the gurukul. Drona made sure that there always was light whenever the princes ate. He had specifically instructed the helpers in the gurukul, “Whatever happens! DO NOT! And I say DO NOT feed the students in dark”.</p><p>The reasons for this weird request came as a surprise for the helpers as they did not understand why he asked them to make sure that the princes did not eat in the dark. It was only Drona who truly knew why.</p><p>Months passed by like a speeding train until one evening when the princes had finished their practice. Arjuna was easily the best warrior amongst the lot. Though archery was his forte, he was equally skilled with other weapons as well as knowledge of society. He was well on his way to master both sh<a href="https://medium.com/@deepakschoudhary/hindu-itih%C4%81sa-series-a-tale-about-jealousy-7e3648bf17cd?source=your_stories_page-------------------------------------">ā</a>stra and shastra. However, Arjuna off late had reached a plateau.</p><p>He couldn’t quite understand how he could improve himself further. Guru Drona would ask him to look inside for the answer but that had not helped. It was all that he could think of. Even now while all other princes ate and talked, he was lost in thought. He made a morsel of his food in his hand and as he slowly moved his hand towards the mouth, a strong wind extinguished the lamp.</p><p>But to his surprise, Arjuna still was able to put food in his mouth. It was now that he realized what eluded him this far. His hands having repeated the actions so much, knew exactly where his mouth was. Be it a brightly lit room or absolute darkness.</p><p>This is what he was missing. He started practicing in the dark, alienating his skill from every other help. It is said that at the peak of his powers, Arjuna did not need to see the target to shoot. His control over his senses was such that even the slightest sound would make him turn and point to the exact location of the source.</p><h4>Lesson</h4><p>Like Arjuna, we too are bounded by restrictions that are put on us. Sometimes by our own selves and sometimes by the circumstances we find ourselves in.</p><p>In the midst of all this, it’s easy to lose confidence if one isn’t well prepared. This is where Arjuna understood the value of practice, the value refining one’s abilities to such an extent that there is no parallel. As the famous quote goes,</p><blockquote>Our deepest fear is not that we are inadequate. Our deepest fear is that we are powerful beyond measure. It is our light, not our darkness that most frightens us.</blockquote><p><em>I hope this piece gives you some insight about the the value of practice as well as putting yourself in a difficult position in order to excel. It’s an effort to preserve teachings from our scriptures and I will be writing about more tales from our itihãsa and dharmashãstras in the future.</em></p><p>— Deepak Choudhary<br>Magha Krishna Ekadashi, Vikram Samvat 2081</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c22a3b24839" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hindu Itihāsa Series: A tale about jealousy]]></title>
            <link>https://deepakschoudhary.medium.com/hindu-itih%C4%81sa-series-a-tale-about-jealousy-7e3648bf17cd?source=rss-b9afaa8107ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e3648bf17cd</guid>
            <category><![CDATA[hinduism]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[mahabharata]]></category>
            <category><![CDATA[india]]></category>
            <category><![CDATA[self-improvement]]></category>
            <dc:creator><![CDATA[Deepak Choudhary]]></dc:creator>
            <pubDate>Tue, 05 Nov 2024 06:40:29 GMT</pubDate>
            <atom:updated>2024-11-05T06:55:00.868Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/540/0*Rer0XXtzQoqUZhQz.jpg" /></figure><h4>Prologue</h4><p>The princes of Hastinapur had by now started their school under the great Dronāchārya. Contrary to what is believed widely, Karna too was a student of Guru Drona amongst the other princes. Adinath, his father had requested the gurus <em>Kripā</em> and <em>Drona</em> to take his son as a pupil and the gurus did oblige. The princes would be taught equally. However, there was one whose devotion won over <em>Drona</em>. Arjuna, with his extreme devotion to the art and excruciating practice he put himself through impressed not just the other princes but the teachers as well. It’s well known that teachers too have favorites and <em>Arjuna</em> was <em>Drona’s</em>.</p><h4>The story starts…</h4><p><em>Arjuna’s</em> closeness to <em>Drona</em> invited admirers and enemies alike. Supported and aided by <em>Duryodhana</em>, <em>Karna</em> envied <em>Arjuna</em> as well as the other <em>Pandavas</em>. Not a moment would pass by when <em>Karna</em> did not try to prove himself better than Arjuna. Like the infamous character of <em>Sardar Khan</em> from the popular Hindi movie <em>Gangs of Wasseypur</em>, Karna too had only one goal in life. Destruction of <em>Arjuna</em>, to prove to all that it was him who was the best archer in <em>Aryavarta</em>(<em>old name for the Indian subcontinent</em>).</p><p>One fine day, <em>Karna</em> approached Guru <em>Drona</em> in private and said, “O guru! <em>Dhananjaya</em> is superior to all of us in the science of weapons. I wish to learn about the Brahma weapon. I want to know all about it, as with its power I shall be invincible.”</p><p>Curious to know his motives, <em>Drona</em> asked him what he intended to do with it as he already was a skilled warrior, second only to the great <em>Phālguna</em>. <em>Karna</em> replied, “I want to battle <em>Arjuna</em> with it!!”</p><p>It was now that the great guru denied him the knowledge of the <em>Brahmāstra</em>. Only a <em>brāhamana</em> who has fulfilled all his vows or a <em>kshatriya</em> who had practiced austere penances shall be worthy of knowing about such a powerful weapon, he mentioned.</p><p>Denied by his guru, the jealousy in Karna’s heart took a greater form. He at once decided to find <em>Parashurāma</em>, one of the greatest warriors alive in the world. He left for <em>Mahendragiri</em> mountains which was known to be the home for the great descendant of <em>Bhrigu</em>. It’s here that <em>Karna</em> told <em>Bhārgava</em> that he was a <em>brāhmana</em> and wished his tutelage and knowing about the Brahma weapon. A lie that would be caught later on when one day his teacher would be sleeping with his head in Karna’s lap and Karna wouldn’t move one bit even though a flesh eating insect was digging into his thigh muscle.</p><p>Only a <em>kshatriya</em> is capable of enduring such high levels of pain and the great warrior was able to spot it. Having spotted it, he would curse <em>Karna</em> about forgetting the knowledge which he earned by lying to his teacher.</p><h4>Lesson</h4><p>Jealousy, like the other seven deadly sins can be a great motivator but also confirms one’s failure ahead. <em>Karna</em>, though a great warrior wanted to better <em>Arjuna</em> so much that he made it his life’s goal. It is due to this that his mind got corrupted. At every step of the way, he tried his best to gain any advantage he could over his foe by any means thereby corrupting his <em>dharma.</em></p><p>Karna had flourished well, even better than Arjuna had he focused on himself and was devoted to learning the skills instead of bettering Arjuna. Similar to Karna in life, we too are often faced with the same circumstance where we come across folks who are perceived better than us and it fills us with a sense of jealousy.</p><p>In times, like these it’s important that we act like Arjuna rather than Karna and work on bettering ourselves keeping our progress in mind instead of pulling down the other person. Similar to the game of “prisoner’s dilemma”, winning together is the best option one has.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e3648bf17cd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hindu Itihāsa Series: Coping with a loss]]></title>
            <link>https://deepakschoudhary.medium.com/hindu-itih%C4%81sa-series-coping-with-a-loss-da56b2bd20d4?source=rss-b9afaa8107ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/da56b2bd20d4</guid>
            <category><![CDATA[grief-and-loss]]></category>
            <category><![CDATA[dharma]]></category>
            <category><![CDATA[mahabharata]]></category>
            <category><![CDATA[death]]></category>
            <category><![CDATA[love]]></category>
            <dc:creator><![CDATA[Deepak Choudhary]]></dc:creator>
            <pubDate>Fri, 11 Oct 2024 10:46:36 GMT</pubDate>
            <atom:updated>2024-10-11T10:46:36.561Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*tLpaLUT6OQJqDA_O" /></figure><h4>Prologue</h4><p>The story goes back to when the royal children of Hastināpur were still quite young. It was back then when Duryodhana was still known as Suyodhana and his siblings Dushāsana and Dushāla were known as Sushāna and Sushāla respectively. <br>It was a warm sunny day at the gurukul of Guru Drona (Dronāchārya), who was as good a teacher as he was a warrior. Drona had recently settled in Hastināpur with his wife Kripi who was the sister of one of the seven immortals in Hindu belief, Kripāchārya and his young son Ashwathāmā, who although younger than the eldest Kuru prince, Suyodhan, was still as tall as Kripa.</p><p>It was a lesson day, much like any other day but the events of this day would be vital in shaping the future of the land of Bharata. The princes along with Ashwathāma had gathered around in an open field, playing with each other, teasing each other and sharing bitter sweet moments between the two camps of Kuru and Pandu.</p><h4>The story begins</h4><p>Whilst the children played amongst themselves, Drona walked with a serious face. Drona, although a great teacher was also known for being quite strict. He commanded all his pupils to gather around and form a line.</p><p>Now that the students were standing in a queue, he approached his own son Ashwathāma. He asked him, “What do you see ?”</p><p>“A tree, sire!”, Ashwathāma spoke with a soft voice. “I see your brains is already muddled after all the time you’ve spent with Suyodhan and gang. Go back to your seat, son. Next was the overly large Bhim who slowly approached his spot next to the Guru upon being called. “And what you see, O Bhim !”</p><p>Taking a pause, Bhim casually replied, “I can see some ripe mangoes on that tree Gurudev”. “Oh ho ho !! Looks like that large tummy of yours hasn’t been fed in a while, huh !!”, replied Drone. His words dripping in sarcasm. Bhim, dragged his feet back to his spot as the other students tried hard to contain their laughter. They knew better to not laugh at Bhim. He was after all, kind of a bully when it came to food or attacks on his ego in his younger years.</p><p>“Suyodhan!!”, roared Drona. His voice growing visibly impatient. “Let’s see what you see Kuru prince!!”, Drona spoke with a smirk as Suyodhan walked hesitantly to the spot. “Its a tree only, what else can one see??!”, young Suyodhan thought to himself when suddenly he saw something.</p><p>“I see…. I see….love. Nestled in those tangled branches, away from this unfair world. I see love, gurudev. Sweet, innocent love”, Suyodhan said in a gentle, loving tone.</p><p>“Look here all !! The blind raja’s kid too is plain simple blind after all!! Love!?? Are you even here in the academy, boy ?”, laughed Drona, hysterically. The remaining students, too burst out laughing. Visibly confused, Suyodhan wondered why they laughed at him.</p><p>“Arjun!! Please step up and tell me what you see! And you, Suyodhan! Stop hanging out with that no good Kripā and his irritating <em>nāstika</em> buddy Cārvāka!!”, commanded Drona.</p><p>Having taken his spot, Arjun replied, “Just the eye”.</p><blockquote>“Shoot”, ordered Drona.</blockquote><p>Swish! Went the arrow, leaving Arjuna’s bow and swiftly piercing the eye of the bird. The poor lifeless body immediately fell to the ground with a soft thud. The remaining Pandavas containing their excitement of their brother demonstrating a skill who no other student could even think of replicating.</p><p>“No!!!”, screamed Suyodhan. He knew what this meant and as he approached the now dead bird, it’s partner too flew down to it. Suyodhan’s eyes a little teary now, he tried pumping the chest of the bird in the hopes of reviving it. In his mind, he thought the arrow had only touched the bird’s wings or some other part. He still had a chance to save it and all it required was some bandages with some good care, he thought to himself.</p><p>But the partner had now realized what had happened. She knew. She knew what the scriptures had said one too many times. All this whilst being, just a bird. Death is just a change of clothes for what is the being, ātaman. It is but a change in dimensions.</p><p>Briefly nudging her partner’s body one last time, she flew away.</p><h4>Lesson</h4><p>We had seen three <em>purushārthas </em>being mentioned in the previous article in this series(<a href="https://deepakschoudhary.medium.com/a-lesson-in-power-and-perseverance-from-the-hindu-itih%C3%A3sa-72d716ce1a6a">read it here</a>). Moksha is the final purushārtha which forms the core part of <em>hindu</em> belief. This is believed in by all <em>darshanas</em>, <em>āstika </em>or <em>nāstika</em>.</p><p>Life and death are two sides of a coin which keeps on flipping and the only relief from this cycle is what m<em>oksha </em>is. This realm we live in is merely a <em>karmabhoomi </em>for us humans. Which is why, <em>Buddha </em>too believed that life was nothing but a struggle. We are destined to leave it as soon as we’re born perform our dharma whilst we are here.</p><p>Which is why <em>mrityu </em>is seen as just a passing by, a change of clothes. When one passes away, it does affect us. We grief in our own ways, taking our time and when it’s time, we move on to our dharma, cherishing the memories of the ones who although may never hold our hands again but will always touch our soul !</p><p><em>I hope this piece gives you some insight about the nature of power, perseverance and patience. It’s an effort to preserve teachings from our scriptures and I will be writing about more tales from our itihãsa and dharmashãstras in the future.</em></p><p>— — Deepak Choudhary<br>Ashvina Shukla Navami, Vikram Samvat 2081</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da56b2bd20d4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A lesson in power and perseverance from the Hindu Itihãsa]]></title>
            <link>https://deepakschoudhary.medium.com/a-lesson-in-power-and-perseverance-from-the-hindu-itih%C3%A3sa-72d716ce1a6a?source=rss-b9afaa8107ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/72d716ce1a6a</guid>
            <category><![CDATA[personal-growth]]></category>
            <category><![CDATA[perseverance]]></category>
            <category><![CDATA[personal-development]]></category>
            <category><![CDATA[power]]></category>
            <category><![CDATA[mahabharata]]></category>
            <dc:creator><![CDATA[Deepak Choudhary]]></dc:creator>
            <pubDate>Sun, 06 Oct 2024 06:39:49 GMT</pubDate>
            <atom:updated>2024-10-11T05:37:41.588Z</atom:updated>
            <content:encoded><![CDATA[<h3>Hindu Itihāsa Series: A lesson in power and perseverance</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lqkJhGtyjtUvG_Th.jpg" /></figure><h4>Prologue</h4><p>Once the greatest war this world has ever seen ended, there wasn’t much one could see on the battlefield. This war that lasted a humongous 18 days and had millions of warriors participating in an effort to find glory and a hope for a better tomorrow in the lands of Bharata. It was here that Yudhisthira gets overcome by guilt from the destruction caused. However, it was his dharma to rule the kingdom now that he along with his four brothers had vanquished adharma fighting tooth and nail. <br>He approaches Bhisma, the legendary fighter who lay on a bed of arrows still, waiting to pass on the knowledge he acquired over decades to the new king. It is here that our tale is told. Amongst the many, questions and answers that were exchanged, there was one which we shall talk about now. The new king Yudhisthira asks Bhisma,</p><blockquote>Pitāmā, what is the origin of the word Rājā ?</blockquote><h4>The story begins…</h4><p>In the early days of Satyuga, no kingdoms existed. People were still conscious of their Dharma and lived an honest life. Over time however, their consciousness got muddled. The knowledge of the vedas started to vanish and the Mãtsya nyāya (big fish eats small fish) became the norm. Disturbed by this, the Devatās approached Brahma for a solution. It is here that Brahma wrote a treatise encompassing the three purushārthas: Dharma, Artha, Kāma. This treatise however was too long and too complicated for humans.</p><p>Enter, Shivā who further shortened the treatise from 1 lakh chapters to around 10 thousand. Indra, the king of the Devatãs learnt it and further shortened it to 5 thousand chapters which was further acted upon by the guru of the Devatās, Brihaspati and then Shukrāchārya who finally gave a 1000-chapter treatise.</p><p>Having finalized the treatise, they needed someone who could rule the Earth using this, be a just king who would further Dharma again. The Devatās approached Vishnu for this. Vishnu, having given it deep thought created his mānasputra, Virāja. But, there was now a problem, given his origin, Virāja was enlightened already and thus he chose renunciation of power and the royal privilege.</p><p>Virāja however, left behind his son Keertimãna to take over the reigns but alas, he too chose the path of nirvāna before leaving his son Kardama to take over. Kardama participated in intense tapasyã to overcome all his senses and it was his son, Ananga who finally accepted rulership. Ananga having been trained well, served as a good king. But as is the nature of power, it pushes you to do more. Ananga’s son, Atibala expanded the boundaries of the kingdom to vast measures. It was now that power started to corrupt Atibala. Enslaved by his sensual indulgences, he was destroyed soon after. <br>Atibala had a son named Vena in whom the seed that had corrupted Atibala, grew into a tree of Adharma. Vena was cruel, egoistic and did not pay heed to anyone else but himself. His oppresion grew to such extents that his subjects loathed him. He had to be killed by the rishis to stop the further spreading of adharma.</p><p>The kingdom now needed a ruler without whom it would fall to anarcy and utter chaos. It was here that the rishis created a man from the remains of Vena. His first words were, “Please tell me, how do I serve you?”</p><p>This man would later go on to be called Prithu, after whom the earth is named “Prithvi”. Prithu would go on to establish a state of Dharma across the globe. He looked after the people, cared for their prosperity, punished the miscreants and governed society as was envisioned by Brahmã.</p><h4>Epilogue</h4><p>Bhismā explained to Yudhisthira now that since Prithu brought happiness and delight (ranjati) to his people, he was called a Rājā.</p><p>Because he saved the rishis, upheld justice and saved the vedic traditions from extiction (kshatrānāt), he was called a Kshatriya.</p><p>And because he made the earth suitable for civilization, the earth is called <em>Prithvi.</em></p><h4>What can we learn?</h4><p>Achieving success is rarely a one shot thing. You will most probably never achieve success in the first attempt but given enough dedication, hard work, introspection and improvisation, success is inevitable. <br>Success comes to those who persevere for it and are patient for it.</p><p>On the contrary, power if not kept in check will always corrupt you. Do what you must to keep yourself humble before it’s too late and external factors are needed to put a stop on your journey on the path of adharma.</p><p><em>I hope this piece gives you some insight about the nature of power, perseverance and patience. It’s an effort to preserve teachings from our scriptures and I will be writing about more tales from our itihãsa and dharmashãstras in the future.</em></p><p>— — Deepak Choudhary<br> Ashvina Shukla Chaturthi, Vikram Samvat 2081</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=72d716ce1a6a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Go Simplified: Channels]]></title>
            <link>https://deepakschoudhary.medium.com/go-simplified-channels-c480f5771343?source=rss-b9afaa8107ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/c480f5771343</guid>
            <category><![CDATA[learning-to-code]]></category>
            <category><![CDATA[goroutines]]></category>
            <category><![CDATA[go-channels]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Deepak Choudhary]]></dc:creator>
            <pubDate>Thu, 30 Jun 2022 17:11:50 GMT</pubDate>
            <atom:updated>2022-06-30T17:25:18.324Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Share information, not resources</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*m90meYGc8dmAOCcQE52rIA.png" /></figure><p>Welcome back to the Go Simplified series. We covered scheduling and context switching the last time around. In case you have not checked it out, you can do so <a href="https://deepakschoudhary.medium.com/go-simplified-scheduling-and-context-switching-c8607a32b73d">here</a>.</p><p>Today we shall discuss <strong>channels </strong>and below are the questions I shall answer for you:</p><ol><li>Mechanics behind channels</li><li>How channels work ?</li><li>How send and receive works underneath ?</li></ol><h4>Okay so first thing first, what is a channel ?</h4><p>Go uses the concept of goroutines which can be thought of as “threadlets”. They behave like threads, have similar states and follow a fork join model. Sometimes, communication is required between goroutines and this is where channels come in use. Channels provide a structure for you to communicate efficiently between goroutines.</p><h4>Sounds sweet, what else can I do with channels ?</h4><p>Well, you can use them to synchronize goroutine. They are typed so you can rest assured that you won’t get a surprise when reading values from channels. In addition, they are thread safe so the variables can be used concurrently by multiple goroutines.</p><h4>The hchan struct !</h4><p>All channels use the hchan struct behind the scenes. Let us take a look at what all is there here:</p><pre>type hchan struct {<br>    qcount   uint           // total data in the queue<br>    dataqsiz uint           // size of the circular queue<br>    buf      unsafe.Pointer // points to an array of dataqsiz elements<br>    elemsize uint16<br>    closed   uint32<br>    elemtype *_type // element type<br>    sendx    uint   // send index<br>    recvx    uint   // receive index<br>    recvq    waitq  // list of recv waiters<br>    sendq    waitq  // list of send waiters<br>    <br>    // lock protects all fields in hchan, as well as several<br>    // fields in sudogs blocked on this channel.<br>    //<br>    // Do not change another G&#39;s status while holding this lock<br>    // (in particular, do not ready a G), as this can deadlock<br>    // with stack shrinking.<br>    lock mutex<br>   }</pre><ol><li>All goroutines operating on the channel must first acquire a lock on the channel using the <strong><em>mutex</em></strong><em>.</em></li><li><strong><em>buf </em></strong>happens to be a circular ring buffer where the data is stored when using buffered channels [more on buffered channels later in the post].</li><li><strong>recvq </strong>and <strong>sendq </strong>are waiting queues for blocked goroutines who wanted to operate on the channel. They follow the <strong>waitq </strong>struct.</li><li><strong>dataq </strong>size is the size of the buffer and <strong>qcount </strong>is the total elements in the queue.</li></ol><h4>The waitq struct</h4><p>The waitq struct looks like below and denotes a linked list of goroutines.</p><pre>type waitq struct {<br>    first *sudog<br>    last  *sudog<br>}</pre><p>Linked lists are denoted by the <strong><em>sudog </em></strong>struct. Let’s check out how that looks like:</p><pre>type sudog struct {<br>   // The following fields are protected by the hchan.lock of the<br>   // channel this sudog is blocking on. shrinkstack depends on<br>   // this for sudogs involved in channel ops.<br>   <br>   g *g<br>   <br>   next *sudog<br>   prev *sudog<br>   elem unsafe.Pointer // data element (may point to stack)<br> <br>   // The following fields are never accessed concurrently.<br>   // For channels, waitlink is only accessed by g.<br>   // For semaphores, all fields (including the ones above)<br>   // are only accessed when holding a semaRoot lock.<br>   <br>   acquiretime int64<br>   releasetime int64<br>   ticket      uint32<br>   <br>   // isSelect indicates g is participating in a select, so<br>   // g.selectDone must be CAS&#39;d to win the wake-up race.<br>   isSelect bool<br>   <br>   // success indicates whether communication over channel c<br>   // succeeded. It is true if the goroutine was awoken because a<br>   // value was delivered over channel c, and false if awoken<br>   // because c was closed.<br>   success bool<br>   <br>   parent   *sudog // semaRoot binary tree<br>   waitlink *sudog // g.waiting list or semaRoot<br>   waittail *sudog // semaRoot<br>   c        *hchan // channel<br>}</pre><ol><li><strong>g</strong> is a reference to the goroutine.</li><li><strong>elem </strong>field is what points to the memory which contains the value to be sent or the location where a value shall be received.</li></ol><h4>Operation: Initialization</h4><ol><li><strong>hchan </strong>struct is allocated in heap when we use the <strong>make()</strong> function</li><li><strong>make()</strong> then returns a pointer to the allocated memory.</li><li>Since the output of <strong>make()</strong> is a pointer is can be sent between functions to send/receive data.</li></ol><p>Note: create a channel using the following code and debug to see the initial values.</p><pre>ch:= make(chan int, 4)</pre><h4><strong>Operation: Send/Receive Data on a Buffered Channel</strong></h4><p>So we know what happens when we create a channel. Let’s understand what happens when we have a couple of goroutines sending and receiving from a channel.</p><p><strong>Setting:</strong></p><p>We have our channel from the last operation. Let’s assume we have a list of values which need to be sent to the channel by goroutine G1 and another goroutine G2 needs to read these values from the channel.</p><p><strong>Scenario 1: G1 executes first and puts values into the channel while G2 follows and reads the values</strong></p><ol><li>G1 will acquire the lock on the channel first.</li><li>Then it enqueues the element in the circular ring buffer. Note that this is a memory copy. The element is copied into the buffer.</li><li>Then it increases the value of <strong>sendx </strong>to 1 since 1 value was put inside the channel and releases the lock.</li><li>G2 comes along now and tries to acquire the value from the channel.</li><li>G2 acquires a lock on the <strong>hchan</strong> struct.</li><li>It dequeues the element from the buffer and copies the value to a variable.</li><li>G2 then increments the <strong>recvx </strong>to 1 and releases the lock.</li></ol><p><strong><em>Note</em></strong>: <em>There is no memory sharing. Values are copied to and from the </em><strong><em>hchan </em></strong><em>struct and </em><strong><em>hchan </em></strong><em>is protected by the </em><strong><em>mutex </em></strong><em>lock.</em></p><p><strong>Scenario 2: Buffer is full as G2 hasn’t been around and G1 has clogged the pipe</strong></p><ol><li>G1 enqueues 4 values inside our channel which makes the buffer full.</li><li>Now it needs to wait for dequeue operation before more values can be queued inside the buffer.</li><li>Buffer is currently in blocked state.</li><li>G1 will now create a <strong>sudog </strong>struct where g element holds reference to the goroutine G1 and the value to be sent is stored in the <strong>elem </strong>field for the <strong>sudog </strong>struct.</li><li>Now this <strong>sudog </strong>is enqueued into the <strong>sendQ </strong>list and G1 requests the scheduler to remove itself from the OS thread so that other goroutines can be put on the OS thread.</li><li>Now G2 comes along, acquires the lock and dequeues the first element from the queue and copies the value into a vairable</li><li>After this, it pops the waiting G1 on the <strong>sendQ</strong>. Then it enqueues the 4th value into the buffer. Note that it’s G2 which enqueues the value which lets G1 rest easy as it does not need to make a comeback.</li><li>G2 now sets state of G1 as runnable by calling the <strong>goready </strong>function for G1.</li><li>G1 is now moved to runnable state and gets added to local run queue and will get it’s turn when a chance is available.</li></ol><p><strong>Scenario 3: Buffer is empty since G1 has been away and G2 is trying to read from an empty channel</strong></p><ol><li>G2 has won the race and is the first to reach the channel and acquires a lock.</li><li>Since the channel is empty, G2 now creates a <strong>sudog </strong>struct for itself and enqueues it into the <strong>revcq </strong>of the channel. The <strong>elem </strong>field will now hold reference to a stack variable where G2 wants to accept the value from the channel.</li><li>G2 now calls the scheduler to park itself.</li><li>Context switching now occurs and G1 is given a chance to populate the channel.</li><li>G1 first checks if any goroutines are waiting in <strong>recvq </strong>of channel and finds G2.</li><li>G1 now copies the value directly into the stack of G2. It’s writing into the variable of G2. This takes off some burden off of G2.</li><li>G1 now pops G2 and puts it into the runnable state using the scheduler.</li><li>G2 now is ready and will be scheduled whenever a chance is available.</li></ol><h4>So that was smooth but what about unbuffered channels ?</h4><p>Well, we sort of have seen what will happen in our previous scenarios. An unbuffered channel is basically one where the length of the buffer is practically 0 since the <strong>buf </strong>value is only used for buffered channels.</p><p><strong>Scenario 1 : Send on an unbuffered channel</strong></p><ol><li>G1 wants to send data to the unbuffered channel.</li><li>G1 checks if there are any waiting goroutines in <strong>recvq</strong>.</li><li>If found, G1 will write the value directly into the stack variable of G2.</li><li>G1 then puts G2 into a runnable state.</li><li>If there is no receiver goroutine then sender gets parked in <strong>sendq </strong>and data is put in the <strong>elem </strong>field.</li><li>G2 now comes in, copies the data to it’s stack variable and puts G1 back to runnable state after popping it from <strong>sendq</strong>.</li></ol><p><strong>Scenario 2: Receive on an unbuffered channel</strong></p><ol><li>G2 wants to receive from an unbuffered channel.</li><li>It checks if there are any blocked goroutines on the <strong>sendq</strong>.</li><li>If found, it copies the value from the <strong>elem </strong>field of the <strong>sudog </strong>struct into it’s stack variable.</li><li>It then puts the sender goroutine back to a runnable state.</li><li>If no sender goroutine was found, G2 puts itself inside <strong>recvq </strong>and a reference to it’s stack variable is stored inside the <strong>elem</strong> field.</li><li>G1 i.e. sender comes along and sees G2 stuck in <strong>recvq</strong>.</li><li>It puts the value directly into G2’s stack variable and pops it, putting it back to runnable state.</li></ol><h4>Summary</h4><p>In conclusion, channels are a beautiful construct allowing you ease of communication between your goroutines efficiently. In this article I have made an assumption that you would have read my article on <a href="https://deepakschoudhary.medium.com/go-simplified-scheduling-and-context-switching-c8607a32b73d">Context Switching and Scheduling</a>. If you haven’t I would urge you to take a look.</p><p>Hope you had a nice time reading this article. If you did, show some love in the form of claps and comments. Feedbacks are more than welcome and encouraged.</p><p>For now, may your have bug free code in production always. See ya until next time.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c480f5771343" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Go Simplified: Scheduling and Context Switching]]></title>
            <link>https://deepakschoudhary.medium.com/go-simplified-scheduling-and-context-switching-c8607a32b73d?source=rss-b9afaa8107ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/c8607a32b73d</guid>
            <category><![CDATA[golang-development]]></category>
            <category><![CDATA[context-switching]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[goroutines]]></category>
            <category><![CDATA[go-scheduler]]></category>
            <dc:creator><![CDATA[Deepak Choudhary]]></dc:creator>
            <pubDate>Tue, 08 Feb 2022 04:35:01 GMT</pubDate>
            <atom:updated>2022-02-08T04:35:01.784Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*X3wISRJVhedcaMScynAwhA.jpeg" /><figcaption>Source: <a href="https://content.techgig.com/">content.techgig.com</a></figcaption></figure><p>So you recently got introduced to this marvelous language or have been using it for a while. You got your hands greasy with incredible goroutines and channels and the other shebang. However you would like some more information on just how it all works underneath those APIs. Well say no more cause I got you with this Simplified series article explaining just what the scheduler is and how does Go manage all the context switches.</p><h4>What is the Scheduler ?</h4><p>The Go scheduler is part of the Go runtime which is part of the executable. It’s called an <strong>M:N scheduler</strong> as well. [<em>We’ll see why this M:N, down the road</em>]</p><p>Go runtime will create a number of <strong>OS threads = GOMAXPROCS. GOMAXPROCS </strong>is the default number of processors on the machine. As of Go 1.14, Go allows for asynchronous preemption routines. [<em>We’ll get to this later in this article</em>]</p><p>The scheduler will also pre-empt a goroutine based on a time slice in case you thought that idle routines will keep on hogging memory. [Leaks <em>can happen still but hey, Go is trying it’s best. Okay!?</em>]</p><h4>Okay, but can you make it a more graphic ?</h4><p>Sure, below diagram shows the states a Go routine can be in.</p><ol><li>When the routine, is created, it achieves the <strong>Runnable</strong> state.</li><li>When it gets scheduled, it goes to the <strong>Executing</strong> state.</li><li>If the routine while in <strong>Executing </strong>state, run through it’s time slice, it is pre-empted by the scheduler and goes back to <strong>Runnable </strong>state.</li><li>If the routine gets blocked, eg. I/O event, blocked on channel etc. It moves to <strong>Waiting</strong> state.</li><li>Once the block no longer exists, it goes back to <strong>Runnable</strong> state.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/1*R9FM13HonViR2Fhtwb100Q.png" /><figcaption>States achieved by goroutines</figcaption></figure><p>Let’s try a full rundown of all elements involved in routine scheduling.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/769/1*1zplc0XcnFqgYY1HnbmsGg.png" /><figcaption>Goroutine context switch</figcaption></figure><ol><li>For a system core, an OS thread is created <strong>M</strong>.</li><li>For that thread, a logical processor <strong>P </strong>is created which attached itself to the OS thread and then schedules goroutines on that OS thread context.</li><li><strong>R1 </strong>here is a goroutine currently executing on the thread <strong>M</strong>.</li><li><strong>R2</strong>, <strong>R3</strong>, <strong>R4 </strong>form the <strong>Local Running Queue</strong> on the processor <strong>P.</strong></li><li><strong>GR1</strong>, <strong>GR2 </strong>form the <strong>Global Running Queue</strong>.</li><li>Once the local running queue is empty, the processor will pull threads from the global running queue to execute them.</li><li>Whenever a new goroutine is created, it gets added to the end of the global running queue.</li></ol><p><em>So, I can say that at any given moment, I can schedule </em><strong><em>N</em></strong><em> routines on </em><strong><em>M</em></strong><em> OS threads which runs at most </em><strong><em>GOMAXPROCS </em></strong><em>number of processors.</em></p><p>Congratulations! You now know why we called it the M:N scheduler.</p><h4>Okay looks fairly straight forward, how does the blocking work ?</h4><p>Glad you asked. Let’s take a look at Context Switching due to Synchronous call first :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kEZsAZaqBUSs1JRzlPw28g.png" /><figcaption>Context Switching due to synchronous system call</figcaption></figure><ol><li>Let’s assume <strong>G1</strong> starts to read a file synchronously which then blocks <strong>M1</strong>.</li><li>Runtime then asks for another thread from the pool cache/OS. Let’s call this <strong>M2</strong>.</li><li>Now processor P is detached from thread <strong>M1 </strong>and attached to thread <strong>M2</strong>. <strong>R1 </strong>is still attached to <strong>M1</strong>.</li><li>P now schedules <strong>R2</strong>. <strong>R3 </strong>remains in local running queue.</li><li>Once <strong>R1 </strong>has finished, it’s moved back to local running queue and <strong>M1 </strong>is put to sleep and put to thread pool cache.</li></ol><h4>Tell me about asynchronous system calls context switching now !!</h4><p>Asynchronous system calls happen when the file descriptor that is used to do the I/O operation is set to non blocking mode.</p><p>Now if that file descriptor is not ready, the process is not blocked but an error is returned instead. Application now retries the operation at a later time. Application now needs to create an event loop and create call backs or create a table to maintain these mappings and states.</p><p>Go uses <strong>netpoller</strong> viz. an abstraction built in <strong>syscall </strong>package. When a goroutine makes an async call and the file-descriptor is not ready, <strong>netpoller </strong>is used to park the routine.</p><p><strong>netpoller </strong>uses interfaces provided by system to check on the status of the file descriptor. Once it gets notification for the file descriptor, it in turn notifies the go routine.</p><p>Lets see this in a diagram :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TfuHS2f83vm9XmiDb28cwQ.png" /><figcaption>Context Switching due to Asynchronous System Calls</figcaption></figure><ol><li>Let’s imagine that <strong>R1</strong> is making an <strong>async </strong>call which has now returned and error due to the file descriptor not being ready.</li><li>The scheduler upon encountering the error, it moves the goroutine to the <strong>netpoller </strong>thread.</li><li><strong>netpoller </strong>will not keep checking and notify <strong>R1 </strong>when the process can be resumed.</li><li>P on the side can start working on <strong>R2 </strong>while <strong>R1 </strong>is watched by <strong>netpoller</strong>.</li><li>Once <strong>R1 </strong>is finished, it goes back to the <strong>local running queue</strong>.</li></ol><p><strong><em>So here, we did not need to ask for another thread from the OS. We used the netpoller thread to park the time taking routine.</em></strong></p><p><strong>Cool, but what happens when a processor runs out of routines to work on ?</strong></p><p>Here is where the concept of <strong>work stealing</strong> comes into picture. Unlike most humans, processors just love executing tasks. So below are the rules followed for work stealing :</p><ol><li>If no routines are present in Local Running Queue(<strong>LRQ</strong>), try to steal from another Local Running Queue.</li><li>If no routines are found in the other <strong>LRQ</strong>, check Global Running Queue(<strong>GRQ</strong>).</li><li>If no routines are found in the <strong>GRQ</strong>, check the <strong>netpoller</strong>.</li></ol><p>This provides a good way to make the best use of time at hand.</p><p>Hope you liked this article. Show some love in the form of comments, critiques and applauds!</p><p>If you like the idea of this series, please let me know that as well in the comment section so that I can keep bringing you more on the Simplified series !!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c8607a32b73d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I published my first package...]]></title>
            <link>https://deepakschoudhary.medium.com/how-i-published-my-first-package-2a0c902159fe?source=rss-b9afaa8107ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a0c902159fe</guid>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[sqlite]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[gorm]]></category>
            <category><![CDATA[package]]></category>
            <dc:creator><![CDATA[Deepak Choudhary]]></dc:creator>
            <pubDate>Wed, 31 Mar 2021 15:53:23 GMT</pubDate>
            <atom:updated>2021-03-31T15:53:23.056Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oJ0nNOlxD6nh9qVPZbs5Tw.png" /></figure><blockquote><strong>“The first time you do a thing is always exciting.” -Agatha Christie</strong></blockquote><p>As lines of code overshadow the fleeting sense of time and space for us developers, there comes a time when we contribute back to the world in the form of a package. This article is going to tell you a tale for just that.</p><p>There’s always a first time for everything. A first time for your bike ride, a first time for heartbreak and definitely a first time for a package you write which will someday be used by other developers.</p><h4>Setting the scene for a breakthrough…</h4><p>The requirement was for an solution which would handle authentication and authorization for other applications on the machine. The solution needs to be locally deployed on the system and should be able to store authentication and authorization related data in a relational database. Since the systems were going to be fairly limited on memory the choice of server side language was <a href="https://golang.org/">Go</a>. Go being the light weight, memory friendly, concurrency spitting language it is was a straightforward choice.</p><p>When it came to databases however, the fairly limited system memory was a road block for using a DB like PostgreSQL or MySQL.</p><h4>Enter SQLite…</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b-y1lZrBrdqQAqJnyRtMpA.png" /></figure><p><a href="https://www.sqlite.org/index.html">SQLite</a> is a extremely low footprint relational databases around currently. Written in C, this small packet big bang DB is present almost everywhere. If you haven’t heard about it, check your phone and most probably it’ll be there. SQLite is an extremely lightweight (~600Kb), entirely self contained, portable database which requires no prior configuration/installation.</p><h4><strong>Another problem raises it’s ugly head…</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*WpB-1uJaKyvY3Kb3SOsQfg.jpeg" /></figure><p>We were not sure if the individual deployments will forever be the scenario and in the future we might have to switch to a centralized deployment or support multiple databases. This usually means you go with an ORM. However, Go being the way it is. It’s difficult to have an ORM in it’s true sense for it. Time to make the best out of what we had, we decided to use GORM.</p><p><a href="https://gorm.io/">GORM: The fantastic ORM library for Golang</a> is one of the most famous ones out there.</p><h4>SQLite !! Are you sure ? You know we need that encryption</h4><p>SQLite by default does not have encryption and all your data will be stored in plain text in the database file. In addition to that, the default SQLite driver that GORM provides does not work with encrypted SQLite databases.</p><p><em>How do you solve it you ask ?</em></p><p>You get on the internet and find someone who has implemented the encryption logic. Post hours of looking for a solution and countless repositories, the solution was simple.</p><p>The gorm SQLite driver uses another package at it’s core to interact with the SQLite database. If I could just improve upon it and use another package which can interact with an encrypted SQLite DB it should work.</p><p><strong>EUREKA !!!</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*HrX-qfjxoxyhqWN9G828yQ.jpeg" /></figure><p>Thank you to the guys at <a href="https://mute.one/">Mute Communications Ltd</a>. I found a <a href="https://github.com/mutecomm/go-sqlcipher">Go driver</a> which could interact with an encrypted SQLite database file. All I had to do was replace the driver and make sure it worked and alas! My package was ready to publish.</p><p>You can find the package <a href="https://github.com/jackfr0st13/gorm-sqlite-cipher">here</a>.</p><blockquote><strong>“With great power comes great responsibility”- Uncle Ben(Spiderman)</strong></blockquote><h4>Future Work, Improvements…</h4><p>As of the time of this writing, I have not been able to test all the operations and features of GORM. The code could also do with some additional features like choice of encryption. Currently the package used provides AES-256 as the only encryption available. It would help to have other encryption logics available for user selection as well.</p><p>However, that is part and parcel of any open source code. There’s always something that can be improved.</p><p>If you like what I put on paper and would like to read more of my articles, show some love in the form of claps and responses.</p><blockquote>Keep learning, keep growing.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a0c902159fe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Back to Basics: The Beginning]]></title>
            <link>https://deepakschoudhary.medium.com/back-to-basics-the-beginning-2cef72a84637?source=rss-b9afaa8107ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/2cef72a84637</guid>
            <category><![CDATA[datastrucutre]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Deepak Choudhary]]></dc:creator>
            <pubDate>Sun, 19 Jul 2020 11:34:59 GMT</pubDate>
            <atom:updated>2020-07-19T11:34:59.280Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*9-5SmpqZaFxf6KV8dJh03w.jpeg" /></figure><p>As I write this, I have spent a total of 117 days locked up in my house. COVID19 has indeed taken a toll on not just economies but the psyche of the general public. As a developer, I decided to take this as an opportunity to revisit algorithms and data structures. This idea which was throttled by the job interviews I have been taking recently made me wonder how there must be others who are looking for this. A way for you to visualize these famous algorithms so that you can base your own on them.</p><blockquote>A building is only as strong as the foundations. The walls can’t even support its own weight. But when that weight is transferred to the foundation, the whole building is stable</blockquote><blockquote>— Rob Dingman.</blockquote><p>Taking from the above quote, this series aims to provide the following :</p><ol><li><em>A explanation of what and how of the algorithm.</em></li><li><em>Examples from the real world you can relate the algorithm with.</em></li><li><em>Some questions you can ask yourself and try yourself to test your understanding of the algorithm.</em></li></ol><p>Pointless to say,</p><blockquote>If you cant explain something simply, you don’t understand it well enough.</blockquote><blockquote>— Albert Einstein.</blockquote><p>The article will assume that the reader does not know anything and will aim to explain everything from the bottom. Another assumption this series will make is that you know basic algebra. Suppose I tell you f(<em>x</em>) = 6<em>x </em>and ask you f(5). You should know that the answer is 30.</p><p>If you are an experienced developer or graduate, feel free to skip to the main parts. However, I would suggest you <strong><em>go with the flow, </em></strong>if you have the time.</p><h3>What is an algorithm ?</h3><p>An algorithm in it’s most basic form, is a set of instructions required to achieve a task. So basically any code which does anything can be considered an algorithm. However, there are some which are more interesting as they take on a different approach to solve a problem faster or without using much resources.</p><p>Let’s take an example. Given there are <em>n </em>boxes, each of which has either a red colored or a yellow colored ball. I need to find which ones have a red ball.</p><h4>Simplest algorithm :</h4><ol><li><em>Open each box.</em></li><li><em>If it has a red ball, keep it aside.</em></li><li><em>If it has a yellow ball, move on to the next one.</em></li><li><em>Once all red ball boxes are separated from the yellow ones, you have your answer.</em></li></ol><h4>Takeaways:</h4><p><em>This algorithm grows at the rate of</em> <strong><em>n. </em></strong>Meaning, if there are 5 boxes, the worst case would require me to check all 5.</p><h3>What are data structures ?</h3><p>A data structure is basically a construction in the memory which helps you to efficiently use your data. It’s similar to you keeping tabs on your files, bookmarks in your book. It makes it easy to reach the section which has data worth your value or the page you last stopped at. Computer will similarly have these organized spaces which will have their own properties and use cases.</p><p>Now these data structures can be <strong>linear </strong>or <strong>non linear</strong>. We’ll see in the upcoming parts what we mean by linear and non linear in detail. However, for simplicity sakes and basic overview you can think of linear data structures like continuous seats in a movie theatre. They are one after the other and connected. For non linear data structures, you can think of a company’s hierarchy. You have nodes which have relationships with other nodes and there are levels which make the whole structure not very simple outright.</p><p>What data structure are you going to talk about ?</p><p>In this series, we’ll talk about the following data structures:</p><ol><li>Arrays</li><li>Lists</li><li>Stacks</li><li>Queues</li><li>Maps</li><li>Trees</li><li>Graphs</li></ol><p>This part was all about introducing you to the realm of algorithms and data structures. In the next article we shall start with <strong><em>searching</em></strong>. How to do it, how to make it more efficient and how can you relate to it.</p><p><strong><em>Stay curious! Cheers!</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2cef72a84637" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>