From 351d0a4f1712bfdecddff5e906f823d7b1b44e42 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Sat, 22 Feb 2025 23:59:13 +0000 Subject: [PATCH] Add daily email for 2025-02-10 Refactoring and Test-Driven Development --- source/_daily_emails/2025-02-10.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 source/_daily_emails/2025-02-10.md diff --git a/source/_daily_emails/2025-02-10.md b/source/_daily_emails/2025-02-10.md new file mode 100644 index 00000000..13039b95 --- /dev/null +++ b/source/_daily_emails/2025-02-10.md @@ -0,0 +1,30 @@ +--- +title: Refactoring and Test-Driven Development +date: 2025-02-10 +permalink: daily/2025/02/10/refactoring +tags: + - software-development +cta: ~ +snippet: | + How does refactoring work whilst doing test-driven development? +--- + +To do test-driven development, you start by writing a test which, because you're testing code that doesn't exist, will fail. + +The objective is to get the get the test to pass. + +You want to write just enough code to get the test to pass. + +It can be the simplest and naive code possible as long as it gets the tests to pass. + +Once the test passes, you can refactor and change the code in any way you want. + +This may be changing from a `foreach` loop to using a function like `array_map` or `array_reduce`, or splitting logic into separate classes. + +You may refactor your refactor and decide that a name or approach isn't correct and change it. + +You may split your code into service classes and then decide to use commands or actions. + +You can make whatever changes you want as long as the tests continue to pass. + +The implementation can change, but the outcome stays the same.