    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
     <channel>
        <title>ACCU  :: Organising Source Code</title>
        <link>https://members.accu.org/index.php/journals/374</link>
        <description>Professionalism in Programming</description>
        <dc:language>en-us</dc:language> 
        <dc:creator>Administrator</dc:creator> 
        <admin:generatorAgent rdf:resource="http://www.xaraya.org" /> 
        <admin:errorReportsTo rdf:resource="mailto:webeditor@accu.org" />
       <sy:updatePeriod>hourly</sy:updatePeriod>
       <sy:updateFrequency>1</sy:updateFrequency>
       <docs>http://backend.userland.com/rss</docs>


        <h2>Journal Articles</h2>


<div class="xar-mod-head"><span class="xar-mod-title">Overload Journal #52 - Dec 2002 + Design of applications and programs</span></div>

<table border="0" cellpadding="1" cellspacing="0">
    <tbody>
    <tr>
        <td valign="top">
            Browse in :
       </td>
       <td valign="top">

                                            <a href="https://members.accu.org/index.php/journals/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c76/">Journals</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c78/">Overload</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c191/">52</a>
                    (7)
<br />

                                            <a href="https://members.accu.org/index.php/journals/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c13/">Topics</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c67/">Design</a>
                    (236)
<br />

                                            <a href="https://members.accu.org/index.php/journals/c191-67/">Any of these categories</a>

                    -                        <a href="https://members.accu.org/index.php/journals/c191+67/">All of these categories</a>
<br />
</td>
   </tr>
   </tbody>
</table>




<div class="xar-error">
   <p>
 <strong>Note:</strong> when you create a new publication type,
the articles module will automatically use the templates
<em>user-display-[publicationtype].xt</em>
and <em>user-summary-[publicationtype].xt</em>.
If those templates do not exist when you try to preview or display a new article,
you'll get this warning :-)  Please place your own templates in themes/<em>yourtheme</em>/modules/articles . The templates will get the extension .xt there. </p>
</div>
<div class="xar-norm xar-standard-box-padding">
   <h1><strong>Title:</strong>&nbsp;Organising Source Code</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 02 December 2002 21:57:50 +00:00 or Mon, 02 December 2002 21:57:50 +00:00</p>
<p><strong>Summary:</strong>&nbsp;</p>
<p><strong>Body:</strong>&nbsp;<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e18" id="d0e18"></a></h2>
</div>
<p>We've all seen it, one directory containing lots and lots of
files. Where to start? Where is main? How do they fit together?
This is the classic <span class="emphasis"><em>Topsy
system</em></span>, someone ran the wizard once and just kept on
adding more and more files.</p>
<p>While it is simple to put all our files in one place we are
missing an opportunity to communicate information about the system.
The original designer may know these five files form a discrete
group, and another six over there form another module but this
isn't obvious, that information has been lost, recovering it takes
time.</p>
<p>Consequently our understanding slows, and changes to the system
are delayed - the software is resisting change. We need to split
the system into comprehensible, logical, cohesive modules; we can
then use the directory tree structure to convey the system
structure.</p>
<p>Dividing our system across several directories has other
advantages. It becomes easier for multiple developers to work on
the system at the same time, and it becomes easier to transfer
modules between multiple projects.</p>
<p>The directory structure of a project is closely linked with the
source code control system employed - one mirrors the other. We
cannot consider the layout of files without talking about the
source code control too - once we commit files to source code
control it becomes more difficult to move them to other directories
or rename them.</p>
<p>Libraries, files, and directories represent the most physical
manifestation of source code short of a printout. Consequently they
form a key part of our overall strategy. Neglecting these aspects
leads to blob-like software that lacks cohesion.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e35" id="d0e35"></a>Splitting the
system into modules</h2>
</div>
<p>Many programming courses start by teaching their students the
need to divide systems into modules. <span class=
"emphasis"><em>Modularization</em></span> has moved beyond
buzz-word status, we take for granted that it is a <span class=
"emphasis"><em>good thing</em></span> and all systems should
exhibit it. Some of the benefits cited usually include:</p>
<div class="itemizedlist">
<ul type="disc">
<li>
<p><span class="emphasis"><em>Comprehensibility:</em></span> while
modularization helps us understand smaller elements of a system we
need to be able to integrate this knowledge. Integrative knowledge
is more difficult to express.</p>
</li>
<li>
<p><span class="emphasis"><em>Division of labour:</em></span> if is
easier for multiple developers to work on a modularised system then
a monolithic one. We also get <span class=
"emphasis"><em>specialisation of labour</em></span> where experts
in one aspect of the system can work on one module, and other
experts on other modules.</p>
</li>
<li>
<p>Modularization should help focus our minds on cohesion,
coupling, dependencies, division of tasks and such, this should all
make the system easier to change.</p>
</li>
</ul>
</div>
<p>Reuse is often cited as another advantage of modularization,
given the current debate on reuse I won't cite it as an automatic
benefit. However, if we wish to share elements between projects
then there must be some division of the source code.</p>
<p>But what are our modules? <span class=
"emphasis"><em>Module</em></span> and <span class=
"emphasis"><em>modularization</em></span> are such overloaded words
we're never really sure what they mean. <span class=
"emphasis"><em>Component</em></span> has similar problems.</p>
<p>Individual files can be a module, but that is too fine grained
for most purposes. And if a module is a file why use the word
module? And what difference does it make?</p>
<p>One of our usual objectives in defining modules is that we wish
to practice <span class="emphasis"><em>information
hiding.</em></span> It seems to me that the correct level to define
our modules is the level at which we can actively hide some
information, that is, hide some implementation.</p>
<p>Once our C or C++ code is compiled to object code we can hide
the implementation since we only need distribute the header files
and the object file. Still, the object file has a one-to-one
relationship with the source file so we're not hiding much.</p>
<p>We need a bigger unit to hide in. When we bundle many object
files together we get a static library. This is more promising. Our
code can interface to the library by including one or more header
files and we shouldn't need to care whether the library is made up
of one file, two files, or 25.</p>
<p>Static libraries are simple to create and use. Once compilation
and linking are complete then static libraries present no
additional overheads or requirements, we can have as many of them
as we want at no additional run-time cost. Hence, they are well
suited to be building blocks when decomposing a system into
discrete chunks.</p>
<p>Dynamic link libraries are more complicated, by no means are
they simply &quot;static libraries which have been linked differently.&quot;
We must consider run-time issues, where are the libraries found?
How do we find them? Do we have the right version? Dynamic
libraries have their place but they should not be the basic
building block.</p>
<p>When we create a static library we want to hide a secret inside
the library. The secret is <span class=
"emphasis"><em>implementation detail</em></span>. We want the
library to represent an idea, and we want to hide the realisation
of the idea from the rest of the system. To this end, the library
needs to be highly cohesive, that is, it needs to express its ideas
fully but no more than need be, it should not have lots of
bells-and-whistles. The library also needs to pay attention to what
it depends on, how connected it is to other modules in the system,
that is, we want to minimise coupling.</p>
<p>We can't reason about the cohesion and coupling of every file,
class and function in a system, that would take forever. While
individual developers may consider these forces within the library
module at a system level we would be overwhelmed by such details.
Static library modules represent the basic ideas from which a
system is built. Since each one contains a complete idea we should
expect to have many static libraries in our system. Many is good,
it shows that your ideas are discrete and can be expressed
individually.</p>
<p>Although you can cram more than one idea into a library you
usually know when you are doing so. It is pretty obvious when the
library is called &quot;Logging&quot; and you are putting database update
functions in that something is wrong.</p>
<p>It is also possible to fracture an idea and split it across
multiple libraries, but again it is pretty obvious. You quickly
notice that library &quot;Logging&quot; always requires library &quot;LogMessage&quot;
and something isn't quite right here.</p>
<p>Good systems are decomposed into many distinct static libraries
- we should prepare for and encourage this. On top of the libraries
we will find at least one application which results in an
executable program. It may only comprise one file, a main.cpp, with
the bulk of the code farmed out to static libraries.</p>
<p>You may well find that your project produces several
applications, when this happens you can benefit from good
modularization. There is no need for each application to provide
its own logging system, you use the logging library.</p>
<p>Is this reuse? Well, that depends on your definition of reuse. I
would argue that you are producing a family of programs with common
characteristics for which you use common code. In time you may
transfer some of this code to other projects.</p>
<p>How do we encourage modularization? Well, we start by providing
a structure into which we can modularize our project. Since we will
be writing files, we need a directory tree to place them in.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e110" id="d0e110"></a>The Directory
Tree</h2>
</div>
<p>In the early days of a project we may like to work light,
especially if there is just one developer on the project. But very
quickly a project crosses a line, usually when a second developer
starts work, or you decide that you could pull in code from a
previous project. Once you've crossed this line you need to
structure the work area of the project, that is, the directory
layout.</p>
<p>Obviously we want a logical directory structure but we also want
one we can add to. We need to be able to create sub-directories for
new modules, and we don't want to get overwhelmed by directories.
It is better to have many small modules, in many directories, than
several &quot;catch all&quot; modules in a few directories. Above all, we
need to give ourselves space.</p>
<p>We want to use the directory tree to partition the system into
recognisable chunks: all the database files in one directory, all
the logging files in another, and so on. When someone comes new to
the system each chunk is clearly defined. Of course, they still
have to understand the insides of each chunk, and how they fit
together but you are not faced with one overwhelming mass of
files.</p>
<p>The directory structure we use should map directly into the
structure used in our source code control system. The two are
closely intertwined, and although I've tried to separate the
rationale for each I can't, there is one hierarchy and it should
apply in the directory tree and in the source code control
tree.</p>
<p>Some control systems allow us to break this link and check files
out to different locations. On occasions this can be useful but if
you find you need to do this regularly you should consider why.
Your structure is lacking something. Even with the best intentions
breaking the link becomes troublesome, in the long run it is better
to come up with a solution which does not break the link between
directory hierarchy and source code hierarchy.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e123" id="d0e123"></a>Where is the
root?</h2>
</div>
<p>All trees need to be rooted somewhere and software trees are no
different. If we always refer to our directories by relative paths
we need not care where they are rooted. However, experience shows
that this eventually breaks down, at sometime we need to refer to
the absolute location of files. It is a lot easier to reason about
a path like <tt class=
"literal">/home/allan/develop/lib/include/logging</tt> than to
reason about <tt class="literal">../../../include/logging</tt> -
try shouting the latter across the room.</p>
<p>In the Unix world there is only one ultimate root, <tt class=
"literal">/</tt>, but we all have local roots, e.g. <tt class=
"literal">/home/allan</tt>. Usually our trees are rooted in our
home directory but not always. Typically we set an environment
variable to the point where our tree is rooted and append from
there, so we get <tt class=
"literal">PROJECT_ROOT=/home/allan/develop</tt>, and <tt class=
"literal">$PROJECT_ROOT/lib/include/logging</tt>.</p>
<p>(I was confused for far too long over Unix environment
variables, sometimes they just wouldn't work for me. What I was
failing to appreciate is that there are two types: shell variables,
and exported variables.)</p>
<p>In the one-root-per-disc world of Microsoft things are a little
more complex. Traditionally I would use the subst command to create
a virtual drive on my machine, this I could point wherever I liked
- it is worth putting this command in a start up script.</p>
<pre class="programlisting">
  subst w: d:\develop
</pre>
<p>Thus, each developer can have their directory tree where they
like, their C: drive, or D:, at the root, or within another
tree.</p>
<p>More recently I've moved over to the Unix way of doing things
even in the Microsoft world. As it happens .dsp project files are
happy to pick up environment variables so you can use the same
technique as in Unix.</p>
<p>Unfortunately, Microsoft has made environment variables a lot
more hassle under Windows than Unix. Unix is simple: set them in
your shell .rc file and change them at the command line. The .rc
file can be copied, e-mailed and edited easily. Under Windows, you
need to go fiddling in the control panel, and the location seems to
move slightly with each version of Windows.</p>
<p>This may seem like a lot of unnecessary work but it pays for
itself if you ever need to maintain two different development trees
on the same machine, say a maintenance version 2.1.x and the new
development 3.0.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e162" id="d0e162"></a>The External
Tree</h2>
</div>
<p>It is it increasingly unusual to find a system that doesn't use
any third party code or libraries. Whether these are commercial
libraries like RogueWave, Open Source projects like Xerces or
future standards like Boost we are increasingly dependent on code
we have not created.</p>
<div class="sidebar">
<p class="title c2">Source Code Control</p>
<p>The fact that the directory structure outlined above maps well
to a source code control system is no accident. Which came first?
The two are closely intertwined, I've tried to separate the
rationale between the two before - and failed, the two are the
same.</p>
<p>Some source code control systems, for example, Visual Source
Safe, allow you to put your source files in a check-out directory
which is different to the source control directory. For each Source
Safe repository folder containing source files, there is a
<span class="emphasis"><em>working directory</em></span>, but you
are free to have a working directory hierarchy that is completely
different to the folders directory. This doesn't work, there are
not two hierarchies, there is one, why should the hierarchy under
control be different to the one on your hard disk?</p>
<p>Normally, left to our own devices we usually keep the two
hierarchies in synch. On occasions though we face pressures that
may lead us to break the link. This frequently happens when it is
necessary to share files between two groups. Even with the best
intentions this becomes troublesome, in the long run it is better
to come up with a solution that does not break the link between
directory hierarchy and source code hierarchy.</p>
<p>Putting code in a source code control system does remove some
flexibility. I've yet to find a system which is good at renaming
and moving files. Suppose we have a static library <tt class=
"literal">Toys.lib</tt>, and suppose we decide to make it an
optional DLL, <tt class="literal">Toys.dll</tt>, so we need to
change its position in the tree. Most of the files can be used &quot;as
is&quot; but it is surprisingly difficult to move them, we may end up
adding them as completely new files and losing their history.</p>
<p>In fact, this opens up a more perplexing question: just how
should we treat those files? Sometimes we may be happy to treat
them as new, erase the long history that is getting in the way,
sometimes we may want to explicitly state the relationship.</p>
<p>The problem can be particularly bad when a file changes over
time, quite legitimately the code comes to represent something
which isn't reflected in the name. Should we change the name? The
current name may be confusing but to change it would lose its
history.</p>
<p>Worse still is what happens when we delete files. We want them
gone for good reason, but they must exist somehow so we can
reference what happened.</p>
<p>I can't provide fixed answers for these questions. Each case is
different, influenced by your source control system, your
environment and your team's attitude.</p>
</div>
<p>It is important to differentiate between in-house code, which we
have created and own the rights to, and code which is external to
our organisation. The development cycle for these two sources of
code is very different. Our own code is changing according to a
cycle which we dictate, the third party code changes whether we
want it to or not, of course, we decide if and when we accept these
changes so in the meantime the code is static.</p>
<p>Once we've decided on our root, and how we refer to it, we need
to split our directory tree to show what is ours and what is not.
Typically this means we create an <span class=
"emphasis"><em>External</em></span> directory tree which contains
third party code, e.g. <tt class=
"literal">/home/allan/develop/external</tt>, while our own code
goes in a separate tree such as <tt class=
"literal">/home/allan/develop/ProjectFire</tt>. (Sometimes the
External tree is called &quot;third party&quot; tree, but this gets confused,
is it: 3rdParty, or ThirdParty, or 3Party, where are the
capitals?)</p>
<p>Sometimes we find one external tree can be used for several
projects. This may mean we have multiple versions of the same
product in the tree, say Xerces 1.6 and Xerces 1.7. We have two
solutions here: one is to include everything in one external tree
and reference what we need, the second is multiple external trees,
we may have <tt class=
"literal">/home/allan/develop/external/v2.1</tt> and <tt class=
"literal">/home/allan/develop/external/v3.0</tt>. Which way you
jump depends on your project requirements.</p>
<p>It is not normally a good idea to try and delta one version of
an external product on top of a previous version. The complications
of new files, removed files and renamed files usually make this a
lot of effort for little reward. It is simpler to just allow
multiple versions in the tree.</p>
<p>On my current project I have environment variables for almost
everything, so I have one external tree and within that I can point
<tt class="literal">XERCES_ROOT</tt> to the version of Xerces I
need.</p>
<p>The other half of the development tree is your own source code.
You'll probably find this is dwarfed by the third party code, I
normally find that even on my biggest projects a Zip file of our
code will happily fit on a floppy disc but the third party stuff
needs its own CD.</p>
<p>Of course, life isn't quite this straightforward, you may well
have code from elsewhere in your organisation, perhaps this is
supplied by the <span class="emphasis"><em>infrastructure
team,</em></span> or the <span class="emphasis"><em>client
application group</em></span> or the New York office. Sometime
you'll want to share the tree with them, sometimes you'll want to
treat them as external code, or maybe you split your tree three
ways: external, enterprise and team. It depends on how much you
need to isolate yourself from these developers.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e233" id="d0e233"></a>Align
libraries with namespaces</h2>
</div>
<p>If you're following my guidelines from above the chances are
you've got at least one executable application, several DLLs and
lots of static libraries. Each application, DLL and library needs
its own space - that is: its own directory. Only by giving them
their own directories can you explicitly spell out what belongs
where.</p>
<p>Where static libraries are concerned you need to split the files
into two directories. Most, of the code in a static library is
contained in .cpp files (or .c, or .cxx or whatever.) This is
implementation detail. You want to put this out of the way - out of
sight, out of mind. However, the interface to the library is going
to be expose in a set of .h files, these need to be put somewhere
publicly visible, somewhere obvious, somewhere well known.</p>
<p>Traditionally we do this by creating a lib subdirectory, inside
this we would have:</p>
<pre class="programlisting">
  /lib
    /include
    /Logging
    /AccessControl
</pre>
<p>(Although most OS's now allow you to have spaces in directory
and filenames they are still best avoided, they complicate
matters.)</p>
<p>In our <tt class="literal">lib/Logging</tt> directory we would
put all files implementing our logging system, the files exposing
the public interface would be put in the lib/include directory
where we can all find them. Similarly, <tt class=
"literal">lib/AccessControl</tt> contains the implementation for
our access system, and the public interface files are also put in
<tt class="literal">lib/include</tt>.</p>
<p>Using one include directory we quickly fill it with a lot of
disparate files which adds nothing to our structural information.
We could leave them with the implementation files - but now we
can't tell what is a private, implementation only header file, and
what is a public interface file.</p>
<p>Alternatively, we could put them all in separate directories but
this could mean we end up with lots and lots of -I options on the
link line, imaging:</p>
<pre class="programlisting">
  gcc -I $PROJECT_ROOT/libs/include/Logging
      -I $PROJECT_ROOT/libs/include/AccessControl
      ....
</pre>
<p>Well who cares what it looks like? Does it really matter? No,
but, each time you add a new library you need to change your
makefile to specify the new include directory.</p>
<p>A better solution is to specify one root include directory, and
within our code specify the actual library we're interested in,
hence we get</p>
<pre class="programlisting">
  gcc -I $PROJECT_ROOT/libs/include
</pre>
<p>and</p>
<pre class="programlisting">
  // main.cpp
  #include &quot;Logging/LogManager.hpp&quot;
  #include &quot;AccessControl/AccessOptions.hpp&quot;
</pre>
<p>The real power of this comes when we align with namespaces. So,
each library has its own namespace and the namespace corresponds to
the sub-directory. Continuing the above example we get:</p>
<pre class="programlisting">
  ...
  int main(int argc, char* argv[]) {
    Logging::Logger log;
    AccessControl::User user(argv[1]);
    ...
  }
</pre>
<p>Looking back to the source tree, we should also think about
balancing it is little bit, it now seems a little lop-sided, so we
get:</p>
<pre class="programlisting">
  /lib
    /include
      /AccessControl
      /Logging
      /Utils
    /source
      /AccessControl
      /Logging
      /Utils
</pre>
<p>The extra level of directories may seem surplus but actually
helps space the project quite well. When you put this altogether
you get a very powerful technique for managing your files and
module structure, it really pays off.</p>
<p>A couple of points to note however: firstly, not all header
files will go in the <tt class="literal">/include</tt> directories.
Some don't represent an interface to the library, they are not
intended for public use so they should only exist in the <tt class=
"literal">/source</tt> directories. It is good to make a clear
distinction between what is available to the general public and
what is considered local implementation detail.</p>
<p>Second, I've taken to prefixing my header guards with the
namespace name as well, so:</p>
<pre class="programlisting">
  #ifndef ACCESSMGR_HPP
</pre>
<p>becomes:</p>
<pre class="programlisting">
  #ifndef ACCESSCONTROL_ACCESSMGR_HPP
</pre>
<p>Once you're free of thinking up completely unique filenames you
quickly find several <tt class="literal">Factory.hpp</tt> files
appearing, it doesn't really matter because one will be <tt class=
"literal">Logging/Factory</tt> and one will be <tt class=
"literal">AccessControl/Factory</tt>. However, some debuggers (OK,
I'm thinking of one from Redmond) can have problems telling the
files apart.</p>
<p>If you already think of namespaces as program modules this
technique may be obvious, if you're still thinking of namespaces as
a convenient way to avoid name clashes then you haven't realised
their full potential yet. A namespace is a C++ language module; a
static library is the natural corollary.</p>
<p>Lastly, and fairly obviously, this doesn't quite apply to
template files where the implementation must be exposed in the same
file as the interface. I'll still tend to stick with my solution
and place them in the <tt class="literal">lib/include/xxx</tt>
directory because nowhere else really makes sense. Hopefully, in
time, the C++ compiler vendors will resolve this problem, but in
the meantime systems where the majority of the code is templates
are fairly rare.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e317" id="d0e317"></a>DLLs</h2>
</div>
<p>DLLs should be treated just like static libraries, that is, I
give them a DLL directory and split this into source and includes.
DLLs are different from static libraries, the linkage rules are
different, they are used for different reasons - some people regard
use of one over the other as fairly arbitrary but with experience
you come to see them as two very different beasts.</p>
<p>One of my personal rules is to avoid subtlety in design. Let's
call it Kelly's Law of Software Subtlety:</p>
<p><span class="bold"><b>Subtlety is bad If it is different make it
obvious - Write it BIG</b></span></p>
<p>Since DLLs are different to libraries put them somewhere
else.</p>
<p>As your system grows you can easily find you have 10 or more
static libraries to manage and perhaps another 3 or 4 DLLs. If we
separate out DLLs, we give ourselves more space. There is a natural
difference here so use it.</p>
<p>We need to add another -I to our compile line, but it is just
one more, the same namespace alignment scheme can be used for DLLs
provided you don't need to specify C linkage for any of your
functions.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e333" id=
"d0e333"></a>Applications</h2>
</div>
<p>Even if your objective is to produce just one final application,
say, <tt class="literal">server.exe</tt>, the chances are you will
end up with more than one executable, even if all but one are
trivial. Executables are the top of the food chain when it comes to
source code so it pays to put them there - straight off the project
root.</p>
<p>If however, your project is going to produce many applications
you may want to avoid littering the project root with lots of
directories. In this case create a <tt class="filename"><tt class=
"literal">project_root/app</tt></tt> directory and create a
sub-directory for each on there.</p>
<p>There is no need to split header files from source files because
the application does not expose its internals like this. If you
find you need to access application files, and you see things like
<tt class="literal">#include &quot;../otherapp/widget.hpp&quot;</tt>
appearing in your code it is an indication that there is some
shared functionality that belongs in a library where it is readily
accessible to all. The directory tree is highlighting a refactoring
needed in your system.</p>
<p>On some projects you may find that one or more applications are
large enough to warrant being broken into libraries by themselves.
If so then don't hesitate, go for it!</p>
<p>Each one becomes a mini-project in its own right, apply the tree
design I've just outlined to each application. You'll probably find
some common libraries shared between them all, they stay where they
are, but for a large application it should have its own library
structure. This is just recursion, apply the pattern over again
taking the application's directory as your new root.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e356" id="d0e356"></a>Putting it
together</h2>
</div>
<p>You'll probably find that you have other stuff which needs to be
in the tree, makefiles, documentation and such. Where these belong
to a component, say documentation for your logging library, then
place the documents same directory as the library. Where they are
common, say system documentation, place them in a docs directory
from the root - if necessary divide it.</p>
<p>In the case of makefiles you'll find that some are common and
need to be placed in a well known place in the tree, but most are
specific to individual elements - indeed each library, dll,
application, should have its own.</p>
<p>Your source tree should now be looking something like this:</p>
<pre class="programlisting">
  $project_root
    /apps
      /repairtool
      /server
      /testtool
    /dlls
      /include
        /BlueWidgets
        /RedWidgets
      /source
        /BlueWidgets
        /RedWidget
      /docs
    /libs
      /include
        /AccessControl
        /Logging
        /Utils
      /source
        /AccessControl
        /Logging
        /Utils
    /make
</pre>
<p>At first sight this may seem a bit excessive, but the important
point is it gives you space, it gives you organisation, you are
free to do what you like in any sub-directory and it won't
interfere with another. This model will scale, we are building in
depth for extendibility.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e369" id="d0e369"></a>External tree
and source control</h2>
</div>
<p>Nor do I have a good answer for the question &quot;Do we check in the
external tree?&quot; There are three possible answers here:</p>
<div class="orderedlist">
<ol type="1">
<li>
<p>Check nothing in: the code has come from elsewhere, you can
always get it again, download it, install from CD. Maybe you want
to burn some CDs with downloads on so you can always get old
versions. Of course, what happens when you fix a bug in external
code? I once found a fault in the ACE library, I devised a fix and
contributed it back but it was several months before a version of
ACE was released with my fix. In the meantime we checked-in my fix
to our ACE copy in CVS and carried on working.</p>
</li>
<li>
<p>Check in source code: if you have the source code you can
recreate the binaries, this will save people having to locate
several dozen different resources. And it helps when you make a
change to external code. However, each developer needs their own
copies of the binaries - access over a network to a common store
can substantially slow compile time - but it can be quite time
consuming to build lots of third party libraries.</p>
</li>
<li>
<p>Check in source and binaries: source control systems aren't
really built for binaries and they rapidly bloat when you check in
everything, and if we do then developers need even bigger hard
discs to get trees containing lots of stuff they don't actually
want.</p>
</li>
</ol>
</div>
<p>Nor does the external tree contain all the third party products
in your system. Do you check in your compiler? Perl? Your OS?</p>
<p>Source control is not confined to your source code control
system, it should encompass all the elements needed by your system:
compilers, OS, patches, etc, etc. It is unrealistic to put
everything under source control so you need to look elsewhere.</p>
<p>The best solution I know to this dilemma is:</p>
<div class="orderedlist">
<ol type="1">
<li>
<p>Only check in source code, this means you can tinker with Boost,
ACE, or whatever as you need to.</p>
</li>
<li>
<p>Build the binaries under clean conditions - as you would your
own source but place it somewhere generally available, say a Samba
drive. This is a kind of cache and ensures that everyone is using
the same thing and saves everyone rebuilding it. Some people may
care to place some of this stuff on their local hard disc.</p>
</li>
<li>
<p>Burn CD copies of all third party product used to build your
system, be they libraries, compilers or whatever, and put them in a
safe, well known location.</p>
</li>
</ol>
</div>
<p>The objective is: to be able to take a new machine and only use
what is in the cupboard and source code control be able to build
your entire system.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e402" id=
"d0e402"></a>Conclusion</h2>
</div>
<p>Our directory structure affects our source code. At the simplest
level this is shown in our makefiles, makefiles are the glue that
links the two, makefiles explain how to integrate the system.
Directory trees always have an effect on code, rather than hide
this detail we should use it to our advantage. The directory tree
can encode important details about the system structure and
organisation, and its extension points.</p>
<p>Much comes down to your work environment, your schedule, your
team, but these issues are important. The ideas I've laid out come
up again and again, each team will have slightly different needs
but all solutions exhibit a general similarity.</p>
<p>Above all you need to actively organise your source code,
external tools and resources. These things don't just happen. This
organisation is an integral part of your software development
strategy and helps communication.</p>
</div>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
