<?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 Prashant Jha on Medium]]></title>
        <description><![CDATA[Stories by Prashant Jha on Medium]]></description>
        <link>https://medium.com/@prashant94jha?source=rss-f1d3f65b28a5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Prashant Jha on Medium</title>
            <link>https://medium.com/@prashant94jha?source=rss-f1d3f65b28a5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 18:35:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@prashant94jha/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[Search]]></title>
            <link>https://prashant94jha.medium.com/search-d3ab44a062f6?source=rss-f1d3f65b28a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/d3ab44a062f6</guid>
            <category><![CDATA[philosophy]]></category>
            <category><![CDATA[life]]></category>
            <category><![CDATA[spirituality]]></category>
            <dc:creator><![CDATA[Prashant Jha]]></dc:creator>
            <pubDate>Sun, 04 Oct 2026 05:30:36 GMT</pubDate>
            <atom:updated>2026-10-04T05:30:36.434Z</atom:updated>
            <content:encoded><![CDATA[<p>एक दिन दोस्तोयेव्स्की की बात याद आती है — <br>“You’ve destroyed and betrayed yourself for nothing.”</p><p>फिर तुम किसी को रोकना छोड़ देते हो।<br>न लौटने वाले का इंतज़ार करना छोड़ देते हो।<br>बेचैन होना छोड़ देते हो।</p><p>और बहुत वक़्त बाद<br>तुम्हें तुम ख़ुद याद आते हो — <br>जो किसी के आने से पहले भी था,<br>जो किसी के जाने के बाद भी है।<br>तुम पहली बार ख़ुद के पास लौटकर आते हो।</p><p>और शायद तब समझ आता है — <br>ख़ुद को पा लेना ही ज़िंदगी का मतलब था,<br>और ख़ुद को खो देना ही ज़िंदगी का अंत।</p><p>तब दोस्तोयेव्स्की की एक और बात याद आती है — <br>“The mystery of human existence lies not in just staying alive,<br>but in finding something to live for.”</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d3ab44a062f6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React19 : What can we expect?]]></title>
            <link>https://prashant94jha.medium.com/react19-what-can-we-expect-9ede3c607446?source=rss-f1d3f65b28a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ede3c607446</guid>
            <category><![CDATA[updates]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Prashant Jha]]></dc:creator>
            <pubDate>Sun, 25 Feb 2024 10:09:53 GMT</pubDate>
            <atom:updated>2024-02-25T10:09:53.368Z</atom:updated>
            <content:encoded><![CDATA[<h3>React19 : What can we expect?</h3><p>React team have been working on next improvement in the library. The new release will be introduced on May 15–16 on new version launch of React 19.</p><p>Below are the major things in this release.</p><p><strong>React Compiler</strong></p><p><strong>React compiler which powers instagram.com will be released.</strong> React can sometimes re-renders too much on state change. There are manual ways to handle it via memoization. We can use useCallback, useMemo, memo but it clutters up our code, easy to go wrong and it takes some extra work to keep up to date.</p><p>react forget is code name for the compiler that is built by meta to automatically memoize react hooks and components. This lets devs write code without manually memoize while acheiving same performance as memoized and even better in some cases.</p><p>This compiler simplifies developers experience and optimize app by default by memoizing the react hooks and components under the hood.</p><p><strong>Actions</strong></p><p>For server side rendering we used Next.js and and to make hydration faster we used React Server Components. This broader collection of features will be combined into “Actions”. Action allows you to pass a function to DOM elements.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sTCyD_wjBn_lYmtCWGwVxg.png" /></figure><p>Action function can be sync and async both and it can be used on both client and server side.</p><p>By default action will be submitted within a transition keep the current page active while performing the action.</p><p><strong>useOptimistic</strong></p><p>we can now use useOptimistic hook for optimistic state update. We can apply temporary update. That will be reverted once final state commits.</p><p><strong>Document Metadata</strong></p><p>We’ll have built in support for &lt;title&gt;, &lt;meta&gt; and &lt;link&gt; tag anywhere in component tree. These will work in same way in CSR, SSR or RSC. This will provide built in support of features available in React Helmet. So React Helmet tag will be eliminated with this.</p><p><strong>Asset loading</strong></p><p>Now we’ll have Suspense for &lt;style&gt;, &lt;link&gt; and &lt;script&gt; tags as well so react can determine whether the content in these tags are ready to be displayed.</p><p>not a big release on this new version launch but it’ll surely make a developers life easier than before.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ede3c607446" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Scope & Closure]]></title>
            <link>https://prashant94jha.medium.com/scope-closure-6fcf1b1acc43?source=rss-f1d3f65b28a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/6fcf1b1acc43</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Prashant Jha]]></dc:creator>
            <pubDate>Mon, 22 May 2023 02:55:22 GMT</pubDate>
            <atom:updated>2023-05-22T10:23:15.785Z</atom:updated>
            <content:encoded><![CDATA[<p>Hey folks, here in this blog I am summarizing second part of You don’t Know JS book series. Which is Scope &amp; Closure by Kyle Simpson.</p><p>Why not first? Because first part is only introduction of Programming, JS and briefs about what this book is going to cover. It’s like explaining A for Appple, B for Ball to a kid who is already in class 2.</p><p>Here in this blog I’ll cover all aspects of Scope and closure and after understating this blog thoroughly I promise you you’ll never struggle with weird behaviors of JS scope or variables.</p><h3>Chapter 1. What is Scope?</h3><p>Storing the value in a variable and retrieving the value out of that variable gives a program life (state) and the rules around storing and retrieving the value in/from variable is scope. To understand the setup process for these rules, which is scope, we need to understand compilation process.</p><p>Wait, JS is interpreted language, right? Nope.</p><p>JS isn’t compiled in advance like Java but it performs the same steps till the code generation in more sophisticated way. There are 3 steps in compilation process .</p><p><strong>1. Tokenizing/Lexing :-</strong> It is process of breaking up a string of characters in meaningful tokens like var a = 10; will be broken in 5 tokens which are var, a, =, 10, and ;.</p><p><strong>2. Parsing:-</strong> To understand the grammatical meaning of these tokens and relation of tokens with each other, these tokens have to be related to each other’s like family tree. For that Abstract Syntax Tree (AST) get created with nested elements. This whole process is Parsing.</p><p><strong>3. Code-Generation: -</strong> The process of taking the AST and converting it into executable code.</p><p>JS engine is bit more complex. With all these 3 steps it performs the code optimization between parsing and code-generation which includes removing redundant variables and other elements.</p><p>For every single line of code, JS sees it as two statements. One that compiler will handle during execution and another that JS engine will handle during execution.</p><p>like for var a = 10;</p><p>When compiler goes through this line, compiler check the current scope for variable ‘a’ if ‘a’ isn’t present in scope compiler asks scope to create one variable with name ‘a’.</p><p>Then in second step compiler produce code to handle assignment operator.</p><p>For second step JS engine performs the look-Up to find the variable ‘a’ and assign value 10 to it. There are 2 types of look ups that JS engine has to perform to find the variable and assign value to it. LHS (left hand side) lookup and RHS (Right Hand side) lookup. LHS lookup is when variable is at left hand side of operator and RHS lookup is lookup of value of a variable.</p><p>Type of lookup is important because these look-ups behaves differently in circumstances where variable has not been declared. Like below example :-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/0*EnQX0GFMx8fbEQUv.png" /></figure><p>Here for line b = a; JS engine is using LHS lookup. It’s assigning value ‘a’ to variable ‘b’ which is on left hand side of assignment operator. JS engine will search for variable ‘b’. JS engine will not find it anywhere so then global scope will create a new variable of name ‘b’ in global scope and hand it back to JS engine then JS engine assign value ‘a’ to that newly created variable ‘b’.</p><p>But if RHS lookup will fail to find the variable, as in line console.log(a, b) it’ll result in Reference error as it’ll not find that variable ‘b’ and will throw the error b isn’t defined.</p><h3>Chapter 2. Lexical Scope</h3><p>It is scope that is defined at lexing time, the time when JS engine breaks the string of characters into tokens, based on where variables and scope are authored.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/0*epzGXKI-jwehyUfn.png" /></figure><p>Here the first bubble encompasses the global scope and only one identifier foo in it.</p><p>Second bubble encompasses the scope of foo with access of 3 identifier i.e; a, b, and bar()</p><p>Third bubble encompasses the scope of bar which has access to only one identifier c.</p><p>The bar is inside foo because we chose to define that inside foo. bar has access of all identifiers which is inside foo and foo has access of all identifiers which is inside global scope.</p><p>Scope look-up stops once it finds the first match for the variable. We can define variable at multiple layers of scope. That is called shadowing. But, scope look-up immediately stops once it finds the first match for the variable.</p><p>Scope look-up will start at innermost level and goes upwards until the first match. For example, in bar we are accessing c. JS engine will start look up for that variable and will access the first variable defined in scope of bar. So suppose even if c will be there in scope of foo JS engine will not go on looking for that variable in scope of foo since it has already accessed it from scope of bar. This phenomenon is shadowing.</p><p>So <strong>lexical scope is defined by where the function is declared and not by where and how it is invoked.</strong></p><h3>Chapter 3. Function Versus Block Scope</h3><p>As we explored in previous section, scopes are nested inside each other which is defined at author time. And we only explored function-based scopes. But there are another structure in JS also which creates it’s own bubble, it’s own scope.</p><p>But before exploring other scope let’s dig a bit more about function scope.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/301/0*RB5gM35SWo6bW9yY.png" /></figure><p>Here in this code snippet, we have 3 scope bubble. Global, foo and bar. bar() has access of all the identifiers defined in global scope and scope of foo(), and scope of bar() itself. But foo() can not access the identifiers defined in scope of bar() and global scope can’t access the identifiers defined in scope of foo().</p><p>While this design can be quite useful, variable existing across the scope can lead to unexpected results without careful precautions.</p><ol><li><strong>Principle of least privilege/least authority/least exposure :-</strong> In design of software, you should expose only what is minimally necessary and hide everything else. Which means any identifier which is not required in scope should not be accessible in that scope. For example :-</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*pwcjEKzVnEeo3C57.png" /></figure><p>Here as we can see function doSomeThingElse() function and variable b is required only inside function doSomething() and not being used anywhere in global scope. so, it’s not a good practice to expose doSomethingElse() function and variable ‘b’ to global scope and polluting it unnecessarily. A better approach w ill be</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/0*vwcbLjclVPjOBR96.png" /></figure><p><strong>2. Collision Avoidance :- </strong>It’s good to hide identifiers inside scope to avoid unintended collision with identifiers with same name in another scope with different use case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/0*7BpOCFuhyGREtycJ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/0*_zRgbtigDl9GA2Zx.png" /></figure><p>To avoid collision, we can also create a object with unique name and then we can write all the properties and methods inside that uniquely named object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/0*6OkO4mlSgcNte9Zx.png" /></figure><p>But this(function foo) type of function introduces some problems. First, we declare a function using a name which pollutes the enclosing (global in this case) scope and then we have to call the function.</p><p>To overcome these two problems we can use immediately invoked function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/0*ovpd3XrEe4ckXN8U.png" /></figure><p>Here we are using function expression instead of function declaration.</p><p><strong>What is function expression and function declaration</strong> you ask. Simply putting when word function is first word in line that is called function declaration otherwise function expression. Here first character is ‘(’ so this is function expression.</p><p>Here function foo is not bound in enclosing (global in this case) scope instead of it’s own enclosing scope and we didn’t have to call it explicitly.</p><p>To not to pollute enclosing scope we could have used anonymous function also. Like :-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/348/0*c3kl6LpZqq7NyCMD.png" /></figure><p>But anonymous function has some drawbacks :-</p><ol><li>Anonymous function has no useful to display in stacktrace. which makes debugging difficult.</li><li>It refer itself anonymous function has to use arguments.callee method which is deprecated.</li><li>It’s not readable/understandable.</li></ol><p>So<strong> it’s always better to use named function.</strong></p><p><strong>Block as Scope</strong></p><p>While function is main unit of scope. Using block scope lead to even better, cleaner and maintainable code. It’s used to declare identifier as close as possible which extends least authority principle. It also avoids collision.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/0*A2EvnW1D8dFN7QcD.png" /></figure><p>In this above example, there was no need to declare i variable in global or function scope and pollute them unnecessarily, so we declared inside loop.</p><p>Initially in JS we didn’t have any inbuilt mechanism for block scoping, but it changed with ES6. Now in JS, we have let and const which is used for block scoped variable and we can use var for function scoping.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/357/0*SPQKPZIQJdLodPhZ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/505/0*3j36gNk0S3hs68se.png" /></figure><p><strong>Garbage Collection</strong></p><p>Block scope is useful to garbage collection and in closure also to reclaim memory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/655/0*A5p4XJFawWTOZuuH.png" /></figure><p>Here in this code, ideally after process() function someReallyBigData should have been garbage collected but since click function has closure over entire (global in this case) scope JS engine will still have access over someReallyBigData. To handle this we can write code like :-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/673/0*bHzteikhtdhyqp2b.png" /></figure><p>So, we can say <strong>any variable declared within scope is attached to that scope</strong>.</p><h3>Chapter 4. Hoisting</h3><p>Consider the following line of code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/267/0*qmmZguLr6JzLIe7C.png" /></figure><p>Since egg (declaration)comes before chicken (assignment). so compiler compiles this same code like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/364/0*XE885EUNuqGAwaAA.png" /></figure><p>So here our output will be 2. So we can say, In JS variables and function declarations are moved from where they were in code to top of the code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/442/0*Z61L2ExafiaYdnrA.png" /></figure><p>When compiler compiles this code it get’s</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/418/0*k6asrumENXheKw7q.png" /></figure><p>So, in a way calling function in both style is same and right.</p><p>While variable and functions both are hoisted we can’t say the same for function expressions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/381/0*5h3uBibnDMIq-Dc-.png" /></figure><p>Here variable foo is hoisted and attached to enclosing (global) scope so when in line number 1 we tried to access function foo it didn’t throw reference error because variable foo was there. It found foo while matching the type it found it was variable and not a function so line number 1 throws type error.</p><h3>Chapter 5. Scope Closure</h3><p>Now, we are very well aware of lexical scope so what are going to discover in this section is almost anticlimactic. That is closure.</p><p>So, what is closure? <strong>Closure is when a function is able to remember &amp; access it’s lexical scope even if it that function is executing outside of it’s lexical scope</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/502/0*XWAx6NV67I5Ku2Su.png" /></figure><p>Here bar function has lexical scope over outer function foo and variable a of foo is being used inside bar function. We are returning bar() from foo() assigning it into baz and baz() still have access to a.</p><p>We can see baz() is executing outside of foo but still have access of variable a of foo function. In this way, bar() is creating closure over foo().</p><p><strong>Any of the various ways that functions can be passed around as values, and indeed invoked in other locations, are all examples of closure.</strong></p><p>Be that timer, event handlers, AJAX requests, cross-window messaging, web worker or any of the synchronous/asynchronous tasks. Whenever we pass in callback function we can see closure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/483/0*JmlVKSAfDUAM0cd8.png" /></figure><p><strong>Loops &amp; Closures</strong></p><p>Let’s say we need to write a code to print first 5 numbers after every second. So, We wrote like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/469/0*ZTSfqJqpcfA9-MYP.png" /></figure><p>Will that work? Let’s try…</p><p>ooh!! it printed 6, 6, 6, 6, 6 after every second. But we expected it to print 1, 2, 3, 4, 5.</p><p>What went wrong? As we know var is global variable. So when we wrote the for loop and declared variable i we declared that variable in global scope. And we are executing timer function after every i*1000 milliseconds. So, when we executed console.log(i) after i*1000 milliseconds i.e; 1 second value of i has already crossed 5 and became 6. We are running the timer function after every i*1000 seconds but every time console.log(i) access the same value of i from global scope which has become 6.</p><p>To prevent this and get desired result we can write code like :-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/546/0*BvQXLI5g4SYyKCq2.png" /></figure><p>Here we created IIFE and assigning i to j. So every time we invoke that function we are creating a new variable altogether and assigning i to j. So now whenever our loop runs console statement starts with a fresh value of j printing 1, 2, 3, 4, 5.</p><p>or we can also use let variable here</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/0*SKoca0R_EC8hTKMG.png" /></figure><p>Since let is block scope. Every time the loop is running it’s creating a new i variable in each block and setTimeout function is access the value of i from that same block. So every time console.log will get a new of i printing 1, 2, 3, 4, 5 after 1 seond of gap.</p><p>There are few code patterns that leverage the power of closure. Let’s explore more powerful of them. Which is <strong>Module Design Pattern</strong>.</p><p>There are 2 requirements of Module Design Pattern:-</p><ol><li>There must be an outer enclosing function. That must be called once.</li><li>The enclosing function must return at least one inner function, so that inner function access over private scope and can access and modify that private scope.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/0*8O9ZbUJa-XqVHHgK.png" /></figure><p>here we have CoolModule with 2 private variables ‘something’ and ‘another’.</p><p>We are using these 2 variables in doSomeThing and doAnother methods and editing another variable in doAnother method and then returning an object with 2 objects having these 2 functions.</p><p>Here we are calling outer function CoolModule once and assigning it’s value to variable foo.</p><p>Inner function doSomething and doAnother has access of ‘something’ and ‘another’ (private value) of foo function and doAnother is also modifying the ‘another’ variable of foo function.</p><p>This pattern is Module Pattern. It is powerful tool that can help to improve the maintainability and reusability of JavaScript code. It helps in:-</p><p><strong>Encapsulation</strong>:- It keeps code organized and maintainable by wrapping it in single object. Which prevents naming collision and makes it easier to change the code.</p><p><strong>Performance</strong>:- The module pattern can improve performance by reducing the amount of code that is executed on the page. This is because the module pattern only loads the code that is needed for a particular function or feature.</p><p>That’s all about Second part i.e., Scope &amp; Closure, of You Don’t Know JS series by Kyle Simpson. In this blog we covered all the 5 chapters of this book. Firstly we learnt what is Scope itself in first chapter then in second and third chapter we learnt about different types of scopes (lexical scope, function scope and block scope). In fourth and fifth chapter we learnt about behavior of scope (Hoisting &amp; Closure) and how it works in JS.</p><p>I’ll cover third book of this series soon. If you liked this blog please give a few claps, write your suggestions below. Thank you!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6fcf1b1acc43" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dependency Inversion Principle]]></title>
            <link>https://prashant94jha.medium.com/dependency-inversion-principle-ee00322bd746?source=rss-f1d3f65b28a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/ee00322bd746</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Prashant Jha]]></dc:creator>
            <pubDate>Thu, 30 Mar 2023 06:45:25 GMT</pubDate>
            <atom:updated>2023-03-30T06:45:25.986Z</atom:updated>
            <content:encoded><![CDATA[<p>This is last blog on SOLID design principle series. In this blog I’ll write about Dependency inversion principle. For dependency inversion principle, Uncle Bob AKA Robert C. Martin says, “Component <em>should depend upon abstractions, not on concrete details.</em>” Which essentially means:-</p><ol><li>High level modules should not depend on low level modules. Both should depend on abstraction.</li><li>Abstraction should not depend on details. Details should depend on abstraction.</li></ol><p>In order to understand it better, let’s go through an example. Suppose we are building an online store and using stripe as payment gateway.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*RFCuKD63zUYfoYgiVB97lA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/1*gxVXZ8sY0d4OAu0DwyX-mQ.png" /></figure><p>Later on, we discovered that there is another payment gateway let’s say paypal which is providing better services. So now we want to integrate paypal in our application instead of stripe.</p><p>In this current code, to add paypal we have to edit our main component that is App.js. But it is violating dependency inversion principle. According to dependency inversion principle, App.js should be flexible enough to adapt the changes of payment gateway. We can adit the abstract component which is wrapping the payment gateway, but we must not change App.js which is higher order module.</p><p>So, to follow the dependency inversion principle, we can modify our code in below way:-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/1*1UgxmgFNNhymFlvHR4K4Pg.png" /><figcaption>High Level Module</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/1*P3IC0aoWM4S_hsCBfwvGlg.png" /><figcaption>PayPal Payment Gateway</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/1*SWrmk4d7DsOP1awVZ2Gi8Q.png" /><figcaption>Stripe Payment Gateway</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*z1x8Hzv5H7pbhFTh6jPNtA.png" /><figcaption>Abstract Component for payment gateway</figcaption></figure><p>In this method, we don’t have to do any change in App.js component. Which is high level module. Instead of that we can change PaymentGateway abstract component and same change will be reflected in App.js component.</p><p>By this way, here we are following dependency inversion principle. Here high level module, App.js, doesn’t depend on low level module which is Stripe.js and PayPal.js directly. We created another abstract component PaymentGateway to add dynamic change in App.js.</p><p>This concludes Dependency Inversion Principle. ‘D’ in SOLID.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ee00322bd746" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Interface Segregation Principle]]></title>
            <link>https://prashant94jha.medium.com/interface-segregation-principle-99d419ba2d28?source=rss-f1d3f65b28a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/99d419ba2d28</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Prashant Jha]]></dc:creator>
            <pubDate>Wed, 29 Mar 2023 09:11:18 GMT</pubDate>
            <atom:updated>2023-03-29T09:13:17.904Z</atom:updated>
            <content:encoded><![CDATA[<p>Make fine grained interfaces that are client (component) specific. Clients should not be forced to implement interfaces they don’t use.<br> — Uncle Bob AKA Robert C. Martin</p><p>If all the properties of interface isn’t being used in a component then that large interface can be broken in smaller interfaces and those smaller interfaces can be used in another component if required. For example :-</p><p>interface config {<br> color?: string;<br> width?: number;<br> height?: number;<br>}</p><p>function createSquare(config: config): { color: string; area: number } {<br> let newSquare = { color: “white”, area: 100 };<br> if (config.color) {<br> newSquare.color = config.color;<br> }<br> if (config.width) {<br> newSquare.area = config.width * config.width;<br> }<br> return newSquare;<br>}</p><p>function createRectangle(config: config): { color: string; area: number } {<br> let newRectangle = { color: “white”, area: 100 };<br> if (config.color) {<br> newRectangle.color = config.color;<br> }<br> if (config.width) {<br> newRectangle.area = config.width * config.height;<br> }</p><p>return newRectangle;<br>}</p><p>let mySquare = createSquare({ color: “black”, width:30 });<br>console.log(mySquare)</p><p>let myRectangle = createRectangle({ color: “black”, width:30, height:30 });<br>console.log(myRectangle)</p><p>Here as we can see, height property of config interface is not required in createSquare function. But config interface is being used in createSquare function. So, In that createSquare function height is unnecessary extra parameter. It’s manageable in here but just imagine this same scenario in huge codebase. It’s totally mess having a large chunk of unnecessary data. It it better to avoid such casee using Interface segregetion principle. It better to write same code like :-</p><p>interface config {<br> color?: string;<br> width?: number;<br>}</p><p>interface extraParameter{<br> height?:number;<br>}</p><p>function createSquare(config: config): { color: string; area: number } {<br> let newSquare = { color: “white”, area: 100 };<br> if (config.color) {<br> newSquare.color = config.color;<br> }<br> if (config.width) {<br> newSquare.area = config.width * config.width;<br> }<br> return newSquare;<br>}</p><p>function createRectangle(config: config, extraParameter: extraParameter): { color: string; area: number } {<br> let newRectangle = { color: “white”, area: 100, };<br> if (config.color) {<br> newRectangle.color = config.color;<br> }<br> if (config.width) {<br> newRectangle.area = config.width * extraParameter.height;<br> }</p><p>return newRectangle;<br>}</p><p>let mySquare = createSquare({ color: “black”, width:30 });<br>console.log(mySquare)</p><p>let myRectangle = createRectangle({ color: “black”, width:30 }, { height:30 });<br>console.log(myRectangle)</p><p>Here in this code snippet, as we can see we moved height parameter in another extra interface and using that property with help of extraParameter interface in createRectangle method only. Where that property is required.</p><p>This concludes interface segragetion principle. ‘I’ in SOLID.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=99d419ba2d28" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Liskov Substitution Principle]]></title>
            <link>https://prashant94jha.medium.com/liskov-substitution-principle-df52fc93cab2?source=rss-f1d3f65b28a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/df52fc93cab2</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Prashant Jha]]></dc:creator>
            <pubDate>Mon, 27 Mar 2023 09:04:22 GMT</pubDate>
            <atom:updated>2023-03-27T09:04:22.197Z</atom:updated>
            <content:encoded><![CDATA[<p>Liskov Substitution principle states “Derived class must be substitute of parent class.” In JS method of child component must be exact replica of method of parent component.</p><p>The method in child component should be exact number of arguments, exact types of arguments and exact return type as parent (types referring to typescript).</p><p>Simply put, you should be able to replace a parent component with a child component that behaves in the same way. This makes the code more flexible and easier to scale.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FeArhUBO5ziSgqclZ9ndyA.png" /></figure><p>Here as we can see, we are using BtnTwo in BtnOne component and in both component print method is same only. That method can be replaced in both component with each other. So, we can write the same code as below :-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HyBeTto9WdNrUXvcA2mnuA.png" /></figure><p>In less number of lines where print method is interchangeable between BtnOne and BtnTwo. Which fulfills the Liskov Substitution principle.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df52fc93cab2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Open-Closed Principle]]></title>
            <link>https://prashant94jha.medium.com/open-closed-principle-c74557f336f9?source=rss-f1d3f65b28a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/c74557f336f9</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Prashant Jha]]></dc:creator>
            <pubDate>Wed, 22 Mar 2023 19:16:27 GMT</pubDate>
            <atom:updated>2023-03-22T19:16:27.758Z</atom:updated>
            <content:encoded><![CDATA[<p><em>“Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification.”</em></p><p>Now this statement is confusing. How entity can be open and closed at same time?</p><p>This statement means that we must not edit the main function and it should be adaptable enough to the changes.</p><p>For Example, here in below code if we want to add details of few more people we need to add &lt;p&gt; tags for names and departments for those people manually in getDetails() function. In this scenario, we are extending the functionality but along with that we are also editing the main function. Ideally and according to open closed principle we should not edit main function i.e., getDetails() and it should be adaptable enough to show the added person details whenever we want to add more without changing anything in that function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*US39t0bdghWi2SumyNSDLw.png" /></figure><p>For that, we can write code in this way. Here we created an array of objects and passed that array as argumrnt to getDetails() function and in getDetails() function we are mapping over the array to get details of passed persons object.</p><p>Now here if we want to add show more persons’ details, we just need to add those persons’ object in persons array and result will be get reflected on screen.</p><p>As we can see, to extend the main functionality we are no longer editing the getDetails() function. That function is adaptable enough to display the result as par persons array. If we will remove the object from persons array or add few more objects those changes will get reflected without changing the getDetails() function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u_D3HulORoBSe9vzgZTsFw.png" /></figure><p>By this way, we achieved the open closed principle. Which is considered the most complicated principle in SOLID principles.</p><p>And this concludes open-clsoed principle, ‘O’ in ‘SOLID’ principles. Feedback is always appreciated. If you like this article please give a clap and comment your suggestions also. Thank You!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c74557f336f9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Single Responsibility Principle]]></title>
            <link>https://prashant94jha.medium.com/single-responsibility-principle-36e5a7bccf13?source=rss-f1d3f65b28a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/36e5a7bccf13</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Prashant Jha]]></dc:creator>
            <pubDate>Mon, 20 Mar 2023 19:17:32 GMT</pubDate>
            <atom:updated>2023-03-20T19:17:32.603Z</atom:updated>
            <content:encoded><![CDATA[<p>While we can write code, it is very crucial to write clean code. And to write better code we can follow SOLID design principles. That will help us to write more maintainable and scalable code. Where features can be added very efficiently and easily without breaking the existing code. So that we can spend more time on writing the code instead of understanding it. I’ll be writing blogs on each principle of SOLID to give a concrete understanding and a better explanation. Feel free to follow along starting with S i.e., Single Responsibility principle.</p><p>Single responsibility principle says a component should have one and only one reason to change. That means a component should be doing only one kind of work. If there are 2 or more different functionalities then those functionalities should reside in another components even if those are small ones. So that later on scaling those small components will be easy enough and we can add more features to that component without effecting the other functionality in parent component.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3ihV9PjGvEPbzAC0-u04JQ.png" /></figure><p>Here as we can see, in this Gym component we are writing 2 entirely different functions in terms of working. One is to calculate gym hour and the other is to notify the ‘gym rat’ as soon as gym hour is exceeding the maximum gym hours allowed. Now, if we will update any of those 2 functions we are updating parent component. Which is violating the single responsibility principle. Which says that there must be only one reason to change the component.</p><p>For separation of concern and according to single responsibility principle we should write one function in another component so that scaling that code will be easier in future. By looking at functionality of this program we can see that it’s better to separate notification function into another component because there is more probability of scaling of that component like in future we may want to send a notification email also or a WhatsApp message to notify that ‘gym rat’.</p><p>So it’s better to write code like :-</p><p>Here we wrote another component for notification</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*G1_BbjZQoNqLj0TO_GvYBA.png" /></figure><p>and lazy loaded/imported that component in main Gym component.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Reku_LS7L30x8ze7Lv8B0A.png" /></figure><p>Here we can clearly see the separation of concern and scaling that Notification component will be much more easy and reliable in future without effecting the main parent component.</p><p>This concludes single responsibility principle, ‘S’ in ‘SOLID’ principles. Feedback is always appreciated. If you like this article please give a clap and comment your suggestions also. Thank You!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=36e5a7bccf13" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[useCallback and useMemo]]></title>
            <link>https://prashant94jha.medium.com/usecallback-and-usememo-8c0f41ef0265?source=rss-f1d3f65b28a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c0f41ef0265</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[hooks]]></category>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-performance]]></category>
            <dc:creator><![CDATA[Prashant Jha]]></dc:creator>
            <pubDate>Tue, 31 Jan 2023 02:25:58 GMT</pubDate>
            <atom:updated>2023-01-31T02:27:12.084Z</atom:updated>
            <content:encoded><![CDATA[<p>Whenever we set state in react application our component re-renders. This might cause performance issues especially in large application and in large component where we’ll have have a good number of state and we’ll be updating that. So, on every state update our component will re-render. To solve this issue react introduced 2 hooks. Which is useMemo and use Callback. Both are used for performance enhancement and avoid re-rendering of our component in case of state update.</p><p>Since both hooks are used for performance optimisation, understanding the use case of both the hooks might be confusing for developers. Here we’ll solve that problem in in this blog that which hooks should be used in which condition. Firstly lets check their syntax.</p><p>usecallback :-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/1*35hV_NvualAAVb1Ur0nrsw.png" /></figure><p>useMemo :-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/235/1*5vZCN1yXhTdEJE7y2fA-UA.png" /></figure><p>oh f#$%!! syntax is also same. Both are used for performance optimisation. Syntax for both are same. Damn!!</p><p>Let’s skip to the good part to understand the difference between them. Basic difference between them is useCallback lets us cache a function definition between re-render while useMemo lets us cache the result of function between re-render. In other words, useCallback returns a memoized function and useMemo returns a memoized value.</p><p>Let’s dig deep in this difference.</p><p>In below example, we are calling our child component and updating the state of component itself. So whenever we’ll update the state our component will re-render and since child is there in parent component. &lt;Child&gt; will also keep on getting re-rendered on every state update even though &lt;Child&gt; component doesn’t have any direct dependency on that state.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/1*NgQ7Xqj8qchgQhDRRO-C0g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*M_gHgZClXB6W2z9qjrhBXA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3g1cWOLWhtJkqkHtD-Trcw.gif" /></figure><p>To overcome this problem, react introduced useMemo hook. Now we’ll wrap our child component in useMemo while using that in parent and use that returned value inside parent component.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/1*IRpK1FcjN3s31v4qQ7Itcw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DPsdHxmbcthtE62AaYrovw.gif" /></figure><p>As we can see, now when we are updating state of parent it’s not re-rendering the child component.</p><p>But what if we’ll pass a function/variable of parent component to child component as prop? In that case, when we’ll update state of parent that function/variable will get re-rendered and as we are passing that to child component our child component also will be re-rendered every-time on parent state update.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*kWi4pFaKzsLRLjhjsCoKng.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AgNHrMGGg-6MqQ79jmx-KA.gif" /></figure><p>As we can see here even if the child component is wrapped in useMemo hook but as we are passing checkCounter() function to child component which gets updated on every state update. So on every state update our child component is getting re-rendered just because of that prop change.</p><p>To avoid this problem we have another magical hook. useCallback!!</p><p>We’ll wrap checkCounter in useCallback function. So by this way we’ll cache our checkCounter function and pass that to child component. Now the checkCounter function is cached. It’ll not re-render on every state update and as we’ll not update this function on every state update our child component will also not get re-rendered on every state update because of the prop.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/1*L5RKYFq8jiOaFxaTTHfUew.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PcEpophaTrybLftXD9r3Tg.gif" /><figcaption>using useCallback</figcaption></figure><p>So the main use case of</p><p>useMemo are:-</p><ul><li>skipping expensive calculation</li><li>skipping re-rendering of component</li></ul><p>useCallback are :-</p><ul><li>skipping re-rendering</li><li>preventing an effect from firing too often</li><li>updating state from customised callback</li></ul><p>Now, when the usage are clear of useMemo and useCallback we can use these hooks in our code. It’ll not our code clean in direct way but if used effectively it’ll increase performance of our react application for sure.</p><p>For more deeper insighte, please check :-</p><ul><li><a href="https://beta.reactjs.org/reference/react/useCallback#usecallback">useCallback</a></li><li><a href="https://beta.reactjs.org/reference/react/useMemo">useMemo</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c0f41ef0265" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Function & Block]]></title>
            <link>https://prashant94jha.medium.com/function-block-adb04eb48eb7?source=rss-f1d3f65b28a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/adb04eb48eb7</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Prashant Jha]]></dc:creator>
            <pubDate>Thu, 27 Oct 2022 15:44:00 GMT</pubDate>
            <atom:updated>2022-10-27T15:44:09.687Z</atom:updated>
            <content:encoded><![CDATA[<p>In JavaScript the most commonly used scope is function. With each function we create a scope for itself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/274/1*ZjUR-llzbtiiehqehMsSDA.png" /></figure><p>All variable belong to function and can be used throughout the entirety of function. But, if don’t take careful precaution it can also lead to unexpected pitfalls.</p><p><strong>Hiding in plain scope :-</strong></p><p>Software design principle Principle of least privilege states that in design of software we should expose only what is minimally necessary and hide everything else.</p><p>So instead of writing</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/323/1*URSLveHXnBJptEagVsjCXQ.png" /></figure><p>It’s better to write</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/332/1*TKqKRyhMQUh_IUfgKbwXsQ.png" /></figure><p>Another benefit of abstraction is collision avoidance. for example</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/305/1*dcOVids2piLGkwGGkQLWEA.png" /></figure><p>will result in infinite loop. So instead of writing such code we can write</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/339/1*AkChWscQqS5iP49sCHtlpg.png" /></figure><p><strong>Anonymous vs Named function :-</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/364/1*c2FxKRPFp5r0pyR7cAR4Ew.png" /></figure><p>Let’s take example of setTimeout. This is most common anonymous function we come across. Using anonymous function has couple of advantages. This is quick and easy to type. But there are drawbacks which come with anonymous function. Some of them are :-</p><ol><li>It has no useful name to display in stackTrace which makes debugging tough.</li><li>To refer anonymous function we have to use deprecated arguments.callee reference.</li><li>A descriptive name helps self documenting the code in question.</li></ol><p>So the best practise is to always name function expression. We can write the same upper anonymous function like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/393/1*a5U_QGX4s1cGH6jewlhckw.png" /></figure><p><strong>Immediately invoking function expression :-</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/241/1*TirgElJ77Z0CLORJq3n0Gw.png" /></figure><p>while this works, there are certain problems/points it introduces :-</p><ol><li>To invoke a function we have to use identifier name fun which pollutes enclosing scope, global in this case.</li><li>We have to explicitly call the function to execute it.</li></ol><p>To overcome these JS have a solution which is immediate invoked function expression (IIFE). It does not need identifier to be called. In this way, it doesn’t pollutes the enclosing scope and it does not need to called explicitly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/210/1*hHfZITjUMrOuIL4ppjqOEg.png" /></figure><p>First pair of () makes the function an expression and second pair of () executes the function.</p><p>We can use IIFE to inverse the order of things where the function to execute is given second and parameter to pass to it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/362/1*F-qcAB_xeBGtGQuDwafM0w.png" /></figure><p>This pattern is used in UMD (universal module definition) project.</p><p><strong>Block as Scope :-</strong></p><p>Function is most common unit of scope. Other units of scope are possible and use of other units make our code even more better, cleaner and maintainable.</p><p>Here comes the block into picture. Block scope is used to hide information in block instead of function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/255/1*cIdjh81IRGS4Pwa_lNARKA.png" /></figure><p>Here our intent was to use i only within the context of for loop so we declared it inside the for loop instead of polluting the parent scope and to avoid unintended use variable in wrong places. That is what block scoping is all about. Declaring a variable as closer, as local as possible.</p><p><strong>Let :-</strong> The let keyword attach the variable declaration to the scope of whatever block it’s contained in.</p><p>Let implicitly hijacks block scope for it’s variable declaration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/413/1*mOYHY7wr338ipE_szRpa3Q.png" /></figure><p>Creating explicit blocks for block scoping making it more obvious where variables are attached or not. Explicit code is preferred over implicit or subtle code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/473/1*KcT2FKd5A2rqSyS-Jw_2Fw.png" /></figure><p>here in line number 6 and 10 we added opening and closing braces as explicit block. Now it’ll be easier as whole block to move around this code later in refactoring.</p><p>Declaration made with let will not hoist to entire scope of block they appear in. Such declaration will not observably ‘exist’ in block until declaration statement.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/445/1*Xbo5Z4VszoQHl7PG4UYStg.png" /></figure><p><strong>Garbage collection :- </strong>Block scoping is useful to closure and and garbage collection to reclaim memory.</p><p>Consider :-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/506/1*at7pgjS4TUT2rJEmqV0oUQ.png" /></figure><p>here there is no need of someReallyBigData after the process function but still it exists. ideally is should not be taking space in memory after execution of someReallyBigData function and it should have been vanished.</p><p>We can handle this problem using block scope and let variable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/579/1*OHrKmdOBUtXZtnmxu4C2WQ.png" /></figure><p>let has block scope so as soon as we invoke the block in line number 8 and 13 someReallyBigData which is let variable will be destroyed and will not be present in memory from line number 14 or in line number 1–7. This is how let and block can be used to do garbage collection better.</p><p>Declaring explicit block for variable to locally bind it is powerful tool.</p><p><strong>Const :-</strong></p><p>const also creates a blocked scope variable but whose value is fixed (constant). Any attempts to change that value will result in error.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/557/1*2_uODZ4E3H6QVqSbSs6MCg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=adb04eb48eb7" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>