Clean Code
- Name Variables and other things properly
- Create meaningful name
- Bad : String cd;
- Good : String currentDate;
- Long Variable Names
- Bad : Person[] peopleFromIndiaWhoCanSpeakFrench;
- Good : Person[] indiansSpeakingFrench;
- Bad Notations
- Bad : int iSize; String sName;
- Good : int size, String name;
- Avoid Disinformation
- Bad : String[] accountList;
- Good : String[] accounts;
- Avoid Noise Words (Data, Info, etc)
- Bad : UserInfo / BookData
- Good : User / Book
- Use Pronounceable Names
- Bad : String yyyymmdstr;
- Good : String currentDate;
- Use Searchable Names
- Bad : if (student.classes.length < 7)
- Good : if (student.classes.length < MAX_CLASSES_PER_STUDENT)
- Write Functions Properly
- Keep them Small, Functions should be small, really small. They should rarely be 20 lines long.
- Make Sure They Just Do One Thing
- Encapsulate Conditionals in Functions
- Fewer Arguments, Functions should have two or fewer arguments, the fewer the better. Avoid three or more arguments where possible.
- Do not use Flag Arguments, Flag arguments naturally contradict the principle of single responsibility. When you see them, you should consider dividing the function into two. Example : isDraft, isPaid, isPremium
- Do Not Have Side Effects
- Don't Repeat Yourself
- Bonus :
The Pragmatic Programmerhttps://drive.google.com/file/d/11dEXWs9l6TkbKCmkiJ7L4BHM0pVpyk08/view?usp=share_link
Komentar
Posting Komentar