Clean Code - Deepstash
Clean Code

Asim Husanović's Key Ideas from Clean Code
by Robert C. Martin

Ideas, facts & insights covering these topics:

20 ideas

·

12.6K reads

67

2

Explore the World's Best Ideas

Join today and uncover 100+ curated journeys from 50+ topics. Unlock access to our mobile app with extensive features.

READABILITY IS KEY

The main objective when writing code is for it to be easily understood by humans. Remember, your fellow developers will interact with your code much more than machines will.

  1. Try to make your code more readable today. Use descriptive names and clear structures.
  2. Think about a piece of code that was hard for you to understand. What made it difficult, and how could it have been improved for readability?

243

1.57K reads

NAME IT WELL

Choosing informative and meaningful names for variables, functions, classes, and other identifiers helps your code speak for itself, reducing the need for comments.

  1. Review your code today. Do the names of variables, functions, or classes reflect their roles and behaviors? Consider revising any ambiguous or unclear names.
  2. Reflect on a situation where a poorly named variable or function confused you. How could it have been named better?

228

1.08K reads

ONE FUNCTION, ONE TASK

Each function you write should have a singular, well-defined responsibility. Keeping functions small and focused makes your code more maintainable and less prone to bugs.

  1. Check your code today for any functions that may be trying to do too much. Consider breaking them down into smaller, more focused functions.
  2. Can you recall a function you encountered that was trying to do too much? How might you redesign it for better clarity and simplicity?

229

972 reads

MINIMIZE COMMENTS

In well-written code, comments should be the exception, not the rule. If your code is self-explanatory, there's no need to add extra commentary.

  1. Look through your code today and ask yourself if each comment is necessary. Could the code be refactored to make it self-explanatory instead?
  2. Think about a time when excessive comments cluttered a codebase. How might it have been improved to reduce reliance on comments?

225

878 reads

FORMAT FOR READABILITY

The way you format your code, including indentation and the use of whitespace, can greatly influence its readability. Consistency is key.

  1. Pay special attention to the formatting of your code today. Make sure it is consistent and follows established conventions.
  2. Consider a time when poor formatting made code harder to understand. How could better formatting have improved the situation?

220

761 reads

NO OUTPUT ARGUMENTS

Functions should avoid modifying the state of their inputs. Instead, return the results. This practice leads to clearer and more predictable code.

  1. Review your functions today. Do any of them modify their arguments? Could they be refactored to return the results instead?
  2. Have you experienced confusion or bugs related to functions modifying their arguments? How could this have been avoided?

226

801 reads

HANDLE ERRORS PROPERLY

Don't ignore errors. They should be handled and communicated effectively, preferably through exceptions, making your code more robust and maintainable.

  1. Check your code for error handling today. Are all potential errors or exceptions accounted for and handled effectively?
  2. Can you recall a situation where inadequate error handling led to issues? How could proper error handling have improved the situation?

219

657 reads

RESPECT BOUNDARIES

Knowing where to draw lines between software systems and how to manage those interfaces effectively can make a big difference in the complexity and maintainability of your code.

  1. Assess the boundaries in your code today. Are interfaces between systems clear and well managed?
  2. Can you recall a time when poorly defined boundaries led to issues? How could better boundary management have improved the situation?

221

621 reads

TEST YOUR CODE

Unit testing is essential for maintaining code health. Tests should be clean, well-written, and just as maintained as your production code.

  1. Take a look at your test coverage today. Is there any part of your code not adequately covered by tests? Consider writing tests for those areas.
  2. Think of an occasion where a lack of testing led to problems. How could sufficient unit tests have prevented the issues?

219

523 reads

KEEP IT SMALL

Classes should be as small as possible, with a single responsibility. This practice increases code clarity, reusability, and maintainability.

  1. Review your classes today. Are any of them trying to do too much? Consider breaking them into smaller, single-purpose classes.
  2. Can you recall a time when a large class with multiple responsibilities led to confusion or bugs? How might it have been structured better?

218

541 reads

SYSTEMS MATTER

Keeping system architecture clean and comprehensible is crucial. It's just as important that high-level structures are as understandable as low-level code.

  1. Consider the architecture of your current project today. Is it as clean and comprehensible as it could be?
  2. Have you encountered a situation where poor system architecture made it difficult to work effectively? How could it have been improved?

218

509 reads

EMERGENCE THROUGH SIMPLICITY

Good architecture often emerges from following simple practices: passing all tests, eliminating duplication, ensuring expressiveness, and minimizing the number of classes and methods.

  1. Reflect on your current practices. Are you adhering to these principles? Where can you implement these to improve your code's architecture?
  2. Can you think of a situation where not following these practices led to a convoluted or flawed system design? How could adherence to these practices have improved it?

217

488 reads

UNDERSTAND CONCURRENCY

Concurrency brings its own set of challenges. Writing concurrent code requires explicit strategizing and testing to ensure correct functioning.

  1. If your code uses concurrency, scrutinize it closely. Are you confident it's handling concurrency correctly?
  2. Can you remember a time when inadequate handling of concurrency caused problems? How could these issues have been avoided?

217

479 reads

CONTINUOUS REFINEMENT

Your code should undergo continual revision and improvement. By constantly refining it, you can maintain simplicity and flexibility in your software.

  1. Review your codebase today. Identify areas that could benefit from refactoring or improvement.
  2. Recall a time when lack of code refinement led to complexity or rigidity. How could regular refinement have helped?

219

437 reads

MASTER YOUR TOOLS

Understanding your testing framework, like Junit, can make your unit tests cleaner and more efficient. Mastering your tools equates to more efficient and reliable code.

  1. Dedicate some time to explore the features and best practices of your testing framework today. How can you use it more effectively?
  2. Can you think of a situation where better knowledge of your tools could have saved time or prevented issues? How could having that knowledge have changed the outcome?

219

395 reads

AVOID DUPLICATION

The "Don't Repeat Yourself" (DRY) principle states that each piece of knowledge should have a single, unambiguous representation within the system. Duplicated code can lead to inconsistencies and bugs.

  1. Examine your code today for any signs of duplication. If you find any, consider refactoring to eliminate it.
  2. Can you recall a time when duplicated code caused issues in your project? How could adherence to the DRY principle have prevented those issues?

218

402 reads

IMPROVE LEGACY CODE

Working with legacy code can be challenging but understanding and improving its structure can greatly aid in maintainability and extensibility.

  1. If you're working with legacy code, try to understand it better today. Identify areas for potential improvement.
  2. Have you encountered difficulties with legacy code? What strategies could have made dealing with this code easier?

219

397 reads

USE TOOLS WISELY

Employ tools like static code analyzers and linters to enforce coding standards and conventions. They can help you maintain high-quality code.

  1. Evaluate the tools you're using today. Are there any additional tools that could help maintain your coding standards?
  2. Can you remember a situation where a coding tool could have prevented a problem or made your work more efficient? How would the tool have changed the outcome?

218

358 reads

STAY PROFESSIONAL

Professionalism in software development means taking responsibility for delivering clean, functioning code. Take pride in your work and strive for excellence.

  1. Reflect on your work today. Are there areas where you could have demonstrated more professionalism? How can you improve in this aspect moving forward?
  2. Can you think of a situation where a lack of professionalism led to issues? How could a more professional approach have prevented these problems?

216

342 reads

BEWARE OF SMELLS

Certain patterns, known as 'code smells,' can indicate potential problems in your design. Understanding these patterns helps you avoid problems before they arise.

  1. Look at your code today with an eye for 'code smells.' Can you identify any and rectify them?
  2. Can you recall a time when recognizing a 'code smell' could have helped you prevent an issue? How would you handle a similar situation in the future?

217

438 reads

IDEAS CURATED BY

asimhusanovic

As an engineer with an official degree in software engineering, I am primarily interested in science and technology. I enjoy reading literature of many genres, and I especially like those from human behavior, sociology, history, and, should I say, science

Curious about different takes? Check out our Clean Code Summary book page to explore multiple unique summaries written by Deepstash users.

Different Perspectives Curated by Others from Clean Code

Curious about different takes? Check out our book page to explore multiple unique summaries written by Deepstash curators:

Discover Key Ideas from Books on Similar Topics

Grokking Algorithms

3 ideas

Grokking Algorithms

Aditya Bhargava

Atomic Habits

10 ideas

Atomic Habits

James Clear

Atomic Habits

5 ideas

Atomic Habits

James Clear

Read & Learn

20x Faster

without
deepstash

with
deepstash

with

deepstash

Personalized microlearning

100+ Learning Journeys

Access to 200,000+ ideas

Access to the mobile app

Unlimited idea saving

Unlimited history

Unlimited listening to ideas

Downloading & offline access

Supercharge your mind with one idea per day

Enter your email and spend 1 minute every day to learn something new.

Email

I agree to receive email updates