{ "uuid": [ { "value": "ea06edab-74a5-42d4-add9-d4dce3d0f792" } ], "langcode": [ { "value": "en" } ], "type": [ { "target_id": "daily_email", "target_type": "node_type", "target_uuid": "8bde1f2f-eef9-4f2d-ae9c-96921f8193d7" } ], "revision_timestamp": [ { "value": "2025-05-11T09:00:07+00:00" } ], "revision_uid": [ { "target_type": "user", "target_uuid": "b8966985-d4b2-42a7-a319-2e94ccfbb849" } ], "revision_log": [], "status": [ { "value": true } ], "uid": [ { "target_type": "user", "target_uuid": "b8966985-d4b2-42a7-a319-2e94ccfbb849" } ], "title": [ { "value": "You need tests to refactor safely" } ], "created": [ { "value": "2024-09-01T00:00:00+00:00" } ], "changed": [ { "value": "2025-05-11T09:00:07+00:00" } ], "promote": [ { "value": false } ], "sticky": [ { "value": false } ], "default_langcode": [ { "value": true } ], "revision_translation_affected": [ { "value": true } ], "path": [ { "alias": "\/daily\/2024\/09\/01\/you-need-tests-to-refactor-safely", "langcode": "en" } ], "body": [ { "value": "\n

Once you have working code<\/a>, you can refactor it to make it better.<\/p>\n\n

You can rename variables, extract new functions or classes, ensure the code is styled and formatted correctly - anything to make the code easier to read, understand or maintain.<\/p>\n\n

But, the key thing is the code still needs to work.<\/p>\n\n

You don't want to break working code and introduce a regression, even if it is messy or difficult to read.<\/p>\n\n

The best way I know to approach this is by having automated tests covering this code, and ensure they are working and passing before starting to refactor.<\/p>\n\n

Then you can run the tests again and ensure they still pass.<\/p>\n\n

If they pass, the code still works and the refactoring was successful.<\/p>\n\n

If not, the code is broken and you need to revert the changes and start again.<\/p>\n\n ", "format": "full_html", "processed": "\n

Once you have working code<\/a>, you can refactor it to make it better.<\/p>\n\n

You can rename variables, extract new functions or classes, ensure the code is styled and formatted correctly - anything to make the code easier to read, understand or maintain.<\/p>\n\n

But, the key thing is the code still needs to work.<\/p>\n\n

You don't want to break working code and introduce a regression, even if it is messy or difficult to read.<\/p>\n\n

The best way I know to approach this is by having automated tests covering this code, and ensure they are working and passing before starting to refactor.<\/p>\n\n

Then you can run the tests again and ensure they still pass.<\/p>\n\n

If they pass, the code still works and the refactoring was successful.<\/p>\n\n

If not, the code is broken and you need to revert the changes and start again.<\/p>\n\n ", "summary": null } ] }