Hi all,
I'll try to explain shortly how I see the fileless C++ environment working:
- There are no .h, *.cpp files etc.
- Classes, namespaces, functions etc. and their relations are stored in a
database
- When editing a C++ entity, you only see the code of that entity.
- There is no 'include' preprocessor command, or at least it is not used to
add C++ entities to the program.
- To use some external C++ entity in your program (like a standard library
class), you 'tell' the system that your program uses that entity. You don't
include anything. In a GUI environment this would be probably accomplished
by drag&dropping a name from available entities list into the project, or
something like that.
- To compile the program, the system generates a properly ordered sequence
of all C++ entities you used, and passes this to the compiler. If proper
ordering cannot be found, it means that there are circular references in the
program, and this is just an error.
- If the output sequence is temporarily stored in a file just before
invoking the compiler, there's no need for special compiling tools - an
ordinary file-based compiler can be used.
- To define a sub-entity (a nested class for example) you define a separate
entity, and 'tell' the environment that it is nested in some other. You
don't write class inside class (or if you do so, the environment will
automatically remove it from there).
I'm interested in this kind of environment, because I worked a lot with fair
sized file-based C++ projects, and I find the filesystem a nuisance. There's
an issue of how to split your source code between the files, and then how to
name them. In most cases I would like to have my files named by the names of
C++ entities, and have one entity in one file. But this is not always
possible (see example at the bottom). It usually causes problems where
classes and namespaces are nested inside each other. In this case I used to
split the source files between directories, mimicking the hierarchy of their
nesting in the project (i.e. I usually had a separate dir for each namespace
etc.). But this generally does not work good, because filesystem hierarchy
is something _different_ than C++ hierarchy.
As far as I remember, B. Stroustrup in one of his books (either in TC++PL or
in 'The Design and Evolution of C++') wrote that it's not neccesary for a
C++ program to be stored in files. I don't know if there's anything in the
C++ standard which makes this obligatory?
Example where class B cannot be defined in other file than class A, unless a
weird #include-in-the-middle-of-class is used:
class A {
class B { };
B b;
};
Best regards,
Marcin