旋转设计和粘度

发布于 2024-07-22 00:52:48 字数 86 浏览 5 评论 0原文

罗伯特·C·马丁 (Robert C. Martin) 在他的一本书中提到粘度是设计腐烂的症状。 我不完全理解软件开发中的粘度概念。 你能给我一些例子吗?

Robert C. Martin in one of his book mention about viscosity as a symptom of rotting design. I don't fully understand idea of viscosity in software development.
Could you give me some examples?

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

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

发布评论

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

评论(3

梦情居士 2024-07-29 00:52:48

随着代码变得越来越旧,它会变得更加充满黑客攻击,并且更加充满依赖关系,因此在不破坏某些内容的情况下进行更改变得更加困难。

因此它变得更少“流体”和更多“固体”,因此类似于粘度。

As code gets older, it gets more full of hacks, and more full of dependencies, and consequently gets harder to change without breaking something.

So it gets less "fluid" and more "solid", hence the analogy to viscosity.

白色秋天 2024-07-29 00:52:48

粘度是液体抵抗外力变化的能力。 水是该测量的基础,并且具有非常低的粘度(即,它会在给定路径下从一个地方自由流动到另一个地方),而酸奶在冷却时具有如此高的粘度,几乎是固体且漂亮很多东西都会留在你放置的地方(除非你穿着浅色裤子,在这种情况下它每次都会找到那里......)。

在软件中,这意味着您的代码抵抗更改的程度。 如果您有很多依赖项,那么更改主要类可能会很困难,从而导致不太理想的解决方法,从而增加代码的阻力(增加其粘度)。 精心设计的代码(低粘度)可以更新和添加,而不会对应用程序或依赖它的其他类产生重大影响。

Viscosity is the ability of a liquid to resist changes from external forces. Water is the basis for the measure and has a very low viscosity (i.e. it will flow freely from one place to another given a path), while, say, yogurt which has such a high viscosity when chilled that it is almost a solid and pretty much stays where you put it (unless you are wearing light colored pants in which case it finds its way there every time...).

In software, this translates to how much your code resists changes. If you have a lot of dependencies, then it can be difficult to alter a major class, thus leading to less-than-ideal workarounds which in turn increase the code's resistance (increasing its viscosity). Well designed code (low viscosity) can be updated and added to without having a major impact on applications or other classes which depend on it.

顾忌 2024-07-29 00:52:48

他有两个用途,设计粘性和环境粘性。

首先,牙膏和花生酱等高粘度流体流动不如水等低粘度流体顺畅。

高粘度设计使得修改比保留设计更容易。 黑客行为使代码变得更加僵化,进一步增加了粘度。

环境粘度是指工作流程。 如果编译时间很长,或者构建系统或运行测试很痛苦,程序员就会采取捷径来减轻痛苦。

He has two uses, viscosity of design and viscosity of environment.

First, fluids with high viscosity, like toothpaste and peanut butter, don't flow as smoothly as low-viscosity fluids like water.

High-viscosity design makes it easier to make a hack than to preserve the design. The hack makes the code even more rigid, increasing the viscosity even further.

Viscosity of environment refers to work flow. If compile times are long, or it's a pain to build the system or run the tests, programmers will take shortcuts to ease the pain.

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