抗癌网,内容丰富有趣,生活中的好帮手!
抗癌网 > 癌症新知和癌症真相的区别_旧版代码是癌症

癌症新知和癌症真相的区别_旧版代码是癌症

时间:2019-12-12 12:14:17

相关推荐

癌症新知和癌症真相的区别_旧版代码是癌症

癌症新知和癌症真相的区别

It’s far too often that I see people shying away from newest technologies in the spirit of backwards compatibility. “We can’t move the minimum PHP requirement to 5.5 because we have 50% of our users on 5.4 still!”, they say. “There’s no way for us to move to Guzzle 4+, our back end is built on version 3 and it would take too much time and money”. I like the common argument from WordPress the best: “We can’t go full OOP and logic/presentation decoupling, because most of our users are running shared hosts with PHP 5.1 or don’t know OOP and/or MVC”.

我经常看到人们本着向后兼容的精神回避最新技术。 他们说:“我们无法将PHP的最低要求提高到5.5,因为我们仍然有50%的用户使用5.4!” “我们无法转移到Guzzle 4+,我们的后端是基于版本3构建的,这将花费太多时间和金钱。” 我最喜欢WordPress的常见论点:“我们不能进行完整的OOP和逻辑/表示分离,因为我们的大多数用户都在使用PHP 5.1运行共享主机,或者不知道OOP和/或MVC。”

Nonsense.

废话。

旧版代码–重大问题 (Legacy Code – a big NO)

This might come out controversial, but I firmly believe there is no room for legacy code in modern systems. Allow me to elaborate before you sharpen your pitchfork and light your torch. What I mean by that is: there should be absolutelyzeroreason to keep implementing the functions you’re adding to the new version retroactively into the old version, just because some people are still using it, even if the people using it are a vast majority.

这可能会引起争议,但我坚信现代系统中没有留有遗留代码的空间。 在您削尖干草叉和点燃火炬之前,请允许我详细说明。 我的意思是:绝对有零个理由要继续将要添加到新版本中的功能追溯地实现到旧版本中,即使有些人仍在使用它,即使使用它的人很多多数。

To clarify: bugfixing legacy versions until their long term support contract runs out or you feel like it if you’re in charge, yes. Adding new features you think up for version X into version X-1 in order not to make the X-1 users mad, absolutely and 100% not. Likewise, adding X-1 code into version X just because it can “serve the purpose” should be illegal. If you’re still charging people for X-1 and basing your upgrades on that, your business plan is bad and you should feel bad.

澄清一下:在旧版本的长期支持合同到期之前进行错误修复,或者如果您负责的话,您会觉得很不错,是的。 为X-1版本添加您认为适用于X版本的新功能,以免使X-1用户发狂,绝对不会,而且100%不会。 同样,将X-1代码添加到版本X中仅仅是因为它可以“达到目的”,这也是非法的。 如果您仍在向X-1收取费用并以此为基础进行升级,则您的业务计划很糟糕,您应该会感到很糟糕。

Who am I to spout such nonsense, though, right? I’ve never had to maintain a large project with stakeholders and boards to please, a project that moves super slow and makes everyone happy as long as it works, no matter the fact that it could, potentially, work 100 times safer and 1000 times faster, right? Not exactly. My biggest baby was a big publisher site with a complex back end, built on ZF1. If you’ve ever done anything in ZF1, you know what a vortex of painful antipatterns it is. When the application started showing signs of deterioration due to increased traffic, I rebuilt the front end of the back end (the most heavily used part of the app) in its entirety on an ajax interface and API calls, lightening the load drastically and buying enough time to rebuild the entire suite of applications we had on the only thing the higher ups allowed – Zend Framework 2. If you’ve done anything onthat, you know it’s a slightly less dense vortex of antipatterns, but still a vortex of antipatterns and bloat – but what I’m trying to say here is – huge upgrades and total rewrites can happen, if capable people are behind them. If all you’re doing are agile meetings and brainstorming, there’s no amount of LTS contracts that can stop you from looking stupid in five years.

可是,我该向谁撒谎呢? 我从来不需要与利益相关者和董事会一起维护一个大型项目,这个项目运行速度极慢,只要它可以正常工作,每个人都会感到高兴,无论它可能会安全地工作100倍,也可能工作1000倍更快吧? 不完全是。 我最大的宝贝是建立在ZF1上,后端复杂的大型发布商网站。 如果您曾经在ZF1中做过任何事情,您就会知道它是痛苦的反模式的漩涡。 当应用程序开始显示由于流量增加而导致性能下降的迹象时,我在ajax接口和API调用上完全重建了后端的前端(该应用程序中使用最频繁的部分),从而大大减轻了负载并购买了足够的东西是时候重建整个应用程序套件了,唯一允许更高版本的东西是Zend Framework2。如果您对此进行了任何操作,您就会知道它是反模式的密度稍低的旋涡,但是仍然是反模式的涡旋和肿-但我想在这里说的是-如果有能力的人支持,那么可能会发生大规模的升级和全面的重写。 如果您要做的只是敏捷的会议和头脑风暴,那么没有多少LTS合同可以阻止您五年内变得愚蠢。

Even if you’re doing free and/or open source work, you shouldn’t break your back for X-1 users, because you’re only doing them a favor by doing a major version increment, and with it, a major upgrade with a potential BC break. They should either adapt, or wither away.

即使您从事免费和/或开源工作,也不应为X-1用户退缩,因为您只是通过主要版本增加以及主要升级来帮他们一个忙。可能会导致BC中断。 他们要么适应,要么枯萎。

So why should we exile legacy code from modern systems?

那么,为什么我们要从现代系统中流走遗留代码呢?

永无止境的LTS诅咒 (The Neverending LTS Curse)

By taking the “support everything for as long as we can” approach, you’re burying yourself in a bottomless pit and looking at stretching yourself so thin several years down the line when you find yourself having to maintain four different versions, you’ll be banging your head into the wall wondering why you didn’t cut the V1 and V2 users loose when you still could have. In an attempt to maintain a bigger audience, developers often go out of their way to help users of past versions, for the sole purpose of keeping them around. This is also why WordPress is, in its current state, such an unfixable mess of amateur code. Don’t let yourself get chained to old versions.

通过采取“在可能的情况下尽一切可能提供支持”的方法,您将自己埋在了一个无底洞中,并且当您发现自己必须维护四个不同的版本时,希望将自己拉得这么薄,直到几年之后。想着为什么不把V1和V2用户放宽了却仍然不满意。 为了保持更大的受众,开发人员通常会竭尽全力为过去版本的用户提供帮助,其唯一目的就是保持他们的周围。 这也是为什么WordPress在目前的状态下无法解决的业余代码问题。 不要让自己束缚于旧版本。

These users are dead weight and should be discarded, no matter how much money they bring you. Give them methods of transition and move on – if they’re in any way capable, they’ll catch up in no time. If not, they’re not worth it.

这些使用者很重,无论带给您多少金钱,都应丢弃。 给他们过渡的方法并继续前进-如果他们有任何能力,他们将立即赶上。 如果没有,那是不值得的。

By supporting older versions for too long, you enter the WP curse in which older versions, versions so bad they’re cringeworthy, require ever more manpower and effort to fix. This manpower is better spent building new versions and hiring developer advocates to help users transition.

通过长时间支持较旧的版本,您将进入WP诅咒,在该诅咒中,较旧的版本(非常糟糕以至于不能令人信服)需要更多的人力和精力进行修复。 最好将人力用于构建新版本,并聘请开发人员倡导者来帮助用户过渡。

您正在疏远和负面影响高级用户 (You’re alienating and negatively affecting advanced users)

The last time this desperate legacy grabbing affected me directly was while installing a CMS that proved particularly difficult to install in a Vagrant environment – not only due to symlink issues which are, by now, widely known (even to the creator of Vagrant), but due to them including a legacy version of the CMS inside the main CMS, because they share some installation properties, and the back end wasn’t fully rewritten into the new version yet. Why move onto a new version at all then? Why rush things if you’re clearly so far from ready?

上次这种绝望的遗留问题直接影响了我,当时是在安装CMS时 ,事实证明, 在CMS上安装它在Vagrant环境中尤为困难-不仅是由于符号链接问题已经广为人知(甚至是Vagrant的创建者),而且由于它们在主CMS中包含CMS的旧版,因为它们共享一些安装属性,并且后端尚未完全重写为新版本。 为什么要继续使用新版本? 如果您显然还没准备好,为什么还要着急呢?

By rushing the new version, they ended up with a sort of hybrid that’s neither here nor there – a Frankenstein’s monster of legacy code that still kind of works, but badly, and new code that has potential but cannot reach it without the mess that is the legacy code. While this approach does make the job of development companies who are still stuck in the 1990s easier, it makes the job of advanced users much, much harder. By catering to a crowd that should, by all logic, be extinct, you’re alienating and negatively affecting advanced users even more.

通过推出新版本,他们最终得到了一种既不存在又不存在的混合体-科学怪人的遗留代码怪兽仍然可以工作,但是很糟糕,并且新代码具有潜力,但如果没有混乱就无法实现旧版代码。 虽然这种方法确实使仍陷于1990年代的开发公司的工作变得容易,但它使高级用户的工作变得困难得多。 通过迎合应该完全灭绝的人群,您正在疏远和进一步影响高级用户。

You know how it goes: don’t waste too much time trying to do the little details in legacy browsers. Nobody using those browsers will notice anyway. The same applies for users of libraries or content management systems – those who care about the legacy system won’t care about what you’re introducing into the new one, so you shouldn’t sweat blood over them more than necessary.

您知道这是怎么回事:不要在传统浏览器中花太多时间尝试做一些小细节。 无论如何,使用这些浏览器的人都不会注意到。 这同样适用于图书馆或内容管理系统的用户-那些关心旧系统的人不会关心您在新系统中引入的内容,因此,您不应在不必要的情况下流血。

失败有时会带来成功 (Failure sometimes ushers success)

Of course, sometimes it just isn’t possible, and these exceptions are rare and valuable learning materials. One curious case of versioning and BC breaks is Python. Python is an awesome language. You can build almost anything in it. It won’t work as well as it could in a language built for that purpose, but that’s the nature of jack-of-all-trades types – they can do anything very well, just nothing flawlessly. When Python 3 came around, it introduced some BC breaks, preventing Python 2 users from a simple transition.

当然,有时候这是不可能的,并且这些例外是稀有且有价值的学习资料。 Python是版本控制和BC中断的一个奇怪案例。 Python是一种很棒的语言。 您几乎可以在其中构建任何东西。 用为此目的构建的语言无法很好地工作,但这就是万事通类型的本质-他们可以做的很好,只有完美无瑕。 当Python 3出现时,它引入了一些BC中断,从而阻止了Python 2用户进行简单的过渡。

Most excuses were “There aren’t enough Py3 packages out there yet” and “We have too much code in Py2 to rewrite it all” – to which I say “Build what you need yourself” and “Poor programmers, being forced to program and all”, respectively. Granted, there were some valid arguments, and those tend to show up in projects that are so absurdly large, but the Py2 vs Py3 issue actually resulted in something else – the “Python Rift”. By the time Python 4 rolls around, the people who so vehemently refused to transition to version 3+ will still be stuck in Python 2 and the BC shift will become even greater for them. At that point, they might as well try and learn a new language. On the other hand, those who “braved the rift” and upgraded to 3+ without much hesitation, rewriting crucial modules themselves and adapting the language to their needs instead of the other way around will have a much easier time transitioning to newer versions.

大多数借口是“目前还没有足够的Py3软件包”和“我们在Py2中有太多代码无法全部重写” –我要说的是“构建自己需要的东西”和“可怜的程序员,被迫编程和所有”。 当然,有一些有效的论据 ,而且这些论点往往会出现在如此荒谬的大型项目中,但是Py2 vs Py3问题实际上导致了其他一些问题–“ Python Rift”。 到Python 4发行时,如此强烈地拒绝过渡到3+版本的人仍将陷在Python 2中,BC转变对他们来说将变得更大。 在那时,他们不妨尝试学习一种新的语言。 另一方面,那些毫不犹豫地“勇敢面对”并升级到3+,自己重写关键模块并根据自己的需要调整语言的人,则可以很容易地过渡到较新的版本。

This BC break effectively cut off the lazy and prepared the Python landscape for a new generation of developers. In my mind, that’s a success ushered by a version bump failure. Programming, like so many other walks of life, is still based on survival of the fittest – and if you can’t consume new technologies adequately, get out of the way for those who can.

这次BC中断有效地消除了懒惰,并为新一代开发人员准备了Python格局。 在我看来,这是版本颠簸失败带来的成功。 像许多其他行业一样,编程仍然以优胜劣汰为基础-如果您不能充分使用新技术,则可以为那些有能力的人摆脱困境。

应用程序与库/包 (Applications vs Libraries/Packages)

There’s also the questions of apps vs libs. In other words, should the “no legacy” rule apply both to applications depending on, for example, frameworks that get a new release, or should this only apply to libraries in that they should cut ties with previous versions when new ones show up?

还有应用与库的问题。 换句话说,“无遗留”规则是否应同时适用于依赖于例如获得新版本的框架的应用程序,还是应该仅适用于库,因为它们应在新版本出现时与先前版本保持联系?

Both, in a way.

两者都在某种程度上。

Libraries that get a version bump to X+1 should follow the clear path to progress – from the moment you have a publicly available new version, maintain a bugfix-only approach on the last one.

使版本升至X + 1的库应遵循清晰的进度-从您拥有公开可用的新版本之时起,在最后一个版本上保留仅错误修正的方法。

Applications that use such libraries are in a more difficult situation due to their logic depending on the APIs that may have changed. The sensible approach is to wait for stability reports from the community and, when verified, to begin the transition. During the transition period, both the old and the new version of the library/framework can remain in use, and once all necessary parts have been upgraded, the old version should be scrapped. Doesn’t this take a long time, though?

使用此类库的应用程序由于其逻辑取决于可能已更改的API而处于更加困难的情况。 明智的方法是等待社区的稳定性报告,并在经过验证后开始过渡。 在过渡期间,旧版本和新版本的库/框架都可以继续使用,并且一旦所有必需的部件都已升级,则应废弃旧版本。 不过,这需要很长时间吗?

没有足够大的网络应用 (There is no web app big enough)

“But Bruno, some apps are huge and would take months to be rewritten”, you might say. “Transitioning from ZF1 to ZF2 is a year’s work!”, to which I say: nonsense. There is no web application big enough to warrant that timeframe. In fact, I’ll go one step further and say that there’s no web application big enough to ever warrant using a big framework like Symfony or Zend.

您可能会说:“但是,布鲁诺,某些应用程序非常庞大,需要几个月才能被重写”。 “从ZF1到ZF2的过渡是一年的工作!”我要说的是:胡说八道。 没有足够大的Web应用程序可以保证该时间范围。 实际上,我将进一步说,没有足够大的Web应用程序足以保证使用Symfony或Zend之类的大型框架。

No disrespect to either of those frameworks, they’re hyper complex behemoths of mostly professional code, but if you follow best practices, respect separation of concerns, encapsulate your services and APIfy your application so you can write front ends completely separate from back ends, there is absolutely nothing stopping you from doing full rewrites in under a month, regardless of the app’s size and/or popularity – provided your team mates are coders, and not theoreticians. It doesn’t matter how many patterns and algorithms you know about – you need to know how to use them to be effective enough to do transitions.

不管这些框架是什么,它们都是大多数专业代码的超级复杂庞然大物,但是如果您遵循最佳实践,尊重关注点分离,封装服务和APIfy应用程序,则可以将前端与后端完全分开,不论应用程序的大小和/或受欢迎程度如何,绝对都不会阻止您在一个月内进行完全重写-前提是您的队友是编码员,而不是理论家。 知道多少模式和算法都没关系–您需要知道如何使用它们才能有效地完成转换。

升级方案 (Upgrade Scheme)

Which upgrade scheme should one use then? There is only one acceptable upgrade scheme any software developer should ever use, regardless of app/lib popularity:

那么应该使用哪种升级方案? 无论app / lib的受欢迎程度如何,任何软件开发人员都只能使用一种可接受的升级方案:

Introduce new branch for new version为新版本引入新分支 Mark the old version/branch as deprecated将旧版本/分支标记为已弃用 Publicly state how much life the old version has left公开说明旧版本还剩下多少生命 Issue warning to all users of the old version向所有旧版本的用户发出警告 Implement new features in the new branch ONLY, bugfix the old branch/version仅在新分支中实现新功能,错误修正旧分支/版本 When EOL for old version, cut all ties. Don’t bugfix, don’t consult, don’t even reference it in docs. Kill it.当EOL为旧版本时,请断开所有联系。 不要修正错误,不要咨询,甚至不要在文档中引用它。 杀死它。

That’s it – following this procedure will let you never get into legacy trouble.

就是这样–按照此步骤进行操作,将永远不会给您带来麻烦。

One project that adopted this approach in a way is Guzzle. They have a 3+ version, a 4+ version for those who can get with the rapid development of the 21st century, and a bleeding edge version for the daredevils who want the latest and greatest upgrades at all times.

一个在某种程度上采用了这种方法的项目是Guzzle 。 他们提供3+版本,适合21世纪快速发展的用户使用4+版本,也适合那些希望随时获得最新,最大升级的敢死队。

结论 (Conclusion)

As a web developer, I firmly believe legacy code should be abandoned in regards to new features on major version shifts. If you have a large project depending on software that’s moved up a version more than two months ago, you should stop all operations and rewrite everything to respect the new version –especiallyif the software you’re using is business critical. There is no application in the world big enough to need more than two months for a full transition, and if there is, it should be scrapped and written from scratch – the web is much simpler than all of us let on.

作为一名Web开发人员,我坚信应该在主要版本转换中放弃有关旧功能的旧代码。 如果您有一个大型项目,取决于两个月前升级了某个版本的软件,则应停止所有操作并重写所有内容以遵守新版本-特别是在使用的软件对业务至关重要的情况下。 世界上没有足够大的应用程序需要两个月以上的时间才能进行完整过渡,如果有,则应从头开始进行报废和编写–网络比我们所有人都容易得多。

What do you think? Should legacy code be kept around indefinitely? A specific number of versions? Not at all? How do you feel about legacy code in third party projects used by a major project versus legacy code of those third party projects themselves? Do you feel there should be a difference in how either of those handles outdated code? Am I dead wrong here on all accounts? I’d love to have a good discussion about this – after all, my views and experiences are, obviously, my own. Let us know in the comments below.

你怎么看? 是否应将旧代码无限期保留? 特定数量的版本? 一点也不? 您如何看待大型项目使用的第三方项目中的遗留代码与那些第三方项目本身的遗留代码? 您是否认为这两种处理过时的代码的方式应该有所不同? 我在所有帐户上都错了吗? 我很乐意就此进行讨论-毕竟,我的观点和经验显然是我自己的。 在下面的评论中让我们知道。

翻译自: /legacy-code-cancer/

癌症新知和癌症真相的区别

如果觉得《癌症新知和癌症真相的区别_旧版代码是癌症》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。