The Strangler Fig Pattern
El Patrón Strangler Fig
Rather than rewriting legacy code all at once, grow new clean code around it like a strangler fig grows around a tree — until the old code can be safely removed. Incremental replacement keeps the system running throughout the transformation.
En lugar de reescribir el código legado de una vez, haz crecer código nuevo y limpio a su alrededor como una higuera estranguladora crece alrededor de un árbol — hasta que el código antiguo pueda eliminarse de forma segura. El reemplazo incremental mantiene el sistema funcionando durante toda la transformación.
Tests Are Your Safety Net
Las Pruebas Son tu Red de Seguridad
Before touching legacy code, write characterization tests. These tests don't describe what the code should do — they describe what it currently does, preserving behavior during refactoring. If a test breaks after your change, you accidentally changed behavior.
Antes de tocar código legado, escribe pruebas de caracterización. Estas pruebas no describen lo que el código debería hacer — describen lo que hace actualmente, preservando el comportamiento durante la refactorización. Si una prueba falla tras tu cambio, cambiaste el comportamiento sin querer.
✏️
Code Challenge
Desafío de Código
Extract testable units from the monolithic function.
Extrae unidades comprobables de la función monolítica.
💡 Key takeaway
Refactor in small, verifiable steps. Each step should leave the code better and all tests green.
Refactoriza en pasos pequeños y verificables. Cada paso debe dejar el código mejor y todas las pruebas en verde.