清理代码库的最佳方法是什么 [英] What would be the best way to clean up a code base

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

问题描述

我有一个大型的旧版Microsoft Visual C ++应用程序,我希望将该应用程序划分为多个较小的库,以便于维护和清理.我想知道是否有人可以建议任何工具或技术.添加功能很痛苦,并且测试这些新功能是否会破坏其他功能.

I have a large legacy Microsoft Visual C++ application that I want to divide the application into smaller libraries for easier maintenance and cleanup. I was wondering if there is any tool or techniques anyone could suggest. It is a pain to add features and test is those new feature will break anything else.

推荐答案

这是我们在公司类似情况下所做的事情.我们创建了一个全新的空项目,然后根据新代码库的严格规则将其移到那里,并尽可能地对其进行单元测试.这是一项艰巨的任务,但是一旦完成,您将拥有一个全新的代码,该代码具有清晰的结构并且可以快速,安全地进行更改.
This is what we did in similar case in our company. We created completely new empty project and then moved stuff there putting it according to strict rules of new code base + wrapping it up with unit testing as much as it was possible. This is big task, but once it is done you have a brand new code with clear structure and ability to be changed fast and safely.


将方法编译到库中的通常原因是因为重用.您具有许多应用程序所使用的通用功能,并且只想拥有一个源.
如果此应用程序是旧应用程序,则该代码可能不会在其他任何地方使用.
由于我不知道代码的样子,因此很难知道为什么要拆分代码.
也许设计没有很好的结构?如果是这种情况,您可以开始创建新的类来改进结构,但是源代码是使用主应用程序编译的.

如果要确保更改后代码没有损坏,则应为要更改的零件创建测试用例.当然,您要做的是之前进行任何更改.
编写和使用测试用例需要大量工作,但最终可能会使您摆脱昂贵的bug.

测试案例基础知识 [ ^ ]
如何编写有效的测试用例 [ ^ ]
The usual reason to compile methods into a library is because of reuse. You have common functionality that is used by many applications and you only want to have one source.
If this application is legacy the code might not be used anywhere else.
As I don''t know what the code looks like, it is difficult to know why you want to split up the code.
Maybe the design does not have a good structure? If that is the case, you can start to create new classes that improves the structure, but the source code is compiled with the main application.

If you want to make sure that the code is not broken after a change, you should create test cases for the part you are changing. And of course you do that before you make any changes.
To write and use test cases is a lot of work, but in the end of the day it might save you from expensive bug.

TEST CASE Fundamentals[^]
How to write effective Test cases[^]


首先,这是个坏主意.

但是,如果您仍然要这样做,请认真阅读有关单元测试的内容.对于非托管C ++,请查看Sourceforge的CPPUnit.
First of all, this is a bad idea.

But if you are going to do it anyway, do some serious reading up on unit testing. For unmanaged C++, have a look at CPPUnit at Sourceforge.


这篇关于清理代码库的最佳方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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