SlideShare a Scribd company logo
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

PDF
Effective Detox Testing - React Advanced 2023
Josh Justice
 
PDF
Designing Effective Tests with React Testing Library - React Summit 2023
Josh Justice
 
PDF
Testing React Native Apps - Chain React 2023
Josh Justice
 
PDF
Designing Effective Tests with React Testing Library - React Day Berlin 2022
Josh Justice
 
PDF
Building for Mobile and Web with Expo - React Day Berlin 2022
Josh Justice
 
PDF
Intro to React Native Testing Library
Josh Justice
 
PDF
Building for Mobile and Web with Expo - React Advanced London 2022
Josh Justice
 
PDF
Sustainable Learning - ReactATL Jan 2022
Josh Justice
 
Effective Detox Testing - React Advanced 2023
Josh Justice
 
Designing Effective Tests with React Testing Library - React Summit 2023
Josh Justice
 
Testing React Native Apps - Chain React 2023
Josh Justice
 
Designing Effective Tests with React Testing Library - React Day Berlin 2022
Josh Justice
 
Building for Mobile and Web with Expo - React Day Berlin 2022
Josh Justice
 
Intro to React Native Testing Library
Josh Justice
 
Building for Mobile and Web with Expo - React Advanced London 2022
Josh Justice
 
Sustainable Learning - ReactATL Jan 2022
Josh Justice
 

More from Josh Justice (8)

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

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