how to write maintainable software...2014/05/21 · how to write maintainable software a crash...
TRANSCRIPT
SZ
www.softwarezaken.nl
HOW TO WRITE MAINTAINABLE SOFTWARE A crash course in code quality and software maintainability Sieuwert van Otterloo [email protected] 06-10509674 @entreprenl
SZ
www.softwarezaken.nl
About Sieuwert van Otterloo Current activities: • Startup enthusiast (investor, journalist) • Software expert (court-registered IT expert, scrum
coach, software auditor) • Strategy consultant (McKinsey & Company, Eden
McCallum)
Claims to fame: • Has assessed 100+ IT systems (election software, railway software,
insurance and banking systems and ATM software) • Has interviewed more than 100 startup founders to give better advice.
The goal is to interview founders from all NL-based startups • First round investor in several startups (SOWISO, Buzzoek, Kidswatcher,
Arete Caerus, Plot Projects, SellanApp)
SZ
www.softwarezaken.nl
Computer issues delay flights in Los Angeles
LOS ANGELES (AP) — Flights to and from airports in the Los Angeles area were grounded for more than an hour Wednesday due to a computer failure at an air traffic control facility in the region, the Federal Aviation Administration said. The problems rippled nationwide. Dozens of planes heading into the region were diverted elsewhere, and flights scheduled to take off to the Los Angeles area were held on the ground across the country. […] A notice posted on the FAA website said planes were not allowed to depart Los Angeles because of a failure within the agency's En Route Automation Modernization system, also known as ERAM. […]
The ERAM system is critical to the FAA's plans to transition from a radar-based air traffic control system to satellite-based navigation, but its rollout is years behind schedule and hundreds of millions of dollars over budget. ERAM is replacing another computer system that was so old that most of the technicians who understood its unique computer language have retired.
May 1, 2014 8:51 AM
http://news.yahoo.com/computer-issues-delay-flights-los-angeles-234300027.html
SZ
www.softwarezaken.nl
Build a system
Write a program
Ideal position of this course in your personal learning plan
Listen
Do
Agile / Scrum basics
Learn to code
How to write maintainable
software
Startup weekend
Scaling agile
Lean startup
Join / start a startup
Grow and build a business Make IT decisions
Management techniques
Mastering Lean
Security
SZ
www.softwarezaken.nl
Agenda
• The motivation: Why software maintainability is important
• The destination: What does maintainable code look like
• The road: How to put quality into the software development process
• The roadblocks: How to deal with quality assessments
SZ
www.softwarezaken.nl
Why software is important
Marc Andreessen Founder of Netscape, Venture capitalist
Software is eating the world: • Today, the world's largest bookseller, Amazon, is a software
company • Today's largest video service by number of subscribers is a
software company: Netflix. • Today's dominant music companies are software companies,
too: Apple's iTunes, Spotify and Pandora. • Today's fastest growing entertainment companies are
videogame makers • The best new movie production company in many decades,
Pixar, was a software company. • Today's largest direct marketing platform is a software
company—Google. • Today's fastest growing telecom company is Skype • LinkedIn is today's fastest growing recruiting company..
Source: Wall street journal, August 20 2011
SZ
www.softwarezaken.nl
Team growth
Selling your company
Buy another
company
Software maintainability is important for scaling startups
Idea
MVP
Product / market fit
Reduce risk of chaos
Need to pass due diligence
process
Need to sanitize and
integrate
SZ
www.softwarezaken.nl
The classic view on software costs
Conservative example: • The system needs 15% maintenance per year • The system grows 10% per year • System lasts 10 years
Result: maintenance costs are 140% higher than development cost
!"!!!! !15!!!17!!
!18!!!20!!
!22!!!24!!
!27!!
!29!!
!32!!
!35!!
!239!!
100!
0!25!50!75!
100!125!150!175!200!225!250!275!
build! Year!1! Year!2! Year!3! Year!4! Year!5! Year!6! Year!7! Year!8! Year!9! Year!10! Total!
SZ
www.softwarezaken.nl
Agile view on software quality: technical debt
• Technical debt are issues that the customer cannot see, but the developers can
• You can either clean it up (refactor) or work around it • If you do not clean up, you pay interest
0.0#
5.0#
10.0#
15.0#
20.0#
25.0#
Sprint#1#
Sprint#2#
Sprint#3#
Sprint#4#
Sprint#5#
Sprint#6#
Sprint#7#
Sprint#8#
Sprint#9#
Sprint#10#
Sprint#11#
Sprint#12#
Story&po
ints&
Development&speed&&
without#refactoring#
With#refactoring#0.0#
50.0#
100.0#
150.0#
200.0#
250.0#
300.0#
350.0#
400.0#
Sprint#1#
Sprint#2#
Sprint#3#
Sprint#4#
Sprint#5#
Sprint#6#
Sprint#7#
Sprint#8#
Sprint#9#
Sprint#10#
Sprint#11#
Sprint#12#
Sprint#13#
Sprint#14#
Sprint#15#
Sprint#16#
Sprint#17#
Sprint#18#
Sprint#19#
Sprint#20#
Story&po
ints&
Value&delivered&&
without#refactoring#
With#refactoring#
SZ
www.softwarezaken.nl
Agenda
• The motivation: Why SW maintainability is important
• The destination: What does maintainable code look like
• The road: How to put quality into the software development process
• The roadblocks: How to deal with quality assessments
SZ
www.softwarezaken.nl
Volume
Very small Nice and small
Hard to handle
Impossible
< 10.000 lines of code
< 100.000 lines of code
Less than 500.000 lines of code
>500.000 lines of code
SZ
www.softwarezaken.nl
Understanding the scale Small system (60.000 LoC) Huge system (600.000 LoC)
Annual maintenance: 9 personmonths
Annual maintenance: 90
personmonths
SZ
www.softwarezaken.nl
System volume
0"1" 1"
6"7"
5"
10"8"
12"
18"
11"10"
1" 1" 1"0"
0"2"4"6"8"
10"12"14"16"18"20"
A"100+
200"
B"200+
500"
C"500+
1k"
D"1k+2k"
E"2k+5k"
F"5k+10k"
G"10k+20k
"
H"20k+50k
"
I"50k+100k
"
J"100k
+200k"
K"200k
+500k"
L"500k
+1M"
M"1M
+2M"
N"2M+5M
"
O"5M+10M
"
P"10M
+up"
Nr.$o
f$systems$
Volume$in$lines$of$code$
System$volume$
SZ
www.softwarezaken.nl
Example of a very small program
#!/bin/perl -sp0777i<X+d*lMLa^*lN%0]dsXx++lMlN/dsM0<j]dsj!$/=unpack('H*',$_);$_=`echo 16dio\U$k"SK$/SM$n\EsN0p[lN*1!lK[d2%Sa2/d0$^Ixp"|dc`;s/\W//g;$_=pack('H*',/((..)*)$/)!
SZ
www.softwarezaken.nl
Use of technologies
Java
Simple stack
Java
Complicated stack
Javascript Shell
C
‘Legacy’ stack
XML
PL/SQL
php perl
Java XSLT
x86
SZ
www.softwarezaken.nl
Duplication
Found 185 duplicate lines in the following files: Between lines 29 and 235 in /java/jabref-2.9.2/src/java/net/sf/jabref/export/layout/format/FormatChars.java Between lines 31 and 239 in /java/jabref-2.9.2/src/java/net/sf/jabref/oo/OOPreFormatter.java Found 194 duplicate lines in the following files: Between lines 130 and 397 in /java/jose-144-source/java/de/jose/util/Metaphone2.java Between lines 129 and 396 in /java/jose-144-source/java/de/jose/util/Metaphone.java
SZ
www.softwarezaken.nl
Complexity: decision points per method
Source: SweetHome 3D, fileOBJWriter.java
Best: less than 7 decision points per method (128 paths)
Mediocre: less than 10 (1024 paths)
This code: 36 decision points ( 68,719,476,736
paths)
public boolean equals(Object obj) { if (obj instanceof ComparableAppearance) {
Appearance appearance2 = ((ComparableAppearance)obj).appearance; ……..
if (!color1.equals(color2)) {! return false;!
} else if (material1.getShininess() != material2.getShininess()) {! return false;!
} else if (material1.getClass() != material2.getClass()) {! return false;!
} else if (material1.getClass() == OBJMaterial.class) {! OBJMaterial objMaterial1 = (OBJMaterial)material1;!
OBJMaterial objMaterial2 = (OBJMaterial)material2;! if (objMaterial1.isOpticalDensitySet() ^ objMaterial2.isOpticalDensitySet()) {!
return false;! } else if (objMaterial1.isOpticalDensitySet() && objMaterial2.isOpticalDensitySet()!
&& objMaterial1.getOpticalDensity() != objMaterial2.getOpticalDensity()) {!
return false;!
} else if (objMaterial1.isIlluminationModelSet() ^ objMaterial2.isIlluminationModelSet()) {!
return false;! } else if (objMaterial1.isIlluminationModelSet() && objMaterial2.isIlluminationModelSet()! && objMaterial1.getIlluminationModel() != objMaterial2.getIlluminationModel()) {! return false;!
} else if (objMaterial1.isSharpnessSet() ^ objMaterial2.isSharpnessSet()) {! return false;!
} else if (objMaterial1.isSharpnessSet() && objMaterial2.isSharpnessSet()!
&& objMaterial1.getSharpness() != objMaterial2.getSharpness()) {! return false;!
}! }!
}! }!
}! }!
SZ
www.softwarezaken.nl
Other important aspects
• Missing exception handling • TODO comments • Long ‘do-it-all’ files • Memory actions and leaks • Safe use of user strings • Complex queries • Code copyrighted by others
SZ
www.softwarezaken.nl
Typical quality model (SIG)
SZ
www.softwarezaken.nl
Benchmarking quality
Raw measurements of your system
Averaging
% score for each component Overall % score
Measurement of open source systems
“120 violations of type X”
“Aspect X is better than 55% of
systems”
“Maintainability is better than 60% of
systems”
SZ
www.softwarezaken.nl
Agenda
• The motivation: Why SW maintainability is important
• The destination: What does maintainable code look like
• The road: How to put quality into the software development process
• The roadblocks: How to deal with quality assessments
SZ
www.softwarezaken.nl
Joint code ownership
• Everyone in the team should feel comfortable explaining each line of code
• All founders should be interested in the code on which the company runs
SZ
www.softwarezaken.nl
Create daily feedback
• Integrate and test a working system at least every two weeks
• Agree on basic code quality standards Structure
Tools
Mindset
• Create a fully automated daily build process • Use automated tools in the build process (checkstyle,
FxCop, Simian, PMD, Sonar) • Configure automated checks in the IDE (Visual studio)
• Monitor issues daily as a lead developer • Address root causes of issues in retrospectives:
• Training needs for new and current developers • Important refactoring actions • Adjustments to quality standards
SZ
www.softwarezaken.nl
Five steps for a quality program
1. Make strategy and technology choices
2. Set quality standards and architecture rules
3. Start measuring
4. Create good new code
5. Clean up old code
SZ
www.softwarezaken.nl
Agenda
• The motivation: Why SW maintainability is important
• The destination: What does maintainable code look like
• The road: How to put quality into the software development process
• The roadblocks: How to deal with quality assessments
SZ
www.softwarezaken.nl
Top 4 situations when assessments / audits happen
1. A large company buys your service
3. Someone invests in your company
4. Someone buys your company
2. You are supplier in a delayed/troubled
project
Product focus Company focus
SZ
www.softwarezaken.nl
Software Risk Assessment process
System context and
business strategy
Risks
Quality
Economics
Is the input for determining … Are the basis
for…
Conclusions
Code review
Recommen-dations
SZ
www.softwarezaken.nl
How not to deal with an assessment
Develop a system as fast as possible at minimal cost
OK, here it is
Can you audit the system?
What quality standards did you demand?
What quality standards did you use?
None, we focused on cost and speed
We asked nothing special, but we expect a fit for use system conforming to industry best practices
Client Supplier Assessor
Let’s report a lot of findings to show that we worked really hard
SZ
www.softwarezaken.nl
A better way to deal with assessments
Develop a system as fast as possible at minimal cost Here is our own standard, is that good
enough for you?
What quality standards did you use?
We agreed on this standard. We checked to code and it complies. Let us know if you
find any issues
We worked really hard and have these findings
Well done! We do not see major risks, but if needed we have a quality process and
can fix these in the next release.
The quality is what has been agreed, and will be even better in the next release
Client Supplier Assessor
SZ
www.softwarezaken.nl
How to deal with due diligence
1. Keep it short by starting late: Do not start the assessment before the other deal details are sorted out
2. Ensure the goal is limited: For instance to determine whether the software has issues that cannot be fixed and cause major risks
3. Ensure involvement: Auditors should listen to your side, share and discuss findings before reporting any issues.
SZ
www.softwarezaken.nl
Conclusions
• Software quality is important for any growing or grown company • You can achieve quality with the right agile development process
SZ
www.softwarezaken.nl
Thank you!
• These slides will be made available on www.softwarezaken.nl
• If you have any questions, contact me • I can be hired for additional workshops, coaching and
consulting on any of the topics below:
IT strategy
maintainable software
Starting with agile / scrum
Lean startup
Secure software development
Call or mail me: [email protected] +31 6 1050 9674
Lean startup for corporates
Startup search & selection
IT contracts IT management
for non-IT