What is Clean Code?
YouTube Viewers YouTube Viewers
15.1K subscribers
8,319 views
0

 Published On Oct 14, 2020

Let's discover what exactly this term means for professional software developers with #QuickAnswer.

#programming #tech #softwaredevelopment #developer #sde

Clean Code (R. Martin) - US: https://amzn.to/3jVUEDU | UK: https://amzn.to/2Iij4Jz
Best Practices for Programmers - US: https://amzn.to/2SPRSEg | UK: https://amzn.to/2Fr2h6e

What Is Clean Code?

This is a term you might hear when professional software developers discuss the quality of their work. Standing on the bleachers you might think that code that does it’s job, or plainly: works is a good code. programmers believe that code not only has to work, but it also has to be easy to work with. Such code is following Clean Code practices. These make your code: easy to understand and explain, easy to change and extend, easy to debug and fix performant and focused .
So all in all, Clean Code is meant to be beautiful in a sense: elegant, optimal, maintainable, concise, and ready for new features. All this makes the code pleasant to work with, but don’t get me wrong: it’s not easy to write clean code. There are a lot of rules that you have to follow. I’ll mention some of them in a second, but first a caveat:
You see: programming clean code is a little bit like an art - you have to make a lot of subtle, implicit choices when painting a picture. When you’re done anyone can tell if you did well or badly, even if they themselves cannot paint at all. Same goes with clean code: your subtle choices will matter, and getting really good takes a lot of practice.
When distilling the rules of clean coding we can start by looking at the opposite: I know that all of us have seen some messy code, very often written by ourselves. Such code may be produced in rush, or just as a proof of concept. Eventually we forget what the code was all about, and move on. Few weeks later we get back to it and discover in horror that we no longer know what’s going on: where we can stick this new bit of functionality without causing an avalanche of bugs, errors and regression.
So what are key practices of clean code?
Meaningful names: label your symbols clearly, in a pronounceable, searchable manner that avoids mental mapping, puns, cleverness. Pick one word per concept and keep names short.
Write elegant functions: Small, well-defined, without side effects. Make them do one thing well, and one thing only. Keep your code DRY, structured and focused.

Use correct comments: avoid redundant, misleading, mandated or journal comments, but keep and use legal, informative and clarification comments.
Format your code correctly, according to standard agreed upon in your product and team

Avoids unnecessary classes, keep them small, and cohesive. Define your abstraction well, focus on responsibilities and isolation.
Handle all errors: define normal flow, use try-catch-finally, unchecked exceptions and provide context when throwing

Test your code. At least with unit tests. Preferably also use integration, component, and end-to-end tests. Use all the safeguards you can.
Becoming a good, clean programmer requires practice, and a lot of work and introspection to master this craft. In other words: when reading clean code, you can tell that it is written by someone who cares.

You can learn more in resources from the description. I wish you all the best in improving your skills. Subscribe, and I’ll see you in the next one, cheers!

show more

Share/Embed