DEV Community

Sardar Mudassar Ali Khan
Sardar Mudassar Ali Khan

Posted on • Edited on

1

25 Clean Code Tips That You Should Be Familiar

  • 1. Format your code
  • 2. Use meaningful names
  • 3. Avoid returning NULL
  • 4. Keep class size small
  • 5. Don’t reinvent the wheel
  • 6. Use appropriate tools/IDE
  • 7. Structure your solution well
  • 8. Use proper naming convention
  • 9. Use OOP Principles in your code
  • 10.Write short methods (20-30 lines)
  • 11.Removed unused and duplicate code
  • 12.Avoid catching generic exceptions
  • 13.Don’t put everything in single class
  • 14.Use constants instead of magic numbers
  • 15.Avoid deep nested conditions and loops
  • 16.For simple if-else use ternary operator
  • 17.Don’t use too many parameters in Methods
  • 18.Refactor code and re revaluate conditions
  • 19.Use async/await for better user experience
  • 20.Unit test and test code after code reviews
  • 21.Use expression bodied methods where possible
  • 22.Use version control to maintain history of code
  • 23.Now a days libraries a quite common, choose wisely
  • 24.Don’t use a lot of comments, only add where necessary
  • 25.Follow coding and design principles (SOLID, KISS, YAGNI)
  • 26.Eliminate extra functions and create functions where possible

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Cloudinary image

Video API: manage, encode, and optimize for any device, channel or network condition. Deliver branded video experiences in minutes and get deep engagement insights.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay