Slide 1

Slide 1 text

Taking over someone else's codebase

Slide 2

Slide 2 text

Florian Mierzejewski Android Engineer @Trade Republic - Berlin, Germany

Slide 3

Slide 3 text

Trade Republic • Europe’s first commission-free mobile broker • Easy, fast and convenient access to capital markets for everyone. • Make stock trading dead simple and commission-free.

Slide 4

Slide 4 text

What is this about? • Avoid frustration • Strategies to take over a codebase • Making it better, leaving it in a better state than we found it

Slide 5

Slide 5 text

Mindset

Slide 6

Slide 6 text

• Starting with a good mindset • Taking everything as a challenge • Learning about new domains

Slide 7

Slide 7 text

–Someone on Hackernews “My #1 rule for existing codebases: Just because you wouldn't have done it the way they did doesn't mean they did it wrong.”

Slide 8

Slide 8 text

–Someone on Hackernews “I think it's developer nature to look at a huge pile of code that someone else wrote and immediately think: This is a pile of crap. I can do better, so the first thing to do is rewrite all of this, my way (which just so happens to be The Right Way).”

Slide 9

Slide 9 text

–Someone on Hackernews “Realise that after 3 years, they have hopefully fixed a lot of bugs and got to a solution that is somewhat mature and better than you can do in a week.”

Slide 10

Slide 10 text

–Someone on Reddit “My number 1 red flag of working with a developer, unless they are very early in their career, is hearing them describe a codebase as awful. Most really are not that bad and are usually just using unfamiliar and less than ideal design patterns and coding practices.”

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

Before starting coding away…

Slide 13

Slide 13 text

Different kinds of taking over • Alone with or without the original developer • With a team that has a clue or no clue about the current codebase

Slide 14

Slide 14 text

Looking at the code • Crash reporting • App reviews • Performance • History of the code

Slide 15

Slide 15 text

• Structure • God classes, base classes • Architecture • Tests • CI setup

Slide 16

Slide 16 text

• Writing down questions while going through the codebase • Dev tools to make life easier • What are the external actors, who are we relying on, how stable are they • Basic security • Deployment process and existing level of automation • High level overview of dependencies • Dependency injection

Slide 17

Slide 17 text

Making use of the codebase owner • Vague understanding of the whole system and then dive into the more non obvious / tricky parts with the original developer • Focusing on the history of the codebase, why are things the way they are? History and context are hard to deduce from code / documentation • Chesterton's fence principle

Slide 18

Slide 18 text

Staying kind • Put yourself in the seat of the original developer, have some empathy • What is this piece of * even doing? - Could you guide me through what this piece of code is doing? • Being understandable, we all have to take those shortcuts during crunch time that we never ever get to revisit later

Slide 19

Slide 19 text

Having an impact

Slide 20

Slide 20 text

Do not • Huge refactoring from the get go • Start writing new code right away • Introduce breaking changes • Play the blame game, it gets you only so far

Slide 21

Slide 21 text

• Understand the purpose of the system, what its users want from it and how they use it to achieve that. • Learn about processes • Get to know the architecture Do

Slide 22

Slide 22 text

Do • Start with a task where existing code need to be changed • Small refactoring tasks / bugs • Get familiar with the language of the domain • Ask for help • Read wiki / documentation

Slide 23

Slide 23 text

Do • Take your time • Communicate your codebase concerns • Take notes on what needs to be looked at / addressed • Find the right level of detail • Create or find a good candidate for a Blueprint

Slide 24

Slide 24 text

Do • Use the debugger • Ask for a time budget on refactoring and share wins to show a positive impact (test coverage up, less dependencies so app smaller, feeling more confident in making changes, app more stable…) • Focus on the worst parts, the rest can always wait, if it isn’t broken don’t fix • There will always be something that needs to be addressed, the codebase is never going to be fully migrated • Expect to write quite some glue between both worlds • Test, Refactor, Repeat

Slide 25

Slide 25 text

Android specifics • Look at what is nowadays considerer deprecated and / or dangerous, AsyncTasks? PostDelayed? Go through @Deprecated warnings • Was there some playing around with things that are experimental / very new • State of modularisation

Slide 26

Slide 26 text

Incremental changes • Extract collaborators from base / god classes • Composition over inheritance • Using ActivityCallbacks • Modularisation (start by creating new modules for features), • Synchronise between platforms

Slide 27

Slide 27 text

Incremental changes • Wrap important domain primitives • Dev tools that make you save time in the long run • Pre-commit hooks • Reduce test execution time • ComponentActivity

Slide 28

Slide 28 text

ComponentActivity • LifecycleObserver • OnBackPressedDispatcher • ActivityResultCaller

Slide 29

Slide 29 text

Use requireX() getActivity().navigateTo(…) VS if (activity "!= null) activity.navigateTo(…) VS activity"?.navigateTo(…) VS requireActivity().navigateTo(…)

Slide 30

Slide 30 text

The Scout Rule

Slide 31

Slide 31 text

• Time to give back so the next person have less of a hard time taking over • How can we make it better so the next one can hit the ground running? • Clear commits, ticket number, explanation if obscure hacks with links • Take note about what was missing while taking over and fill the gaps

Slide 32

Slide 32 text

Zusammenfassung

Slide 33

Slide 33 text

• Taking over is a hell of a challenge, in a good way • Do not approach this as a chore • Do not rewrite the entire codebase • Do take your time • Do make it your own with little incremental changes • Do leave your current codebase as clean as possible

Slide 34

Slide 34 text

Questions?