- Your name must answer this question:
1.a. Why it exists?
1.b. What it does?
1.c. How it is used? - Choose descriptive and unambiguous names.
- Make meaningful distinction.
- Use pronounceable names.
- Use searchable names.
- Don't use prefix.
- Use domain name.
- Do one thing.
- Use descriptive names.
- Zero or one argument.
- No output argument.
- No flag argument.
- Have no side effect.
- DRY.
- Fail fast.
- Don't write comment to explain your code.
- Try to express our code.
2.a Give a meaningful name.
2.b Put in the right context. - Comments are always evolved to follow the code.
- It's all about communication.
- Vertical formatting is like reading a newspaper.
- 80 chars width.
- If we work in a team, use team rules (create it if you don't have).
- Everything is an object is a myth.
- Avoid hybrids structures (half object and half data).
- Keep class field private and final.
- Obey the Law of Demeter (LoD).
- Don't use setter or getter.
- Avoid using exception for flow control.
- Use checked exception.
- Don't return NULL.
- Don't pass NULL.
- Use fail fast.
- Don't catch until you have to.
- Provide context with exception.
- Try to encapsulate any boundary interface inside a class.
1.a. Avoid returning it or accepting it as an argument. - Learn your boundaries by writing a tests.
- If your boundaries not yet available, create it.
3.a. You can use adapter pattern as a bridge when they are available to use.
Reference:
Martin, Robert C. 2009. Clean code: a handbook of agile software craftsmanship. Upper Saddle River, NJ: Prentice Hall.
Bugayenko, Yegor. 2017. Elegant Object Volume 1. CreateSpace Independent Publishing Platform; 1.0 edition (February 17, 2016)
Bugayenko, Yegor. 2017. Elegant Object Volume 2. CreateSpace Independent Publishing Platform; 1.4 edition (April 18, 2017)