Level-Up as a Developer by Working with Legacy Codebases
Tags: resources, tdd, functional
Published: 2023-12-06 06:58:52

---
title: Level-Up as a Developer by Working with Legacy Codebases
published: true
description: A step-by-step roadmap to increase your confidence when working with legacy codebases.
tags: resources, tdd, functionalprogramming
# cover_image: https://direct_url_to_image.jpg
# Use a ratio of 100:42 for best results.
# published_at: 2023-12-06 06:38 +0000
---

Here's a list of topics and resources to use the next time you have a little down-time. Applying these skills will help you write more maintainable code. Over time you will also gain a reputation for being the kind of developer people turn to when they have a thorny problem to solve.

## Functional Programming Basics
Functional Programming is a vast subject, but you can start to see benefits from the understanding of a single concept: Pure Functions. Let's start with a simple definition 👇

{% embed https://www.freecodecamp.org/news/pure-function-vs-impure-function/ %}

This next video👇explains how to use it in your software. 

> Note: He refers to pure-functions as "calculations" and side-effects as "actions", so keep that in mind.

{% embed https://www.youtube.com/watch?v=EqO4TcNLjl0 %}

You will only learn by doing, so if you'd like to practice:
* Go through your current code-base
* Look for a Function where the side-effects and business-logic are mixed together
  * ideally you already understand the details of the function really well
* Separate out the Business Logic into a Pure-Function with just the "Calculations", and keep it separate from your side-effects.
  * Ensure your application still works.

If you would like an example, here's code for an example ShoppingCart Class where you can add items and a discount is calculated before checkout:
* [Business Logic mixed with Side-Effects](https://www.typescriptlang.org/play?#code/PQKhCgAIUglBTADgJ3gZ3gOwC5sgQ0jQAsB7RRAS0wHNIBjfZbSAd0u2Mg-gFs98mACaQUpAG6Uh6BsXj0A1qQCuLAGbLM9bJVKZ8AGw4BPAHRQQwcPQP40eAMpkK1GgGEmLAN5RRySuL42PDcwfwAXETY-rQA2gC6kAC8kAkA3L4oAUEh2KTYhgD6WfTwkZjKvABG8MjJkAAMGb74QkIAkmEAFDy8kWjRrgA0fpSl5ZU1yACUkeKkUpA+kCuQnJRopr2biMokPWHTGatrxBumeQUGxf6lkADUKSXwx6vAwJAOUiHwamry2EiABlSDQaK5TiFWkIOLpMJBSGoCPDer4VvQ9GhSAZ4KYDKCugADTp8SAAcgAJF5egBfMkENrwISmSAAFXyhlG40gFKp602lyKzxphKOvhp4F89DkihU2C6s0g80WyzeHwAQntqOg8PjwfRIgBBCgGYwESAAJgaAFJIDC0BjNCxWHJ4ZxchyDFyQhsEeJapAAKwNBpohiYlj2x04er8i6em5jEIAPiDIcgAH5GqYLZBIk1JSd3p9vpBfv9tEaTcYIVGVDHBCI9eDaGG44Lrs9oCkAIyQAC0do20ewr3RmOxuL1RONiCMTJ5XjrTugkB7IZptuXOBZADFqJznpFeV52wnhaLmkWPl9pGW-gDIm5iEwW3R3Qw9nleLU22dNtKr7wG4X6kD+yAKleaolne5aPp8WAwrQ5oYpgaiUMgvBBHCZZYZQBh-ucGDCG4ejoZh2F6AAonhBiQeKhajIEwSyEBIEDGBtQKnMCwiKqKzFl8vDKLYLGAcgb6Qp+HHgWGqFYjieIEoSz6vhC9CgeBPJ8v+8ZXImpQimKKwSpk-jMSExFCKRaEYVhOjUbR3FKrxSxhoJlDCaJlmIRChCoeR9k4Xw+D4XJE6KdOABENmBZR8IhfhRBYNgUXGZAEqmcWVEAB74Lwc4hHs+A0GU1gRgwnj1Jg8CsJ8zhULQHjMPRjDMKY0IkrwXRRQACsgpBCMo2iQIaUUjAALCGYptdgHVtF1PX9YNw0sOq42WtNGSzaY0ryEoqj0UAA)
* [Business Logic separated into a Pure Function](https://www.typescriptlang.org/play?#code/PQKhCgAIUglBTADgJ3gZ3gOwC5sgQ0jQAsB7RRAS0wHNIBjfZbSAd0u2Mg-gFs98mACaQUpAG6Uh6BsXj0A1qQCuLAGbLM9bJVKZ8AGw4BPAHRQQwcPQP40eAMpkK1GgGEmLAN5RRySuL42PDcwfwAXETY-rQA2gC6kAC8kAkA3L4oAUEh2KTYhgD6WfTwkZjKvABG8MjJkAAMGb74QkIAkmEAFDy8kWjRrgA0fpSl5ZU1yACUkeKkUpA+kCuQnJRopr2biMokPWHTGatrxBumeQUGxf6lkADUKSXwx6vAwJAOUiHwamry2EiABlSDQaK5TiFWkIOLpMJBSGoCPDer4VvQ9GhSAZ4KYDKCugADTp8SAAcgAJF5egBfMkENrwISmSAAFXyhlG40gFKp602lyKzxphKOvhp4F89DkihU2C6s0g80WyzeHwAQntqOg8PjwfRIgBBCgGYwESAwtAYzQsKp2JkI+GcXIcgxc+BohiYliW604eqMAz0ZS2YIAEQ2fvl-IurpuY3gYs970+30gv3+2iNJuMEN9Kn9ghEevBtE9McF12e0BSAEZIABaC2RgvYV7ozHY3F6onGxBGB1U-M26CQWsNBo0gCkzatrZZADFqJznpFeV4K3HhaLmicU19pOm-gDIm5iExS3RnQw9nleLVy2dNtKL-A3LfSPfkArd2rU4eMxPT4sBhWhzQxTA1EoZBeCCOF01gygDEfc4MGENw9CgmC4L0ABRRCDB-cVJRWLJAmCWRX3fAZP1qBU5gWERVRWfdKF4EMcko5BL0hG8aK-T0IKxHE8QJQkzwvCFg342oeT5J9YyueNShFMUVglTJ-HIkI0KEDDIOg2CdDwgj6KVRilmTD4vnY0MdJAiFCAgrCjPgvh8CQwTOxEnsACJ9JcnD4XcpCiCwbBfLUyAJQ0lMAAVlFQSANC0YynVIBhDGDOzeOHf07QwEQ9F4yt3XAFLtHgwNspyCM5xtLpKzi24ykgCpqlqRV2qmSyWI+PtTXNAAmBoZzylhWDkJ05DWV13W4PAJFkgBWCdfFQbBEvSq5moTSAAD5IFWhpIAAfkaUwhsgSImnAWKPlwgAPfBeH7EI9nwGgymsb1MuYepMHgVhPmcKhaA8ZgiMYZhTGhEleC6XzmtIIRlG0SBDV8kYABYJzFaHsFhtp4cR5HUfR9UscgEaGnxzxTGleQlFUIigA)

Why would you want to do this though. 
* Most bugs tend to be in the Business Logic 
* If a Function or a Class logs to a DB or sends an email every time it's run, it becomes harder to test properly.
* If you can extract a Calculation into a Pure Function, it becomes easier to run.
* The easier it becomes to run, the easier it is to fix bugs.
* You can even write unit-tests for your Pure-Functions and run them automatically on every change, making it easier to catch [regressions](https://en.wikipedia.org/wiki/Software_regression).

## Next Steps
There's a few other skills I think make it easier to work with old code, I'm going to add those in shortly:
* TDD, for better-quality pure-functions
* C4 Architecture Diagrams, for standardized documentation
* Sequence Flow Diagrams in Mermaid, to get quicker feedback on code
* Trunk Based Development, to reduce operational overhead for small teams
* CodeScene, to manage the health of a codebase and pay-down tech-debt
* Approval Testing, when the original devs on a project aren't available

Leave me a comment or DM me on [Twitter](twitter.com/jlouzado) if you have any specific requests or questions.