Slide 1

Slide 1 text

Refactoring Reminders Don’t get lost in the trees Samantha Wong - Dashboard Learning Sessions - 20 May 2021

Slide 2

Slide 2 text

Why Samantha Wong - Dashboard Learning Sessions - 20 May 2021

Slide 3

Slide 3 text

Readability Samantha Wong - Dashboard Learning Sessions - 20 May 2021

Slide 4

Slide 4 text

Communication Ideas (Business) Logic Samantha Wong - Dashboard Learning Sessions - 20 May 2021

Slide 5

Slide 5 text

Maintainability Samantha Wong - Dashboard Learning Sessions - 20 May 2021

Slide 6

Slide 6 text

When Samantha Wong - Dashboard Learning Sessions - 20 May 2021

Slide 7

Slide 7 text

Rule of Three “Two instances of the same code do not require refactoring - three, yes.” 1. When you’re doing something for the first time, just get it done. 2. When you’re doing something similar for the second time, cringe at having to repeat but do the same thing anyway. 3. When you’re doing something for the third time, start refactoring. Samantha Wong - Dashboard Learning Sessions - 20 May 2021

Slide 8

Slide 8 text

Scout’s Rule “Always leave the campsite cleaner than when you found it.” Samantha Wong - Dashboard Learning Sessions - 20 May 2021

Slide 9

Slide 9 text

WRF Work > Right > Fast Make It Work, then Make It Right, then Make It Fast Samantha Wong - Dashboard Learning Sessions - 20 May 2021

Slide 10

Slide 10 text

How

Slide 11

Slide 11 text

Code Smells (?)

Slide 12

Slide 12 text

Code Smells - Bloaters Photo from refactoring.guru

Slide 13

Slide 13 text

Code Smells - Abusers Photo from refactoring.guru

Slide 14

Slide 14 text

Code Smells - Preventers Photo from refactoring.guru

Slide 15

Slide 15 text

Code Smells - Dispensables Photo from refactoring.guru

Slide 16

Slide 16 text

Code Smells - Couplers Photo from refactoring.guru

Slide 17

Slide 17 text

But how many of these sound like judgement calls? Samantha Wong - Dashboard Learning Sessions - 20 May 2021

Slide 18

Slide 18 text

Function Patterns Class Interaction Service Design Class Interaction Function Patterns Function Patterns Function Patterns Function Patterns Function Patterns science art Samantha Wong - Dashboard Learning Sessions - 20 May 2021

Slide 19

Slide 19 text

Use Only What is Needed, Not More Less is More! Samantha Wong - Dashboard Learning Sessions - 20 May 2021

Slide 20

Slide 20 text

Principle of Least Astonishment Samantha Wong - Dashboard Learning Sessions - 20 May 2021

Slide 21

Slide 21 text

Be Idiomatic Make use of the tools you have Samantha Wong - Dashboard Learning Sessions - 20 May 2021

Slide 22

Slide 22 text

Fail Loudly with trace Samantha Wong - Dashboard Learning Sessions - 20 May 2021

Slide 23

Slide 23 text

Would I be able to understand this in one week, two months, three years? Samantha Wong - Dashboard Learning Sessions - 20 May 2021

Slide 24

Slide 24 text

Delete Rename Move Oh! And prefer Renaming a file than Deleting and Adding. For it to appear as a rename in Git - rename the file in one commit, then modify in another if necessary. Samantha Wong - Dashboard Learning Sessions - 20 May 2021

Slide 25

Slide 25 text

Start Small Samantha Wong - Dashboard Learning Sessions - 20 May 2021

Slide 26

Slide 26 text

Communicate! Before, please Samantha Wong - Dashboard Learning Sessions - 20 May 2021

Slide 27

Slide 27 text

Guiding Principles - No change in functionality - Tests continues passing and build is green - Can do/stop anytime (!) Samantha Wong - Dashboard Learning Sessions - 20 May 2021

Slide 28

Slide 28 text

Principles > Practices Samantha Wong - Dashboard Learning Sessions - 20 May 2021

Slide 29

Slide 29 text

One More Thing Samantha Wong - Dashboard Learning Sessions - 20 May 2021

Slide 30

Slide 30 text

On nulls Let’s try to avoid them! - `null` should not be allowed as a valid input - There should be an explicit empty/base case for that. - Making variables non-nullable makes application behaviour predictable - `null` should only be allowed if we cannot help something to be null if things goes wrong As an Input: Samantha Wong - Dashboard Learning Sessions - 20 May 2021

Slide 31

Slide 31 text

On nulls [cont] - It’s the easy go-to for an empty object As an Output: Samantha Wong - Dashboard Learning Sessions - 20 May 2021

Slide 32

Slide 32 text

Links References https://www.industriallogic.com/img/ blog/2005/09/smellstorefactorings.p df https://flylib.com/books/en/1.476.1/ https://refactoring.guru/

Slide 33

Slide 33 text

CI/CD - Small, frequent changes -> lowering deployment risk - Build pipelines need to be well maintained - - Easy to find where are the mistakes

Slide 34

Slide 34 text

End Samantha Wong - Dashboard Learning Sessions - 20 May 2021