了解别人的代码的工具和最佳做法 [英] Tools and best practices to understand somebody else's code

查看:117
本文介绍了了解别人的代码的工具和最佳做法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时候,有人需要挖掘别人的代码,理解它,并且可以重构/修复它。所以我想知道你使用哪些工具/做法?这不是关于任何特定的语言或平台,而是一般的建议。

我自己觉得在调试器下运行有问题的代码非常有用(如果可能的话),设置断点和逐步执行代码。

此外,我已经使用了一些具有逆向工程功能的UML工具来看大图。可视化对我来说效果很好。

有一个工具,我已经使用了一些:了解。它不是一个UML工具,但它有一堆可视化的代码。例如,一个功能的控制流程图,它不是UML的一部分,但有时它非常有用。

我听说有时人们会为他们想要学习的代码编写测试,一直在为我工作有时我想要理解的代码不是很可测试。

还有其他工具,如分析器,依赖检查器,记录器等。有没有人可以使用它成功?怎么样?

首先使用什么开始?下一步是什么?

解决方案

我以前一直处于这种状况...这不是很有趣。我找到的最好的方法是编写单元测试来覆盖将要更改的区域。即使测试已经存在,这样可以让您体验到您打算重构的代码的api和行为。此外,您还可以获得更多测试来验证替换实施。


Sometimes one needs to dig into someone else's code, understand it and maybe refactor/fix it. So I'm wondering what tools/practices do you use to do that? It's not about any specific language or platform, rather some advises in general.
I myself find it very useful to run the code in question under debugger (if it is possible of course), set breakpoints and step through the code.
Also I've used a few UML tools with reverse engineering features to see the big picture. Visualization works pretty well for me.
There's one tool, that I've used quite a bit: Understand. It's not a UML tool, but it has a bunch of visualizations for the code. For instance control flow diagram for a function, which is not part of UML, but sometimes it's very useful.
I've heard that sometimes people write tests for the code they want to learn, but it hasn't been working for me. Sometimes the code I want to understand is not very testable.
There are other tools, like profilers, dependency checkers, loggers etc. Does anybody use it with any success? And how?
What the first thing use start with? What's the next?

解决方案

I have been in this situation before... It's not much fun. The best way I've found is to write unit-tests to cover the areas that are going to change. Even if tests already exist, this gives you experience with both the api and behavior of the code you intend to refactor. Additionally, you gain more tests to verify the replacement implementation.

这篇关于了解别人的代码的工具和最佳做法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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