如何开始修改大项目

时间:2023-01-31 22:55:36


I have to do enhancements to an existing C++ project with above 100k lines of code.
My question is How and where to start with such projects ?
The problem increases further if the code is not well documented. Are there any automated tools for studying code flow with large projects?

我必须使用超过100k行代码对现有C ++项目进行增强。我的问题是如何以及从何处开始这些项目?如果代码没有很好地记录,问题会进一步增加。是否有任何自动化工具可用于研究大型项目的代码流?

Thanx,

10 个解决方案

#1


There's a book for you: Working Effectively with Legacy Code

有一本书适合您:有效地使用遗留代码

It's not about tools, but about various approaches, processes and techniques you can use to better understand and make changes to the code. It is even written from a mostly C++ perspective.

它不是关于工具,而是关于可以用来更好地理解和更改代码的各种方法,过程和技术。它甚至是从C ++的角度编写的。

#2


Use Source Control before you touch anything!

在触摸任何东西之前使用Source Control!

#3


  • First study the existing interface well.
  • 首先要好好研究现有的界面。

  • Write tests if they are absent, or expand already written ones.
  • 如果不存在则编写测试,或者扩展已编写的测试。

  • Modify the source code.
  • 修改源代码。

  • Run tests to check if the modification somehow breaks the older behaviour.
  • 运行测试以检查修改是否以某种方式破坏了旧行为。

#4


There is another good book, currently freely available on the net, about object oriented reengineering : http://www.iam.unibe.ch/~scg/OORP/

目前网上免费提供另一本关于面向对象再造的好书:http://www.iam.unibe.ch/~scg/OORP/

#5


The book "Code Reading" by Diomidis Spinellis contains lots of advice about how to gain an overview and in-depth knowledge about larger, unknown projects.

Diomidis Spinellis的“Code Reading”一书包含了很多关于如何获得有关较大的未知项目的概述和深入知识的建议。

Chapter 6 is focuses sonely on that topic (Tacking Large Projects). Also the chapters about tooling (Ch. 9) and architecture (Ch. 8) might contain nice hints for you.

第6章重点关注该主题(Tacking Large Projects)。关于工具(第9章)和架构(第8章)的章节也可能包含很好的提示。

However, the book is about understanding (by reading) the "code". It does not tackle directly the maintenance step.

然而,这本书是关于理解(通过阅读)“代码”。它没有直接解决维护步骤。

#6


First thing I would do is try to find the product's requirements.

我要做的第一件事就是尽量找到产品的要求。

It's almost unthinkable that a product of this size would be developed without requirements.

这种尺寸的产品在没有要求的情况下开发几乎是不可想象的。

By perusing the requirements, you'll be able to:

通过仔细阅读要求,您将能够:

  • get a sense of what the product (and hence the code) is at least supposed to be doing
  • 了解产品(以及代码)至少应该做什么

  • see just how well (or poorly) the code actually fulfills those requirements
  • 看看代码实际满足这些要求的程度(或差)

Otherwise you're just looking at code, trying to divine the intention of the developers...

否则你只是在看代码,试图暗示开发人员的意图......

#7


Running Doxygen with the EXTRACT_ALL tag set to document all the relationships in the code base. It's not going to help you with the code flow, but hopefully it will shed some light with regards to the structure and design of the entire application.

运行Doxygen并设置EXTRACT_ALL标记以记录代码库中的所有关系。它不会帮助您完成代码流程,但希望它能够为整个应用程序的结构和设计提供一些启示。

#8


If you are able to run the code in a PC, you can try to build a callgraph usually from a profiling output.

如果您能够在PC中运行代码,则可以尝试通常从分析输出构建调用图。

Also cross referencing tools like cscope, ctags, lxr, etc. Can help a lot. A

还可以交叉引用工具,如cscope,ctags,lxr等。可以提供很多帮助。一个

Spending some time reading, building class diagrams or even adding comments to the parts of the code you took long to understand are steps towards getting familiar with the codebase and getting ready to modify/extend it.

花一些时间阅读,构建类图,甚至为你需要长时间理解的代码部分添加注释是熟悉代码库并准备修改/扩展它的步骤。

#9


The first thing you need to do is understand how the code works. Read what documentation there is and then watch the program operate under a debugger. If you watch the main function/loop and then slowly work your way deeper into the program, you can gain a pretty good idea how things are operating. Make sure you write down your findings so others who follow after you have a better position to start from.

您需要做的第一件事是了解代码的工作原理。阅读有关的文档,然后观察程序在调试器下运行。如果您观看主要功能/循环,然后慢慢深入到程序中,您就可以很好地了解操作的方式。确保你写下你的发现,以便其他人在你有更好的职位开始后跟进。

#10


A very good austrian programmer once told me that in order to understand a program you first have to understand the data-structures that the program uses.

一位非常优秀的奥地利程序员曾告诉我,为了理解程序,首先必须了解程序使用的数据结构。

#1


There's a book for you: Working Effectively with Legacy Code

有一本书适合您:有效地使用遗留代码

It's not about tools, but about various approaches, processes and techniques you can use to better understand and make changes to the code. It is even written from a mostly C++ perspective.

它不是关于工具,而是关于可以用来更好地理解和更改代码的各种方法,过程和技术。它甚至是从C ++的角度编写的。

#2


Use Source Control before you touch anything!

在触摸任何东西之前使用Source Control!

#3


  • First study the existing interface well.
  • 首先要好好研究现有的界面。

  • Write tests if they are absent, or expand already written ones.
  • 如果不存在则编写测试,或者扩展已编写的测试。

  • Modify the source code.
  • 修改源代码。

  • Run tests to check if the modification somehow breaks the older behaviour.
  • 运行测试以检查修改是否以某种方式破坏了旧行为。

#4


There is another good book, currently freely available on the net, about object oriented reengineering : http://www.iam.unibe.ch/~scg/OORP/

目前网上免费提供另一本关于面向对象再造的好书:http://www.iam.unibe.ch/~scg/OORP/

#5


The book "Code Reading" by Diomidis Spinellis contains lots of advice about how to gain an overview and in-depth knowledge about larger, unknown projects.

Diomidis Spinellis的“Code Reading”一书包含了很多关于如何获得有关较大的未知项目的概述和深入知识的建议。

Chapter 6 is focuses sonely on that topic (Tacking Large Projects). Also the chapters about tooling (Ch. 9) and architecture (Ch. 8) might contain nice hints for you.

第6章重点关注该主题(Tacking Large Projects)。关于工具(第9章)和架构(第8章)的章节也可能包含很好的提示。

However, the book is about understanding (by reading) the "code". It does not tackle directly the maintenance step.

然而,这本书是关于理解(通过阅读)“代码”。它没有直接解决维护步骤。

#6


First thing I would do is try to find the product's requirements.

我要做的第一件事就是尽量找到产品的要求。

It's almost unthinkable that a product of this size would be developed without requirements.

这种尺寸的产品在没有要求的情况下开发几乎是不可想象的。

By perusing the requirements, you'll be able to:

通过仔细阅读要求,您将能够:

  • get a sense of what the product (and hence the code) is at least supposed to be doing
  • 了解产品(以及代码)至少应该做什么

  • see just how well (or poorly) the code actually fulfills those requirements
  • 看看代码实际满足这些要求的程度(或差)

Otherwise you're just looking at code, trying to divine the intention of the developers...

否则你只是在看代码,试图暗示开发人员的意图......

#7


Running Doxygen with the EXTRACT_ALL tag set to document all the relationships in the code base. It's not going to help you with the code flow, but hopefully it will shed some light with regards to the structure and design of the entire application.

运行Doxygen并设置EXTRACT_ALL标记以记录代码库中的所有关系。它不会帮助您完成代码流程,但希望它能够为整个应用程序的结构和设计提供一些启示。

#8


If you are able to run the code in a PC, you can try to build a callgraph usually from a profiling output.

如果您能够在PC中运行代码,则可以尝试通常从分析输出构建调用图。

Also cross referencing tools like cscope, ctags, lxr, etc. Can help a lot. A

还可以交叉引用工具,如cscope,ctags,lxr等。可以提供很多帮助。一个

Spending some time reading, building class diagrams or even adding comments to the parts of the code you took long to understand are steps towards getting familiar with the codebase and getting ready to modify/extend it.

花一些时间阅读,构建类图,甚至为你需要长时间理解的代码部分添加注释是熟悉代码库并准备修改/扩展它的步骤。

#9


The first thing you need to do is understand how the code works. Read what documentation there is and then watch the program operate under a debugger. If you watch the main function/loop and then slowly work your way deeper into the program, you can gain a pretty good idea how things are operating. Make sure you write down your findings so others who follow after you have a better position to start from.

您需要做的第一件事是了解代码的工作原理。阅读有关的文档,然后观察程序在调试器下运行。如果您观看主要功能/循环,然后慢慢深入到程序中,您就可以很好地了解操作的方式。确保你写下你的发现,以便其他人在你有更好的职位开始后跟进。

#10


A very good austrian programmer once told me that in order to understand a program you first have to understand the data-structures that the program uses.

一位非常优秀的奥地利程序员曾告诉我,为了理解程序,首先必须了解程序使用的数据结构。