SlideShare a Scribd company logo
1 of 41
Download to read offline
Getting Better All the Time
How to Escape Bad Code
Josh Justice
Big Nerd Ranch
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
I have to work with
some bad code.
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
(to the code)
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
What do I do about
bad code?
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
What do you do about
bad code?
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
Work around bad code?
• Development will be slow
• Workarounds mean the next change will be even slower
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
Rewrite bad code?
• A big chunk of work that doesn't deliver features to the user and
that can't be interrupted
• If I break it, I own it
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
So what do we do about
bad code?
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
Wait…
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
Wait…
I just remembered something…
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
Wait…
I just remembered something…
…that changes everything
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
This component has
thorough tests!
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
I can make it better
as I go.
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
(to the code)
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
That was pretty fun!
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
Refactoring
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
Refactoring
Small changes that improve the
arrangement of the code without
changing its functionality.
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
Why Small Changes?
• Value: making the improvements that pay off right away
• Delivery: code is shippable after each refactoring
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
What to do about bad code?
Make it better all the
time.
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
What to do about bad code?
Make it better all the
time, if…
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
What to do about bad code?
Make it better all the
time
IF…
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
Make it better all the time, if…
you have
comprehensive tests
you can trust.
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
"Trust our tests?"
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
"Trust our tests?"
"I can hardly stand our
tests!"
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
Is it even possible to
get comprehensive
tests you can trust?
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
Test-Driven Development (TDD)
1. Write a test and see it fail ("red")
2. Write just enough code to make the test pass ("green")
3. Refactor
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
(to the code)
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
reactnativetesting.io/gettingbetter
• The rest of the TDD sequence
• More refactors
• Pointers to more resources on TDD in React Native
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
The biggest benefit of TDD:
TDD equips you to
make your code better
all the time.
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
Write whichever kinds
of tests give you
confidence to make it
better all the time.
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
"TDD is too much work."
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
Know what else is a lot of work?
Living with bad code
forever.
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
You're going to deal with bad code
somehow.
You don't want to work around it.
You often can't rewrite it.
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
The way I know to escape bad code:
Make it better all the time.
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
Imagine…
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
Imagine coming into a new codebase
totally confident you
can trust the tests.
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
TDD
→ great tests
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
TDD
→ great tests
→ making it better all the time
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
TDD
→ great tests
→ making it better all the time
→ great code!
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
About Me
Principal Architect at Big Nerd Ranch
• Mobile app consulting
• Corporate training
Get in touch:
reactnativetesting.io/gettingbetter
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh
Justice - reactnativetesting.io/gettingbetter
Thank you.
reactnativetesting.io/gettingbetter
Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter

More Related Content

More from Josh Justice

Building an App for Mobile and Web with Expo
Building an App for Mobile and Web with ExpoBuilding an App for Mobile and Web with Expo
Building an App for Mobile and Web with ExpoJosh Justice
 
User-Modifiable Software: Smalltalk and HyperCard
User-Modifiable Software: Smalltalk and HyperCardUser-Modifiable Software: Smalltalk and HyperCard
User-Modifiable Software: Smalltalk and HyperCardJosh Justice
 
Practical Accessibility (A11y)
Practical Accessibility (A11y)Practical Accessibility (A11y)
Practical Accessibility (A11y)Josh Justice
 
Old Solutions to New Testing Problems
Old Solutions to New Testing ProblemsOld Solutions to New Testing Problems
Old Solutions to New Testing ProblemsJosh Justice
 
Test-Driven Development in Vue with Cypress
Test-Driven Development in Vue with CypressTest-Driven Development in Vue with Cypress
Test-Driven Development in Vue with CypressJosh Justice
 
Test-Driven Development in React with Cypress
Test-Driven Development in React with CypressTest-Driven Development in React with Cypress
Test-Driven Development in React with CypressJosh Justice
 
Newbie's Guide to Contributing to Babel
Newbie's Guide to Contributing to BabelNewbie's Guide to Contributing to Babel
Newbie's Guide to Contributing to BabelJosh Justice
 
Outside-in Testing in Vue with Cypress
Outside-in Testing in Vue with CypressOutside-in Testing in Vue with Cypress
Outside-in Testing in Vue with CypressJosh Justice
 

More from Josh Justice (8)

Building an App for Mobile and Web with Expo
Building an App for Mobile and Web with ExpoBuilding an App for Mobile and Web with Expo
Building an App for Mobile and Web with Expo
 
User-Modifiable Software: Smalltalk and HyperCard
User-Modifiable Software: Smalltalk and HyperCardUser-Modifiable Software: Smalltalk and HyperCard
User-Modifiable Software: Smalltalk and HyperCard
 
Practical Accessibility (A11y)
Practical Accessibility (A11y)Practical Accessibility (A11y)
Practical Accessibility (A11y)
 
Old Solutions to New Testing Problems
Old Solutions to New Testing ProblemsOld Solutions to New Testing Problems
Old Solutions to New Testing Problems
 
Test-Driven Development in Vue with Cypress
Test-Driven Development in Vue with CypressTest-Driven Development in Vue with Cypress
Test-Driven Development in Vue with Cypress
 
Test-Driven Development in React with Cypress
Test-Driven Development in React with CypressTest-Driven Development in React with Cypress
Test-Driven Development in React with Cypress
 
Newbie's Guide to Contributing to Babel
Newbie's Guide to Contributing to BabelNewbie's Guide to Contributing to Babel
Newbie's Guide to Contributing to Babel
 
Outside-in Testing in Vue with Cypress
Outside-in Testing in Vue with CypressOutside-in Testing in Vue with Cypress
Outside-in Testing in Vue with Cypress
 

Getting Better All the Time: How to Escape Bad Code

  • 1. Getting Better All the Time How to Escape Bad Code Josh Justice Big Nerd Ranch Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 2. I have to work with some bad code. Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 3. (to the code) Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 4. What do I do about bad code? Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 5. What do you do about bad code? Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 6. Work around bad code? • Development will be slow • Workarounds mean the next change will be even slower Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 7. Rewrite bad code? • A big chunk of work that doesn't deliver features to the user and that can't be interrupted • If I break it, I own it Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 8. So what do we do about bad code? Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 9. Wait… Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 10. Wait… I just remembered something… Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 11. Wait… I just remembered something… …that changes everything Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 12. This component has thorough tests! Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 13. I can make it better as I go. Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 14. (to the code) Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 15. That was pretty fun! Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 16. Refactoring Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 17. Refactoring Small changes that improve the arrangement of the code without changing its functionality. Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 18. Why Small Changes? • Value: making the improvements that pay off right away • Delivery: code is shippable after each refactoring Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 19. What to do about bad code? Make it better all the time. Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 20. What to do about bad code? Make it better all the time, if… Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 21. What to do about bad code? Make it better all the time IF… Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 22. Make it better all the time, if… you have comprehensive tests you can trust. Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 23. "Trust our tests?" Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 24. "Trust our tests?" "I can hardly stand our tests!" Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 25. Is it even possible to get comprehensive tests you can trust? Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 26. Test-Driven Development (TDD) 1. Write a test and see it fail ("red") 2. Write just enough code to make the test pass ("green") 3. Refactor Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 27. (to the code) Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 28. reactnativetesting.io/gettingbetter • The rest of the TDD sequence • More refactors • Pointers to more resources on TDD in React Native Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 29. The biggest benefit of TDD: TDD equips you to make your code better all the time. Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 30. Write whichever kinds of tests give you confidence to make it better all the time. Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 31. "TDD is too much work." Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 32. Know what else is a lot of work? Living with bad code forever. Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 33. You're going to deal with bad code somehow. You don't want to work around it. You often can't rewrite it. Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 34. The way I know to escape bad code: Make it better all the time. Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 35. Imagine… Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 36. Imagine coming into a new codebase totally confident you can trust the tests. Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 37. TDD → great tests Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 38. TDD → great tests → making it better all the time Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 39. TDD → great tests → making it better all the time → great code! Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 40. About Me Principal Architect at Big Nerd Ranch • Mobile app consulting • Corporate training Get in touch: reactnativetesting.io/gettingbetter Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter
  • 41. Thank you. reactnativetesting.io/gettingbetter Getting Better All the Time: How to Escape Bad Code - React Native EU 2022 - Josh Justice - reactnativetesting.io/gettingbetter