Here we are again with another principle from The Pragmatic Programmer — EXCEPTIONS 📘 One of the problems with exceptions is knowing when to use them. Are they meant for every error? No, They should be used only for unexpected situations — the things that break your assumptions. If something is part of normal program behavior — like: • A user entering invalid input • Searching for a record that might not exist • Checking if an optional file is present That’s normal flow. Handle it with regular conditions (if/else, return values). That’s just your program doing its job. But if something happens that breaks a core assumption — like: • A configuration file that is guaranteed to exist is suddenly missing • A database connection fails unexpectedly • A critical dependency crashes That’s exceptional. That’s when you use an exception. A simple mindset shift helped me: Exceptions are not traffic lights controlling normal flow. They’re fire alarms 🚨 — you use them when something that should never happen actually happens. #programming #softwaredevelopment #cleancode #coding #bestpractices #pragmaticprogrammer #javascript #php #softwareengineering
Pragmatic Programmer: Using Exceptions for Unexpected Situations
More Relevant Posts
-
🚀 𝐌𝐚𝐬𝐭𝐞𝐫𝐢𝐧𝐠 𝐍𝐚𝐦𝐢𝐧𝐠 𝐂𝐨𝐧𝐯𝐞𝐧𝐭𝐢𝐨𝐧𝐬 𝐢𝐧 𝐏𝐫𝐨𝐠𝐫𝐚𝐦𝐦𝐢𝐧𝐠 🚀 Consistency in naming isn’t just style—it’s clarity, collaboration, and long-term success. Here are some of the most common conventions every developer should know: 🔹 𝐂𝐚𝐦𝐞𝐥 𝐂𝐚𝐬𝐞 👉 Example: firstName 💡 Usage: Variables & functions 🔹 𝐏𝐚𝐬𝐜𝐚𝐥 𝐂𝐚𝐬𝐞 👉 Example: UserAccount 💡 Usage: Classes, interfaces, enums 🔹 𝐒𝐧𝐚𝐤𝐞 𝐂𝐚𝐬𝐞 👉 Example: user_account 💡 Usage: Python variables, DB fields 🔹 𝐊𝐞𝐛𝐚𝐛 𝐂𝐚𝐬𝐞 👉 Example: user-account 💡 Usage: URLs, CSS classes 🔹 𝐒𝐜𝐫𝐞𝐚𝐦𝐢𝐧𝐠 𝐂𝐚𝐬𝐞 👉 Example: MAX_SIZE 💡 Usage: Constants 🔹 𝐇𝐮𝐧𝐠𝐚𝐫𝐢𝐚𝐧 𝐍𝐨𝐭𝐚𝐭𝐢𝐨𝐧 👉 Example: strFirstName, arrUserNames 💡 Usage: Legacy C/C++ style ✨ 𝐁𝐞𝐬𝐭 𝐏𝐫𝐚𝐜𝐭𝐢𝐜𝐞𝐬 1. Stay consistent across your codebase 2. Use clear, descriptive names 3. Follow language-specific guidelines (PEP 8, Java conventions, etc.) 𝘎𝘰𝘰𝘥 𝘯𝘢𝘮𝘪𝘯𝘨 = 𝘳𝘦𝘢𝘥𝘢𝘣𝘭𝘦, 𝘮𝘢𝘪𝘯𝘵𝘢𝘪𝘯𝘢𝘣𝘭𝘦, 𝘢𝘯𝘥 𝘴𝘤𝘢𝘭𝘢𝘣𝘭𝘦 𝘤𝘰𝘥𝘦. 🧑💻 #Programming #CodeQuality #BestPractices #SoftwareDevelopment #CleanCode #DevTips
To view or add a comment, sign in
-
The Power of Iteration, the Art of the Loop 🔄 In programming, if you have to do the same thing twice, you’re doing it wrong. Today was all about efficiency and automation as I dove deep into JavaScript Loops. What I covered today: ✔️ The Logic of Iteration ✔️ The "For" Loop ✔️ The "While" & "Do-While" Loops ✔️ Control Flow ✔️ Problem Solving 📢 You can check out my GitHub repo in comment. #JavaScript #CodingJourney #WebDevelopment #Loops #BangladeshDevelopers
To view or add a comment, sign in
-
-
💻 Keep these handy (Developer Edition) Code Snippet Library → https://snippets.dev Free API Collection → https://lnkd.in/gsTgEWeC Regex Tester → https://regex101.com JSON Formatter → https://jsonformatter.org CSS Generator → https://cssgenerator.org Favicon Generator → https://lnkd.in/gG2JY5ES Open Source Alternatives → https://lnkd.in/gccktyrw System Design Primer → https://lnkd.in/gJzpSaTh Dev Docs Search → https://devdocs.io Save this list — it will save you hours while building. 🚀 #WebDevelopment #Developers #Programming #DevTools #DeveloperResources #CodingTips
To view or add a comment, sign in
-
-
JavaScript doesn’t execute code randomly. Every time it runs, it creates an Execution Context ⚡ Understanding this concept makes hoisting and closures much easier to master. 🔹 Two Main Phases: 1️⃣ Memory Creation Phase • Variables are stored as undefined • Functions are stored completely in memory 2️⃣ Code Execution Phase • Code runs line by line • Values get assigned 🔹 Example: var a = 10; function greet() { console.log("Hello"); } 👉 Memory Phase: a → undefined greet → full function 👉 Execution Phase: a → 10 Once you understand Execution Context, debugging becomes much easier and JavaScript starts making logical sense instead of feeling “magical”. Connect with me on LinkedIn: https://lnkd.in/dx7fPEsy #JavaScript #ExecutionContext #FrontendDeveloper #WebDevelopment #Programming #Coding #Developers #TechContent #LearningInPublic 🚀
To view or add a comment, sign in
-
-
The Ultimate JavaScript Array Methods Cheat Sheet for Developers JavaScript array methods are powerful tools for manipulating and transforming data efficiently. This comprehensive cheat sheet provides detailed explanations, syntax, and practical examples for all essential array methods, helping you write cleaner, more efficient, and modern JavaScript code. Read the full article 👇 https://lnkd.in/d_q_Ynf9 #Programming #WebDevelopment #SoftwareEngineering #Tech #Coding #JavaScript #JSArrayMethods #FrontendDevelopment #JavaScriptTips #ArrayMethods #FutureOfWork #DigitalTransformation
To view or add a comment, sign in
-
-
Sharing beginner-friendly notes on Advanced Functions in JavaScript 🧠 Covered two of the most important concepts every JS developer needs to master, Closures and Higher-Order Functions. The guide walks through how closures "remember" their lexical scope, enabling data privacy, memoization, and function factories. Also explored essential Higher-Order Functions like map, filter, reduce, and practical utilities like debounce, throttle, curry, and compose with clear examples and visual diagrams. A practical guide for understanding how functions truly work under the hood. Feedback and suggestions are welcome! #JavaScript #Coding #Learning #Programming
To view or add a comment, sign in
-
𝐄𝐯𝐞𝐫𝐲 𝐃𝐞𝐯𝐞𝐥𝐨𝐩𝐞𝐫 𝐇𝐚𝐬 𝐅𝐞𝐥𝐭 𝐓𝐡𝐢𝐬 𝐏𝐚𝐢𝐧 Spent hours debugging… Restarted the server… Checked the database… Blamed the framework… Even questioned your career choice for a minute. And the issue? A missing semicolon… An extra comma… Or one tiny typo hiding in 1,000 lines of code. 🛠️ Tiny errors. 💥 Massive crashes. 📉 Broken builds. 📈 Big learning. From React components not rendering… To Node.js servers failing silently… To APIs throwing 500s… Most disasters start with the smallest syntax mistake. Debugging isn’t frustration - it’s how great engineers are built. It teaches patience, attention to detail, and real problem-solving. So next time you’re stuck… Double-check your syntax. Read the logs again. Trust the process. #DeveloperLife #Debugging #Programming #JavaScript #FullStack #WebDevelopment #CodingJourney #SoftwareEngineering #TechLife #LearnToCode
To view or add a comment, sign in
-
-
𝐄𝐯𝐞𝐫𝐲 𝐃𝐞𝐯𝐞𝐥𝐨𝐩𝐞𝐫 𝐇𝐚𝐬 𝐅𝐞𝐥𝐭 𝐓𝐡𝐢𝐬 𝐏𝐚𝐢𝐧 Spent hours debugging… Restarted the server… Checked the database… Blamed the framework… Even questioned your career choice for a minute. And the issue? A missing semicolon… An extra comma… Or one tiny typo hiding in 1,000 lines of code. 🛠️ Tiny errors. 💥 Massive crashes. 📉 Broken builds. 📈 Big learning. From React components not rendering… To Node.js servers failing silently… To APIs throwing 500s… Most disasters start with the smallest syntax mistake. Debugging isn’t frustration - it’s how great engineers are built. It teaches patience, attention to detail, and real problem-solving. So next time you’re stuck… Double-check your syntax. Read the logs again. Trust the process. #DeveloperLife #Debugging #Programming #JavaScript #FullStack #WebDevelopment #CodingJourney #SoftwareEngineering #TechLife #LearnToCode
To view or add a comment, sign in
-
-
𝐄𝐯𝐞𝐫𝐲 𝐃𝐞𝐯𝐞𝐥𝐨𝐩𝐞𝐫 𝐇𝐚𝐬 𝐅𝐞𝐥𝐭 𝐓𝐡𝐢𝐬 𝐏𝐚𝐢𝐧 Spent hours debugging… Restarted the server… Checked the database… Blamed the framework… Even questioned your career choice for a minute. And the issue? A missing semicolon… An extra comma… Or one tiny typo hiding in 1,000 lines of code. 🛠️ Tiny errors. 💥 Massive crashes. 📉 Broken builds. 📈 Big learning. From React components not rendering… To Node.js servers failing silently… To APIs throwing 500s… Most disasters start with the smallest syntax mistake. Debugging isn’t frustration - it’s how great engineers are built. It teaches patience, attention to detail, and real problem-solving. So next time you’re stuck… Double-check your syntax. Read the logs again. Trust the process. #DeveloperLife #Debugging #Programming #JavaScript #FullStack #WebDevelopment #CodingJourney #SoftwareEngineering #TechLife #LearnToCode
To view or add a comment, sign in
-
-
I’ve noticed a pattern in how I used to debug code. The moment something broke, my first reaction was to start changing things. Add a console.log. Rewrite a function. Try a different approach. Sometimes it fixed the issue. But most of the time, I was just poking around in the dark. Lately I’ve been trying something simpler. Before touching the code, I pause and ask a few questions: - What exactly is the bug? - Where is the data coming from? - At what point does the behavior change? Just slowing down for a few minutes often reveals what’s actually going wrong. And surprisingly, the fix becomes much clearer. I’m starting to realize debugging is less about typing more code and more about understanding the system. What’s the first thing you usually do when something breaks in your code? 👨💻 #WebDevelopment #JavaScript #SoftwareEngineering #FullStack #LearnInPublic #Programming
To view or add a comment, sign in
Explore related topics
- Tips for Exception Handling in Software Development
- Coding Best Practices to Reduce Developer Mistakes
- Principles of Elegant Code for Developers
- When to Use Prebuilt Coding Solutions
- SOLID Principles for Junior Developers
- Best Practices for Exception Handling
- How Developers Use Composition in Programming
- Ways to Improve Coding Logic for Free
- Strategies for Writing Error-Free Code
- How to Improve Code Maintainability and Avoid Spaghetti Code
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development
Thanks Fawzi. Good insights. Also note that raising exceptions has performance overhead