News for hackers. Stuff that matters.
Re:Ask HN: What is the first thing you implement at a new co... by james_morton on Wednesday June 20, 2018 @08:41AM (#17354803)
More likely the hacks are there because requirements changed and the software wasn't initially built to be flexible enough to support change.

A rewrite will solve it in the short term - until requirements change again.

However, I would much rather apply the new 'hacks' onto the rewritten 10 line function than figure out the original 200 line behemoth.

Re:Ask HN: What is the first thing you implement at a new co... by swsieber on Wednesday June 20, 2018 @09:01AM (#17354927)
Each hack individually, yes, is likely to be there because of requirements changing.

But collectively, it's likely that one of those hacks is there to account for some edge case that's not intuitive and will be missed on the rewrite.

Re:Ask HN: What is the first thing you implement at a new co... by organsnyder on Wednesday June 20, 2018 @09:08AM (#17354978)
In my experience, it's extremely difficult to know which particular lines of code are obsolete. This becomes even more difficult as a codebase ages and is worked on by more contributors. Add on another exponent for every business stakeholder that has a hand in defining the business rules—especially if you have requirements coming from multiple sources that may not be aware of each other.
Re:Ask HN: What is the first thing you implement at a new co... by eastbayjake on Wednesday June 20, 2018 @09:28AM (#17355125)
This is why we have the strangler pattern, right? You wrap the legacy functionality with a set of tests that define the functional requirements of the code, then your new refactored solution needs to keep those tests passing. (And then once you've done that, make sure that your "hacks and bugfixes" get test cases so you can make sure the next refactor accounts for them!)
Re:Ask HN: What is the first thing you implement at a new co... by vorpalhex on Wednesday June 20, 2018 @09:29AM (#17355126)
Which is why comprehensive testing is important. If we have test cases that accurately capture our requirements, then we can refactor and know when we've err'd from the path. If we don't have test cases, then we have to make best guesses (and we know how that one turns out).
Re:Ask HN: What is the first thing you implement at a new co... by finaliteration on Wednesday June 20, 2018 @10:12AM (#17355517)
Accuracy is key, here. I came into my current job with some pretty awful tests in place that “passed” and showed good coverage but did absolutely nothing for actually hitting the necessary cases...
Re:Ask HN: What is the first thing you implement at a new co... by test6554 on Wednesday June 20, 2018 @10:53AM (#17355946)
I have some code I inherited that I have rewritten it twice now and the second time is when it really became stable and also easier to work with.
Re:Ask HN: What is the first thing you implement at a new co... by walshemj on Wednesday June 20, 2018 @02:01PM (#17357899)
Or you rewrite it to be more flexible and seriously think about what if's eg what if sales tax was changed in the middle of a month/billing period.

This is a real example at one job in the UK on budget day I used to listen the budget speech live in case it had any impact on the system I worked on.

Re:Ask HN: What is the first thing you implement at a new co... by ruok0101 on Wednesday June 20, 2018 @02:12PM (#17358025)
I worked with one guy once where he wanted the "ultimate flexibility" and every data model object basically became a database table with the columns 'key' and 'value'. Trying to think of everything ahead of time has its own problems...
Re:Ask HN: What is the first thing you implement at a new co... by walshemj on Wednesday June 20, 2018 @02:48PM (#17358435)
Which is how map/reduce systems work at the core - and how we implemented it back in the 1980's.

Each record type and field in that record had its own entry in a MIDAS table so you could process say TELEX records differently to Email, Data etc.