Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

Who? • David Salgado • @digitalronin (twitter, github, stackoverflow) • CTO, Tech co-founder, lead dev. etc. • Technical Architect @ Ministry of Justice

Slide 3

Slide 3 text

I've done some rewrites Apologise in advance: presentation is a random walk rewrites touch on lots of different areas, & so does this talk

Slide 4

Slide 4 text

What is a ‘rewrite’?

Slide 5

Slide 5 text

Decide to replace
 a working system
 with one that is equivalent
 but different Let's unpack that

Slide 6

Slide 6 text

Decide to replace
 a working system
 with one that is equivalent
 but different Not like you ended up replacing every line of code during normal development

Slide 7

Slide 7 text

Decide to replace
 a working system
 with one that is equivalent
 but different If it's not working, you're fixing, not rewriting

Slide 8

Slide 8 text

Decide to replace
 a working system
 with one that is equivalent
 but different If it's not equivalent, you're developing, not rewriting

Slide 9

Slide 9 text

Decide to replace
 a working system
 with one that is equivalent
 but different If it's not different, you've just run "cp -r"

Slide 10

Slide 10 text

Why? • “This code sucks” • “We should use #{shiny_new_tech}” • “This design/architecture sucks” • (aka “because micro-services”) Usually (not always) it's the developers who are pushing the rewrite There is a big problem with all of these arguments

Slide 11

Slide 11 text

– Dan Milstein “Developers tend to spectacularly underestimate the effort involved...and spectacularly overestimate the value generated” Remember, we're talking about replacing a working system - so, the current code is generating value for the business Let's look at this idea a bit more closely

Slide 12

Slide 12 text

This is what your
 product owner hears

Slide 13

Slide 13 text

This is what your
 product owner hears “We want to spend a huge amount of effort
 (aka money), and deliver no benefit” If you've got a smart product owner, they might hear...

Slide 14

Slide 14 text

This is what your
 product owner hears “We want to spend a huge amount of effort
 (aka money), and deliver no immediate benefit” If you've got a really smart product owner...

Slide 15

Slide 15 text

This is what your
 product owner hears “We want to spend a huge amount of effort
 (aka money), and deliver no immediate benefit to the business” Digress, & talk about Incentives

Slide 16

Slide 16 text

Incentives Let's look at the incentives for doing a rewrite

Slide 17

Slide 17 text

Incentives • Faster to add new features • Enables feature XXXXX • Fewer critical failures • Less devops load • Happier devs • Recruitment Business

Slide 18

Slide 18 text

Incentives • Work on a better system • Write software, not maintain it • Play with new toys • New tech/language/patterns • + CV / career • Faster to add new features • Enables feature XXXXX • Fewer critical failures • Less devops load • Happier devs • Recruitment Developers Business write software - we'll come back to that

Slide 19

Slide 19 text

Not perfectly aligned * Rewrite could be good for devs, but bad for business, or vice versa (but usually devs are pushing for rewrite)

Slide 20

Slide 20 text

Not saying "pitch a rewrite you know is a bad idea for your organisation" - depends on your situation and your conscience Know your goals and the goals of those around you => more chance of a good outcome

Slide 21

Slide 21 text

“This code sucks” So common, it's a cliche (like builders/mechanics). OK, sometimes it's true, but there are other factors Why?

Slide 22

Slide 22 text

Writing vs. Reading Code • Easier • More fun • Reputation Comes back to writing versus reading "Here is my gift to the world" github stars, twitter followers - "Here is a thing" vs. "I made this lib suck less" Serious problem in our industry - could be a separate talk

Slide 23

Slide 23 text

Should you ever rewrite?

Slide 24

Slide 24 text

Probably not ...but sometimes, yes - the new tech/architecture really is necessary - the code really does suck So, let's look at how to do it

Slide 25

Slide 25 text

How (not) to rewrite Or rather, how not to. One, very common anti-pattern...

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

Big Bang • Feature freeze • Build new system (from scratch) • Migrate • Profit / Unicorns / Kittens / Ponies

Slide 28

Slide 28 text

Why not? • It will take (a lot) longer than you think • You've stopped delivering value to users • The feature freeze is a lie • You're locked in • => Massive Risk There is a better way

Slide 29

Slide 29 text

Instead of jumping off a cliff there is a better way to get where you're going

Slide 30

Slide 30 text

Incremental • Work in small chunks • Freedom to stop at any point • Minimise Risk (one sprint) one sprint is an ideal scenario, but you can always get close to that

Slide 31

Slide 31 text

Strangler Application The most common pattern for doing an incremental rewrite Martin Fowler, 2004 sinister name

Slide 32

Slide 32 text

Strangler vine, aka strangler fig Dark, tropical forests where sunlight doesn't reach the ground

Slide 33

Slide 33 text

Start with a tree. vine seed lands in crevice grows up and down, using the tree's structure, intercepting sunlight & nutrients Tree dies & only the vine remains

Slide 34

Slide 34 text

Start with a tree. vine seed lands in crevice grows up and down, using the tree's structure, intercepting sunlight & nutrients Tree dies & only the vine remains

Slide 35

Slide 35 text

Start with a tree. vine seed lands in crevice grows up and down, using the tree's structure, intercepting sunlight & nutrients Tree dies & only the vine remains

Slide 36

Slide 36 text

Strangler Application 1. Set up production instance of new, alongside old 2. Build feature in new, that looks like old 3. Delete feature in old 4. Repeat until old is gone In terms of a software rewrite, process looks like this More detail about how to implement this in practice

Slide 37

Slide 37 text

No. 1 rule - be prepared. Lots you can do before you start to make it easier to survive "Ash" - evil dead movies chainsaw where his hand used to be, & carries a shotgun Good mindset to have when embarking on a rewrite

Slide 38

Slide 38 text

Test Coverage • Prove that new == old • Use your favourite testing tool • Containerisation Feature tests (acceptance tests) Don't start until you can prove new == old Changing tech, could be unfamiliar. Old tech could be horrible. Test suite can be its own application Containers can help - new & old & test suite can all target the same backend data store

Slide 39

Slide 39 text

Walking Skeleton • Infrastructure • Deployment (CI/CD) • Web App. • Look & feel • Routing • Shared auth/session Writing the code is the easy part. Don't leave ops work to the end. Do it first look & feel - users shouldn't notice the difference. How to route some requests to new & some to old routing: sub-domain? path-based routing? sessions (to have a subset of users see new app)? shared auth. - port old auth to new app. can be quite a big task, move to standards? oauth or JWT

Slide 40

Slide 40 text

Spike one function • Simple • Genuine • Authenticated • a.k.a. “Tracer Bullet” genuine - not a static content page: something that really exercises your system e.g. "edit my account" "tracer bullet" in Dave Thomas' "The Pragmatic Programmer" - crappy name, but it's about seeing what you're aiming at

Slide 41

Slide 41 text

Back-end Systems • Choose component • Refactor (clarify boundaries) • Extract as a service • Replace with new version • Repeat Not just web apps - Can replace a backend system, one piece at a time Might be a bit more work One thing to beware of...

Slide 42

Slide 42 text

Scope-creep • “We can fix XXX during the rewrite” • This will kill you, and eat your brain • Fix then rewrite or rewrite then fix One of the few nice things about a rewrite is the clearly defined scope This is what the chainsaw and the shotgun are for; "while you're in that bit of the code..." Puts you in an indeterminate state; new != old. Can't roll back, b/c user experience is different rewrite & development are different activities - guard that separation

Slide 43

Slide 43 text

Summary • Incremental rewrite • Strangler Application • Prepare • Tests. Shared Authentication. DevOps • Fight scope-creep • (Mostly) Don’t rewrite, refactor From a dev. POV, I'd argue that launching a rewrite is the lazy option Unless you're changing tech. (for which you need a good reason), you can almost always refactor your way to clean, maintainable, performant code ...

Slide 44

Slide 44 text

but it's usually harder, and less fun than throwing away and starting from scratch

Slide 45

Slide 45 text

References • Things You Should Never Do, Part I
 http://www.joelonsoftware.com/articles/fog0000000069.html • How To Survive a Ground-Up Rewrite Without Losing Your Sanity
 http://onstartups.com/tabid/3339/bid/97052/How-To-Survive-a-Ground-Up- Rewrite-Without-Losing-Your-Sanity.aspx • Strangler Vine Pattern
 http://martinfowler.com/bliki/StranglerApplication.html • Walking Skeleton
 http://blog.codeclimate.com/blog/2014/03/20/kickstart-your-next- project-with-a-walking-skeleton/