In a world of ever-changing business requirements, how can you keep your software moving at the same pace?
If you keep adding lines of code around the previous iteration to add new functionality, things can become complex quite fast.
By measuring complexity, you can resolve and prevent bugs, while measuring class responsibility can make refactoring easier, for example.
In this talk Dennis will go through certain concepts of analysing software with automated tools to spit out numbers which tell a story about your code.
10. LOC: Physical lines of code
LLOC: Logical lines of code
CLOC: Comment lines of code
NCLOC: Non-comment lines of code
Different types:
11. How many lines of code?
7 physical lines of code
3 logical lines of code
1 comment lines of code
6 non-comment lines of code
1 <?php
2
3 /* this is a for-loop */
4 for ($i = 0; $i < 100; $i++)
5 {
6 printf("hello");
7 }
12. How many lines of code?
6 physical lines of code
3 logical lines of code
3 comment lines of code
3 non-comment lines of code
1 <?php
2
3 /**
4 * This is a for-loop
5 */
6 for ($i = 0; $i < 100; $i++) printf("hello");
14. WARNING!
Don’t use these statistics as a form
of measuring quality or productivity!
People will just ‘game’ the system
*applies different codestyle*
15.
16. Use it to gain more insight
about the application
“Measuring programming progress by lines of code
is like measuring aircraft building progress by weight.”
--Bill Gates
17. composer require phploc/phploc
$ phploc loc1.php
phploc 2.0.2 by Sebastian Bergmann.
!
Size
Lines of Code (LOC) 7
Comment Lines of Code (CLOC) 1 (14.29%)
Non-Comment Lines of Code (NCLOC) 6 (85.71%)
Logical Lines of Code (LLOC) 3 (42.86%)
Classes 0 (0.00%)
Average Class Length 0
Average Method Length 0
Functions 0 (0.00%)
Average Function Length 0
Not in classes or functions 3 (100.00%)
19. Cyclomatic Complexity
“It is a quantitative measure of the number of
linearly independent paths through a program's source code.”
M = E − N + 2P
E = the number of edges of the graph.
N = the number of nodes of the graph.
P = the number of connected components.
http://www.literateprogramming.com/mccabe.pdf
27. N-path Complexity
“The NPath complexity of a method is the number of
acyclic execution paths through that method.”
28. “The NPath complexity of a method is the number of
acyclic execution paths through that method.”
N-path Complexity
29. “The NPath complexity of a method is the number of
acyclic execution paths through that method.”
N-path Complexity
30. N-path Complexity
Path coverage
M = E − N + 2P
E = the number of edges of the graph.
N = the number of nodes of the graph.
P = the number of connected components.
38. Measuring Coupling
Afferent Coupling (Ca):"
Amount of other packages depending on this class (incoming)
!
Efferent Coupling (Ce):"
Amount of dependencies of this class
!
Instability (I):"
Resilience to change, metric between 0 and 1. Where 0 is stable.
I = Ce / (Ce + Ca)
39. Measuring Coupling
Ca = 2
Ce = 3
I = Ce / (Ce + Ca)
I = 3 / (3+2)
I = 0,6
I = 0,0 = Completely stable
I = 1,0 = Completely unstable
40. Measuring Coupling
Abstract:"
Either an abstract class or interface
!
Concrete:"
Any class that is neither abstract or final
!
Abstractness (A):"
How abstract a package is, ratio between 0 and 1. Where 0 is concrete.
A = Abstract / (Abstract + Concrete)
41. Measuring Coupling
PHPMD (PHP Mess Detector)
Can detect (code size rules):
- Cyclomatic complexity
- N-path complexity
- Excessive method length
- Too many methods
- etcetera
10
200
100
10
And other things
- Clean Code
- Design Rules
- Naming Rules
- Unused Code Rules