Slide 1

Slide 1 text

Rewriting iOS apps in the wild

Slide 2

Slide 2 text

Alberto Gragera [email protected] Co-Founder and Technical Director @gragera_

Slide 3

Slide 3 text

We embark on every project with a commitment to create something elegant, enduring and effective. That is our heartbeat. Our approach is uniquely simple and honest, we are a small dedicated software studio, delivering outstanding work. Karumi is the Rock Solid code software development studio.

Slide 4

Slide 4 text

OPINIONS

Slide 5

Slide 5 text

I've seen things you people wouldn't believe

Slide 6

Slide 6 text

Refactor vs Rewrite

Slide 7

Slide 7 text

Two things to keep in mind before getting started

Slide 8

Slide 8 text

Reescribir una App es un proceso muy complicado y en cierta medida contraintuitivo con respecto a lo que nos enseñan las buenas prácticas del software Do not underestimate complexity

Slide 9

Slide 9 text

Think twice before rewriting from scratch

Slide 10

Slide 10 text

Why do we have to rewrite?

Slide 11

Slide 11 text

Because shit happens

Slide 12

Slide 12 text

“Ok, I have the time. Let’s do this right!”

Slide 13

Slide 13 text

I can build this cake!

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

Sooooo yeah, rewriting apps is something that we do every now and then ¯\_(ϑ)_/¯

Slide 17

Slide 17 text

Common sense

Slide 18

Slide 18 text

Write the tests before rewriting! Common sense

Slide 19

Slide 19 text

BUT it might come with significant tradeoffs The concept is "

Slide 20

Slide 20 text

If you are rewriting some SpaceX code, you might want to write the tests first, no matter how complex it is We are making mobile apps anyway

Slide 21

Slide 21 text

Replace layers transversally Common sense

Slide 22

Slide 22 text

TONS OF

Slide 23

Slide 23 text

AND DANGER

Slide 24

Slide 24 text

PROCESS

Slide 25

Slide 25 text

Think hard about your new architecture

Slide 26

Slide 26 text

Viper-ish

Slide 27

Slide 27 text

Design your APIs as you would love to use them

Slide 28

Slide 28 text

Use whatever the language offers to make your APIs shine

Slide 29

Slide 29 text

Evaluate how much would it cost to make the old code testable Probably days

Slide 30

Slide 30 text

Some tips that could help you

Slide 31

Slide 31 text

Protocol extensions to wrap existing models

Slide 32

Slide 32 text

protocol UserViewModel { var id: String { get } var userName: String { get } var email: String? { get } var memberSince: NSDate? { get } var isMe: Bool { get } }

Slide 33

Slide 33 text

extension User : UserViewModel { var id: String { return String(self.userId) } var userName: String { return self.name ?? NSLocalizedString( "NoUsername.DefaultName", comment: "Default name for users with no name”) } var memberSince: NSDate? { return DateParser.fromString(self.memberSinceDate) } var isMe: Bool { get { return String(User.ObtenerInstancia().userId) == id } } }

Slide 34

Slide 34 text

Inject presenters in existing ViewControllers so you can control the flow

Slide 35

Slide 35 text

Study the old code, thoroughly

Slide 36

Slide 36 text

Pick your first battle, don’t go all Chuck Norris on the old code

Slide 37

Slide 37 text

Implement the full architecture

Slide 38

Slide 38 text

Re implementa la feature elegida por completo en la nueva arquitectura No te preocupes por el código duplicado en este punto, es totalmente normal Reimplement the chosen feature in the new architecture

Slide 39

Slide 39 text

Add scaffolding and seams to connect the old with the new

Slide 40

Slide 40 text

Scaffolding?

Slide 41

Slide 41 text

Intermediate code to glue the old architecture with the new one

Slide 42

Slide 42 text

Make it super easy for the code reader to identify scaffolding code UserScaffolding

Slide 43

Slide 43 text

Centralize the scaffolding code per feature UserScaffolding

Slide 44

Slide 44 text

Seams?

Slide 45

Slide 45 text

A place in our code base where we can alter behaviour without being forced to edit it in that place

Slide 46

Slide 46 text

For example, if you don’t want to change the getInstance calls, add a setInstance method to alter that behavior from the outside

Slide 47

Slide 47 text

End of scaffolding and seams

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

One does not simply Put code in production One just

Slide 50

Slide 50 text

Release fast and release often

Slide 51

Slide 51 text

KAIZEN

Slide 52

Slide 52 text

New Old Old Scaffold Scaffold New Old Old New Old Old Scaffold Scaffold

Slide 53

Slide 53 text

If a smelly part is small enough, throw it away and rewrite it

Slide 54

Slide 54 text

It is easier to replace code that is barely used

Slide 55

Slide 55 text

SUMMARY

Slide 56

Slide 56 text

Strategist

Slide 57

Slide 57 text

+

Slide 58

Slide 58 text

Surgeon

Slide 59

Slide 59 text

+

Slide 60

Slide 60 text

Demolition ball

Slide 61

Slide 61 text

Thanks!

Slide 62

Slide 62 text

Questions?