什么 C++你在实践中使用重构吗?

发布于 2024-10-03 11:41:54 字数 243 浏览 6 评论 0原文

我将创建现有自动化 C++ 重构工具的比较表,并探索创建此类工具(免费且开源)的能力。

我的问题是:您在日常工作中真正使用了哪些重构?有一些显而易见的事情,例如重命名变量/类/方法,但是 C++ 是否有一些特定的事情,例如处理模板、STL、复制构造函数、初始值设定项等?

我感兴趣的是构建 C++ 开发人员每天在编码中面临的所有小问题的真实情况,并且至少在理论上可以自动化。我正在和我的同事交谈,但这可能还不够。

提前致谢。

I'm going to create the comparison table of existing automated C++ refactoring tools as well as explore an ability of creation of such tool, free and open-source.

My question is: what refactorings do you really use in your everyday work? There are obvious things like renaming variable/class/method, but is there something specific for C++, like dealing with templates, STL, copy constructors, initializers, etc., etc?

I'm interested in building of realistic picture of all that little problems that C++ developer is facing each day in his coding and that could be automated at least in theory. I'm talking to my colleagues but that's probably not enough.

Thanks in advance.

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

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

发布评论

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

评论(6

如果没结果 2024-10-10 11:41:54

从答案中可以清楚地看出,很少有 C++ 程序员见过真正的重构工具。是的,它们非常罕见,并且与您使用的 IDE 高度相关。这是不可避免的,否则没有什么好方法来找出哪些源代码文件为最终可执行文件提供了代码。预处理器使其变得更具挑战性,您需要知道宏值。需要源代码解析器,但还不够。

Visual Assist for VS 是我所知道的一种。

It is pretty clear from the answers that few C++ programmers have ever seen a real refactoring tool. Yes, they are quite rare and highly specific to the IDE you use. That's inevitable, there is otherwise no good way to find out what source code files contribute code to the final executable. The preprocessor makes it extra challenging, you need to know the macro values. A source code parser is required but not enough.

Visual Assist for VS is one I know of.

甜扑 2024-10-10 11:41:54

正如您所说,有一些明显的事情:

  • 重命名是一件事,
  • 更改函数签名是另一件事(特别是因为函数几乎必然是重复的:标头中的声明和源代码中的实现)
  • 重命名/移动文件(包含指令的更新)

请注意尽管它很基本,但很少能得到很好的处理。我的主要抱怨是评论通常不会更新(我不是在谈论 doxygen 自动生成的无用的混乱)。因此,如果我在标头中描述该类的使用,或者在另一个源文件中使用该类的理由,则注释现在已过时,因为通过重命名该类,现在没有人会知道它指的是什么......

有然而更有趣的情况是:

  • 当更改函数签名时,您需要更新所有调用站点,开发人员将需要帮助来本地化它们
  • 通过继承,能够作用于层次结构的所有类:更改函数签名(再次) )或添加/删除虚拟覆盖。
  • 使用模板:概念提案已被删除,如果您可以综合所传递类型的要求(必要的方法/内部类型),以便在更改这些要求(通过修改模板定义)时收到列表通知,那就太好了此模板正在使用且不再符合它的类(并且应更新)。请注意,如果只是重命名类型/方法,您可能希望自动传播更改,只要它不破坏其他任何内容。

祝你好运...

As you said there are obvious things:

  • renaming is one
  • altering a function signature is another (especially since a function is almost necessarily duplicated: declaration in the header and implementation in the source)
  • renaming / moving a file (update of include directives)

Note that though it's basic, it's rarely well dealt with. My primary complaint being that comments are generally not updated (I am so not speaking about doxygen auto-generated useless clutter). So if I was describing the use of the class within a header, or the justification of using this class in another source file, the comment is now obsolete because by renaming the class no one will now know what it refers to...

There are however much more interesting cases:

  • When changing a function signature, you need to update all the call sites, the developer will need help for localizing them
  • With inheritance, the ability to act on all classes of a hierarchy: changing a function signature (once again) or adding/removing a virtual override.
  • With template: the Concept proposal having been dropped, it would be good if you could synthetise the requirements on the type passed (methods / inner types necessary) so that when altering those requirements (by modifying the template definition) one gets notified of the list of classes that are in use by this template and no longer conform to it (and shall be updated). Note that in case it's just renaming the type / method, you might want to automatically propagate the change, as long as it doesn't break anything else.

Good luck...

飘过的浮云 2024-10-10 11:41:54

看看 Martin Fowler 的 重构:改进现有代码的设计重构模式,作者:Joshua Kerievsky。这些依次引用 GoF 设计模式 书,所以也买吧。

如果您能够超越基本的重命名功能和提取功能,那么您可能会成为赢家。

Take a look in Martin Fowler's Refactoring: Improving the Design of Existing Code and Refactoring to Patterns by Joshua Kerievsky. These in turn reference the GoF Design Patterns book so get that too.

If you can beyond the basic Rename Feature and Extract Function then you might be onto a winner.

梦在深巷 2024-10-10 11:41:54

这是我昨天想出的一个 C++ 设计模式:放弃继承,支持策略

Here's a C++ design pattern I came up with yesterday: Ditch inheritance in favor of policies.

浮世清欢 2024-10-10 11:41:54

我希望支持的一种重构实际上是注入方法。或多或少与提取方法相反。

因为也许我发现我可以重新排列生成的代码以获得更好的清晰度或效果;但我不知道目前有工具支持这一点。

One refactoring that I wish was supported is actually inject method. More-or-less the opposite of extract method.

Because perhaps I see that I can then rearrange the resulting code to better clarity or effect; but I am not aware that there is tool support for this at present.

瘫痪情歌 2024-10-10 11:41:54

您好,我使用 http://www.devexpress.com/Products/Visual_Studio_Add-in/RefactorCPP / 使用这个工具我可以重命名变量/类/方法,更改函数体,初始化程序

Hi i use http://www.devexpress.com/Products/Visual_Studio_Add-in/RefactorCPP/ with this tool i do renaming variable/class/method, changing function body,initializers

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