C++ and the packages

Hey,

In general, the C++ files are organized as follow :

/include
/src

with many many files in the same directories, and sometimes some additional others directories

In Java, we use the package principle, and the source are often better organized.

I want to try to organize the C++ file like the Java file, i.e. using the package principle.
I don't know if it is a good idea, and if it is a good think for C++.
We need to change the oll C++ developers reflex (It is difficult), but I hope that it is a
good think.

Some peoples have said that they prefer to organize like the C++ way, because when
we have many many file, they will gain some time in the compilation. I'm not sure that
it is a good argument.

Does someone have comment about this ?

And the question is :

is it better to arrange the file like the old C way
or the new Java way for C++ projects ... ?

Demez Christophe

Products Manager
DigitalWave
cdemezAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dhymesCommented:
Well let us face the facts Java and C++ are two different monsters even if they are syntactically almost the same. The organization of your C++ files can be arranged anyway you want them providing you customize your makefile to organize them as such.

One way to do this would be to put all of your common source files under a common directory. Create a makefile for each directory. Then to build the whole package or library or ..... create a master makefile that will go out to each directory and do a make.

Regards,
Dave
0
nietodCommented:
Is there a question here?
0
dhymesCommented:
I believe the question is, how do you arrange your C++ source code in the same manner as you would a Java Package. I hope that is what was asked!!??
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

cdemezAuthor Commented:
Edited text of question.
0
nietodCommented:
cdemez, please don't edit the question once it has been commented on.  it makes it hard for other experts to follow the "dialog".

I don't know enough about java and these packages to be of any help, but If you are just talking about what directory in which to put source code files, that is really up too you, just doing it as you see fit. If you are talking about where in the source code file to place a #include, again that is up to you.  If there is more to it than that...
0
dhymesCommented:
For a C++ project, in my opinion (many opinions out there), it is better to put all of the files for a particulare project within the same directory.

For instance. If you create a project called tools and you would like tools to be available anywhere, then you could create a tools library. Now, anyone that wants to use objects from your tools library should only need to include your tools header file and link in the library. So, I would create a directory called tools and put all of my tools source code in that directory.

Now, maybe I have a NetworkDevice class that I would also like to make public to the world, so I would simply create a NetworkDevice directory and include all of my class files within this directory.

Some people like to include a subdirectory for all of the header files to keep the source files seperate from the header files. In Java you don't need to worry about this. So, it is up to you, for your header files *.h you can put them in the same directory or create a seperate directory to keep them all bundled together.

Hope this helps,
Dave
0
dhymesCommented:
Ya, this is not the same in JAVA. If you want to create a package in java you have to name the directory  MyDir and in each java source file include the "package MyDir" directive to tell the Java virtual compiler what package the source file belongs to. There are no simulare constructs in C++ since everything get compiled and linked together.

Mmm, can't think of anything else.
0
ramshakalCommented:
If you want to achieve same functionality as package then first know that

(1)To make classes easier to find and use, to avoid naming conflicts, and to control access, programmers bundle  groups of related classes into packages
(2) A package is a collection of related classes and interfaces that provides access protection and namespace management.

All the above people told you about how to orgainze your files in directories. But package is different than that. Look into the term NAMING CONFLICTS, CONTROL ACCESS and NAMESPACE management.
       The analogous construction to the package mechanism in C++ is the namespace (NAMESPACE) feature. Think of the package and import keyword in Java as the analogous of the namespace and using directive in C++.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.