理解面向对象代码的工具和方法
在我的工作/学习中,我必须查看、理解和修改以面向对象风格编写的、几乎没有文档的重要代码。就我而言,这些是 C++ 架构模拟器。
我想向更有经验的人了解查看和理解现有项目的一些更有效的方法。这是一个开放式问题,也许我无法正确表达我的意思,但这对我来说是一个重要的问题。每次我必须修改模拟器或其他工具时,我都会花费大量时间来理解流程。我正在努力使这个过程更高效、更省时。
是否有工具可以获取代码库并生成有用的图表表示(例如 UML 图)?在分析代码时是否有任何对您有用的特定技术?
In my work / study, I have had to look at, understand, and modify non-trivial code written in an object-oriented style, with little documentation. For my case these are architectural simulators in C++.
I would like to know from more experienced people about what are some of the more efficient ways to look at and understand an existing project. This is an open-ended question, and maybe I am not being able to express properly what I mean, but this is an important issue for me. Every time I have to modify a simulator or some other tool, I spend quite a lot of time struggling with understanding the flow. I am trying to make this process more efficient and less time-consuming.
Are there tools that can take a code base and generate a useful diagram representation like UML diagrams? Also are there any specific techniques that has been useful to you while analyzing code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您拥有的可能性之一是 doxygen
On of the possibilities you have is doxygen
此维基百科页面提供了一个不错的工具列表,您可能会觉得有用。我自己也很喜欢 cpplint。
This Wikipedia page gives a decent list of tools that you may find helpful. I'm fond of cpplint, myself.
如果我处于你的情况,我要做的第一件事就是尝试找到原作者。作者对代码的理解将比仅仅阅读(假设的)注释所获得的要好得多。
如果找不到原作者,那么答案取决于您想用代码做什么。
如果您想添加一些代码,那么最好的选择就是坐下来强迫自己理解设计的结构。如果不这样做,那么您添加的任何代码都可能不太适合整体结构。
要理解设计,您需要阅读大量代码。我认为没有一个简单的方法可以解决这个问题(除非代码设计和结构异常良好)。当你阅读更多的代码时,你没有读过的代码会变得更容易理解。您将能够重新利用您对设计中使用的组件和模式的理解,以快速了解特定部件的功能。
祝你好运!
If I was in your situation the first thing I would do would be to attempt to track down the original author. The author will have a far better understanding of the code than what you could get from just reading the (hypothetical) comments.
If the original author cannot be found then the answer depends on what you want to do with the code.
If you want to add some code, then your best bet is to sit down and force yourself to understand the structure of the design. If you do not, then any code that you add is likely to fit very poorly into the overall structure.
To understand the design you will need to read a lot of code. I do not think there is an easy way around it (unless the code is unusually well designed and structured). As you read more code the code that you have not read will become easier to understand. You will be able to reuse you understanding of the components and patterns used in the design to quickly understand what a particular part is doing.
Good Luck!