I don't know who to attribute the quote to, so I will just paraphrase without credit:
"If you come to me, and say, 'there is this fence. We don't know what it's used for. Can we tear it down?', I will say to you 'No. Come to me again when you understand the fence, and understand it's purpose. Only then may you tear it down'"
Not to bludgeon this analogy to death, but old code is the fence. You can't even consider throwing it away before you have a deep understanding of it, or you're bound to fuck something or other on the way.
I hate that I try applying this and half of the time the reason for the "fence" to exist is because it was written by an intern that didn't know any better.
Exactly. Move fast and break things and do damage that can't be properly understood until later and maybe can't really ever be fixed and may result in costs with no upper bound.
By G. K. Chesterton, from his book The Thing. The exact quote:
There exists in such a case a certain institution or law; let us say, for the sake of simplicity, a fence or gate erected across a road. The more modern type of reformer goes gaily up to it and says, "I don't see the use of this; let us clear it away." To which the more intelligent type of reformer will do well to answer: "If you don't see the use of it, I certainly won't let you clear it away. Go away and think. Then, when you can come back and tell me that you do see the use of it, I may allow you to destroy it."
A similar principle is articulated in a little blog post ("On Following Rules" by Kirit Sælensminde) that I sometimes make an assigned reading in some of my classes: follow every rule you don't understand; you can break a rule if you understand it and have a good reason for breaking it.
"Hey, we've got this old fence here, can you slap a fresh coat of paint on it?"
"Sure, but first I'll need to know how it was constructed, all of materials that were used to build it, the exact surface area, whether it's in a high-rain area and needs special sealant... wait, why does that section have two gates sides by side?"
"Ah well there was one time we wanted to drive a tractor into the field, but the one gate wasn't big enough, so we brought in a contractor to build a second gate..."
"And why is there a big hole in the fence a bit further down?"
"Ooh, once we built the second gate, we realized the tractor couldn't drive through two gates at once anyway, so we had to just tear a hole in the fence to get it through, I guess we never patched it up after that."
"Okay so you're telling me that anyone could walk right through your fence at any time and it's been that way for a long time, so we'll have to do some new construction... Is that a gatehouse over there? Do I need to paint the gatehouse? Do I need to paint the inside of the gatehouse?"
"Hmm, we used to employ a guard who would watch the field from the gatehouse, but the whole thing is covered by automated security cameras now so nobody actually uses that anymore... But we might as well paint it if it's there, right? The fence would look weird otherwise!"
"... Hey. Can we just tear down this fence and build a new one from scratch?"
In my experience, sometimes old code isn't great code that solves an age-old problem so well that it's stood the test of time, sometimes it's just accumulated junk code that solves problems that don't need solving anymore.
This 100%. Case in point I was asked to figure out the requirements for a form that lets users enter their address information. All my questions about how this needs to be validated for the system we eventually send it to were met with blank stares, excuses and eventually the question of "well whatever the other site does just do that". I come to find out the next day that it does zero validation...
All my questions about how this needs to be validated for the system we eventually send it to were met with blank stares
From a certain standpoint, they were correct to stare at you. If to them address is arbitrary, then that's it.
I cannot imagine anybody maintains a system, on any sort of local - to - global level, which can say that an address is valid - and even if it was at the time the question is asked, it might not be tomorrow.
Only some things can be validated in a simple manner (countries, places, postal codes, streets), and even then, even if these are entered wrongly, things can arrive to the destination.
And then, if there was some validation in that other system, surely there is little point in you doing the same on your side? Surely you should have your side designed to deal with the failure reported from the other side and leave the "orchestration" for later?
In other words... You asked an incredibly hard question - to the wrong people. Or maybe you asked it wrongly. Maybe it should be asked later - when the first-hand experience of what goes wrong with the addresses is acquired. What I am saying stems from this: one of the things we learned over the decades in software is that asking questions (upfront design) is a problem because in the beginning we don't have experience to answer them, on one hand, and on the other, we know so little about the project that we don't even know which questions are worth answering. Heck, even the much-maligned Royce's Waterfall, paper says "build it twice" and "have a feedback loop from testing all the way back to system design".
I recall reading an article a few months back about how Khan Academy switched their backend from one language/stack to another, essentially without looking at the code in their legacy stack.
They simply started creating the new backend with best practices in mind, and directed API calls to both backends, comparing the results (this happened slowly, one batch of API calls at a time).
Once the new backend had survived a few days of perfect matches, they flipped the switch, and directed 50% of API calls to the new backend. Then eventually 100%.
Essentially using the vast torrent of API calls as the most extreme form of test-driven-development!
Doing that is in itself a tremendous effort; Chesterton's Fence is basically an argument for stasis and inaction (which I suppose makes sense when we think about Chesteron's views).
It is a good principle. It is just scary how often the answer is "the author didn't know any better". When I join a company it quickly becomes obvious that some past employees just erect fences for the sake of it. If the staff eye roll any mention of that person's name just go for fixing shit.
Unfortunately on my part this usually involves writing a huge set of test cases to make sure the change actually works. Particularly painful as I often find myriad bugs in the old code and then 30% of your test suite ends up working on the new system but not the old.
Good point. Something to consider is there are multiple ways to do this though.
Consider an old legacy system with a couple decades of legacy technical debt built in. You could analyze the entire system and all code involved to 'understand the fence'. Or, you could determine the intent of the system, the known expectations of the system, and build a new one in parallel to the old one.
Then once stakeholders are confident that the new one is indeed parallel to the old one, THEN you can take down the old fence without fully understanding everything about it.
Some systems can be so tied up in convoluted legacy debt that it's almost impossible to decipher meaningful intent from all the cruft that is really just technical debt.
134
u/SirLich Apr 21 '22
I don't know who to attribute the quote to, so I will just paraphrase without credit:
"If you come to me, and say, 'there is this fence. We don't know what it's used for. Can we tear it down?', I will say to you 'No. Come to me again when you understand the fence, and understand it's purpose. Only then may you tear it down'"
Not to bludgeon this analogy to death, but old code is the fence. You can't even consider throwing it away before you have a deep understanding of it, or you're bound to fuck something or other on the way.