如何管理实用模块和code片段使用Git,升压, [英] How to manage utility modules and code snippets with git, boost,

查看:127
本文介绍了如何管理实用模块和code片段使用Git,升压,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当编程我积累code片段和实用工具类。我想存储那些将来实际使用。

When programming I accumulate code snippets and utility classes. I want to store those for practical future use.

问题简单地是什么是做到这一点的最好办法。更详细的一个例子:

The question briefly is what is the best way to do this. More elaborate with an example:

在写code我们保持我们的重用花絮不错涵盖常见任务。不过,为了使我们的项目开源,说与在github混帐,这个花絮也需要提供。我想知道如何最好地做到这一点。

When writing code we keep reusing our nice tidbits to cover common tasks. However in order to make our projects open source, say with git on github, this tidbits also need to be available. I was wondering how to best do this.


  • 请我做我的个人事业回购项目能够在git的子模块作为添加?

  • 还是我为每个单独的珍闻混帐回购协议,这样一个项目可以添加特定的珍闻的特定版本作为子模块。 (这解决了与工具库像提振,其中获得巨大的,即使你的程序可能只需要其中的一小部分有问题)

  • 或者我同时结合成一个子模块与实用程序回购,其中外部项目可以有实用回购作为子模块?如果他们想使用一个珍闻版本x和版本ÿ珍闻的B会发生什么?可能是好的只是有一个集中概述?

就像所有的公共code,这样的片段要轻,速度快,测试,随身携带,记录和preferably相对自成一体。现在,我在某个地方找到这个漂亮code和它使用CTASSERT,这是不可移植。

Like all public code, snippets like that should be light, fast, tested, portable, documented and preferably relatively self contained. Now I find this nice code somewhere and it uses CTASSERT, which is not portable.

我应该怎么办?


  • 我可以使用升压static_assert,但增加了一个重大的依赖性稍微code段,因为提升是不平凡的,我的系统上它编译至2GB。更糟糕的是,它也使用它提供了一些非常基本的功能代码段增加了这种依赖关系到每个项目。此外,作为助推据我所知,还没有git的回购,所以一个项目不能自动照顾这一个子模块的依赖关系。

  • 请我再拍片段,并用拉重新发明轮子,创造更多code做的事情,提振已经做的愚蠢的副作用我自己的编译时断言。

林期待听到你如何解决这个问题,总体思路和指导方针。

Im looking forward to hearing how you solve this problem, and general thoughts and guidelines.

推荐答案

有似乎是在这个小ANIMO,但我依然看好,并希望从别人输入的想法真的很兴奋。这是我想出了:

There seems to be little animo in this, but I am still really quite excited about it and hoping for input ideas from others. This is what I have come up with:

激励

每个程序员都积累了一堆重复使用的code片段。大多数情况然而,这些片段在全局头文件最终从他们在哪里,然后复制一个项目/粘贴到新的项目。

Every programmer accumulates a bunch of reusable code snippets. Most often however these snippets end up in a global header file for a project from where they are then copy/pasted to new projects.

这有几个缺点。在code是笨拙的,它是否认自己的生活,适当的单元测试和发展演变。而且这会导致徘徊在没有基础设施相似或相同的code的多个副本,一次维护。

This has a few disadvantages. The code is clumsy and it is denied it's own life with proper unit testing and development evolution. Further this leads to several copies of similar or identical code lingering around without infrastructure to maintain them at once.

所有公开发布的code也需要code段要达到标准进行全面测试。

Any publicly released code also needs the code snippets to be up to standards and thoroughly tested.

实施

我发现这个一个很好的解决方案可以在git的片段库中创建。我创建正好可以在这个库作为一个子模块和个别片段所有未来的项目是从该回购再次子模块。用户可以比选择仅下载那些同时享受中央,他们使用包括所有的目录,以及到文档和单元测试中心的访问片段。

I found that a good solution for this can be created with a snippet library in git. All future projects I create can just take in this library as a submodule and individual snippets are again submodules from that repo. The user can than choose to only download those snippets they use while enjoying a central include directory for all, and central access to documentation and unit testing.

我有一个TidBits_Cpp库。这个仓库有每个code片段子模块。

I have one TidBits_Cpp repository. This repository has submodules with each code snippet.

主要回购具有一样提升了包括目录,除了在中央目录只包括包括子目录其他文件,只有在那里正是每珍闻之一,一个包括你需要,如果你想使用珍闻。它们封装子目录包含一个命名空间花絮。保持子模块的名称空间出局允许其他人,包括在自己的代码片段库,这些片段,并加入他们周围自己的命名空间。

The main repo has an include directory just like boost, except that the includes in the central directory only include other files from subdirectories and there is only one exactly per tidbit, the one include you need if you want to use that tidbit. They wrap the subdirectory includes in a namespace tidbits. Keeping the namespace outs of the submodules allows other people to include these snippets in their own snippet libraries and add their own namespace around them.

一个片段每个子模块主要有头只与一个单元测试标头,实施,和一个独立的单元测试应用程序。

Each submodule with a snippet has mainly header only implementation with a header for unit testing, and a standalone unit testing app.

单元测试基类也是一个珍闻。主要回购有一个测试系统上存在的所有花絮单元测试的应用程序。为此,它有一个虚拟目录包括这应该是最后一次在包含路径,让您可以随时编译。检查定义可以知道哪些code是实际可用的单元测试。

The unit testing base class is also a TidBit. The main repo has a unit testing application that tests all the TidBits that exist on the system. For this it has a directory with dummy includes which should be last in the include path, so you can always compile. Checking defines allows to know which code is actually available for unit testing.

在所有子模块code假定中央include目录是在包含路径。

All code in the submodules assumes the central include directory to be in the include path.

是DoxyFiles,以及视觉工作室的解决方案。 Eclipse是更难,因为它与从不同的目录中使用cpp文件的项目涉及严重。我将在以后添加的Makefile为其他编译器和平台。

Included in the repository are DoxyFiles, as well as visual studio solutions. Eclipse is harder because it deals badly with projects that use cpp files from different directories. I will add MakeFiles later for other compilers and platforms.

要得到这个希望使用一个珍闻应包括指向主TidBits_Cpp库子模块的任何项目的全部力量,再拉他们想使用的子模块。他们可以立即运行所有单元测试,而无需编写任何code,然后就开始编码。

To get the full power of this any project that wants to use a TidBit should include a submodule pointing to the main TidBits_Cpp repository, and then pull the submodules they want to use. They can immediately run all unit tests without writing any code, and then just start coding.

从父回购的开销很小,因为它只包含一个行包括以及1个文件夹中的一些单元测试的东西,一个的Doxyfile。

The overhead from the parent repo is small, since it only contains one-line includes as well as 1 folder with some unit testing stuff and a DoxyFile.

这种系统的优点是,片段式回购不需要甚至是我自己的。我可以在任何GitHub的库调用作为一个子模块,因此可以在其他

The beauty of this kind of system is that the snippet repos need not even by my own. I can call in any github repository as a submodule, and so can other

考虑到静态断言,好了,我没有拉我自己一个人,虽然也有可以在这里找到解决方案,而无需增加提振,因为为code段的依赖。主要的原因,我不会做,这是因为刺激是很大的,它不能作为一个Git仓库,所以它不能获得作为一个子模块自动下载。

Considering the static assert, well, I did pull my own one, although there are solutions available here without having to add boost as a dependency for a code snippet. The main reasons I would not do this is because boost is big and it is not available as a git repository, so it cannot get downloaded automatically as a submodule.

不过,由于乔治·Fritzsche也指出,<一个href=\"http://stackoverflow.com/questions/1226206/is-there-a-reason-to-not-use-boost/4129295#4129295\">here能够提取与BPC升压的一部分。的缺点是,对于例如静态断言这仍然装置70的文件...

However, as Georg Fritzsche pointed out here it is possible to extract a part from boost with bpc. The disadvantage is that for static assert for example this still means 70 files...

如果你有兴趣,这是链接到我的仓库,但考虑目前不一个多说明这个职位。在那里code,现在仍然是非常正在开发中,还没有适合公开发布。也不是有文档等,所有这一切都为未来的时代。

If you are interested, this is the link to my repository, however consider it at the moment not more than an illustration to this post. The code in there right now is still very much under development and not yet suited for public release. Neither is there documentation etc. All that is for future times.

这篇关于如何管理实用模块和code片段使用Git,升压,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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