Incremental Development: Maintaining and improving long-lived site

A presentation at Web Unleashed in October 2018 in Toronto, ON, Canada by Anne Thomas

Slide 1

Slide 1

Incremental Development Maintaining and improving long-lived sites

Slide 2

Slide 2

  1. The WHAT.

Slide 3

Slide 3

Long-lived Short-lived - Common for web - Microsites applications and - Marketing sites products (themes) (movies, promotions) - Legacy code - Whoops, you don’t abounds! exist anymore! 3

Slide 4

Slide 4

Our challenges. Code from 4+ years ago. 4

Slide 5

Slide 5

Legacy code is everywhere. How much are you living with? 5

Slide 6

Slide 6

It’s all around us... Third-party libraries that are defunct Cryptic code written by a technical wiz Custom In-house frameworks Languages that have a dwindling supply of developers ● Code you wrote last month in a rush ● ● ● ●

Slide 7

Slide 7

Technical debt is unavoidable. Does your team pay off their credit card every month? 7

Slide 8

Slide 8

Be kind. Don’t spend energy blaming previous developers. 8

Slide 9

Slide 9

Reckless Prudent No one has time to review it, so we’ll just commit to master. We know this bug exists, but we have to focus on this feature instead. Deliberate Inadvertent What are JavaScript design patterns?

  • Martin Fowler In hindsight, it’s clear that we should have taken this approach instead.

Slide 10

Slide 10

  1. The WHY.

Slide 11

Slide 11

“ Legacy code. The phrase strikes disgust in the hearts of programmers. It conjures images of slogging through a murky swamp of tangled undergrowth with leeches beneath and stinging flies above. It conjures odors of murk, slime, stagnancy, and offal. Although our first joy of programming may have been intense, the misery of dealing with legacy code is often sufficient to extinguish that flame. - Michael Feathers, Working Effectively with Legacy Code 11

Slide 12

Slide 12

Whoa. That doesn’t sound fun. 12

Slide 13

Slide 13

Reaching the Tipping Point ● Developers are scared to change anything ● Worried about the “Butterfly Effect” ● No one want to work on that codebase anymore ● Architecture can’t be scaled/impacts future planning ● High turnover on the team

Slide 14

Slide 14

Be kind to your future self ● Be ready to support new features down the line ● Not all “features” are optional (eg. a11y) ● Browsers change rapidly and new APIs appear that you will want to use ● There is no “set it and forget it”

Slide 15

Slide 15

Maintenance is often overlooked ● It’s not hip, cool or sexy ● Not working with code that is the latest and greatest ● BUT being able to properly understand (and respect) legacy code is a skill ● It is critical and important

Slide 16

Slide 16

Preaching to the choir. You already feeling the pain.. 16

Slide 17

Slide 17

  1. The WHERE.

Slide 18

Slide 18

I see dead parentheses. Identifying your issues. 18

Slide 19

Slide 19

Questions to ask ● Is it currently broken? Like really broken? ● Can a hotfix be applied in the short-term? ● When is the last time the code was touched? ● Are you refactoring just to be fancy? ● Does anyone understand what the code does? ● Does the old code affect new code?

Slide 20

Slide 20

Make friends with your codebase. Leave that bitterness at the door. 20

Slide 21

Slide 21

Spend time with your code ● Practice reading other people’s code ● Work your way through the event flows (Characterization tests) ● Get acquainted before you make edits ● Identify easy fixes like removing old polyfills and unnecessary vendor prefixes (tiny wins, but still tidies things up)

Slide 22

Slide 22

Resist the urge to tear it all down ● Time investment is massive - most companies can’t afford this (t = $) ● BUT small iterative improvements can have a big impact (especially in the front end) ● Team is familiar with current stack and introducing new one would cause major friction

Slide 23

Slide 23

Or maybe… tear it all down ● Higher-ups are on board, willing to invest ● Architecture is needlessly complicated for something that could be built with a modern framework ● MUST have clear spec to make sure there is not massive loss of features

Slide 24

Slide 24

  1. The HOW. (Mileage may vary)

Slide 25

Slide 25

A caveat... ● Focusing on the front end ● Suggestions are from personal experience and case studies from other companies ● Unfortunately every codebase is different

Slide 26

Slide 26

Documentation. (collective groan) 26

Slide 27

Slide 27

Code style guides. Get everyone on the same page. 27

Slide 28

Slide 28

Design patterns. Rinse and repeat.. 28

Slide 29

Slide 29

Tooling. Linters, compilers, task-runners - make your life easy-ers. 29

Slide 30

Slide 30

Test Driven Development. Can take a while to implement, but time savings in the long term. 30

Slide 31

Slide 31

Feature flags. Only visible to a select few. 31

Slide 32

Slide 32

Version control. For your sanity. 32

Slide 33

Slide 33

Releases. And a changelog! 33

Slide 34

Slide 34

Some examples... Just a couple - there are lots! 34

Slide 35

Slide 35

Case studies ● Github and removing jQuery from front end ● Dropbox moving from Underscore to Lodash ● Slack having to tweet about legacy code :( ● Dependencies - left-pad ● CloudZoom vs newer Zoom library

Slide 36

Slide 36

  1. The WHO.

Slide 37

Slide 37

Warm and fuzzies. It is TOUGH to work on legacy code all day every day. 37

Slide 38

Slide 38

“ Fall in Love with the Problem, Not the Solution - Unknown 38

Slide 39

Slide 39

We’re all in this together ● Refactor your own code! Nothing is too precious to be reworked and improved ● Provide opportunities to work on new features ● Get team to take personal ownership of code that they are commiting

Slide 40

Slide 40

Tenacity and optimism ● Don’t become complacent with the code you are committing ● Know your contribution affects the long-term prospects of the business and the site

Slide 41

Slide 41

Get buy-in. Use data to back up importance of tackling technical debt with those holding the purse-strings. 41

Slide 42

Slide 42

Know when to ask for help ● Employees aren’t always going to have specific skill set you need ● Is it cheaper to hire someone vs. do it yourself? ● An expert can almost always accelerate the process ● Don’t develop in a vacuum - different perspectives can be invaluable

Slide 43

Slide 43

  1. The WHEN.

Slide 44

Slide 44

Is it worth it? ● Can be difficult to convince people in charge of budgets to go back and update “working” code ● Speak to fragility of existing code ● Spaghetti code impedes velocity of new feature implementation ● Performance!

Slide 45

Slide 45

Don’t bet the farm - wait out trends ● Difficult to hire for outdated tech ● Technology changes at incredible pace - think back 2, 5, 10, 15 years ● Popularity = more resources ● WordPress vs SilverStripe vs MODx ● React vs Angular vs Vue vs NewHotness

Slide 46

Slide 46

Start on the right foot ● Learn from past mistakes ● Make sure you have someone on your team who understands architecture ● Think ahead to future features ● Understand the mvp ● Build time for maintenance into your developers’ schedule

Slide 47

Slide 47

Resources ● Working Effectively with Legacy Code Michael Feathers (OOP) ● Life-changing magic of deleting code ● Human cost of technical debt ● How to conquer legacy code ● Getting to know a legacy codebase ● So you've inherited a legacy codebase ● Top 4 symptoms of bad code ● 10 Things you will eventually learn about JS projects

Slide 48

Slide 48

“ It is not the strongest of the species that survives, nor the most intelligent that survives. It is the one that is the most adaptable to change. - Charles Darwin 48

Slide 49

Slide 49

Thank you! @AlfalfaAnne @outofthesandbox 49