Best Programming Practices for Clean Code

Explore top LinkedIn content from expert professionals.

  • View profile for Samitha Nanayakkara

    Senior Tech Lead | Educator

    2,090 followers

    I recently noticed a junior engineer in one of my teams taking the initiative to refactor a module, and I genuinely appreciate their proactive approach. Seeing team members embrace ownership and contribute to a healthier codebase is inspiring. Suppose you think a module, a feature or a component of the codebase can be improved for performance/reliability or readability. In that case, you should do it without seeking permission if it is not a breaking change. Waiting for a dedicated code cleanup sprint rarely happens. Cleaning code often doesn’t provide immediate business benefits compared to feature development. Hence, technical debt accumulates, leading to a challenging codebase. So, it’s better to take action now rather than later. if you think the module can be improved, do it while collecting data to support your claims, which you can then present in the code review/ PR review. This way, you cultivate an ownership and accountability mindset essential for every software engineer, enhancing personal growth and team efficiency.

  • View profile for Sergei Grozov

    Software Engineer | Backend | 9+ yrs C#/.NET | Scalable Systems & AI-Powered Solutions

    5,806 followers

    Don't Let DRY Make Your Code Too Thirsty The DRY (Don't Repeat Yourself) principle means that every piece of knowledge should only exist once in your codebase. Sounds great, right? But when does DRY become TOO DRY? Sometimes, in an effort to eliminate all repetition, we can end up over-abstracting our code. This can lead to code that is hard to understand, maintain, or extend. For example, if you find yourself creating overly generic methods or classes that try to handle too many scenarios, you might be taking DRY too far. This makes the code confusing for others (or even your future self) and increases the chance of introducing bugs when changes are needed. DRY isn't always the best choice. In cases like DTOs or database schemas, repetition can be more readable and clear. Reusing too much can make your design rigid and harder to change when requirements evolve. Pros of DRY: • Reduces repetition, making your code easier to maintain. • Less copy-pasting means fewer chances for mistakes and errors. • Changes in logic require fewer edits, which reduces the risk of bugs. Cons of DRY: • Too much abstraction can make your code hard to understand. • Reusing too much logic across different parts can make changes risky and cause unexpected problems. Where have you found DRY to be more trouble than it's worth? How do you balance avoiding repetition without over-complicating your code? #DRY #SoftwareEngineering #ProgrammingPrinciples #CleanCode #CSharp

  • View profile for Dr Milan Milanović

    Chief Roadblock Remover and Learning Enabler | Helping 400K+ engineers and leaders grow through better software, teams & careers | Author | Speaker | Leadership & Career Coach

    270,790 followers

    The best engineers I know delete more code than they write Junior engineers add features. Senior engineers remove complexity Every line of code you write is a liability. It needs to be maintained. It can break. It adds cognitive load to anyone who reads it later The best pull requests I've seen in the last year? Half of them deleted more than they added. Someone refactored three classes into one. Someone replaced 200 lines of custom logic with a library function. Someone removed an entire abstraction layer that wasn't pulling its weight Deletion is a skill. You have to know what's safe to remove. You have to understand the system well enough to see what's redundant, over-engineered, or just wrong Next time you open a file, ask: What can I remove? The best code is the code you don't write

  • View profile for Alexandre Zajac

    SDE & AI @Amazon | Building Hungry Minds to 1M+ | Daily Posts on Software Engineering, System Design, and AI ⚡

    152,617 followers

    The 10 Rules NASA Swears By to Write Bulletproof Code: 0. Restrict to simple control flow ↳ No goto, setjmp, longjmp, or recursion. Keep it linear and predictable. This ensures your code is easily verifiable and avoids infinite loops or unpredictable behavior. 1. Fixed loop bounds ↳ Every loop must have a statically provable upper bound. No infinite loops unless explicitly required (e.g., schedulers). This prevents runaway code and ensures bounded execution. 2. No dynamic memory allocation after initilization ↳ Say goodbye to malloc and free. Use pre-allocated memory only. This eliminates memory leaks, fragmentation, and unpredictable behavior. 3. Keep functions short ↳ No function should exceed 60 lines. Each function should be a single, logical unit that’s easy to understand and verify. 4. Assertion density: 2 per function ↳ Use assertions to catch anomalous conditions. They must be side-effect-free and trigger explicit recovery actions. This is your safety net for unexpected errors. 5. Declare data at the smallest scope ↳ Minimize variable scope to prevent misuse and simplify debugging. This enforces data hiding and reduces the risk of corruption. 6. Check all function returns and parameters ↳ Never ignore return values or skip parameter validation. This ensures error propagation and prevents silent failures. 7. Limit the preprocessor ↳ Use the preprocessor only for includes and simple macros. Avoid token pasting, recursion, and excessive conditional compilation. Keep your code clear and analyzable. 8. Restrict pointer use ↳ No more than one level of dereferencing. No function pointers. This reduces complexity and makes your code easier to analyze. 9. Compile with all warnings enabled ↳ Your code must be compiled with zero warnings in the most pedantic settings. Use static analyzers daily to catch issues early. Some of these rules can be seen as hard to follow, but you can't allow room for error when lives are at stake. Which ones are you still applying? #softwareengineering #systemdesign ~~~ 👉🏻 Join 46,001+ software engineers getting curated system design deep dives, trends, and tools (it's free): ➔ https://lnkd.in/dCuS8YAt ~~~ If you found this valuable: 👨🏼💻 Follow Alexandre Zajac 🔖 Bookmark this post for later ♻️ Repost to help someone in your network

  • View profile for Allen Holub

    I help you build software better & build better software.

    32,907 followers

    Last night, I was chatting in the hotel bar with a bunch of conference speakers at Goto-CPH about how evil PR-driven code reviews are (we were all in agreement), and Martin Fowler brought up an interesting point. The best time to review your code is when you use it. That is, continuous review is better than what amounts to a waterfall review phase. For one thing, the reviewer has a vested interest in assuring that the code they're about to use is high quality. Furthermore, you are reviewing the code in a real-world context, not in isolation, so you are better able to see if the code is suitable for its intended purpose. Continuous review, of course, also leads to a culture of continuous refactoring. You review everything you look at, and when you find issues, you fix them. My experience is that PR-driven reviews rarely find real bugs. They don't improve quality in ways that matter. They DO create bottlenecks, dependencies, and context-swap overhead, however, and all that pushes out delivery time and increases the cost of development with no balancing benefit. I will grant that two or more sets of eyes on the code leads to better code, but in my experience, the best time to do that is when the code is being written, not after the fact. Work in a pair, or better yet, a mob/ensemble. One of the teams at Hunter Industries, which mob/ensemble programs 100% of the time on 100% of the code, went a year and a half with no bugs reported against their code, with zero productivity hit. (Quite the contrary—they work very fast.) Bugs are so rare across all the teams, in fact, that they don't bother to track them. When a bug comes up, they fix it. Right then and there. If you're working in a regulatory environment, the Driver signs the code, and then any Navigator can sign off on the review, all as part of the commit/push process, so that's a non-issue. There's also a myth that it's best if the reviewer is not familiar with the code. I *really* don't buy that. An isolated reviewer doesn't understand the context. They don't know why design decisions were made. They have to waste a vast amount of time coming up to speed. They are also often not in a position to know whether the code will actually work. Consequently, they usually focus on trivia like formatting. That benefits nobody.

  • View profile for Nikki Siapno

    Eng Manager | ex-Canva | 400k+ audience | Helping you become a great engineer and leader

    213,974 followers

    SOLID principles are key in object-oriented programming. But what does each principle actually mean, and why are they significant? 𝗦𝗢𝗟𝗜𝗗 𝗿𝗲𝗽𝗿𝗲𝘀𝗲𝗻𝘁𝘀 𝗳𝗶𝘃𝗲 𝗽𝗿𝗶𝗻𝗰𝗶𝗽𝗹𝗲𝘀 𝗼𝗳 𝗼𝗯𝗷𝗲𝗰𝘁-𝗼𝗿𝗶𝗲𝗻𝘁𝗲𝗱 𝗽𝗿𝗼𝗴𝗿𝗮𝗺𝗺𝗶𝗻𝗴. Whether or not you use OOP, 𝗸𝗻𝗼𝘄𝗶𝗻𝗴 𝘁𝗵𝗲𝘀𝗲 𝗽𝗿𝗶𝗻𝗰𝗶𝗽𝗹𝗲𝘀 𝗴𝗶𝘃𝗲𝘀 𝘆𝗼𝘂 𝗮 𝗹𝗲𝗻𝘀 𝗶𝗻𝘁𝗼 𝘁𝗵𝗲 𝗳𝗼𝘂𝗻𝗱𝗮𝘁𝗶𝗼𝗻𝘀 𝗼𝗳 𝗰𝗹𝗲𝗮𝗻 𝗰𝗼𝗱𝗲 which can be applied to many areas of programming. 𝗦 — Single Responsibility Principle 𝗢 — Open/Closed Principle 𝗟 — Liskov Substitution Principle 𝗜 — Interface Segregation Principle 𝗗 — Dependency Inversion Principle Let’s break down each principle ↓ 𝟭. 𝗦𝗶𝗻𝗴𝗹𝗲 𝗥𝗲𝘀𝗽𝗼𝗻𝘀𝗶𝗯𝗶𝗹𝗶𝘁𝘆 𝗣𝗿𝗶𝗻𝗰𝗶𝗽𝗹𝗲 (𝗦𝗥𝗣) Each unit of code should only have one job or responsibility. A unit can be a class, module, function, or component. This keeps code modular and removes the risk of tight coupling. 𝟮. 𝗢𝗽𝗲𝗻-𝗖𝗹𝗼𝘀𝗲𝗱 𝗣𝗿𝗶𝗻𝗰𝗶𝗽𝗹𝗲 (𝗢𝗖𝗣) Units of code should be open for extension but closed for modification. You should be able to extend functionality with additional code rather than modifying existing ones. This principle can be applied to component-based systems such as a React frontend. 𝟯. 𝗟𝗶𝘀𝗸𝗼𝘃 𝗦𝘂𝗯𝘀𝘁𝗶𝘁𝘂𝘁𝗶𝗼𝗻 𝗣𝗿𝗶𝗻𝗰𝗶𝗽𝗹𝗲 (𝗟𝗦𝗣) You should be able to substitute a subclass with its base class. In other words, all functionality in the base class should be utilized by all of its subclasses. If it can’t, it shouldn’t be in the base class. An example of this is with a Bird base class. You might assume that it should have a fly method. But what about the birds that can’t fly? Like a Penguin. In this example, fly should not be in the base class as it does not apply to all subclasses. 𝟰. 𝗜𝗻𝘁𝗲𝗿𝗳𝗮𝗰𝗲 𝗦𝗲𝗴𝗿𝗲𝗴𝗮𝘁𝗶𝗼𝗻 𝗣𝗿𝗶𝗻𝗰𝗶𝗽𝗹𝗲 (𝗜𝗦𝗣) Provide multiple interfaces with specific responsibilities rather than a small set of general-purpose interfaces. Clients shouldn’t need to know about the methods & properties that don't relate to their use case. Complexity ↓ Code flexibility ↑ 𝟱. 𝗗𝗲𝗽𝗲𝗻𝗱𝗲𝗻𝗰𝘆 𝗜𝗻𝘃𝗲𝗿𝘀𝗶𝗼𝗻 𝗣𝗿𝗶𝗻𝗰𝗶𝗽𝗹𝗲 (𝗗𝗜𝗣) You should depend on abstractions, not on concrete classes. Use abstractions to decouple dependencies between different parts of the systems. Direct calls between units of code shouldn’t be done, instead interfaces or abstractions should be used. —— Want more engineering insights like this? Subscribe to our 𝗳𝗿𝗲𝗲 𝗻𝗲𝘄𝘀𝗹𝗲𝘁𝘁𝗲𝗿 for a 𝘄𝗲𝗲𝗸𝗹𝘆 𝗱𝗲𝗲𝗽-𝗱𝗶𝘃𝗲 and roundup of our best content: blog.levelupcoding.co #softwareengineering #webdevelopment #programming

  • View profile for Brij kishore Pandey
    Brij kishore Pandey Brij kishore Pandey is an Influencer

    AI Architect | AI Engineer | Generative AI | Agentic AI

    708,505 followers

    Clean code isn't just about readability —it's about creating maintainable, scalable solutions that stand the test of time. When we prioritize readability, simplicity, and thoughtful architecture, we're not just making our lives easier; we're creating value for our teams and organizations. A few principles that have made the most significant difference in my work over years: • Meaningful naming that reveals intent • Functions that do one thing exceptionally well • Tests that serve as documentation and safety nets • Consistent formatting that reduces cognitive load The greatest insight I've gained is that clean code is fundamentally an act of communication—with future developers, our teammates, and even our future selves. The time invested upfront pays dividends during maintenance, debugging, and onboarding. What clean code practices have transformed your development experience? I'd love to hear about the principles that guide your work. Image Credit - Keivan Damirchi

  • View profile for Rahul Agarwal

    Staff ML Engineer | Meta, Roku, Walmart | 1:1 @ topmate.io/MLwhiz

    44,701 followers

    Few Lessons from Deploying and Using LLMs in Production Deploying LLMs can feel like hiring a hyperactive genius intern—they dazzle users while potentially draining your API budget. Here are some insights I’ve gathered: 1. “Cheap” is a Lie You Tell Yourself: Cloud costs per call may seem low, but the overall expense of an LLM-based system can skyrocket. Fixes: - Cache repetitive queries: Users ask the same thing at least 100x/day - Gatekeep: Use cheap classifiers (BERT) to filter “easy” requests. Let LLMs handle only the complex 10% and your current systems handle the remaining 90%. - Quantize your models: Shrink LLMs to run on cheaper hardware without massive accuracy drops - Asynchronously build your caches — Pre-generate common responses before they’re requested or gracefully fail the first time a query comes and cache for the next time. 2. Guard Against Model Hallucinations: Sometimes, models express answers with such confidence that distinguishing fact from fiction becomes challenging, even for human reviewers. Fixes: - Use RAG - Just a fancy way of saying to provide your model the knowledge it requires in the prompt itself by querying some database based on semantic matches with the query. - Guardrails: Validate outputs using regex or cross-encoders to establish a clear decision boundary between the query and the LLM’s response. 3. The best LLM is often a discriminative model: You don’t always need a full LLM. Consider knowledge distillation: use a large LLM to label your data and then train a smaller, discriminative model that performs similarly at a much lower cost. 4. It's not about the model, it is about the data on which it is trained: A smaller LLM might struggle with specialized domain data—that’s normal. Fine-tune your model on your specific data set by starting with parameter-efficient methods (like LoRA or Adapters) and using synthetic data generation to bootstrap training. 5. Prompts are the new Features: Prompts are the new features in your system. Version them, run A/B tests, and continuously refine using online experiments. Consider bandit algorithms to automatically promote the best-performing variants. What do you think? Have I missed anything? I’d love to hear your “I survived LLM prod” stories in the comments!

  • View profile for Mahima Hans

    Software Engineer at Salesforce | Ex-Microsoft | Your Technical Interview Coach | Public Speaker

    335,973 followers

    Coding the correct optimized approach for the problem and keeping the code bug free is important, but what's also very important is making your code more understandable and readable. I mean all of us like reading well-written and clean pieces of code only, right? Here are a few tips that can help you make your code more elegant and readable- ✅ Use meaningful names: Choose descriptive names for variables, functions, classes so that it becomes easier for others to understand their purpose or meaning. ✅ Thoughtful comments: Wherever necessary, add comments to provide context or explain complex logic. Ideally, your code should be self-explanatory and excessive comments should be minimised. ✅ Proper indentation and formatting: This one is very important and I've seen interviewers emphasize on this one when they're assessing you. ✅ Reusable code: Remove duplicate code by creating reusable functions of using abstraction techniques. This reduces maintenance efforts and maintains consistency. ✅ Write modular code: Break your code into smaller, independent modules where each module should have a clear purpose and be responsible for a specific task. ✅ Avoid writing long code lines: Writing long lines of code makes it difficult to read moving back and forth horizontally. Use nesting and indentation to avoid this. Keep coding. All the best!❤️

  • View profile for Saumya Singh

    Making you Successful & Aware | Remote Software Engineer | Youtuber | 400K+ followers IG | LinkedIn Top Voice’25| International Open Source Awardee | Educator | Google Connect Winner | 3xTEDx Speaker | Winner SIH

    290,152 followers

    Interviewed 25 freshers for a tech role. Only one got hired. No fancy portfolio. But the way he explained why he wrote code a certain way, that clarity stood out. After the interview, I asked him - “You seem very clear about fundamentals. What’s your prep strategy?” He said, “Ma’am, I stopped solving random DSA problems and started learning how real developers think, through solid principles and code design.” That line hit me hard. Most freshers focus on: ❌ Solving 1000+ coding problems ❌ Memorizing frameworks ❌ Copy-pasting projects from GitHub But what recruiters actually test is your clarity of thinking - how you design, structure, and reason about code. If you’re a fresher preparing for a tech job, here’s what you should start doing: ✅ Do mock interviews focused on problem-solving and design reasoning ✅ Learn how to write clean, scalable, and maintainable code ✅ Learn how to explain your decisions : Why you chose a data structure, why that API design, clarity beats complexity. ✅ Show your learning curve : A small GitHub project with consistent commits says more than a flashy cloned project. ✅ Focus on code design principles like SOLID - this is what senior developers live by If you’ve been applying but not getting shortlisted, this might be your missing piece. Here’s a free masterclass (limited seats) every developer must attend: “Master Google’s SOLID Principles” : https://shorturl.at/CfE9Q Even if you’re a beginner, this session by Industry Expert will change how you look at code. Follow for more Saumya Singh #career #guidance

Explore categories