Clean Code, the famous book written by uncle Bob (Robert C.Martin) , Is a great book to teach you to improve your coding style, transforming your bad, cluttered code, into readable, clean and maintainable code. As I continue reading the book, I can't imagine how much I benefited from it specially that I am a beginner developer..I loved it to the degree I didn't want to forget any of the principles listed in the book, so I started to make a summary for each chapter.. I am sharing this summary for anyone interested in improving his coding skills, but doesn't have enough time to read the whole book, and also because sharing is awesome :).. I hope you love it same as I did.. btw the book is free as pdf on the internet on many websites, just search google.... let's start our journey.
Part 1 Naming
Clean Code is code that has been taken care of to be descriptive and readable..
- use intention revealing names:
- don't use abbreviations.
nameis better than
- clear distinctions: avoid
getAccountInfo()in same class, or e.g. avoid
- use pronouncable and meaningfull names.
- Serchable names ( can be found easily by search tools as per their meaning).
- Avoid encodings (coded names).
- minimize the usage of prefixes like
- Classes and objects should have noun or noun phrase names like
- Methods should have verb or verb phrase names like
- Don't use cute or humourous or witty names.
- Accessors, mutators, and predicates should be named for their value and prefixed with
is, according to the javabean standard.
- Use names related to the solution applied like the pattern used e.g. factory , builder.
- If not possible relate it to the problem being solved, like relate variables to address e.g.
- Add meaningful context, like creating a class which will hold the variables that are being used in the same context, this will make the variables belong to that class and thus have contextual meaning.
Continue to Part 2-a...