TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Strangler pattern, a powerful simple concept to do refactoring

211 点作者 neo2006超过 6 年前

17 条评论

cle超过 6 年前
&gt; There&#x27;s another important idea here - when designing a new application you should design it in such a way as to make it easier for it to be strangled in the future. Let&#x27;s face it, all we are doing is writing tomorrow&#x27;s legacy software today. By making it easy to be strangled in the future, you are enabling the graceful fading away of today&#x27;s work.<p>This is a very important point that I&#x27;ve been harping on for years. If the nature of your business requires quickly adapting to new business needs--then make your software and systems easy to delete! Chances are good that they&#x27;ll be obsolete&#x2F;outdated in a few years, and everyone will be much happier if the system is easy to remove and replace.<p>How to implement that is very dependent on the nature of your systems, how you deploy, your company&#x27;s tech and operational culture, etc. But it&#x27;s very much worth thinking about: &quot;If this project were to fail in the long run, how hard would it be to get rid of?&quot; In large companies, lingering legacy systems can make or break an entire organization.
评论 #19126410 未加载
评论 #19126351 未加载
评论 #19128124 未加载
jadbox超过 6 年前
The main problem I&#x27;ve seen with this strategy is &#x27;funding&#x27; for the new system gets pulled half-way, and there&#x27;s no time remaining to refactor the old system. Fast-forward a year later, someone else may try to write a 3rd refactor using a different 3rd improved system design. Now that project also stalls out due to project pressing concerns. Now the codebase is polluted with different systems that require more training to work with, more lines of code to cause bugs (mixed frameworks), and generally a headache. I still think the Stangler pattern is a good one, just make sure you get enough leeway to reach the &#x27;strangler&#x27; moment where most of the old code becomes deprecated and removed.
评论 #19125747 未加载
评论 #19135829 未加载
systematical超过 6 年前
Agreed. We are wrapping up the rewrite of a CRM and man-oh-man has it been long. Two years in the making due to being taken on and off, on and off, and yet again on and off the project. Looking back. I wish I had either just rewritten the existing system, piece by piece at a time, or at least starting moving pieces one-by-one out via micro-services to a new backend. The front-end then could&#x27;ve been completed in a smaller rebuild.<p>Regardless, had we gone with a strangler approach, we probably would&#x27;ve been done months ago. As it stands, there is at least another week or two of development via QA break&#x2F;fixing until its ready to go live.<p>With that said, I still think there are times when a full rewrite makes sense. We redid our API two years ago when it was still small and I am happy we did the full rewrite. The old architecture just wouldn&#x27;t have been able to scale with where we are now and I felt the code was just too far gone to be helped.<p>As always, life is full of learning experiences.
评论 #19125807 未加载
评论 #19125333 未加载
weliketocode超过 6 年前
There&#x27;s already been tons of discussion here on HN about rewrites.<p>But, for the love of programming, please seriously consider this gradual rewrite&#x2F;strangler pattern&#x2F;whatever you want to call it over the often disastrous complete rewrite.
评论 #19125180 未加载
评论 #19124943 未加载
评论 #19127484 未加载
ajuc超过 6 年前
We&#x27;ve used this pattern in an warehouse management system in a company I worked for years ago.<p>Old version had almost all the logic in PL&#x2F;SQL, some Qt forms for high-level management, and C++ console apps (warehouse processes) running on portable terminals through telnet (so in reality these were running on the server, and portable clients were telneting to it to control it).<p>First we introduced XML-based protocol between C++ app and portable terminals, and a .net client running on these terminals to replace telnet. This allowed for a simple graphical interface instead of text-only, so there was a good motivation for customers to upgrade. Also it separated the parts clearly and allowed to mix and match new and old parts in the system.<p>Then we introduced J2EE application server, exposed the database through hibernate, and new processes were written in java (jbpm to be specific). They still used the same XML protocol and .net client, so old C++ processes could call java processes and vice-versa.<p>New processes required the possibility to call PL&#x2F;SQL logic so the features that were needed were exposed through J2EE services to the java processes.<p>Finally we added a way to write new management forms in Eclipse RCP.<p>We also planned on moving the logic from PL&#x2F;SQL to J2EE completely, and becoming database independent, but we never got to that.<p>The rewrite was never completed, there was a merger in the meantime, and we switched tech again, at which point most of the team left :)<p>But what we finished was working reliably, no features were lost, and as far as I know some customers still use the old system, some use both, some use the new system.<p>The thing that made it easy to do, but also hard to finish - was the logic in PL&#x2F;SQL. As long as we left that be it made moving everything else easy. But at the same time it was a constant temptation to just call the old PL&#x2F;SQL function instead of writing a new J2EE service, and finish the task at hand faster.
评论 #19125920 未加载
desc超过 6 年前
In the codebase I maintain, this boils down to a &#x27;gradual rewrite from the outside in&#x27; combined with refactoring bits of the &#x27;in&#x27; where practical. You create new independent code paths on the way &#x27;in&#x27; instead of trying to make the existing ones cope with yet another use case. These tend to highlight bits of existing core code which can be refactored as isolated and testable components, typically by copy-pasting them into a separate library and updating references piecemeal. Old code hangs around as long as it&#x27;s referenced, but new code doesn&#x27;t necessarily have to touch that copy.<p>Eventually the monolith&#x27;s trunk gets hollowed out as useful pieces become dependencyless libraries, and the tangled knot of rotting branches, vines, and strange green things with purple lumps starts to die back as a multitude of independent and healthy trunks grow from the surrounding earth.<p>At the risk of breaking the metaphor...
hnthrowaway919超过 6 年前
We opted for something similar when facing a technology pivot point in our front-end application. Instead of opting to re-write our entire application that had been built over the course of 3 years, we chose to integrate the replacement technology side-by-side with the original. This enabled us to add new features using the new technology as needed, along with allowing us to move old features over as we were able to. So far, I&#x27;m pretty happy with it. But, at some point, we will have to actively prioritize re-writing old content using the new technology, or else we&#x27;ll be stuck with this frankenstein forever.
评论 #19126502 未加载
jabart超过 6 年前
I&#x27;ve seen a team of 5 junior devs on an existing product outpace 10 senior devs on a team to replace that product from scratch for 3+ years.<p>A third team, of like 3 devs, made a proof of concept using the Strangler pattern and just a simple API to interact with the existing database within a year and took over the &quot;rewrite project&quot;.
评论 #19124453 未加载
评论 #19129474 未加载
CoolGuySteve超过 6 年前
That&#x27;s a pretty funny analogy considering the same tree appears to be the inspiration behind the design of the aptly-named &quot;Bed of Chaos&quot; from Dark Souls: <a href="https:&#x2F;&#x2F;66.media.tumblr.com&#x2F;02253f537ab15bd946d55cdb9b0b7b41&#x2F;tumblr_nzvs61E4LV1ukgbqco9_1280.jpg" rel="nofollow">https:&#x2F;&#x2F;66.media.tumblr.com&#x2F;02253f537ab15bd946d55cdb9b0b7b41...</a>
评论 #19126623 未加载
magoghm超过 6 年前
I think this is an insightful point of view: &quot;Let&#x27;s face it, all we are doing is writing tomorrow&#x27;s legacy software today.&quot;<p>Maybe we spend too much time trying to design flexible programs that can be easily updated to support new requirements (which, in my experience, usually ends up just being extra complexity which must be maintained and never allowed the extra flexibility it was supposed to deliver), and it might be wiser to sometimes think about software which is easy to replace.
评论 #19125817 未加载
mpweiher超过 6 年前
(2004)<p>Adopted a similar pattern recently on a project, results aren&#x27;t fully in yet, but it looks like it might work.<p>However, while I understand the reluctance about rewrites, in my personal experience they have actually been very successful.<p>So beware the absolutes. <i>Always</i> beware the absolutes ;-)
评论 #19124444 未加载
iandanforth超过 6 年前
&quot;We describe how a small, successful, self-selected XP team approached a seemingly intractable problem with panache, flair and im-modesty.&quot; - Abstract of the linked paper<p><a href="http:&#x2F;&#x2F;cdn.pols.co.uk&#x2F;papers&#x2F;agile-approach-to-legacy-systems.pdf" rel="nofollow">http:&#x2F;&#x2F;cdn.pols.co.uk&#x2F;papers&#x2F;agile-approach-to-legacy-system...</a>
csytan超过 6 年前
This pattern was taught to be by a former mentor, except he phrased it &quot;always be ready to ship&quot;. I used it to convert my app from rendered HTML + jQuery into a full fledged VueJS app + API. Much, much better than rewriting.<p>One more thing to add, is that a lot of software (e.g. SAAS) has users that depend on it. You want to make sure that your customers are happy through the transition.
tuukkah超过 6 年前
The link from &quot;Further reading&quot; was a great read too: <i>Legacy Application Strangulation: Case Studies (2013)</i><p><a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=19126939" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=19126939</a>
pm90超过 6 年前
Maybe a little OT but it seems a little surprising that this Man, Martin Fowler just observes nature and creates design patterns out of it. And of course once he writes an article everyone starts talking about it.<p>I&#x27;m not sure how I feel about it. The quality of his articles are generally pretty good. But it seems a little reckless (or perhaps foolhardy) for just one person to dictate all new design patterns.
评论 #19125042 未加载
评论 #19125365 未加载
评论 #19126162 未加载
curiousDog超过 6 年前
Isn’t this common sense though? How else would you re-write a complex, legacy system? But then again, I feel the same way about all virtues Martin Fowler extols.
评论 #19182641 未加载
评论 #19132823 未加载
Fib0112358超过 6 年前
god, that&#x27;s a terrible name