Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>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:</p> <p><strong>Motivation</strong></p> <p>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. </p> <p>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.</p> <p>Any publicly released code also needs the code snippets to be up to standards and thoroughly tested. </p> <p><strong>Implementation</strong> </p> <p>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.</p> <p>I have one TidBits_Cpp repository. This repository has submodules with each code snippet. </p> <p>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.</p> <p>Each submodule with a snippet has mainly header only implementation with a header for unit testing, and a standalone unit testing app.</p> <p>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.</p> <p>All code in the submodules assumes the central include directory to be in the include path.</p> <p>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.</p> <p>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.</p> <p>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.</p> <p>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 </p> <p>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. </p> <p>However, as <a href="https://stackoverflow.com/users/168225/georg-fritzsche">Georg Fritzsche</a> pointed out <a href="https://stackoverflow.com/questions/1226206/is-there-a-reason-to-not-use-boost/4129295#4129295">here</a> 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... </p> <p>If you are interested, this is <a href="https://github.com/najamelan/TidBits_Cpp" rel="nofollow noreferrer">the link to my repository</a>, 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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload