When Best Practices Must Wait: Delivering Enhancements Under Pressure
đ§ When Best Practices Take a Back Seat: Delivering in a Legacy Code Fire Drill
As developers, we pride ourselves on writing clean, modular, and testable code. We refactor ruthlessly, write unit tests religiously, and follow best practices like gospel. But what happens when youâre dropped into a client project with:
- A legacy Python application
- No unit tests
- Poor documentation
- Tight deadlines
- Strict policies (e.g., no AI tool usage)
And yet, youâre expected to deliver an enhancement or bugfix without breaking anything?
This post explores how to temporarily suspend ideal practices and instead adopt pragmatic principles to meet delivery goals without jeopardizing the systemâor your sanity.
đŻ The Real-World Scenario
Youâre a consultant brought in mid-project. The system is:
- Old and fragile
- Light on documentation
- Missing test coverage
- Written in Python (a language you can read but arenât fluent in)
You have just two days to ship a new feature. Refactoring and test suites are out of the question. The project timelineâand your credibilityâare at stake.
So what do you do?
đ§ The Pragmatic Survival Plan
1. Understand the Entry Point
Start at the top of the codebase. Look for:
if __name__ == "__main__":
main()
Trace where execution begins. Youâre not trying to understand everythingâjust the parts relevant to the use case.
đş Sample Call Path
main.py
â
âââ generate_customer_report()
âââ fetch_customer_data()
âââ enrich_with_metadata()
âââ write_csv_report()
2. Trace Only What You Need
Look for the flow that touches your use case. For example:
def enrich_with_metadata(data):
for row in data:
row["customer_type"] = get_type(row["id"])
# You want to add "region" here
return data
Skip everything else. Donât drown in unrelated modules or utility code.
3. Use Runtime Clues
When you canât write tests, let the app tell you what itâs doing:
print(f"[DEBUG] Customer ID: {row['id']}")
print(f"[DEBUG] Enriched Row: {row}")
Or, if logging is available:
logger.debug(f"Customer Region: {row['region']}")
Youâre building an ad-hoc understanding of the code as it runs.
4. Make Safe, Minimal Changes
Avoid sweeping refactors. Your change should be:
- Contained
- Reversible
- Impact-limited
For example:
def enrich_with_metadata(data):
for row in data:
row["customer_type"] = get_type(row["id"])
row["region"] = get_region(row["id"]) # Your enhancement
return data
Donât rename things or clean up old logic unless absolutely necessary.
5. Manually Test with Purpose
Without a test suite, define a manual checklist:
Step | Input | Expected Output |
---|---|---|
1. Run report for ID 123 | customer_id=123 |
Row has "region": "West" |
2. Run report for ID 456 | customer_id=456 |
Row has "region": "South" |
Test incrementallyârun only the code paths you touched.
6. Leave a Trail for Future Developers
Add comments like:
# TODO: Added 'region' field for enhancement X. Needs tests/refactor later.
And in your commit notes or changelog:
- Enhancement: Added region field to report output
- File modified: reporting.py (enrich_with_metadata)
- Manually tested with sample customer IDs
đ§ Why This Approach Works
Youâre applying disciplined, scoped effort under pressure. This means:
- You donât risk breaking unrelated features.
- You deliver quickly without trying to modernize everything.
- You leave breadcrumbs for future improvements.
đ Summary Workflow Diagram
[ Entry Point ]
â
[ Trace Use Case Path ]
â
[ Add Logs/Prints to Observe Behavior ]
â
[ Make Minimal Targeted Code Change ]
â
[ Manually Test with Clear Scenarios ]
â
[ Document Change & Flag for Future Refactor ]
đ§đ˝ââď¸ Final Thoughts
In a perfect world, weâd never touch code without refactoring or writing tests. But in the real worldâespecially in consultingâyou often face trade-offs.
When that happens:
â Prioritize delivery â Minimize risk â Stay transparent â Plan for follow-up refactor/testing
Sometimes, the most professional move isnât doing whatâs idealâitâs doing whatâs necessary, responsibly.
Have thoughts or want to share your experience? Feel free to reach out via LinkedIn âIâd love to hear how others approach this challenge.