DEV Community

Cover image for Share Your Top Clean Code Tips!
Sloan the DEV Moderator for CodeNewbie

Posted on

Share Your Top Clean Code Tips!

Share your favorite tips for writing clean and maintainable code that others in the community might find helpful.
Follow the CodeNewbie Org and #codenewbie for more discussions and online camaraderie!

Top comments (2)

Collapse
 
sagaofsilence profile image
Sachin

When writing code with the order of preference being correct, solid (errorproof), clean, and beautiful (elegant or idiomatic), consider the following principles:

Correct:

  1. Ensure that the code meets the specified requirements and produces the expected results.
  2. Test thoroughly, including edge cases and potential failure scenarios.

    Code Craft: The Practice of Writing Excellent Code by Pete Goodliffe | Goodreads

    Many programmers know how to write correct code - code …

    goodreads.com

Solid (Errorproof):

  1. Implement error handling and validation to make the code robust.
  2. Anticipate and handle exceptions gracefully to prevent unexpected crashes.
  3. Use defensive programming techniques to guard against unexpected inputs or situations.

    Writing Solid Code by Steve Maguire | Goodreads

    Fatbrain Review Explains Microsoft's techniques for de…

    goodreads.com

Clean:

  1. Prioritize readability and maintainability.
  2. Follow clean code principles, such as meaningful variable and function names, small functions, and clear comments.
  3. Eliminate code smells and redundancy to make the codebase more understandable.

    The Robert C. Martin Clean Code Collection by Robert C. Martin | Goodreads

    The Robert C. Martin Clean Code Collection consists of …

    goodreads.com

Beautiful (Elegant or Idiomatic):

  1. Write code in an elegant and idiomatic style, adhering to the conventions of the programming language.
  2. Strive for simplicity and expressiveness, avoiding unnecessary complexity.
  3. Follow best practices and design patterns when appropriate.

Beautiful Code: Leading Programmers Explain How They Think by Andy Oram | Goodreads

How do the experts solve difficult problems in software…

goodreads.com
Collapse
 
michaeltharrington profile image
Michael Tharrington

Nice Sachin!