Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Separate "include" and "src" folders for application-level code? [closed]

This questions concerns mostly Unix/Linux style C++ development. I see that many C++ libraries store their header files in a "include" folder and source files in an "src" folder. For the sake of conformance I adopted this in my own code. But it is not clear to me whether this should be done for application code as well. I've seen a few cases where a flat directory structure is used for that. What would be the recommended approach?

like image 369
StackedCrooked Avatar asked May 27 '10 19:05

StackedCrooked


People also ask

Should header files be in separate folder?

It keeps your folder structure cleaner. Headers and source files are distinctly different, and are used for different things, so it makes sense to separate them.

What is src folder in Python?

“src” folder includes python files (e.g. *. py) and it should be used in production. All preprocessing logic, prediction logic should be store in here. “notebook” files which is created during experiment.

What should I put in my src folder?

The /src folder is used to store the file with the primary purpose of reading (and/or editing) the code. The /src folder contains all the sources, i.e. the code which is required to be manipulated before it can be used.

What is src folder in Java project?

Describes the Java™ source tree. When you create an API project, it is set up as a Java project with separate folders for source and class files. The source folder is named src .


2 Answers

I also separate them, but not strictly on the extension, but on the access of the file.

Suppose you have a module that manages customer information and uses 2 classes to do this: Customer, CustomerValidityChecker. Also suppose that other parts in your application only need to know about the Customer class, and that the CustomerValidityChecker is only used by the Customer class to perform some checking. Based on these assumptions I store the files like this:

Public folder (or include folder):

  • customer.h

Private folder (or source folder):

  • customer.cpp
  • customervaliditychecker.h
  • customervaliditychecker.cpp

That way, it becomes immediately clear for callers of your module which parts are accessible (public) and which parts aren't.

like image 139
Patrick Avatar answered Sep 21 '22 04:09

Patrick


We have a build system that auto-generates our makefiles. One thing it does is recursively descend any subdirectories and build them as libraries, linking them together with the main directory's objects to make the application. (In practice, these "subdirectories" are usually symbolic links.) Libraries are static unless the directory name ends in ".so". One thing that's nice about this is that a full build of our system, which has many executables, doesn't have to repeatedly compile the common libraries.

However, as a result of this, there's no separation of headers and sources. And it has never been a problem. Honestly, I think it's better this way because headers and source files have commonality of location, and you can grab a directory and know you got everything you need to use it. It also works great with Subversion's "externals" feature, and similar features in other VCSs.

One last place where an include/src separation fails is if you use any code generators, such as flex, bison, or gengetopts. Figuring out where these tools should put their outputs so they get built is tricky if you've spread things out.

like image 24
Mike DeSimone Avatar answered Sep 18 '22 04:09

Mike DeSimone