$ git init myproject
$ cd myproject
$ ...
$ ./profit

Thinking of a name, making the directory, putting it under revision control, firing up your editor -- all this is easy. Imagining the endgame where your users get to use the result of all your work is a little harder. What's really hard is all that ... in the middle. Deciding what bits of your project go where can be a toughie though, unless you're lucky enough to already know where things ought to go, it can be a bit of a nightmare.

Fortunately for most generalised kinds of projects there will be one or more recommended layouts for your codebase, just like there's a standard for the over-all filesystem heirarchy. Let's explore a few of these...

Generic C/C++ project

Typically a generic C/C++ project will have a hierarchy akin to:

  Makefile / configure.ac / CMakeLists / Whatever
    your C and C++ files go here, and headers private to the program
    C and C++ files, for libmyproject go here
    header files for libmyproject go here

This isn't strict, and more complex projects will usually deviate in interesting ways from this, but it's a good start for a basic project.

Python Modules and programs

Python modules and programs often have a standardised shape too, in part because of the utilities which exist for preparing them:

    all your shiny library files in here, __init__.py etc.

Again, while not strict, the python distutils define a number of expectations which when met make life easier for the budding pythonista.


There are a number of 'standard' build systems for Java, but I'll show you the layout I've learned which seems to be common for gradle built apps of the kind I've played with, with IntelliJ IDEA as the IDE.

  build.gradle settings.gradle gradlew etc. (gradle stuff)
    in here goes some magic to make gradle work
  myproject.ipr etc (IntelliJ stuff)
          Your java files go here
        Your resources go here


Clearly the above do not encompass every kind of project, nor do they accurately represent all instances of the generalised kinds of project they claim to be; however they are good starting points if you are beginning a project and you're not sure quite how to lay it out. In a lot of cases, the general layout is dictated by the standardised tools for building such projects, and in that case it would behoove you to follow the standard for such tools as you choose to use.

Of course, which build tools you choose is another aesthetic (and functional) decision, and we'll perhaps cover that in a future article.

Ultimately what matters is that, for your project, your layout is logical and does not introduce difficulty when locating parts of the source. If necessary you can have a document in your source tree explaining where things are. So long as you stick to your layout consistently, noone will be overly upset if things are not quite as they expected.

P.S. I tried to include Go here, but it just made me feel sick so I gave up, sorry.

P.P.S. No, I never claimed to be non-partisan here.

In my experience, the layout that you've shown for Java (with the exception of the gradle specific parts) is by far the most common layout. I'd go so far as to say that it's the definitive standard. It was made popular by Maven.

IMHO the post would profit from information about placement of (unit) tests. For Java with the standard layout, you would place tests in src/test/java and test resources in src/test/resources.

Comment by www.cloudid.de/?user=a47602f3eec8afceacef3dd015129173fa461fb1 Wed Jun 3 19:03:04 2015