为什么 eclipse-python 没有神奇的重构?
Eclipse 能够利用编译的字节码来启用“神奇重构”功能——重命名方法、向上和向下跟踪类层次结构以及通过方法调用进行跟踪。
存在哪些技术障碍使得 Python 和 Javascript 等语言更难做到这一点?
Eclipse is able to utilize compiled bytecode to enable "magic refactor" functionality--renaming methods, tracing up and down class hierarchies and tracing through method calls.
What technical barriers exist that make this harder to do for languages like Python and Javascript?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因为动态绑定。 Python 是一种动态语言,您可以用变量做几乎所有事情。您甚至可以访问全局字典并引入由运行时值组成的新变量。
因此 IDE 无法确定哪些变量何时存在。看这个例子:
没有人或IDE可以知道
thisNowExists
是否在位置#1
定义,所以如果你想重命名愚蠢的命名thisNowExists
> 低于该点,我们是否也应该重命名#1
之前的外观是未定义的。您必须进行高级控制流分析才能很好地猜测
thisNowExists
是在 try/catch 语句下面定义的,但由于脚本的动态加载 (thisNowExists = 1; import实
)并排序,它甚至可以在不带参数的import sys
之前存在。以不同的方式命名你的变量,查找/替换是你最好的选择;)
Because of dynamic binding. Python is a dynamic language in a way that you can do almost everything with your variables. You can even access the globals-dict and introduce new variables composed of runtime values.
So an IDE can’t be sure which variables exist when. See this example:
No human or IDE can know if
thisNowExists
is defined at the position#1
, so if you want to rename the stupidly namedthisNowExists
below that point, it is undefined if we should rename the appearance before#1
, too.You would have to do advanced control flow analysis to take a good guess that
thisNowExists
is defined below the try/catch statement, but due to dynamic loading of the script (thisNowExists = 1; import silly
) and sorts, it could even exist beforeimport sys
without arguments.naming your variables differently and find/replace is your best option ;)
所以事实证明,在 python 中跟踪方法和类层次结构等静态信息是完全可能的。 PyDev eclipse 插件可以做到这一点。 PyLint 插件尝试对动态变量之类的东西进行静态分析,假设运行时没有发生任何奇怪的事情,并且做得相当不错。
so it turns out that tracing of static information like methods and class hierarchies is perfectly possible in python. PyDev eclipse plugin does it. PyLint plugin attempts to do static analysis even on stuff like dynamic variables by assuming that nothing funky happens at runtime and does a pretty good job.