<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sameer Kumar</title>
    <description>The latest articles on DEV Community by Sameer Kumar (@sameer1612).</description>
    <link>https://dev.to/sameer1612</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F652915%2Fbbad6279-66e9-40ca-b368-5b1147a5bba0.png</url>
      <title>DEV Community: Sameer Kumar</title>
      <link>https://dev.to/sameer1612</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sameer1612"/>
    <language>en</language>
    <item>
      <title>🔮 Functional Programming for Humans — Foundations</title>
      <dc:creator>Sameer Kumar</dc:creator>
      <pubDate>Mon, 29 Jul 2024 06:09:34 +0000</pubDate>
      <link>https://dev.to/sameer1612/functional-programming-for-humans-foundations-hel</link>
      <guid>https://dev.to/sameer1612/functional-programming-for-humans-foundations-hel</guid>
      <description>&lt;p&gt;Functional programming (FP) is like the cool, rebellious middle child of the programming (language) family. Instead of following the traditional imperative way of doing things step-by-step, FP focuses on creating clean, predictable code by treating functions as first-class citizens. It’s like the stand-up comedy of coding: sharp, witty, and always on point.&lt;/p&gt;

&lt;p&gt;A lot of jargon in the introduction itself? Thought so.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Some quick bullet points to wash off that cult image of FP&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;  There isn’t a clear line dividing functional programming languages from other languages.&lt;/li&gt;
&lt;li&gt;  You can write functional code in almost all languages. Even in boundaries of strict OOP languages.&lt;/li&gt;
&lt;li&gt;  Your code doesn’t need to be 100% functional. Try to keep it as immutable and pure as humanely possible.&lt;/li&gt;
&lt;li&gt;  FP doesn’t make you cool. It may do a little bit of idiot-proofing though.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8a9q5kjstt95csfhzmu1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8a9q5kjstt95csfhzmu1.png" alt="I ate a monad for breakfast and two endofunctors for lunch" width="500" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Today we’ll go through a few jargon to set the stage for upcoming adventures. I’ll stick to dumb JavaScript for code examples. Let’s keep Haskell/Elixir show off for later, hold peace it’ll come.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Pure functions&lt;/li&gt;
&lt;li&gt; Immutability&lt;/li&gt;
&lt;li&gt; Side effects&lt;/li&gt;
&lt;li&gt; Higher order functions&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;Pure functions&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnw2760m4if6044s0ecmq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnw2760m4if6044s0ecmq.png" alt="Walter white likes pure blue crystals" width="533" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The simplest and most important concept of functional programming is to make code outputs consistent. The same input(s) should give the same output. As simple as that. No T&amp;amp;C applied.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv5dy0e50kts6zbi7eg2r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv5dy0e50kts6zbi7eg2r.png" alt="pure functions always return the same output for the same inputs" width="800" height="686"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You send &lt;code&gt;2&lt;/code&gt; and &lt;code&gt;3&lt;/code&gt; to a function called &lt;code&gt;sum&lt;/code&gt;. It should always give you &lt;code&gt;5&lt;/code&gt; and never 23. Javascript joke!&lt;/p&gt;

&lt;p&gt;So you ask: Dear Sameer, it’s dead simple to ask for any computer program let aside this FP. Doesn’t all code work like that, or at least should work like that?&lt;/p&gt;

&lt;p&gt;Well easier said than done in large codebases where everything is like a mess of randomness. Let’s take a few simple examples.&lt;/p&gt;

&lt;p&gt;Pure functions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function add(a, b) {  
    return a + b;  
}  

// Example usage:  
console.log(add(2, 3)); // 5  
console.log(add(2, 3)); // 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function toUpperCase(str) {  
    return str.toUpperCase();  
}  

// Example usage:  
console.log(toUpperCase("hello")); // "HELLO"  
console.log(toUpperCase("hello")); // "HELLO"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Impure functions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let counter = 0;  

function incrementCounter() {  
    counter += 1;  
    return counter;  
}  

// Example usage:  
console.log(incrementCounter()); // 1  
console.log(incrementCounter()); // 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Outputs a random number between 1 and 10  
function getRandomNumber() {  
    return Math.floor(Math.random() * 10) + 1;  
}  

// Example usage:  
console.log(getRandomNumber()); // 2  
console.log(getRandomNumber()); // 6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However rudimentary, that gives a general idea. A pure function will always be consistent. Impure ones can and will backstab you in most unexpected places. Imagine, one time your bank account shows $150,000 and you refresh the page to see $150. Good enough for a minor heart attack, aye?&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;Immutability&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;Let’s define mutation first&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvnjfqgl5o5e7t7087303.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvnjfqgl5o5e7t7087303.png" alt="Let’s define mutation first" width="726" height="254"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fup0rfbg4x3s69woyx1gg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fup0rfbg4x3s69woyx1gg.png" alt="Sheldon from BBT doesn’t like changes. Triggers his OCD" width="632" height="395"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;No change == No mutation == Immutability == Trust&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now that we have semi-formally defined it, let’s look at how it works. After all, programming is all about changing one data into another. We’ll write a small mutable code and see the perks of its immutable version.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function updateAge(obj, newAge) {  
    obj.age = newAge;  
    return obj;  
}  

// Example usage:  
const person = {  
    name: 'Alice',  
    age: 25  
};  
console.log(updateAge(person, 26)); // { name: 'Alice', age: 26 }  
console.log(person); // { name: 'Alice', age: 26 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s dissect. Good Alice is 25 years old, to begin with. If I come to the last line directly and want to know the age of Alice(aka &lt;code&gt;person&lt;/code&gt;), I’ll have to track this &lt;code&gt;person&lt;/code&gt; object everywhere and carefully understand who modified it and “how”.&lt;/p&gt;

&lt;p&gt;Let’s fix this mutation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function updateAge(obj, newAge) {  
    return { ...obj, age: newAge };  
}  

// Example usage:  
const person = {  
    name: 'Alice',  
    age: 25  
};  
console.log(updateAge(person, 26)); // { name: 'Alice', age: 26 }  
console.log(person); // { name: 'Alice', age: 25 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, anywhere we meet this &lt;code&gt;person&lt;/code&gt;, we are guaranteed to know its state by seeing it’s original definition. If this new value is required for something, go ahead and keep it in a new &lt;code&gt;updatedPerson&lt;/code&gt; variable. If someone later wanna know the age of &lt;code&gt;updatedPerson&lt;/code&gt; , he’ll just jump to the place where it is first defined. Savvy?&lt;/p&gt;

&lt;p&gt;Benefits you ask. Here are a few:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; It becomes easy for the language’s internal tools to clean the used memory, aka, garbage collection.&lt;/li&gt;
&lt;li&gt; An implicit guarantee that value will remain consistent throughout the life of a variable.&lt;/li&gt;
&lt;li&gt; A ton of predictability in the code. You can just skim a few lines and tell what the value is at any point in time, without reading the entire code.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Idiot proofing. You know that someone else won’t modify what you read the first time. Ah! Do those edited WhatsApp messages ring a bell?&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Higher order functions
&lt;/h1&gt;

&lt;p&gt;This one ain’t much. Simply said, a function can take and return functions too, just like it plays with regular data.&lt;/p&gt;

&lt;p&gt;Depending on your previous programming experience this may look normal or whaaaat. I expect no in-between experience.&lt;/p&gt;

&lt;p&gt;When you treat functions as first-class citizens, you can do some pretty amazing things by combining or passing them around. Let’s see a few examples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// High-order function that returns another function  
function makeMultiplier(multiplier) {  
    return function(number) {  
        return number * multiplier;  
    };  
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Example usage (custom tailored functions on the fly)  
const double = makeMultiplier(2);  
const triple = makeMultiplier(3);console.log(double(5)); // 10  
console.log(triple(5)); // 15
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {map} from 'lodash';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numbers = [1, 2, 3, 4, 5]; // This map function takes a list of some data and a function.  
// Basically running the same function on each item in the list.  
const doubledNumbers = map(numbers, number =&amp;gt; number * 2 );// Example usage  
console.log(doubledNumbers); // [2, 4, 6, 8, 10]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  &lt;strong&gt;Side Effects&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Furls3r91cmhj3dpkay4t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Furls3r91cmhj3dpkay4t.png" alt="Now I Am Become Death, the Destroyer of Worlds" width="525" height="475"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here the real trouble starts. As the name suggests, your code will poke its nose into things that are beyond its scope. If the function modifies or triggers something that’s outside its scope, it can wake the dead from graves. We may never know the full extent of what this external call did until you are neck deep in that call stack rabbit hole.&lt;/p&gt;

&lt;p&gt;Too many fancy words? My sympathies. Let’s see the code you wrote some days back.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F451ccbdweo3vo84r71pg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F451ccbdweo3vo84r71pg.png" alt="Yeah Yeah Yeah! Now you tell me that you didn’t know that bunnies too have nukes. Classic" width="800" height="974"&gt;&lt;/a&gt;&lt;br&gt;
Yeah Yeah Yeah! Now you tell me that you didn’t know that bunnies too have nukes. Classic!&lt;/p&gt;

&lt;p&gt;Let’s create a cocktail of what we learned from pure functions and immutability. Side effects totally rack jacks our two beloved concepts.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numbers = [1, 2, 3];  

export function addNumber(number) {  
    numbers.push(number); // Modifies the original array  
}  

export function viewArray() {  
    console.log(numbers); // Prints numbers array  
}  

// Sinjo calling same method in different files  
viewArray() // 1,2,3  
viewArray() // 1,2,3  
viewArray() // 1,2,3  

// nastyuser_123 called it somewhere randomly  
addNumber(4)  
viewArray() // 1,2,3,4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These functions are making side effects on the numbers array. Our good user Sinjo is compulsively printing arrays using &lt;code&gt;viewArray&lt;/code&gt; function and getting the same results everywhere, pseudo-smiling in purity. Then someone called this &lt;code&gt;addNumber(4)&lt;/code&gt; and now his system is broken and he doesn’t even know why.&lt;/p&gt;

&lt;p&gt;Sinjo wants answers, Sinjo wants justice! ❤️‍🩹&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffd9c35qpd0bwngy6ui1b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffd9c35qpd0bwngy6ui1b.png" alt="Image description" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That’s all folks for today. Reflect on this jargon list. Whatever we went through should give a clear idea about what problems we are trying to solve. In the next piece, we’ll get our hands dirty with some deeper concepts. Ciao.&lt;/p&gt;

&lt;h1&gt;
  
  
  Want to connect?
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/in/sameerkumar1612/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://hi-sameer.vercel.app/" rel="noopener noreferrer"&gt;Website&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>PostGraphile — The Gateway Drug To GraphQL</title>
      <dc:creator>Sameer Kumar</dc:creator>
      <pubDate>Fri, 03 Nov 2023 10:02:49 +0000</pubDate>
      <link>https://dev.to/sameer1612/postgraphile-the-gateway-drug-to-graphql-5505</link>
      <guid>https://dev.to/sameer1612/postgraphile-the-gateway-drug-to-graphql-5505</guid>
      <description>&lt;p&gt;Postgraphile is the quickest way to scaffold a fully functional GraphQL CRUD API for your application without touching a line of code, (well that’s a lie but let it pass for dramatic effect). This article will expose you to the basics of what GraphQL is and how can we create an api quickly with postgraphile.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Disclaimer: This article will give an overview of what these concepts are at top level. Go ahead with documentation of specific library to understand real world implemenetation details.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  What is GraphQL
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs29fva17cdf5h5823ffw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs29fva17cdf5h5823ffw.png" alt="Image description" width="800" height="420"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://graphql.org/" rel="noopener noreferrer"&gt;https://graphql.org&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;GraphQL is a query language(QL) just like the good old SQL. I won’t go into any bookish definition. Let’s understand it practically.&lt;/p&gt;

&lt;p&gt;Now that the QL part is sorted, let’s give meaning to the graph word. It may chime with the feel of ERDs used in RDBMS. Okay my bad, forgot my promise of being practical. Let’s visualize the medium or any blog as a graph in the simplest possible manner.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuza7vol5pkgk6fwdkdcb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuza7vol5pkgk6fwdkdcb.png" alt="Image description" width="800" height="501"&gt;&lt;/a&gt;&lt;br&gt;
User 1 wrote 2 articles — Article 2 has 2 comments — User 2 wrote Comment 1 — User 2 also wrote Article 3&lt;/p&gt;

&lt;p&gt;Now things appear much more visually understandable. We can see the connection that each record bears with another, without abstractly thinking in terms of tables. At this point, everything starts looking like one big graph of records.&lt;/p&gt;

&lt;p&gt;To sum up, GraphQL is a query language to query this graph of records, just like SQL is a query language for data stored in tables.&lt;/p&gt;
&lt;h2&gt;
  
  
  Terminologies
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Node&lt;/strong&gt;: An individual object present in our database.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Edge&lt;/strong&gt;: Relationship of the said object with others.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Query&lt;/strong&gt;: As the name suggests, process of getting one or more fields from the node.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Mutation&lt;/strong&gt;: A change operation on the node as a whole or some of its fields.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Schema&lt;/strong&gt;: A representation of the overall structure of the graphql system.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Resolver&lt;/strong&gt;: A function that tells how to get a certain field on a node.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These folks have picked up some sensible nomenclature. It seems redundant to even explain what each term means. +10 points. If you want to learn it, nothing beats the &lt;a href="https://graphql.org/learn/" rel="noopener noreferrer"&gt;official docs&lt;/a&gt;. But, for the sake of completeness, let's do a small example.&lt;/p&gt;
&lt;h2&gt;
  
  
  Sample code in JavaScript
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { ApolloServer } from "@apollo/server";  
import { startStandaloneServer } from "@apollo/server/standalone";  

const typeDefs = `#graphql  
  type Book {  
    title: String  
    author: String  
  }  

  type Query {  
    books: \[Book\]  
  }  
`;  

const books = [  
  {  
    title: "The Awakening",  
    author: "Kate Chopin",  
  },  
  {  
    title: "City of Glass",  
    author: "Paul Auster",  
  },  
];  

const resolvers = {  
  Query: {  
    books: () =&amp;gt; books,  
  },  
};  

const server = new ApolloServer({  
  typeDefs,  
  resolvers,  
});  

const { url } = await startStandaloneServer(server, { listen: { port: 4000 } });  

console.log(`🚀 Server listening at: ${url}`);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;I know it may be overwhelming for someone new. Let’s quickly break it down a bit in some bullet points.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;**@apollo/server**&lt;/code&gt; is the GraphQL provider library, which makes the implementation and life easier. It has both a server and a client.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;**typeDefs**&lt;/code&gt; is used to define the structure of our data and allow queries.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;**books**&lt;/code&gt; is a mock source of data, in the real application this will be some database.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;**resolvers**&lt;/code&gt; provide the implementation details as to how these queries will be resolved.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Output
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4uk0nsasi9c1738f5lxs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4uk0nsasi9c1738f5lxs.png" alt="Image description" width="800" height="428"&gt;&lt;/a&gt;&lt;br&gt;
localhost:4000&lt;/p&gt;

&lt;p&gt;I wonder if anything can be simpler. You might not have noticed that it solves one of the biggest problems with REST APIs.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;With GraphQL we fetch only the specific fields that are required for our current need.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Long gone are days when API responses will contain two-thirds of useless data for work in hand. It is a game changer for large-scale applications owing to this solution for overfetching.&lt;/p&gt;

&lt;p&gt;Apart from overfetching, underfetching is no less a problem. Imagine you want a book and its publisher’s name to show on a webpage. One query goes for the book and then the next one for publisher API. With GraphQL, it can be easily done in one shot as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;query BooksWithAuthor {  
  books: {  
    title,  
    author,  
    publisher: { name }  
  }  
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So far so good. I see you vibing with the overall idea. Define how you’d like the output to be and it comes just like that without repeated queries. What can be accessed and how it will be furnished can be tightly controlled by typedefs and resolvers in the backend.&lt;/p&gt;

&lt;p&gt;In the next section, we’ll take a few bitter pills to set the expectations right.&lt;/p&gt;

&lt;h1&gt;
  
  
  What isn’t GraphQL
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fccij2dkkour2zeyjzhc0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fccij2dkkour2zeyjzhc0.png" alt="Image description" width="512" height="341"&gt;&lt;/a&gt;&lt;br&gt;
Not a piece of cake&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Repeat after me, GraphQL is just a type of API, like REST.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;GraphQL is not a:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Standalone full-scale server&lt;/li&gt;
&lt;li&gt;  Database paradigm or Query Language&lt;/li&gt;
&lt;li&gt;  Business logic container&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, even with GraphQL, you’ll need a traditional SQL/no-SQL database like MySQL, Postgres, MongoDB, etc. We are just changing the way the front end calls the back end in contrast to the traditional REST API.&lt;/p&gt;

&lt;p&gt;GraphQL is a delight for front-end developers. Nothing makes them happier than using GraphQL to fetch all the data they need in one shot. Imagine a single API call giving all the information needed to render a page completely.&lt;/p&gt;

&lt;p&gt;Then why it isn’t spreading like wildfire in the developer circles? Well, that’s because it’s a pain for backend devs to write and manage these APIs. All that nesting becomes troublesome to write &lt;code&gt;typedefs&lt;/code&gt; for. Nuances for connecting with every single table, handling permissions, and most of all tuning the performance.&lt;/p&gt;

&lt;p&gt;If one is not going for traditional table joins then imagine hitting a query to get publisher details for every book that you get. It’s the infamous N+1 problem in the world of SQL and REST. Frontend becomes a little easy but the backend becomes a nightmare.&lt;/p&gt;
&lt;h1&gt;
  
  
  What is PostGraphile
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhvdmgdcggabw8ei1r6bz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhvdmgdcggabw8ei1r6bz.png" alt="Image description" width="512" height="341"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.graphile.org/postgraphile/" rel="noopener noreferrer"&gt;PostGraphile Instant GraphQL API&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is a GraphQL implementation using Postgres as its database, the best database known to mankind. The good part is that it involves the least amount of manual intervention possible. Almost a no-code solution if you want to query or modify your database without any customization.&lt;/p&gt;

&lt;p&gt;It can be used in three ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Schema only — It generates the GraphQL schema by using Postgres table reflections and leaves implementation to users.&lt;/li&gt;
&lt;li&gt;  CLI mode — It can be run using the PostGraphile CLI tool with options and a list of extensions passed inline.&lt;/li&gt;
&lt;li&gt;  Library mode — The most versatile approach where it can be mounted as a route to existing NodeJS applications. Custom functions can be written to extend the schema obtained from the database.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For a complete overview, we will look into library mode. In its essence, PostGraphile is a middleware that sits between the Postgres database and your web API, which automatically scans and facilitates GraphQL queries and mutations. In short, it automagically creates &lt;code&gt;typedefs&lt;/code&gt; and &lt;code&gt;resolvers&lt;/code&gt;.&lt;/p&gt;
&lt;h1&gt;
  
  
  Getting started
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt; Scaffold an express application.&lt;/li&gt;
&lt;li&gt; Install PostGraphile. &lt;code&gt;npm install postgraphile&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; Add some quick start configs to the starting point of the app.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require("express");  
const { postgraphile } = require("postgraphile");  

const app = express();  

const postgraphileOptions = {  
  watchPg: true,  
  dynamicJson: true,  
  setofFunctionsContainNulls: false,  
  ignoreRBAC: false,  
  showErrorStack: "json",  
  extendedErrors: \["hint", "detail", "errcode"\],  
  exportGqlSchemaPath: "schema.graphql",  
  graphiql: true,  
  enhanceGraphiql: true,  
  allowExplain(\_) {  
    return true;  
  },  
  enableQueryBatching: true,  
  legacyRelations: "omit",  
};  

app.use(postgraphile(process.env.DATABASE\_URL, "public", postgraphileOptions));  

app.listen(process.env.PORT);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Apart from PostGraphile feature toggles, we need to pass the database URL as the most important parameter to PostGraphile for it to bootstrap the application.&lt;/p&gt;

&lt;p&gt;It may appear monkey business up till here but forget not. This is all you need. It doesn’t matter if your database contains 2 or 200 tables, 10 or a million records, 10 or 10,000 users, etc.&lt;/p&gt;

&lt;p&gt;You might have noticed we are not defining any &lt;code&gt;typedefs&lt;/code&gt; or &lt;code&gt;resolvers&lt;/code&gt;. Postgraphile is looking at our well-structured Postgres db and converting the table schema into a GraphQL schema.&lt;/p&gt;

&lt;p&gt;Apart from the HTTP endpoint, we get a full-blown playground to test our queries and mutations easily. It comes up at the &lt;code&gt;/graphiql&lt;/code&gt; route. Have a look below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsha28sqxuy7m4n290kfc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsha28sqxuy7m4n290kfc.png" alt="Image description" width="800" height="570"&gt;&lt;/a&gt;&lt;br&gt;
localhost:5001/graphiql&lt;/p&gt;

&lt;p&gt;No surprise, it works just like the regular GraphQL API, and we can do that nested query, which we were amazed at. On the left, we have a full-blown explorer, which shows what our schema looks like. The center panel is for queries and mutations. The right one is for our output. Once we are confident, we can just copy the centerpiece and paste it into our front-end application.&lt;/p&gt;

&lt;p&gt;One super important thing to notice here is that all this schema is generated by following some strict naming conventions. Notice how we used the field name &lt;code&gt;tracksByUserId&lt;/code&gt; to get all tracks of a user where the &lt;code&gt;tracks&lt;/code&gt; table is connected to &lt;code&gt;users&lt;/code&gt; table using the user_id field. There are a handful of such rules that you can check on the PostGraphile website.&lt;/p&gt;

&lt;p&gt;In the next section, we’ll go through some common things you may want to do in PostGraphile.&lt;/p&gt;
&lt;h1&gt;
  
  
  How to do stuff in the PostGraphile world
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjqmncybrdb1we999ual2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjqmncybrdb1we999ual2.png" alt="Image description" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Preparing the database
&lt;/h2&gt;

&lt;p&gt;This is going to be the old simple Postgres setup with no additional steps. Create a schema explicitly if you need access control to certain tables. Make sure to add necessary foreign keys to connect various tables. In the end, all we need is a valid database URL to feed in PostGraphile initialization. The format looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;postgres://user:password@somehost:2345/somedb
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Creating a custom field
&lt;/h2&gt;

&lt;p&gt;It’s pretty common to need a composite/computed field in your response object. The simplest example is combining the first and last name into full name. There are two ways to achieve it:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;Use database-level functions&lt;/strong&gt;: This method is the fastest and most optimized because code lives right into the database. For this example, you just need to open the database console and run the following:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE OR REPLACE FUNCTION users\_fullname(users users) RETURNS text AS  
$$  
SELECT CONCAT(users.first\_name, ' ', users.last\_name)  
$$ LANGUAGE sql STABLE;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice that it follows a certain format in naming. The name of the function will always be &lt;code&gt;tableName_fieldName&lt;/code&gt;, allowing PostGraphile to connect it as the resolver for that specific field automatically. You can keep it as a db migration script or whatever fits your use case.&lt;/p&gt;

&lt;p&gt;2. &lt;strong&gt;Write resolver manually when things are more complex&lt;/strong&gt;: We need to go this path to cleanly define custom functionalities in the PostGraphile system. For the given example of fullName, we can create it as an extension in a separate file and import it into the main file where we initialize the app.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;fullname.js&lt;/code&gt; contains this custom resolver to extend what we already have. The name of the file is totally up to you.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { makeExtendSchemaPlugin, gql } = require("graphile-utils");  

// Create a GraphQL schema extension to add the computed full\_name field  
const FullNamePlugin = makeExtendSchemaPlugin({  
  typeDefs: gql\`  
    extend type User {  
      fullName: String  
    }  
  \`,  
  resolvers: {  
    User: {  
      fullName: (user, args, context, resolveInfo) =&amp;gt; {  
        return \`${user.firstName} ${user.lastName}\`;  
      },  
    },  
  },  
});  

module.exports = FullNamePlugin;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we can import this file into our main file as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const FullNamePlugin = require("./fullname");  

const postgraphileOptions = {  
  ...  
  appendPlugins: \[  
    FullNamePlugin,  
  \],  
  ...  
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With just this much work, our custom field and resolver are ready to use in our application. And, it works as expected.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq5b2d0u4ggzkhrg07u3l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq5b2d0u4ggzkhrg07u3l.png" alt="Image description" width="800" height="593"&gt;&lt;/a&gt;&lt;br&gt;
Querying custom fields in postgraphile&lt;/p&gt;
&lt;h2&gt;
  
  
  Adding a description to fields in GraphQL Explorer
&lt;/h2&gt;

&lt;p&gt;It makes sense, and it is hardcore simple. Add a comment to the field using SQL, and it will be available in the explorer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;comment on column tracks.bpm is E'Beats per Minute...';

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zd9n8x6cayhfz7537b5h.png)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
Auto-generated documentation for the bpm field&lt;/p&gt;
&lt;h2&gt;
  
  
  Control visibility/modification of fields or tables
&lt;/h2&gt;

&lt;p&gt;Again magic comments are to our rescue. Postgraphile can be instructed to exclude any field or table from GraphQL access by using smart tags such as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// users table is marked as read only  
comment on table users is E'@omit create, update, delete';  

// version field from tracks table is completely removed from graphql  
comment on column tracks.version is E'@omit read';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Access control to records
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9f74tvalqzkcedf197jw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9f74tvalqzkcedf197jw.png" alt="Image description" width="500" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since it is so deeply tied to Postgres, it makes full use of Postgres roles and schemas for security. Postgraphile comes with a built-in implementation of JWT and can be used to fine-tune access further. A simple authorization looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GRANT SELECT ON users TO app\_users;  
GRANT DELETE ON users TO app\_admins;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, row-level security features can be used to finely restrict people from accessing a certain row in the table.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;create policy user\_policy\_select  
on public.users for select to users  
USING (  
email = current\_setting('current\_user\_email')  
);  
ALTER TABLE users ENABLE ROW LEVEL SECURITY;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Filtering records
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa581lkbj98c3qh26q8bo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa581lkbj98c3qh26q8bo.png" alt="Image description" width="600" height="327"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Filtering is supported natively to a certain extent, and it can be enhanced with full relational operator support using a connection filter plugin. Sample syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;query getOneUser {  
  user(id: 1) {  
    id  
    email  
    name  
  }  
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://www.graphile.org/postgraphile/filtering/" rel="noopener noreferrer"&gt;Postgraphile Filtering&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/graphile-contrib/postgraphile-plugin-connection-filter" rel="noopener noreferrer"&gt;Connection Filter Plugin&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One good thing to know is that postgraphile behind the scenes optimizes your query conversion from GQL to SQL. The result is one single top-level query, thus eliminating the N+1 problem we discussed earlier.&lt;/p&gt;

&lt;p&gt;You can go on with postgraphile documentation to continue your exploration further.&lt;/p&gt;

&lt;h1&gt;
  
  
  Cons of PostGraphile
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2nd4c54qfxx4adnega2q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2nd4c54qfxx4adnega2q.png" alt="Image description" width="800" height="508"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once again, same question: if everything is so awesome, why isn’t everyone using this as a defacto way of building applications?&lt;/p&gt;

&lt;p&gt;The answer was evident from the start. PostGraphile takes away a lot of control from the user for its magic to happen. From big technical details to simple things, such as how one should name his fields, are dictated by PostGraphile. Engineers don’t like this, and they seriously don’t.&lt;/p&gt;

&lt;p&gt;Apart from technical things, the community is pretty small. So, if you are stuck somewhere, the lord may have mercy.&lt;/p&gt;

&lt;p&gt;Being so close to db creates a big abstraction for developers. Making change is tough because things are living right in the database. And, also switching the db is not much of an option.&lt;/p&gt;

&lt;p&gt;Regardless, I like the simplicity it brings to the table. We can use this solution for small websites like personal blogs, portfolios, hobby projects, etc. It seems a solid contender for even big websites that are frontend-heavy and don’t have much going in the backend apart from simple crud.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F37umjxg89561137vdwzd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F37umjxg89561137vdwzd.png" alt="Image description" width="611" height="408"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It's been a bumpy ride, ain’t it? GraphQL is an interesting piece of technology and can be useful in certain scenarios, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  You don’t know the access pattern of the consumer apps.&lt;/li&gt;
&lt;li&gt;  Your tables are huge, and in most cases, people only need a small subset of fields.&lt;/li&gt;
&lt;li&gt;  Performance issues need to be solved by reducing response payload size and network roundtrips.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But be aware implementing those types and resolvers will suck life out of you as the application starts getting complex. PostGraphile’s approach is clap-worthy but a little idealist. Nonetheless, if someone is starting with GraphQL, postgraphile serves as a magical option to use your existing database and get a feel of how things will look in the GraphQL world without investing time and effort in an elaborate setup.&lt;/p&gt;

&lt;h1&gt;
  
  
  Want to connect?
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/in/sameerkumar1612/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://hi-sameer.vercel.app/" rel="noopener noreferrer"&gt;Website&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>database</category>
      <category>graphql</category>
    </item>
    <item>
      <title>No More Drama: Conflict Resolution</title>
      <dc:creator>Sameer Kumar</dc:creator>
      <pubDate>Tue, 24 Oct 2023 13:25:16 +0000</pubDate>
      <link>https://dev.to/sameer1612/no-more-drama-conflict-resolution-4837</link>
      <guid>https://dev.to/sameer1612/no-more-drama-conflict-resolution-4837</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Earth and World are not same things. You might have heard people discussing their world view, and not the earth view!&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;Oh! you are confused? Works well for me. After ages, I am writing a non-tech article solving softer problems in this diverse tech industry. Let’s take a purely fact-driven objective take on this issue, no personal takes. Any personal opinion from me will pollute the theme of this discussion.&lt;/p&gt;

&lt;h1&gt;
  
  
  Earth vs World
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz20gzhf2tpf2qbhd42o7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz20gzhf2tpf2qbhd42o7.png" alt="Image description" width="600" height="527"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Okay, let’s clear up this one first. First, a quick definition to set baseline context and ensure we all are on the same page. Don’t disagree at this point, otherwise, I’ll find you and have a word, the old-fashioned way.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Earth&lt;/strong&gt; — A planet on which we live. It looks blue, blue is beautiful.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;World&lt;/strong&gt; — A consolidated model of everything someone “knows about”, covering the earth and beyond.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now that term, world-view makes sense. The key takeaway is that “The Matrix” is real and everything is a mere interpretation of someone trapped in it.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Nothing is absolute truth if more than one person is involved in the context. Even this very sentence depends on your prejudice.&lt;br&gt;&lt;br&gt;
Bold Take! I get it, let’s break it into digestible chunks.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Conflict — The Origins
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhabviamm2mrykqiwfnkr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhabviamm2mrykqiwfnkr.png" alt="Image description" width="800" height="407"&gt;&lt;/a&gt;&lt;br&gt;
Most of the time, I witness conflicts either professionally or personally circle around the root cause of identity crisis. We work our entire lives to gain an identity in society and make sense of our existence. Psychologically, it is understandable that we can’t gain that identity if we compromise every now and then, we’ll be wiped off. After all, we are what people perceive about us.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;We defend what we stand for because they define us. Without that, there are billions of similar human bodies occupying the earth, who gives a crap.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;As you would have guessed yourself, conflicts rise when contrasting identities collide. Seems right, as long as something is scientifically justified, I’m cool with it. Now that raises the question, “If it is so normal, then why does it feel so piercing at times, is there a crack in human anthropology?”&lt;/p&gt;

&lt;p&gt;The answer seems straightforward to me. It is a well-architected negative feedback loop. You lose an argument, you feel inferior, you work on it, win the next one.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8kdrgmlay064pikwt2wh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8kdrgmlay064pikwt2wh.png" alt="Image description" width="800" height="648"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Well now that we have established that we are not fighting but our opinions are, let’s look at how to fix it. Without a solution, this whole discussion will be a sham.&lt;/p&gt;

&lt;h1&gt;
  
  
  Perception — The problem
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxu0mdnsyz5ztgzci511d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxu0mdnsyz5ztgzci511d.png" alt="Image description" width="450" height="394"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Perception is the root cause of each conflict. Take the example of the cover image of this article. Both are fighting because one perceives the digit as 6 and the other as 9. This is a little evened out, let’s give it the benefit of the doubt. Maybe an office scenario, where two colleagues are fighting over which solution fits better as in the case of a competing project proposal. This seems more relatable. Ain’t it?&lt;/p&gt;

&lt;p&gt;The way every person lives in this world is totally unique and hence the viewpoint. No two people ever can perceive the same thing/event in exactly the same way. So, by our Many World theory, both are right. If someone is wrong at all then it’s the person who thinks “only” he/she is right.&lt;/p&gt;

&lt;p&gt;Example: Two people fighting over which is better SUV or Sedan. X says SUVs are best because it is for all terrains. Y says Sedans are best because they look the best. One common issue that will follow after the sane argument above is defensive-offensive justifications. This point beyond perceptions overtakes facts and people start influencing and imposing their opinions so that the competition starts thinking in their favor, eventually folding towards his/her point of view.&lt;/p&gt;

&lt;h1&gt;
  
  
  Perspective — The solution
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxo0rthuo94n0k5hzqgbd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxo0rthuo94n0k5hzqgbd.png" alt="Image description" width="702" height="395"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To understand the gist of this term it takes a lot of maturity and experience. How many times, you have seen a conflict resolution with your colleague ending in, let’s do whatever is good for the project, or Here are 3 pros and cons of my approach?&lt;/p&gt;

&lt;p&gt;Ain’t that relatable? Some workplaces do encourage such good outcomes, including mine, but at the end of the day we are humans and our perception goes ahead of us. Perspective is like glasses that you can wear and see what another person might be seeing. Seems trivial in the text but takes a lot of courage to compromise own identity and adopt others’ even for a short while.&lt;/p&gt;

&lt;h1&gt;
  
  
  Steps for resolution
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7242uyrynuww63llkndv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7242uyrynuww63llkndv.png" alt="Image description" width="800" height="451"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;Detach&lt;/strong&gt;: Detach your identity from the problem at hand. Exclude all your relevant experience from the “decision” part.
&lt;em&gt;Example: For me as a programmer, my first language java always makes a tiny vote in deciding how a system should look, maybe subconsciously. As expected, for two equally good proposals I’ll subconsciously choose one that is in harmony with my experience. Maybe between Java and Ruby, I decided on Java. I know both, no problems for me either way, but on the flip side maybe the other guy only knows Ruby and is going through a nightmare thinking about the Java behemoth he’ll have to deal with if this one gets approved.&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Objectify your thoughts&lt;/strong&gt;: This is extremely important as in any conversation, conversation skills play a bigger role than the underlying points. We should even that out by looking at things objectively first before going into subjective explanations. Make a bullet list of why your idea is good and what problems it has. Writing or even thinking about the second part will clean up half the malice. I bet it will be just a smooth discussion thereafter because you yourself have attested to where you(your idea) win and lose.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;You are not the only right one&lt;/strong&gt;: Start the discussion with one clear goal that you are not the right person in this discussion or your idea is not the right one. It changes everything when you open yourself to walk in another’s shoes and see things as they are thinking. On a positive note, you can find a flaw in other people’s thought processes and can give feedback rather than being dismissive at the surface level.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  If you start losing to yourself. Repeat the following:
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;I, a well-educated rational person, can’t even listen with an open mind to someone who maybe comes from a different culture, upbringing, education, experience, work style, goals and more. I am awesome !!!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Funny but works. An instant dose of humbleness gets delivered. Never involve yourself. Let those 5 bullet points shoot each other. Whatever survives the battle, go with that.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu3rf2xbjxdaep66xw2ko.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu3rf2xbjxdaep66xw2ko.png" alt="Image description" width="618" height="499"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If everything is based on perspective, how can mine be the absolute one?&lt;/p&gt;

&lt;p&gt;This sheer fact changes everything as long as you are courageous enough to compromise your identity for the duration of the discussion.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I landed in such a conflict with one of my friends last month while deciding tech stack for his mobile application. For reference, he is a hardcore native mobile developer and I just know a little bit of Flutter. I vouched for Flutter, he went for Kotlin. We shot each other for an hour and later realized how stupid we were and the idea for this article came.&lt;/p&gt;

&lt;p&gt;Even he laughed when opened a notepad and started noting figures for usage volume and access patterns. In the end, we went for react native after salvaging a significant chunk of business logic from the main React web application.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Give it a shot, feels good!&lt;/em&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Want to connect?
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/in/sameerkumar1612/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://hi-sameer.vercel.app/" rel="noopener noreferrer"&gt;Website&lt;/a&gt;&lt;/p&gt;

</description>
      <category>softwaredevelopment</category>
      <category>productivity</category>
      <category>marketing</category>
      <category>management</category>
    </item>
    <item>
      <title>The Pragmatic Guide to Your First JavaScript Library</title>
      <dc:creator>Sameer Kumar</dc:creator>
      <pubDate>Sun, 22 Oct 2023 14:40:22 +0000</pubDate>
      <link>https://dev.to/sameer1612/the-pragmatic-guide-to-your-first-javascript-library-1cfa</link>
      <guid>https://dev.to/sameer1612/the-pragmatic-guide-to-your-first-javascript-library-1cfa</guid>
      <description>&lt;p&gt;JavaScript libraries! Every man and his dog has a &lt;code&gt;node_modules&lt;/code&gt; folder full of them. This article will be more or less a pragmatic guide to writing these without going neck-deep in history and theory. &lt;/p&gt;

&lt;p&gt;Let’s get started. First of all, a bit of pseudo-nomenclature. For all intent and purposes, we will classify libraries into two sections: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Utilities: Non-UI libraries, as in these libraries, will provide functionalities in JavaScript without manipulating the DOM. For example, Lodash gives us a function to sort an array. &lt;/li&gt;
&lt;li&gt;Components: UI manipulation libraries, which mainly intend to manipulate the DOM. For example, a react component library like material UI. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Intuitively, it’s clear that building utilities is easier than building components because of the technical stack’s width involved. What the particular library internally does is beyond our scope. We will focus on how to pack, distribute, and use them. &lt;/p&gt;

&lt;h1&gt;
  
  
  Setup the Most Basic Example 
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;Remember, in most cases a good library is a decoupled section of your application that you want to distribute to others. Folder structure:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgh5z49xt3ljsiwn5g5ra.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgh5z49xt3ljsiwn5g5ra.png" alt="Image description" width="800" height="660"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can get the idea by looking at the example application I have set up. Codes living in the &lt;code&gt;lib&lt;/code&gt; folder, don’t directly link to the business logic of the main application.&lt;/p&gt;

&lt;p&gt;For our first example, we are building a utility library that returns a random ninja’s name using a highly complex randomization logic. Let’s look at the file contents:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// lib/ninja.js  

const ninjas = \["Kakashi", "Itachi", "Shikamaru"\];  

export function getRandomNinja() {  
  return ninjas\[Math.floor(Math.random() \* ninjas.length)\];  
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// index.js  

import { getRandomNinja } from "./lib/ninja";  

console.log(getRandomNinja());
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!-- index.html --&amp;gt;  

&amp;lt;!doctype html&amp;gt;  
&amp;lt;html&amp;gt;  
  &amp;lt;body&amp;gt;  
    &amp;lt;h1 id="name"&amp;gt;&amp;lt;/h1&amp;gt;  
  &amp;lt;/body&amp;gt;  

  &amp;lt;script type="module"&amp;gt;  
    import { getRandomNinja } from "./lib/ninja.js";  

    const ninja = getRandomNinja();  
    document.getElementById("name").textContent = ninja;  
  &amp;lt;/script&amp;gt;  
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Looks good. Let’s try to run it. A flying brick received right in the face. Hey, we are positive people. We are going to look into it. No worries!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxzd0a47vjbhdderi4l6y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxzd0a47vjbhdderi4l6y.png" alt="Image description" width="800" height="660"&gt;&lt;/a&gt;&lt;br&gt;
&amp;gt;&amp;gt;&amp;gt; node index.js&lt;/p&gt;
&lt;h2&gt;
  
  
  Modular JavaScript (MJS)
&lt;/h2&gt;

&lt;p&gt;The error looks straightforward. Let’s try to look into the second suggestion before dialing into the whole &lt;code&gt;node_modules&lt;/code&gt; ecosystem. We are going to rename those JS files to the mjs extension. And voila! It works. Even the HTML example started working as expected after changing the extension of the referenced file there.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ninja-lib ❯❯❯ node index.mjs  
Shikamaru  
ninja-lib ❯❯❯ 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For its help, mjs definitely deserves a discussion here. MJS is an acronym for Modular JavaScript.&lt;/p&gt;

&lt;p&gt;So, officially, there are two flavors of JavaScript: one regular one and another that imports and exports modules “natively.” There are technical differences in their internal implementation and scope resolution, but let’s not get ahead of ourselves.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;MJS is newer and may not work in a Neanderthal’s machine running Internet Explorer, but for common masses, its good to go.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Here comes package.json
&lt;/h2&gt;

&lt;p&gt;Now, we’re revisiting the previous suggestion of using a &lt;code&gt;package.json&lt;/code&gt; file. Apart from the internal cons of mjs, the main reason for the former approach being widely accepted is because of more familiarity with devs and machines.&lt;/p&gt;

&lt;p&gt;We rolled back those mjs extensions to regular js files and added this bare-bone &lt;code&gt;package.json&lt;/code&gt; file at the root of our project. Notice we mentioned it’s a module here. Everything works as expected!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// package.json  

{  
  "name": "ninja-lib",  
  "author": "Sameer Kumar",  
  "type": "module",  
  "version": "1.0.0",  
  "description": "Library for finding real ninjas",  
  "main": "index.js",  
  "directories": {  
    "lib": "lib"  
  }  
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This &lt;code&gt;lib&lt;/code&gt; folder is now ready for shipping. You can push it to GitHub or npm. Each platform has a very easy quick start guide to publish there; nothing too technical involved. Your users get exactly what you have written in the &lt;code&gt;lib&lt;/code&gt; folder — no surprises packaged. This works well depending on the complexity of your library and how much less it depends on other libraries.&lt;/p&gt;

&lt;h1&gt;
  
  
  Stepping Up With Distribution Strategies
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F51ygadcfw77b7p3tdavn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F51ygadcfw77b7p3tdavn.png" alt="Image description" width="600" height="337"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that we have written something, we want to distribute it to other folks in a clean “packaging.” After all, we just added a &lt;code&gt;package.json&lt;/code&gt; file, so the name should carry the weight.&lt;/p&gt;

&lt;p&gt;A module/library can be packaged in a few well-accepted formats. Some techniques are:&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;UMD (Universal Module Definition)&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;UMD is a versatile module format that works in all environments, including in the browser. It provides a way to create modules that can be used with minimum expectations from the consumer.&lt;/p&gt;

&lt;p&gt;Forget the mumbo-jumbo, remember the &lt;code&gt;script&lt;/code&gt; tag from the golden days. You’ll go for this packaging if you want to simply import in an HTML file and move on like we used to in our beloved jQuery. Here’s what that looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!-- index.html --&amp;gt;  

&amp;lt;!doctype html&amp;gt;  
&amp;lt;html&amp;gt;  
  &amp;lt;body&amp;gt;  
    &amp;lt;h1 id="name"&amp;gt;&amp;lt;/h1&amp;gt;  
  &amp;lt;/body&amp;gt;  

  &amp;lt;script src="https://code.jquery.com/jquery-3.7.1.js"&amp;gt;&amp;lt;/script&amp;gt;  
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;ES6 Modules (ESM)&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;ECMAScript Modules (ESM) are a native module system for JavaScript, and modern browsers and Node.js support them. They use &lt;code&gt;import&lt;/code&gt; and &lt;code&gt;export&lt;/code&gt; statements to define and load modules.&lt;/p&gt;

&lt;p&gt;We have already done an example of this format in our previous ninja finder example. Here’s the code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// calculator.js  

export function sum(a, b) {  
  return a + b;  
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// index.js  

import { sum } from "calculator.js";  

console.log(sum(2, 2));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;CommonJS (CJS)&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;CommonJS is a module system used primarily in Node.js. It uses the &lt;code&gt;require&lt;/code&gt; and &lt;code&gt;module.exports&lt;/code&gt; (or &lt;code&gt;exports&lt;/code&gt;) syntax to define and import modules.&lt;/p&gt;

&lt;p&gt;No wonder you have seen it once or twice. It is the predecessor to the ES6 &lt;code&gt;import&lt;/code&gt;/&lt;code&gt;export&lt;/code&gt; syntax we used in our above example. It is slowly fading out of even the backend development ecosystem in favor of the ES6. You must have seen it in Express apps.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;It’s very important to consider this packaging format if you are shipping your library for both frontend and backend.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// calculator.js  

const sum = (a, b) =&amp;gt; {  
  return a+b;  
};  

exports.sum = sum;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// index.js  

const calculator = require('./calculator');  
console.log(\`2 + 2: ${calculator.sum(2, 2)}\`);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Many more of these formats are custom-tailored for specific use cases, but the above three should be good enough for us potato developers. ;)&lt;/p&gt;

&lt;p&gt;Honorable mentions should extend to SystemJS and AMD (Asynchronous Module Definition) as well.&lt;/p&gt;

&lt;h1&gt;
  
  
  Bundling Systems
&lt;/h1&gt;

&lt;p&gt;Now, the real fun starts. You don’t want the user to import 42 separate js files to handle other files that need to be imported. To be honest, your user won’t take a look at your library either. It should be as close to a one-click installation as possible. As seen in the UMD example above, we added a ton of jQuery features just by adding one line of script tag.&lt;/p&gt;

&lt;p&gt;Some common bundling toolchains build your application/library into an optimized distributable bundle. The strategy can vastly differ from everything bundled into a single js file or split into chunks that automatically load when needed. A few big names in this game are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Webpack&lt;/li&gt;
&lt;li&gt; Rollup&lt;/li&gt;
&lt;li&gt; Parcel&lt;/li&gt;
&lt;li&gt; esbuild&lt;/li&gt;
&lt;li&gt; SWC&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Each one has its own nuances, but for us, all are doing the same work of bundling. Some are faster, some are more extensible, some are more supported, etc.&lt;/p&gt;

&lt;p&gt;For our purpose, nothing matters. When choosing one for your project, you’ll do deep analysis for sure. One that I can suggest, which works well, is a tool called &lt;a href="https://vitejs.dev/" rel="noopener noreferrer"&gt;Vite&lt;/a&gt;. Vite is not a bundler but a build framework that internally uses esbuild and Rollup for bundling. Let's implement it in our ninja application.&lt;/p&gt;

&lt;h1&gt;
  
  
  Adding Vite to Existing Application
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhwbcd3k0nlzjo2drqul2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhwbcd3k0nlzjo2drqul2.png" alt="Image description" width="640" height="640"&gt;&lt;/a&gt;&lt;/p&gt;
https://vitejs.dev



&lt;p&gt;Adding Vite is super simple. Let’s add it to our &lt;code&gt;package.json&lt;/code&gt; file. Notice the &lt;code&gt;scripts&lt;/code&gt; and &lt;code&gt;devDependencies&lt;/code&gt; sections. Run &lt;code&gt;npm install&lt;/code&gt; or &lt;code&gt;yarn&lt;/code&gt; to install the new dependencies we added. Here’s what that looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// package.json  

{  
  "name": "ninja-lib",  
  "type": "module",  
  "version": "1.0.0",  
  "description": "Library for finding real ninjas",  
  "scripts": {  
    "dev": "vite",  
    "build": "vite build"  
  },  
  "devDependencies": {  
    "vite": "^4.4.5"  
  }  
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With it installed, we are ready to roll with all the goodies with Vite, especially my favorite, hot reload. Before we start our dev server, let’s make some changes so the code will accept Vite.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Vite for a single-page application
&lt;/h2&gt;

&lt;p&gt;By default, Vite looks for the &lt;code&gt;index.html&lt;/code&gt; file in the root directory, so we are good there for now. Let’s simplify the HTML a bit by adding the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!-- index.html --&amp;gt;  

&amp;lt;!doctype html&amp;gt;  
&amp;lt;html&amp;gt;  
  &amp;lt;body&amp;gt;  
    &amp;lt;h1 id="name"&amp;gt;&amp;lt;/h1&amp;gt;  
  &amp;lt;/body&amp;gt;  

  &amp;lt;script src="./index.js" type="module"&amp;gt;&amp;lt;/script&amp;gt;  
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// index.js  

import { getRandomNinja } from "./lib/ninja.js";  

document.getElementById("name").innerHTML = getRandomNinja();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is all. Nothing else is needed to run the application. We can start the application by doing &lt;code&gt;npm run dev&lt;/code&gt; or &lt;code&gt;yarn dev&lt;/code&gt;. A local server will run and manage our application on a certain port &lt;code&gt;5173&lt;/code&gt; by default. All properties of Vite can be configured by adding a &lt;code&gt;vite.config.js&lt;/code&gt; file at the project’s root.&lt;/p&gt;

&lt;p&gt;The application can be optimized and built by running &lt;code&gt;npm run build&lt;/code&gt; or &lt;code&gt;yarn build&lt;/code&gt;. It creates a distribution folder, &lt;code&gt;dist&lt;/code&gt;, which contains one HTML and js file that encapsulates the entire application. Even if we add ten more files, the output will still produce the same two files. And hence came the name of the process, bundling.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnurk593qx2v5n9yklukf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnurk593qx2v5n9yklukf.png" alt="Image description" width="800" height="657"&gt;&lt;/a&gt;&lt;/p&gt;
yarn build



&lt;h2&gt;
  
  
  Using Vite to build libraries
&lt;/h2&gt;

&lt;p&gt;Hey, hey, hey, where did we go in the flow? We were building a library, not another single-page application. Oopsies, my bad!&lt;/p&gt;

&lt;p&gt;Let’s add the &lt;code&gt;vite.config.js&lt;/code&gt; file we talked about earlier. Here, we instructed Vite to build a library and also pointed to the main file of our library, as you can see below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// vite.config.js  

import { defineConfig } from "vite";  
import path from "path";  

export default defineConfig({  
  build: {  
    lib: {  
      entry: path.resolve(\_\_dirname, "./lib/ninja.js"),  
      name: "Ninja",  
      fileName: (format) =&amp;gt; \`ninja.${format}.js\`,  
    },  
  },  
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Upon running the &lt;code&gt;build&lt;/code&gt; command again, we see that now the &lt;code&gt;dist&lt;/code&gt; folder only contains the library we want to ship — thankfully, in two flavors by default. &lt;code&gt;ninja.es.js&lt;/code&gt; works better as an npm package but &lt;code&gt;ninja.umd.js&lt;/code&gt; will be better as a script tag. Note that we can configure it to churn out other formats, too.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F20tlj5o05d6y3gxh6s3f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F20tlj5o05d6y3gxh6s3f.png" alt="Image description" width="800" height="458"&gt;&lt;/a&gt;&lt;/p&gt;
yarn build

 

&lt;p&gt;Let's chime into the magic now. Here, we added a new &lt;code&gt;demo.html&lt;/code&gt; file that has literally no connection to our application. We got our application working by importing it as a simple js script, not even &lt;code&gt;type=“module”&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!-- demo.html --&amp;gt;  

&amp;lt;!doctype html&amp;gt;  
&amp;lt;html&amp;gt;  
  &amp;lt;body&amp;gt;  
    &amp;lt;h1 id="name"&amp;gt;&amp;lt;/h1&amp;gt;  
  &amp;lt;/body&amp;gt;  

  &amp;lt;script src="./dist/ninja.umd.js"&amp;gt;&amp;lt;/script&amp;gt;  
  &amp;lt;script&amp;gt;  
    const ninja = Ninja.getRandomNinja();  
    document.getElementById("name").textContent = ninja;  
  &amp;lt;/script&amp;gt;  
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s get “modern” and use ESM build as well. Works like a charm.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { getRandomNinja } from "./dist/ninja.es.js"; // library name later  

document.getElementById("name").innerHTML = getRandomNinja();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Though this may look similar to what we were doing earlier, on the bright side, this one import can have hundreds of files clubbed and optimized in a single unit.&lt;/p&gt;

&lt;h1&gt;
  
  
  Building Components
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1v3qojb8h2e9ubgykg9w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1v3qojb8h2e9ubgykg9w.png" alt="Image description" width="500" height="364"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After going through all the foundational work, we are now ready to get into the real deal. Let’s imagine we are building a notification library of sorts. Calling js functions only is not going to suffice. We need to do some HTML of our own and, in turn, hook it to the user’s DOM as well.&lt;/p&gt;

&lt;p&gt;Vite or any other build system can only bundle JavaScript as its core functionality. Our requirements have overgrown our capabilities. Anyway, let's give it a shot. We’ll make sure not to go in the same single-page application direction again.&lt;/p&gt;

&lt;p&gt;We will display a message on the screen without end user intervention by using our own HTML. This can vary from a simple text to a self-contained application. Here’s what the code looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!-- notify.html --&amp;gt;  

&amp;lt;h1 id="ninja-notify"&amp;gt;  
  &amp;lt;span&amp;gt;Your ninja is: &amp;lt;/span&amp;gt;  
  &amp;lt;span id="name"&amp;gt;&amp;lt;/span&amp;gt;  
&amp;lt;/h1&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// ninja.js  

import notifyHTML from "./notify.html?raw";  

const ninjas = \["Kakashi", "Itachi", "Shikamaru"\];  

function getRandomNinja() {  
  return ninjas\[Math.floor(Math.random() \* ninjas.length)\];  
}  

export function notifyNinja() {  
  const notifyEl = document.createElement("div");  
  notifyEl.innerHTML = notifyHTML;  
  document.body.appendChild(notifyEl);  
  document.getElementById("name").innerText = getRandomNinja();  
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// index.js  

import { notifyNinja } from "./lib/ninja.js";  

notifyNinja();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!-- index.html --&amp;gt;  

&amp;lt;!doctype html&amp;gt;  
&amp;lt;html&amp;gt;  
  &amp;lt;body&amp;gt;&amp;lt;/body&amp;gt;  

  &amp;lt;script src="./index.js" type="module"&amp;gt;&amp;lt;/script&amp;gt;  
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Okay, all done. This setup will smoothly bring the component we created in our library to the consumer application. I played a trick regarding HTML files. Did you notice?&lt;/p&gt;

&lt;p&gt;Using the above import syntax, we can inject HTML into the js file as if it were a raw string. This is super powerful in bundling because our bundler will otherwise error out, saying that it doesn’t identify the HTML file type. Makes sense, it is a JavaScript bundler, after all.&lt;/p&gt;

&lt;p&gt;Rest assured, it builds correctly, and we get the same single-file builds in our &lt;code&gt;dist&lt;/code&gt; folder, one for &lt;code&gt;umd&lt;/code&gt;, and one for &lt;code&gt;esm&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fev8zu90d9qa16v787mfc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fev8zu90d9qa16v787mfc.png" alt="Image description" width="800" height="529"&gt;&lt;/a&gt;&lt;/p&gt;
Demo HTML



&lt;p&gt;The last piece is all about fusing our styles. CSS is a world with dozens of build systems just like JavaScript. One sane thing to do here is pray to our overlord, Vite, to manage it somehow. Luckily, Vite has a rich ecosystem of plugins (actually, esbuild and Rollup plugins).&lt;/p&gt;

&lt;p&gt;Here, we have added one such plugin, &lt;code&gt;vite-plugin-css-injected-by-js&lt;/code&gt;, that injects all CSS used in the library’s js files directly into the bundle, which will create a host application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// package.json  

{  
  "name": "ninja-lib",  
  "type": "module",  
  "version": "1.0.0",  
  "description": "Library for finding real ninjas",  
  "scripts": {  
    "dev": "vite",  
    "build": "vite build"  
  },  
  "devDependencies": {  
    "vite": "^4.4.5",  
    "vite-plugin-css-injected-by-js": "^3.3.0"  
  }  
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Adding some random styles&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/\* styles.css \*/  

#ninja-notify {  
  color: cornflowerblue;  
  font-family: sans-serif;  
  position: fixed;  
  top: 1rem;  
  right: 1rem;  
  padding: 1em 2em;  
  border: 1px solid cornflowerblue;  

  border-radius: 0.5em;  
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
// ninja.js  

import notifyHTML from "./notify.html?raw";  
import "./styles.css";  

const ninjas = \["Kakashi", "Itachi", "Shikamaru"\];  

function getRandomNinja() {  
  return ninjas\[Math.floor(Math.random() \* ninjas.length)\];  
}  

export function notifyNinja() {  
  const notifyEl = document.createElement("div");  
  notifyEl.innerHTML = notifyHTML;  
  document.body.appendChild(notifyEl);  
  document.getElementById("name").innerText = getRandomNinja();  
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsad8upal7jhfli3twuzl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsad8upal7jhfli3twuzl.png" alt="Image description" width="800" height="529"&gt;&lt;/a&gt;&lt;/p&gt;
Demo HTML



&lt;p&gt;And it works, no doubts there. The &lt;code&gt;dist&lt;/code&gt; folder still consists of just a single JavaScript output, which contains HTML, CSS, and JavaScript, ready to be imported into the host application with zero configuration. If you have a larger library, then it will be better to keep bundles split for performance gains.&lt;/p&gt;

&lt;h1&gt;
  
  
  Final Words
&lt;/h1&gt;

&lt;p&gt;I hope this walk-through was somewhat helpful. There is a lot of tooling around single-page applications mainly due to the popularity of the mighty three: Angular, React, and Vue.&lt;/p&gt;

&lt;p&gt;This guide is a bare minimum boarding point to help you explore the library. If you are/get stuck somewhere, feel free to reach out. Good luck. Craft something helpful!&lt;/p&gt;

&lt;p&gt;Get the full code &lt;a href="https://github.com/sameer1612/ninja-lib" rel="noopener noreferrer"&gt;at this link&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Want to connect?
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/in/sameerkumar1612/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://hi-sameer.vercel.app/" rel="noopener noreferrer"&gt;Website&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>tutorial</category>
      <category>programming</category>
    </item>
    <item>
      <title>Overcoming Vim-Phobia: My journey of redemption</title>
      <dc:creator>Sameer Kumar</dc:creator>
      <pubDate>Fri, 06 Oct 2023 12:10:35 +0000</pubDate>
      <link>https://dev.to/sameer1612/overcoming-vim-phobia-my-journey-of-redemption-2m7d</link>
      <guid>https://dev.to/sameer1612/overcoming-vim-phobia-my-journey-of-redemption-2m7d</guid>
      <description>&lt;p&gt;Hee-haw… Here we go. I have been coding for almost a decade now. And, for anyone who spends two-thirds of his day doing so, his toolchain matters. Let’s go for a walk down the memory lane. This article is going to be different.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Disclaimer: Today’s content is going to be subjective, so, please read with an open mind.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h1&gt;
  
  
  &lt;strong&gt;Sometime Around 2010 — Notepad Grade&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhkzif5ttadsbxiyiygpy.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhkzif5ttadsbxiyiygpy.jpg" alt="Image description" width="460" height="259"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I was dabbling in Notepad++ to learn Java development as a young, clueless potato. At that moment, I didn’t even understand what an editor was. To me, it seemed like a Notepad with extra buttons.&lt;/p&gt;

&lt;p&gt;The focus was on learning programming, not DX (Development Experience). The only intriguing thing was that I could run code using a plugin by pressing one of the function keys. It gave me a big advantage over writing in Notepad and running Windows command prompt.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key points
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  It's good to have a place to write and execute code together.&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  &lt;strong&gt;Two Years Later — Eclipse&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;I could decently code in a couple of languages now. One of the books I was reading recommended the next shiny thing, Eclipse. Eclipse had hit quite the right spot. For the first time, the toolchain was becoming addictive. The joy of coding, building, and running those Java Swing apps without diving into the build and execution system was simply… muahhh.&lt;/p&gt;

&lt;p&gt;Internet was not big, so I often would go through offline docs and figure my way out. It got tedious at times, but there wasn’t another way out. For the first time, I wondered why this software didn’t behave like the previous one. No, I didn’t know the word IDE yet. I only knew that Java runs on three billion devices, and I had to be good at it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key points
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  It’s better if your software can handle the configuration work for you.&lt;/li&gt;
&lt;li&gt;  It’s even better if your software can tell you what to write next.&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  &lt;strong&gt;2014 — Meeting Linux and VI&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu389h1nbymnrmb6fhks3.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu389h1nbymnrmb6fhks3.jpg" alt="Image description" width="460" height="354"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I got this new blue laptop. The sticker says, “Ubuntu.” What the heck is this thing? Where is my DVD with pirated Windows and activation key written on the back of it? Went to the school library, and boy, that book on Unix gave me tremors of joy. I decided to shift to Linux permanently &lt;em&gt;(and I never touched Windows ever since)&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;I couldn’t understand why weirdos on the internet always suggest editing random config files using something called VI. Who on god’s green earth would open a terminal, navigate to a file, and enter into that creepy vi thing from where one can’t even quit?&lt;/p&gt;

&lt;p&gt;Sadly, it was a part of the college curriculum, and I had to write in it. The good thing is that after you press ‘i’, vi becomes “normal.” I hated it so bad that I wrote a gedit config, so my professor thought I was coding in the terminal.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key points
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  Never push for a product/outcome. You may push for an idea and see if people resonate with it.&lt;/li&gt;
&lt;li&gt;  Every developer should use Linux. No exceptions. &lt;em&gt;(Personal take: I also consider macOS a Linux distro.&lt;/em&gt;)&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  2017 — Sublime Art of Coding
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbocrrlax4jxga5ro3ox9.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbocrrlax4jxga5ro3ox9.jpg" alt="Image description" width="608" height="625"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, things were taking shape. I had decided my career path as a web developer. I often built small utility apps. Again, the book I was referring to told me that the Sublime is the next shiny thing. Ahoi! I was on board.&lt;/p&gt;

&lt;p&gt;There is something about it that feels close to my heart. It was JSON configuration, and I spent the whole week tweaking things in the settings file. It was a near-magical experience to copy a JSON file on a USB drive and make my friend’s machine like mine. Lowkey dotfiles, hehehe.&lt;/p&gt;

&lt;p&gt;At that point, my Sublime started to look like a different application to regular Sublime users. To this day, I am a hardcore ricing fan &lt;em&gt;(a fancy term for customizing your software)&lt;/em&gt;. And yes, I am immune to that pop-up asking me to buy Sublime, just like good old Winrar.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key points
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  Sublime was fast for the kind of things it can do.&lt;/li&gt;
&lt;li&gt;  The only reason it “failed” was due to VS Code’s similar pitch, corporate backing, and excellent community support. Developers moved to VS Code, and no one develops tooling around the software they personally don’t use. Vim is nowhere close to Sublime's power (all mighty GUI), but the community stuck to it, and it became awesome over time.&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  2019 — The Rise of VS Code
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fne9i15t70bli6ynsnsrx.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fne9i15t70bli6ynsnsrx.jpg" alt="Image description" width="799" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I felt like I was getting ancient and even started working professionally. Sublime text was like the back of my hand now. Every keybinding and config option lived in my mind. Not to mention the plethora of extensions, well customized for my workflow.&lt;/p&gt;

&lt;p&gt;At that point, losing my Sublime config folder was more of a worry than the laptop itself. Just kidding, I knew git by then. The office was asking to work in VS Code, so again, there were no options. Spent a month tweaking it.&lt;/p&gt;

&lt;p&gt;In the end, I wondered what a Frankenstein’s monster I had made. It looked like Sublime, responded like Sublime married to VS Code, and started heavy like my old friend, Eclipse. The worst part was that the senior guy scolded me every time he tried debugging on my machine. Usual hacker problems, no big deal.&lt;/p&gt;

&lt;p&gt;One thing I love about VS Code is its zero-config extension ecosystem. And it overall felt smart under the hood while coding. I could feel that it had something that Sublime lacked. To this day, VS Code has been my favorite coding software. If something can be coded, it will eventually be in VS Code. I feel it is like the modern version of emacs.&lt;/p&gt;

&lt;p&gt;I felt the difference between strict and dynamically typed language firsthand. I worked on Ruby on Rails those days and dynamically typed languages are a nightmare for any editor. Shoot me, but I hate Ruby, Python, JavaScript, etc., even though I code in them daily for one reason. Maybe for that one reason, I knock on the doors of JetBrains from time to time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key points
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  VS Code had a vision of being an omnipresent editor, and the community made it happen.&lt;/li&gt;
&lt;li&gt;  Its core is rigid and well-thought-out, on top of which people make what they want.&lt;/li&gt;
&lt;li&gt;  Its blessing proves to be its curse. Since anybody can easily write anything, people write them without much thought and later blame VS Code for being slow.&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  2021 — Oops, I Have a Bit of a Perfection Problem
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3kjhxa7gxhz26ek8h34p.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3kjhxa7gxhz26ek8h34p.jpg" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What’s this OCD-looking thing, you ask? It’s a condition where you are a bit too strict about how things should be. You may say, wow, that’s a good thing, but then if your table’s edges don’t match your laptop’s, you get a shiver of anxiety.&lt;/p&gt;

&lt;p&gt;Also, I get distracted fast, so I need a focused environment. I left this article to get the above image, and now I am back after reading about the movie this meme came from. OK, cool, we are on the same page now. See, we aren’t much different after all!&lt;/p&gt;

&lt;p&gt;I like both environments, outside and inside the laptop, to be ultra-mimal. Check out the screenshots at the bottom of this page; there aren’t even close icons on application windows, if possible. From letter spacing in fonts to the inner padding of a popup, everything is a trigger. To be honest, it makes me happy to do this kind of stuff, and if you search for “&lt;a href="https://www.google.com/search?q=unix+ricing&amp;amp;sca_esv=569943774&amp;amp;rlz=1C5CHFA_enIN1027IN1027&amp;amp;tbm=isch&amp;amp;sxsrf=AM9HkKk1ZU8VoN9PJwh8SNsMDjq60CA-Lw%3A1696225086301&amp;amp;sa=X&amp;amp;sqi=2&amp;amp;ved=2ahUKEwj4h-Lt0taBAxXYTWwGHYNRAuoQ_AUoAnoECAMQBA&amp;amp;biw=1728&amp;amp;bih=949&amp;amp;dpr=2" rel="noopener noreferrer"&gt;Unix ricing&lt;/a&gt;,” you’ll get blown away.&lt;/p&gt;

&lt;p&gt;On the other hand, literally on the other hand, I started getting wrist pain due to constant jumping from letters and arrows. Grinding 80 hours a week comes with its own perks. 😅&lt;/p&gt;

&lt;p&gt;I was googling about this wrist pain condition, and funnily enough, one of the tips was to use Vim (-mode) on your computer. That sneaky VI, I couldn’t even understand was the same thing until I opened it. I had some residual hate towards it.&lt;/p&gt;

&lt;p&gt;For server work, I was using Nano. Later, I moved to micro, which was closer to VS Code bindings. Every stunt it takes to avoid my arch nemesis, Vi. I realised that literally every tool I use has that weird Sublime and VS Code hybrid keybindings.&lt;/p&gt;

&lt;p&gt;Gosh! I hate myself. Can’t even use another person’s computer running a pure version of that software. To support the no terminal mindset, over the years, I forgot all my appreciation for awk, sed, grep, etc. Things needed to change; I couldn’t live in this denial.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key points
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  Do what you enjoy and not necessarily what keeps you abstracted from the real problems.&lt;/li&gt;
&lt;li&gt;  Everybody spends time in denial. It's normal as long as you are ready to come out of it after realization.&lt;/li&gt;
&lt;li&gt;  Learn core (gnu-) Linux tools. You’ll understand the benefits in the long term. For example, I’d have been much better at regex if I had just continued using grep and sed for finding and replacing.&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  &lt;strong&gt;2022 — Adopting Vim Motions&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;For the first month, I used nothing more than hjkl. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Filmhmq6854mqanjsgg9a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Filmhmq6854mqanjsgg9a.png" alt="Image description" width="680" height="324"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I resolved to use Vim. Not because it’s any better for my specific workflow but because I wanted to break my dependency on VS Code.&lt;/p&gt;

&lt;p&gt;I knew I couldn’t drop into Vim for my day job. So, I settled on the middle ground of using Vim bindings in VS Code. Courtesy to a YouTuber called Ben Awad, who showed this peaceful path of adopting Vim. I always wondered how he could magically teleport to random places when I could only move there really fast.&lt;/p&gt;

&lt;p&gt;On the safe side, I’d automatically turn it off in all my office project folders. Nothing in Vim particularly amazed me then because I had a similar shortcut in mind for VS Code. Yet, the constant tussle between both was getting hard. By the end of the year, I could fluently navigate in VS Code using Vim keybindings. After almost a year of usage, I started seeing the ergonomic and functional benefits*&lt;em&gt;.&lt;/em&gt;*&lt;/p&gt;

&lt;h2&gt;
  
  
  Key points
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  Be practical, you son of a gun. Learn to walk before you run.&lt;/li&gt;
&lt;li&gt;  Temptations to achieve what others flash is a good motivation. Personal willpower won’t be enough to explore unchartered territories. We need some rocket fuel to kickstart the process.&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  2023 — The Final Migration
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffxpv1k0mk4hnlm8018j1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffxpv1k0mk4hnlm8018j1.jpg" alt="Image description" width="758" height="748"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It was darn stupid of me to think that one day I’d uninstall VS Code and move to Vim someday because I could navigate there similarly. I didn’t realize I was using Vim bindings for doing VS Code things; the workflow part was still a miss. All that I learned was a few keyboard shortcuts.&lt;/p&gt;

&lt;p&gt;I moved anyway. One day I had to find and replace a few words in a project. I couldn’t do it, so welcome back home. VS Code, at this point, had become my identity. I could fly through code blazingly fast in VS Code, and my friends knew me for that. So I settled back in, leaving Vim.&lt;/p&gt;

&lt;p&gt;I was happy I could do whatever those Vim nerds could do, yet I knew I was still in a big comfort zone bias. My problem was that I was using VS Code with a hybrid keybinding, and now I replaced even that with something else. What kind of a solution was that?&lt;/p&gt;

&lt;p&gt;Luckily, I got a break from office project work sometime back, and I knew this was the chance to transition my configs. I realized I had no trouble in moving from Sublime to VS Code; it was a happy process. I started working in raw Neovim, and yeah, it was painful, but I had a plan. Whenever I missed something, I would “read Neovim docs” and add it.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Makes me happy I understand and have written every single line of my editor config myself. Took two months but now I have my own sweet little PDE (Personal Development Environment).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This covered everything from default indentation size to a file tree to language servers. Earlier, I watched a YouTube video from ThePrimeagen on Neovim setup, and it overwhelmed me so badly that I had to take a week’s break from thinking about my own configuration. 😂&lt;/p&gt;

&lt;h2&gt;
  
  
  Key points
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  Acknowledge the iceberg theory. One gets attracted to what floats and not the work it will take to create and understand the base. My suggestion, if you ask, is simple. Respect it!&lt;/li&gt;
&lt;li&gt;  My biggest motivation for making the final switch was the aww factor surrounding Vim as a software. All you see in the screenshots below is text on a terminal window, no images, no real buttons, and no GUI of any kind. They aren’t even real icons. It’s really hard. Imagine you can’t even change the fonts or the size of it. Every single thing is carefully manipulating text on a black terminal window. That respect for the people who build it keeps me going.&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  &lt;strong&gt;Today&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;Now that I have fully moved my workflow to Neovim, it doesn’t even feel any different. I was already used to Vim bindings, only the aesthetics have changed. Yet the good part is I understand how these moving pieces work. I understand how that in-line error message shows, from where these fancy auto-completions come, how each line gets formatted, and much more. Looking back, I could have peeped into the source code of VS Code or its extensions, but the mindset was to use it and not learn it.&lt;/p&gt;

&lt;p&gt;The biggest shift is that I look at software in general from the mentality of the builder rather than a consumer. Now, when I see something, I ponder how to build it rather than use it.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;After all, I am an engineer and my identity revolves around two main things: how well I understand softwares and what I (can) build&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h1&gt;
  
  
  Some Snaps of My Coding Setup
&lt;/h1&gt;

&lt;p&gt;Terminal using iterm2&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fronljdc9q1azramkocfj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fronljdc9q1azramkocfj.png" alt="Image description" width="800" height="541"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Neovim landing page&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F14s95natw4h4awfgniki.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F14s95natw4h4awfgniki.png" alt="Image description" width="800" height="498"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;AI code suggestions&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5qi6f6cl6o82euaosq57.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5qi6f6cl6o82euaosq57.png" alt="Image description" width="800" height="569"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Language-based completions and documentation&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqse22xzsh5w326hbkj8k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqse22xzsh5w326hbkj8k.png" alt="Image description" width="800" height="539"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Fuzzy file and content exploration&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe1g7gthfaarb7ae7in4l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe1g7gthfaarb7ae7in4l.png" alt="Image description" width="800" height="615"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Change tracking (can rollback to things changed days ago, no git needed)&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdcv39dl7rgh3zy8drjbn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdcv39dl7rgh3zy8drjbn.png" alt="Image description" width="800" height="615"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Unfortunately, I can’t go through every screen and utility, but if you like the setup, I can write an article on how everything is set up from scratch. A detailed tutorial of sorts on the basics of terminal and Vim customization. Do drop a comment if you’d like me to.&lt;/p&gt;




&lt;h1&gt;
  
  
  FAQs
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt; Will using Vim make me a better developer?
— Yes, I take the guarantee.&lt;/li&gt;
&lt;li&gt; How hard is the transition?
— It’s pretty easy. Just a few hundred keybindings, lol. (I have a super secret ninja way to learn them all in 30 minutes)&lt;/li&gt;
&lt;li&gt; Why does it even matter? It’s just an editor. My work goes with what I write in it.
— You want to be an engineer or a writer. Figure out fast! Good that you chose engineer. Now think again: how many fundamentals of engineering do you get exposed to that your day job abstracts from you. You don’t want to be an engineer with a weak core, do you?&lt;/li&gt;
&lt;li&gt; It seems too hard to get started. Will I grab it?
— Took two years, multiple quits, and it only worked when I started from scratch and incrementally added functionality. It’s your child now. You won’t say anything bad about it. Remember that you don’t choose your interests; you raise interest in things you put effort into.&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3t7svdkqaxvp0203betb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3t7svdkqaxvp0203betb.png" alt="Image description" width="640" height="503"&gt;&lt;/a&gt;&lt;br&gt;
True Story…&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Want to Connect?&lt;/strong&gt;  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/in/sameerkumar1612" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://hi-sameer.vercel.app" rel="noopener noreferrer"&gt;Website&lt;/a&gt;&lt;/p&gt;

</description>
      <category>vim</category>
      <category>neovim</category>
      <category>programming</category>
      <category>productivity</category>
    </item>
    <item>
      <title>JetBrains Fleet — A VS Code killer?</title>
      <dc:creator>Sameer Kumar</dc:creator>
      <pubDate>Wed, 19 Oct 2022 07:41:15 +0000</pubDate>
      <link>https://dev.to/sameer1612/jetbrains-fleet-a-vs-code-killer-2odb</link>
      <guid>https://dev.to/sameer1612/jetbrains-fleet-a-vs-code-killer-2odb</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;An excellent lightweight polyglot IDE from JetBrains.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;JetBrains is pure love. It doesn’t matter which code editor you use but a few things are always of personal priority. For me, it’s aesthetics, speed, and intelligent suggestions. Extra point for aesthetics 💛.&lt;/p&gt;

&lt;p&gt;I used to be a long-time Sublime Text fan. Then it faded into oblivion and I packed my bags and moved to VS code which has the above three in ascending order. Still, nothing beats my experience with JetBrains IDEs, especially RubyMine while I was working on ruby on rails development. The only thing that taints these gorgeous IDEs is the speed, primarily the time to get interactive.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;JetBrains’ answer to most of its problems is &lt;strong&gt;Fleet&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Fleet is targeted to be more of an intelligent editor than a full-blown IDE. And I consider this a good thing because most of the time we don’t want all those nuclear features packed inside the IDE to manipulate a few lines of code and get decent IntelliSense. When I installed fleet for the first time, I was a bit skeptical because I thought I’ll be losing all the good parts of IDE but after using it for a couple of days, I can say that all that power is not needed in day-to-day uses.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;Things I liked in fleet ❤️&lt;/strong&gt;
&lt;/h1&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Aesthetics&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7bjd1gbsrarwg72np3e1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7bjd1gbsrarwg72np3e1.png" alt="Image description" width="800" height="547"&gt;&lt;/a&gt;&lt;br&gt;
JetBrains fleet editor&lt;/p&gt;

&lt;p&gt;If you ask me one thing I don’t like about VS code, it will be the look and feel. It's no surprise that VS code can be customized to the very extremes using the plethora of extensions but still, it feels very plasticky to me. Earlier I thought it was just me, but when I asked a couple of my friends who are longtime users of JetBrains, they also seconded that JetBrains IDEs offer a more sturdy look and feel.&lt;/p&gt;

&lt;p&gt;Fleet takes the old IDE inspiration and conveys it in a modern design language. The new design is extremely fluent and distraction-free. The application itself is divided into four panes.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; The first pane is on the left side and is divided into three tabs featuring a &lt;strong&gt;file explorer, version control, and commit history&lt;/strong&gt;. Upon selecting the pane each of these three subsections can be easily navigated using keyboard shortcuts. The presentation and navigation felt buttery smooth and they just work.&lt;/li&gt;
&lt;li&gt; The second pane is at the bottom and can host different views, including terminal, run logs, docker, etc. which can be selected from the drop-down presented there. It’s totally up to us what we want to see, maybe in the future, there will be custom views as well.&lt;/li&gt;
&lt;li&gt; The third pane is on the right side and can contain the same views as the second one. It can be used as a secondary panel, but in most cases, I think I’m better without it still, it’s nice to have when screen real estate is not a limitation.&lt;/li&gt;
&lt;li&gt; Apart from these, the main editor area itself is quite a distraction-free, accessible, and clean-looking view. Looking at the customization side of things we can change the theme, font, and other common attributes. The application theme ties itself to the system theme pretty well and the defaults are well-designed.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;KeyMaps&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmlb1m43qqaqflygwm9j5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmlb1m43qqaqflygwm9j5.png" alt="Image description" width="225" height="225"&gt;&lt;/a&gt;&lt;br&gt;
Fleet keymaps&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Thou shall leave your editor but not thy keymaps”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Coming from a different editor, the biggest challenge is getting your muscle memory of keyboard shortcuts transferred but here almost half of the keyboard shortcuts were already aligning with VS Code, and it took me around 15 minutes to map other shortcuts as per my liking.&lt;/p&gt;

&lt;p&gt;Being a keyboard-driven power user I find a lot of things missing from IDEs as well as VS Code. The very first thing I noticed was not being able to move to a tab by using command plus number keys but again we are just looking at the preview version and these things will be integrated when it comes to the real release or a plugin will tackle it.&lt;/p&gt;

&lt;p&gt;Overall keyboard navigation was very responsive including the find files and actions part, even in a large-scale project containing thousands of files. But, then it's JetBrains, their whole core is dedicated to fueling enterprise codebases.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffd8jmz4juvhfytrim93s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffd8jmz4juvhfytrim93s.png" alt="Image description" width="800" height="566"&gt;&lt;/a&gt;&lt;br&gt;
Fleet palette view.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;DX ( Development Experience )&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy4cny21p888fobqsnhak.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy4cny21p888fobqsnhak.png" alt="Image description" width="800" height="600"&gt;&lt;/a&gt;&lt;br&gt;
DX = Happy Developer&lt;/p&gt;

&lt;p&gt;It can look and feel good, but at the same time, it can be a waste without solid development experience. Thankfully, it’s going on the right track here. It’s not the time to evaluate the finished product as it’s not finished yet, but we can get a clear direction in which things are going to move.&lt;/p&gt;

&lt;p&gt;The editor managed to be a super fast experience by turning off IntelliSense by default, but it can be enabled with a simple click on the bolt in the top right.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F566db0r9rxknedvm7o1a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F566db0r9rxknedvm7o1a.png" alt="Image description" width="360" height="150"&gt;&lt;/a&gt;&lt;br&gt;
The smart mode in the fleet editor.&lt;/p&gt;

&lt;p&gt;It starts as nothing but a notepad, and on clicking the smart mode toggle it pulls in enough power to provide you with some good-quality intelligence for mid-weight development. We can do all those familiar things like jumping to the declaration, finding usage, global find using regex, etc. The visual presentation of content and mapping of controls is welcoming to both JetBrains and VS Code users.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjkogp109s2l1jr4sfdnx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjkogp109s2l1jr4sfdnx.png" alt="Image description" width="800" height="701"&gt;&lt;/a&gt;&lt;br&gt;
Cloud-enabled features in JetBrains fleet.&lt;/p&gt;

&lt;p&gt;A more worthy feature in the fleet is its remote backend. Use the power of virtual machines in the cloud to build your app and run Fleet along with the IntelliJ code-processing engine. It solves the “&lt;em&gt;IntelliJ is too heavy to run on my tiny machine&lt;/em&gt;” problem by pulling all the fancy stuff in the cloud and you have only the code local while keeping bulky intelligence features in the cloud.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fss19kan8vaklxprnpbt0.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fss19kan8vaklxprnpbt0.jpg" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;br&gt;
Pros and &lt;strong&gt;Cons&lt;/strong&gt; of JetBrains fleet editor.&lt;/p&gt;

&lt;p&gt;Let’s take a break from our walk in the garden and be slapped in the face with a brick called reality. Although it is still in preview and the vision is not solidified yet but few things are crystal clear. I am listing two things below which in my humble opinion may not work in favor of the fleet vision.&lt;/p&gt;

&lt;h1&gt;
  
  
  Things that scare 😱
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Not a Free and Open Source Software ( FOSS )
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F10h94dl192fiuiefbdr5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F10h94dl192fiuiefbdr5.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;br&gt;
Open source software.&lt;/p&gt;

&lt;p&gt;It's not a surprise that JetBrains will keep the code closed as it did with all other products it built so far. But, the fleet is not on the same lines as creating highly specialized enterprise-grade software that sets benchmarks in the industry.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0siouizlyk0cjxkvnuz9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0siouizlyk0cjxkvnuz9.png" alt="Image description" width="600" height="570"&gt;&lt;/a&gt;&lt;br&gt;
Fleet extensions framework.&lt;/p&gt;

&lt;p&gt;Jetbrains themselves can not make the Fleet a polyglot system and it will be in the product’s best interest to offload the work to the community which specializes in a particular language and framework. As of now, there is no extensions framework but it's in the pipeline before the final release.&lt;/p&gt;

&lt;p&gt;But, even when it lands, a small dev community sitting behind a paywall can not make a rich ecosystem like vscode. We have seen other IDE products from JetBrains and the range of extensions is very low.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F46fjgpc7fgz6swoa4nvm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F46fjgpc7fgz6swoa4nvm.png" alt="Image description" width="464" height="164"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I don’t sing of charity here but if the competitor is offering everything for free, the motivation to switch gets automatically low.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Not as lightweight as it says on the label
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv9odoelyz6ywo6lmiep6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv9odoelyz6ywo6lmiep6.png" alt="Image description" width="800" height="716"&gt;&lt;/a&gt;&lt;br&gt;
JetBrains Fleet resource consumption.&lt;/p&gt;

&lt;p&gt;JetBrains environment running this fast is never heard of. I was pleasantly surprised when I stressed it with big codebases and everything worked with the same fluency. Then I looked into the system resource consumption and it wasn't much to be proud of. Have a look yourself.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkawz8va64swtsfnk962m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkawz8va64swtsfnk962m.png" alt="Image description" width="800" height="524"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frhx3o6eko1kyf4xjwkb3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frhx3o6eko1kyf4xjwkb3.png" alt="Image description" width="800" height="524"&gt;&lt;/a&gt;&lt;br&gt;
JetBrains Fleet vs VS Code performance benchmarks.&lt;/p&gt;

&lt;p&gt;For context, I have the same mid-size angular application running in both editors with just two files open and the server running in the integrated terminal.&lt;/p&gt;

&lt;p&gt;As promised Fleet and its backend are running separately. But, the memory consumption is too high for it. To add to it I have at least 30 extensions added in the VS Code and the Fleet is fresh out of the box.&lt;/p&gt;

&lt;p&gt;I have a beefy MacBook M1 Pro with higher specs than an average user. So, I can not justify that someone on a weaker machine will get the same speedy performance despite such resource usage.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Now that we have seen both sides with equal enthusiasm, it will be good to summarise this review with a non-opinionated summary. I must say, the fleet is what I was wanting for years but for others, it might be yet another shiny object. JetBrains has an IDE for almost every language and Fleet is an attempt to move in the polyglot direction. Since both of these are targetting different communities, it’s tempting to put them in the category of android vs apple comparison. On one side you are getting something extremely versatile and flexible but on the other side, you get a very refined and polished product best suited for the existing ecosystem users.&lt;/p&gt;

&lt;h2&gt;
  
  
  🤝 Want To Connect?
&lt;/h2&gt;

&lt;p&gt;LinkedIn: &lt;a href="https://www.linkedin.com/in/sameerkumar1612/" rel="noopener noreferrer"&gt;https://www.linkedin.com/in/sameerkumar1612&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>webdev</category>
      <category>productivity</category>
    </item>
    <item>
      <title>5 must have softwares for pros like you.</title>
      <dc:creator>Sameer Kumar</dc:creator>
      <pubDate>Fri, 07 Oct 2022 09:37:13 +0000</pubDate>
      <link>https://dev.to/sameer1612/5-must-have-softwares-for-pros-like-you-2pn</link>
      <guid>https://dev.to/sameer1612/5-must-have-softwares-for-pros-like-you-2pn</guid>
      <description>&lt;p&gt;I have been using Linux for many years and am amazed that there is a tool for every use case. The same goes for MacBook as well, there is a plethora of free tools that will make you more productive and at the same save a lot of frustration coming out of repetitive manual work.&lt;/p&gt;

&lt;h1&gt;
  
  
  Meeter
&lt;/h1&gt;

&lt;h2&gt;
  
  
  [Meeter
&lt;/h2&gt;

&lt;h3&gt;
  
  
  We will get out of your way, so you can get done what needs to be done. Our simple and minimalist macOS app allows you…
&lt;/h3&gt;

&lt;p&gt;&lt;a href="http://www.trymeeter.com" rel="noopener noreferrer"&gt;www.trymeeter.com&lt;/a&gt;&lt;br&gt;
](&lt;a href="https://www.trymeeter.com/" rel="noopener noreferrer"&gt;https://www.trymeeter.com/&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Meeter is a tool which sits in your top bar and sends you a quick join popup when a meeting starts. It works with almost all meeting solutions, including google meet, Microsoft teams, cisco webex, etc. I can not simply live without it. I came to know about this one out of very particular frustration about google meet.&lt;/p&gt;

&lt;p&gt;And, here it goes, like every sane user I had more than 5 google accounts logged in my browser, and whenever I used to click a meeting link, it would join by the default account, and then the chain of frustration starts. Meeter tracks your on-device calendar and ensures that when you click the join button, you are joined through the intended account.&lt;/p&gt;

&lt;p&gt;No more missing the call, because it keeps running a countdown timer in your top bar. Optionally it can also display the meeting title as well.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--evvMlemM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/916/1%2Az0BicF_GTzD91M47FqDhvQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--evvMlemM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/916/1%2Az0BicF_GTzD91M47FqDhvQ.png" width="458" height="74"&gt;&lt;/a&gt;Countdown to the next meeting in the top bar.&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SyvTI5lu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/1400/1%2AUgOt5JOJYcgfCDRvjNGzEg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SyvTI5lu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/1400/1%2AUgOt5JOJYcgfCDRvjNGzEg.png" alt="Meeter — https://www.trymeeter.com/" width="800" height="291"&gt;&lt;/a&gt;Meeter — &lt;a href="https://www.trymeeter.com/" rel="noopener noreferrer"&gt;https://www.trymeeter.com/&lt;/a&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  Bandwidth+
&lt;/h1&gt;

&lt;h2&gt;
  
  
  [‎Bandwidth+
&lt;/h2&gt;

&lt;h3&gt;
  
  
  ‎* Track your Wi-Fi hotspot usage. * Zero configuration required. It just works. Bandwidth+ is a simple app so only…
&lt;/h3&gt;

&lt;p&gt;](&lt;a href="https://apps.apple.com/us/app/bandwidth/id490461369" rel="noopener noreferrer"&gt;https://apps.apple.com/us/app/bandwidth/id490461369&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Working from home on a limited internet connection is a big challenge and I had to track the speed and usage constantly. This small tool comes as a full package solution for such use cases.&lt;/p&gt;

&lt;p&gt;Even if you are on the better side, at least it can help you decide when call quality goes down, then whom to blame. 🎃&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iNGR9eA3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/1400/1%2AgfesFjugUQD8C-qfbugegA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iNGR9eA3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/1400/1%2AgfesFjugUQD8C-qfbugegA.png" alt="Bandwidth+ — https://apps.apple.com/us/app/bandwidth/id490461369" width="800" height="500"&gt;&lt;/a&gt;Bandwidth+ — &lt;a href="https://apps.apple.com/us/app/bandwidth/id490461369" rel="noopener noreferrer"&gt;https://apps.apple.com/us/app/bandwidth/id490461369&lt;/a&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  Fig
&lt;/h1&gt;

&lt;h2&gt;
  
  
  [Fig
&lt;/h2&gt;

&lt;h3&gt;
  
  
  The terminal is a sensitive environment. All cloud features are opt-in and your data is encrypted at rest. For…
&lt;/h3&gt;

&lt;p&gt;](&lt;a href="https://fig.io/" rel="noopener noreferrer"&gt;https://fig.io/&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;As an engineer, I can not live without a terminal, or rather say most of the time I live in the terminal. Fig comes in handy by suggesting the next commands very intelligently and aesthetically in form of a dropdown.&lt;/p&gt;

&lt;p&gt;These commands are context-aware and for most parts cover all daily use cases. To some extent, it serves as live documentation in the terminal.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VZ7ROPs4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/1400/1%2ACnqw46EoBsvOY4itbgcNcw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VZ7ROPs4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/1400/1%2ACnqw46EoBsvOY4itbgcNcw.png" alt="Fig — https://fig.io/" width="800" height="619"&gt;&lt;/a&gt;Fig — &lt;a href="https://fig.io/" rel="noopener noreferrer"&gt;https://fig.io/&lt;/a&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  Photopea
&lt;/h1&gt;

&lt;h2&gt;
  
  
  [Photopea | Online Photo Editor
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Free online photo editor supporting PSD, XCF, Sketch, XD and CDR formats. ( Adobe Photoshop, GIMP, Sketch App, Adobe XD…
&lt;/h3&gt;

&lt;p&gt;](&lt;a href="https://www.photopea.com/" rel="noopener noreferrer"&gt;https://www.photopea.com/&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Now and then, there comes a need to make a quick header for my blog or trim 2px from the logo I am supposed to put on a website. Since I am not a creative designer or photographer by profession, it doesn't make sense to use a full-blown Adobe product.&lt;/p&gt;

&lt;p&gt;For the long period that I used this free product, I never felt the need to get photoshop installed. It will cater to all typical use cases of photoshop in a familiar layout without costing a penny. I encourage donating if you can to the good cause of bringing such a good photoshop alternative online.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--stATjwLC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/1400/1%2A7zy8y2h-mluIJDAxaYNN8g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--stATjwLC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/1400/1%2A7zy8y2h-mluIJDAxaYNN8g.png" alt="Best mac softwares." width="800" height="533"&gt;&lt;/a&gt;Photopea — &lt;a href="https://www.photopea.com/" rel="noopener noreferrer"&gt;https://www.photopea.com/&lt;/a&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  Top Notch
&lt;/h1&gt;

&lt;h2&gt;
  
  
  [TopNotch for macOS
&lt;/h2&gt;

&lt;h3&gt;
  
  
  TopNotch is a little macOS app that makes your menu bar black and hides the notch.
&lt;/h3&gt;

&lt;p&gt;](&lt;a href="https://topnotch.app/" rel="noopener noreferrer"&gt;https://topnotch.app/&lt;/a&gt;)&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Makes the notch disappear like a 🥷.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Macbook M1 Pro brought a good camera system but in turn gave me the biggest OCD ever, THE NOTCH. It started getting quite distracting and then I found this application that smartly hides your notch and gives realistic-looking rounded corners as well.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PjOLkIxD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/1400/1%2A97KTTrL7yb6WeoVQ15j5Lg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PjOLkIxD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/1400/1%2A97KTTrL7yb6WeoVQ15j5Lg.png" width="800" height="263"&gt;&lt;/a&gt;TopNotch — &lt;a href="https://topnotch.app/" rel="noopener noreferrer"&gt;https://topnotch.app/&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Want To Connect?&lt;/strong&gt;&lt;br&gt;
LinkedIn: &lt;a href="https://www.linkedin.com/in/sameerkumar1612/" rel="noopener noreferrer"&gt;https://www.linkedin.com/in/sameerkumar1612&lt;/a&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>productivity</category>
      <category>tooling</category>
    </item>
    <item>
      <title>React 18: When to use “useImperativeHandle” and “forwardRefs”</title>
      <dc:creator>Sameer Kumar</dc:creator>
      <pubDate>Tue, 13 Sep 2022 11:54:11 +0000</pubDate>
      <link>https://dev.to/sameer1612/when-to-use-useimperativehandle-and-forwardrefs-in-react-18-3l1b</link>
      <guid>https://dev.to/sameer1612/when-to-use-useimperativehandle-and-forwardrefs-in-react-18-3l1b</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Sometimes, you have to take out the big guns&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This article is a continuation of &lt;a href="https://medium.com/react-v18-demystifying-useref-forwardref-and-useimperativehandle-feec2fc5b2f6" rel="noopener noreferrer"&gt;https://betterprogramming.pub/react-v18-demystifying-useref-forwardref-and-useimperativehandle-feec2fc5b2f6&lt;/a&gt; where we saw what refs are and how they operate. With the knowledge gained from the previous article, let’s dive into a little more complex understanding, which can come in handy in real-world projects with a lot of component nesting and a bit of real DOM-based needs.&lt;/p&gt;

&lt;h1&gt;
  
  
  Forward Ref
&lt;/h1&gt;

&lt;p&gt;What’s a solution without a problem, right? So, let’s define a situation where regular refs can not get the job done. What if we have a parent component that wants a reference to one of the elements defined in the child component and modifies the focus state? Let’s create such an example.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JNun25rD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/3954/1%2AeLWlolRaMn11RnnBbH642g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JNun25rD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/3954/1%2AeLWlolRaMn11RnnBbH642g.png" width="800" height="545"&gt;&lt;/a&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zg3vE9mf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/3920/1%2A_4mb7gSEAbJLPfX_mdTvhQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zg3vE9mf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/3920/1%2A_4mb7gSEAbJLPfX_mdTvhQ.png" width="800" height="495"&gt;&lt;/a&gt;The parent component controls the focus of the button defined in the child component.&lt;/p&gt;

&lt;p&gt;As you can see above, the parent component controls the focus on the child component’s button. It is not as simple as passing the ref defined in the parent as a prop to the child. In our case, ref is a special property defined on the exact HTML element whose focus is to be changed, not the child component wrapper, as it’s just a function.&lt;/p&gt;

&lt;p&gt;We can attain the desired behaviour by wrapping our child component into a &lt;code&gt;forwardRef&lt;/code&gt; function provided by React, which will handle this delegation. This function should transfer the sent props and allows one extra prop on the component, that being our “ref.” Here’s the code:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h1&gt;
  
  
  useImperativeHandle
&lt;/h1&gt;

&lt;p&gt;Well, seemingly, what we achieved in the previous section is enough for even complex situations. Still, at times you may be tempted to define a custom ref functionality inside your component, which will be exposed to components using it. Let’s try to create a situation where we need such fine-grained control.&lt;/p&gt;

&lt;p&gt;By default, the focus colour on input is &lt;code&gt;blue&lt;/code&gt; but let’s say if our ninja is supposed to get a supercritical jonin level mission, then the input field should focus on &lt;code&gt;red&lt;/code&gt; instead.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--o9mgBcq8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/6468/1%2AT0uOssF90_YeOKgDjfJrBg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--o9mgBcq8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/6468/1%2AT0uOssF90_YeOKgDjfJrBg.png" width="800" height="570"&gt;&lt;/a&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ts9X_gEG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/6468/1%2AtMJLmQI44rvjHPCo89Vwvg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ts9X_gEG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/6468/1%2AtMJLmQI44rvjHPCo89Vwvg.png" width="800" height="570"&gt;&lt;/a&gt;The parent component can control which colour the child’s input focuses on.&lt;/p&gt;

&lt;p&gt;To illustrate the use of &lt;code&gt;useImperativeHandle&lt;/code&gt; in this case, let’s divert from common sense and build two custom methods tied to the input component through ref. Instead of the default focus method, this time, we’ll have two custom methods &lt;code&gt;focusRed()&lt;/code&gt; and &lt;code&gt;focusBlue()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We’ll still need to use &lt;code&gt;forwardRef&lt;/code&gt; to pass on the ref to the child component, but inside the child component, we’ll create these new functions with the help of the &lt;code&gt;useImperativeHandle&lt;/code&gt; hook. Here’s what the code looks like:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;blockquote&gt;
&lt;p&gt;One important thing to notice is that in the code above we are not extending the methods available by default as in previous case but creating totally a new set of methods. So, the &lt;code&gt;_default focus()_&lt;/code&gt; method is no more available to us and calling it will give us sweet errors.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IMuy6J3l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/1400/1%2A91DtTO0n1C-kP-Jyh4ERhA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IMuy6J3l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/1400/1%2A91DtTO0n1C-kP-Jyh4ERhA.png" width="800" height="187"&gt;&lt;/a&gt;The focus method is not available when using the imperative handle.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;To sum up, I’ll repeat what I said in the previous article: Refs to DOM themselves should not be used when doing a virtual dom-based development because the changes you make in the real DOM don’t get properly transferred to the vDOM setup, and that leads to unexpected reactivity.&lt;/p&gt;

&lt;p&gt;I chose &lt;code&gt;focus&lt;/code&gt; as the central topic for this article just because it’s one of the main needs when refs need to be summoned. React mentions a limited set of use cases for refs, which you can see here: &lt;a href="https://reactjs.org/docs/refs-and-the-dom.html#when-to-use-refs" rel="noopener noreferrer"&gt;https://reactjs.org/docs/refs-and-the-dom.html#when-to-use-refs&lt;/a&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Want To Connect?
&lt;/h2&gt;

&lt;p&gt;LinkedIn: &lt;a href="https://www.linkedin.com/in/sameerkumar1612/" rel="noopener noreferrer"&gt;https://www.linkedin.com/in/sameerkumar1612&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>react</category>
      <category>programming</category>
    </item>
    <item>
      <title>React v18: useRef — What, When and Why?</title>
      <dc:creator>Sameer Kumar</dc:creator>
      <pubDate>Fri, 22 Jul 2022 12:05:34 +0000</pubDate>
      <link>https://dev.to/sameer1612/react-v18-useref-what-when-and-why-m0l</link>
      <guid>https://dev.to/sameer1612/react-v18-useref-what-when-and-why-m0l</guid>
      <description>&lt;h2&gt;
  
  
  Part 1: Taming React’s necessary evil — &lt;strong&gt;useRef&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The concept of values and references is not new to any programmer. Values are what the name suggests, simple snapshots of data at a point in time. To jog your memory for the latter, references are pointers to some data which may change over time, but the reference itself remains the same. Think of it as a house’s address; the address always remains the same, although the house may renovate to a new one over time.&lt;/p&gt;

&lt;p&gt;React highly recommends thinking in terms of UI = function(state). This simplification can handle maybe 99% of what we were used to doing with the traditional DOM-based paradigm, but the final 1% needed some plumbing.&lt;/p&gt;

&lt;p&gt;The React team left an escape hatch for such situations in the form of the refs. IMHO, refs are a necessary evil that helps us take the liberty of solving problems for which React itself can’t provide solutions due to its data-driven design philosophy.&lt;/p&gt;

&lt;p&gt;Since refs can get pretty complex to understand. We’ll cover three areas mentioned in the title separately. For part 1, we’ll understand what React references are and how to use the most fundamental useRef hook. In the upcoming part, we’ll cover more complex examples and use cases.&lt;/p&gt;




&lt;h2&gt;
  
  
  useRef
&lt;/h2&gt;

&lt;p&gt;==========&lt;/p&gt;

&lt;p&gt;Starting with the most basic implementation using the &lt;code&gt;useRef&lt;/code&gt; hook provided by React. Let’s think of a situation that doesn’t need fancy DOM latches but a simple number to reference outside React’s state system. Our application is going to be a super simple counter app.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F1400%2F1%2AtuuGb7QC2TVEXNwe4tDEHw.png" alt="Component re-renders when updating the data contained in the React state."&gt;

&lt;blockquote&gt;
&lt;p&gt;Component re-renders when updating the data contained in the React state.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It’s no rocket science to infer from the console logs that our component is rendering again for every change in the num value, which may be a nightmare come true in a complex production application.&lt;/p&gt;




&lt;p&gt;Let’s try bringing in the ref to the picture and see how it performs. We will bring a number here which should not change between re-renders, and also, it should not cause a rerender if its value changes.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F1400%2F1%2AA5o_zRUjKGA94SuvuXkTmQ.png" alt="React refs persist data across component rerenders and don’t cause rerenders when updated."&gt;

&lt;blockquote&gt;
&lt;p&gt;React refs persist data across component re-renders and don’t cause re-renders when updated.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As we can see from this example, our application can retain the random value stored in the ref variable even if the component is rerendering due to clicks on the increment button. The key takeaway from this experiment is that the referenced value is independent of the component lifecycle here.&lt;/p&gt;




&lt;p&gt;Let’s go for a more practical example where you will see refs being used in real applications. In this case, we have an HTML input element, for which we want to see if it’s blank. If yes, then we put some random value there.&lt;/p&gt;

&lt;p&gt;React believes in the unidirectional controlled component strategy, which says inputs should be tied to some state, and what we see in the input should only be generated through a change in the linked state. In our case, we will not have any state linked to it. We also don’t want to go ballistic by putting an &lt;code&gt;id&lt;/code&gt; and starting with a &lt;code&gt;document.getElementById&lt;/code&gt; like the old school way.&lt;/p&gt;

&lt;p&gt;What we can do is use a ref as a pointer to this DOM element and control its value from within React. Let’s take a look at the following code:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F1400%2F1%2A4jtCtuKToWhBA4jspdu-ug.png" alt="Refs help us to hook to any DOM element on page and interact with them outside react’s official way."&gt;

&lt;blockquote&gt;
&lt;p&gt;Refs help us to control any DOM element on the page and interact with it outside the React way.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;From the above demo, we can see that the input is populated the first time itself, and that too without accessing the real DOM API directly. Our &lt;code&gt;inputRef&lt;/code&gt; is serving as a pointer to the input DOM element, using which we can manage its properties directly, bypassing the React’s state system.&lt;/p&gt;




&lt;p&gt;Managing form using refs is often discouraged as it kills the whole reason behind using a state-driven library like React.&lt;/p&gt;

&lt;p&gt;Let’s look at something which is more suiting for the use of React refs. Imagine we loaded a form, and we want to automatically move focus to an input field for achieving UX brownie points. We can take the above application, for example, and use refs to focus the input field on load. This can be a welcoming feature that forms loads, and you know what to begin with. In the golden era, this could also open your mobile keyboard, but it is now blocked due to security and user preferences.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F1400%2F1%2AedJOV8FJjC9zS34N3rEuBg.png" alt="Focus input field using react refs."&gt;

&lt;blockquote&gt;
&lt;p&gt;Focus input field using React refs.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  The Dark Side
&lt;/h2&gt;

&lt;p&gt;=============&lt;/p&gt;

&lt;p&gt;If something this powerful is presented to programmers, how could they not abuse it? But, just because we have a ton of parachutes, it doesn't mean every day is a skydiving day. Refs are meant to be used in cases that need direct dom, such as our above example. The first counterexample is also something that can be handled with caching using the &lt;code&gt;useMemo&lt;/code&gt; hook.&lt;/p&gt;

&lt;p&gt;React warned us from starting against accessing DOM directly in a virtual DOM system. The biggest concern is predictability. The uni-directional data model in React will not respond if something directly changes the DOM element without properly notifying React.&lt;/p&gt;

&lt;p&gt;In our case, if we make a small timeout trigger that will change the data directly, we will lose the notification to the other component we defined for a controlled change. We can see the message in the lower paragraph tag has not been updated after the ref changed the value.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F5980%2F1%2AJnOysx6wAx5wxwVEWM25_Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F5980%2F1%2AJnOysx6wAx5wxwVEWM25_Q.png" alt="Value updated directly by using ref in a 2-second timeout broke our application."&gt;&lt;/a&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F5980%2F1%2AOGuCqKG1qmE3NL4TNKwE2w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F5980%2F1%2AOGuCqKG1qmE3NL4TNKwE2w.png" alt="Value updated directly by using ref in a 2-second timeout broke our application."&gt;&lt;/a&gt;Value updated directly by using ref in a 2-second timeout broke our application.&lt;/p&gt;




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

&lt;p&gt;==========&lt;/p&gt;

&lt;p&gt;We have gone through enough examples to understand how refs can help us and what we should look out for. In the next part, we will look into some more complex use cases which may come in handy for a bigger application that needs cross-component communication and passing refs to other components.&lt;/p&gt;




&lt;h2&gt;
  
  
  Want To Connect?
&lt;/h2&gt;

&lt;p&gt;LinkedIn: &lt;a href="https://www.linkedin.com/in/sameerkumar1612/" rel="noopener noreferrer"&gt;https://www.linkedin.com/in/sameerkumar1612&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>react</category>
      <category>programming</category>
    </item>
    <item>
      <title>The Boy Scout Rule 💡👩‍💻</title>
      <dc:creator>Sameer Kumar</dc:creator>
      <pubDate>Mon, 23 May 2022 14:06:27 +0000</pubDate>
      <link>https://dev.to/sameer1612/the-boy-scout-rule-2njn</link>
      <guid>https://dev.to/sameer1612/the-boy-scout-rule-2njn</guid>
      <description>&lt;h4&gt;
  
  
  This post is going to be a little different.
&lt;/h4&gt;




&lt;blockquote&gt;
&lt;p&gt;Most engineers have heard of the 'boy-scout rule': 'Always leave the code better than you found it.' It's often been heralded as a magic cure for technical debt; if only all software engineers behaved like good citizens, our software wouldn't deteriorate so relentlessly.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;A small snippet from an office talk describing impact of it on real projects:&lt;br&gt;
&lt;/p&gt;
&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
      &lt;div class="c-embed__cover"&gt;
        &lt;a href="https://www.linkedin.com/posts/sameerkumar1612_sameer-on-coding-standards-activity-6934497182557315072-NcIC?utm_source=linkedin_share&amp;amp;amp%3Butm_medium=member_desktop_web" class="c-link s:max-w-50 align-middle" rel="noopener noreferrer"&gt;
          &lt;img alt="" src="https://res.cloudinary.com/practicaldev/image/fetch/s--yzi2ptzk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://media.licdn.com/dms/image/C4D05AQHI3Tp7QJ62_w/videocover-high/0/1653311457013%3Fe%3D2147483647%26v%3Dbeta%26t%3DucVq_VpjBRqJAayMm1kwOczHoEFPAVj42BjY8NFY4PY" height="450" class="m-0" width="800"&gt;
        &lt;/a&gt;
      &lt;/div&gt;
    &lt;div class="c-embed__body"&gt;
      &lt;h2 class="fs-xl lh-tight"&gt;
        &lt;a href="https://www.linkedin.com/posts/sameerkumar1612_sameer-on-coding-standards-activity-6934497182557315072-NcIC?utm_source=linkedin_share&amp;amp;amp%3Butm_medium=member_desktop_web" rel="noopener noreferrer" class="c-link"&gt;
          Sameer Kumar on LinkedIn: Sameer on coding standards
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;p class="truncate-at-3"&gt;
          👩‍💻 Most engineers have heard of the &amp;amp;#39;boy-scout rule&amp;amp;#39;: &amp;amp;#39;Always leave the code better than you found it.&amp;amp;#39; It&amp;amp;#39;s often been heralded as a magic cure…
        &lt;/p&gt;
      &lt;div class="color-secondary fs-s flex items-center"&gt;
          &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://res.cloudinary.com/practicaldev/image/fetch/s--aGQ1YUtN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://static.licdn.com/aero-v1/sc/h/al2o9zrvru7aqj8e1x2rzsrca" width="64" height="64"&gt;
        linkedin.com
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;





&lt;p&gt;Audio snippet:&lt;br&gt;
&lt;iframe class="tweet-embed" id="tweet-1528731583473065985-428" src="https://platform.twitter.com/embed/Tweet.html?id=1528731583473065985"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1528731583473065985-428');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1528731583473065985&amp;amp;theme=dark"
  }



&lt;/p&gt;




&lt;p&gt;What you think about conscious negligence and voluntarily clearing technical debt left by previous engineers?&lt;/p&gt;




&lt;p&gt;Quote referred from: &lt;a href="https://www.stepsize.com/blog/how-to-be-an-effective-boy-girl-scout-engineer#:~:text=Most%20engineers%20have%20heard%20of,wouldn't%20deteriorate%20so%20relentlessly." rel="noopener noreferrer"&gt;Here&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  To Connect
&lt;/h2&gt;

&lt;p&gt;🏭 LinkedIn: &lt;a href="https://www.linkedin.com/in/sameerkumar1612" rel="noopener noreferrer"&gt;https://www.linkedin.com/in/sameerkumar1612&lt;/a&gt;&lt;br&gt;
✍️ Medium: &lt;a href="https://sameer-kumar-1612.medium.com" rel="noopener noreferrer"&gt;https://sameer-kumar-1612.medium.com&lt;/a&gt;&lt;br&gt;
✍️ Dev.to: &lt;a href="https://dev.to/sameer1612"&gt;https://dev.to/sameer1612&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>React v18: Why useEffect suddenly go crazy?</title>
      <dc:creator>Sameer Kumar</dc:creator>
      <pubDate>Sun, 22 May 2022 06:32:52 +0000</pubDate>
      <link>https://dev.to/sameer1612/react-v18-why-useeffect-suddenly-go-crazy-2678</link>
      <guid>https://dev.to/sameer1612/react-v18-why-useeffect-suddenly-go-crazy-2678</guid>
      <description>&lt;p&gt;&lt;strong&gt;R&lt;/strong&gt;eact version 18 has brought some very appreciable changes to the core. One such bittersweet change is in for form of the mount -&amp;gt; unmount -&amp;gt; remount pattern of loading components in strict mode. If you have not tasted this first hand, be prepared because at first glance it seems some sort of dark magic on your happily working application. Let’s dive.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem
&lt;/h2&gt;

&lt;p&gt;Let’s take this fairly simple code for example. Judging by the empty dependency array in useEffect, we can expect “App Loaded” to be printed once in our console and be done with it.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you are confused with the use of this  &lt;a href="https://medium.com/console-log-and-his-ninja-pals-4fc0863ad5f4" rel="noopener noreferrer"&gt;&lt;strong&gt;console.count&lt;/strong&gt;&lt;/a&gt; method, do read here: &lt;a href="https://medium.com/console-log-and-his-ninja-pals-4fc0863ad5f4" rel="noopener noreferrer"&gt;Awesome console methods&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F1400%2F1%2AqQwTmbp0rFNlvwzrVHDRNQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F1400%2F1%2AqQwTmbp0rFNlvwzrVHDRNQ.png" alt="useEffect hook in react."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Surprisingly, we are seeing this message being printed twice. That raises the question, are we doing something wrong or is react drunk today?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F1400%2F1%2A_-kV-3vo6A7keUrYCMfWmg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F1400%2F1%2A_-kV-3vo6A7keUrYCMfWmg.png" alt="Double console log in react useEffect."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Background
&lt;/h2&gt;

&lt;p&gt;To understand this whole mess let’s discuss first the concept of pure functions and idempotence. The following illustration is self-explanatory and we can see that under the same conditions, a function should produce the same output. Whereas, idempotence means that even if a function runs multiple times, the outcome should be the same.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F516%2F1%2AKzkeD6AfVwyK-JAZxTF-lQ.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F516%2F1%2AKzkeD6AfVwyK-JAZxTF-lQ.jpeg" alt="Idempotence in pure functions."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Well, you must be wondering what it has to do with our problem in hand with react. Take a practical example, we intend to subscribe to a stream of notifications coming from a certain server and we keep it in useEffect expecting it to subscribe ONCE the user opens our website, using the empty dependency array for the purpose. But, as established in our little demo, code written in useEffect ran twice and hence will our subscription. Possible outcomes can be:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  We are showing two or more notifications, depending on the number of times our component is rendered. &lt;em&gt;[Application level pure behaviour is no more present, sometimes showing 1 notification, sometimes 83.]&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;  Our subscription server may throw an error that, “You are already subscribed”. &lt;em&gt;[Idempotence cries in the corner.]&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;

&lt;p&gt;Enough mathematics for the day, let’s look into the fix. “The fix” is essentially sticking to the best practices. I found many online resources, suggesting custom hooks to replace useEffect hacked with using ref and whatnot. Frameworks tend to make our life easier by abstracting decisions and we launch full-scale battles for finding ways to sneak out. Effect always provides a cleanup function which should be used to clean the work done during the effect run. It can be used to do the unsubscription in our hypothetical example. Looking at our previous example, it should be like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F1400%2F1%2AfM5vvJ5W9NORDZhFbNq86A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F1400%2F1%2AfM5vvJ5W9NORDZhFbNq86A.png" alt="useEffect with cleanup function."&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F1400%2F1%2AjbN-6thY4mpZk3QK7m9r1g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F1400%2F1%2AjbN-6thY4mpZk3QK7m9r1g.png" alt="Correct use of useEffect hook."&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;The react team decided to bring strict mode to these hooks for establishing best programming practices during the development phase. As in the case of our useEffect, this double mount saves us from many unseen issues that can come into the production later as we saw in our subscription example. Also, take note that React doesn't do this &lt;strong&gt;mount — unmount — mount&lt;/strong&gt; cycle in an actual production build, it’s a dev mode feature provided by using the &lt;a href="https://reactjs.org/docs/strict-mode.html" rel="noopener noreferrer"&gt;&lt;strong&gt;StrictMode&lt;/strong&gt;&lt;/a&gt; tag in the index.tsx for the sole purpose of imposing best practices.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F1280%2F1%2Anlbr7xs5X82ZUrsGTFCidQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F1280%2F1%2Anlbr7xs5X82ZUrsGTFCidQ.png" alt="StrictMode in react."&gt;&lt;/a&gt;&lt;a href="https://reactjs.org/docs/strict-mode.html" rel="noopener noreferrer"&gt;StrictMode in react.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  To Connect
&lt;/h2&gt;

&lt;p&gt;🏭 LinkedIn: &lt;a href="https://www.linkedin.com/in/sameerkumar1612/" rel="noopener noreferrer"&gt;https://www.linkedin.com/in/sameerkumar1612&lt;/a&gt;&lt;br&gt;&lt;br&gt;
✍️ Medium: &lt;a href="https://medium.com/" rel="noopener noreferrer"&gt;https://sameer-kumar-1612.medium.com&lt;/a&gt;&lt;br&gt;&lt;br&gt;
✍️ Dev.to: &lt;a href="https://dev.to/sameer1612"&gt;https://dev.to/sameer1612&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Console.log and his Ninja Pals 🥷</title>
      <dc:creator>Sameer Kumar</dc:creator>
      <pubDate>Sat, 21 May 2022 07:57:02 +0000</pubDate>
      <link>https://dev.to/sameer1612/consolelog-and-his-ninja-pals-2n4f</link>
      <guid>https://dev.to/sameer1612/consolelog-and-his-ninja-pals-2n4f</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Swiss knife of javascript ninjas, our beloved console.log has some lesser-known yet more powerful variations. In this blog, we’ll explore some methods with examples which I find very useful in day to day debugging and scripting.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;The &lt;code&gt;console&lt;/code&gt; object provides access to the browser's debugging console (e.g. the &lt;a href="https://firefox-source-docs.mozilla.org/devtools-user/web_console/index.html" rel="noopener noreferrer"&gt;Web console&lt;/a&gt; in Firefox). The specifics of how it works vary from browser to browser, but there is a &lt;em&gt;de facto&lt;/em&gt; set of features that are typically provided everywhere. It provides a set of methods and formatters to show information in the browser console in a more user-friendly way depending on the type of data being passed to the specific method. Since everyone is already familiar with the&lt;code&gt;log&lt;/code&gt; method, we’ll look into the rest.&lt;/p&gt;




&lt;h3&gt;
  
  
  console.count()
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;The count method can be used to display the number of times this message was shown on screen.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fGwW7QTZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/1264/1%2Azg8Hi7Cr-2nurbDXBOE1_A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fGwW7QTZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/1264/1%2Azg8Hi7Cr-2nurbDXBOE1_A.png" alt="console.count() javascript method" width="632" height="530"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  console.error()
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;The error method is the correct way to log error messages to the console, which uses browser tooling for proper representation of the error and semantically justifies the log. Also, you’ll find count on top of the console reflecting the number of errors &lt;em&gt;[ x 2 ]&lt;/em&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--U177ye_r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/1400/1%2AZS2NIOwsu-Zwk-lWxKbDyA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--U177ye_r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/1400/1%2AZS2NIOwsu-Zwk-lWxKbDyA.png" alt="console.error(msg, object 1, …, object n)" width="800" height="283"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  console.table()
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;The best of all the methods and my personal favourite. Really useful to debug API responses which contain an array of 100s of similar objects. Instead of opening each and looking into them, we can have a flat tabular representation.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TDM93RXs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/1400/1%2AakHT-SvgV7cWwzzOe15teg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TDM93RXs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/1400/1%2AakHT-SvgV7cWwzzOe15teg.png" alt="console.table([object 1, … , object n])" width="800" height="345"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  console.time()
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;A quick and dirty way to measure the performance of your javascript code. You can get a benchmark of some intensive operations or find which operations are taking the longest in a chain using this method.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Woah! Javascript and new macs are&lt;/em&gt; &lt;strong&gt;&lt;em&gt;fast!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--D7gKCATY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/1400/1%2AVtJ0pPGZdyHg_RWeAZKFJw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--D7gKCATY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/1400/1%2AVtJ0pPGZdyHg_RWeAZKFJw.png" alt="console.time(string)" width="780" height="294"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  console.trace()
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;When things get serious, you may need to solve the chicken-egg problem, ie, which method was called first. Especially troubles get more troublesome when playing the async game.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wsEVVGWH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/1400/1%2APHK5NIrXgEbQYyCcwWVS8g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wsEVVGWH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/1400/1%2APHK5NIrXgEbQYyCcwWVS8g.png" alt="console.trace()" width="800" height="518"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  console.warn()
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;A semantic way to handle non-nuclear threats thrown by your application. A possible use case can be if your user is about to hit a certain limit, you can log some warning messages, until finally throwing an error. Or, most commonly seen in deprecation warning of certain functions.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ayg6zrL6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/1400/1%2A62K-Rbfohm1ojd8kukWMQA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ayg6zrL6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/1400/1%2A62K-Rbfohm1ojd8kukWMQA.png" alt="console.warn(msg, object 1, … , object n)" width="800" height="229"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  console.asset()
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Sometimes it's not worth logging every time. Maybe say, we are tracking mouse movement and need a message if the mouse cursor moves outside a box. To help in such situations, assert does conditional logging whenever the provided condition in the first parameter is false.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fIWk8ZsM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/1400/1%2A3rcrvXgmiavF8MeH2yye1w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fIWk8ZsM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/1400/1%2A3rcrvXgmiavF8MeH2yye1w.png" alt="console.asset(boolean, string, object)" width="800" height="222"&gt;&lt;/a&gt;&lt;/p&gt;




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

&lt;p&gt;So, ninja pals, today we have learnt about many ninja tools that the console provides us with. These methods can make our stressful debugging moments a little bit happier and add a lot of semantic meaning to the power of almighty &lt;strong&gt;console.log(“Live Long and Prosper…”)&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  To Connect
&lt;/h2&gt;

&lt;p&gt;🏭 LinkedIn: &lt;a href="https://www.linkedin.com/in/sameerkumar1612/" rel="noopener noreferrer"&gt;https://www.linkedin.com/in/sameerkumar1612&lt;/a&gt;&lt;br&gt;
✍️ Medium: &lt;a href="https://medium.com/" rel="noopener noreferrer"&gt;https://sameer-kumar-1612.medium.com&lt;/a&gt;&lt;br&gt;
✍️ Dev.to: &lt;a href="https://dev.to/sameer1612"&gt;https://dev.to/sameer1612&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://creativecommons.org/licenses/by/4.0/" rel="noopener noreferrer"&gt;Some rights reserved&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
