title: Should I put many functions into one file? Or, more or less, one function per file?
body: <p>I love to organize my code, so ideally I want one class per file or, when I have non-member functions, one function per file.</p>
  
  <p>The reasons are:</p>
  
  <ol>
  <li><p>When I read the code I will always
  know in what file I should find a
  certain function or class. </p></li>
  <li><p>If it's one class or one non-member
  function per header file, then I won't
  include a whole mess when I
  <code>include</code> a header file.</p></li>
  <li><p>If I make a small change in a function then only that function will have to be recompiled.</p></li>
  </ol>
  
  <p>However, splitting everything up into many header and many implementation files can considerately slow down compilation. In my project, most functions access a certain number of templated other library functions. So that code will be compiled over and over, once for each implementation file. Compiling my whole project currently takes 45 minutes or so on one machine. There are about 50 object files, and each one uses the same expensive-to-compile headers. </p>
  
  <p>Maybe, is it acceptable to have one class (or non-member function) per <em>header</em> file, but putting the implementations of many or all of these functions into <em>one</em> implementation file, like in the following example?</p>
  
  <pre><code>// foo.h
  void foo(int n);
  
  // bar.h
  void bar(double d);
  
  // foobar.cpp
  #include &lt;vector&gt;
  void foo(int n) { std::vector&lt;int&gt; v; ... }
  void bar(double d) { std::vector&lt;int&gt; w; ... }
  </code></pre>
  
  <p>Again, the advantage would be that I can include just the foo function or just the bar function, and compilation of the whole project will be faster because <code>foobar.cpp</code> is <em>one</em> file, so the <code>std::vector&lt;int&gt;</code> (which is just an example here for some other expensive-to-compile templated construction) has to be compiled in only once, as opposed to twice if I compiled a <code>foo.cpp</code> and <code>bar.cpp</code> separately. Of course, my reason (3) above is not valid for this scenario: After just changing foo(){...} I have to recompile the whole, potentially big, file <code>foobar.cpp</code>. </p>
  
  <p>I'm curious what your opinions are!</p>