DEV Community

iBrendan!
iBrendan!

Posted on

Dev Journal - Day 2 - Odin Project - JS Fundamentals - Clean Code

Importance of Clean Code Practices
To make it easier to read and understand previously written code, whether it be my code, or code that will be referenced later in a larger professional codebase.

What I Learned
Clean code principles lead to source code that is easier to read, debug, and test. Implementing clean code principles is a foundational skill that pays off especially when it's time to refactor code or test it test. A few principles I plan to adopt are

  • Review and clarify code logic (perhaps using pseudocode or flow diagrams) prior to blindly typing into a debugger
  • Use descriptive naming conventions for variables (noun phrases e.g “numberOfItems) and functions (verbs e.g getCount() )
  • Write explanatory, clarifying comments as-needed and not as a crutch to explain my code
  • Avoid extremely large functions, and instead break up large functions into smaller digestible ones
  • Correctly and consistently indent code to make it easier to read and follow

Additional Clean Code Principles I Liked

  • On Comments: While comments are neither inherently good or bad, they are frequently used as a crutch. You should always write your code as if comments didn't exist. This forces you to write your code in the simplest, plainest, most self-documenting way you can humanly come up with.

  • On Personal Style: A professional programmer is prepared to bend her personal style to reflect the needs of the team. So even if you like ternary operators, don't use them if your team doesn't find them easy to understand. You can program in your own style on your personal projects, but anything you do in a team should follow the needs of that team.

References

  1. The Odin Project - Clean Code
  2. Pluralsight - Steps to Clean Code

Latest comments (0)