使用公认的反模式是否已被证明可以真正解决问题,或者以任何其他方式带来好处?

发布于 2024-08-13 09:38:04 字数 66 浏览 8 评论 0原文

使用公认的反模式是否已被证明在某些特定情况下确实有效?您是否曾经通过使用反模式在您的项目中解决过问题或获得过任何好处?

Has using an acknowledged anti-pattern ever been proven to actually work in a certain specific case? Did you ever solve a problem or gain any kind of benefit in one of your projects by using an anti-pattern?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

命硬 2024-08-20 09:38:04

我对“反模式”概念的理解是,它包含的解决方案具有只会在长期内显现出来的缺点。事实上,与其中许多相关的主要危险——比如编写带有大量全局变量和 goto 的意大利面条代码,或者将异常扔进空的 catch 块的黑洞中—— -它们之所以有吸引力,是因为它们为眼前的问题提供了权宜的解决方案。

编辑添加:因此,有时您确实可以从这些反模式中获益。有时候,你认为自己正在编写没人会再碰的一次性代码,这是完全错误的,你最终会遇到维护程序员诽谤你的传统和性卫生,但其他时候你是对的,那个与打包结合在一起的蹩脚 shell 脚本电线和吐痰完成了您想要完成的工作,然后幸运地被遗忘,为您节省了相当多的时间和精力来组装一些像样的东西。

My understanding of the "anti-pattern" concept is that it encompasses solutions that have drawbacks that only reveal themselves over the long term. Indeed, the primary danger associated with a lot of them---like writing spaghetti code with loads of global variables and gotos every which way, or tossing exceptions into the black hole of an empty catch block---is that they're seductive because they provide an expedient solution to an immediate problem.

EDIT to add: Because of that, sometimes you do derive benefit from these anti-patterns. Sometimes your calculation that you're writing throwaway code that no one will touch again is dead wrong and you wind up with maintenance programmers slandering your heritage and sexual hygiene, but other times you're right and that crummy shell script that's held together with baling wire and spit does the job you intended it to do and is then blessedly forgotten, saving you the considerable time and effort of putting together something decent.

汹涌人海 2024-08-20 09:38:04

反模式仍然如此广泛,只是因为它们解决了一个特定的问题(同时创建了 10 个新问题)。也称为解决方法。但他们怎么说呢?没有什么比临时搭建的东西更持久。

事实上,我相信,如果事情从一开始就做对了,我们都会失业。

Anti-Patterns are still so widely around just because they solve a particular problem (while creating 10 new ones). Also known as workaround. But how do they say? Nothing lasts longer than a makeshift.

In fact I believe we'd all be jobless if things had been done right from the beginning.

云归处 2024-08-20 09:38:04

根据我的经验,它解决的最大问题是启动新应用程序。

当开发团队彻底确定新应用程序的范围后,实施正确解决方案的时间表通常会让管理层难以承受。因此,通常,您编码是为了满足时间表,而不是解决方案的“正确性”以达到发布日期(但让其他人为下一个版本编码“正确”的解决方案),这使得它本质上是“扔掉”代码。

The biggest problem that it has solved in my experience is launching a new application.

When the dev team has scoped the new application thouroughly, the timeline to implement the correct solution is usually too much for management to bear. Therefore, oftentimes, you code to meet the timeline, rather than "correctness" of the solution to get to the launch date, (but have others coding the "correct" solution for the next rev), making it essentially "throw-away" code.

温柔戏命师 2024-08-20 09:38:04

一种软件反模式是 Softcoding,也在 每日 WTF。当程序员将“应该”位于代码内部的材料放入外部资源时,就会发生软编码。

我正在使用的软件可能会受到软编码的影响。外部文件驱动软件。这些外部文件是一种微语言:必须先将它们编译为 XML,然后软件才能使用它们。这种微语言有自己的工具。

但软编码总是取决于情人的想法。

使用带有自己的解析器的微语言提供的材料让我的生活变得更轻松。一个数据源可以生成许多不同的输出:除了主程序使用的版本之外,我还能够将信息提取为 HTML、.csv 和客户想要的其他格式。其他程序可以用微语言生成代码,使自动化变得更容易。

在我们的例子中,软编码是一种有用的模式,而不是反模式。

One software anti-pattern is Softcoding, also defined at the daily WTF. Softcoding happens when programmers put material that "should be" inside code into external resources.

I'm working with software that some might say is suffering from softcoding. External files drive the software. Those external files are a micro-language: they must be compiled to XML before the software can use them. This micro-language has its own tools.

But softcoding is always in the mind of the beholder.

Having the material in a micro-language with its own parser has made my life easier. One data source can generate many different outputs: In addition to the version that the main program uses, I am able to extract information into HTML, .csv, and other formats that our customers want. Other programs can generate code in the micro-language, making automation easier.

In our case, softcoding has been a useful pattern, not an anti-pattern.

夜雨飘雪 2024-08-20 09:38:04

将其称为模式而不是法则是有原因的。

我猜想,几乎每个人都至少有一个例子,说明代码中的某个位置确实做了错误的事情,但从长远来看,它的结果比“正确”的事情要好。

还有更长的反模式造成麻烦的例子列表。

出于无知或懒惰,我曾多次使用过魔法按钮,有时它实际上效果很好,而且事实证明我不需要适当的 MVC 的额外抽象。

There is a reason for calling it a pattern rather than a law.

I would surmise that almost everyone has at least one example of a place in code where exactly the wrong thing was done, and it turned out better in the long term than the "right" thing would have.

And a far longer list of examples of anti-patterns causing trouble.

I have used magic pushbuttons a number of times, out of ignorance or laziness, and sometimes it actually worked out just fine, and it turned out that I did not need the extra abstraction of proper MVC.

落叶缤纷 2024-08-20 09:38:04

Duff 的设备利用循环切换序列(又名For-Case Paradigm)反模式。

Duff's Device utilizes the Loop-Switch Sequence (AKA For-Case Paradigm) anti-pattern.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文