寻找猴子修补有什么问题的具体示例吗? [英] Looking for a concrete example of what's wrong with monkey patching?

查看:87
本文介绍了寻找猴子修补有什么问题的具体示例吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听到了很多关于猴子打补丁多么酷或猴子打补丁是地球上最糟糕的事情的信息.我的想法是,如果您编写一些代码然后又有人更改其功能来执行其他操作,那将是不好的.但我正在寻找一个具体的例子,说明这种情况可能确实会伤害您.我的意思是,我一直都在编写代码,然后我的同事对其进行更改.那么,猴子补丁与此有何不同? 最糟糕的情况是什么?

I've heard a lot of oohs and aahs about how monkey patching is so cool or monkey patching is the worst thing on earth. I have the idea that it's not good if you write some code and then someone else changes its functionality to do something else. But I'm looking for a concrete example of a situation where this could really hurt you. I mean, I write code all the time and then my coworkers make changes to it. So, how is monkey patching any different from that? What's the worst that could happen?

推荐答案

编程已经缓慢而稳定地摆脱了需要理解全局状态才能理解局部行为的编码实践.一些示例:

Programming has had a slow but steady movement away from coding practices that require understanding global state to understand local behavior. Some examples:

  • Gotos使得推理流程变得更加困难,因为您可能需要查看一下 远处的代码,以了解如何到达特定的行.
  • 还不赞成使用全局变量,因为程序的任何部分都可以更改影响其他任何部分的状态.
  • 支持函数式编程,因为它意味着您无需担心函数外部的任何状态即可了解其行为.
  • Gotos make it harder to reason about the flow of control because you may need to look at code far away to see how you get to a particular line.
  • Global variables are also frowned upon because any part of your program can change state that affects any other part.
  • Functional programming is supported because it means you don't need to worry about any state outside of your function to understand how it behaves.

猴子修补程序意味着,如果不查看程序中的所有其他代码行,就无法知道代码行的功能.快速完成某件事可能很有用,但是它将使大型程序变得难以理解.由于许多大型程序都是从小型程序开始的,因此猴子修补可能是您要摆脱的习惯.

Monkey patching means that there is no way to know what a line of code does without looking at every other line of code in the program. It might be useful to get something done quickly, but it will make large programs impossible to understand. Since so many large programs start as small programs, monkey patching is probably a habit you want to get out of.

这篇关于寻找猴子修补有什么问题的具体示例吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆