Every change to a codebase increases technical debt leaving it less stable, bug-prone, and closer to technical bankruptcy requiring a rewrite. Let's explore how to measure technical debt to gain a score and highlight the current condition of a PHP application. We will then introduce simple steps for improving code quality, deliver new features faster, and lower project stress.
2. 2
Managing Technical Debt
●
About me
– OSS Contributor
– PHP Certified
– Zend Certification Advisory Board
– PHP-Fig voting member (IBM i Toolkit)
– Consultant at Zend Technologies
– Organizer SoFloPHP (South Florida)
– Organizer SunshinePHP (Miami)
– Long distance (ultra) runner
– Photography Enthusiast
– Judo Black Belt Instructor
3. 3
Managing Technical Debt
●
About me
– OSS Contributor
– PHP Certified
– Zend Certification Advisory Board
– PHP-Fig voting member (IBM i Toolkit)
– Consultant at Zend Technologies
– Organizer SoFloPHP (South Florida)
– Organizer SunshinePHP (Miami)
– Long distance (ultra) runner
– Photography Enthusiast
– Judo Black Belt Instructor
I am the
PHP Ninja!!!
4. 4
Managing Technical Debt
●
Fan of iteration
– Pretty much everything requires iteration to do well:
●
Long distance running
●
Judo
●
Development
●
Evading project managers
●
Managing Technical Debt!
6. 6
Managing Technical Debt
●
What is Technical Debt?
– Code Smells
...a code smell is any characteristic in the
source code of a program that possibly
indicates a deeper problem… - wikipedia
https://en.wikipedia.org/wiki/Code_smell
7. 7
Managing Technical Debt
●
Code “smells”
– “Smells” hinting a refactor may be needed:
●
Duplicate Code (rule of 3)
●
Long Methods
●
Large Class
●
Long Parameter (argument) List
●
Divergent Change – cascade change to accommodate another
●
Shotgun Surgery – change ripples as bugs
●
Feature Envy – method uses parts from other class
●
Switch Statements – sacrifice polymorphism
8. 8
Managing Technical Debt
●
Code “smells”
– Cont'd:
●
Lazy Class – class not doing much
●
Speculative Generality – something built for possible future
●
Temporary Field/Variable
●
Message Chains – object asking object asking object
●
Middle Man – directors in place but serve no real purpose
●
Inappropriate Intimacy – classes share private parts
●
Data Class – getters and setters, but nothing else
●
Comments – where comments cover bad code
9. 9
● Comments can also be a bad “smell“
●
Comments are often used to cover up bad code.
●
Code should be self-documenting
Managing Technical Debt
10. 10
● Coding Standards save time
●
Gives direction
●
PHP Framework Interoperability Group (https://www.php-fig.org).
●
Standard NOT important
●
Unless it‘s public code
●
Choose one
●
Stick with it
●
Consistency is key
Managing Technical Debt
11. 11
● Names should be clear
●
Functions and variables should tell a story.
$elapsedTimeInDays;
$daysSinceCreation;
$daysSinceModified;
$fileAgeInDays;
$elapsed;
$createdDays;
$modifiedDays;
$age;
GoodBad
Managing Technical Debt
12. 12
● Shy away from variations of the same name
●
To ensure names are different enough to portray difference.
$product
$productInfo
$productData
$productDescription
What is the difference between these?
Managing Technical Debt
13. 13
● Certain characters are hard to understand
Lower case L
Uppercase O (oh)
Uppercase I (eye)
Bad
Managing Technical Debt
14. 14
● Technical names help developers who actually read the code.
● Non-technical terms for client documentation.
● Class names should be nouns
●
Describe.
●
Ex. - Customer, Account, Product, Company.
● Method names should be verbs
●
Action.
●
Ex. - getCustomer, closeAccount, updateProduct, addCompany.
●
Pick a set of keywords and stick with them.
●
Ex. - fetch, get, add, update, remove, delete
Managing Technical Debt
15. 15
● More on Clean Code
●
Functions:
●
Short
●
Single purpose
●
As expected
●
Well named
●
Recognizing bad doesn't mean we know how to make good
●
We know a good/bad song, but are not song writers
●
Clean code = caring developer
●
Does not require many comments
Managing Technical Debt