What is Clean Code?

preview_player
Показать описание
Let's discover what exactly this term means for professional software developers with #QuickAnswer.

#programming #tech #softwaredevelopment #developer #sde

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!
Рекомендации по теме
Комментарии
Автор

Hey Smok, I discovered your videos recently and I've got to say I really enjoy watching them. You're an awesome programmer. Keep it up!

MultiGreen
Автор

Great topic, often overlooked and undervalued.

DevsLikeUs
Автор

Hi Smok, Can You make a video Clean Architecture ?

levimendes
Автор

Is this C++ Expert book worth to read as C++ dev? In your opinion ofc :)

thebarylowi
Автор

Another pleasant video, but didn't you forget something? What about DRY, KISS, SOLID? I know you've included some of its principles without naming them and some apply to OOP only, but those phrases/acronyms are so popular and shouldn't be paved over (in my opinion). Or maybe you keep them for another video? ◕‿◕

iwannabedev
Автор

I really try to follow these rules and my code still looks like sh*t. Ughhhh... ;P

MrKret