维护一个满足两个版本平台的项目的正确方法是什么? [英] What is the proper way to maintain a project that meets two versions of a platform?

查看:136
本文介绍了维护一个满足两个版本平台的项目的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个以特定编程语言实现的项目,出于任何原因,这些语言的使用分为两个(或更多)版本。

Suppose I have a project implemented in a specific programming language whose use is fragmented into two (or more) versions, for any reason.

这两个版本提供了不同的实现项目某些功能的机制。因此,相同的代码在版本之间是不可移植的。

These two versions provide different mechanisms to implement some functionality of the project. Thus, the same code is not portable between versions.

如何在git存储库中组织这种情况?尽管如此,保持分支内特定版本的目录?在同一个存储库中复制分支?或者为每个版本使用不同的存储库?

How to organize this situation in a git repository? Nevertheless, Keep directories for specific versions within a branch? Duplicates branchs in the same repository? Or use different repositories for each version?

推荐答案

这取决于编程语言,但如果两个版本导致你的代码有很大的不同,那么我想:

It depends a bit on the programming language, but if the difference between the two versions results in a significant difference in your code, then I would want to:


  1. 定义了一个接口来表示实现需要不同的功能。 / li>
  2. 编写该接口的两个实现。
  3. 根据语言和项目,在构建时或运行时选择正确的一个。 / li>
  1. define an interface representing the functionality whose implementation needs to differ.
  2. write two implementations of that interface.
  3. select the right one either at build time or run time, as appropriate to the language and the project.

将两个不同的实现分开后,可以将它们保留在同一个分支中,就像保留任何两个不同的实现

Once you've separated the two different implementations, you can keep them in the same branch just as you'd keep any two different implementations of the same interface in a branch.

对于一个微不足道的差别,例如,如果您只需要将稍微不同的标志传递给某个函数,那么我可能不会去解决所有的麻烦。相反,我只是做相当于:

For a trivial difference, for instance if all you need is to pass slightly different flags to some function, then I'd probably not go to all that trouble. Instead I'd just do the equivalent of:

#if NEW_PLATFORM
    // enable useful new flag 2
    #define FLAGS 0x11
#elif OLD_PLATFORM
    // we can live without flag 2 if it's not supported
    #define FLAGS 0x1
#else
    #error what platform even is this?
#endif

但是要小心,随着代码的发展,无关紧要的差异会随之增加,带着一堆平台检测代码。您应该瞄准在至多一个地方测试平台,或者甚至更好地使用构建选项来控制整个事物。在上述情况下,您可以调用 USE_USEFUL_NEW_FLAG ,而不是显式编码,它取决于特定的平台版本。然后,根据您的构建配置了解哪些平台支持哪些功能。

But beware, insignificant differences can grow as the code develops, and you end up with a mess of platform detection code. You should aim to test the platform in at most one place, or even better just control the whole thing with a build option. In the above case you could call that USE_USEFUL_NEW_FLAG rather than explicitly coding that it depends on a particular platform version. Then it's up to your build configuration to know which platforms support which features.

这篇关于维护一个满足两个版本平台的项目的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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