有没有任何代码分析工具可以让我的工作变得更轻松?

发布于 2024-09-10 23:10:19 字数 1539 浏览 8 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

泪是无色的血 2024-09-17 23:10:19

我需要想出一种测试方法
我的代码以确保它出现
与之前的代码的答案相同。

单元测试

由于您提到它是一个接受文件中的参数并输出报告的程序,因此您可以生成一些输入,为您想要的部分提供足够的覆盖范围想要针对旧代码的输出进行单元测试。

如果出现问题,请不要忘记,您也有可能在旧代码中发现了错误。

http://www.junit.org/

渐进式移植

我会去一点一点地移植它,我觉得它会适合你的问题,因为在一份报告中你可以抓取特定字段并忽略那些您尚未移植的字段(假设输出一个字段/计算,您不需要移植整个程序)并根据旧代码(或其他正确源,以防万一)中的正确值验证它旧代码中的错误)。

I need to come up with a way to test
my code to make sure it comes up with
the same answers as the previous code.

Unit Testing

Since you mentioned that it is about a program that takes parameters in a file and outputs a report, you could generate a few inputs that give sufficient coverage to the portions you want to unit test against the output from the old code.

If something breaks don't forget there is also a chance you have discovered a bug in the old code.

http://www.junit.org/

Progressive Port

I'd go for porting it piece by piece, I kind of feel it will fit your problem since in a report you can grab specific fields and ignore those that you have not ported yet (assuming to output one field/calculation you do not need the whole program to be ported) and verify it against the correct value from the old code (or other correct source in case of bugs in the old code).

十六岁半 2024-09-17 23:10:19

我认为您应该开始编写测试以确保移植的代码不会破坏任何现有报告的行为。

至于自动代码分析工具,在这方面最有可能为您提供帮助的是数据流分析工具,它可以对从文件到变量再到报告的数据流进行假设建模。不幸的是,几周前我对此类工具的搜索失败了。您可能希望在某些地方有手绘的 DFD,只是为了确保您不会被某些东西绊倒。 Graphviz 可以在这方面提供帮助。

它可能有助于将功能复制到 Java(我知道这听起来很反常),但您可以在 PMD、FindBugs 和 Java 中类似代码质量保证工具的监视下仔细重构代码。

编辑:我忘记了某个类别的工具可以提供帮助的部分 - 这些是 Java 世界中的代码切片工具,我必须承认到目前为止我还没有使用过它们。以下是可能有帮助的列表:

I think you should start off writing tests to ensure that the ported code does not break any of the existing report's behavior.

As for automated code analysis tools, the ones most likely to aid you in this area are the data flow analysis tools, which can hypothetically model the flow of data from the file into the variables and out to the report. Unfortunately, a search for such tools resulted in a failure a few weeks back, for me. You might want to have hand-drawn DFDs in places, just to make sure you don't trip over something. Graphviz can help in this area.

It might help copying over the functionality over to Java (I know this sounds perverse), but you could refactor the code carefully under the watchful eyes of PMD, FindBugs and similar code quality assurance tools in Java.

EDIT: I had forgotten the part where in tools of a certain category could be of aid - these are the code slicing tools in the Java world, and I must admit that I haven't used them so far. Here's a list that might help:

遇见了你 2024-09-17 23:10:19

我前段时间问了一个有点相关的问题,这让我想到了一种可能的方法:是否有 C/C++ 的 Findbugs 和/或 PMD 等效项?

我想到的是,如果这段代码如此简陋,也许花一些时间来尝试就地修复/重构它。显然,如果您要转向 Java,那么很难说服自己花时间改进生命周期较短的 C++ 代码。也就是说,如果你用改进的代码替换一些明显愚蠢的部分,它可能会更短、更紧凑、更明显正确,并且当你试图说服自己新代码在功能上时更容易移植和分析相当于旧代码。

在回答我的问题时建议的最有用的工具是 SplintCppcheck

前段时间提出了另一个更广泛的问题,可能会贡献相关的想法:有哪些开源 C++ 静态分析工具可用?

I asked a somewhat related question some time ago that makes me think of a possible approach: Is there a Findbugs and / or PMD equivalent for C/C++?

What occurs to me is that, if this code is so janky, perhaps it would be a good idea to spend some time to try to repair / refactor it in place. Obviously, if you're headed to Java, it's a hard thing to convince yourself to spend time on improving C++ code that has a short lifespan. That said, if you replace some of the obviously stupid portions with improved code, it'll likely be shorter, tighter, more obviously correct and a whole lot easier to port and to analyze as you try to convince yourself that the new code is functionally equivalent to the old code.

The most useful tools suggested in answers to my question were Splint and Cppcheck.

There was another broader question asked some time ago that may contribute related ideas: What open source C++ static analysis tools are available?

不寐倦长更 2024-09-17 23:10:19

免责声明:我以前从未做过这样的事情。

你不能先使用 C++ 到 Java 转换器(快速谷歌搜索让我找到了一个产品,该产品声称能够以非常合理的价格做到这一点,如果它确实有效C++ 到 Java 转换器)。

然后,创建单元测试并开始重构。

Disclaimer: I've never had to do anything like this before.

Couldn't you first use a C++ to Java converter (a quick google search led me to a product which claims to be able to do that at a very reasonable price if it does in fact work C++ to Java Converter).

Then, create your unit tests and begin refactoring.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文