SlideShare a Scribd company logo
1 of 53
Download to read offline
@PeterHilton
http://hilton.org.uk/
How to write 

maintainable code
Wikimedia / CC BY-SA 3.0
Writing 

unmaintainable code
Scott Edmunds / CC BY 2.0
Modern
languages give
you all the toys
Modern languages’ maintainable code problem
1. OOP and FP at the same time
2. Exceptionally expressive programming language
3. Rapid language development - major changes
4. Early-adopter culture
5. Computer science vs mathematics vs enterprise dev

(a rich community but sometimes with conflicting goals)
6@PeterHilton •
Causes of unmaintainable code
We’re lazy.
We’re too clever for our own good.
(functional programmers especially)
We should stop starting things and start finishing things
(especially refactoring)
8@PeterHilton •
Consequences of unmaintainable code
1. Higher cost to develop a new feature or fix a bug
2. Developers become unhappy and leave
3. Higher cost to hire new developers
4. Fewer good developers on the team
5. Code gets less maintainable
6. Go back to step 1 - enjoy the descent into legacy code hell
9@PeterHilton •
Clean code & tests 

to the rescue
11@PeterHilton •
1. Learn how to write
unmaintainable code*
2. Don’t do that!
* How To Write Unmaintainable Code,

Roedy Green, Canadian Mind Products

https://github.com/Droogans/unmaintainable-code
Marks of unmaintainable code
1. Inconsistent code styles (OOP vs FP, Java vs Haskell)
2. Repetition
3. Too much abstraction (unnameable invented concepts)
4. Spaghetti code
5. Lasagne architecture (too many layers)
6. Inadequate tests (low coverage, incomprehensible)
12@PeterHilton •
Use a consistent coding style
Pick one way to use/avoid FP and OOP, and stick to it.
This is easy, provided that you never:
1. learn anything new about your language
2. learn anything new about functional programming
3. learn anything new about programming
4. move to a newer language version
5. work with other people who have different backgrounds
13@PeterHilton •
@PeterHilton •
Learning to write clean code
is the first step towards
maintainable code
There’s a book for that!
However, the book isn’t
perfect and doesn’t target
Scala.
15
Naming things
16@PeterHilton •
Good names for everything are the key to clean code
How hard can it be?*
Use software tools, practice, get better at it.
* see me afterwards if you don’t know any jokes about
naming things being hard
Piotr / CC BY 2.0
Naming smells
19@PeterHilton •
foo, data, object
employee, employee2
acc, pos, a, i, T, U
>=>, <*>, ¶
InvoiceManager, getPrice
isOpen, dateCreated
appointment_list, company_person
shipment, order, journey
1. Meaningless and abstract names
2. Numeric suffixes
3. Abbreviated or short names
4. Symbolic names
5. Vague words
6. Vestigial Hungarian notation
7. Multiple words
8. Wrong names
Adopting better naming practices
Recognise and fix naming smells
Start with meaning and intention
Use words with precise meanings
Prefer fewer words in names
Never use abbreviations in names, except for id
20@PeterHilton •
How to name things

(the hardest problem in programming)
1. Learn to recognise bad naming
2. Refactor - rename bad names to better names
3. Improve your vocabulary by reading and gaming
4. Wield your thesaurus and dictionary
5. Adopt better naming practices
6. Learn to write
7. Tell jokes, especially puns - learn to spot ambiguity
21@PeterHilton •
3. Write clean code
4. Get better at naming

22@PeterHilton •
Explanatory functional tests
Acceptance Test-Driven Development (ATDD)
Behaviour-Driven Development (BDD)
Specification by Example
… use acceptance tests written in domain language,

in collaboration with requirements stakeholders, that
document system behaviour (in addition to unit tests)
23@PeterHilton •
@PeterHilton • 24
‘Like cheap wine, long paper
documentation ages rapidly
and leaves you with a bad
headache if you try to use it
a year after it was created.
On the other hand,
maintaining a system
without any documentation
also causes headaches.’
5. Write explanatory
functional tests

25@PeterHilton •
How to write 

maintainable code
Clean code and good
unit tests are great,
but they’re not enough
(this is the bad news)
27@PeterHilton •
Clean code & tests are not enough
Even if you could write clean code all the time (you can’t)
your code still needs more explanation.
You don’t have to repeat yourself to the compiler, but
human learning requires repetition. 

You have to repeat yourself to help people understand you.
However, Uncle Bob is misleading about comments…
28@PeterHilton •
Comments are the
easiest way to document
code. If you don’t have
comments, you probably
have no docs at all. 29@PeterHilton •
Write good comments
1. Try to write good code first
2. Try to write a one-sentence comment
3. Refactor the code (make it easier to explain)
4. Delete unnecessary comments
5. Rewrite bad comments

(all good writing requires rewriting)
6. Add detail where needed

(which isn’t often) 30@PeterHilton •
‘Beware of DRY, the
evil siren that tricks
you into abstraction’
Martin Thompson a.k.a. @mjpt777
31@PeterHilton •
@PeterHilton •
Avoiding duplication
at all costs may lead
to incomprehensible
abstractions.
32
Too much abstraction
Dogmatic adherence to do-not-repeat-yourself leads to too
many abstractions.
Most of these abstraction layers don’t correspond to the
domain, so you can’t find good names for them.
(Half probably aren’t abstractions anyway, just indirection)
33@PeterHilton •
The Rule of Three
‘The first time you do something, you just do it.
The second time you do something similar, you wince at the
duplication, but you do the duplicate thing anyway.
The third time you do something similar, you refactor.’
- Kevlin Henney
https://vimeo.com/138863968
34@PeterHilton •
35@PeterHilton •
6. Apply The Rule of Three
before you remove
duplication
7. Accept that
maintainable code
costs more
36@PeterHilton •
How to maintain
maintainable code
There’s not much
point writing
maintainable code
if you don’t actually
maintain it 38@PeterHilton •
Proportion of clean code during software development%cleancode
0
25
50
75
100
number of lines of code
April Untitled 3 Untitled 10 June Untitled 5 Untitled 8 Untitled 11
‘We’ll clean it up later’
‘There’s too much 

code to clean it up’
Clean code
All of your code can be clean code, in theory…
But this gets harder as the codebase grows
Code falls off the maintenance cliff after around 100K lines
This is more likely to happen with business applications
than focused libraries for developers
(Likely the strongest argument for external dependencies)
40@PeterHilton •
http://cloc.sourceforge.net v 1.58

---------------------------------------------

Language files blank comment code

---------------------------------------------

Scala 287 8035 10396 28889

Javascript 7 3032 4729 22150

Java 99 2066 5075 7743

HTML 45 271 0 1286

XML 11 16 9 151

CoffeeScript 2 8 9 16

---------------------------------------------

SUM: 451 13428 20218 60235

---------------------------------------------
formal continuous
code review

(pull requests)
review meetings pair programming
Constantly improve the code
Take the Boy Scout Principle seriously (actually enforce it)
Do code review on all changes
Recognise code smells
Refactor
Even if you can’t win, you can lose more slowly
43@PeterHilton •
8. Keep the codebase
small
9. Increase refactoring
effort as it grows
44@PeterHilton •
README-Driven Development
45@PeterHilton •
‘… we have projects with short, badly written, or entirely
missing documentation…
There must be some middle ground between reams of
technical specifications and no specifications at all. And in
fact there is.
That middle ground is the humble Readme.’
http://tom.preston-werner.com/2010/08/23/readme-driven-development.html
Write a project/project introduction
Explain the system’s purpose
(What is the business reason? Why are we here?)
Describe the scope
(What defines what the system does and doesn’t do?)
Summarise what it does
(What does it actually do? What is it for?)
46@PeterHilton •
Detailed system documentation
Most systems don’t need detailed documentation.
Only complex systems require detailed documentation, e.g.
Architecture diagram
UML diagram
Data dictionary
Process model
Business rules 47@PeterHilton •
10.Write the minimum
viable documentation

(the rest is waste)
48@PeterHilton •
Summary
‘Hell is other people’s
code’*
* Sartre didn’t actually say this
50@PeterHilton •
Summary
51@PeterHilton •
1. Recognise unmaintainable code (and refactor)
2. Write clean code (and get better at naming)
3. Write acceptance tests that explain functionality
4. Apply The Rule of Three before you remove duplication
5. Accept that maintainable code costs more
6. Write docs and comments for the code you actually have
7. Keep the codebase small (or increase refactoring effort)
8. Write the minimum viable system documentation
joyofcoding.org
@PeterHilton
http://hilton.org.uk/http://hilton.org.uk/presentations/maintainable-code

More Related Content

What's hot

Clean Code and Common Engineering Practices
Clean Code and Common Engineering PracticesClean Code and Common Engineering Practices
Clean Code and Common Engineering PracticesRuth Sperer
 
高品質軟體的基本動作 101 for NTHU
高品質軟體的基本動作 101 for NTHU高品質軟體的基本動作 101 for NTHU
高品質軟體的基本動作 101 for NTHUSu Jan
 
Putting the science in computer science
Putting the science in computer sciencePutting the science in computer science
Putting the science in computer scienceFelienne Hermans
 
Responding to extended writing electronically v3
Responding to extended writing electronically v3Responding to extended writing electronically v3
Responding to extended writing electronically v3john6938
 
A brief primer on OpenAI's GPT-3
A brief primer on OpenAI's GPT-3A brief primer on OpenAI's GPT-3
A brief primer on OpenAI's GPT-3Ishan Jain
 
Inheritance Versus Roles - The In-Depth Version
Inheritance Versus Roles - The In-Depth VersionInheritance Versus Roles - The In-Depth Version
Inheritance Versus Roles - The In-Depth VersionCurtis Poe
 
English for information technology 1
English for information technology 1English for information technology 1
English for information technology 1Viktoria Shvetsova
 
A Pragmatic Approach
A Pragmatic ApproachA Pragmatic Approach
A Pragmatic ApproachHakanCanpek
 
I Wrote an FFV1 Decoder in Go for Fun: What I Learned Going from Spec to Impl...
I Wrote an FFV1 Decoder in Go for Fun: What I Learned Going from Spec to Impl...I Wrote an FFV1 Decoder in Go for Fun: What I Learned Going from Spec to Impl...
I Wrote an FFV1 Decoder in Go for Fun: What I Learned Going from Spec to Impl...Derek Buitenhuis
 
Writing code for people
Writing code for peopleWriting code for people
Writing code for peopleAlexey Ivanov
 
INF 103 Effective Communication/tutorialrank.com
 INF 103 Effective Communication/tutorialrank.com INF 103 Effective Communication/tutorialrank.com
INF 103 Effective Communication/tutorialrank.comjonhson291
 
Stop fearing legacy code
Stop fearing legacy codeStop fearing legacy code
Stop fearing legacy codeYaki Koren
 
How to contribute to open source
How to contribute to open sourceHow to contribute to open source
How to contribute to open sourceAlbert Wong
 

What's hot (20)

Clean Code and Common Engineering Practices
Clean Code and Common Engineering PracticesClean Code and Common Engineering Practices
Clean Code and Common Engineering Practices
 
高品質軟體的基本動作 101 for NTHU
高品質軟體的基本動作 101 for NTHU高品質軟體的基本動作 101 for NTHU
高品質軟體的基本動作 101 for NTHU
 
01.intro
01.intro01.intro
01.intro
 
Putting the science in computer science
Putting the science in computer sciencePutting the science in computer science
Putting the science in computer science
 
Responding to extended writing electronically v3
Responding to extended writing electronically v3Responding to extended writing electronically v3
Responding to extended writing electronically v3
 
A brief primer on OpenAI's GPT-3
A brief primer on OpenAI's GPT-3A brief primer on OpenAI's GPT-3
A brief primer on OpenAI's GPT-3
 
Best practices in coding for beginners
Best practices in coding for beginnersBest practices in coding for beginners
Best practices in coding for beginners
 
Inheritance Versus Roles - The In-Depth Version
Inheritance Versus Roles - The In-Depth VersionInheritance Versus Roles - The In-Depth Version
Inheritance Versus Roles - The In-Depth Version
 
Going Pro
Going ProGoing Pro
Going Pro
 
Learning Python
Learning PythonLearning Python
Learning Python
 
Raising the Bar
Raising the BarRaising the Bar
Raising the Bar
 
English for information technology 1
English for information technology 1English for information technology 1
English for information technology 1
 
A Pragmatic Approach
A Pragmatic ApproachA Pragmatic Approach
A Pragmatic Approach
 
Open source
Open sourceOpen source
Open source
 
I Wrote an FFV1 Decoder in Go for Fun: What I Learned Going from Spec to Impl...
I Wrote an FFV1 Decoder in Go for Fun: What I Learned Going from Spec to Impl...I Wrote an FFV1 Decoder in Go for Fun: What I Learned Going from Spec to Impl...
I Wrote an FFV1 Decoder in Go for Fun: What I Learned Going from Spec to Impl...
 
Writing code for people
Writing code for peopleWriting code for people
Writing code for people
 
INF 103 Effective Communication/tutorialrank.com
 INF 103 Effective Communication/tutorialrank.com INF 103 Effective Communication/tutorialrank.com
INF 103 Effective Communication/tutorialrank.com
 
BDACA - Tutorial1
BDACA - Tutorial1BDACA - Tutorial1
BDACA - Tutorial1
 
Stop fearing legacy code
Stop fearing legacy codeStop fearing legacy code
Stop fearing legacy code
 
How to contribute to open source
How to contribute to open sourceHow to contribute to open source
How to contribute to open source
 

Similar to How to write maintainable code - Peter Hilton - Codemotion Amsterdam 2017

Voxxed Days Thessaloniki 2016 - Documentation Avoidance
Voxxed Days Thessaloniki 2016 - Documentation AvoidanceVoxxed Days Thessaloniki 2016 - Documentation Avoidance
Voxxed Days Thessaloniki 2016 - Documentation AvoidanceVoxxed Days Thessaloniki
 
10 Big Ideas from Industry
10 Big Ideas from Industry10 Big Ideas from Industry
10 Big Ideas from IndustryGarth Gilmour
 
No, you don't need to learn python
No, you don't need to learn pythonNo, you don't need to learn python
No, you don't need to learn pythonQuantUniversity
 
I Don't Code, Am I No Longer Useful
I Don't Code, Am I No Longer UsefulI Don't Code, Am I No Longer Useful
I Don't Code, Am I No Longer UsefulMaaret Pyhäjärvi
 
Code smells and Other Malodorous Software Odors
Code smells and Other Malodorous Software OdorsCode smells and Other Malodorous Software Odors
Code smells and Other Malodorous Software OdorsClint Edmonson
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to PythonSpotle.ai
 
10 tips to save you time and frustration while programming
10 tips to save you time and frustration while programming10 tips to save you time and frustration while programming
10 tips to save you time and frustration while programmingHugo Shi
 
WordCamp US: Clean Code
WordCamp US: Clean CodeWordCamp US: Clean Code
WordCamp US: Clean Codemtoppa
 
Future of Python Certified Professionals in Data Science and Artificial Intel...
Future of Python Certified Professionals in Data Science and Artificial Intel...Future of Python Certified Professionals in Data Science and Artificial Intel...
Future of Python Certified Professionals in Data Science and Artificial Intel...M M Nair
 
An Ultimate Guide To Hire Python Developer
An Ultimate Guide To Hire Python DeveloperAn Ultimate Guide To Hire Python Developer
An Ultimate Guide To Hire Python DeveloperRishiVardhaniM
 
Better Functional Design through TDD
Better Functional Design through TDDBetter Functional Design through TDD
Better Functional Design through TDDPhil Calçado
 
Stop wasting-time-by-applying-clean-code-principles
Stop wasting-time-by-applying-clean-code-principlesStop wasting-time-by-applying-clean-code-principles
Stop wasting-time-by-applying-clean-code-principlesEdorian
 
14 Habits of Great SQL Developers
14 Habits of Great SQL Developers14 Habits of Great SQL Developers
14 Habits of Great SQL DevelopersIke Ellis
 
Behind the buzzwords: using chatbots & AI for everyday wins!
Behind the buzzwords: using chatbots & AI for everyday wins!Behind the buzzwords: using chatbots & AI for everyday wins!
Behind the buzzwords: using chatbots & AI for everyday wins!SoHo Dragon
 
InftyReader and ChattyInfty Overview
InftyReader and ChattyInfty OverviewInftyReader and ChattyInfty Overview
InftyReader and ChattyInfty Overviewsteveapps4android
 
TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019Paulo Clavijo
 
Global Day of Coderetreat'14 - Istanbul Event
Global Day of Coderetreat'14 - Istanbul EventGlobal Day of Coderetreat'14 - Istanbul Event
Global Day of Coderetreat'14 - Istanbul EventLemi Orhan Ergin
 
Lessons learned after 190M lessons served
Lessons learned after 190M lessons servedLessons learned after 190M lessons served
Lessons learned after 190M lessons servedRicardo Bánffy
 

Similar to How to write maintainable code - Peter Hilton - Codemotion Amsterdam 2017 (20)

Voxxed Days Thessaloniki 2016 - Documentation Avoidance
Voxxed Days Thessaloniki 2016 - Documentation AvoidanceVoxxed Days Thessaloniki 2016 - Documentation Avoidance
Voxxed Days Thessaloniki 2016 - Documentation Avoidance
 
10 Big Ideas from Industry
10 Big Ideas from Industry10 Big Ideas from Industry
10 Big Ideas from Industry
 
No, you don't need to learn python
No, you don't need to learn pythonNo, you don't need to learn python
No, you don't need to learn python
 
I Don't Code, Am I No Longer Useful
I Don't Code, Am I No Longer UsefulI Don't Code, Am I No Longer Useful
I Don't Code, Am I No Longer Useful
 
Code smells and Other Malodorous Software Odors
Code smells and Other Malodorous Software OdorsCode smells and Other Malodorous Software Odors
Code smells and Other Malodorous Software Odors
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 
Java basics
Java basicsJava basics
Java basics
 
Traits of a Good Engineer
Traits of a Good EngineerTraits of a Good Engineer
Traits of a Good Engineer
 
10 tips to save you time and frustration while programming
10 tips to save you time and frustration while programming10 tips to save you time and frustration while programming
10 tips to save you time and frustration while programming
 
WordCamp US: Clean Code
WordCamp US: Clean CodeWordCamp US: Clean Code
WordCamp US: Clean Code
 
Future of Python Certified Professionals in Data Science and Artificial Intel...
Future of Python Certified Professionals in Data Science and Artificial Intel...Future of Python Certified Professionals in Data Science and Artificial Intel...
Future of Python Certified Professionals in Data Science and Artificial Intel...
 
An Ultimate Guide To Hire Python Developer
An Ultimate Guide To Hire Python DeveloperAn Ultimate Guide To Hire Python Developer
An Ultimate Guide To Hire Python Developer
 
Better Functional Design through TDD
Better Functional Design through TDDBetter Functional Design through TDD
Better Functional Design through TDD
 
Stop wasting-time-by-applying-clean-code-principles
Stop wasting-time-by-applying-clean-code-principlesStop wasting-time-by-applying-clean-code-principles
Stop wasting-time-by-applying-clean-code-principles
 
14 Habits of Great SQL Developers
14 Habits of Great SQL Developers14 Habits of Great SQL Developers
14 Habits of Great SQL Developers
 
Behind the buzzwords: using chatbots & AI for everyday wins!
Behind the buzzwords: using chatbots & AI for everyday wins!Behind the buzzwords: using chatbots & AI for everyday wins!
Behind the buzzwords: using chatbots & AI for everyday wins!
 
InftyReader and ChattyInfty Overview
InftyReader and ChattyInfty OverviewInftyReader and ChattyInfty Overview
InftyReader and ChattyInfty Overview
 
TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019
 
Global Day of Coderetreat'14 - Istanbul Event
Global Day of Coderetreat'14 - Istanbul EventGlobal Day of Coderetreat'14 - Istanbul Event
Global Day of Coderetreat'14 - Istanbul Event
 
Lessons learned after 190M lessons served
Lessons learned after 190M lessons servedLessons learned after 190M lessons served
Lessons learned after 190M lessons served
 

More from Codemotion

Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...Codemotion
 
Pompili - From hero to_zero: The FatalNoise neverending story
Pompili - From hero to_zero: The FatalNoise neverending storyPompili - From hero to_zero: The FatalNoise neverending story
Pompili - From hero to_zero: The FatalNoise neverending storyCodemotion
 
Pastore - Commodore 65 - La storia
Pastore - Commodore 65 - La storiaPastore - Commodore 65 - La storia
Pastore - Commodore 65 - La storiaCodemotion
 
Pennisi - Essere Richard Altwasser
Pennisi - Essere Richard AltwasserPennisi - Essere Richard Altwasser
Pennisi - Essere Richard AltwasserCodemotion
 
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...Codemotion
 
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019Codemotion
 
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019Codemotion
 
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Francesco Baldassarri  - Deliver Data at Scale - Codemotion Amsterdam 2019 - Francesco Baldassarri  - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 - Codemotion
 
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...Codemotion
 
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...Codemotion
 
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...Codemotion
 
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...Codemotion
 
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019Codemotion
 
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019Codemotion
 
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019Codemotion
 
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...Codemotion
 
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...Codemotion
 
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019Codemotion
 
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019Codemotion
 
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019Codemotion
 

More from Codemotion (20)

Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
 
Pompili - From hero to_zero: The FatalNoise neverending story
Pompili - From hero to_zero: The FatalNoise neverending storyPompili - From hero to_zero: The FatalNoise neverending story
Pompili - From hero to_zero: The FatalNoise neverending story
 
Pastore - Commodore 65 - La storia
Pastore - Commodore 65 - La storiaPastore - Commodore 65 - La storia
Pastore - Commodore 65 - La storia
 
Pennisi - Essere Richard Altwasser
Pennisi - Essere Richard AltwasserPennisi - Essere Richard Altwasser
Pennisi - Essere Richard Altwasser
 
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
 
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
 
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
 
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Francesco Baldassarri  - Deliver Data at Scale - Codemotion Amsterdam 2019 - Francesco Baldassarri  - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
 
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
 
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
 
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
 
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
 
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
 
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
 
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
 
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
 
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
 
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
 
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
 
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
 

Recently uploaded

Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 

Recently uploaded (20)

Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

How to write maintainable code - Peter Hilton - Codemotion Amsterdam 2017

  • 2. Wikimedia / CC BY-SA 3.0
  • 4.
  • 5. Scott Edmunds / CC BY 2.0 Modern languages give you all the toys
  • 6. Modern languages’ maintainable code problem 1. OOP and FP at the same time 2. Exceptionally expressive programming language 3. Rapid language development - major changes 4. Early-adopter culture 5. Computer science vs mathematics vs enterprise dev
 (a rich community but sometimes with conflicting goals) 6@PeterHilton •
  • 7.
  • 8. Causes of unmaintainable code We’re lazy. We’re too clever for our own good. (functional programmers especially) We should stop starting things and start finishing things (especially refactoring) 8@PeterHilton •
  • 9. Consequences of unmaintainable code 1. Higher cost to develop a new feature or fix a bug 2. Developers become unhappy and leave 3. Higher cost to hire new developers 4. Fewer good developers on the team 5. Code gets less maintainable 6. Go back to step 1 - enjoy the descent into legacy code hell 9@PeterHilton •
  • 10. Clean code & tests 
 to the rescue
  • 11. 11@PeterHilton • 1. Learn how to write unmaintainable code* 2. Don’t do that! * How To Write Unmaintainable Code,
 Roedy Green, Canadian Mind Products
 https://github.com/Droogans/unmaintainable-code
  • 12. Marks of unmaintainable code 1. Inconsistent code styles (OOP vs FP, Java vs Haskell) 2. Repetition 3. Too much abstraction (unnameable invented concepts) 4. Spaghetti code 5. Lasagne architecture (too many layers) 6. Inadequate tests (low coverage, incomprehensible) 12@PeterHilton •
  • 13. Use a consistent coding style Pick one way to use/avoid FP and OOP, and stick to it. This is easy, provided that you never: 1. learn anything new about your language 2. learn anything new about functional programming 3. learn anything new about programming 4. move to a newer language version 5. work with other people who have different backgrounds 13@PeterHilton •
  • 14.
  • 15. @PeterHilton • Learning to write clean code is the first step towards maintainable code There’s a book for that! However, the book isn’t perfect and doesn’t target Scala. 15
  • 16. Naming things 16@PeterHilton • Good names for everything are the key to clean code How hard can it be?* Use software tools, practice, get better at it. * see me afterwards if you don’t know any jokes about naming things being hard
  • 17.
  • 18. Piotr / CC BY 2.0
  • 19. Naming smells 19@PeterHilton • foo, data, object employee, employee2 acc, pos, a, i, T, U >=>, <*>, ¶ InvoiceManager, getPrice isOpen, dateCreated appointment_list, company_person shipment, order, journey 1. Meaningless and abstract names 2. Numeric suffixes 3. Abbreviated or short names 4. Symbolic names 5. Vague words 6. Vestigial Hungarian notation 7. Multiple words 8. Wrong names
  • 20. Adopting better naming practices Recognise and fix naming smells Start with meaning and intention Use words with precise meanings Prefer fewer words in names Never use abbreviations in names, except for id 20@PeterHilton •
  • 21. How to name things
 (the hardest problem in programming) 1. Learn to recognise bad naming 2. Refactor - rename bad names to better names 3. Improve your vocabulary by reading and gaming 4. Wield your thesaurus and dictionary 5. Adopt better naming practices 6. Learn to write 7. Tell jokes, especially puns - learn to spot ambiguity 21@PeterHilton •
  • 22. 3. Write clean code 4. Get better at naming
 22@PeterHilton •
  • 23. Explanatory functional tests Acceptance Test-Driven Development (ATDD) Behaviour-Driven Development (BDD) Specification by Example … use acceptance tests written in domain language,
 in collaboration with requirements stakeholders, that document system behaviour (in addition to unit tests) 23@PeterHilton •
  • 24. @PeterHilton • 24 ‘Like cheap wine, long paper documentation ages rapidly and leaves you with a bad headache if you try to use it a year after it was created. On the other hand, maintaining a system without any documentation also causes headaches.’
  • 25. 5. Write explanatory functional tests
 25@PeterHilton •
  • 26. How to write 
 maintainable code
  • 27. Clean code and good unit tests are great, but they’re not enough (this is the bad news) 27@PeterHilton •
  • 28. Clean code & tests are not enough Even if you could write clean code all the time (you can’t) your code still needs more explanation. You don’t have to repeat yourself to the compiler, but human learning requires repetition. 
 You have to repeat yourself to help people understand you. However, Uncle Bob is misleading about comments… 28@PeterHilton •
  • 29. Comments are the easiest way to document code. If you don’t have comments, you probably have no docs at all. 29@PeterHilton •
  • 30. Write good comments 1. Try to write good code first 2. Try to write a one-sentence comment 3. Refactor the code (make it easier to explain) 4. Delete unnecessary comments 5. Rewrite bad comments
 (all good writing requires rewriting) 6. Add detail where needed
 (which isn’t often) 30@PeterHilton •
  • 31. ‘Beware of DRY, the evil siren that tricks you into abstraction’ Martin Thompson a.k.a. @mjpt777 31@PeterHilton •
  • 32. @PeterHilton • Avoiding duplication at all costs may lead to incomprehensible abstractions. 32
  • 33. Too much abstraction Dogmatic adherence to do-not-repeat-yourself leads to too many abstractions. Most of these abstraction layers don’t correspond to the domain, so you can’t find good names for them. (Half probably aren’t abstractions anyway, just indirection) 33@PeterHilton •
  • 34. The Rule of Three ‘The first time you do something, you just do it. The second time you do something similar, you wince at the duplication, but you do the duplicate thing anyway. The third time you do something similar, you refactor.’ - Kevlin Henney https://vimeo.com/138863968 34@PeterHilton •
  • 35. 35@PeterHilton • 6. Apply The Rule of Three before you remove duplication
  • 36. 7. Accept that maintainable code costs more 36@PeterHilton •
  • 38. There’s not much point writing maintainable code if you don’t actually maintain it 38@PeterHilton •
  • 39. Proportion of clean code during software development%cleancode 0 25 50 75 100 number of lines of code April Untitled 3 Untitled 10 June Untitled 5 Untitled 8 Untitled 11 ‘We’ll clean it up later’ ‘There’s too much 
 code to clean it up’
  • 40. Clean code All of your code can be clean code, in theory… But this gets harder as the codebase grows Code falls off the maintenance cliff after around 100K lines This is more likely to happen with business applications than focused libraries for developers (Likely the strongest argument for external dependencies) 40@PeterHilton •
  • 41. http://cloc.sourceforge.net v 1.58
 ---------------------------------------------
 Language files blank comment code
 ---------------------------------------------
 Scala 287 8035 10396 28889
 Javascript 7 3032 4729 22150
 Java 99 2066 5075 7743
 HTML 45 271 0 1286
 XML 11 16 9 151
 CoffeeScript 2 8 9 16
 ---------------------------------------------
 SUM: 451 13428 20218 60235
 ---------------------------------------------
  • 42. formal continuous code review
 (pull requests) review meetings pair programming
  • 43. Constantly improve the code Take the Boy Scout Principle seriously (actually enforce it) Do code review on all changes Recognise code smells Refactor Even if you can’t win, you can lose more slowly 43@PeterHilton •
  • 44. 8. Keep the codebase small 9. Increase refactoring effort as it grows 44@PeterHilton •
  • 45. README-Driven Development 45@PeterHilton • ‘… we have projects with short, badly written, or entirely missing documentation… There must be some middle ground between reams of technical specifications and no specifications at all. And in fact there is. That middle ground is the humble Readme.’ http://tom.preston-werner.com/2010/08/23/readme-driven-development.html
  • 46. Write a project/project introduction Explain the system’s purpose (What is the business reason? Why are we here?) Describe the scope (What defines what the system does and doesn’t do?) Summarise what it does (What does it actually do? What is it for?) 46@PeterHilton •
  • 47. Detailed system documentation Most systems don’t need detailed documentation. Only complex systems require detailed documentation, e.g. Architecture diagram UML diagram Data dictionary Process model Business rules 47@PeterHilton •
  • 48. 10.Write the minimum viable documentation
 (the rest is waste) 48@PeterHilton •
  • 50. ‘Hell is other people’s code’* * Sartre didn’t actually say this 50@PeterHilton •
  • 51. Summary 51@PeterHilton • 1. Recognise unmaintainable code (and refactor) 2. Write clean code (and get better at naming) 3. Write acceptance tests that explain functionality 4. Apply The Rule of Three before you remove duplication 5. Accept that maintainable code costs more 6. Write docs and comments for the code you actually have 7. Keep the codebase small (or increase refactoring effort) 8. Write the minimum viable system documentation