<?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>Forem: Vijay</title>
    <description>The latest articles on Forem by Vijay (@viissgg).</description>
    <link>https://forem.com/viissgg</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%2F107007%2Ffaa4272c-c573-40d9-be93-d8d9239a8348.jpg</url>
      <title>Forem: Vijay</title>
      <link>https://forem.com/viissgg</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/viissgg"/>
    <language>en</language>
    <item>
      <title>Struggling with 'command not found' on Mac?</title>
      <dc:creator>Vijay</dc:creator>
      <pubDate>Thu, 07 Aug 2025 08:21:23 +0000</pubDate>
      <link>https://forem.com/viissgg/struggling-with-command-not-found-on-mac-k92</link>
      <guid>https://forem.com/viissgg/struggling-with-command-not-found-on-mac-k92</guid>
      <description>&lt;p&gt;You open a new terminal window. You type a command.&lt;/p&gt;

&lt;p&gt;But your Mac says, "command not found." It's super annoying. &lt;/p&gt;

&lt;p&gt;What’s going on here?&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;The Problem: Your Terminal Forgot Everything&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;You're trying to use a command like &lt;code&gt;nvm&lt;/code&gt;. It's a handy tool, right? But your computer has no idea what you're talking about.&lt;/p&gt;

&lt;p&gt;This happens with tools you install with Homebrew. The &lt;code&gt;nvm&lt;/code&gt; command only works after you run a specific command.&lt;/p&gt;

&lt;p&gt;You have to tell your terminal about it again.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;The Explanation: Shell Configuration&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Think of your terminal like your buddy. When you first say hi, he's got a fresh memory. He doesn't remember anything from your last chat.&lt;/p&gt;

&lt;p&gt;The special &lt;code&gt;source&lt;/code&gt; command is how you remind him. It's a command that tells the shell to run a file's commands. It's like you're loading a script.&lt;/p&gt;

&lt;p&gt;That script tells your shell where to find &lt;code&gt;nvm&lt;/code&gt;. Now your terminal remembers what to do.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;The Solution: Make It Automatic&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;We need to make sure your terminal remembers this automatically. We do that by editing a special file. This file runs every time you open a new terminal.&lt;/p&gt;

&lt;p&gt;You just need to put that &lt;code&gt;source&lt;/code&gt; command inside.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Step 1: Find your shell's config file.&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Most modern Macs use &lt;strong&gt;zsh&lt;/strong&gt;. If you're using zsh, you'll want to edit the &lt;code&gt;.zshrc&lt;/code&gt; file. If you have an older Mac, it might be &lt;strong&gt;bash&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Then you'll need to edit the &lt;code&gt;.bash_profile&lt;/code&gt; file. Not sure? Just type &lt;code&gt;echo $SHELL&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Step 2: Add the fix to the file.&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Open your file with a simple command. Use &lt;code&gt;nano ~/.zshrc&lt;/code&gt; or &lt;code&gt;nano ~/.bash_profile&lt;/code&gt;. Scroll to the bottom of the file.&lt;/p&gt;

&lt;p&gt;Paste this little snippet of code there.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;NVM_DIR&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$HOME&lt;/span&gt;&lt;span class="s2"&gt;/.nvm"&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;brew &lt;span class="nt"&gt;--prefix&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;/opt/nvm/nvm.sh"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="se"&gt;\.&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;brew &lt;span class="nt"&gt;--prefix&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;/opt/nvm/nvm.sh"&lt;/span&gt; &lt;span class="c"&gt;# This loads nvm&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  &lt;strong&gt;Step 3: Save and restart your terminal.&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Hit &lt;code&gt;Ctrl + X&lt;/code&gt; to exit and save. Then open a new terminal window. You can also run &lt;code&gt;source ~/.zshrc&lt;/code&gt; or &lt;code&gt;source ~/.bash_profile&lt;/code&gt; to try it right away.&lt;/p&gt;

&lt;p&gt;Now, your terminal should remember your &lt;code&gt;nvm&lt;/code&gt; command every time. No more "command not found" errors.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;It’s a simple fix for a common headache.&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;You've just automated your terminal's memory. It’s a small change. But it makes a big difference.&lt;/p&gt;

&lt;p&gt;Now you can get back to coding without the hassle. Pretty cool, right?&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Prompting Techniques in Gen AI: The Founder's Guide to Getting Better Results</title>
      <dc:creator>Vijay</dc:creator>
      <pubDate>Mon, 28 Jul 2025 13:21:28 +0000</pubDate>
      <link>https://forem.com/viissgg/prompting-techniques-in-gen-ai-the-founders-guide-to-getting-better-results-3a8j</link>
      <guid>https://forem.com/viissgg/prompting-techniques-in-gen-ai-the-founders-guide-to-getting-better-results-3a8j</guid>
      <description>&lt;p&gt;Most founders are terrible at prompting.&lt;/p&gt;

&lt;p&gt;They treat AI like Google search. They type random questions. Then wonder why outputs suck. Your prompting strategy determines everything. &lt;/p&gt;

&lt;p&gt;Better prompts = better results = better ROI.&lt;/p&gt;

&lt;p&gt;Here's how to actually do it right.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;What Good Prompting Actually Is&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Think of prompting like giving instructions to an intern.&lt;/p&gt;

&lt;p&gt;You wouldn't just say "write something." You'd provide context. Set expectations. Give examples. Explain the goal.&lt;/p&gt;

&lt;p&gt;AI works the same way.&lt;/p&gt;

&lt;p&gt;Good prompts have four parts:&lt;br&gt;
• Clear context about the situation&lt;br&gt;
• Specific task you want done&lt;br&gt;
• Expected format for the output&lt;br&gt;
• Success criteria or constraints&lt;/p&gt;

&lt;p&gt;Bad prompts are vague. Good prompts are precise.&lt;/p&gt;

&lt;p&gt;The difference? Hours of time saved. And results you can actually use.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;The Anatomy of Effective Prompts&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Every great prompt follows a pattern.&lt;/p&gt;

&lt;p&gt;It's not magic. It's just structure. Here's the framework I teach every founder:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Context&lt;/strong&gt;: Set the stage first.&lt;br&gt;
"You're a marketing expert helping a B2B SaaS startup."&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task&lt;/strong&gt;: Be specific about what you want.&lt;br&gt;
"Write three subject lines for our product launch email."&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Format&lt;/strong&gt;: Tell it how to respond.&lt;br&gt;
"Format as a numbered list with brief explanations."&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Constraints&lt;/strong&gt;: Add guardrails.&lt;br&gt;
"Keep each subject line under 50 characters."&lt;/p&gt;

&lt;p&gt;This takes 30 seconds to write. But saves hours of back-and-forth.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;The 5 Biggest Prompting Mistakes I See&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Most founders mess up the basics.&lt;/p&gt;

&lt;p&gt;They skip context. Use vague language. Don't iterate. These mistakes cost time and money.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mistake #1: Being too generic&lt;/strong&gt;&lt;br&gt;
Bad: "Write marketing copy"&lt;br&gt;
Good: "Write a 100-word product description for our project management tool targeting small business owners"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mistake #2: No examples provided&lt;/strong&gt;&lt;br&gt;
Always show what good looks like. AI learns from examples better than explanations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mistake #3: Forgetting to specify format&lt;/strong&gt;&lt;br&gt;
Do you want bullets? Paragraphs? A table? Say it upfront.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mistake #4: Not iterating on results&lt;/strong&gt;&lt;br&gt;
First output is rarely perfect. Ask for revisions. Be specific about changes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mistake #5: Treating each prompt like a one-shot&lt;/strong&gt;&lt;br&gt;
Build conversations. Reference previous outputs. Create context chains.&lt;/p&gt;

&lt;p&gt;Fix these five things. Your results improve immediately.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Advanced Techniques That Actually Work&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Once you master the basics, try these.&lt;/p&gt;

&lt;p&gt;These techniques separate good prompters from great ones. They're not complicated. Just specific.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Chain of Thought Prompting&lt;/strong&gt;&lt;br&gt;
Ask AI to think step-by-step. Add "Let's think through this step by step" to complex requests.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Role-Based Prompting&lt;/strong&gt; &lt;br&gt;
Start with "You are a [specific expert]." This primes better responses.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Few-Shot Learning&lt;/strong&gt;&lt;br&gt;
Give 2-3 examples of input/output pairs. AI picks up patterns quickly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Constraint Laddering&lt;/strong&gt;&lt;br&gt;
Start broad. Add constraints gradually. This prevents over-specification early.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Output Formatting&lt;/strong&gt;&lt;br&gt;
Use templates. "Respond using this format: Problem: [X], Solution: [Y], Impact: [Z]"&lt;/p&gt;

&lt;p&gt;These techniques work. But only if you use them consistently.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;How to Train Your Team on Prompting&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Your team needs prompting skills too.&lt;/p&gt;

&lt;p&gt;Don't assume they'll figure it out. Good prompting isn't intuitive. It's a learnable skill.&lt;/p&gt;

&lt;p&gt;Here's my training approach:&lt;br&gt;
• Start with the basic framework&lt;br&gt;
• Practice on real company tasks&lt;br&gt;
• Share successful prompts across teams&lt;br&gt;
• Create a prompt library&lt;br&gt;
• Review and iterate together&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Common training mistakes:&lt;/strong&gt;&lt;br&gt;
• Teaching too many techniques at once&lt;br&gt;
• Not practicing on real work&lt;br&gt;
• Skipping the feedback loop&lt;br&gt;
• Treating it as one-time training&lt;/p&gt;

&lt;p&gt;Make prompting part of your process. Not an afterthought.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Measuring Prompt Effectiveness&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;You can't improve what you don't measure.&lt;/p&gt;

&lt;p&gt;Track these metrics for your AI initiatives:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Time to useful output&lt;/strong&gt;: How long until you get something usable?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Revision cycles needed&lt;/strong&gt;: How many back-and-forth rounds?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Output quality scores&lt;/strong&gt;: Rate results on accuracy and relevance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Team adoption rates&lt;/strong&gt;: Who's actually using AI tools?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cost per useful output&lt;/strong&gt;: Factor in API costs and time spent.&lt;/p&gt;

&lt;p&gt;Most founders skip measurement. Then wonder why AI isn't working.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Building Prompting Systems That Scale&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Individual great prompts are nice. Systems are better.&lt;/p&gt;

&lt;p&gt;Here's how to scale prompting across your startup:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create prompt templates&lt;/strong&gt;&lt;br&gt;
Build reusable prompts for common tasks. Marketing copy. Code reviews. Customer support.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Build prompt libraries&lt;/strong&gt;&lt;br&gt;
Document what works. Share across teams. Version control your best prompts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Establish quality standards&lt;/strong&gt;&lt;br&gt;
Define what good output looks like. Train your team to recognize it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Automate repetitive prompts&lt;/strong&gt;&lt;br&gt;
Use APIs for recurring tasks. Don't manually copy-paste the same prompts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Monitor and optimize&lt;/strong&gt;&lt;br&gt;
Track performance. Update prompts based on results. Iterate constantly.&lt;/p&gt;

&lt;p&gt;The goal isn't perfect prompts. It's consistent, scalable results.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;What This Means for Your Startup&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Good prompting is a competitive advantage.&lt;/p&gt;

&lt;p&gt;While competitors struggle with poor AI outputs, you'll get better results faster. Your team will be more productive. Your AI investments will actually pay off.&lt;/p&gt;

&lt;p&gt;Start with the basics:&lt;br&gt;
• Use the four-part prompt structure&lt;br&gt;
• Avoid the five common mistakes&lt;br&gt;&lt;br&gt;
• Train your team properly&lt;br&gt;
• Measure what matters&lt;br&gt;
• Build systems that scale&lt;/p&gt;

&lt;p&gt;The companies winning with AI aren't the ones with the biggest budgets. They're the ones with the best prompting.&lt;/p&gt;

&lt;p&gt;Your AI is only as good as your prompts. Make them count.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>genai</category>
      <category>chatgpt</category>
      <category>startup</category>
    </item>
    <item>
      <title>Why Gen AI Isn't Optional for Your Startup Anymore</title>
      <dc:creator>Vijay</dc:creator>
      <pubDate>Mon, 28 Jul 2025 10:36:27 +0000</pubDate>
      <link>https://forem.com/viissgg/why-gen-ai-isnt-optional-for-your-startup-anymore-3g10</link>
      <guid>https://forem.com/viissgg/why-gen-ai-isnt-optional-for-your-startup-anymore-3g10</guid>
      <description>&lt;p&gt;Your competitors are already building with AI.&lt;/p&gt;

&lt;p&gt;Here's what every software product owner needs to know about staying competitive in 2025. Generative AI isn't some distant future tech anymore. It's here, it's accessible, and it's changing everything about how we ship products.&lt;/p&gt;

&lt;p&gt;The question isn't whether you should adopt it. The question is how fast you can move.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;The Window for AI Advantage Is Closing Fast&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Remember when having a mobile app was revolutionary?&lt;/p&gt;

&lt;p&gt;That advantage lasted maybe 18 months before everyone caught up. AI adoption is happening even faster. Your customers are already using ChatGPT, Claude, and other AI tools daily. They expect that same intelligence in your product.&lt;/p&gt;

&lt;p&gt;Here's the brutal truth: if you're not integrating AI features now, you're falling behind. Your users will find alternatives that do. And they won't look back.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;But Integration Doesn't Have to Be Overwhelming&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;You don't need a PhD in machine learning to get started.&lt;/p&gt;

&lt;p&gt;The barrier to entry has dropped dramatically. Here's what's actually required:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;API integrations (you're already doing this with payments, auth, etc.)&lt;/li&gt;
&lt;li&gt;Basic prompt engineering (think of it like writing good search queries)&lt;/li&gt;
&lt;li&gt;User experience design (your bread and butter)&lt;/li&gt;
&lt;li&gt;Data handling best practices (table stakes for any app)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Start small. Pick one workflow your users repeat constantly. Add AI to make it faster, smarter, or more personalized.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Your Customers Are Already Thinking AI-First&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;I talked to a founder last week who was shocked.&lt;/p&gt;

&lt;p&gt;His users were copying data from his app into ChatGPT to get insights he could have provided. They were literally leaving his product to get the AI experience they wanted.&lt;/p&gt;

&lt;p&gt;Think about your user journey. Where do people get stuck? Where do they need to think hard or do repetitive work? Those are your AI opportunities.&lt;/p&gt;

&lt;p&gt;Your customers aren't asking for AI features because they assume you'll figure it out. But they're quietly evaluating alternatives that do.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;The Economics Actually Make Sense Now&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Here's what surprised me most about AI integration costs.&lt;/p&gt;

&lt;p&gt;The API calls are cheaper than you think. GPT-4 costs about $0.03 per 1,000 tokens. That's roughly 750 words. For most use cases, you're talking pennies per user interaction.&lt;/p&gt;

&lt;p&gt;Compare that to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Customer support tickets you won't need to handle&lt;/li&gt;
&lt;li&gt;Features you won't need to build from scratch
&lt;/li&gt;
&lt;li&gt;User churn you won't experience&lt;/li&gt;
&lt;li&gt;Development time you'll save on repetitive functionality&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The ROI calculation is getting easier every month.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Start With These Three Areas&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Don't try to AI-ify everything at once.&lt;/p&gt;

&lt;p&gt;Focus on these high-impact, low-risk areas first:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Content generation&lt;/strong&gt;: Help users create, edit, or optimize text&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data analysis&lt;/strong&gt;: Turn spreadsheets into insights automatically
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Smart automation&lt;/strong&gt;: Reduce clicks and repetitive tasks&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Pick the one that directly impacts your core metrics. Revenue, retention, or user activation. Build it, ship it, measure it.&lt;/p&gt;

&lt;p&gt;Then move to the next one.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Your competition isn't waiting for perfect.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;They're shipping AI features that are good enough to delight users. You should be too.&lt;/p&gt;

&lt;p&gt;The startups winning in 2025 won't be the ones with the most sophisticated AI. They'll be the ones who integrated it thoughtfully, quickly, and kept iterating.&lt;/p&gt;

&lt;p&gt;Your users are ready. The technology is ready. The question is: are you?&lt;/p&gt;

</description>
      <category>ai</category>
      <category>genai</category>
      <category>chatgpt</category>
      <category>startup</category>
    </item>
    <item>
      <title>Your Features Are Boring Users to Death</title>
      <dc:creator>Vijay</dc:creator>
      <pubDate>Sat, 19 Jul 2025 13:03:05 +0000</pubDate>
      <link>https://forem.com/viissgg/your-features-are-boring-users-to-death-d34</link>
      <guid>https://forem.com/viissgg/your-features-are-boring-users-to-death-d34</guid>
      <description>&lt;p&gt;Are you writing product copy like engineering documentation, not sales material?&lt;/p&gt;

&lt;p&gt;Probably, you are making the three mistakes below:&lt;/p&gt;

&lt;h2&gt;
  
  
  Mistake #1: You're Listing Features, Not Benefits
&lt;/h2&gt;

&lt;p&gt;You describe what your product does. Users care about what it does for them.&lt;/p&gt;

&lt;p&gt;Instead of "Advanced AI-powered analytics dashboard," try "See which customers will churn before they leave." Don't list technical specs. Show the outcome users get.&lt;/p&gt;

&lt;p&gt;Your features should make users think "I need this."&lt;/p&gt;

&lt;h2&gt;
  
  
  Mistake #2: You're Speaking Geek, Not Human
&lt;/h2&gt;

&lt;p&gt;You use words like "optimize," "leverage," and "streamline." Normal people don't talk like that.&lt;/p&gt;

&lt;p&gt;Say "makes your work faster" instead of "optimizes workflow efficiency." Write like you're explaining to your mom. She's smart, but she's not a developer.&lt;/p&gt;

&lt;p&gt;Drop the buzzwords. Use simple language.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mistake #3: You're Not Solving Their Pain
&lt;/h2&gt;

&lt;p&gt;You focus on how cool your product is. Users want their problems solved.&lt;/p&gt;

&lt;p&gt;Start with their frustration: "Tired of losing customers without knowing why?" Then show your solution. Make it about them, not you.&lt;/p&gt;

&lt;p&gt;Address their 3 AM worries directly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stop writing like a manual. Start writing like a human who understands other humans' problems.&lt;/strong&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Turn Boring Features Into Customer Magnets</title>
      <dc:creator>Vijay</dc:creator>
      <pubDate>Fri, 18 Jul 2025 13:17:53 +0000</pubDate>
      <link>https://forem.com/viissgg/turn-boring-features-into-customer-magnets-4ope</link>
      <guid>https://forem.com/viissgg/turn-boring-features-into-customer-magnets-4ope</guid>
      <description>&lt;p&gt;Most founders can build amazing products. &lt;/p&gt;

&lt;p&gt;But they can't write compelling copy. Your features sound boring and technical. Customers scroll past without reading anything.&lt;/p&gt;

&lt;h2&gt;
  
  
  Formula #1: Feature → Benefit → Outcome
&lt;/h2&gt;

&lt;p&gt;Start with what it does first.&lt;/p&gt;

&lt;p&gt;Then explain what that means exactly. Finally, show the end result. This creates a clear path.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: "Auto-backup saves work every minute. You'll never lose progress again. Sleep better knowing data's safe."&lt;/p&gt;

&lt;p&gt;Features become benefits when connected properly. Use this formula everywhere possible.&lt;/p&gt;

&lt;h2&gt;
  
  
  Formula #2: Problem → Solution → Result
&lt;/h2&gt;

&lt;p&gt;Lead with customer pain first.&lt;/p&gt;

&lt;p&gt;Show how you fix it completely. End with their total transformation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: "Tired of manual invoicing? Auto-invoice creates bills instantly. Get paid faster, work less."&lt;/p&gt;

&lt;p&gt;Pain-first writing hooks readers immediately. They feel understood and valued.&lt;/p&gt;

&lt;h2&gt;
  
  
  Formula #3: Before → After → Impact
&lt;/h2&gt;

&lt;p&gt;Paint their current frustrating state clearly.&lt;/p&gt;

&lt;p&gt;Show the improved reality after. Explain why it matters most.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: "Before: Hunting through folders daily. After: Find anything in clicks. Save three hours weekly."&lt;/p&gt;

&lt;p&gt;Contrast makes benefits crystal clear. People love dramatic transformations.&lt;/p&gt;

&lt;p&gt;These formulas work for any feature. Practice them on your worst copy. Your conversion rates will thank you.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stop listing features like grocery items. Use these formulas to sell instead. Your customers will actually read everything. Sales will follow naturally.&lt;/strong&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Solving Dynamic Layout With CSS Grid</title>
      <dc:creator>Vijay</dc:creator>
      <pubDate>Fri, 16 May 2025 10:35:56 +0000</pubDate>
      <link>https://forem.com/viissgg/solving-dynamic-layout-with-css-grid-2g56</link>
      <guid>https://forem.com/viissgg/solving-dynamic-layout-with-css-grid-2g56</guid>
      <description>&lt;p&gt;Today, I had a requirement to render a list of items in two columns.&lt;/p&gt;

&lt;p&gt;Interestingly, 2 of the items need to use both columns.&lt;/p&gt;

&lt;p&gt;First, I tried to use Flexbox, and then I thought, let's use Grid.&lt;/p&gt;

&lt;p&gt;To test it out, I created a simple HTML structure for grid layout.&lt;/p&gt;

&lt;p&gt;Here it is:&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;div class="grid-container"&amp;gt;
    &amp;lt;div class="grid-item"&amp;gt;1&amp;lt;/div&amp;gt;
    &amp;lt;div class="grid-item"&amp;gt;2&amp;lt;/div&amp;gt;
    &amp;lt;div class="grid-item"&amp;gt;3&amp;lt;/div&amp;gt;
    &amp;lt;div class="grid-item"&amp;gt;4&amp;lt;/div&amp;gt;
    &amp;lt;div class="grid-item"&amp;gt;5&amp;lt;/div&amp;gt;
    &amp;lt;div class="grid-item"&amp;gt;6&amp;lt;/div&amp;gt;
    &amp;lt;div class="grid-item span-both"&amp;gt;7&amp;lt;/div&amp;gt;
    &amp;lt;div class="grid-item span-both"&amp;gt;8&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;In this structure, I created a grid container with 8 items. I needed to span the 7th and 8th items to use both columns. So I have added one more class on it &lt;code&gt;span-both&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;And then I added below CSS code to make it work.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.grid-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr); /* Two columns */
    gap: 10px; /* Space between items */
}

.grid-item {
    background-color: lightblue;
    padding: 20px;
    text-align: center;
}

.span-both {
    grid-column: 1 / -1; /* Span both columns */
}

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

&lt;/div&gt;



&lt;p&gt;You might be thinking, 'How does that work?'&lt;/p&gt;

&lt;p&gt;So here is my explanation: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Grid Container:&lt;/strong&gt; The &lt;code&gt;display: grid;&lt;/code&gt; property activates the grid layout. I used &lt;code&gt;grid-template-columns: repeat(2, 1fr);&lt;/code&gt; to create two equal columns.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Styling Grid Items:&lt;/strong&gt; I gave each grid item a light blue background and some padding for better visibility.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Spanning Columns:&lt;/strong&gt; The &lt;code&gt;.span-both&lt;/code&gt; class uses &lt;code&gt;grid-column: 1 / -1;&lt;/code&gt;, allowing the 7th and 8th items to stretch across both columns, making them stand out.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's it for today.&lt;/p&gt;

&lt;p&gt;Feel free to experiment with different layouts, colors, and spacing to create a grid that suits your needs.&lt;/p&gt;

&lt;p&gt;Or let me know if you are having any issues. &lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
      <category>css</category>
      <category>webdev</category>
      <category>frontend</category>
      <category>ui</category>
    </item>
    <item>
      <title>5 Surprising and Lesser-Known HTTP Methods Facts Every Developer Should Know to Avoid API Pitfalls</title>
      <dc:creator>Vijay</dc:creator>
      <pubDate>Tue, 22 Oct 2024 12:58:18 +0000</pubDate>
      <link>https://forem.com/viissgg/5-surprising-and-lesser-known-http-methods-facts-every-developer-should-know-to-avoid-api-pitfalls-3hon</link>
      <guid>https://forem.com/viissgg/5-surprising-and-lesser-known-http-methods-facts-every-developer-should-know-to-avoid-api-pitfalls-3hon</guid>
      <description>&lt;p&gt;Not just backend developers—frontend developers should also have a solid understanding of HTTP methods. &lt;/p&gt;

&lt;p&gt;And I’m sure you understand it will. But if not, here is a refresher for the most common HTTP methods.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;GET&lt;/strong&gt;: is the method used to retrieve data from the server.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;POST&lt;/strong&gt;: is how you send data to create resources. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PUT&lt;/strong&gt;: is used to update or create a resource.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;DELETE&lt;/strong&gt;: removes a resource from the server. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PATCH&lt;/strong&gt;: makes partial updates to an existing resource. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;While they are doing great for their purpose, they have some more power, which is not very common. &lt;/p&gt;

&lt;p&gt;Let’s see what are those: &lt;/p&gt;

&lt;h2&gt;
  
  
  Fact #1: GET Can Include a Body (But It’s Rarely Used)
&lt;/h2&gt;

&lt;p&gt;GET requests usually don’t have a body, but they technically can.&lt;/p&gt;

&lt;p&gt;You must be wondering why someone will send a body in GET; for that purpose, we already have POST. Yeah, you're right, but there are some cases where it can be useful. For example, in the case of Long URLs. You might need some parameters that can’t be sent in the URL due to its length restriction. In that case, sending in the body in JSON format can be useful. But it’s always better to use other methods like POST when you need to send data.&lt;/p&gt;

&lt;p&gt;GET is flexible, but using a body is uncommon for good reason. &lt;/p&gt;

&lt;h2&gt;
  
  
  Fact #2: POST is Not Always About Creating Resources
&lt;/h2&gt;

&lt;p&gt;While POST is known for creating new resources, it is also used for complex queries.&lt;/p&gt;

&lt;p&gt;There are several use cases where the APIs need to filter the data based on several conditions. That condition can result in complex queries that can’t be sent in URLs due to their length restriction. In that case, POST might be a better choice than GET, as it can carry more data in the request body. &lt;/p&gt;

&lt;p&gt;So, POST is versatile beyond just creating resources. &lt;/p&gt;

&lt;h2&gt;
  
  
  Fact #3: PUT vs PATCH: More Than Just Syntax
&lt;/h2&gt;

&lt;p&gt;PUT replaces the entire resource, while PATCH makes partial updates.&lt;/p&gt;

&lt;p&gt;If you use PUT to update a user profile, you must send the whole resource, even if only one field changes. Otherwise, all other details will be lost. In this case, PATCH is more efficient when only a small part of the data needs updating.&lt;/p&gt;

&lt;p&gt;Remember, PATCH is your go-to for small, efficient updates.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fact #4: DELETE Can Return a Body
&lt;/h2&gt;

&lt;p&gt;It’s not common, but DELETE requests can return a response body.&lt;/p&gt;

&lt;p&gt;After the DELETE requests are successful, it returns the confirmation that the resource was removed. But you can design your APIs in such a way that they can return the deleted resource’s details in the response. You may ask what the use of it is. They can be useful if you want to log in or display confirmation of the deleted data.&lt;/p&gt;

&lt;p&gt;Well, DELETE isn’t just for removing—it can provide useful feedback, too.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fact #5: Safe and Idempotent Aren’t the Same
&lt;/h2&gt;

&lt;p&gt;Methods like GET are both safe and idempotent, but these terms mean different things.&lt;/p&gt;

&lt;p&gt;A safe method doesn’t change the server’s state, while an idempotent method guarantees that repeating the request has the same effect every time. For example, DELETE is idempotent but not safe since it changes the server state by removing a resource.&lt;/p&gt;

&lt;p&gt;~&lt;/p&gt;

&lt;p&gt;Now, you may ask me, what is the point of knowing these lesser-known facts?&lt;/p&gt;

&lt;p&gt;If you know these, the chances of unexpected behaviour in your APIs will be less.&lt;/p&gt;

&lt;p&gt;I hope these lesser-known details will help you design and work with APIs more effectively. Let me know what other facts you know. Happy coding.&lt;/p&gt;

&lt;p&gt;If you have enjoyed reading this, follow me on &lt;a href="https://twitter.com/ViiSSGG" rel="noopener noreferrer"&gt;Twitter/X&lt;/a&gt; to read more.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>restapi</category>
      <category>frontend</category>
      <category>backend</category>
    </item>
    <item>
      <title>5 Key Techniques to Create Responsive Layouts So That You Don’t Have to Relying On Heavy CSS Frameworks</title>
      <dc:creator>Vijay</dc:creator>
      <pubDate>Mon, 21 Oct 2024 15:44:18 +0000</pubDate>
      <link>https://forem.com/viissgg/5-key-techniques-to-create-responsive-layouts-so-that-you-dont-have-to-relying-on-heavy-css-frameworks-2eaa</link>
      <guid>https://forem.com/viissgg/5-key-techniques-to-create-responsive-layouts-so-that-you-dont-have-to-relying-on-heavy-css-frameworks-2eaa</guid>
      <description>&lt;p&gt;You don’t need heavy CSS frameworks to build responsive layouts.&lt;/p&gt;

&lt;p&gt;CSS frameworks like Tailwind and Bootstrap are really powerful, but sometimes, they are too much for smaller websites. You can achieve all those features offered by them in pure CSS code. Under the hood, they all use the same basic technique for responsive websites.&lt;/p&gt;

&lt;p&gt;In fact, if you really want to know how those frameworks and responsive websites work, then you need to understand the 5 fundamental techniques.&lt;/p&gt;

&lt;p&gt;Here are the 5 techniques to make your website responsive:&lt;/p&gt;

&lt;h2&gt;
  
  
  Technique #1: Configure the Viewport
&lt;/h2&gt;

&lt;p&gt;Did you know a single meta tag can control how your website scales on any screen size?&lt;/p&gt;

&lt;p&gt;Yeah, that meta tag is Viewport.&lt;/p&gt;

&lt;p&gt;If you don't know what the Viewport is, then Viewport is the visible area on a webpage on a device, whether it is a phone, tablet or desktop. You may ask what it does. It determines how content is scaled and displayed based on the device's screen size.&lt;/p&gt;

&lt;p&gt;Since the screens come in various sizes, the Viewport plays a crucial role in making the website responsive.&lt;/p&gt;

&lt;p&gt;Now, how to use it?&lt;/p&gt;

&lt;p&gt;Simply use the Viewport meta tag in your HTML file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, initial-scale=1.0"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Technique #2: Adopt a Mobile-First Approach
&lt;/h2&gt;

&lt;p&gt;If you’re not designing mobile-first, you’re doing it wrong.&lt;/p&gt;

&lt;p&gt;Because over half of web traffic today comes from mobile devices. And that’s what approach Tailwind adopted. And they are asking you to do the same. Here, we are talking about using pure CSS instead of a framework, but the approach is still the same.&lt;/p&gt;

&lt;p&gt;The mobile-First approach helps in the longer term, as you will have to write multiple versions of the same code for different types of devices.&lt;/p&gt;

&lt;h2&gt;
  
  
  Technique #3: Utilize CSS Grid and Flexbox
&lt;/h2&gt;

&lt;p&gt;Are you still using Float-based layout for your website?&lt;/p&gt;

&lt;p&gt;I hope you are not. And if you are still using it, then it is time to switch to Flexbox and CSS Grid since they are powerful tools for creating flexible layouts.&lt;/p&gt;

&lt;p&gt;When you need to create a one-dimensional layout, go for Flexbox&lt;/p&gt;

&lt;p&gt;And When you need to create a two-dimensional layout, then go for Grid&lt;/p&gt;

&lt;h2&gt;
  
  
  Technique #4: Create Fluid Layouts
&lt;/h2&gt;

&lt;p&gt;Are you using fixed pixel values everywhere on your website?&lt;/p&gt;

&lt;p&gt;Most developers choose to go with pixel(px) value while developing the different layouts on the screen. Pixel values are great for fixed layouts but not so great for responsive layouts. If you use a fluid layout like a percentage-based value, then your layout will smoothly resize on any viewport size.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;90%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Technique #5: Use Media Queries Wisely
&lt;/h2&gt;

&lt;p&gt;Media Queries are another helpful technique for making responsive layouts&lt;/p&gt;

&lt;p&gt;But it needs to be used wisely. It is using different breakpoints for different layouts. Most developers go wrong with it. They start creating for all possible screen sizes, which leads to unmanageable code.&lt;/p&gt;

&lt;p&gt;In my suggestion, media queries should be made on key transitions between device categories. For e.g. Mobile to Tablet, Tablet to Desktop.&lt;/p&gt;

&lt;p&gt;~&lt;/p&gt;

&lt;p&gt;All right, as you can see, there are multiple techniques available to make your website responsive. On paper, it looks like 5 different techniques are ready to be used, but practically, when you start working on any production website, you will start seeing the use case of all those techniques.&lt;/p&gt;

&lt;p&gt;Now go and build a responsive site, and let me know what you used at its best.&lt;/p&gt;

&lt;p&gt;If you have enjoyed reading this, follow me on &lt;a href="https://twitter.com/ViiSSGG" rel="noopener noreferrer"&gt;Twitter/X&lt;/a&gt; to read more.&lt;/p&gt;

</description>
      <category>css</category>
      <category>website</category>
      <category>webdev</category>
      <category>html</category>
    </item>
    <item>
      <title>3 Reasons Why Mastering JavaScript Fundamentals Is Crucial for Frontend Developers for Long-Term Career Success</title>
      <dc:creator>Vijay</dc:creator>
      <pubDate>Fri, 18 Oct 2024 07:59:41 +0000</pubDate>
      <link>https://forem.com/viissgg/3-reasons-why-mastering-javascript-fundamentals-is-crucial-for-frontend-developers-for-long-term-career-success-42d2</link>
      <guid>https://forem.com/viissgg/3-reasons-why-mastering-javascript-fundamentals-is-crucial-for-frontend-developers-for-long-term-career-success-42d2</guid>
      <description>&lt;p&gt;9 years ago, I tried to learn Angular 1.&lt;/p&gt;

&lt;p&gt;And I failed it badly. I was frustrated and scared. I didn't touch it for the next 7-8 months.&lt;/p&gt;

&lt;p&gt;One day, I got my chance to throw my frustration in front of my friend. My friend asked a straightforward question. Do you know any of the below concepts?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Scope and the Scope chain&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;this&lt;/code&gt; keyword&lt;/li&gt;
&lt;li&gt;Closures&lt;/li&gt;
&lt;li&gt;Dependency injection&lt;/li&gt;
&lt;li&gt;Call by Value vs Call by Reference&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I was looking into his eyes deeply lost in nowhere.&lt;/p&gt;

&lt;p&gt;He only said - &lt;strong&gt;You need to master JavaScript Fundamentals.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And so do you.&lt;/p&gt;

&lt;p&gt;Here are 3 more reasons why:&lt;/p&gt;

&lt;h3&gt;
  
  
  Reason #1: Framework Independence
&lt;/h3&gt;

&lt;p&gt;Do you get excited about every shiny new JavaScript framework there or get scared?&lt;/p&gt;

&lt;p&gt;Let me tell you, if your JavaScript fundamentals are strong, then you will love it; otherwise, you will be in a constant state of fear.&lt;/p&gt;

&lt;p&gt;Why is that so?&lt;/p&gt;

&lt;p&gt;The reason is simple - under the hood, all the framework is dependent on JavaScript itself and uses its capabilities. If you understand the fundamentals, then no framework is challenging to learn.&lt;/p&gt;

&lt;h3&gt;
  
  
  Reason #2: Problem-Solving Capabilities
&lt;/h3&gt;

&lt;p&gt;Are you failing your interview due to a lack of problem-solving capabilities?&lt;/p&gt;

&lt;p&gt;Instead of grinding 100 of the LeetCode problems, I would instead take a different approach - develop your own polyfill version of all JavaScript inbuilt methods like &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;filter&lt;/code&gt;, and &lt;code&gt;reduce&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;There are two benefits to doing so&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You will deeply understand how all those methods work under the hood&lt;/li&gt;
&lt;li&gt;Your problem-solving capability will skyrocket.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Reason #3: Code Quality and Maintenance
&lt;/h3&gt;

&lt;p&gt;Need help fixing bugs quickly?&lt;/p&gt;

&lt;p&gt;Every day, we deal with code that's messy, hard to read, and a pain to debug. This happens because developers ignore the basics. When you get the fundamentals right, it's hard to write messy code. By focusing on clean, readable, and maintainable code, you set yourself and your team up for success.&lt;/p&gt;

&lt;p&gt;Technical debt is something you should always take seriously.&lt;/p&gt;




&lt;p&gt;I hope you understand why mastering the fundamentals are important than switching to every new framework.&lt;/p&gt;

&lt;p&gt;Now, go and nailed it. All the best.&lt;/p&gt;

&lt;p&gt;If you have enjoyed reading this, follow me on &lt;a href="https://twitter.com/ViiSSGG" rel="noopener noreferrer"&gt;Twitter/X&lt;/a&gt; to read more.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>The CLEAN Framework: A 5-Step Blueprint for Writing Bug-Free, Maintainable JavaScript Code</title>
      <dc:creator>Vijay</dc:creator>
      <pubDate>Thu, 17 Oct 2024 09:31:53 +0000</pubDate>
      <link>https://forem.com/viissgg/the-clean-framework-a-5-step-blueprint-for-writing-bug-free-maintainable-javascript-code-36i7</link>
      <guid>https://forem.com/viissgg/the-clean-framework-a-5-step-blueprint-for-writing-bug-free-maintainable-javascript-code-36i7</guid>
      <description>&lt;p&gt;Friday evening with the bug. What a scary dream.&lt;/p&gt;

&lt;p&gt;No, it's not a dream. It can happen. In fact, it happens so often that you start wondering about yourself and your team's skills.&lt;/p&gt;

&lt;p&gt;How can you minimise the bug, by the way?&lt;/p&gt;

&lt;p&gt;I have devised a framework to rescue you—the &lt;strong&gt;CLEAN Framework&lt;/strong&gt; for Clean Code.&lt;/p&gt;

&lt;h3&gt;
  
  
  C → Consistency is the king.
&lt;/h3&gt;

&lt;p&gt;Make your code consistent. What that means, if you asked?&lt;/p&gt;

&lt;p&gt;When you start solving the bug, you see the variable names x, y, and z. You are wondering what the hell those are. You trace back all the places it is used and come to know that it is for updating the name, address and email variable. Now, you are cursing yourself as to why you have used x, y, and z instead of a racial variable name to waste your precious Friday evening on a unavoidable bug.&lt;/p&gt;

&lt;p&gt;So, what to do?&lt;/p&gt;

&lt;p&gt;In my way, follow a style guide. Like Airbnb or Google does. I prefer Airbnb.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Airbnb Style Guide&lt;/strong&gt; - &lt;a href="https://github.com/airbnb/javascript" rel="noopener noreferrer"&gt;https://github.com/airbnb/javascript&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Google Style Guide&lt;/strong&gt; - &lt;a href="https://google.github.io/styleguide/jsguide.html" rel="noopener noreferrer"&gt;https://google.github.io/styleguide/jsguide.html&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  L → Lean Functions and Modules
&lt;/h3&gt;

&lt;p&gt;Break it down now, y'all!&lt;/p&gt;

&lt;p&gt;Wondering what and why I'm suggesting to breaking things up?&lt;/p&gt;

&lt;p&gt;Well, Cool down. I'm not saying to break the keyboard in front of you. I suggest breaking down the more extended functions you wrote, which are now difficult to read and understand what's going on. Break it down so that each function does and does one thing well—like a helper function, helping your original function code.&lt;/p&gt;

&lt;p&gt;Small, focused functions are the secret sauce of maintainable code.&lt;/p&gt;

&lt;h3&gt;
  
  
  E → Efficient Optimisation
&lt;/h3&gt;

&lt;p&gt;Speed is necessary, but not at the expense of readability and bug-free code.&lt;/p&gt;

&lt;p&gt;I know, I know. You will say, I have to complete that feature faster as the deadline is near. Now I will ask you how you gonna solve that bug with the same lightning speed you wrote the original code.&lt;/p&gt;

&lt;p&gt;Not easy. Right?&lt;/p&gt;

&lt;p&gt;But here is this. Start with writing your feature. Once you are done and before you push your code for review, ask yourself how you can optimise the code. Should I have used &lt;code&gt;map&lt;/code&gt; instead of &lt;code&gt;forEach&lt;/code&gt;? Should I have used &lt;code&gt;for...of&lt;/code&gt; loop instead of &lt;code&gt;for&lt;/code&gt; loop?&lt;/p&gt;

&lt;p&gt;Optimised code is happy code, and happy code makes for happy developers.&lt;/p&gt;

&lt;h3&gt;
  
  
  A → Antique Code Care
&lt;/h3&gt;

&lt;p&gt;Legacy codes are boring, but actually, they are viable antiques.&lt;/p&gt;

&lt;p&gt;Someone spends a lot of time understanding the requirement and making it work. You are right; sometimes, it is not the best optimised and readable code. But now it's in your hands to make it right. If time allows, refactor it slowly and steadily. Take one step at a time to keep the original features intact.&lt;/p&gt;

&lt;p&gt;Respect the legacy, but don't be afraid to nudge it into the future gently.&lt;/p&gt;

&lt;h3&gt;
  
  
  N → New Feature Adoption
&lt;/h3&gt;

&lt;p&gt;There is the reason why ES6+ feature keep adding.&lt;/p&gt;

&lt;p&gt;They are not just shiny new toys; they are the new superpower of writing cleaner and more efficient code. Arrow functions, destructuring, and template literals are the Swiss Army knife of JavaScript. And let's not forget about asynchronous programming. Promises and async/await are like traffic controllers for your code, keeping everything flowing smoothly without any pile-ups.&lt;/p&gt;

&lt;p&gt;Modern features make your code more expressive and your life easier.&lt;/p&gt;

&lt;h3&gt;
  
  
  Bonus: Test, Debug, Repeat
&lt;/h3&gt;

&lt;p&gt;A well-tested codebase is a happy codebase.&lt;/p&gt;

&lt;p&gt;How do you feel when you go for a blood test and find nothing major? Yeah, the codebase can feel the same way if you imagine it. In fact, if the code is well tested, there is less chance of getting a bug on Friday evening.&lt;/p&gt;

&lt;p&gt;Writing tests are bonus, but it is a must to have.&lt;/p&gt;

&lt;p&gt;Remember, you've got this! You're well-equipped to tackle any JavaScript challenge with the CLEAN framework (Consistency, Lean modules, Efficient optimisation, Antique code care, and New feature adoption). Now go forth and code like the JavaScript ninja you are!&lt;/p&gt;

&lt;p&gt;If you have enjoyed reading this, follow me on &lt;a href="https://twitter.com/ViiSSGG" rel="noopener noreferrer"&gt;Twitter/X&lt;/a&gt; to read more.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>cleancode</category>
      <category>webdev</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Difference Between Jest, Enzyme and React Testing Library</title>
      <dc:creator>Vijay</dc:creator>
      <pubDate>Thu, 02 May 2024 14:49:58 +0000</pubDate>
      <link>https://forem.com/viissgg/difference-between-jest-enzyme-and-react-testing-library-7ki</link>
      <guid>https://forem.com/viissgg/difference-between-jest-enzyme-and-react-testing-library-7ki</guid>
      <description>&lt;p&gt;Jest, Enzyme, and React Testing Library (RTL) are popular tools for testing React applications, but they serve different purposes and have different philosophies.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Jest:&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Jest is a testing framework developed by Facebook. &lt;/p&gt;

&lt;p&gt;It's widely used for testing JavaScript code, including React applications. Jest is known for its simplicity and ease of use. It's an all-in-one solution for testing, providing utilities for test runners, assertions, mocking, and code coverage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Jest's key features include:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Test Runners&lt;/strong&gt;: Jest provides a test runner that executes test cases and provides results.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Assertions&lt;/strong&gt;: It includes built-in assertion utilities to verify the correctness of the code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Mocking&lt;/strong&gt;: Jest allows easy mocking of modules and functions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Snapshots&lt;/strong&gt;: It supports snapshot testing, which captures the output of a component and compares it to a previously saved version.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Code Coverage&lt;/strong&gt;: Jest can generate code coverage reports to help identify untested code.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// sum.js&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// sum.test.js&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./sum&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;adds 1 + 2 to equal 3&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;toBe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// Snapshot testing a React component&lt;/span&gt;
&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;renders a button correctly&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;getByText&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Click Me&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;);&lt;/span&gt;
    &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;getByText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Click Me&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;toMatchSnapshot&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Enzyme:&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Enzyme is a testing utility for React developed by Airbnb. &lt;/p&gt;

&lt;p&gt;It provides tools to make testing React components easier and more intuitive. Enzyme focuses on component-level testing, allowing you to shallow or deep render components and interact with them in tests.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Enzyme's key features include:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Shallow Rendering&lt;/strong&gt;: Rendering only the component and not its children, useful for isolating unit tests.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Full DOM Rendering&lt;/strong&gt;: Rendering the full DOM, including child components, for more comprehensive integration testing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Component Interactions&lt;/strong&gt;: Enzyme allows you to simulate user interactions such as clicks and input changes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Assertions&lt;/strong&gt;: While Enzyme itself doesn't include assertion utilities, it's often used in conjunction with Jest or other assertion libraries.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// MyComponent.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;MyComponent&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Click me&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;MyComponent&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// MyComponent.test.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;shallow&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;enzyme&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;MyComponent&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./MyComponent&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click event&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mockFn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;jest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;wrapper&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;shallow&lt;/span&gt;&lt;span class="p"&gt;(&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;MyComponent&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;mockFn&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;wrapper&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;button&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;simulate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mockFn&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toHaveBeenCalled&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;React Testing Library (RTL):&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;React Testing Library is a lightweight testing library for React developed by Kent C. Dodds. &lt;/p&gt;

&lt;p&gt;It promotes writing tests that resemble how users interact with your application. RTL encourages testing components in the way they are used by end-users, focusing on behavior rather than implementation details.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;RTL's key features include:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Queries&lt;/strong&gt;: RTL provides a set of query methods to select elements in the DOM, similar to how users would find elements.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Accessibility&lt;/strong&gt;: It emphasizes testing accessibility features, ensuring your components are usable by all users.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No Component API&lt;/strong&gt;: RTL doesn't provide utilities for manipulating or inspecting components directly, encouraging testing from the user's perspective.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Integration with Jest&lt;/strong&gt;: While RTL can be used with any test runner, it integrates seamlessly with Jest.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example RTL Test:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// MyComponent.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;MyComponent&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Click me&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;MyComponent&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// MyComponent.test.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;fireEvent&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@testing-library/react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;MyComponent&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./MyComponent&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click event&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mockFn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;jest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;getByText&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;MyComponent&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;mockFn&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;fireEvent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;click&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;getByText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Click me&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mockFn&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toHaveBeenCalled&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Choosing the right tool depends on your project's needs:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Jest:&lt;/strong&gt; If you need a general-purpose testing framework for JavaScript, including React components, Jest is a solid choice.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Enzyme:&lt;/strong&gt; If you need to test complex React components with intricate internal state or logic, Enzyme can be helpful.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;React Testing Library:&lt;/strong&gt; If you prioritize testing from a user's perspective and want to ensure that components behave as expected in response to user interactions, React Testing Library is often preferred.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In many cases, a combination of these tools can be effective, using Jest as the test runner, React Testing Library for user-facing behavior, and Enzyme for specific situations where testing internal state is necessary.&lt;/p&gt;

</description>
      <category>react</category>
      <category>testing</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>3 Key Steps of Diffing Algorithm in React for Efficiently Updating the Real DOM</title>
      <dc:creator>Vijay</dc:creator>
      <pubDate>Wed, 01 May 2024 14:10:57 +0000</pubDate>
      <link>https://forem.com/viissgg/3-key-steps-of-diffing-algorithm-in-react-for-efficiently-updating-the-real-dom-oea</link>
      <guid>https://forem.com/viissgg/3-key-steps-of-diffing-algorithm-in-react-for-efficiently-updating-the-real-dom-oea</guid>
      <description>&lt;p&gt;Ever wondered how React's diffing algorithm manages to efficiently update the real DOM ?&lt;/p&gt;

&lt;p&gt;React's diffing algorithm is a crucial mechanism that efficiently updates the real DOM based on changes in the virtual DOM. It plays a significant role in React's performance optimization by minimizing the number of DOM manipulations required.&lt;/p&gt;

&lt;p&gt;Here are the 3 key steps.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Virtual Dom Generation
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;After a state or prop change, React creates a new virtual DOM tree that reflects the updated UI state.&lt;/li&gt;
&lt;li&gt;Virtual DOM is a lightweight in-memory representation of the UI.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2. Recursive Comparison
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;React's diffing algorithm recursively compares the root nodes of the previous and new virtual DOM trees.&lt;/li&gt;
&lt;li&gt;It employs a heuristic approach with the following key principles:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Element Type:&lt;/strong&gt; If elements have different types (e.g., &lt;code&gt;div&lt;/code&gt; vs. &lt;code&gt;span&lt;/code&gt;), they are considered entirely different and replaced.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Key Prop:&lt;/strong&gt; If elements have the same type and a &lt;code&gt;key&lt;/code&gt; prop, React assumes their order and identity are significant. It rearranges or replaces elements based on key changes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Text Content:&lt;/strong&gt; If elements have the same type and no &lt;code&gt;key&lt;/code&gt; prop, React compares their text content. If different, the element's text is updated.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Attributes:&lt;/strong&gt; If elements have the same type and content, React compares their attributes. If any attributes differ, the corresponding DOM element's attributes are updated.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  3. DOM Reconciliation
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Based on the diffing results, React determines the minimal set of DOM operations needed to bring the actual DOM in sync with the virtual DOM.&lt;/li&gt;
&lt;li&gt;This might involve:

&lt;ul&gt;
&lt;li&gt;Inserting new DOM nodes.&lt;/li&gt;
&lt;li&gt;Updating existing DOM nodes (e.g., text content, attributes).&lt;/li&gt;
&lt;li&gt;Removing DOM nodes that are no longer present in the virtual DOM.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Time and Space Complexity
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Naive Approach
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;In worst case, comparing two trees has a time complexity of O(n^3), where n is the number of nodes.&lt;/li&gt;
&lt;li&gt;This can be computationally expensive for large trees.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  React's Heuristic Approach:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;To achieve efficient diffing, React employs a heuristic approach that leverages the following optimizations:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Key Prop:&lt;/strong&gt; React uses the &lt;code&gt;key&lt;/code&gt; prop to uniquely identify nodes across different renders. This allows the algorithm to track node movements and updates more efficiently.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Structural Assumptions:&lt;/strong&gt; React assumes that elements of different types will produce different trees, reducing the need for extensive comparisons.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Depth-First Traversal:&lt;/strong&gt; React traverses the trees in a depth-first manner, focusing on the first child node before moving to siblings. This helps in early detection of changes and potential optimizations.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Through these optimizations, React's diffing algorithm achieves a time complexity of O(n) in most practical scenarios, making it significantly faster than the naive approach.&lt;/li&gt;

&lt;li&gt;The space complexity of React's diffing algorithm is generally O(n), as it requires memory to store the virtual DOM trees and the diffing results.&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;Consider the following simple React component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;MyComponent&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;You clicked &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; times&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Click me&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;When the &lt;code&gt;count&lt;/code&gt; state changes, React creates a new virtual DOM with the updated value. The diffing algorithm then compares the virtual DOM with the real DOM:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Root Comparison:&lt;/strong&gt; Both roots are &lt;code&gt;div&lt;/code&gt; elements, so the comparison moves to the child elements.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Recursive Comparison:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;p&lt;/code&gt; elements are compared. The text content has changed, so the real DOM element is updated.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;button&lt;/code&gt; elements are compared. They are the same type, so their props are compared. The &lt;code&gt;onClick&lt;/code&gt; handler is the same, so no change is needed.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;As a result, only the text content of the &lt;code&gt;p&lt;/code&gt; element is updated in the real DOM, minimizing unnecessary DOM manipulations.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Key Points:&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The diffing algorithm is essential for React's efficient DOM updates.&lt;/li&gt;
&lt;li&gt;It minimizes the number of DOM manipulations, leading to better performance and responsiveness.&lt;/li&gt;
&lt;li&gt;React uses heuristics and optimizations to achieve near-linear time complexity.&lt;/li&gt;
&lt;li&gt;The time complexity is typically O(n).&lt;/li&gt;
&lt;li&gt;Understanding the diffing algorithm can help you write React components that are more performant and efficient.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>react</category>
      <category>frontend</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
