<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Anshul Rajput on Medium]]></title>
        <description><![CDATA[Stories by Anshul Rajput on Medium]]></description>
        <link>https://medium.com/@anshulrajput046?source=rss-d07c9f1b3b3f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*zxFsdF_0v03UJ5xHaHnnQA.jpeg</url>
            <title>Stories by Anshul Rajput on Medium</title>
            <link>https://medium.com/@anshulrajput046?source=rss-d07c9f1b3b3f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 06:45:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@anshulrajput046/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[I Haven’t Written Code by Hand in Months. Nobody Told Me I’d Miss It.]]></title>
            <link>https://medium.com/@anshulrajput046/i-havent-written-code-by-hand-in-months-nobody-told-me-i-d-miss-it-89995993d5c2?source=rss-d07c9f1b3b3f------2</link>
            <guid isPermaLink="false">https://medium.com/p/89995993d5c2</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[careers]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Anshul Rajput]]></dc:creator>
            <pubDate>Fri, 20 Nov 2026 11:08:39 GMT</pubDate>
            <atom:updated>2026-11-20T11:08:39.019Z</atom:updated>
            <content:encoded><![CDATA[<h4>AI made me faster than I’ve ever been. It also quietly took away the part of programming I loved. An honest look at what we’re trading, and how to keep the good part.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yl9JXUlyqyW_ntmumlfeDw.png" /></figure><p>Here’s what my workday looks like now.</p><p>I describe a change. One AI agent writes it. A second AI agent reviews it, and I tell that one to be harsh.</p><p>I read the review. I push back. I ask for fixes. I approve.</p><p>Then I do it again. And again. 🔁</p><p>It works. I ship more than I ever have.</p><p>And then one day it hit me. I couldn’t remember the last time I wrote a real function myself, start to finish.</p><p>Nobody warned me about what came next. <strong>I missed it.</strong></p><p>I’ll tell you exactly what I miss in a minute. It surprised me, because it wasn’t the typing.</p><h3>🧑‍💻 The job changed while I wasn’t looking</h3><p>Turns out I’m not the only one feeling this.</p><p>On November 20, CNBC ran a story about developers who are moving faster than ever with AI, but <strong>miss the struggle</strong>. One CTO told them that engineers who used to spend three weeks on a prototype can now make <strong>ten in an afternoon</strong>.</p><p>The same CTO said something that stuck with me:</p><blockquote>“The [AI] agents are spitting out so much code that [engineers] haven’t read it all anymore.”</blockquote><p>And that’s the mood everywhere:</p><ul><li>In September, David Heinemeier Hansson (the creator of Ruby on Rails) told the Rails World crowd it was <strong>“pencils down”</strong> on writing code by hand at his company.</li><li>In October, Microsoft offered voluntary buyouts to about <strong>60,000</strong> employees. TechCrunch summed up Satya Nadella’s explanation like this: everyone uses AI to do their work, and their jobs become focused on managing that AI.</li></ul><p>So the job is quietly turning into this: describe, direct, review, approve.</p><p>That’s real work. Important work. But it’s <em>different</em> work. And nobody really asked us if we wanted to switch.</p><h3>😶 What I actually miss</h3><p>It isn’t the typing. Nobody misses typing.</p><p>Here’s what I miss:</p><ul><li><strong>The flow.</strong> Two hours disappearing into one problem, and looking up surprised that it’s dark outside.</li><li><strong>The click.</strong> That moment when a bug that made zero sense suddenly makes complete sense.</li><li><strong>Owning every line.</strong> Knowing why each line is there, because I put it there.</li><li><strong>The tiny, silly pride</strong> of a clean solution that nobody else will ever notice.</li></ul><p><em>Me, back when I wrote the code myself:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*kmA1c3kvZbEw94aJ.gif" /></figure><p>Reviewing gives you almost none of that. Reviewing is useful. It’s just a different feeling.</p><p>It’s the difference between making chai and tasting someone else’s chai. ☕ You can tell if it’s good. You can say “more ginger.” But you didn’t make it.</p><h3>🧩 The struggle was doing a job</h3><p>Here’s what worries me more than my own feelings.</p><p>All that struggle (the flow, the stuck hours, the click) is how most of us got good. It built the instincts we now use to review AI code.</p><p>A few weeks ago I wrote about <a href="https://medium.com/@anshulrajput046/is-ai-making-me-a-worse-developer-i-checked-the-research-5de1ea8de826">an Anthropic study</a> where developers who leaned on AI learned noticeably less, and the biggest gap was in debugging. That’s the exact skill reviewing depends on.</p><p>CNBC’s story raised the same worry about juniors. If AI takes all the small coding and debugging tasks, where do new developers get their scars?</p><p><strong>We’re reviewing with instincts we built by struggling. Nobody has figured out yet how the next generation builds theirs.</strong></p><h3>📊 Not everyone feels this way (and that’s fine)</h3><p>To be fair, plenty of developers are genuinely happy to let the typing go.</p><p>Lenny’s Newsletter’s 2026 survey of tech workers found people splitting into four groups on AI:</p><ul><li>😄 Energized: <strong>41%</strong></li><li>😐 Conflicted: <strong>35%</strong></li><li>😵 Disoriented: <strong>12%</strong></li><li>😠 Resentful: <strong>12%</strong></li></ul><p>If you feel energized and conflicted on the same day, you’re probably completely normal.</p><p><em>The developer I refuse to become:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*R8VB3z9In3aq2Hr_.gif" /></figure><p>I don’t want to be the person yelling at clouds about how real programmers write everything by hand. I use AI every single day and I’m not going back.</p><p>I just want to keep the part that made me love this job in the first place.</p><blockquote>Let AI do the typing. Keep the thinking.</blockquote><h3>🛠️ How I’m keeping the good part (steal these)</h3><p>Nothing dramatic. Small habits that protect the craft without slowing you down.</p><h4>1. Write one thing by hand every week ✍️</h4><p>A small script, a tiny fix, a coding puzzle. AI switched off. You’re not doing it for the output. You’re doing it for the flow.</p><h4>2. Read everything before you approve it 👀</h4><p>If a change is too big to read, it’s too big to approve. Ask for it in smaller pieces. “I haven’t read it all” should never be how code reaches production.</p><h4>3. Solve it in your head first 🧠</h4><p>Before you prompt, take two minutes to sketch how <em>you</em> would do it. Then compare it with what the agent wrote. Either you learn something, or you catch something.</p><h4>4. Keep the interesting bugs for yourself 🐛</h4><p>Give the boring work to AI. Keep the weird, “how is this even possible” bugs. Those are where the click lives.</p><h4>5. Explain it to someone 🗣️</h4><p>A teammate, a junior, or a blog. If you can explain it in plain words, you still own it. (This is exactly why I started writing again.)</p><h3>💭 So what am I now?</h3><p>I used to describe my job as writing software.</p><p>These days it feels closer to designing it, directing it, and being responsible for it.</p><p>Maybe that’s a promotion. Maybe it’s a different job wearing the old job’s name. I honestly don’t know yet.</p><p>What I do know is that the part of me that loved programming hasn’t gone anywhere. It just needs a little protected time now.</p><h3>⚡ TL;DR (for the scrollers, I see you 👋)</h3><ul><li>AI agents now write most of my code. I direct, review and approve. I ship more than ever.</li><li>What I miss isn’t typing. It’s the flow, the click, owning every line, and quiet pride.</li><li>That struggle is how we built the instincts we now use to review AI code, and juniors may not get it.</li><li>Tech workers are split: <strong>41%</strong> energized, <strong>35%</strong> conflicted, <strong>12%</strong> disoriented, <strong>12%</strong> resentful.</li><li>Write one thing by hand weekly, read before you approve, solve it in your head first, keep the fun bugs, and explain things.</li></ul><p><em>Be honest in the comments 👇 Do you miss writing code by hand? Or are you glad it’s gone? I’ll read every single one.</em></p><p><em>More from me: </em><a href="https://medium.com/@anshulrajput046/ai-writes-the-code-who-checks-it-801d3a6750b1"><em>AI Writes the Code. Who Checks It?</em></a><em> and </em><a href="https://medium.com/@anshulrajput046/is-ai-making-me-a-worse-developer-i-checked-the-research-5de1ea8de826"><em>Is AI Making Me a Worse Developer?</em></a></p><p><strong>Ship fast. Check faster.</strong><br>Anshul ✌️</p><p><strong>Sources</strong></p><ul><li>CNBC, <a href="https://www.cnbc.com/2026/11/20/ai-coding-tools-software-engineers.html">AI is changing software engineering, and some developers miss the struggle</a> (November 20, 2026)</li><li>The Pragmatic Engineer, <a href="https://newsletter.pragmaticengineer.com/p/the-pulse-ror-creator-sparks-new">RoR creator sparks new “death of coding by hand” debate</a></li><li>TechCrunch, <a href="https://techcrunch.com/2026/11/18/microsoft-ceo-satya-nadella-explains-why-he-asked-60k-employees-to-quit">Microsoft CEO Satya Nadella explains why he asked 60K employees to quit</a> (November 18, 2026)</li><li>Lenny’s Newsletter, <a href="https://www.lennysnewsletter.com/p/how-tech-workers-are-feeling-in-2026">How tech workers are feeling in 2026</a></li><li>Anthropic, <a href="https://www.anthropic.com/research/AI-assistance-coding-skills">How AI assistance impacts the formation of coding skills</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89995993d5c2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tokenmaxxing: Amazon Just Told Its Engineers to Stop Using AI for Show]]></title>
            <link>https://medium.com/@anshulrajput046/tokenmaxxing-amazon-just-told-its-engineers-to-stop-using-ai-for-show-4c58886ec3bc?source=rss-d07c9f1b3b3f------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c58886ec3bc</guid>
            <category><![CDATA[claude]]></category>
            <category><![CDATA[tokenization]]></category>
            <category><![CDATA[ai-agent]]></category>
            <category><![CDATA[anthropic-claude]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Anshul Rajput]]></dc:creator>
            <pubDate>Wed, 28 Oct 2026 09:37:50 GMT</pubDate>
            <atom:updated>2026-10-28T09:37:50.282Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Big tech built leaderboards for AI usage. Engineers gamed them. Now Amazon calls those numbers “deeply flawed.” Here’s what that means for the rest of us.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PRjWnWsoudUPUywbGNluqg.png" /></figure><p>Somewhere in a big tech company this year, an engineer asked AI to explain documentation that was sitting right in front of them.</p><p>They didn’t need the help.</p><p>They needed the <strong>number</strong> to go up. Because there was a leaderboard, and their name was too low on it. 👀</p><p>That has a name now: <strong>tokenmaxxing</strong>.</p><p>And on October 27, Amazon officially told its engineers to knock it off. What they said instead is the most sensible thing I’ve read about AI at work all year.</p><h3>🏆 Welcome to the token leaderboard</h3><p>Quick definition first. AI models charge by the <strong>token</strong> (roughly a chunk of a word). More prompts, longer chats, more agents running means more tokens.</p><p>So some companies started tracking token usage to see who was “adopting AI.” And then they started ranking people by it. You can probably guess what happened next.</p><p>According to reporting by The Pragmatic Engineer:</p><ul><li>At <strong>Meta</strong>, an employee-built dashboard nicknamed “Claudeonomics” ranked more than <strong>85,000</strong> employees by token usage. Top users earned titles like <strong>“Session Immortal”</strong> and <strong>“Token Legend.”</strong> I’m not making this up. Meta took it down after a public backlash.</li><li>Meta employees used about <strong>60.2 trillion tokens in 30 days</strong>. At public API prices, that would be roughly <strong>$900 million</strong>. (Meta almost certainly pays less, but still.)</li><li>At <strong>Salesforce</strong>, one message reportedly told staff to spend at least <strong>$170 a month</strong> on an AI coding tool or be flagged.</li><li>A <strong>Microsoft</strong> engineer admitted to prototyping features they had no plan to build, and using agents for tasks they could do faster by hand, just to avoid looking like a low AI user.</li></ul><p><em>Engineering teams, hitting their monthly token target:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/0*-BqqlY62Z8pqRefR.gif" /></figure><p>Amazon had its own version. It shut down an internal leaderboard in May after finding people were handing pointless tasks to AI just to climb the ranks.</p><h3>📜 What Amazon actually said</h3><p>The memo first went around internally in September, then Amazon posted it publicly on October 27. CNBC reported the details. A few lines stood out.</p><p>On metrics: token usage, AI tool adoption rates, and counts of code changes or reviews are <strong>“deeply flawed”</strong> ways to measure how teams use AI. They’re not banned. They should be read <strong>“with care and judgment”</strong>, next to other data.</p><p>On what actually matters: <strong>“We believe that it is best to measure, and be measured by, long-term outcomes.”</strong></p><p>And my favourite line:</p><blockquote>“If your work does not benefit from current AI tooling, that is a finding, not a failing.”</blockquote><p>They also wrote that an engineer who can explain where AI doesn’t help their work yet is <strong>“demonstrating the judgement we are asking for.”</strong></p><p>To be fair to Amazon, this isn’t an anti-AI memo. There are no token caps. Engineers who haven’t picked up the tools are still expected to learn them. The message is simpler: use AI where it helps, and be honest where it doesn’t.</p><h3>📏 We’ve seen this movie before</h3><p>If you’ve been in software for a while, this story feels very familiar.</p><ul><li>Measure <strong>lines of code</strong>, and you get bloated code.</li><li>Measure <strong>story points</strong>, and estimates quietly grow.</li><li>Measure <strong>commits per day</strong>, and you get a lot of tiny commits.</li><li>Measure <strong>test coverage</strong>, and you get tests that touch everything and check nothing.</li></ul><p>Tokens are just the newest member of the family.</p><p>There’s a name for this. It’s called <strong>Goodhart’s law</strong>, usually summed up as: <em>when a measure becomes a target, it stops being a good measure.</em> The moment people are ranked by a number, they get very creative about moving the number.</p><p><em>Me, watching someone climb the token leaderboard:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*2_1gGhTm3slrRkq-.gif" /></figure><p>The sad part is what gets lost. Every token spent on looking busy costs money, adds noise to reviews, and pulls attention away from the work customers actually notice.</p><p><strong>Tokens tell you how hard the AI worked. They don’t tell you if anything got better.</strong></p><h3>🤖 Where AI earns its tokens (in my own work)</h3><p>I use AI agents every single day. One writes code, a different one reviews it hard. So I’m not writing this from the sidelines.</p><p>Here’s where, for me, the tokens are clearly worth it:</p><ul><li><strong>Tough reviews.</strong> A second model reviewing a change has caught bugs that my own tests missed. I wrote about one of them in <a href="https://medium.com/@anshulrajput046/ai-writes-the-code-who-checks-it-801d3a6750b1">AI Writes the Code. Who Checks It?</a></li><li><strong>The boring, well-defined stuff.</strong> Boilerplate, test scaffolding, repetitive changes across many files.</li><li><strong>Finding my way around unfamiliar code.</strong> “Where is this value set, and who reads it?” is a great question for an agent.</li></ul><p>And here’s where tokens get burned for nothing:</p><ul><li><strong>When I haven’t reproduced the problem myself.</strong> If I hand an agent a bug I haven’t confirmed, it happily chases ghosts. Lots of tokens, no fix.</li><li><strong>When the agent “helps” beyond the ask.</strong> Agents often tidy imports, add logging and reformat code nobody asked them to touch. Every extra change is something I now have to review.</li><li><strong>Tiny edits.</strong> A one-line change I can type in ten seconds doesn’t need a prompt, a plan and a review.</li><li><strong>Things I need to truly understand.</strong> Handing those off saves minutes today and costs me later. (That was the whole point of <a href="https://medium.com/@anshulrajput046/is-ai-making-me-a-worse-developer-i-checked-the-research-5de1ea8de826">Is AI Making Me a Worse Developer?</a>)</li></ul><h3>🛠️ Use AI with judgment (steal these)</h3><p>Small habits. No leaderboard needed.</p><h4>1. Ask “would I be faster by hand?” ✋</h4><p>Before you open the chat, take two seconds. If the honest answer is yes, just do it. Nobody gets a medal for prompting.</p><h4>2. Know what “done” looks like before you hand it off 🎯</h4><p>Reproduce the bug. Write down the expected result. An agent with a clear target finishes faster and burns far fewer tokens than one exploring in the dark.</p><h4>3. Watch for extra changes you didn’t ask for 🧹</h4><p>Before you review the logic, check the diff for drive-by edits. Ask the agent to undo anything outside the task. Smaller diffs mean faster, safer reviews.</p><h4>4. Keep a “where AI helps me” list 📝</h4><p>Two columns: helps, doesn’t help (yet). Update it every couple of weeks. It turns a vague feeling into the exact judgment Amazon says it wants to see.</p><h4>5. If you lead a team, measure what customers feel 📈</h4><p>Time from idea to production. Bugs that reach users. Incidents. How often you have to roll back. If AI is helping, these move. If only the token count moves, you’ve learned something too.</p><h3>💭 So, should we use AI less?</h3><p>Not really. We should use it <em>on purpose</em>.</p><p>The engineers who stand out over the next few years won’t be the ones with the biggest token bill. They’ll be the ones who can tell you exactly where AI saved the day, where it wasted an afternoon, and why.</p><blockquote>Use AI like a senior engineer uses a meeting: only when it’s worth everyone’s time.</blockquote><h3>⚡ TL;DR (for the scrollers, I see you 👋)</h3><ul><li><strong>Tokenmaxxing</strong> means burning AI tokens to look productive, often to climb an internal leaderboard.</li><li>Meta’s leaderboard ranked <strong>85,000+</strong> people and handed out titles like “Token Legend” before it was taken down.</li><li>Amazon’s memo calls usage metrics <strong>“deeply flawed”</strong> and says <strong>“that is a finding, not a failing”</strong> when AI doesn’t help.</li><li>It’s Goodhart’s law again: lines of code, story points, and now tokens.</li><li>Ask if you’d be faster by hand, define “done” first, trim extra changes, keep a helps/doesn’t list, and measure outcomes.</li></ul><p><em>Tell me in the comments 👇 Does your company track AI usage? And what do they actually measure?</em></p><p><strong>Ship fast. Check faster.</strong><br>Anshul ✌️</p><p><strong>Sources</strong></p><ul><li>CNBC, <a href="https://www.cnbc.com/2026/10/27/amazon-ai-coding-tokenmaxxing.html">Amazon’s anti-tokenmaxxing memo says engineers should be pickier about using AI</a> (October 27, 2026)</li><li>Quartz, <a href="https://qz.com/amazon-engineers-tokenmaxxing-ai-metrics-memo-102726">Amazon warned engineers AI usage metrics are “deeply flawed”</a></li><li>The Pragmatic Engineer, <a href="https://blog.pragmaticengineer.com/the-pulse-tokenmaxxing-as-a-weird-new-trend/">The Pulse: “Tokenmaxxing” as a weird new trend</a> (April 2026)</li><li>Fortune, <a href="https://fortune.com/2026/04/09/meta-killed-employee-ai-token-dashboard/">Meta killed an employee AI token dashboard</a> (April 2026)</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c58886ec3bc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Is AI Making Me a Worse Developer? I Checked the Research.]]></title>
            <link>https://medium.com/@anshulrajput046/is-ai-making-me-a-worse-developer-i-checked-the-research-5de1ea8de826?source=rss-d07c9f1b3b3f------2</link>
            <guid isPermaLink="false">https://medium.com/p/5de1ea8de826</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[anthropic-claude]]></category>
            <category><![CDATA[generative-ai-tools]]></category>
            <dc:creator><![CDATA[Anshul Rajput]]></dc:creator>
            <pubDate>Thu, 22 Oct 2026 12:33:34 GMT</pubDate>
            <atom:updated>2026-10-22T12:33:34.166Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UsWB-2m2khgUJjjtIK70Bw.png" /></figure><blockquote>A 2026 study found developers who leaned on AI learned less. But the ones who used it a certain way did just fine. The difference is one habit.</blockquote><p>Quick test. 🧪</p><p>Close your AI assistant. Yes, that one, in the sidebar.</p><p>Now tell me what this prints:</p><pre>funcs = [lambda: i for i in range(3)]<br>print([f() for f in funcs])</pre><p>No running it. No asking anyone. Just you and your brain.</p><p><em>Me, trying to answer it without asking AI:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/0*NRaMxNjGbCsyXEix.gif" /></figure><p>Got an answer? Hold on to it. I’ll tell you if you’re right at the end.</p><p>And if your first instinct was to paste it into a chat window… this article is for you. It was for me too. 😅</p><h3>🤔 The question I didn’t want to ask</h3><p>I recently started writing on Medium again after a long break. The reason is simple: writing things down is the best way I know to actually learn them.</p><p>That made me think about the other thing I do every single day. I write code with AI help, all day long.</p><p><strong>Is that helping me learn? Or is it quietly doing the learning for me?</strong></p><p>Turns out somebody already ran the experiment.</p><h3>🔬 The experiment</h3><p>In January 2026, Anthropic (the company behind Claude) published a randomized study.</p><p>Yes, an AI company published research showing AI can make you learn less. Respect. 🫡</p><p>Here’s how it worked. <strong>52 developers</strong>, mostly junior, had to learn a Python library none of them had used before: Trio, a library for async programming.</p><p>Half of them could use an AI assistant. The other half had to do it by hand. Then everyone took a quiz on what they had just learned.</p><p>The results:</p><ul><li>✍️ Coded by hand: <strong>67%</strong></li><li>🤖 Used AI: <strong>50%</strong></li></ul><p>That’s nearly two letter grades. And the biggest gap of all was on <strong>debugging</strong> questions.</p><p>So what did the AI group get in return? They finished about <strong>2 minutes faster</strong>. And that difference wasn’t even statistically significant.</p><p><strong>Two minutes saved. Two letter grades lost.</strong></p><p><em>My debugging skills after a month of letting AI fix every error:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/335/0*ADLzWB4Q5Ai1uT4n.gif" /></figure><h3>🧩 The twist: how you use it matters</h3><p>The AI group didn’t all do badly. The researchers looked at <em>how</em> each person used the assistant, and the patterns split surprisingly cleanly.</p><p><strong>Learned the least (quiz score under 40%):</strong></p><ul><li>Handed the whole task to AI</li><li>Started with a few questions, then slowly handed everything over</li><li>Let AI do the debugging, round after round</li></ul><p><strong>Learned the most (quiz score of 65% or more):</strong></p><ul><li>Generated code, then asked follow-up questions to understand it</li><li>Asked for code and an explanation together</li><li>Asked only conceptual questions, and fixed their own errors</li></ul><p>Look at that second list again. Those people used AI and still scored about as well as the people who had no AI at all.</p><p>So whether AI makes you worse comes down to one question: <strong>who’s doing the thinking?</strong></p><blockquote>If AI does the thinking, AI gets the skill.</blockquote><p>Quick reality check before anyone panics. This was a small study, and some of those groups had only 2 to 7 people in them. The quiz happened right after the task, so it says nothing about the long term. The patterns are correlations, and the researchers say so themselves. It also used a chat assistant in a sidebar, not an agent that edits your files for you. The authors actually expect agents could have a <em>bigger</em> effect. 👀</p><p>So no, this doesn’t prove AI is rotting your brain. But it’s a pretty loud hint.</p><h3>🐛 Why debugging took the biggest hit</h3><p>Think back to how you learned to debug.</p><p>You hit an error. You stared at it. You tried something wrong. Then something else wrong. Then, finally, it clicked.</p><p>That annoying loop is exactly where the skill gets built. When AI fixes the error for you, you skip the loop. You get the fix. You don’t get the lesson.</p><p>And debugging is the one skill you can’t hand off, because it’s what you need when the AI gets it wrong. In <a href="https://medium.com/@anshulrajput046/ai-writes-the-code-who-checks-it-801d3a6750b1">my last article</a> I wrote about a one-line bug that passed all 12 of my tests. Code like that doesn’t announce itself. Somebody has to understand it well enough to smell it.</p><h3>🏋️ What I’m doing about it (steal these)</h3><p>Nothing dramatic. I’m not quitting AI. These are small habits, and each one maps to what the high scorers did.</p><h4>1. Ask “why” before you accept the code 🙋</h4><p>When AI gives you code, find the one line you couldn’t explain to a teammate. Ask about that line. This is literally the “generate, then ask follow-up questions” pattern from the study.</p><h4>2. Give yourself 15 minutes before asking for a fix ⏱️</h4><p>When an error shows up, the first 15 minutes are yours. Read the traceback. Make a guess. Test it. Still stuck? Then ask. You’ll be surprised how often you don’t need to.</p><h4>3. Learning something new? Ask for concepts, write the code yourself 📚</h4><p>For a new library, ask “how does this work and what’s the mental model?” instead of “write this for me.” Save the full handover for things you already know well.</p><h4>4. Explain it back 🗣️</h4><p>In a PR description, a code comment, to a teammate, or in an article. If you can’t explain it in plain words, you don’t own it yet. (This is exactly why I started writing again.)</p><h4>5. Take one no-AI hour a week 🔌</h4><p>Pick a small task and switch the assistant off. Think of it like the gym. You don’t lift weights because the world needs the weights moved. You do it for the muscle. 💪</p><h3>✅ The answer to the quick test</h3><p>Remember the puzzle from the top? Here it is again:</p><pre>funcs = [lambda: i for i in range(3)]<br>print([f() for f in funcs])   # [2, 2, 2]</pre><p>It prints [2, 2, 2]. Most people expect [0, 1, 2].</p><p>Each lambda remembers the <em>variable</em> i, and only looks up its value when you call it. By the time you call them, the loop is over and i is 2. So all three return 2.</p><p>The fix is to grab the value while the loop is running:</p><pre>funcs = [lambda i=i: i for i in range(3)]<br>print([f() for f in funcs])   # [0, 1, 2]</pre><p>Got it right without help? 🎉 Your debugging muscle is in good shape.</p><p>Got it wrong? Even better, honestly. You worked through why, so now you won’t forget it. That’s the whole point of this article.</p><h3>⚡ TL;DR (for the scrollers, I see you 👋)</h3><ul><li>In a 2026 Anthropic study, developers learning a new library scored <strong>50% with AI</strong> vs <strong>67% by hand</strong>. The biggest gap was debugging.</li><li>AI saved them only about <strong>2 minutes</strong>.</li><li>People who used AI to <em>understand</em> scored about as well as people with no AI. People who handed everything over learned the least.</li><li>It’s a small, short-term study. A loud hint, not a final verdict.</li><li>Ask why, try for 15 minutes first, ask for concepts, explain it back, and take a no-AI hour.</li></ul><p><em>Be honest in the comments 👇 Did you get the puzzle right without help? And when did you last debug something with AI switched off?</em></p><p><strong>Ship fast. Check faster.</strong><br>Anshul ✌️</p><p><strong>Sources</strong></p><ul><li>Anthropic, <a href="https://www.anthropic.com/research/AI-assistance-coding-skills">How AI assistance impacts the formation of coding skills</a> (January 2026)</li><li>The full paper on <a href="https://arxiv.org/abs/2601.20245">arXiv (2601.20245)</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5de1ea8de826" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AI Writes the Code. Who Checks It?]]></title>
            <link>https://medium.com/@anshulrajput046/ai-writes-the-code-who-checks-it-801d3a6750b1?source=rss-d07c9f1b3b3f------2</link>
            <guid isPermaLink="false">https://medium.com/p/801d3a6750b1</guid>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[generative-ai-tools]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[vibe-coding]]></category>
            <category><![CDATA[ai-agent]]></category>
            <dc:creator><![CDATA[Anshul Rajput]]></dc:creator>
            <pubDate>Thu, 08 Oct 2026 13:35:11 GMT</pubDate>
            <atom:updated>2026-10-08T13:35:11.086Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Almost every developer ships AI-written code. Almost nobody fully trusts it. Here’s what I do about that gap, and the bug that passed every test I had.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7XWtSyTOdti4GaAtrUU-qA.png" /></figure><p>The tests were green.</p><p>The linter was happy.</p><p>The change looked clean, small, and obvious.</p><p>And the first time anyone called it the “other” way, it would have quietly saved the wrong data. No error, no crash, nothing in the logs. 🙃</p><p>I’ll show you the exact line in a minute. It’s one line, and I promise you’ve written something like it.</p><p>But first, a number that made me put my chai down. ☕</p><h3>📊 The 48% problem</h3><p>On October 6, Stack Overflow released its <strong>2026 Developer Survey</strong>. One question asked developers how much they trust the output of AI tools.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aK_ex1Ue5l6u5BqVD4FgTg.png" /><figcaption>Source: Stack Overflow Developer Survey 2026 (n = 14,304)</figcaption></figure><p>The most popular answer was <strong>“I trust it when I can easily verify the output.”</strong></p><p>And the share who trust AI for <em>important</em> work decisions? <strong>6.6%.</strong></p><p>Put those together. We use AI every day (73% of AI users do, per the same survey), but we trust it only as far as we can check it.</p><p>Which raises an awkward question.</p><p><strong>How many of us actually check?</strong> 🤔</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*D9r_xzZ8gQDpOfQE.gif" /></figure><h3>🕵️ The checking gap</h3><p>Another survey this year, from Sonar, put numbers on it:</p><ul><li><strong>96%</strong> of developers don’t fully trust AI-generated code</li><li>Only <strong>48%</strong> always verify it before committing</li></ul><p>So roughly half of us commit code we don’t trust, without checking it. <em>(Sonar sells code review tools, so add a pinch of salt. But you know it’s not far off.)</em></p><p>This next study surprised me even more.</p><p>In 2025, a research group called <strong>METR</strong> ran a proper randomized study with experienced open-source developers. With AI tools, they finished real tasks <strong>19% slower</strong>.</p><p>But afterwards, those same developers <em>believed</em> AI had made them <strong>20% faster</strong>. 🤯</p><p>Typing got faster. Reviewing, fixing and re-explaining ate all of that time and more, and nobody felt it happening. <em>(Fair warning: METR’s 2026 follow-up was inconclusive, so “AI makes you slower” is not a rule. The gap between how fast we feel and how fast we are is the real lesson.)</em></p><blockquote>AI made writing code faster. Checking it is now where the real time goes.</blockquote><h3>🐛 The bug that passed everything</h3><p>Okay, here’s the bug I promised.</p><p>I work on a trading platform, and we were adding support for a new broker. The code was written with AI help, I reviewed it, and the tests passed. I even ran a mutation sweep (deliberately breaking the code in 12 different ways to check the tests catch each one).</p><p><strong>All 12 caught.</strong> ✅</p><p>Then a second reviewer flagged this line. Here it is, simplified, with the names changed:</p><pre>from enum import Enum</pre><pre>class Broker(Enum):<br>    ACME = &quot;acme&quot;<br>    GLOBEX = &quot;globex&quot;</pre><pre>def pick_master(broker):<br>    if broker == Broker.ACME.value:   # looks fine, right?<br>        return &quot;acme-master&quot;<br>    return &quot;globex-master&quot;</pre><p>Now watch what happens:</p><pre>pick_master(&quot;acme&quot;)        # &#39;acme-master&#39;    ✅<br>pick_master(Broker.ACME)   # &#39;globex-master&#39;  😱</pre><p>Why? Because a plain Python Enum is <strong>not</strong> a string. Broker.ACME == &quot;acme&quot; is False.</p><p>So when the function received the enum instead of the string, it silently fell through to the <em>other</em> broker’s data. A later step then labelled that data with the right broker name. <strong>Wrong data, right label.</strong> The worst kind of bug, because everything looks consistent.</p><p>So why did every test pass? Because every test passed in a <strong>string</strong>. My mutation sweep broke the <em>code</em> 12 ways, but it never changed the <em>input</em>. I proved the code was right for the inputs I thought of. The bug lived in the input I didn’t.</p><p>💡 <strong>The fix:</strong> handle both forms, or use StrEnum (Python 3.11+), where Broker.ACME == &quot;acme&quot; is True.</p><p>The good news: it was caught before commit. Today’s callers all happen to pass strings, so nothing was broken yet. But the next person to pass in the enum would have walked straight into it. It never reached production. 🙏</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/0*ogeS24AlZ4M4n52n.gif" /></figure><p>It taught me something I now repeat like a mantra:</p><blockquote>“Tests pass” is a claim, not a proof.</blockquote><h3>🛠️ What I actually do now (steal these)</h3><p>Nothing fancy here. Pick one and try it tomorrow.</p><h4>1. Let a different AI review the code 🥊</h4><p>The model that wrote the code tends to share its blind spots when it reviews it. So I split the jobs: <strong>one model writes, a different one reviews</strong>, and I tell the reviewer to be harsh: “Find every reason this PR should be rejected.” That’s exactly how the enum bug got caught.</p><h4>2. Change the inputs, not just the code 🎛️</h4><p>Ask: <em>“What types could this argument actually be?”</em> String, enum, None, an empty list, a number sent as a string. Test what your callers could really send, not just the one you had in mind.</p><h4>3. Prove “no regression” by running old vs new 🔬</h4><p>Don’t argue from the diff. Check out the old version, run old and new side by side on the <strong>same real data</strong>, and compare the outputs. Identical where they should be? Proven. Not identical? You just found something.</p><h4>4. Make sure your tests can actually fail 🧨</h4><p>Before trusting a green run, break the code on purpose. If the tests still pass, they weren’t testing what you thought. Bonus: make sure your local setup isn’t quietly supplying something your test forgot to mock.</p><h4>5. Read the diff like a confident intern wrote it 👀</h4><p>Honestly, that’s pretty close to the truth. AI code is often <em>almost right</em>: it compiles, reads well, and is wrong in one boring spot. Slow down on the boring spots: comparisons, default values, else branches, timezones.</p><h3>🧠 The real skill now</h3><p>Writing code is getting cheap. <strong>Knowing whether code is correct is getting expensive.</strong></p><p>The best developer in the room used to be the fastest writer of good code. Now it’s the one who can look at 200 lines of confident, well-formatted AI output and say:</p><blockquote>“Line 47. That’s going to bite us.”</blockquote><p>You build that skill by debugging, reading other people’s code, and getting burned a few times.</p><p>So keep getting burned. Just do it before production. 🔥</p><h3>⚡ TL;DR (for the scrollers, I see you 👋)</h3><ul><li><strong>48%</strong> of developers trust AI only when they can easily check it. Only <strong>6.6%</strong> trust it for important decisions.</li><li>Many of us still commit AI code without fully checking it.</li><li>AI moved the hard part of coding from <strong>writing</strong> to <strong>checking</strong>.</li><li>A one-line enum comparison passed all my tests because I tested the code, not the inputs.</li><li>Use a different AI to review, vary your inputs, compare old vs new, and make sure your tests can fail.</li></ul><p><em>If this saved you one bad Friday deploy, give it a clap 👏 and tell me in the comments: what’s the sneakiest “almost right” bug AI has handed you? I’ll read every one.</em></p><p><strong>Ship fast. Check faster.</strong><br>Anshul ✌️</p><p><strong>Sources</strong></p><ul><li>Stack Overflow 2026 Developer Survey: <a href="https://stackoverflow.blog/2026/10/06/the-results-of-the-2026-developer-survey-are-here">results announcement</a> and <a href="https://survey.stackoverflow.co/2026/ai/data/ai-trust">trust in AI data</a></li><li>Sonar State of Code survey, reported by <a href="https://www.theregister.com/2026/01/09/devs_ai_code/">The Register</a></li><li>METR randomized trial (2025): <a href="https://scienceblog.com/t-a-randomized-trial-by-metr-found-that-experienced-developers-completed-real-coding-tasks-19-slower-when-allowed-to-use-ai-tools-yet-afterwards-they-estimated-on-average-that-ai-had-made-them-20-fast/">summary</a>; on the 2026 follow-up: <a href="https://particula.tech/blog/metr-reversed-19-percent-slower-ai-coding-study">Particula</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=801d3a6750b1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Building a Flexible and Scalable URL Shortener in Django]]></title>
            <link>https://medium.com/@anshulrajput046/building-a-flexible-and-scalable-url-shortener-in-django-f6594d2c0768?source=rss-d07c9f1b3b3f------2</link>
            <guid isPermaLink="false">https://medium.com/p/f6594d2c0768</guid>
            <category><![CDATA[url-shorteners]]></category>
            <category><![CDATA[django-framework]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[api-development]]></category>
            <category><![CDATA[django-rest-framework]]></category>
            <dc:creator><![CDATA[Anshul Rajput]]></dc:creator>
            <pubDate>Sun, 25 May 2025 12:42:37 GMT</pubDate>
            <atom:updated>2025-05-25T12:42:37.174Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*URZEwIJdklyy7eCMHMBeSg.png" /></figure><p>URL shortening is a common feature in many modern web applications. Whether it’s for sharing links on social media, tracking clicks, or simplifying long URLs for readability, having a customizable and reliable URL shortening service is essential.</p><p>In this article, I’ll walk you through how I built a <strong>custom, scalable, and flexible URL shortener using Django</strong>, enhanced by the django-short-url package. We&#39;ll override default functionality to fit real-world use cases like custom domains, flexible serialization, validation, and timestamp tracking on redirects.</p><h3>🧱 Stack &amp; Dependencies</h3><p>To implement this, I used:</p><ul><li><strong>Django</strong> (3.2+)</li><li><strong>django-short-url==1.1.8</strong></li><li><strong>DRF</strong> (Django REST Framework)</li><li><strong>shortuuid</strong></li><li><strong>furl</strong></li><li><strong>drf-yasg</strong> for API docs</li></ul><p>Install required packages:</p><pre>pip install django-short-url==1.1.8 shortuuid furl drf-yasg</pre><h3>⚙️ Django Settings Configuration</h3><p>Enable django_short_url in your INSTALLED_APPS:</p><pre>INSTALLED_APPS = [<br>    ...<br>    &#39;django_short_url&#39;,<br>]</pre><p>Define your custom URL model:</p><pre>SHORT_URL_MODEL = &quot;apps.equity_master.models.custom_short_url.CustomShortURL&quot;</pre><p>Optional settings for greater control:</p><pre>DJANGO_SHORT_URL_DOMAIN = &quot;https://yourdomain.com&quot;<br>DJANGO_SHORT_URL_LENGTH = 10<br>DJANGO_SHORT_URL_REDIRECT_URL = &quot;https://yourdomain.com/404&quot;<br>DJANGO_SHORT_URL_ADD_TIMESTAMP = True<br>DJANGO_SHORT_URL_TIMESTAMP_KEY = &quot;t&quot;<br>BASE_URL = &quot;https://yourdomain.com&quot;</pre><h3>🧩 Creating a Custom URL Model</h3><p>Override the default model to customize behavior and gain flexibility:</p><pre>from django.db import models<br>from django.conf import settings<br>from django_models_ext import BaseModelMixin<br>from django_six import gettext_lazy as _<br><br><br>class CustomShortURL(BaseModelMixin):<br>    surl = models.CharField(<br>        _(u&#39;surl&#39;), max_length=32, blank=True, null=True,<br>        db_index=True, unique=True<br>    )<br>    lurl = models.TextField(<br>        _(u&#39;lurl&#39;), blank=True, null=True,<br>        db_index=True, unique=True<br>    )<br><br>    class Meta:<br>        verbose_name = _(u&#39;shorturl&#39;)<br>        verbose_name_plural = _(u&#39;shorturl&#39;)<br><br>    def __unicode__(self):<br>        return str(self.pk)<br><br>    @property<br>    def fdomain(self):<br>        if hasattr(settings, &#39;DJANGO_SHORT_URL_DOMAIN&#39;):<br>            return settings.DJANGO_SHORT_URL_DOMAIN<br>        elif hasattr(settings, &#39;DOMAIN&#39;):<br>            return settings.DOMAIN<br>        return &#39;&#39;<br><br>    def fsurl(https://medium.com/self,%20domain=None,%20regex=&#39;s&#39;):<br>        return u&#39;{0}/{1}/{2}&#39;.format(domain or self.fdomain, regex, self.surl)<br><br>    @property<br>    def data(self):<br>        return {<br>            &#39;lurl&#39;: self.lurl,<br>            &#39;surl&#39;: self.fsurl(),<br>        }</pre><p>This model adds the ability to construct full short URLs with a custom domain, and defines a data property for simplified response formatting.</p><h3>🛠️ Serializer with Relaxed Validation</h3><p>You might want to allow underscores and port numbers in URLs. Here’s a DRF serializer that does that:</p><pre>from rest_framework import serializers<br>import re<br><br><br>class URLShortenRequestSerializer(serializers.Serializer):<br>    long_url = serializers.CharField(required=True)<br><br>    def validate_long_url(https://medium.com/self,%20value:%20str) -&gt; str:<br>        relaxed_url_regex = re.compile(<br>            r&#39;^(http|https?|ftp)://&#39;<br>            r&#39;(([a-zA-Z0-9-_]+\.)+[a-zA-Z]{2,})&#39;<br>            r&#39;(:\d+)?&#39;<br>            r&#39;(\/[^\s]*)?$&#39;<br>        )<br>        if not relaxed_url_regex.match(value):<br>            raise serializers.ValidationError(&quot;Enter a valid URL.&quot;)<br>        return value</pre><h3>🧪 URL Shortening Logic</h3><p>Here’s the main logic to shorten URLs, create unique slugs using shortuuid, and ensure idempotency by reusing existing entries for the same long URL:</p><pre><br>def get_surl(/service/lurl: str, length: int = None, domain: str = None, regex: str = &#39;s&#39;) -&gt; str:<br>    sobj, _ = CustomShortURL.objects.get_or_create(lurl=lurl)<br><br>    if not sobj.surl:<br>        length = length or getattr(settings, &#39;DJANGO_SHORT_URL_LENGTH&#39;, 22)<br><br>        while True:<br>            sobj.surl = shortuuid.ShortUUID().random(length=length)<br>            try:<br>                sobj.save()<br>                break<br>            except IntegrityError:<br>                # Collision occurred, retry<br>                continue<br><br>    return sobj.fsurl(https://medium.com/domain=domain,%20regex=regex)</pre><h3>🌐 API Endpoint for URL Shortening</h3><p>We now expose a RESTful endpoint using DRF:</p><pre>class ShortenURL(GenericAPIView):<br>    serializer_class = URLShortenRequestSerializer<br>    @swagger_auto_schema(...)<br>    def post(self, request):<br>        serializer = self.get_serializer(data=request.data)<br>        serializer.is_valid(raise_exception=True)<br>        long_url = serializer.validated_data[&quot;long_url&quot;]<br>        surl = get_surl(https://medium.com/long_url,%20regex=f&quot;%7BAPI_PREFIX%7D/s&quot;)<br>        base_url = settings.BASE_URL.rstrip(&#39;/&#39;)<br>        short_url = f&quot;{base_url}{surl}&quot;<br>        return Response({<br>            &quot;long_url&quot;: long_url,<br>            &quot;short_url&quot;: short_url<br>        })</pre><h3>🔁 Redirect View Logic</h3><p>Handles redirection and optional timestamp injection:</p><pre>def convert_to_utf8(url: str) -&gt; str:<br>    return quote(url, safe=&#39;/:&amp;=?#%&#39;)<br><br>def utc_timestamp() -&gt; int:<br>    return int(datetime.utcnow().timestamp())<br><br>def custom_short_url_redirect(request, surl):<br>    try:<br>        lurl = CustomShortURL.objects.get(surl=surl).lurl<br>    except CustomShortURL.DoesNotExist:<br>        lurl = None<br><br>    # Handle case where short URL doesn&#39;t exist<br>    if not lurl:<br>        redirect_url = getattr(settings, &#39;DJANGO_SHORT_URL_REDIRECT_URL&#39;, &#39;&#39;)<br><br>        if callable(getattr(settings, &#39;DJANGO_SHORT_URL_FUNC&#39;, None)):<br>            redirect_url = settings.DJANGO_SHORT_URL_FUNC(request)<br><br>        if not redirect_url:<br>            return render(request, &#39;django_short_url/errmsg.html&#39;, {<br>                &#39;title&#39;: &#39;Error&#39;,<br>                &#39;errmsg&#39;: &#39;Short URL not Exists&#39;<br>            })<br><br>        return redirect(redirect_url)<br><br>    flurl = furl(https://medium.com/lurl)<br><br>    # Optionally append a UTC timestamp<br>    if getattr(settings, &#39;DJANGO_SHORT_URL_ADD_TIMESTAMP&#39;, False):<br>        stamp_key = getattr(settings, &#39;DJANGO_SHORT_URL_TIMESTAMP_KEY&#39;, &#39;t&#39;)<br>        flurl = flurl.remove([stamp_key]).add({stamp_key: utc_timestamp()})<br><br>    # Append query parameters from the original request<br>    redirect_url = flurl.add(<br>        furl(https://medium.com/convert_to_utf8(request.build_absolute_uri())).query.params<br>    ).url<br><br>    return redirect(redirect_url)</pre><h3>🔗 URL Configuration</h3><p>Wire up your views in urls.py:</p><pre>from django.urls import path<br># This goes in your api urls<br>urlpatterns = [<br>    path(&quot;s/&lt;str:surl&gt;&quot;, custom_short_url_redirect, name=&quot;custom_short_url_redirect&quot;),<br>]<br><br># This goes into your project urls<br>urlpatterns = [<br>    path(&quot;s/&lt;str:surl&gt;&quot;, custom_short_url_redirect, name=&quot;custom_short_url_redirect&quot;),<br>]</pre><h3>✅ Sample Request/Response</h3><h3>Request:</h3><pre>POST /shorten-url<br>Content-Type: application/json</pre><pre>{<br>  &quot;long_url&quot;: &quot;https://example.com/path/to/resource&quot;<br>}</pre><h3>Response:</h3><pre>{<br>  &quot;long_url&quot;: &quot;https://example.com/path/to/resource&quot;,<br>  &quot;short_url&quot;: &quot;https://yourdomain.com/s/abc123&quot;<br>}</pre><h3>🧠 Why Customize django-short-url?</h3><p>While django-short-url provides a great foundation, I extended it to:</p><ul><li><strong>Support custom models</strong></li><li><strong>Add timestamp logic on redirects</strong></li><li><strong>Provide API-based interaction</strong></li><li><strong>Improve URL validation</strong></li><li><strong>Ensure unique short links with retry logic</strong></li></ul><h3>🏁 Conclusion</h3><p>You now have a production-ready, customizable URL shortening service built on Django. This setup can be extended to include analytics, user-specific short links, expiration logic, and more.</p><p>Have questions or want to extend this further? Drop a comment or reach out!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f6594d2c0768" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JWT Token Explained: Why It’s Widely Used + Pros, Cons & Use Cases]]></title>
            <link>https://medium.com/@anshulrajput046/jwt-token-explained-why-its-widely-used-pros-cons-use-cases-6696de58ac4f?source=rss-d07c9f1b3b3f------2</link>
            <guid isPermaLink="false">https://medium.com/p/6696de58ac4f</guid>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[jwt-authentication]]></category>
            <category><![CDATA[jwt-token]]></category>
            <category><![CDATA[jwt-auth]]></category>
            <category><![CDATA[jwt]]></category>
            <dc:creator><![CDATA[Anshul Rajput]]></dc:creator>
            <pubDate>Sun, 04 May 2025 08:09:08 GMT</pubDate>
            <atom:updated>2025-05-04T08:09:08.922Z</atom:updated>
            <content:encoded><![CDATA[<p>JWT Token is widely used in web development — but why? Learn the pros, cons, and how JWT compares with other authentication methods in this simple guide.</p><h3>What is a JWT Token?</h3><h3>The Full Form — JSON Web Token</h3><p>JWT stands for <strong>JSON Web Token</strong>. It’s a tiny, secure way for servers and clients (like your browser or phone app) to talk and verify who you are — without needing to constantly check the server’s memory.</p><h3>A Real-World Example (Using a Library Card)</h3><p>Imagine walking into a library. The librarian gives you a special <strong>library card</strong>. Instead of asking who you are every time you borrow a book, they just look at your card. That’s how JWT works — once you log in, you get a “card” (a token) to prove you’re you.</p><h3>What’s Inside a JWT? (Header, Payload, Signature)</h3><p>A JWT is made up of three parts:</p><ul><li><strong>Header</strong>: Says what kind of token it is and how it’s signed.</li><li><strong>Payload</strong>: Holds your information (like user ID or email).</li><li><strong>Signature</strong>: A secret code that proves the token wasn’t tampered with.</li></ul><p>It looks like this: xxxxx.yyyyy.zzzzz – just three strings separated by dots.</p><h3>Why JWT Token is So Popular in Modern Web Apps</h3><h3>Simplicity and Stateless Authentication</h3><p>JWT doesn’t need the server to <strong>remember anything</strong>. Once a token is issued, it works on its own. This makes it super fast and easy to use.</p><h3>Easy to Use with Mobile and Microservices</h3><p>JWTs work great across platforms — web, mobile, and even IoT devices. Microservices love them because they don’t have to call a central server to verify each request.</p><h3>Performance Boost (No Need to Check the Database)</h3><p>Since everything the server needs is inside the token, there’s <strong>no need to hit the database</strong> again and again. That means your app runs faster!</p><h3>JWT vs Other Authentication Mechanisms</h3><h4><strong>JWT vs OAuth 2.0</strong></h4><p>OAuth is more like a <strong>protocol</strong> or set of rules. JWT can be used inside OAuth, but on its own, OAuth handles access across multiple apps (like logging in with Google).</p><h3>JWT vs API Key</h3><p>API keys are just random strings. JWTs are <strong>smart tokens</strong> — they can hold user roles, expiry time, and more.</p><h3>How JWT Works (Step-by-Step Explanation)</h3><ol><li><strong>User Logs In</strong> — You enter your username and password.</li><li><strong>Server Sends Back JWT</strong> — A token is created and sent to you.</li><li><strong>You Store the Token</strong> — Usually in localStorage or cookies.</li><li><strong>Future Requests Include JWT</strong> — Every time you make a request, the token comes along.</li><li><strong>Server Validates the Token</strong> — It checks the signature. If valid, you’re good to go.</li></ol><h3>JWT Token Advantages (Pros)</h3><h3>Lightweight and Compact</h3><p>They’re just text strings — easy to pass around in HTTP headers.</p><h3>No Server Storage Needed</h3><p>Unlike sessions, JWT doesn’t require the server to store anything about the user.</p><h3>Easy to Share Across Services</h3><p>Multiple microservices can <strong>validate the same token</strong> without sharing state.</p><h3>Strong with HTTPS</h3><p>With secure HTTPS and strong signing, JWT is very safe.</p><h3>JWT Token Disadvantages (Cons)</h3><h3>Can’t Be Revoked Easily</h3><p>Once a JWT is out there, it’s valid until it expires — even if the user logs out.</p><h3>Bigger Token Size than Session ID</h3><p>More data inside means larger size, which can affect performance slightly.</p><h3>Risky If Not Stored Securely (XSS Attacks)</h3><p>If you store JWTs in localStorage, and your app is vulnerable to JavaScript injection, someone might steal your token.</p><h3>Complicated Token Rotation</h3><p>Keeping tokens short-lived and refreshing them without annoying users takes some planning.</p><h3>When to Use JWT Token</h3><h3>Perfect for Stateless APIs</h3><p>If you’re building <strong>RESTful APIs</strong> or serverless functions, JWT is perfect. Since it doesn’t rely on server memory, each API call can be handled independently.</p><h3>Great for Mobile and SPAs</h3><p>Single Page Applications (SPAs) and mobile apps often talk to a backend API. JWTs allow them to authenticate quickly, and work well even when offline for a while.</p><h3>Ideal for Microservices and Serverless</h3><p>Microservices are tiny apps that do one job. JWT lets each of them verify the user without needing a shared session. This makes scaling across many services much easier.</p><h3>When NOT to Use JWT Token</h3><h3>When You Need to Revoke Tokens Instantly</h3><p>Imagine someone gets fired, but their token still works for 2 more hours until it expires. With sessions, you could remove them from the database immediately. JWT doesn’t allow this easily.</p><h3>When Using Traditional Web Apps with Sessions</h3><p>Old-school web apps that rely on server-side rendering work best with <strong>session-based authentication</strong>. JWT might be overkill here.</p><h3>If You Want Small, Easily Manageable Tokens</h3><p>JWTs can grow big if you put too much info inside. For low-resource devices or simple apps, a <strong>tiny session ID</strong> might be better.</p><h3>JWT Security Best Practices</h3><p>To keep your tokens (and users) safe, follow these tips:</p><h3>Always Use HTTPS</h3><p>This prevents someone from <strong>stealing tokens</strong> while they’re being sent over the network.</p><h3>Short Expiry Times</h3><p>Set your tokens to <strong>expire quickly</strong>. Use refresh tokens to extend sessions securely.</p><h3>Don’t Store Sensitive Data in Payload</h3><p>Even though the token is signed, anyone can decode the payload. Never put things like passwords inside.</p><h3>Use Strong Signing Algorithms</h3><p>Use RS256 or HS256 for signing. Weak algorithms = easy to fake.</p><h3>Frequently Asked Questions (FAQs)</h3><h3>Is JWT safe to use?</h3><p>Yes — <strong>if used correctly</strong> with HTTPS and secure storage. Never store it in unsafe places like browser memory if you can avoid it.</p><h3>Can JWT be hacked?</h3><p>The token itself is hard to hack due to its digital signature. But poor storage, weak secrets, or vulnerable apps can open doors for attackers.</p><h3>Is JWT better than OAuth?</h3><p>They’re different. <strong>OAuth is a system</strong>; <strong>JWT is a format</strong>. You can actually use JWT <strong>within</strong> OAuth.</p><h3>Where should I store my JWT token?</h3><p>In a secure place. For SPAs, use <strong>HttpOnly cookies</strong> if possible. If you must use localStorage, make sure your app is safe from XSS.</p><h3>Is JWT good for mobile apps?</h3><p>Yes! Mobile apps and JWT tokens are a great match — lightweight, fast, and easy to store on devices.</p><h3>Can JWT be used for login?</h3><p>Absolutely. That’s one of the most common uses. After logging in, the server sends you a JWT which you can use for future requests.</p><h3>Conclusion: Why JWT Token Is the Go-To Choice for Many Developers</h3><p>JWT tokens are like the superhero of modern authentication: <strong>fast, portable, stateless, and simple</strong>. They shine in use cases like APIs, microservices, and mobile apps — where sessions just don’t cut it anymore.</p><p>However, they’re not perfect. JWTs can be <strong>hard to revoke</strong>, and <strong>not ideal for traditional web apps</strong>. But with proper care, good practices, and understanding, JWT becomes a powerful ally in your developer toolkit.</p><p>Whether you’re prepping for interviews or building the next big thing, knowing <strong>when and why to use JWT token</strong> puts you ahead of the game.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6696de58ac4f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Serialization and Deserialization in Django]]></title>
            <link>https://medium.com/@anshulrajput046/understanding-serialization-and-deserialization-in-django-e7b5d2bc78a0?source=rss-d07c9f1b3b3f------2</link>
            <guid isPermaLink="false">https://medium.com/p/e7b5d2bc78a0</guid>
            <category><![CDATA[django-rest-framework]]></category>
            <category><![CDATA[serialization]]></category>
            <category><![CDATA[django-framework]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[deserialization]]></category>
            <dc:creator><![CDATA[Anshul Rajput]]></dc:creator>
            <pubDate>Sun, 20 Apr 2025 13:37:06 GMT</pubDate>
            <atom:updated>2025-04-20T13:37:06.581Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KoLbg2uBcKC_zto2KyoEcw.jpeg" /></figure><p>Serialization and deserialization are two essential concepts that every Django developer must understand. These terms may sound technical at first, but they are actually simple and extremely useful once you get the hang of them.</p><p>Let’s break down the concepts and then move into how they work in Django, in the simplest language possible.</p><h3>🔄 What is Serialization?</h3><p>Serialization is the process of converting complex data types (like Django model instances) into a format that can be easily rendered into JSON, XML, or any other content type. This is especially useful when you want to send data over an API.</p><p>Think of it like this:</p><blockquote><strong><em>Python Object → JSON (or XML)</em></strong></blockquote><p>Example:</p><pre>{<br>    &quot;id&quot;: 1,<br>    &quot;name&quot;: &quot;Anshul&quot;,<br>    &quot;email&quot;: &quot;anshul@example.com&quot;<br>}</pre><p>This JSON can now be sent to a frontend, another API, or stored in a file.</p><h3>Real-world Analogy:</h3><p>Imagine you’re sending a letter to someone in another country. You can’t just send your thoughts. You write them in English (or some other common language). That’s serialization — converting your thoughts (Python objects) into a language others can understand (JSON).</p><h3>🔁 What is Deserialization?</h3><p>Deserialization is the opposite process. It takes data like JSON and converts it back into Python objects (like Django models).</p><blockquote><strong><em>JSON (or XML) → Python Object</em></strong></blockquote><p>This is used when you receive data from an API and want to save or use it in your Django app.</p><h3>Real-world Analogy:</h3><p>Receiving a letter in English and interpreting it in your mind (your thoughts in your language) — that’s deserialization.</p><h3>✅ Why is it Important?</h3><ol><li><strong>APIs</strong>: Serialization is the backbone of APIs.</li><li><strong>Data Portability</strong>: Easily transfer data between systems or over the internet.</li><li><strong>Validation</strong>: Clean and structured way to ensure incoming data is correct.</li><li><strong>Security</strong>: Prevents insecure or malicious data from getting into your system.</li></ol><h3>🔧 Serialization in Django (Without DRF)</h3><p>Django by itself has a basic serializer (django.core.serializers), which can serialize queryset data:</p><pre>from django.core import serializers<br>serialized_data = serializers.serialize(&#39;json&#39;, MyModel.objects.all())</pre><h3>Limitations:</h3><ul><li>No validation</li><li>Read-only</li><li>Can’t handle complex data or nested structures</li></ul><p>That’s where <strong>Django REST Framework</strong> (DRF) comes into play.</p><h3>🔥 Serialization with Django REST Framework (DRF)</h3><p>DRF makes serialization super powerful and flexible. It introduces two core classes:</p><h3>🧱 1. Serializer Class (Manual Serializer)</h3><p>This is like building your form fields by hand. You specify everything.</p><pre>from rest_framework import serializers</pre><pre>class UserSerializer(serializers.Serializer):<br>    id = serializers.IntegerField()<br>    name = serializers.CharField(max_length=100)<br>    email = serializers.EmailField()</pre><h3>When to use it:</h3><ul><li>You want full control over every field.</li><li>Your data isn’t directly tied to a Django model.</li><li>You want custom logic or external data serialization.</li></ul><h3>Pros:</h3><ul><li>Full control</li><li>Great for non-model data</li></ul><h3>Cons:</h3><ul><li>More verbose</li><li>Needs extra code for .create() and .update() methods</li></ul><h3>⚡ 2. ModelSerializer Class (Automatic Serializer)</h3><p>This is the go-to for most developers. It maps fields automatically from a Django model.</p><pre>from rest_framework import serializers<br>from .models import User</pre><pre>class UserModelSerializer(serializers.ModelSerializer):<br>    class Meta:<br>        model = User<br>        fields = [&#39;id&#39;, &#39;name&#39;, &#39;email&#39;]</pre><h3>When to use it:</h3><ul><li>You’re working with Django models</li><li>You want quick and clean code</li></ul><h3>Pros:</h3><ul><li>Less boilerplate</li><li>Built-in .create() and .update()</li><li>Handles nested relationships with less code</li></ul><h3>Cons:</h3><ul><li>Less flexible (but can be overridden)</li></ul><h3>🆚 Serializer vs ModelSerializer</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/1*-a6vUSVudfIxN8dpLKni9A.png" /></figure><p>🛠️ What Happens Under the Hood?</p><h3>Serializing (Python → JSON):</h3><pre>user = User.objects.first()<br>serializer = UserModelSerializer(user)<br>serializer.data  # Returns serialized JSON</pre><h3>Deserializing (JSON → Python):</h3><pre>incoming_data = {&quot;name&quot;: &quot;Anshul&quot;, &quot;email&quot;: &quot;anshul@example.com&quot;}<br>serializer = UserModelSerializer(data=incoming_data)<br>if serializer.is_valid():<br>    user = serializer.save()  # Creates a User object</pre><h3>🧰 Power Features of DRF Serializers</h3><h3>🔍 1. Field Validation</h3><pre>class UserSerializer(serializers.ModelSerializer):<br>    def validate_email(self, value):<br>        if &quot;@example.com&quot; not in value:<br>            raise serializers.ValidationError(&quot;Must use @example.com domain&quot;)<br>        return value</pre><h3>🔄 2. Nested Serializers</h3><pre>class ProfileSerializer(serializers.ModelSerializer):<br>    user = UserModelSerializer()<br>    class Meta:<br>        model = Profile<br>        fields = [&#39;user&#39;, &#39;bio&#39;]</pre><p>Use depth = 1 in Meta for automatic nested serialization.</p><h3>🔒 3. Read-Only &amp; Write-Only Fields</h3><pre>class UserSerializer(serializers.ModelSerializer):<br>    password = serializers.CharField(write_only=True)</pre><pre>    class Meta:<br>        model = User<br>        fields = [&#39;id&#39;, &#39;name&#39;, &#39;email&#39;, &#39;password&#39;]</pre><h3>🧠 4. Custom create() and update()</h3><pre>class UserSerializer(serializers.Serializer):<br>    name = serializers.CharField()</pre><pre>    def create(self, validated_data):<br>        return User.objects.create(**validated_data)</pre><pre>    def update(self, instance, validated_data):<br>        instance.name = validated_data.get(&#39;name&#39;, instance.name)<br>        instance.save()<br>        return instance</pre><h3>🚀 Pro Tips</h3><ul><li>Use context to pass extra info (like request.user) to your serializer.</li><li>Always validate incoming data using .is_valid() before calling .save().</li><li>Split read_only_fields and write_only_fields for better control.</li><li>Use SerializerMethodField for dynamic/custom computed fields.</li></ul><pre>class UserSerializer(serializers.ModelSerializer):<br>    full_name = serializers.SerializerMethodField()</pre><pre>    def get_full_name(self, obj):<br>        return f&quot;{obj.first_name} {obj.last_name}&quot;</pre><h3>✅ Summary</h3><ul><li><strong>Serialization</strong>: Python → JSON</li><li><strong>Deserialization</strong>: JSON → Python</li><li>Use Serializer for custom, non-model data</li><li>Use ModelSerializer for Django models</li><li>Take advantage of DRF features like nested serializers, validation, and custom logic</li></ul><h3>🎯 Final Thoughts</h3><p>Serialization may sound fancy, but it’s just a way to send and receive data in a clean and structured format. Django REST Framework makes it super easy.</p><p>Whether you’re building your first API or managing a complex backend, understanding serializers is key. Take your time, build projects, read the docs, and play with examples.</p><p>The more you practice, the clearer it becomes. Keep experimenting, break things, and keep building!</p><p>Happy coding! 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e7b5d2bc78a0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[10x Your Python Skills with Generators: The Ultimate Guide for Beginners and Pros]]></title>
            <link>https://medium.com/@anshulrajput046/10x-your-python-skills-with-generators-the-ultimate-guide-for-beginners-and-pros-2a17be688e4f?source=rss-d07c9f1b3b3f------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a17be688e4f</guid>
            <category><![CDATA[memory-efficiency]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[python-generators]]></category>
            <category><![CDATA[python-tips]]></category>
            <category><![CDATA[python-programming]]></category>
            <dc:creator><![CDATA[Anshul Rajput]]></dc:creator>
            <pubDate>Fri, 18 Apr 2025 08:53:07 GMT</pubDate>
            <atom:updated>2025-04-18T08:53:07.689Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yp08chwDb2vpDTYlHEMX_Q.jpeg" /></figure><h3>Introduction to Python Generators</h3><p>If you’ve ever struggled with memory limits while processing huge files or wondered how Python streams data so efficiently — <strong>you’ve already brushed past the world of generators</strong> without realizing it.</p><p>Generators are one of Python’s most powerful tools. They’re lightweight, memory-efficient, and designed for <strong>lazy evaluation</strong> — that is, generating values on the fly rather than all at once.</p><p>So whether you’re a beginner or someone preparing for a Python interview, this guide will make you a <strong>generator guru</strong> by the end.</p><h3>Generator Functions vs Normal Functions</h3><p>In Python, a <strong>normal function</strong> returns a value using return. Once it does, it’s done. A <strong>generator function</strong>, on the other hand, uses yield, and can <strong>pause and resume</strong> its execution.</p><pre>def simple_gen():<br>    yield 1<br>    yield 2<br>    yield 3</pre><p>Calling simple_gen() doesn’t give you the values—it gives you a <strong>generator object</strong> that you can iterate over.</p><h3>The yield Keyword</h3><p>Think of yield as a <strong>bookmark</strong>—it tells Python to “pause here and come back later.”</p><p>When the generator is resumed, it picks up <strong>right where it left off</strong>. This is fundamentally different from a return, which ends the function entirely.</p><h3>Internal State Maintenance</h3><p>Generators <strong>remember their state</strong>, so they’re perfect for:</p><ul><li>Long-running processes</li><li>Iterative algorithms</li><li>Lazy loading large datasets</li></ul><h3>Basic Syntax and Structure</h3><p>Here’s a simple generator in action:</p><pre>def countdown(n):<br>    while n &gt; 0:<br>        yield n<br>        n -= 1</pre><p>To use it:</p><pre>for number in countdown(5):<br>    print(number)</pre><p>This prints:</p><pre>5<br>4<br>3<br>2<br>1</pre><p>Easy, right?</p><h3>Generator Expressions (Generator Comprehensions)</h3><p>Like list comprehensions, but <strong>lazy</strong>:</p><pre>squares = (x*x for x in range(1000))</pre><p>These take up almost <strong>zero memory</strong>. Perfect when working with <strong>huge data sets</strong>.</p><p>Compare with:</p><pre>squares_list = [x*x for x in range(1000)]  # Loads all at once</pre><h3>Use-Cases That Demand Generators</h3><ul><li><strong>Reading huge files line by line</strong> without loading the whole file</li><li><strong>Streaming APIs or sensor data</strong></li><li>Processing real-time logs</li><li>Infinite sequences (e.g., Fibonacci series, primes)</li></ul><p>Example:</p><pre>def read_large_file(filename):<br>    with open(filename) as f:<br>        for line in f:<br>            yield line</pre><h3>Chaining Generators Like a Pro</h3><p>Generators can be chained to form <strong>pipelines</strong>:</p><pre>def gen1():<br>    yield from range(5)</pre><pre>def gen2():<br>    for item in gen1():<br>        yield item * 2</pre><p>This keeps your code <strong>modular, readable, and reusable</strong>.</p><h3>Performance Gains with Generators</h3><h3>Memory Efficient</h3><p>Generators are <strong>lazy</strong> — they don’t store data in memory.</p><h3>Speedy in Right Use-Cases</h3><p>For I/O-bound tasks or streamed data, they are <strong>faster and cleaner</strong>.</p><h3>Handling Exceptions in Generators</h3><p>Use try-except inside your generator:</p><pre>def safe_gen():<br>    try:<br>        yield 1<br>        yield 2 / 0<br>    except ZeroDivisionError:<br>        yield &quot;Handled error&quot;</pre><p>Generators also raise StopIteration when done. You can handle this when using next() manually.</p><h3>Generator Tricks &amp; Advanced Patterns</h3><ul><li><strong>yield from</strong> to delegate to sub-generators</li><li>Creating <strong>infinite</strong> streams</li><li>Using .send() for <strong>coroutines</strong> (semi-advanced)</li></ul><h3>Generators vs Iterators vs Coroutines</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*Be0HK28xa_wftf0IVyjscA.png" /></figure><h3>Common Mistakes and How to Avoid Them</h3><p>Mistake Why It’s Wrong Fix Using return instead of yield Ends function early Use yield to continue Forgetting to iterate over generator Doesn’t produce output Use for, list(), or next() Assuming a generator is reusable Most aren’t Re-call function if needed again</p><h3>Do’s and Don’ts of Using Python Generators</h3><p><strong>Do:</strong></p><ul><li>Use for large data or streamed content</li><li>Handle exceptions properly</li><li>Chain for modularity</li></ul><p><strong>Don’t:</strong></p><ul><li>Use where random access is required</li><li>Over-complicate logic inside generators</li></ul><h3>Python Generators in Interviews</h3><h3>Common Questions:</h3><ol><li>What is a generator in Python?</li><li>How is it different from an iterator?</li><li>Can a generator be reused?</li><li>What is the difference between yield and return?</li></ol><h3>Tip:</h3><p>Show a <strong>practical example</strong>, like a file reader or Fibonacci generator, and explain its <strong>advantages</strong> clearly.</p><h3>Python Libraries That Use Generators</h3><ul><li>itertools – infinite iterators, combinations, etc.</li><li>os.walk() – yields directories lazily</li><li>glob.iglob() – lazy file matching</li></ul><h3>Testing and Debugging Generators</h3><pre>gen = countdown(3)<br>print(next(gen))  # Step through<br>print(next(gen))</pre><p>You can also test using:</p><pre>assert list(countdown(3)) == [3, 2, 1]</pre><h3>Wrapping Up</h3><p>Python Generators are a <strong>hidden gem</strong>. They:</p><ul><li>Save memory</li><li>Improve performance</li><li>Work great with streams and pipelines</li></ul><p>Now that you’ve got the know-how, it’s time to use it.py</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a17be688e4f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ The Mysterious Math Black Hole: Why Every Number Falls Into the 4–2–1 Trap]]></title>
            <link>https://medium.com/@anshulrajput046/the-mysterious-math-black-hole-why-every-number-falls-into-the-4-2-1-trap-63bf88020154?source=rss-d07c9f1b3b3f------2</link>
            <guid isPermaLink="false">https://medium.com/p/63bf88020154</guid>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[number-theory]]></category>
            <category><![CDATA[collatz-conjecture]]></category>
            <category><![CDATA[game-theory]]></category>
            <category><![CDATA[statistics]]></category>
            <dc:creator><![CDATA[Anshul Rajput]]></dc:creator>
            <pubDate>Tue, 08 Apr 2025 18:19:25 GMT</pubDate>
            <atom:updated>2025-04-08T18:19:25.237Z</atom:updated>
            <content:encoded><![CDATA[<h3>What Is This So-Called Math Black Hole?</h3><p>Imagine you have a number. Any number. Let’s say 13. You follow a very simple game: if the number is even, divide it by 2. If it’s odd, multiply it by 3 and add 1. You repeat that over and over.</p><p>Eventually, <strong>no matter what number you start with</strong>, you’ll end up in a little number loop: <strong>4 → 2 → 1 → 4…</strong></p><p>Weird, right? It’s like every number in the universe is being pulled into the same black hole. You can call it the <strong>Number Bermuda Triangle</strong> if you like.</p><h3>Say Hello to Collatz: The Guy Behind the Magic</h3><p>This whole wacky concept came from a German mathematician named <strong>Lothar Collatz</strong> in 1937. He probably thought, “Hey, what if I invent the simplest math puzzle in the world and make every genius go bananas for 100 years?”</p><p>And you know what? <strong>It worked.</strong></p><p>The math community has been scratching their heads ever since. Collatz tossed this problem out there like a brain grenade and walked away like a boss. Boom.</p><h3>How Does the Collatz Conjecture Work?</h3><h4>The Rules, As Simple As Brushing Your Teeth</h4><p>Here’s your daily math skincare routine:</p><ol><li>Pick a number (any number!).</li><li>If it’s <strong>even</strong>, divide it by 2.</li><li>If it’s <strong>odd</strong>, do 3n + 1 (triple it, then add 1).</li><li>Repeat.</li><li>Sit back and watch the magic.</li></ol><h4>Let’s Try a Few Numbers (With a Twist!)</h4><p>Let’s say you’re in a silly mood and you pick the number <strong>7</strong>.</p><pre>7 → 22 → 11 → 34 → 17 → 52 → 26 → 13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1</pre><p>BOOM. You hit the <strong>4 → 2 → 1</strong> loop.</p><p>Now try <strong>19</strong>. Or <strong>73</strong>. Or <strong>1,343,226</strong>. They all fall into that same tiny loop eventually.</p><p>It’s like math is a sneaky magician who always pulls the same rabbit out of the hat.</p><h3>Why It’s Called the Black Hole of Math</h3><p>Because just like a real black hole pulls in everything — light, stars, your favorite socks from the laundry — this number loop <strong>sucks in every number you throw at it</strong>.</p><p>You start with chaos, and you always land in the same place. The loop of doom. Or… delight?</p><h3>The Legendary 4 → 2 → 1 Loop</h3><p>This is it. The universal final form. Like the math version of Thanos: inevitable.</p><h4>Even Your Grandma Will End Up Here</h4><p>No offense to Grandma, but even her Bingo numbers will fall into this loop. It’s that powerful.</p><h3>But… What If? The Big Question That Haunts Mathematicians</h3><p>Here’s the kicker: <strong>no one has ever proven</strong> that every number always ends in 1.</p><p>It’s been tested up to mind-boggling numbers (like 2⁶⁰), and it’s always worked. But a full proof? Still missing.</p><p>It’s like knowing every episode of your favorite show ends the same way… but nobody can explain <em>why</em>.</p><h3>Why Is It So Hard to Prove?</h3><p>Short answer: Math is hard.</p><p>Long answer: This problem isn’t about big math, it’s about <em>weird</em> math. Each number’s journey is like a fingerprint — totally different — but they all end up in the same place. Proving that <em>every</em> possible journey ends at 1? That’s a puzzle inside a riddle wrapped in a burrito.</p><h3>Where This Problem Shows Up in Real Life (Surprise!)</h3><p>Programmers love this problem. It’s a great way to practice loops and conditions in coding. Kids love it too — because once they start, they can’t stop playing with numbers.</p><p>It’s also weirdly hypnotic. Try it yourself, and you’ll see.</p><h3>Wild Theories and Nerdy Memes</h3><ul><li>Some people believe the loop is proof of hidden math patterns.</li><li>Others think it’s a trap from the Matrix.</li><li>Math Twitter has memes about the Collatz Conjecture that are… unreasonably funny.</li></ul><h3>Can You Beat the Collatz Curse? (Spoiler: You Can’t)</h3><p>Challenge: Try to find a number that <strong>doesn’t</strong> fall into the 4 → 2 → 1 loop.</p><p>You can’t. But hey, I dare you to try.</p><h3>Teaching It to Kids, Cats, and Confused Adults</h3><p>The best way to teach this is with snacks.</p><ul><li>“If you have 10 cookies and it’s even, eat half.”</li><li>“If you have 9 cookies and it’s odd, triple it and add one — now you’ve got 28. That’s a sugar rush.”</li></ul><p>Fun, visual, and edible.</p><h3>Collatz in Pop Culture (Well, Sort Of…)</h3><p>Okay, it’s not in Marvel movies (yet), but it’s in YouTube math videos, nerdy web comics, and math lectures that get millions of views.</p><p>Who knew a number loop could be this famous?</p><h3>FAQs: Frequently Absurd Questions About the Collatz Conjecture</h3><p><strong>Q: Can I beat it with a negative number?</strong><br> A: You rebel. But no, we’re only talking positive integers here.</p><p><strong>Q: What if I add 2 instead of 1?</strong><br> A: Then you’re inventing your own problem. Nice try, rebel genius.</p><p><strong>Q: Does this mean math is haunted?</strong><br> A: Possibly. This loop sure is spooky.</p><p><strong>Q: Can aliens solve this?</strong><br> A: Maybe. But even if they do, they probably still end up with 4 → 2 → 1.</p><h3>Conclusion: Why We Still Love a Problem with No Answer</h3><p>The Collatz Conjecture is simple, mysterious, and just a little bit magical. It doesn’t matter how old you are or how much math you know — this puzzle pulls you in like a gravity well.</p><p>And the best part? <strong>It’s still unsolved.</strong></p><p>So next time someone says math is boring, tell them about the number that turns into a black hole.</p><p>Or better yet — ask them to play the game. And watch their face when they hit… 4 → 2 → 1.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=63bf88020154" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Writing Cleaner Python: The Art of Pythonic Code (And When Not to Use It)]]></title>
            <link>https://medium.com/@anshulrajput046/writing-cleaner-python-the-art-of-pythonic-code-and-when-not-to-use-it-11a7f8363691?source=rss-d07c9f1b3b3f------2</link>
            <guid isPermaLink="false">https://medium.com/p/11a7f8363691</guid>
            <category><![CDATA[python-basic-questions]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[zen-of-python]]></category>
            <category><![CDATA[optimization]]></category>
            <category><![CDATA[python-programming]]></category>
            <dc:creator><![CDATA[Anshul Rajput]]></dc:creator>
            <pubDate>Tue, 08 Apr 2025 03:26:22 GMT</pubDate>
            <atom:updated>2025-04-08T03:26:22.337Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><em>“Simple is better than complex. Readability counts.” — The Zen of Python</em></blockquote><p>If you’ve spent more than a few weeks writing Python, you’ve probably heard the term <em>“Pythonic”</em>. It’s often tossed around as a gold standard for writing elegant, readable, and concise code. But here’s the twist: <em>Pythonic doesn’t always mean better.</em> In this article, we’ll take a deep dive into Pythonic constructs, when to use them, when to avoid them, and how they actually perform under the hood.</p><h3>🧰 What Does Pythonic Mean?</h3><p>To be Pythonic means to write code that follows the idioms and stylistic recommendations of the language. Think of it like speaking fluent Python, rather than translating from another language. It usually means code that is:</p><ul><li>Readable</li><li>Concise</li><li>Elegant</li><li>Intuitive</li></ul><h3>🔢 List Comprehensions vs. Traditional For Loops</h3><h3>Classic For-Loop:</h3><pre>squared = []<br>for x in range(10):<br>    squared.append(x ** 2)</pre><h3>Pythonic Way:</h3><pre>squared = [x ** 2 for x in range(10)]</pre><h3>Pros:</h3><ul><li>More concise</li><li>Slightly faster due to internal optimizations</li><li>Declarative: expresses <em>what</em> you want, not <em>how</em></li></ul><h3>Cons:</h3><ul><li>Harder to debug or add print statements</li><li>Poor readability with complex logic or nesting</li></ul><h3>When to Use:</h3><ul><li>For simple transformations and filters</li></ul><h3>When Not to:</h3><ul><li>If it includes nested loops or complex conditional logic</li></ul><h3>🔹 Dict &amp; Set Comprehensions</h3><pre>squared_dict = {x: x ** 2 for x in range(5)}<br>unique_letters = {char for char in &quot;abracadabra&quot; if char not in &quot;abc&quot;}</pre><p>These follow the same rules as list comprehensions. Keep it simple and clean. Don’t over-nest.</p><h3>🤍 Lambda Functions vs. Named Functions</h3><pre>square = lambda x: x ** 2</pre><p>Great for one-liners in map, filter, or sorted. But they fall apart with complexity.</p><h3>Use When:</h3><ul><li>You need a quick, throwaway function</li><li>You’re working with functional constructs like map()</li></ul><h3>Avoid When:</h3><ul><li>Logic is complex</li><li>You need docstrings or clarity</li></ul><h3>❓ Ternary Conditional Expressions</h3><pre>result = &quot;even&quot; if x % 2 == 0 else &quot;odd&quot;</pre><h3>Use:</h3><ul><li>For single-line conditionals</li></ul><h3>Avoid:</h3><ul><li>Nesting or chaining multiple ternary operations</li></ul><h3>🔢 Unpacking and Extended Unpacking</h3><pre>a, b, *rest = [1, 2, 3, 4, 5]</pre><h3>Pros:</h3><ul><li>Clean way to deal with sequences</li></ul><h3>Cons:</h3><ul><li>Can become unreadable if overused</li></ul><h3>🚀 Built-ins like any(), all(), zip(), and enumerate()</h3><pre>if any(x &gt; 10 for x in nums):<br>    print(&quot;There&#39;s a number &gt; 10&quot;)</pre><pre>for i, val in enumerate(my_list):<br>    print(i, val)</pre><p>These are not just elegant, they are more efficient and expressive than manual indexing or looping.</p><h3>⭐ Chained Comparisons</h3><pre>if 5 &lt; x &lt; 10:<br>    print(&quot;x is between 5 and 10&quot;)</pre><p>Readable and elegant. Prefer it over x &gt; 5 and x &lt; 10.</p><h3>📂 The with Statement</h3><pre>with open(&quot;file.txt&quot;) as f:<br>    contents = f.read()</pre><h3>Gains:</h3><ul><li>Handles closing files automatically</li><li>Prevents resource leaks</li></ul><p>Always use with for file and resource management.</p><h3>🔗 collections &amp; itertools: Be Lazy and Efficient</h3><p>Use tools like Counter, defaultdict, and namedtuple for data handling. Use itertools.chain() or groupby() to simplify complex iterations.</p><pre>from collections import Counter<br>count = Counter(&quot;abracadabra&quot;)</pre><p>They’re often more readable, and much more performant.</p><h3>🌎 Are Pythonic Constructions Actually Faster?</h3><p>Yes and no.</p><h3>Faster:</h3><ul><li>List comprehensions are faster than for loops for simple expressions.</li><li>any(), all(), and map()/filter() are optimized in C under the hood.</li></ul><h3>Slower or Problematic:</h3><ul><li>Deeply nested comprehensions become slow and unreadable</li><li>Lambdas don’t allow multi-line logic or debugging</li><li>Overusing syntactic sugar often leads to cryptic code</li></ul><p><strong>Benchmark Example:</strong></p><pre># For loop<br>result = []<br>for x in range(100000):<br>    result.append(x * 2)</pre><pre># List comprehension<br>result = [x * 2 for x in range(100000)]</pre><p>List comprehensions are usually about 30–40% faster.</p><h3>🎓 What You Gain vs. What You Lose</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZzEG2u1IV-fiGWaWvfF3qQ.png" /></figure><p>Being Pythonic isn’t about flexing your one-liner muscles. It’s about writing code that feels natural, is easy to read, and gets the job done with elegance. But always ask yourself:</p><ul><li>Is this readable?</li><li>Is this maintainable?</li><li>Would future me (or my teammate) understand this easily?</li></ul><p>Use the power of Python, but don’t forget the wisdom of simplicity. Happy coding! 📚🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=11a7f8363691" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>