Clean Code v2017 en
Clean Code v2017 en
Assoc. prof. Catalin Boja, Asist. Bogdan Iancu, Lect. Alin Zamfiroiu
Which are the discussion topics
• Why clean code?
• Principles
• Naming conventions
• Short dictionary
• Instruments
• Bonus
Just Clean
• Seiri, or organization
• Seiketsu, or standardization.
Book
Chapter 1 Chapter 2
Project
Package1 Package 2
• ... by anyone
http://www.codeoclock.com/2015/03/03/clean-up/
Advantages
http://www.chudovo.com/Blog/CleanCode_General_Principles
What is Good Code
CLEAN Code
=
GOOD Code
What is Bad Code
• Misleading
• DRY
• KISS
• YAGNI
• SOLID
D.R.Y.
• Open-closed (OCP)
• Dependency inversion
https://en.wikipedia.org/wiki/SOLID_(object-oriented_design)
Single Responsability Principle
https://en.wikipedia.org/wiki/Single_responsibility_principle
Single Responsability Principle
https://en.wikipedia.org/wiki/Open/closed_principle
Liskov Substitution Principle
https://en.wikipedia.org/wiki/Liskov_substitution_principle
Interface Segregation Principle
https://en.wikipedia.org/wiki/Dependency_inversion_principle
What do you think about this code?
Naming conventions
• UpperCamelCase
• lowerCamelCase
• Don’t be negativists!
Clean Code Rules for conditional structures
increase complexity
• Delegate by references
• Use interfaces
GOOD vs BAD methods
Good (previous
rules)
BAD
https://ghostlypineapples.wordpress.com
Clean Code rules in Classes
//When I wrote this, only God and I understood what I was doing
//Now, God only knows
Clean Code rules for Comments
• TODO comments
Bad Code = Code smell
Sursa http://ackandnak.com/comics/your-code-smells.html
Short Dictionary
• Test Driven Development (TDD) – code development based on use
cases/test cases
• Automatic Testing (Unit Testing) – Code automatic testing base don use
cases. Useful for refactoring phases because helps you check if all the
functionalities have been preserved. (regression testing)
• Code review – procedure used in AGILE (XP, SCRUM) that requires that any
source code should be checked (reviewed) by a different programmer
• The Broken Window Principle: clădirile cu ferestre sparte sunt mult mai vulnerabile la vandalism, care
va duce la mai multe ferestre sparte;
• The Boy Scout Rule: lasați codul puțin mai curat decât l-ați găsit.
• Supplementary resources :
1. Robert C. Martin (Uncle Bob) – Clean Code: A Handbook of Agile Software Craftsmanship
4. Refactoring. Improving the Design of Existing Code, by Martin Fowler (with Kent Beck, John Brant, William
Opdyke, and Don Roberts)
One more thing
Thank you!