Everyone says they want "Clean Code". However, what is the proper definition of clean code? How do I know if I have written clean code?
For me, clean code has:
Code is clean when it has a balance of utility and legibility. At the point where removing any more code would make it harder to read.
When writing code you don't want to aim for things like being 'short', but you really do want to strive for your code to be things like 'straightforward', and 'simple'.
Likewise 'clean' doesn't always mean perfect code either - it just means easy to work with, easy to work around, easy to delete, and easy to extend.
clean-code: as much "SOLID" and "DRY" principle as possible - HOWEVER let us not be fooled - don't start morphing your code because you got 4/5 of the solid and you really want to fit your code in. Simple and concise classes that don't make a coder go and read how the code is created in the core is very helpful and classes/functions that are intuitive without the need to switch back to documentation (though adding documentation to code helps). Finally: least amount of comments in function headers help (if i need to read a paragraph to know what that piece of code does means it smells IMO)
In addition to what others have said, I would add aesthetic. Lines should not extend 80 characters in length. Nested blocks should not have more than 3 levels of depth. Multi line function calls should be avoided. In my experience, these restrictions lend to code being more simple and modular.
I find a code is "clean" if it
Clean code means simple. Clean code means re-usable. And above all, clean code means generic. You will know if you've written clean code when you want to update something, and it feels super easy. You'll know that your code is clean if you and your colleagues read it, and can't find any optimisation to it. Hope that helps !
Leo Leo
ưewadasdas