Live data from Hacker News

Ask HN: Good resources about legacy code?

news.ycombinator.com

11–20 of 41 posts

Re: Ask HN: Good resources about legacy code?

#11
Are you me?

This is the exact position I was in 6 months ago and it wasn't just legacy code (legacy code isn't inherently bad) it was/is bad legacy code.

https://leanpub.com/mlaphp is very very good, it's a roadmap/process to get a legacy PHP project to a reasonable state efficiently.

Re: Ask HN: Good resources about legacy code?

#12

Are you me? This is the exact position I was in 6 months ago and it wasn't just legacy code (legacy code isn't inherently bad) it was/is bad legacy code. https://leanpub.com/mlaphp is very very good, it's a roadmap/process to get a legacy PHP project to a reasonable state efficiently.

[deleted]

Re: Ask HN: Good resources about legacy code?

#15
post #9

If pieces of a codebase need to be changed, I break it into a few general steps (varies depending on specifics): 1) Look at the code and examine what it would take to make it testable. 2) make tiny, safe refactorings to prepare the code to be tested -- only if you are absolutely certain these changes can cause no side-effects (usually I'll rely on tools to help me do this, just to increase the confidence level). If y…

Since you are working with dynamic language, step 2 should include adding type annotations or whatever they are called in php. Specifying stricter types makes refactoring much easier.

Agreed. Adding type annotations is already a huge refactor in itself though and pretty risky with PHP. Once you have that done life will be much easier.

Re: Ask HN: Good resources about legacy code?

#16
I have learned that it's good to approach something like this with a level of humility. What looks like a big pile of spaghetti code may actually have a structure, just not one you may like. I often think "How stupid can these people be?" only to learn later that they actually had a reasonable design. It pays to take the time to understand the code.

Otherwise I'd try to refactor the code into testable modules as much as possible. Unfortunately PHP is not on your side when it comes to refactoring. Especially in the older version people used a lot of "tricks" that make refactoring hard.

Re: Ask HN: Good resources about legacy code?

#17
In addition to Working Effectively with Legacy Code, Re-Engineering Legacy Software[1] is pretty decent. It's really a lot of the same recommendations; put a test harness in place to guard against regressions, then start pulling out things and making them into more sane, SOLID components. For that aspect, you can look at things like the Uncle Bob Clean Code series, or my personal favorite Adaptive Code via C#[2] which despite the title is pretty general and all about writing code with the SOLID principles.

[1] https://www.manning.com/books/re-engineering-legacy-software

[2] http://amzn.to/2CfxK8w

Re: Ask HN: Good resources about legacy code?

#18
Some advice from someone who has done the same thing multiple times. Find yourself someone who knows the application really well and become their best friend. You'll find some weird things in the codebase and often they'll be able to give you context

Re: Ask HN: Good resources about legacy code?

#19
I've worked with Paul Jones in the past and he has actually modernized one of my own legacy PHP codebases. He wrote down his experiences and advice in "Modernizing Legacy Applications in PHP": https://leanpub.com/mlaphp

It might be worth your time. (Edit: noir_lord also recommended the same book in this thread.)

Post reply on HN