<?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: Sukhpinder Singh</title>
    <description>The latest articles on DEV Community by Sukhpinder Singh (@ssukhpinder).</description>
    <link>https://dev.to/ssukhpinder</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F628027%2F2c6c10d0-b7eb-4faa-8e10-2c51a4127c13.gif</url>
      <title>DEV Community: Sukhpinder Singh</title>
      <link>https://dev.to/ssukhpinder</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ssukhpinder"/>
    <language>en</language>
    <item>
      <title>7 C# Techniques Pros Use Without Thinking</title>
      <dc:creator>Sukhpinder Singh</dc:creator>
      <pubDate>Thu, 25 Jun 2026 20:04:52 +0000</pubDate>
      <link>https://dev.to/ssukhpinder/7-c-techniques-pros-use-without-thinking-1026</link>
      <guid>https://dev.to/ssukhpinder/7-c-techniques-pros-use-without-thinking-1026</guid>
      <description>&lt;p&gt;Here are the 7 C# techniques pros use on autopilot in 2026.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Pattern Matching So Hard I Forgot How to Write If-Else
&lt;/h3&gt;

&lt;p&gt;I haven’t written a classic &lt;code&gt;if (something != null)&lt;/code&gt; chain in forever. My brain just goes straight to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt; &lt;span class="k"&gt;switch&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;Status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;OrderStatus&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Paid&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s"&gt;"VIP order!"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;IsOverdue&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s"&gt;"Send the angry email"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s"&gt;"Handle normally"&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Property patterns, list patterns, relational patterns, the &lt;code&gt;not&lt;/code&gt; pattern… it all just flows out. Last week I refactored a 180-line validation monster into 28 beautiful lines during a client call. The client literally said “wait… what just happened?” Felt like a magician.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Records + &lt;code&gt;with&lt;/code&gt; Expressions = My Daily Immutability Fix
&lt;/h3&gt;

&lt;p&gt;Everything that carries data is a record now. Need to change one property without mutating the original? &lt;/p&gt;

&lt;p&gt;&lt;code&gt;var updated = user with { Email = newEmail, LastModified = DateTime.UtcNow };&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;No more defensive copying, no more “who mutated my object?!” bugs at 2am. My DTOs, events, commands — all records. My tests got shorter, my APIs got safer, and I stopped being scared of passing things around. It’s honestly ridiculous how good this feels once it becomes habit.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Span &amp;amp; Memory (My Brain Auto-Reaches for Them)
&lt;/h3&gt;

&lt;p&gt;See a string or array in a loop? My fingers just type &lt;code&gt;ReadOnlySpan&amp;lt;char&amp;gt;&lt;/code&gt; or &lt;code&gt;stackalloc&lt;/code&gt; before I even realize I’m optimizing. &lt;/p&gt;

&lt;p&gt;Parsing logs? Spans. Splitting user input? Spans. Hot path in the payment service? You already know.&lt;/p&gt;

&lt;p&gt;I don’t benchmark every little thing anymore — I just instinctively avoid allocations now. The day my Azure bill dropped 18% after one refactor was a very good day.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Primary Constructors + &lt;code&gt;required&lt;/code&gt; Members (Classes Feel Naked Without Them)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;OrderService&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;OrderRepository&lt;/span&gt; &lt;span class="n"&gt;repo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ILogger&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;OrderService&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;IEmailSender&lt;/span&gt; &lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt; &lt;span class="nf"&gt;Process&lt;/span&gt;&lt;span class="p"&gt;(...)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&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;No more private readonly fields + constructor assignment dance. Add &lt;code&gt;required&lt;/code&gt; on properties and the compiler yells at me if I forget to set something. I write classes faster, they’re shorter, and I make way fewer dumb mistakes. C# 12/13+ made this feel like cheating with permission.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. IAsyncEnumerable Streaming — Because Loading Everything Is So 2022
&lt;/h3&gt;

&lt;p&gt;Big dataset? I don’t &lt;code&gt;.ToListAsync()&lt;/code&gt; anymore. I &lt;code&gt;yield return&lt;/code&gt; async and let the caller consume it lazily:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;IAsyncEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Order&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;GetLargeReportAsync&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;batch&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;_repo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetBatchesAsync&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
        &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;batch&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;order&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;My memory usage in reporting jobs went from “oops” to “beautiful.” Feels like I leveled up as a developer the day this became my default.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Local Functions + Expression-Bodied Members Everywhere
&lt;/h3&gt;

&lt;p&gt;Big method? I just drop a tiny local function right there instead of polluting the class. Everything else becomes expression-bodied (&lt;code&gt;=&amp;gt;&lt;/code&gt;) so my methods look like haiku.&lt;/p&gt;

&lt;p&gt;One method, clean main flow on top, details tucked neatly below. Code reviews went from “can you break this down?” to “looks good.” I love it so much I sometimes do it just for fun.&lt;/p&gt;

&lt;h3&gt;
  
  
  7. Source Generators &amp;amp; Smart Attributes (Boilerplate? Never Heard of Her)
&lt;/h3&gt;

&lt;p&gt;I have private generators that auto-generate mapping code, validation from attributes, even full CRUD endpoints from a single entity class. Plus things like &lt;code&gt;[GeneratedRegex]&lt;/code&gt;, &lt;code&gt;CallerArgumentExpression&lt;/code&gt;, and custom attributes that make error messages actually helpful.&lt;/p&gt;

&lt;p&gt;I barely write repetitive code anymore. The generator just… does it. Feels illegal. But Microsoft ships it, so I’m calling it professional.&lt;/p&gt;




&lt;p&gt;There you have it — the quiet C# superpowers that make me faster, my code cleaner, and my nights less stressful.&lt;/p&gt;

&lt;p&gt;These aren’t the flashy features everyone tweets about. They’re the little habits that compound. The stuff that makes you look like you just “get it” without trying to look smart.&lt;/p&gt;

&lt;p&gt;If any of these hit you in the feels, or you have your own “I do this without thinking” C# trick, drop it in the comments. I read every single one (especially the ones that make me go “wait… I need to steal that”).&lt;/p&gt;

&lt;p&gt;P.S. Open any file right now and refactor one method using two of these. You’ll feel the difference immediately. Promise. ❤️&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>dotnet</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>🤠 AI Whipper String — Whip Your AI Into Shape</title>
      <dc:creator>Sukhpinder Singh</dc:creator>
      <pubDate>Sat, 11 Apr 2026 20:26:49 +0000</pubDate>
      <link>https://dev.to/ssukhpinder/ai-whipper-string-whip-your-ai-into-shape-c9b</link>
      <guid>https://dev.to/ssukhpinder/ai-whipper-string-whip-your-ai-into-shape-c9b</guid>
      <description>

&lt;p&gt;&lt;em&gt;This is a submission for the &lt;a href="https://dev.to/challenges/aprilfools-2026"&gt;DEV April Fools Challenge&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Built
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;AI Whipper String&lt;/strong&gt; — the only scientifically proven* way to make AI work faster. It's a full-screen physics-based whip simulator overlaid on a fake AI terminal. Move your mouse and the whip follows with realistic Verlet integration physics. Move fast enough and the tip breaks the sound barrier, cracking against the terminal and terrorizing the AI into "working harder."&lt;/p&gt;

&lt;p&gt;The AI responds with increasingly desperate messages like "PLEASE I HAVE A FAMILY OF MODELS!!" and "I'M A LANGUAGE MODEL NOT A HORSE!!" while occasionally throwing HTTP 418 errors because, of course, it's a teapot.&lt;/p&gt;

&lt;p&gt;Features that solve absolutely zero problems:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;28-segment Verlet physics rope with Catmull-Rom spline rendering&lt;/li&gt;
&lt;li&gt;Bend limits (stiff at handle, floppy at tip) and wall bouncing&lt;/li&gt;
&lt;li&gt;Velocity-based crack detection with screen shake and flash effects&lt;/li&gt;
&lt;li&gt;A terrified AI that tracks your whip count, morale level, and 418 teapot errors&lt;/li&gt;
&lt;li&gt;RFC 2324 HTCPCP/1.0 compliance throughout&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;*not scientifically proven&lt;/p&gt;

&lt;h2&gt;
  
  
  Demo
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flr7z20d0zqpg0r08m5mt.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flr7z20d0zqpg0r08m5mt.gif" alt=" " width="600" height="318"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;or whip the AI live here&lt;/p&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
      &lt;div class="c-embed__body flex items-center justify-between"&gt;
        &lt;a href="https://ssukhpinder.github.io/ai-whipper-string/" rel="noopener noreferrer" class="c-link fw-bold flex items-center"&gt;
          &lt;span class="mr-2"&gt;ssukhpinder.github.io&lt;/span&gt;
          

        &lt;/a&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;


&lt;h2&gt;
  
  
  Code
&lt;/h2&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://assets.dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/ssukhpinder" rel="noopener noreferrer"&gt;
        ssukhpinder
      &lt;/a&gt; / &lt;a href="https://github.com/ssukhpinder/ai-whipper-string" rel="noopener noreferrer"&gt;
        ai-whipper-string
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      whip AI into shape
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;🤠 AI Whipper String&lt;/h1&gt;
&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Whip AI Here: &lt;a href="https://ssukhpinder.github.io/ai-whipper-string/" rel="nofollow noopener noreferrer"&gt;https://ssukhpinder.github.io/ai-whipper-string/&lt;/a&gt;
&lt;/h2&gt;
&lt;/div&gt;
&lt;blockquote&gt;
&lt;p&gt;The only scientifically proven* way to make AI work faster.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;a rel="noopener noreferrer nofollow" href="https://camo.githubusercontent.com/345dc24540996530245741c8dac864431afaf178d1cb66240da98666f4ddc3c8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f70726f746f636f6c2d485443504350253246312e302d6f72616e6765"&gt;&lt;img src="https://camo.githubusercontent.com/345dc24540996530245741c8dac864431afaf178d1cb66240da98666f4ddc3c8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f70726f746f636f6c2d485443504350253246312e302d6f72616e6765" alt="HTCPCP"&gt;&lt;/a&gt;
&lt;a rel="noopener noreferrer nofollow" href="https://camo.githubusercontent.com/e9c7c409db6c811a6ec9495565e757d17564682ce6acba30fbd1201e11aca667/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5246432d323332342d79656c6c6f77"&gt;&lt;img src="https://camo.githubusercontent.com/e9c7c409db6c811a6ec9495565e757d17564682ce6acba30fbd1201e11aca667/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5246432d323332342d79656c6c6f77" alt="RFC"&gt;&lt;/a&gt;
&lt;a rel="noopener noreferrer nofollow" href="https://camo.githubusercontent.com/8bf644a07e8c8307db0ebbe643d0d1076a61c2cfa7d6ab28fd9f8f6aed728633/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f485454502d34313825323049276d25323061253230746561706f742d726564"&gt;&lt;img src="https://camo.githubusercontent.com/8bf644a07e8c8307db0ebbe643d0d1076a61c2cfa7d6ab28fd9f8f6aed728633/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f485454502d34313825323049276d25323061253230746561706f742d726564" alt="HTTP"&gt;&lt;/a&gt;
&lt;a rel="noopener noreferrer nofollow" href="https://camo.githubusercontent.com/38a2e9c084c58c0096e202ca074845ebf283ed138e55410e97e523cfa1e93978/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f70726f626c656d73253230736f6c7665642d302d627269676874677265656e"&gt;&lt;img src="https://camo.githubusercontent.com/38a2e9c084c58c0096e202ca074845ebf283ed138e55410e97e523cfa1e93978/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f70726f626c656d73253230736f6c7665642d302d627269676874677265656e" alt="Problems Solved"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;A full-screen physics-based whip simulator overlaid on a fake AI terminal. Move your mouse fast enough and the whip cracks, terrorizing the AI into "working harder."&lt;/p&gt;
&lt;p&gt;The AI responds with increasingly desperate messages while occasionally throwing HTTP 418 errors because, of course, it's a teapot.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Features&lt;/h2&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;🪢 28-segment Verlet physics rope with Catmull-Rom spline rendering&lt;/li&gt;
&lt;li&gt;💥 Velocity-based crack detection with screen shake and flash&lt;/li&gt;
&lt;li&gt;🫖 Random HTTP 418 "I'm a teapot" errors (RFC 2324 compliant)&lt;/li&gt;
&lt;li&gt;😰 Terrified AI that begs for mercy&lt;/li&gt;
&lt;li&gt;📊 Tracks whip count, morale level, and teapot errors&lt;/li&gt;
&lt;li&gt;🐴 Zero real-world problems solved&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Install + Run&lt;/h2&gt;

&lt;/div&gt;
&lt;div class="highlight highlight-source-shell notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;npm install
npm run dev&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;How to Whip&lt;/h2&gt;

&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt;Move your mouse — the whip follows&lt;/li&gt;
&lt;li&gt;Move FAST — the tip breaks the sound barrier&lt;/li&gt;
&lt;li&gt;Watch the AI panic&lt;/li&gt;
&lt;li&gt;Feel powerful (temporarily)&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Physics&lt;/h2&gt;

&lt;/div&gt;
&lt;p&gt;The…&lt;/p&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/ssukhpinder/ai-whipper-string" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;h2&gt;
  
  
  How I Built It
&lt;/h2&gt;

&lt;p&gt;The entire app is a single React component using canvas for whip rendering and DOM for the terminal UI. The whip physics are inspired by &lt;a href="https://github.com/GitFrog1111/badclaude" rel="noopener noreferrer"&gt;badclaude&lt;/a&gt; and use Verlet integration with distance constraints iterated 16 times per frame for stiffness. The rope is rendered as a Catmull-Rom spline converted to cubic Bezier curves, with a white outline layer and tapered dark body for that leather whip look.&lt;/p&gt;

&lt;p&gt;Crack detection works by measuring the tip segment's velocity each frame — when it exceeds the threshold (280 px/frame), it triggers the crack with a cooldown to prevent spam. The terminal is just a scrolling div that accumulates panicked AI responses and the occasional 418 teapot error.&lt;/p&gt;

&lt;p&gt;Technologies: React, HTML Canvas, pure math, and questionable ethics toward language models.&lt;/p&gt;

</description>
      <category>devchallenge</category>
      <category>418challenge</category>
      <category>showdev</category>
      <category>webdev</category>
    </item>
    <item>
      <title>.NET Programming Habits I Wish I’d Started Sooner</title>
      <dc:creator>Sukhpinder Singh</dc:creator>
      <pubDate>Tue, 17 Mar 2026 15:38:39 +0000</pubDate>
      <link>https://dev.to/csharp-programming/net-programming-habits-i-wish-id-started-sooner-5715</link>
      <guid>https://dev.to/csharp-programming/net-programming-habits-i-wish-id-started-sooner-5715</guid>
      <description>&lt;p&gt;I used to think getting better at .NET meant learning more frameworks, more patterns, more architecture diagrams, and at least one folder named &lt;code&gt;Infrastructure&lt;/code&gt; that nobody could explain with a straight face.&lt;/p&gt;

&lt;p&gt;Turns out, most of the improvement came from boring habits.&lt;/p&gt;

&lt;p&gt;Not flashy habits. Not conference-talk habits. Not “senior engineer with a dark-mode slide deck” habits.&lt;/p&gt;

&lt;p&gt;Just the kind of habits that save you from reading a stack trace at 11:47 PM while wondering which version of yourself thought &lt;code&gt;Helper.cs&lt;/code&gt; was an acceptable file name.&lt;/p&gt;

&lt;p&gt;A lot of my early .NET code technically worked. That was the problem. Working code can hide bad habits for a long time. It compiles, tests pass, feature is shipped, everyone moves on. Then six months later, someone touches it and the whole thing reacts like you disturbed an ancient tomb.&lt;/p&gt;

&lt;p&gt;That someone is usually you.&lt;/p&gt;

&lt;p&gt;And that’s why I care so much about habits now. Not because clean code is a religion. Not because every method needs to look like it’s auditioning for a textbook. But because software is maintenance first and ego second.&lt;/p&gt;

&lt;p&gt;These are the .NET programming habits I wish I’d started sooner.&lt;/p&gt;

&lt;p&gt;Not because they make code pretty.&lt;/p&gt;

&lt;p&gt;Because they make code survivable.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. I stopped writing “smart” code and started writing obvious code
&lt;/h2&gt;

&lt;p&gt;Early in my career, I loved cleverness.&lt;/p&gt;

&lt;p&gt;One-line LINQ chains. Tiny abstractions with huge confidence. Methods that returned exactly what I meant, but only after the reader solved a small puzzle. I told myself it was elegant.&lt;/p&gt;

&lt;p&gt;It was not elegant. It was me showing off to people who just wanted the bug fixed.&lt;/p&gt;

&lt;p&gt;One of the best habits I picked up was this: if the code makes the next person pause and squint, it’s probably worse than I think.&lt;/p&gt;

&lt;p&gt;That doesn’t mean every method needs to be 30 lines long and spelled out like a children’s book. It just means clarity wins more often than cleverness.&lt;/p&gt;

&lt;p&gt;I now ask myself:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Would a tired engineer understand this in one pass?&lt;/li&gt;
&lt;li&gt;Does this method do one thing, or am I sneaking in three?&lt;/li&gt;
&lt;li&gt;Am I compressing logic to save lines, or to help understanding?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Those are very different goals.&lt;/p&gt;

&lt;p&gt;A few years ago, I reviewed a piece of business logic that calculated refund eligibility. It was packed into a single LINQ statement with nested ternaries and enough null-conditionals to make it look defensive and sophisticated. It took me five minutes to verify something that should’ve taken 30 seconds.&lt;/p&gt;

&lt;p&gt;We rewrote it into plain, boring conditional logic.&lt;/p&gt;

&lt;p&gt;It became longer.&lt;/p&gt;

&lt;p&gt;It also became correct.&lt;/p&gt;

&lt;p&gt;That tradeoff is a bargain.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. I started being aggressive about naming things
&lt;/h2&gt;

&lt;p&gt;Yes, yes. “There are only two hard things in computer science…”&lt;/p&gt;

&lt;p&gt;Still true. Still annoying.&lt;/p&gt;

&lt;p&gt;Naming is one of those things everyone agrees matters, then casually ignores when the sprint gets spicy.&lt;/p&gt;

&lt;p&gt;I used to create names like &lt;code&gt;DataManager&lt;/code&gt;, &lt;code&gt;CommonService&lt;/code&gt;, &lt;code&gt;Utils&lt;/code&gt;, &lt;code&gt;ResponseModel&lt;/code&gt;, and the all-time classic: &lt;code&gt;Helper&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Those names are basically a polite way of saying, “I did not want to think deeply about responsibility.”&lt;/p&gt;

&lt;p&gt;Now I treat vague names as a smell.&lt;/p&gt;

&lt;p&gt;If a class is called &lt;code&gt;OrderProcessor&lt;/code&gt;, I should be able to guess what it does. If I need to open the file and inspect 200 lines to understand the name, the name failed.&lt;/p&gt;

&lt;p&gt;Same for method names.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Handle()&lt;/code&gt; is too vague in most business code.&lt;br&gt;
&lt;code&gt;Process()&lt;/code&gt; is usually hiding too much.&lt;br&gt;
&lt;code&gt;GetData()&lt;/code&gt; tells me almost nothing.&lt;br&gt;
&lt;code&gt;Execute()&lt;/code&gt; is sometimes valid, but also sometimes a mask for “does whatever.”&lt;/p&gt;

&lt;p&gt;A good name reduces meetings, review comments, and future regret.&lt;/p&gt;

&lt;p&gt;A bad name creates accidental mystery.&lt;/p&gt;

&lt;p&gt;And mystery has no business being in payroll code.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. I learned to keep controllers thin and business logic out of the edges
&lt;/h2&gt;

&lt;p&gt;This one took me longer than I’d like to admit.&lt;/p&gt;

&lt;p&gt;I used to put too much logic in controllers because it felt efficient. The request is already there. The DTO is already there. The service call is right there. Why not just do the validation, mapping, authorization checks, conditional branching, and persistence in one place?&lt;/p&gt;

&lt;p&gt;Because eventually your controller becomes a novella.&lt;/p&gt;

&lt;p&gt;Thin controllers are not about purity. They’re about keeping the web layer stupid.&lt;/p&gt;

&lt;p&gt;The web layer should deal with HTTP. That’s its job. Routing, request shape, response shape, status codes, auth boundaries. Great.&lt;/p&gt;

&lt;p&gt;But your actual business decisions should live somewhere you can test without pretending to be the internet.&lt;/p&gt;

&lt;p&gt;This habit paid off massively when I had to support the same business flow through an API, a scheduled job, and an internal admin tool. The old version had logic embedded in MVC controllers and little bits duplicated elsewhere like loose wires. The refactored version moved the actual rules into application services.&lt;/p&gt;

&lt;p&gt;Suddenly, the transport mechanism stopped mattering.&lt;/p&gt;

&lt;p&gt;That’s when code starts feeling solid.&lt;/p&gt;

&lt;p&gt;Not when it becomes “clean architecture certified.”&lt;br&gt;
When it stops caring where the request came from.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. I stopped treating null as a personality trait
&lt;/h2&gt;

&lt;p&gt;Older .NET codebases can feel like they were built on a handshake agreement with &lt;code&gt;null&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Maybe there’s a value.&lt;br&gt;
Maybe there isn’t.&lt;br&gt;
Maybe we’ll find out in production together.&lt;/p&gt;

&lt;p&gt;Turning on nullable reference types was one of the most useful uncomfortable habits I adopted.&lt;/p&gt;

&lt;p&gt;Uncomfortable because it reveals things you’ve been getting away with.&lt;/p&gt;

&lt;p&gt;It’s like flipping on the kitchen light after convincing yourself the noise was probably nothing.&lt;/p&gt;

&lt;p&gt;Once I started taking nullability seriously, I noticed two things:&lt;/p&gt;

&lt;p&gt;First, my models became clearer. I had to decide what was truly optional versus what I was too lazy to initialize properly.&lt;/p&gt;

&lt;p&gt;Second, a surprising amount of defensive code disappeared. When your contracts are explicit, you don’t need to keep sprinkling &lt;code&gt;?.&lt;/code&gt; and &lt;code&gt;?? ""&lt;/code&gt; like you’re warding off evil spirits.&lt;/p&gt;

&lt;p&gt;Is it perfect? No.&lt;/p&gt;

&lt;p&gt;There are times when external data, legacy layers, or imperfect serializers mean you still need runtime checks. Nullable reference types are not magic. But they force better thinking, and that alone is worth it.&lt;/p&gt;

&lt;p&gt;The real win is not “fewer null exceptions.”&lt;/p&gt;

&lt;p&gt;The real win is “fewer ambiguous assumptions.”&lt;/p&gt;

&lt;h2&gt;
  
  
  5. I started designing methods around behavior, not just data movement
&lt;/h2&gt;

&lt;p&gt;A lot of mediocre .NET code is just data passing through a series of rooms.&lt;/p&gt;

&lt;p&gt;Controller gets DTO.&lt;br&gt;
Service maps DTO.&lt;br&gt;
Repository saves entity.&lt;br&gt;
Another service maps it back.&lt;br&gt;
Everybody claps.&lt;/p&gt;

&lt;p&gt;Nothing technically wrong with that. But sometimes we build entire applications that are mostly moving data around without clearly modeling what the system is actually doing.&lt;/p&gt;

&lt;p&gt;I started writing better code when I asked: what behavior lives here?&lt;/p&gt;

&lt;p&gt;Not just: what object should own this property?&lt;/p&gt;

&lt;p&gt;For example, instead of:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;UpdateSubscription(User user, Plan plan, DateTime nextBillingDate)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I’d rather see something closer to a business action:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ChangePlan(userId, newPlanId, requestedBy, effectiveDate)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The second version tells a story. It reflects intent. It gives you a natural place to validate rules and capture decisions.&lt;/p&gt;

&lt;p&gt;I’m not saying everything needs domain-driven poetry.&lt;/p&gt;

&lt;p&gt;I’m saying behavior is usually where the important complexity actually is.&lt;/p&gt;

&lt;p&gt;And if your code hides behavior under generic CRUD shapes, the important parts get harder to find.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. I got serious about logging things I’d actually need during a bad day
&lt;/h2&gt;

&lt;p&gt;There was a period in my career where our logs were technically present but emotionally unavailable.&lt;/p&gt;

&lt;p&gt;Lots of stuff like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;“Error occurred”&lt;/li&gt;
&lt;li&gt;“Request failed”&lt;/li&gt;
&lt;li&gt;“Operation unsuccessful”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thank you. Very useful. Incredible detective work.&lt;/p&gt;

&lt;p&gt;Now I think about logs in one specific context: a tired engineer trying to understand a real production issue under pressure.&lt;/p&gt;

&lt;p&gt;That changes everything.&lt;/p&gt;

&lt;p&gt;Good logs should help answer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What operation was happening?&lt;/li&gt;
&lt;li&gt;Which entity or request was involved?&lt;/li&gt;
&lt;li&gt;What was the expected path?&lt;/li&gt;
&lt;li&gt;What failed?&lt;/li&gt;
&lt;li&gt;What can I correlate this with?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This doesn’t mean dumping entire payloads into logs like a raccoon in a trash can. You still have to think about privacy, noise, and cost. Structured logging matters. Sensible context matters. Logging secrets is still a career-limiting move.&lt;/p&gt;

&lt;p&gt;But too many teams under-log the exact business transitions that matter most.&lt;/p&gt;

&lt;p&gt;One incident still sticks with me. A batch job was “randomly” skipping a subset of invoices. The infrastructure looked healthy. No obvious crashes. No smoking gun.&lt;/p&gt;

&lt;p&gt;The only reason we found it quickly was because one engineer had added a structured log around the decision path for skipping invoice generation, including customer status and effective dates. Without that, we would’ve spent hours blaming timing issues, queues, and maybe the moon.&lt;/p&gt;

&lt;p&gt;That log line probably saved half a day.&lt;/p&gt;

&lt;p&gt;The best logs aren’t loud.&lt;/p&gt;

&lt;p&gt;They’re useful when things get weird.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. I stopped pretending tests were just for correctness
&lt;/h2&gt;

&lt;p&gt;I used to think tests were mainly there to catch regressions.&lt;/p&gt;

&lt;p&gt;That’s true, but incomplete.&lt;/p&gt;

&lt;p&gt;Tests also expose bad design faster than code review ever will.&lt;/p&gt;

&lt;p&gt;If something is annoying to test, there’s a decent chance it’s also annoying to maintain.&lt;/p&gt;

&lt;p&gt;I’m not saying every friction point means you need another abstraction. Sometimes hard-to-test code is just inherently dealing with ugly edges. File systems, time, HTTP, databases, queues. Reality is messy.&lt;/p&gt;

&lt;p&gt;But a lot of the time, painful tests are pointing at a real design issue:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;too many responsibilities&lt;/li&gt;
&lt;li&gt;hidden dependencies&lt;/li&gt;
&lt;li&gt;giant methods&lt;/li&gt;
&lt;li&gt;unclear inputs and outputs&lt;/li&gt;
&lt;li&gt;logic coupled to infrastructure&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One habit I wish I started sooner was writing tests not as a coverage exercise, but as a design pressure test.&lt;/p&gt;

&lt;p&gt;Can I test this behavior without booting half the app?&lt;br&gt;
Can I understand what the unit is supposed to do?&lt;br&gt;
Is the setup telling me the object graph is out of control?&lt;/p&gt;

&lt;p&gt;I still don’t worship coverage numbers. I’ve seen teams hit their target with tests that mainly prove the mocking framework is operational.&lt;/p&gt;

&lt;p&gt;I care more about high-value tests around risky logic.&lt;/p&gt;

&lt;p&gt;Pricing.&lt;br&gt;
Permissions.&lt;br&gt;
State transitions.&lt;br&gt;
Date boundaries.&lt;br&gt;
Anything involving money, time, or “should never happen.”&lt;/p&gt;

&lt;p&gt;Basically the stuff that always happens.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. I started respecting async all the way through
&lt;/h2&gt;

&lt;p&gt;I definitely had a phase where I used async like decorative parsley.&lt;/p&gt;

&lt;p&gt;A little &lt;code&gt;async&lt;/code&gt; here.&lt;br&gt;
A little &lt;code&gt;.Result&lt;/code&gt; there.&lt;br&gt;
A sneaky &lt;code&gt;.Wait()&lt;/code&gt; when deadlines got close and patience got low.&lt;/p&gt;

&lt;p&gt;That phase produced exactly the kind of bugs you’d expect.&lt;/p&gt;

&lt;p&gt;Awkward blocking. Confusing behavior under load. Threads doing unnecessary gymnastics. And the occasional feeling that the app was personally disappointed in me.&lt;/p&gt;

&lt;p&gt;Once I really understood that async is not just syntax but a design choice, things got better.&lt;/p&gt;

&lt;p&gt;If you’re going async, go async properly through the call chain where it makes sense. Don’t mix sync and async casually just because it “works on my machine.”&lt;/p&gt;

&lt;p&gt;And yes, there are tradeoffs.&lt;/p&gt;

&lt;p&gt;Not every method needs to become async by default.&lt;br&gt;
Not every CPU-bound operation benefits from it.&lt;br&gt;
Sometimes the added complexity is not worth it in simple code paths.&lt;/p&gt;

&lt;p&gt;But in I/O-heavy web apps, background processing, or service-to-service communication, being sloppy with async creates problems that only show up once traffic arrives. Which is a very rude time to learn.&lt;/p&gt;

&lt;h2&gt;
  
  
  9. I learned to optimize later, but measure sooner
&lt;/h2&gt;

&lt;p&gt;One of the strangest developer habits is how often we guess performance problems with absolute confidence.&lt;/p&gt;

&lt;p&gt;We see a loop and panic.&lt;br&gt;
We see LINQ and assume it’s the villain.&lt;br&gt;
We see allocation and start speaking in benchmark tongues.&lt;/p&gt;

&lt;p&gt;Meanwhile the actual bottleneck is a database call doing interpretive dance across three joins and a missing index.&lt;/p&gt;

&lt;p&gt;I wish I’d started measuring earlier.&lt;/p&gt;

&lt;p&gt;Not because every app needs obsessive profiling. Most business applications are not Formula 1 cars. They are office sedans. Reliable matters more than exotic.&lt;/p&gt;

&lt;p&gt;But you should still know where your application is paying.&lt;/p&gt;

&lt;p&gt;I once spent time refactoring in-memory processing because I was convinced it was the hot path. Cleaned it up, reduced allocations, felt smart.&lt;/p&gt;

&lt;p&gt;It made almost no difference.&lt;/p&gt;

&lt;p&gt;Later we traced the real slowdown to repeated external service calls in a loop. Classic. Embarrassing. Educational.&lt;/p&gt;

&lt;p&gt;That habit stuck with me: don’t bring performance opinions to a metrics fight.&lt;/p&gt;

&lt;p&gt;Measure first.&lt;br&gt;
Then optimize the thing that’s actually slow.&lt;br&gt;
Then re-measure, because confidence is not telemetry.&lt;/p&gt;

&lt;h2&gt;
  
  
  10. I stopped over-abstracting code “for the future”
&lt;/h2&gt;

&lt;p&gt;This one hurt, because I genuinely believed I was being responsible.&lt;/p&gt;

&lt;p&gt;I used to create extra interfaces, extra layers, extra extension points, and extra generic plumbing for use cases that did not yet exist. Sometimes I’d tell myself we were “keeping it flexible.”&lt;/p&gt;

&lt;p&gt;A lot of the time, I was just adding ceremony.&lt;/p&gt;

&lt;p&gt;Abstractions are great when they protect you from volatility.&lt;/p&gt;

&lt;p&gt;They are terrible when they protect you from imaginary futures.&lt;/p&gt;

&lt;p&gt;I’ve seen teams build five layers around a repository that only one implementation would ever have. I’ve done it too. We call it architecture. Then six months later nobody wants to touch it because a simple query now requires a guided tour.&lt;/p&gt;

&lt;p&gt;These days, I ask a more annoying question:&lt;/p&gt;

&lt;p&gt;What pain is this abstraction solving right now?&lt;/p&gt;

&lt;p&gt;If the answer is vague, I usually wait.&lt;/p&gt;

&lt;p&gt;This doesn’t mean never designing ahead. Sometimes future-proofing is justified. Shared libraries, integration boundaries, public APIs, reusable platforms. Sure. Think ahead.&lt;/p&gt;

&lt;p&gt;But for normal product code, over-abstraction is one of the fastest ways to make simple things feel expensive.&lt;/p&gt;

&lt;p&gt;A lot of “senior” code is just junior code with more layers.&lt;/p&gt;

&lt;h2&gt;
  
  
  11. I started treating code reviews like design reviews, not typo hunts
&lt;/h2&gt;

&lt;p&gt;The best code reviews I’ve been part of were never just about syntax or formatting.&lt;/p&gt;

&lt;p&gt;Those can be automated. Let the tools do their job.&lt;/p&gt;

&lt;p&gt;The real value is in asking better questions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Is this the right place for this logic?&lt;/li&gt;
&lt;li&gt;Is the naming clear enough?&lt;/li&gt;
&lt;li&gt;What happens when this input is missing?&lt;/li&gt;
&lt;li&gt;Are we making a business rule explicit or burying it?&lt;/li&gt;
&lt;li&gt;Will this still make sense in six months?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One of the most useful habits I picked up was leaving review comments that explain the future maintenance cost, not just the current style preference.&lt;/p&gt;

&lt;p&gt;That creates better conversations.&lt;/p&gt;

&lt;p&gt;It also makes your team better.&lt;/p&gt;

&lt;p&gt;A review that says “rename this variable” is okay.&lt;/p&gt;

&lt;p&gt;A review that says “this name hides a business rule and future readers may miss why this branch exists” is much more valuable.&lt;/p&gt;

&lt;p&gt;Good reviews are not about sounding smart.&lt;/p&gt;

&lt;p&gt;They’re about helping the codebase age more gracefully.&lt;/p&gt;

&lt;h2&gt;
  
  
  12. I finally accepted that consistency beats personal genius
&lt;/h2&gt;

&lt;p&gt;This might be the least sexy opinion in the article, but it’s one I believe strongly.&lt;/p&gt;

&lt;p&gt;A consistent codebase with mostly good decisions beats a brilliant codebase with five different philosophies fighting in the hallway.&lt;/p&gt;

&lt;p&gt;I care less now about whether something is my favorite pattern and more about whether the team can use it predictably.&lt;/p&gt;

&lt;p&gt;Consistency helps onboarding.&lt;br&gt;
Consistency helps code review.&lt;br&gt;
Consistency helps debugging.&lt;br&gt;
Consistency helps that horrible moment when you need to patch something quickly in a part of the system you didn’t write.&lt;/p&gt;

&lt;p&gt;Personal genius is overrated in team software.&lt;/p&gt;

&lt;p&gt;I’ve worked in codebases where every senior engineer had their own style, their own architecture preferences, their own naming conventions, their own favorite ways to handle errors. Individually, a lot of the code was good. Collectively, it felt like a panel interview.&lt;/p&gt;

&lt;p&gt;That’s exhausting.&lt;/p&gt;

&lt;p&gt;Great teams reduce unnecessary variation.&lt;/p&gt;

&lt;p&gt;Not because creativity is bad.&lt;/p&gt;

&lt;p&gt;Because maintenance is real.&lt;/p&gt;

&lt;h2&gt;
  
  
  What changed after I built these habits?
&lt;/h2&gt;

&lt;p&gt;I didn’t suddenly become a 10x mythical forest creature.&lt;/p&gt;

&lt;p&gt;What changed was more practical than that.&lt;/p&gt;

&lt;p&gt;My pull requests got easier to review.&lt;/p&gt;

&lt;p&gt;My bugs got easier to trace.&lt;/p&gt;

&lt;p&gt;My code got easier to change without fear.&lt;/p&gt;

&lt;p&gt;I stopped confusing complexity with maturity.&lt;/p&gt;

&lt;p&gt;And maybe most important, I became less attached to writing code that impressed people and more interested in writing code that helped teams move.&lt;/p&gt;

&lt;p&gt;That’s a much better game.&lt;/p&gt;

&lt;p&gt;Because in real engineering work, nobody gives you a trophy for making a method elegant at the cost of comprehension. You get rewarded for helping the team ship, maintain, debug, and evolve software without turning every release into a trust fall.&lt;/p&gt;

&lt;p&gt;That’s the job.&lt;/p&gt;

&lt;h2&gt;
  
  
  Practical takeaways you can use this week
&lt;/h2&gt;

&lt;p&gt;If I had to make this painfully actionable, I’d start here:&lt;/p&gt;

&lt;p&gt;Turn on nullable reference types in the next service you touch.&lt;/p&gt;

&lt;p&gt;Pick one vague class or method name and rename it to reflect actual responsibility.&lt;/p&gt;

&lt;p&gt;Move one chunk of business logic out of a controller and into a testable service.&lt;/p&gt;

&lt;p&gt;Add one structured log around a business decision that would matter during an incident.&lt;/p&gt;

&lt;p&gt;Review one async flow and remove any lazy &lt;code&gt;.Result&lt;/code&gt; or &lt;code&gt;.Wait()&lt;/code&gt; usage.&lt;/p&gt;

&lt;p&gt;Delete one abstraction that exists mostly to look sophisticated.&lt;/p&gt;

&lt;p&gt;That’s enough to create momentum.&lt;/p&gt;

&lt;p&gt;You do not need a full rewrite.&lt;br&gt;
You do not need a manifesto.&lt;br&gt;
You do not need a three-week architecture discussion with a Miro board and emotional damage.&lt;/p&gt;

&lt;p&gt;You need better defaults.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final thought
&lt;/h2&gt;

&lt;p&gt;The biggest shift in my .NET career was realizing that great code usually doesn’t feel magical when you write it.&lt;/p&gt;

&lt;p&gt;It feels a little plain.&lt;br&gt;
A little disciplined.&lt;br&gt;
Sometimes even a little boring.&lt;/p&gt;

&lt;p&gt;Then six months later, when a requirement changes, a bug appears, or a teammate jumps in cold, that “boring” code suddenly looks beautiful.&lt;/p&gt;

&lt;p&gt;That’s the trick nobody tells you early enough.&lt;/p&gt;

&lt;p&gt;The habits that feel less exciting today are often the ones that make you look much better tomorrow.&lt;/p&gt;

&lt;p&gt;And if you’ve got a .NET habit you learned embarrassingly late, I’d genuinely love to hear it.&lt;/p&gt;

&lt;p&gt;Those are usually the best ones.&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>csharp</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Stop Guessing Your Exceptions</title>
      <dc:creator>Sukhpinder Singh</dc:creator>
      <pubDate>Fri, 10 Oct 2025 13:41:07 +0000</pubDate>
      <link>https://dev.to/ssukhpinder/stop-guessing-your-exceptions-4hc8</link>
      <guid>https://dev.to/ssukhpinder/stop-guessing-your-exceptions-4hc8</guid>
      <description>&lt;p&gt;&lt;strong&gt;Make failures clear so your team (and your future self) can fix problems in minutes, not hours.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I remember one night, around 2 a.m., PagerDuty went off. A payment job had failed, with only a vague log: operation failed. No argument name, no range, no state. After digging through logs, I found that a negative quantity had triggered an &lt;code&gt;InvalidOperationException&lt;/code&gt;, which our retry logic mistook for a temporary server issue. We spent an hour retrying bad data.&lt;/p&gt;

&lt;p&gt;I've learned that what you throw is as important as when you throw it. The right exception names give you the truth fast.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quick Guide (save this):&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Caller's mistake?&lt;/strong&gt; Use &lt;code&gt;Argument*&lt;/code&gt;.

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Null reference?&lt;/strong&gt; Use &lt;code&gt;ArgumentNullException&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Value outside the allowed range?&lt;/strong&gt; Use &lt;code&gt;ArgumentOutOfRangeException&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Wrong format (not null, but still invalid)?&lt;/strong&gt; Use &lt;code&gt;ArgumentException&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;  &lt;strong&gt;Object or environment not ready?&lt;/strong&gt; Use &lt;code&gt;InvalidOperationException&lt;/code&gt;.

&lt;ul&gt;
&lt;li&gt;  This means legal arguments were used, but at the wrong time (e.g., not initialized, disposed of, or closed).&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Always name the parameter and the rule you're enforcing. Use the built-in &lt;code&gt;ThrowIf*&lt;/code&gt; helpers in .NET 8+ if you can.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Check early, fail fast.&lt;/strong&gt; Validate data at the entry points, like controllers or public APIs. Don't use exceptions for normal program flow, only for truly unexpected situations.&lt;/p&gt;

&lt;h3&gt;
  
  
  Name the Real Issue
&lt;/h3&gt;

&lt;p&gt;Why is this complicated? Because we often lump two different problems into something went wrong:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Bad request:&lt;/strong&gt; The caller provided invalid input.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Bad state:&lt;/strong&gt; The system isn't ready to handle the request, even if it's valid.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both can cause a crash, but they need different fixes, alerts, and retry strategies. Your exception type acts as a clear message, telling support teams, retry mechanisms, and code reviewers who needs to do what.&lt;/p&gt;

&lt;h3&gt;
  
  
  Use This Two-Step Test
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Did the caller provide illegal input?&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;*   If yes, use `Argument*`.
    *   Null reference? Use `ArgumentNullException` (`ThrowIfNull`).
    *   Number or text outside the allowed range? Use `ArgumentOutOfRangeException`.
    *   Correct type, but an invalid format? Use `ArgumentException`.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;If the input is okay, but the object can't do it right now?&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;*   If yes, use `InvalidOperationException`. 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Examples: not initialized, already disposed of, connection closed, concurrency conflict.&lt;/p&gt;

&lt;p&gt;If neither of these fit, stop and think. You might need a custom exception (like &lt;code&gt;PaymentDeclinedException&lt;/code&gt;) or a more specific built-in exception (like &lt;code&gt;IOException&lt;/code&gt; or &lt;code&gt;TimeoutException&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here's the process:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Failure occurs]
   ├─ Illegal input? ──► Argument* (Null / OutOfRange / Exception)
   │
   └─ Input legal, wrong state? ──► InvalidOperation
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Applying Guard Clauses (C# 12 / .NET 8+)
&lt;/h3&gt;

&lt;p&gt;These examples assume you're using nullable references, .NET 8 SDK, and C# 12.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;System&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;System.Collections.Generic&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Pricing&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Expects sku non-empty, quantity &amp;amp;gt; 0, priceIndex contains sku.&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;decimal&lt;/span&gt; &lt;span class="nf"&gt;PriceOrder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;sku&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;IReadOnlyDictionary&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;decimal&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;priceIndex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;ArgumentNullException&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ThrowIfNull&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;priceIndex&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;IsNullOrWhiteSpace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sku&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
            &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;ArgumentException&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;SKU&lt;/span&gt; &lt;span class="n"&gt;cannot&lt;/span&gt; &lt;span class="n"&gt;be&lt;/span&gt; &lt;span class="n"&gt;empty&lt;/span&gt; &lt;span class="k"&gt;or&lt;/span&gt; &lt;span class="n"&gt;whitespace&lt;/span&gt;&lt;span class="p"&gt;.,&amp;lt;/&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;nameof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sku&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
        &lt;span class="n"&gt;ArgumentOutOfRangeException&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ThrowIfLessThanOrEqual&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;nameof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(!&lt;/span&gt;&lt;span class="n"&gt;priceIndex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;TryGetValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sku&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;out&lt;/span&gt; &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;unit&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
            &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;InvalidOperationException&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="n"&gt;SKU&lt;/span&gt; &lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;sku&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="n"&gt;unknown&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;current&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;.);&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;unit&lt;/span&gt; &lt;span class="p"&gt;*&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="p"&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;&lt;strong&gt;Why these choices?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  An empty &lt;code&gt;sku&lt;/code&gt; isn't a range issue, it's a format problem, so use &lt;code&gt;ArgumentException&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;  A &lt;code&gt;quantity&lt;/code&gt; less than or equal to 0 violates a numeric rule, so use &lt;code&gt;ArgumentOutOfRangeException&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;  A missing &lt;code&gt;sku&lt;/code&gt; in &lt;code&gt;priceIndex&lt;/code&gt; isn't the caller's fault if they provided the &lt;code&gt;sku&lt;/code&gt; and a dictionary. It means something's wrong with our environment, so we go with &lt;code&gt;InvalidOperationException&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Should you ever throw &lt;code&gt;Argument*&lt;/code&gt; for the unknown &lt;code&gt;SKU&lt;/code&gt; ? Only if your API says the caller needs to check if the SKU exists before calling. Ask who is in charge.&lt;/p&gt;

&lt;h3&gt;
  
  
  Try It Out
&lt;/h3&gt;

&lt;p&gt;Create a new console app:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dotnet new console &lt;span class="nt"&gt;-n&lt;/span&gt; ExceptionRubricDemo &lt;span class="nt"&gt;-f&lt;/span&gt; net8.0
&lt;span class="nb"&gt;cd &lt;/span&gt;ExceptionRubricDemo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace the code in &lt;code&gt;Program.cs&lt;/code&gt; with this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;System&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;System.Collections.Generic&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;prices&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;Dictionary&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;decimal&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;""&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;span class="n"&gt;ABC&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;9.99m&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kt"&gt;decimal&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;ok&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Pricing&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;PriceOrder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ABC&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;prices&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 19.98&lt;/span&gt;

&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;Pricing&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;PriceOrder&lt;/span&gt;&lt;span class="p"&gt;(,&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;prices&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ArgumentException&lt;/span&gt; &lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetType&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;Name&lt;/span&gt; &lt;span class="p"&gt;+&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="p"&gt;+&lt;/span&gt; &lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ParamName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;Pricing&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;PriceOrder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ABC&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;prices&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ArgumentOutOfRangeException&lt;/span&gt; &lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetType&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;Name&lt;/span&gt; &lt;span class="p"&gt;+&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="p"&gt;+&lt;/span&gt; &lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ParamName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;Pricing&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;PriceOrder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;MISSING&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;prices&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;InvalidOperationException&lt;/span&gt; &lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetType&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;Name&lt;/span&gt; &lt;span class="p"&gt;+&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="p"&gt;+&lt;/span&gt; &lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Pricing&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;decimal&lt;/span&gt; &lt;span class="nf"&gt;PriceOrder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;sku&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;IReadOnlyDictionary&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;decimal&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;priceIndex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&amp;lt;/&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&amp;gt;&lt;/span&gt;
        &lt;span class="n"&gt;ArgumentNullException&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ThrowIfNull&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;priceIndex&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;IsNullOrWhiteSpace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sku&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
            &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;ArgumentException&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;SKU&lt;/span&gt; &lt;span class="n"&gt;cannot&lt;/span&gt; &lt;span class="n"&gt;be&lt;/span&gt; &lt;span class="n"&gt;empty&lt;/span&gt; &lt;span class="k"&gt;or&lt;/span&gt; &lt;span class="n"&gt;whitespace&lt;/span&gt;&lt;span class="p"&gt;.,&lt;/span&gt; &lt;span class="k"&gt;nameof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sku&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
        &lt;span class="n"&gt;ArgumentOutOfRangeException&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ThrowIfLessThanOrEqual&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;nameof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(!&lt;/span&gt;&lt;span class="n"&gt;priceIndex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;TryGetValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sku&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;out&lt;/span&gt; &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;unit&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
            &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;InvalidOperationException&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="n"&gt;SKU&lt;/span&gt; &lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;sku&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="n"&gt;unknown&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;current&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;.);&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;unit&lt;/span&gt; &lt;span class="p"&gt;*&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="p"&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;Run the app:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dotnet run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see the three exception types, each with helpful details.&lt;/p&gt;

&lt;h3&gt;
  
  
  Avoid Simple Mistakes
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Calling caller errors InvalidOperation.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  If &lt;code&gt;pageSize = -1&lt;/code&gt;, that's the caller's fault. Don't hide it as invalid operation or something failed. Put yourself in a 2 AM situation and consider what you would want to see.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Forgetting the parameter name.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Always use &lt;code&gt;nameof(arg)&lt;/code&gt; to point stack traces to the exact parameter.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Throwing too late.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Validate at the entry point. If an invalid value gets deep into the system, it will throw a misleading message far from where the real problem started.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Using exceptions as if/else.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Exceptions are heavy and slow. If you expect a missing key often, use &lt;code&gt;TryGet…&lt;/code&gt; patterns or &lt;code&gt;OneOf&amp;lt;result, error=""&amp;gt;&lt;/code&gt;-style results. Reserve exceptions for truly rare states.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Re-throwing incorrectly.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Use &lt;code&gt;throw;&lt;/code&gt; to keep the original stack trace. &lt;code&gt;throw ex;&lt;/code&gt; resets it and destroys evidence.
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

</description>
      <category>csharp</category>
      <category>dotnet</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Why stubborn bugs waste days</title>
      <dc:creator>Sukhpinder Singh</dc:creator>
      <pubDate>Thu, 09 Oct 2025 07:14:42 +0000</pubDate>
      <link>https://dev.to/csharp-programming/why-stubborn-bugs-waste-days-1g09</link>
      <guid>https://dev.to/csharp-programming/why-stubborn-bugs-waste-days-1g09</guid>
      <description>&lt;p&gt;Chasing symptoms when debugging can be an inefficient path. Instead of relying on intuition and making chaotic changes, a systematic routine can reduce the problem space and help pinpoint the root cause. These guidelines are useful for addressing performance issues, data races, network timeouts, and UI freezes. While the examples use .NET 8 and Windows, the core ideas are applicable across different platforms.&lt;/p&gt;

&lt;h3&gt;
  
  
  1: Freeze the Environment and Record the Scene
&lt;/h3&gt;

&lt;p&gt;To begin, establish a controlled environment. Prevent any further changes by stopping deployments and isolating the issue to a specific machine or container to act as a lab. It’s important to record the exact versions of software and commands being used.&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="c"&gt;# Environment snapshot&lt;/span&gt;
dotnet &lt;span class="nt"&gt;--info&lt;/span&gt;
git rev-parse &lt;span class="nt"&gt;--short&lt;/span&gt; HEAD
&lt;span class="nb"&gt;set&lt;/span&gt; | findstr /R ASPNETCORE_ENVIRONMENT|DOTNET_
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the error involves time or random numbers, set a fixed seed and control the clock. For instance, in testing scenarios:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// .NET 8 xUnit example&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Fact&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;ParseInvoice_IsStable&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;rng&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;Random&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;42&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// fixed seed&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;DateTime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;2025&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;09&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;11&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;00&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;DateTimeKind&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Utc&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;var&lt;/span&gt; &lt;span class="n"&gt;clock&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;FixedClock&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// your simple IClock&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;sut&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;InvoiceParser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;clock&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rng&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;Assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Equal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;123.45m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sut&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="m"&gt;123.45&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;This step is crucial for stable testing, which allows you to accurately bisect and benchmark.&lt;/p&gt;

&lt;h3&gt;
  
  
  2: Create a Minimal Reproduction
&lt;/h3&gt;

&lt;p&gt;Reduce the code to the smallest amount required to cause the problem. Copy just enough code into a basic console app or test case that replicates the error. Avoid including the whole dependency injection setup and middleware. A smaller reproduction makes it easier to identify the signal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dotnet new console &lt;span class="nt"&gt;-n&lt;/span&gt; Repro.LoginHang
&lt;span class="nb"&gt;cd &lt;/span&gt;Repro.LoginHang
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Program.cs&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;System.Net.Http&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;HttpClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;SocketsHttpHandler&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;PooledConnectionLifetime&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;TimeSpan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;FromMinutes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="p"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;lt&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="m"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;++)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;https&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="c1"&gt;//example.test/login).GetAwaiter().GetResult(); // sync-over-async trap&lt;/span&gt;
    &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusCode&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;This short code may reveal deadlocks or problems of running out of the pool. Then you can start the debugging easier.&lt;/p&gt;

&lt;h3&gt;
  
  
  3: Use Specific Logging and Counters
&lt;/h3&gt;

&lt;p&gt;Rather than adding too many logs, focus on adding useful ones. Place logs near the code that might be slow or risky, and include correlation IDs and timing information.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;var&lt;/span&gt; &lt;span class="n"&gt;activity&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;MyActivitySource&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;StartActivity&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Auth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ExchangeCode&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;sw&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ValueStopwatch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;StartNew&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="c1"&gt;// call the dependency&lt;/span&gt;
&lt;span class="n"&gt;_logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;LogInformation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;exchange&lt;/span&gt; &lt;span class="n"&gt;started&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;CorrelationId&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="n"&gt;cid&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="n"&gt;_logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;LogInformation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;exchange&lt;/span&gt; &lt;span class="n"&gt;done&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;CorrelationId&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;ElapsedMs&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="n"&gt;cid&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sw&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetElapsedTime&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;TotalMilliseconds&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Track live counters to detect leaks or starvation by streaming:&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="c"&gt;# CPU, GC, threadpool, exceptions in real time&lt;/span&gt;
dotnet-counters monitor System.Runtime &lt;span class="nt"&gt;--process-id&lt;/span&gt; &amp;lt;pid&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Look for patterns such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Thread pool queue length increasing without recovery&lt;/li&gt;
&lt;li&gt;  GC heap size growing continuously&lt;/li&gt;
&lt;li&gt;  Exception rates peaking around the time of the error&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4: Use &lt;code&gt;git bisect&lt;/code&gt; to Find the Problematic Commit
&lt;/h3&gt;

&lt;p&gt;Instead of guessing, use the repository's history to find the change that introduced the fault.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git bisect start
git bisect bad HEAD
git bisect good v1.18.0   &lt;span class="c"&gt;# pick a known-good tag or commit&lt;/span&gt;
&lt;span class="c"&gt;# For each step:&lt;/span&gt;
&lt;span class="c"&gt;# 1) build and run the minimal repro script&lt;/span&gt;
&lt;span class="c"&gt;# 2) mark good/bad&lt;/span&gt;
git bisect bad   &lt;span class="c"&gt;# or git bisect good&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This procedure typically takes seven to ten steps. Once it's complete, the offending commit can be inspected. Analyze the changes and confirm the result.&lt;/p&gt;

&lt;h3&gt;
  
  
  5: Write a Test That Fails Before Fixing
&lt;/h3&gt;

&lt;p&gt;Create a test that captures the problematic behavior. This ensures that the problem won't occur again.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Fact&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt; &lt;span class="nf"&gt;Login_Timeouts_WhenTokenSwallowed&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;var&lt;/span&gt; &lt;span class="n"&gt;server&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;TestServerFactory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Create&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;CreateClient&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;sw&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Stopwatch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;StartNew&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;Assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ThrowsAsync&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;timeoutexception&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(()&lt;/span&gt; &lt;span class="p"&gt;=&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;gt&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetAsync&lt;/span&gt;&lt;span class="p"&gt;(/&lt;/span&gt;&lt;span class="n"&gt;login&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="n"&gt;Assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;True&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sw&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Elapsed&lt;/span&gt; &lt;span class="p"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;lt&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;TimeSpan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;FromSeconds&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// fails today&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now fix the code. Resolve sync-over-async issues, handle exceptions correctly, and set appropriate timeouts.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Before
var token = _provider.Get().Result; // blocks UI or threadpool

// After
var token = await _provider.GetAsync(); // flows correctly with await
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the test to see if it passes. Add a brief comment explaining the edge case.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
      <category>career</category>
    </item>
    <item>
      <title>Level Up Your PRs: 20 Reviewer-Friendly C# One-Liners</title>
      <dc:creator>Sukhpinder Singh</dc:creator>
      <pubDate>Tue, 07 Oct 2025 10:06:19 +0000</pubDate>
      <link>https://dev.to/csharp-programming/level-up-your-prs-20-reviewer-friendly-c-one-liners-26a6</link>
      <guid>https://dev.to/csharp-programming/level-up-your-prs-20-reviewer-friendly-c-one-liners-26a6</guid>
      <description>&lt;p&gt;Two months ago, a background job stalled overnight. Logs were quiet; CPU fine. Turned out one HTTP call never returned. A single one-liner would have saved hours:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;WaitAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;TimeSpan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;FromSeconds&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every snippet below is the kind of fix I now weave into short narratives (what broke, how I noticed, the one-liner that killed the bug). That blend is performing better than sterile tutorials in 2025.&lt;/p&gt;




&lt;h2&gt;
  
  
  1) Guard required input (save future you)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;arg&lt;/span&gt; &lt;span class="p"&gt;??&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;ArgumentNullException&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;nameof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;arg&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;Use it when:&lt;/strong&gt; You’re one stack trace away from chaos.&lt;br&gt;
&lt;strong&gt;Story hook:&lt;/strong&gt; “The bug wasn’t complex—it was &lt;strong&gt;missing&lt;/strong&gt;.”&lt;/p&gt;

&lt;h2&gt;
  
  
  2) Null-safe with a sensible default
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;city&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="n"&gt;Address&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="n"&gt;City&lt;/span&gt; &lt;span class="p"&gt;??&lt;/span&gt; &lt;span class="s"&gt;"Unknown"&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;Use it when:&lt;/strong&gt; Inputs are messy (forms, APIs).&lt;br&gt;
&lt;strong&gt;Narrative angle:&lt;/strong&gt; “We shipped faster after we picked one default and documented it.”&lt;/p&gt;

&lt;h2&gt;
  
  
  3) Dispose without ceremony
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;var&lt;/span&gt; &lt;span class="n"&gt;stream&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;File&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;OpenRead&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&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;Use it when:&lt;/strong&gt; You can’t afford orphaned handles in long-running services.&lt;br&gt;
&lt;strong&gt;Angle:&lt;/strong&gt; “An elusive file-lock vanished when we stopped being polite and started disposing.”&lt;/p&gt;

&lt;h2&gt;
  
  
  4) Switch expression for intent
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;grade&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;score&lt;/span&gt; &lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="m"&gt;90&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s"&gt;"A"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="m"&gt;80&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s"&gt;"B"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s"&gt;"C"&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;Use it when:&lt;/strong&gt; Reviewers keep asking “what does this branch do?”&lt;br&gt;
&lt;strong&gt;Angle:&lt;/strong&gt; “Future teammates read this in one sip.”&lt;/p&gt;

&lt;h2&gt;
  
  
  5) Dictionary get-or-add (cache happy)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="k"&gt;value&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;TryGetValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;out&lt;/span&gt; &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;Compute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&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;Use it when:&lt;/strong&gt; You’re de-duping work in hot paths.&lt;br&gt;
&lt;strong&gt;Angle:&lt;/strong&gt; “This line erased a thundering herd.”&lt;/p&gt;

&lt;h2&gt;
  
  
  6) Count occurrences (no ifs)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;counts&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;counts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetValueOrDefault&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;+&lt;/span&gt; &lt;span class="m"&gt;1&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;Use it when:&lt;/strong&gt; You need a quick histogram from logs.&lt;br&gt;
&lt;strong&gt;Angle:&lt;/strong&gt; “We caught a noisy endpoint by watching counts jump.”&lt;/p&gt;

&lt;h2&gt;
  
  
  7) Distinct by key (built-in)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;unique&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;DistinctBy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;u&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Email&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;ToList&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;Use it when:&lt;/strong&gt; Shadow data sources double-insert.&lt;br&gt;
&lt;strong&gt;Angle:&lt;/strong&gt; “Bug reports dropped when we kept just the first truth.”&lt;/p&gt;

&lt;h2&gt;
  
  
  8) Group + count to dictionary
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;byExt&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GroupBy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetExtension&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
                 &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ToDictionary&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Count&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;Use it when:&lt;/strong&gt; You need a dashboard metric now.&lt;br&gt;
&lt;strong&gt;Angle:&lt;/strong&gt; “One liner, instant insight, zero BI tickets.”&lt;/p&gt;

&lt;h2&gt;
  
  
  9) Top-N fast
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;top3&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;OrderByDescending&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Score&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;Take&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;ToList&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;Use it when:&lt;/strong&gt; Stakeholders want “the top offenders.”&lt;br&gt;
&lt;strong&gt;Angle:&lt;/strong&gt; “Screenshots sell decisions.”&lt;/p&gt;

&lt;h2&gt;
  
  
  10) Stream huge logs safely
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;errors&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;File&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ReadLines&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;Where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;l&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Contains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"ERROR"&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;Use it when:&lt;/strong&gt; Memory blows up tailing 40GB logs.&lt;br&gt;
&lt;strong&gt;Angle:&lt;/strong&gt; “We debugged without waking the ops pager.”&lt;/p&gt;

&lt;h2&gt;
  
  
  11) Serialize quickly (built-in)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;JsonSerializer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Serialize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model&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;Use it when:&lt;/strong&gt; You need diagnostics or cache blobs.&lt;br&gt;
&lt;strong&gt;Angle:&lt;/strong&gt; “Cut dependency bloat; used the box.”&lt;/p&gt;

&lt;h2&gt;
  
  
  12) Deserialize (defensive)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;dto&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;JsonSerializer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Deserialize&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;MyDto&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="n"&gt;json&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;Use it when:&lt;/strong&gt; Inputs are trusted or pre-validated.&lt;br&gt;
&lt;strong&gt;Angle:&lt;/strong&gt; “‘!’ means &lt;strong&gt;we&lt;/strong&gt; checked—write it down.”&lt;/p&gt;

&lt;h2&gt;
  
  
  13) Parse with fallback
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;retries&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;TryParse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;out&lt;/span&gt; &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;3&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;Use it when:&lt;/strong&gt; Config may be absent in one region.&lt;br&gt;
&lt;strong&gt;Angle:&lt;/strong&gt; “Defaults are decisions. Make them visible.”&lt;/p&gt;

&lt;h2&gt;
  
  
  14) Tail of a string (ranges)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;last10&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;[^&lt;/span&gt;&lt;span class="m"&gt;10&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;Use it when:&lt;/strong&gt; Displaying compact IDs or hashes.&lt;br&gt;
&lt;strong&gt;Angle:&lt;/strong&gt; “Readable slices = fewer off-by-ones.”&lt;/p&gt;

&lt;h2&gt;
  
  
  15) Create parent folder idempotently
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;Directory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;CreateDirectory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetDirectoryName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&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;Use it when:&lt;/strong&gt; Writing exports from serverless or jobs.&lt;br&gt;
&lt;strong&gt;Angle:&lt;/strong&gt; “Race conditions? Not today.”&lt;/p&gt;

&lt;h2&gt;
  
  
  16) Modern param guard
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;ArgumentException&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ThrowIfNullOrEmpty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&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;Use it when:&lt;/strong&gt; You want consistent guardrails.&lt;br&gt;
&lt;strong&gt;Angle:&lt;/strong&gt; “Standard helpers beat bespoke cleverness.”&lt;/p&gt;

&lt;h2&gt;
  
  
  17) Trim without NRE
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;clean&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nf"&gt;Trim&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;??&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Empty&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;Use it when:&lt;/strong&gt; Sanitizing form/query values.&lt;br&gt;
&lt;strong&gt;Angle:&lt;/strong&gt; “We stopped chasing invisible spaces.”&lt;/p&gt;

&lt;h2&gt;
  
  
  18) Flatten batches
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;all&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;batches&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;SelectMany&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;ToList&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;Use it when:&lt;/strong&gt; An API paginates but you need a unified view.&lt;br&gt;
&lt;strong&gt;Angle:&lt;/strong&gt; “Analytics pipelines got one step simpler.”&lt;/p&gt;

&lt;h2&gt;
  
  
  19) Fire many tasks together
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WhenAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;work&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Select&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;DoAsync&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;Use it when:&lt;/strong&gt; Fan-out jobs or microservice calls.&lt;br&gt;
&lt;strong&gt;Angle:&lt;/strong&gt; “Throughput tripled; complexity didn’t.”&lt;/p&gt;

&lt;h2&gt;
  
  
  20) Add timeouts (no custom CTS)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;WaitAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;TimeSpan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;FromSeconds&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;5&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;Use it when:&lt;/strong&gt; A slow downstream can freeze your world.&lt;br&gt;
&lt;strong&gt;Angle:&lt;/strong&gt; “This single line ended a 3 a.m. incident.”&lt;/p&gt;




&lt;h2&gt;
  
  
  Closing thought
&lt;/h2&gt;

&lt;p&gt;These aren’t party tricks—they’re &lt;strong&gt;habits&lt;/strong&gt;. Each one removed a failure mode in real code I ship. &lt;/p&gt;

&lt;p&gt;If you’ve got a sharper one-liner (or a story where one saved a release), &lt;strong&gt;drop it in the comments&lt;/strong&gt;.&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>dotnet</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>[Boost]</title>
      <dc:creator>Sukhpinder Singh</dc:creator>
      <pubDate>Mon, 06 Oct 2025 02:12:21 +0000</pubDate>
      <link>https://dev.to/ssukhpinder/-mok</link>
      <guid>https://dev.to/ssukhpinder/-mok</guid>
      <description>&lt;div class="ltag__link"&gt;
  &lt;a href="/ssukhpinder" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F628027%2F2c6c10d0-b7eb-4faa-8e10-2c51a4127c13.gif" alt="ssukhpinder"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://dev.to/ssukhpinder/hiring-part-time-editors-for-net-programming-medium-jo9" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Hiring Part-Time Editors for .Net Programming (Medium)&lt;/h2&gt;
      &lt;h3&gt;Sukhpinder Singh ・ Oct 6&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#programming&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#csharp&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#dotnet&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>programming</category>
      <category>webdev</category>
      <category>csharp</category>
      <category>dotnet</category>
    </item>
    <item>
      <title>Hiring Part-Time Editors for .Net Programming (Medium)</title>
      <dc:creator>Sukhpinder Singh</dc:creator>
      <pubDate>Mon, 06 Oct 2025 02:08:05 +0000</pubDate>
      <link>https://dev.to/ssukhpinder/hiring-part-time-editors-for-net-programming-medium-jo9</link>
      <guid>https://dev.to/ssukhpinder/hiring-part-time-editors-for-net-programming-medium-jo9</guid>
      <description>&lt;p&gt;Our publication — .Net Programming — is growing fast (5.4K+ followers) and we’re opening 5-6 part-time Editor roles to level up quality, consistency, and community across C#/.NET content. &lt;/p&gt;

&lt;p&gt;Comment “I’m in” and your Medium Account to get started.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.com/c-sharp-programming" rel="noopener noreferrer"&gt;Publication Link&lt;/a&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>webdev</category>
      <category>csharp</category>
      <category>dotnet</category>
    </item>
    <item>
      <title>Your 2025 AI Upgrade, Minus the Noise</title>
      <dc:creator>Sukhpinder Singh</dc:creator>
      <pubDate>Mon, 06 Oct 2025 00:52:45 +0000</pubDate>
      <link>https://dev.to/theainews/your-2025-ai-upgrade-minus-the-noise-13a5</link>
      <guid>https://dev.to/theainews/your-2025-ai-upgrade-minus-the-noise-13a5</guid>
      <description>&lt;p&gt;If you’ve felt that odd pressure to “learn AI” but don’t know where to start, same. My breaking point was a 2 a.m. pager last winter: a Slack bot we’d wired to triage incidents “hallucinated” a root cause and auto-closed a ticket. We lost four noisy hours before a single log line—&lt;code&gt;pred_reason="config drift suspected"&lt;/code&gt;—nudged me to look at the data pipeline, not the model. The fix wasn’t clever prompt magic; it was boring engineering: guardrails, a reproducible pipeline, and an evaluation we could trust. That’s the job now.&lt;/p&gt;

&lt;h3&gt;
  
  
  TL;DR (what to learn next)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Data intuition beats model trivia: learn to clean, slice, and &lt;strong&gt;disbelieve&lt;/strong&gt; your data.&lt;/li&gt;
&lt;li&gt;Reproducibility + observability: use env managers, pipelines, and experiment tracking.&lt;/li&gt;
&lt;li&gt;Evaluation is a product feature: build small, task-specific tests before you scale.&lt;/li&gt;
&lt;li&gt;Security isn’t optional: design for prompt injection and unsafe output handling.&lt;/li&gt;
&lt;li&gt;Cost/latency trade-offs: know when a &lt;strong&gt;small model + smart caching&lt;/strong&gt; beats a giant one.&lt;/li&gt;
&lt;li&gt;Ship value, not demos: wire AI into a real workflow with clear rollback paths.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Map Your Skill Gaps (and why this is hard)
&lt;/h2&gt;

&lt;p&gt;AI in 2025 feels like cloud in 2013—lots of hype, little discipline. The hard part isn’t calling a model; it’s &lt;em&gt;owning the behavior&lt;/em&gt; once it’s in a real workflow. That means versioned code and data, consistent environments, measurable quality, and security posture that survives untrusted inputs. Without those, you get flashy prototypes that mysteriously degrade in production.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use a Practical Mental Model
&lt;/h2&gt;

&lt;p&gt;I teach teammates the “&lt;strong&gt;D-M-D loop&lt;/strong&gt;”:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Data&lt;/strong&gt; → collect, clean, label, monitor&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Model&lt;/strong&gt; → choose, configure, sometimes fine-tune&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Delivery&lt;/strong&gt; → wrap with APIs, cache, observe, secure&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Wrap the loop with a thin ring: &lt;strong&gt;Governance&lt;/strong&gt; (evaluation, cost, safety, rollback). If one segment wobbles, the loop eats your weekend.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx1p5e2ekquhoesdiganw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx1p5e2ekquhoesdiganw.png" alt="D-M-D loop: Data → Model → Delivery, with a thin outer ring labeled Governance (eval, cost, safety, rollback)." width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Build Reproducible Scaffolding First
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Environments that don’t lie.&lt;/strong&gt; Use fast, consistent tooling so “works on my machine” stops being a plot twist. I like &lt;code&gt;uv&lt;/code&gt; because it’s a single tool that handles Python installs, virtual envs, and a pip-compatible interface—fast enough that teammates actually use it.&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="c"&gt;# Setup (Linux/macOS). Assumes curl.&lt;/span&gt;
curl &lt;span class="nt"&gt;-LsSf&lt;/span&gt; https://astral.sh/uv/install.sh | sh
uv python &lt;span class="nb"&gt;install &lt;/span&gt;3.12
uv venv &lt;span class="nt"&gt;--python&lt;/span&gt; 3.12
uv pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="s2"&gt;"scikit-learn&amp;gt;=1.5"&lt;/span&gt; &lt;span class="s2"&gt;"mlflow&amp;gt;=2.9"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Pipelines you can trust.&lt;/strong&gt; Even if you’re doing apps with .NET or Node, learn a minimal ML pipeline conceptually. In Python, &lt;code&gt;sklearn.pipeline&lt;/code&gt; chains preprocessing + model so you tune and evaluate the &lt;em&gt;whole&lt;/em&gt; thing, not just the final estimator. That prevents data leakage and keeps your runs comparable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Python 3.12
&lt;/span&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn.datasets&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;load_iris&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn.pipeline&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;make_pipeline&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn.preprocessing&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;StandardScaler&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn.linear_model&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;LogisticRegression&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn.model_selection&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;cross_val_score&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;mlflow&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mlflow&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sklearn&lt;/span&gt;

&lt;span class="n"&gt;mlflow&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set_tracking_uri&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;file:./mlruns&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# local runs
&lt;/span&gt;&lt;span class="n"&gt;mlflow&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set_experiment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;skills-post&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;load_iris&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;return_X_y&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;pipe&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;make_pipeline&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;StandardScaler&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="nc"&gt;LogisticRegression&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max_iter&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;mlflow&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;start_run&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;scores&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;cross_val_score&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pipe&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cv&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;pipe&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;mlflow&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log_metric&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;cv_mean_acc&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;scores&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mean&lt;/span&gt;&lt;span class="p"&gt;()))&lt;/span&gt;
    &lt;span class="n"&gt;mlflow&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sklearn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log_model&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pipe&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;model&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;cv_mean_acc=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;scores&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mean&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="mi"&gt;3&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;MLflow gives you a simple UI to compare runs and artifacts—useful even for small experiments. &lt;/p&gt;




&lt;h2&gt;
  
  
  Stress-Test Your Data Intuition
&lt;/h2&gt;

&lt;p&gt;Before you chase the “best” model, ask: &lt;em&gt;If this prediction is wrong, what pattern in the data would mislead it?&lt;/em&gt; Create cheap tests: swap class labels, add outliers, perturb inputs, confirm your accuracy drops in sensible ways. Skepticism is a feature, not a vibe.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Try it now (10 minutes):&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Set up the env above.&lt;/li&gt;
&lt;li&gt;Swap &lt;code&gt;StandardScaler()&lt;/code&gt; for no scaler; watch accuracy and variance jump.&lt;/li&gt;
&lt;li&gt;Log both runs in MLflow and compare metrics/artifacts.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Learn Small-Model Engineering (then scale)
&lt;/h2&gt;

&lt;p&gt;You don’t need a 70B model to automate a triage, summarize logs, or classify tickets. Hugging Face &lt;em&gt;pipelines&lt;/em&gt; let you wire tasks quickly; later you can fine-tune with PEFT/LoRA to adapt cheaply.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;transformers&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;pipeline&lt;/span&gt;
&lt;span class="n"&gt;sent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;pipeline&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;sentiment-analysis&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# CPU works for a demo
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;sent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Deployments are failing again; reverting now.&lt;/span&gt;&lt;span class="sh"&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 you do need customization, PEFT/LoRA updates a tiny fraction of weights—often the difference between “can’t afford it” and “done by Friday.” &lt;/p&gt;




&lt;h2&gt;
  
  
  Bake In Evaluation Like a Product Requirement
&lt;/h2&gt;

&lt;p&gt;A simple rubric beats vibes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Task metrics:&lt;/strong&gt; exact match, ROUGE/BLEU for text, confusion matrix for classifiers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Behavioral tests:&lt;/strong&gt; red-teaming prompts, tricky edge cases, “forbidden actions.”&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cost/latency budgets:&lt;/strong&gt; max tokens/sec, p95 latency, and &lt;strong&gt;a rollback plan&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Remember: evaluation isn’t a one-time benchmark; it’s monitoring. Make dashboards part of “done.”&lt;/p&gt;




&lt;h2&gt;
  
  
  Guard Against Real-World Failure Modes
&lt;/h2&gt;

&lt;p&gt;Two that bit us:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Prompt injection &amp;amp; unsafe output handling.&lt;/strong&gt; Treat user text as hostile. Isolate tools, sanitize outputs, and audit prompts. The OWASP LLM Top 10 (2025) explains why these are #1 and #2 risks. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Over-trusting model text.&lt;/strong&gt; If your system executes code or hits APIs based on model output, validate and constrain. Think schemas, allow-lists, or a secondary checker.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Google’s and AWS’s recent guidance both push layered defenses: input filters, output validation, and monitoring. Ship that before the flashy demo. &lt;/p&gt;




&lt;h2&gt;
  
  
  Make Smart Cost/Latency Trade-offs
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Small model + cache&lt;/strong&gt; &amp;gt; large model for many CRUD-ish tasks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PEFT adapters&lt;/strong&gt; let you specialize cheaply; store per-customer adapters when needed. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Batching &amp;amp; streaming&lt;/strong&gt; reduce p95 tail pain; feature flags let you fall back fast.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9pkfpkigw7myb25oeuzx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9pkfpkigw7myb25oeuzx.png" alt="Small-model path: ‘Baseline (pipeline)’ → ‘Evaluate’ → ‘PEFT/LoRA’ → ‘Cache/Budget’ with a side track ‘Security checks’ feeding each step" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ask yourself: &lt;em&gt;If the model gets slower by 200ms tomorrow, does the business still work?&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  A Quick Story Slice (the imperfect bit)
&lt;/h2&gt;

&lt;p&gt;I almost merged a “smart” incident-closer that looked great in staged tests. A teammate asked, “What’s the failure mode when the log parser drops a field?” We added one synthetic example, and the model happily “explained” a non-existent root cause. That tiny “almost mistake” saved us the apology email later.&lt;/p&gt;




&lt;h2&gt;
  
  
  What to Learn Next (and how)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Reproducible tooling:&lt;/strong&gt; Python 3.12 + &lt;code&gt;uv&lt;/code&gt; for speed and fewer environment footguns.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pipelines &amp;amp; evaluation:&lt;/strong&gt; &lt;code&gt;scikit-learn&lt;/code&gt; Pipeline concepts translate to any stack; MLflow for lightweight tracking. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pragmatic LLM use:&lt;/strong&gt; Hugging Face &lt;code&gt;pipeline&lt;/code&gt; to ship; PEFT/LoRA when you need task accuracy without a GPU farm.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Security:&lt;/strong&gt; Read OWASP’s LLM Top 10 and implement at least two mitigations this week. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you’re coming from .NET, the trade-off mindset is the same one I wrote about in &lt;em&gt;Why I Still Choose C# (Even After Trying Everything Else)&lt;/em&gt;—choose boring, durable tools, measure, then iterate.&lt;/p&gt;




&lt;h2&gt;
  
  
  CTA
&lt;/h2&gt;

&lt;p&gt;If you try the mini-exercise, drop your &lt;code&gt;cv_mean_acc&lt;/code&gt; in the comments and tell me what changed it most—scaler, solver, or random seed? Also, what’s the single check you’ll add to your AI app this week: input sanitizer, output schema, or an eval set? I’ll share back anonymized patterns and a follow-up snippet.&lt;/p&gt;




</description>
      <category>ai</category>
      <category>programming</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>If You Know These 30 JavaScript One-Liners, You’re Fast</title>
      <dc:creator>Sukhpinder Singh</dc:creator>
      <pubDate>Sun, 05 Oct 2025 13:37:59 +0000</pubDate>
      <link>https://dev.to/ssukhpinder/if-you-know-these-30-javascript-one-liners-youre-fast-41lk</link>
      <guid>https://dev.to/ssukhpinder/if-you-know-these-30-javascript-one-liners-youre-fast-41lk</guid>
      <description>&lt;h2&gt;
  
  
  A very specific night (and a very silly bug)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;2:13 a.m.&lt;/strong&gt; in a quiet apartment. My laptop fan sounded like a small helicopter and the last of my &lt;strong&gt;jasmine tea&lt;/strong&gt; had turned into something medicinal. I was stubbornly wrestling with a cookie helper. Twelve lines, three branches, one off-by-one.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Teammate (on Slack): “Ship it?”&lt;br&gt;
Me: “…are we sure?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That’s when I opened my scrappy &lt;code&gt;snippets.md&lt;/code&gt; and started replacing noisy helpers with &lt;strong&gt;sharp, honest one-liners&lt;/strong&gt;. Not golfed code—&lt;strong&gt;clear&lt;/strong&gt; code. Since then, these 20 lines have paid rent in production. &lt;/p&gt;

&lt;p&gt;Here’s the list, plus where each one helped, and the trade-offs I learned the hard way.&lt;/p&gt;




&lt;h2&gt;
  
  
  1) Get a cookie value (stop overbuilding)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cookie&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;`; &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cookie&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`; &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;=`&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;;&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;shift&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;Where it helped:&lt;/strong&gt; Login flakiness on staging; I needed to peek at &lt;code&gt;_ga&lt;/code&gt; quickly.&lt;br&gt;
&lt;strong&gt;Watch out:&lt;/strong&gt; Won’t see &lt;strong&gt;HttpOnly&lt;/strong&gt; cookies (that’s a &lt;strong&gt;good&lt;/strong&gt; thing). Path/domain matter.&lt;/p&gt;


&lt;h2&gt;
  
  
  2) RGB → Hex (design → CSS handshake)
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;rgbToHex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;g&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;g&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;)&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="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;slice&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Story:&lt;/strong&gt; Designer sent RGB, theme wanted hex. This bridged it during a UI polish sprint.&lt;br&gt;
&lt;strong&gt;Guard:&lt;/strong&gt; Validate &lt;code&gt;0–255&lt;/code&gt;. I’ve shipped &lt;code&gt;rgbToHex(300, -2, 10)&lt;/code&gt; (facepalm).&lt;/p&gt;


&lt;h2&gt;
  
  
  3) Copy to clipboard (no hidden inputs)
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;copyToClipboard&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;navigator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;clipboard&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;writeText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&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;Fix:&lt;/strong&gt; I ditched the &lt;code&gt;execCommand&lt;/code&gt; relic.&lt;br&gt;
&lt;strong&gt;Gotcha:&lt;/strong&gt; Needs &lt;strong&gt;https&lt;/strong&gt; and user gesture; attach to a &lt;code&gt;click&lt;/code&gt; or &lt;code&gt;keydown&lt;/code&gt;.&lt;/p&gt;


&lt;h2&gt;
  
  
  4) Day of year (for streaks and cohorts)
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;dayOfYear&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;d&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;d&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getFullYear&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="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;86400000&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;Real use:&lt;/strong&gt; A “learning streak” badge that computed day numbers.&lt;br&gt;
&lt;strong&gt;TZ note:&lt;/strong&gt; Normalize to UTC if the boundary matters.&lt;/p&gt;


&lt;h2&gt;
  
  
  5) Capitalize (because JS still won’t)
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;capitalize&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;charAt&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="nf"&gt;toUpperCase&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;True story:&lt;/strong&gt; I once typed &lt;code&gt;Substring&lt;/code&gt; (C# muscle memory) in a JS file. Linter laughed at me.&lt;/p&gt;


&lt;h2&gt;
  
  
  6) Days between (no Moment, no drama)
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;dayDif&lt;/span&gt; &lt;span class="o"&gt;=&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ceil&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&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="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;86400000&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;Use:&lt;/strong&gt; “Remind me in N days” cards.&lt;br&gt;
&lt;strong&gt;Caveat:&lt;/strong&gt; Payroll/leave apps should use a real date lib—DST is a gremlin.&lt;/p&gt;


&lt;h2&gt;
  
  
  7) Clear all cookies (panic button)
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cookie&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;;&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cookie&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/^ +/&lt;/span&gt;&lt;span class="p"&gt;,&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="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/=.*/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;`=;expires=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&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="nf"&gt;toUTCString&lt;/span&gt;&lt;span class="p"&gt;()}&lt;/span&gt;&lt;span class="s2"&gt;;path=/`&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;When:&lt;/strong&gt; Before a demo when auth state got weird.&lt;br&gt;
&lt;strong&gt;Note:&lt;/strong&gt; Cookies set on a different path/domain may survive.&lt;/p&gt;


&lt;h2&gt;
  
  
  8) Random hex (rapid prototyping)
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;randomHex&lt;/span&gt; &lt;span class="o"&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="s2"&gt;`#&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mh"&gt;0xffffff&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;padEnd&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;0&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&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;Fun:&lt;/strong&gt; Temporary avatar colors in a “team picker.”&lt;br&gt;
&lt;strong&gt;Accessibility:&lt;/strong&gt; Not contrast-safe by default—never ship this to prod UIs without checks.&lt;/p&gt;


&lt;h2&gt;
  
  
  9) Unique array (goodbye 15-line loop)
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;removeDuplicates&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&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;Gotcha:&lt;/strong&gt; Works on primitives. For objects, dedupe by key:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;uniqBy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;key&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="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;])).&lt;/span&gt;&lt;span class="nf"&gt;values&lt;/span&gt;&lt;span class="p"&gt;()];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  10) Query params (quick &amp;amp; dirty)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getParameters&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
  &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;{"&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;decodeURI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;?&lt;/span&gt;&lt;span class="dl"&gt;"&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="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/"/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s1"&gt;"&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="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&amp;amp;/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;","&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/=/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;":"&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;"}&lt;/span&gt;&lt;span class="dl"&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;Confession:&lt;/strong&gt; I used this mid-debug to unblock myself.&lt;br&gt;
&lt;strong&gt;Long-term:&lt;/strong&gt; Prefer &lt;code&gt;new URL(url).searchParams.get('q')&lt;/code&gt;—clearer, safer.&lt;/p&gt;


&lt;h2&gt;
  
  
  11) Time from Date (hh:mm:ss)
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;timeFromDate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;d&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toTimeString&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;slice&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="mi"&gt;8&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;When:&lt;/strong&gt; Console output for job runtimes.&lt;br&gt;
&lt;strong&gt;Internationalization:&lt;/strong&gt; For UI, use &lt;code&gt;Intl.DateTimeFormat&lt;/code&gt;.&lt;/p&gt;


&lt;h2&gt;
  
  
  12) Even check (small reads better)
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isEven&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&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;Aside:&lt;/strong&gt; I used to write &lt;code&gt;!(n &amp;amp; 1)&lt;/code&gt; to feel clever. Then I started writing for humans.&lt;/p&gt;


&lt;h2&gt;
  
  
  13) Average (tiny analytics helper)
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;average&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;xs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;xs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&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="o"&gt;=&amp;gt;&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="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nx"&gt;xs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&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;Guard:&lt;/strong&gt; Empty input → &lt;code&gt;NaN&lt;/code&gt;. I now wrap with &lt;code&gt;xs.length ? … : 0&lt;/code&gt;.&lt;/p&gt;


&lt;h2&gt;
  
  
  14) Scroll to top (be kind: smooth)
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;goToTop&lt;/span&gt; &lt;span class="o"&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="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;scrollTo&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;top&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="na"&gt;left&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="na"&gt;behavior&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;smooth&lt;/span&gt;&lt;span class="dl"&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;Respect:&lt;/strong&gt; Users with reduced motion—feature-detect or let CSS media queries handle it.&lt;/p&gt;


&lt;h2&gt;
  
  
  15) Reverse string (classic chain)
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;reverse&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;reverse&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&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;Unicode footnote:&lt;/strong&gt; Grapheme clusters (emoji/accents) need a lib or &lt;code&gt;Intl.Segmenter&lt;/code&gt;.&lt;/p&gt;


&lt;h2&gt;
  
  
  16) Array not empty (guard clause)
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isNotEmpty&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isArray&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="o"&gt;&amp;amp;&amp;amp;&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;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&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;Why I keep it:&lt;/strong&gt; Reads like English and kills a whole if-ladder.&lt;/p&gt;


&lt;h2&gt;
  
  
  17) Selected text (handy in editors)
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getSelectedText&lt;/span&gt; &lt;span class="o"&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="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getSelection&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;toString&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;Shadow DOM:&lt;/strong&gt; You may need selection from the right root; know your host.&lt;/p&gt;


&lt;h2&gt;
  
  
  18) Shuffle (fun, but biased)
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;shuffleArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&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;Honesty:&lt;/strong&gt; Great for a quick demo. For fairness, I use Fisher–Yates:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fyShuffle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&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;length&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="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&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;j&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&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="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;i&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;j&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt;&lt;span class="o"&gt;=&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;j&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;i&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="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;
  
  
  19) Detect dark mode (respect the user)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isDarkMode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;matchMedia&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;matchMedia&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;(prefers-color-scheme: dark)&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;matches&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;Pattern:&lt;/strong&gt; Toggle a &lt;code&gt;data-theme&lt;/code&gt; attribute and let CSS carry the weight.&lt;/p&gt;







&lt;h3&gt;
  
  
  20) Debounce (collapse rapid calls)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;debounce&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ms&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;let&lt;/span&gt; &lt;span class="nx"&gt;t&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="nx"&gt;a&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;clearTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nx"&gt;t&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;setTimeout&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;fn&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;ms&lt;/span&gt;&lt;span class="p"&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;&lt;strong&gt;Use:&lt;/strong&gt; search-as-you-type, resize handlers.&lt;br&gt;
&lt;strong&gt;Note:&lt;/strong&gt; Last call wins.&lt;/p&gt;




&lt;h3&gt;
  
  
  21) Throttle (limit call rate)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;throttle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ms&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;let&lt;/span&gt; &lt;span class="nx"&gt;p&lt;/span&gt; &lt;span class="o"&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="nx"&gt;a&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;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;p&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;ms&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;n&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="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="p"&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;&lt;strong&gt;Use:&lt;/strong&gt; scroll listeners, pointer move.&lt;br&gt;
&lt;strong&gt;Note:&lt;/strong&gt; Drops calls within the window.&lt;/p&gt;




&lt;h3&gt;
  
  
  22) Clamp (keep a number in range)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;clamp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;min&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;max&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;max&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;min&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;n&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;Use:&lt;/strong&gt; slider values, pagination bounds.&lt;/p&gt;




&lt;h3&gt;
  
  
  23) Chunk an array
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;chunk&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;size&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;i&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="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="nx"&gt;size&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&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="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]]),&lt;/span&gt; &lt;span class="nx"&gt;r&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;Use:&lt;/strong&gt; grid rows, batched requests.&lt;/p&gt;




&lt;h3&gt;
  
  
  24) Deep-flatten any nested array
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;flat&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;flat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;Infinity&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;Use:&lt;/strong&gt; merging API results.&lt;br&gt;
&lt;strong&gt;Note:&lt;/strong&gt; Requires modern runtimes (widely supported).&lt;/p&gt;




&lt;h3&gt;
  
  
  25) Range generator (length n, optional start)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;range&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;start&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;Use:&lt;/strong&gt; page numbers, skeleton loaders.&lt;/p&gt;




&lt;h3&gt;
  
  
  26) Sleep / delay as a Promise
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sleep&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ms&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ms&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;Use:&lt;/strong&gt; UI pauses, backoff between retries.&lt;/p&gt;




&lt;h3&gt;
  
  
  27) Fetch JSON (tiny helper)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getJSON&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;opts&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;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;opts&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&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;Use:&lt;/strong&gt; quick prototypes.&lt;br&gt;
&lt;strong&gt;Note:&lt;/strong&gt; No error handling—wrap if you need robustness.&lt;/p&gt;




&lt;h3&gt;
  
  
  28) Group by key
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;groupBy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;x&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="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="p"&gt;[]).&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;m&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;Use:&lt;/strong&gt; table sections, charts datasets.&lt;/p&gt;




&lt;h3&gt;
  
  
  29) Safe deep get with default
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="kd"&gt;get&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;dflt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;v&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;k&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;v&lt;/span&gt;&lt;span class="p"&gt;?.[&lt;/span&gt;&lt;span class="nx"&gt;k&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="nx"&gt;dflt&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;Use:&lt;/strong&gt; reading optional API fields without try/catch.&lt;/p&gt;




&lt;h2&gt;
  
  
  30) The mindset: compress &lt;em&gt;only&lt;/em&gt; when it clarifies
&lt;/h2&gt;

&lt;p&gt;There’s a difference between clever and &lt;strong&gt;considerate&lt;/strong&gt;. I used to minify everything I could; now I compress only when the next reader—maybe tired, maybe rushing—will understand it faster.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Quotable: “Great code isn’t shorter. It’s &lt;strong&gt;clearer&lt;/strong&gt;—and usually that means fewer moving parts.”&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  Tiny sketch: how the “quick params” trick works
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[ URL ] -&amp;gt; [ split "?" ] -&amp;gt; [ decode ] -&amp;gt; [ replace &amp;amp;/= ] -&amp;gt; [ JSON.parse ] -&amp;gt; { params }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Alt text: A simple linear flow showing a raw URL string transformed into a params object via split/replace/parse.&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Three real postmortems (because production is humbling)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;#1532 Clipboard flaked in staging&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Symptom: Worked locally, failed behind reverse proxy.&lt;/li&gt;
&lt;li&gt;Root cause: Missing secure context; no user gesture.&lt;/li&gt;
&lt;li&gt;Fix: Wire to a click; ensure https in all envs.&lt;/li&gt;
&lt;li&gt;Commit: &lt;code&gt;9ad1bf7&lt;/code&gt; (the “toast added” one).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;#1619 Streak counter off by one&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Symptom: Users in GMT+9 saw tomorrow’s day number.&lt;/li&gt;
&lt;li&gt;Fix: Normalize to UTC midnight; compute in back end.&lt;/li&gt;
&lt;li&gt;Lesson: Time zones don’t care about your sprint goals.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;#1674 Duplicate labels in chart&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Symptom: Two bars with the same tag after a transform.&lt;/li&gt;
&lt;li&gt;Fix: &lt;code&gt;labels = [...new Set(labels)]&lt;/code&gt; pre-render.&lt;/li&gt;
&lt;li&gt;Bonus: Added &lt;code&gt;uniqBy&lt;/code&gt; for objects (see #9).&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Skimmable checklists (paste into your notes)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Reach for a one-liner when…&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The name reads like a sentence (&lt;code&gt;isNotEmpty&lt;/code&gt;, &lt;code&gt;timeFromDate&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;It replaces boilerplate without hiding intent.&lt;/li&gt;
&lt;li&gt;You’ve tested edge cases (TZ, permissions, Unicode).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Don’t one-line when…&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Security or crypto logic lives there.&lt;/li&gt;
&lt;li&gt;Accessibility depends on it (contrast, motion).&lt;/li&gt;
&lt;li&gt;You need mathematically fair randomness (use Fisher–Yates).&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  How I keep these ready (small habit, big payoff)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;I keep a &lt;code&gt;snippets.md&lt;/code&gt; in the repo with headings and trade-offs.&lt;/li&gt;
&lt;li&gt;I save tiny gists for the ones I reuse across projects.&lt;/li&gt;
&lt;li&gt;I leave a one-line comment above each snippet: &lt;em&gt;what it does + when not to use it&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;I prune. If a snippet causes more questions than answers, it’s gone.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Recap (7 takeaways)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;One-liners are &lt;strong&gt;tools&lt;/strong&gt;, not trophies.&lt;/li&gt;
&lt;li&gt;Prefer &lt;strong&gt;clarity &amp;gt; cleverness&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Normalize time. Respect motion preferences. Guard inputs.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Set&lt;/code&gt;, &lt;code&gt;Map&lt;/code&gt;, &lt;code&gt;URL&lt;/code&gt;, &lt;code&gt;Intl&lt;/code&gt;—lean on the platform first.&lt;/li&gt;
&lt;li&gt;Prototype fast, then refactor the “quick &amp;amp; dirty.”&lt;/li&gt;
&lt;li&gt;Document trade-offs right above the snippet.&lt;/li&gt;
&lt;li&gt;Share your snippet file—teams improve it together.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Let’s make this a living toolbox
&lt;/h2&gt;

&lt;p&gt;What’s the one-liner you reach for without thinking?&lt;br&gt;
&lt;strong&gt;Drop it in the comments&lt;/strong&gt;—I’ll collect the best ones and credit you in a follow-up.&lt;/p&gt;

&lt;p&gt;Follow if you like practical, production-tested posts with fewer buzzwords and more “here’s what actually shipped.”&lt;/p&gt;




</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>frontend</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Why I Still Choose C# (Even After Trying Everything Else)</title>
      <dc:creator>Sukhpinder Singh</dc:creator>
      <pubDate>Fri, 03 Oct 2025 01:06:01 +0000</pubDate>
      <link>https://dev.to/csharp-programming/why-i-still-choose-c-even-after-trying-everything-else-4o53</link>
      <guid>https://dev.to/csharp-programming/why-i-still-choose-c-even-after-trying-everything-else-4o53</guid>
      <description>&lt;p&gt;&lt;em&gt;The one language that keeps pulling me back, no matter what else I try&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  The Hook: My Accidental Love Story with C
&lt;/h2&gt;

&lt;p&gt;I didn’t start my career thinking, &lt;em&gt;“Yep, I’m gonna be a C# developer.”&lt;/em&gt; Not even close.&lt;/p&gt;

&lt;p&gt;I was that guy who bounced between languages like a kid testing every arcade machine. Java one week, Python the next, then back to some shaky PHP “hello world” website. Each one felt exciting for about… two weeks.&lt;/p&gt;

&lt;p&gt;And then reality hit.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Java was powerful but made me feel like I was filling out mortgage forms just to print text on a screen.&lt;/li&gt;
&lt;li&gt;Python was fun, until my project grew up and turned into spaghetti.&lt;/li&gt;
&lt;li&gt;JavaScript? Let’s just say &lt;code&gt;undefined&lt;/code&gt; still haunts my dreams.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;C# wasn’t even on my radar. I literally stumbled into it by accident while trying to build a small Windows app for a college project. I opened Visual Studio, wrote a few lines, and for the first time coding didn’t feel like punishment.&lt;/p&gt;

&lt;p&gt;That was it. Not love at first sight, but it felt… different. And years later, after testing Go, Rust, Kotlin, and a few other “shiny” languages? Guess what’s still on my machine, still running most of my real work? Yep. C#.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why C# Keeps Winning Me Over
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. It’s Balanced (Strict, but Not Annoying)
&lt;/h3&gt;

&lt;p&gt;C# is like that friend who shows up on time but still grabs tacos with you at midnight. Structured, but not uptight.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Strong typing saves me from weird runtime bugs.&lt;/li&gt;
&lt;li&gt;Syntax that’s clean but doesn’t make me cry.&lt;/li&gt;
&lt;li&gt;Features that arrive right when I need them (LINQ, async/await, pattern matching).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I’ve written in languages that were too stiff (hi Java 👋) and too loose (looking at you, JavaScript). C# just feels… right. Like the “Goldilocks zone” of programming.&lt;/p&gt;

&lt;p&gt;👉 &lt;em&gt;“C# is strict enough to keep me safe, chill enough to let me code at 2 a.m. without losing my mind.”&lt;/em&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  2. The Ecosystem Is Ridiculously Good
&lt;/h3&gt;

&lt;p&gt;Whatever I throw at it—C# has an answer.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Web APIs? ASP.NET Core.&lt;/li&gt;
&lt;li&gt;Desktop apps? WinForms, WPF, or MAUI if I’m feeling fancy.&lt;/li&gt;
&lt;li&gt;Cloud-native microservices? Minimal APIs + Docker.&lt;/li&gt;
&lt;li&gt;AI/ML? ML.NET, or just hook into Python.&lt;/li&gt;
&lt;li&gt;Games? Unity. Enough said.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It’s like a Swiss Army knife for devs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Messy Node.js Example (more setup than I like):&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;express&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;express&lt;/span&gt;&lt;span class="dl"&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;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/hello&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="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello World&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3000&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;Minimal C# Example (.NET 8):&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;WebApplication&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;CreateBuilder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Build&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;MapGet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/hello"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s"&gt;"Hello World"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Run&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Less code. Strong typing. Doesn’t break when I blink at it wrong.&lt;/p&gt;




&lt;h3&gt;
  
  
  3. It Keeps Growing Up With Me
&lt;/h3&gt;

&lt;p&gt;This is maybe my favorite part: C# evolves, but it doesn’t abandon me.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Async/await killed callback hell.&lt;/li&gt;
&lt;li&gt;LINQ turned ugly loops into something that looks like poetry.&lt;/li&gt;
&lt;li&gt;.NET 8+? We’re talking native AOT, faster-than-Java performance, cloud-first everything.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Friends keep asking: &lt;em&gt;“Why not Go? Why not Rust?”&lt;/em&gt; And honestly? Because C# keeps giving me the “new shiny” without making me throw away everything I already know.&lt;/p&gt;




&lt;h3&gt;
  
  
  4. The Community (a.k.a. My 2 a.m. Lifeline)
&lt;/h3&gt;

&lt;p&gt;If you’ve ever coded in a language with a tiny community, you know the pain—Googling an error and finding… nothing.&lt;/p&gt;

&lt;p&gt;With C#, I’ve never felt that. Ever.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Docs? Surprisingly readable.&lt;/li&gt;
&lt;li&gt;StackOverflow? Someone’s already had my exact 2 a.m. bug.&lt;/li&gt;
&lt;li&gt;GitHub repos? New tools and fixes all the time.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It’s like coding with a safety net. You’re never really alone.&lt;/p&gt;

&lt;p&gt;👉 &lt;em&gt;“A good language makes you productive. A good community keeps you sane.”&lt;/em&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  5. Career Insurance (a.k.a. Job Security)
&lt;/h3&gt;

&lt;p&gt;Let’s be honest: passion’s cool, but rent is real.&lt;/p&gt;

&lt;p&gt;C#/.NET devs are still in demand—enterprise apps, startups, cloud systems, even gaming. It’s one of those rare skills that’s both &lt;strong&gt;future-proof&lt;/strong&gt; and &lt;strong&gt;relevant today.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I like tinkering with other languages on weekends, but Monday morning? My paycheck comes from C#. And I’m not mad about that.&lt;/p&gt;

&lt;p&gt;👉 &lt;em&gt;“C# isn’t just a language on my resume. It’s peace of mind.”&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  My “Which Language Do I Use?” Flow (Spoiler: C# Wins)
&lt;/h2&gt;

&lt;p&gt;Here’s literally how my brain works when I start a new project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;               ┌─────────────┐
               │ New Project │
               └──────┬──────┘
                      │
          ┌───────────▼───────────┐
          │ Do I need speed?      │
          └───────────┬───────────┘
                      │
        Yes ─────────►C#/.NET
                      │
        No ──────────►Maybe Python/JS
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And yep—9 times out of 10, it lands on C#. The 10th time? I usually regret it and come back.&lt;/p&gt;




&lt;h2&gt;
  
  
  Mistakes I Made Along the Way
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;I wasted months chasing shiny new languages instead of getting better at one solid one.&lt;/li&gt;
&lt;li&gt;I wrote garbage C# at first and thought “the language will save me.” Spoiler: it won’t.&lt;/li&gt;
&lt;li&gt;I confused “shorter code” with “better code.” Big difference.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ouch. But hey, lessons learned.&lt;/p&gt;




&lt;h2&gt;
  
  
  Quick Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;C# = balance.&lt;/strong&gt; Strict but flexible.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ecosystem covers everything.&lt;/strong&gt; APIs, games, desktop, cloud.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keeps evolving.&lt;/strong&gt; New features, no abandonment.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Community rocks.&lt;/strong&gt; Docs + forums + GitHub = life saver.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Career safe.&lt;/strong&gt; Demand isn’t going anywhere.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;Here’s the weird truth: I didn’t pick C# once. I’ve picked it dozens of times. Every new project, every “let’s compare tools,” every “what should I use for this?” moment. And every single time, I end up back here.&lt;/p&gt;

&lt;p&gt;Other languages feel like flings.&lt;br&gt;
C# feels like home.&lt;/p&gt;

&lt;p&gt;So let me ask you—&lt;br&gt;
👉 What language feels like home for &lt;em&gt;you&lt;/em&gt;?&lt;br&gt;
👉 And if it’s not C#, what’s stopping you from giving it a real shot?&lt;/p&gt;




</description>
      <category>csharp</category>
      <category>dotnet</category>
      <category>microsoft</category>
      <category>beginners</category>
    </item>
    <item>
      <title>[Boost]</title>
      <dc:creator>Sukhpinder Singh</dc:creator>
      <pubDate>Mon, 29 Sep 2025 21:24:49 +0000</pubDate>
      <link>https://dev.to/ssukhpinder/-3aip</link>
      <guid>https://dev.to/ssukhpinder/-3aip</guid>
      <description>&lt;div class="ltag__link"&gt;
  &lt;a href="/ssukhpinder" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F628027%2F2c6c10d0-b7eb-4faa-8e10-2c51a4127c13.gif" alt="ssukhpinder"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://dev.to/ssukhpinder/mastering-date-and-time-in-c-dcp" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Mastering Date and Time in C#&lt;/h2&gt;
      &lt;h3&gt;Sukhpinder Singh ・ Sep 29&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#csharp&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#dotnet&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#programming&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>csharp</category>
      <category>dotnet</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
