最安全的方法来改变项目中的变量名 [英] Safest way to change variable names in a project

查看:215
本文介绍了最安全的方法来改变项目中的变量名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我一直在做一个相对大的项目,我自己,我已经认识到,早些时候的一些变量名是..不太理想。

So I've been working on a relatively large project by myself, and I've come to realise that some of the variable names earlier on were.. less than ideal.

但是,如何轻松地改变项目中的变量名?有没有这样一个工具,可以通过一个项目目录,解析所有的文件,然后将变量名称替换为所需的一个?

But how does one change variable names in a project easily? Is there such a tool that can go through a project directory, parse all the files, and then replace the variable names to the desired one? It has to be smart enough to understand the language I imagine.

我在想使用regexp(sed / awk on linux?)工具来替换变量名,但是有很多次我的特定变量也被包含为字符串的一部分。

I was thinking of using regexp (sed/awk on linux?) tools to just replace the variable name, but there were many times where my particular variable is also included as a part of strings.

还有一个关于改变c ++命名空间的东西的问题,因为实际上有两个

There's also the issue about changing stuff on a c++ namespace, because there is actually two classes in my project that share the same name, but are in different namespaces.

我记得视频工作室能够做到这一点,但是最安全和最优雅的方式是什么

I remember visual studio being able to do this, but what's the safest and most elegant way to do this on linux?

推荐答案

最安全(非自动化方式):

Safest (non automated way) way:


  1. 确保所有的单元测试都正常工作。

  2. 将所有内容保存到源代码管理中。

  3. 全球用XXXvarXXX(认真)替换var

    a。或者也许只是你认为需要编辑的文件。

  4. 尝试并编译。无法编译的一切都很容易撤消,只需删除XXX。

  5. 编译时运行单元测试。

  6. 单元测试工作时。将XXXvarXXX全局替换为新名称。

  7. 确保单元测试仍然有效

  8. 将所有内容保存在源代码管理中。

  1. Make sure all your unit tests work.
  2. Save everything into source control.
  3. Globally replace var with XXXvarXXX (seriously)
    a. Or maybe just the files you think need editing.
  4. Try and compile. Everything that does not compile is easy to undo just remove the XXX.
  5. When it compiles run the unit tests.
  6. When the unit tests work. Do a global replace of XXXvarXXX to the new name.
  7. Make sure the unit tests still work
  8. Save everything in source control.

舌头只有一半。 : - )

Tongue only half in cheek. :-)

这篇关于最安全的方法来改变项目中的变量名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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