5
sjwsjwsjw
13d

cant figure out how to refactor legacy code in any clean/acceptable way

Comments
  • 5
    Figure out the behaviors. Write tests to ensure it behaves that way. Start with the easy stuff, end with the important stuff.

    Now start refactoring.
  • 1
    Also block PRs/merges on automated test pipelines passing.
  • 2
    Start SMALL! Broken but refactored code is worse than working but shit code lol. And @lungdart said, write tests, get the general behaviors sorted out and test the general behaviors and functionality.
  • 4
    What happens when the legacy code fails tests it should pass? What if those quirks are relied upon?
  • 0
    keep bashing your head until you untangle those earphone wires until it works idk

    I generally figure out what things do, map everything important out in pseudo code, then throw out like 80% of the old codebase and make the code more concise

    also people often write repeat algorithms in a bunch of places and don't realize it
  • 2
    i've always regretted being born but it's more intense when this is supposed to be a small & easy ticket
  • 1
    @Demolishun tests? Yeah, right.
  • 1
    @electrineer I am assuming they are going to write some for the new code.
  • 1
    If you can find what code gets called on what situation, it starts to become possible to extract code into functions you can unit test. It’s neigh impossible if it relies on thousands of god objects and their state, but it’s a starting point if you can get to the very smallest possible unit of code.
    Setting the office on fire is a better alternative as well.
  • 3
    Nuking the old code and starting from scratch might be less effort.
Add Comment