+ 4

How to write clean codes?

6th Jul 2019, 4:34 PM
😈😈Devil
😈😈Devil - avatar
5 Answers
+ 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
6th Jul 2019, 5:07 PM
JTLZ
+ 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
6th Jul 2019, 4:46 PM
Airree
Airree - avatar
+ 5
Practise lots of practise makes you able to make a clean and good sequence wise code in an proper way .
7th Jul 2019, 12:12 PM
Sayyam Jain
Sayyam Jain - avatar
+ 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.
6th Jul 2019, 6:23 PM
HonFu
HonFu - avatar
+ 2
There is a book called 'Clean Code' by Robert C. Martin. Every dev should read it.
6th Jul 2019, 5:12 PM
KKJ