+ 4
How to write clean codes?
5 Respostas
+ 16
1. It should be elegant — Clean code should be pleasing to read. Reading it should make you smile the way a well-crafted music box or well-designed car would.
2. Clean code is focused —Each function, each class, each module exposes a single-minded attitude that remains entirely undistracted, and unpolluted, by the surrounding details.
3. Clean code is taken care of. Someone has taken the time to keep it simple and orderly. They have paid appropriate attention to details. They have cared.
4. Runs all the tests
5. Contains no duplication
6. Minimize the number of entities such as classes, methods, functions, and the like
+ 7
Try to put things where they are supposed to be. If you got a lot of values/functions that have a similar purpose, toss those bad boys in objects
+ 5
Practise lots of practise makes you able to make a clean and good sequence wise code in an proper way .
+ 4
Avoid indentation monsters that no one can understand.
Instead, modularize long units of codes into subcodes (functions and programs) and give them fitting names.
Generally, find fitting names for everything. Reading a bunch of a, b, c, x, y frp, xinzr_f will make the most trivial code look arcane.
Don't let lines grow too wide! Personally, I like to stay at about 50 letters. That way, if you have a few indentation levels, you will stay below 80 letters.
Don't allow dead code or unnecessarily longwinded code. If it doesn't do anything, kill it (or at least outcomment), if it's lengthy, try to make it shorter.
+ 2
There is a book called 'Clean Code' by Robert C. Martin. Every dev should read it.