Why not use package structure from java?

M

mlt

Why does c++ not support packing modules into packages like in java? Its way
more easy to work with large scale applications in this way. Would that be
possible in the future with c++?
 
A

Alf P. Steinbach

* mlt:
Why does c++ not support packing modules into packages like in java?

I think you mean, "Why does C++ not support modules a.k.a. packages like in Java?".

Because C++ is a much earlier language. The idea of modules started AFAIK in the
late 1960's with Niklaus Wirth's Modula language (preceding his Pascal in 1971,
which didn't have modules and was more of a toy language intended for students
to be able to compile by hand, which they did, but which aspect was lost when
education went down the drain), and he built on that further when creating
Modula-2 and then Oberon. And the idea was incorporated in more practical
variants of Pascal such as UCSD Pascal, there called "units", and in Ada, there
called "packages". Then in Eiffel the ideas of class and module were merged.

Original Java, in spite of what even its designers claim, was essentially a
minimalistic stripped down Eiffel re-expressed with more familiar-to-most C-like
syntax, but in a way just as ironic as the devolution to primitive C syntax the
clean module concept in Eiffel was devolved backwards to the earlier more
primitive package concept. I think Java's popularity and Eiffel's niche status
speaks volumes about how important familiarity is. Eiffel is without a doubt the
more powerful and more clean language, but at this point it's not a practical
choice over Java since Java now has an enormous, very rich "standard" library.

C++ inherited the C separate compilation and header file way of "manually"
creating logical modules, and so the need for language supported modules in C++
wasn't pressing at that time, around 1980 -- but now it is. And it's not a
small problem. For example, a fully general module facility should allow for
separate compilation of templates, but C++ already has a language feature for
that, namely "export" that only 1 compiler implements, that stands in the way.

Its way
more easy to work with large scale applications in this way. Would that be
possible in the future with c++?

David Vandevoorde made a modules proposal but it came too late for C++0x.

It will however most probably be considered, possibly amended, and adopted, later.


Cheers & hth.,

- Alf
 
N

Nathan Stoddard

Why does c++ not support packing modules into packages like in java? Its
way more easy to work with large scale applications in this way. Would
that be possible in the future with c++?

The C++ equivalent of packages is namespaces. They're not exactly alike,
but they are similar.
 
A

Alf P. Steinbach

* Nathan Stoddard:
The C++ equivalent of packages is namespaces. They're not exactly alike,
but they are similar.

No, that's just a very superficial syntactical similarity: don't confuse the two.

Modules have to do with separate compilation and modular design.

Namespaces have nothing to do with separate compilation and have only a very
tenuous connection to modular design.

Java packages form hierarchies that correspond to directories, C++ namespaces
form hierarchies that don't have any relation to physical packaging.

To implement logical modules in C++ you use namespaces for the logical
packaging, and header files plus possibly separate compilation for the physical
packaging. You do not get the benefit of direct support for any of this. There
is nothing like Java packages in current C++; in particular, namespaces are not.

Cheers & hth.,

- Alf
 
M

Michael Doubez

* mlt:
Why does c++ not support packing modules into packages like in java?
[snip]
David Vandevoorde made a modules proposal but it came too late for C++0x.

It will however most probably be considered, possibly amended, and adopted, later.

My understanding was that it had been voted out.
Is it really just a matter of timing ?
 
J

James Kanze

* mlt:
Why does c++ not support packing modules into packages
like in java?
[snip]
David Vandevoorde made a modules proposal but it came too
late for C++0x.
It will however most probably be considered, possibly
amended, and adopted, later.
My understanding was that it had been voted out. Is it really
just a matter of timing ?

Mostly. It wasn't "voted out", but voted to be deferred.

Note that the proposal does not resemble Java's packages in the
least---Java's packages really aren't any more than C++
namespaces. The proposal was for a real module system, like in
Modula-2.

With regards to the original poster's question: C++ already
supports almost everything that Java does in this regard, and
more. About the only thing that's missing is package access
rights (and these don't work in Java anyway). Other than that,
namespaces are an almost exact equivalent of package in Java,
with "using Namespace::Class" the same as "import
Package.Class", and "using namespace Namespace" the same as
"import Namespace.*". Except, of course, that in C++, you can
restrict the visibility of the "import" to any desired scope.
 
J

James Kanze

* Nathan Stoddard:
No, that's just a very superficial syntactical similarity:
don't confuse the two.

No. The C++ equivalent of packages is namespaces. The two are
very similar.
Modules have to do with separate compilation and modular
design.

Agreed. But Java's packages have nothing to do with modules.
(Java's classes do behave like a module in some ways.)
Namespaces have nothing to do with separate compilation and
have only a very tenuous connection to modular design.
Java packages form hierarchies that correspond to directories,
C++ namespaces form hierarchies that don't have any relation
to physical packaging.

Unless you want them to. Java imposes a file organization on
you, whether it corresponds to anything logical or not. C++
leaves it up to you. Typically, in C++, it's not an issue,
since you're not required to link every single class
dynamically.
To implement logical modules in C++ you use namespaces for the
logical packaging, and header files plus possibly separate
compilation for the physical packaging. You do not get the
benefit of direct support for any of this. There is nothing
like Java packages in current C++; in particular, namespaces
are not.

There's no real direct support for anything resembling modules
in Java, either. There are a few constraints concerning file
organization (that aren't relevant to modules), but otherwise,
nothing.
 
C

Christof Donat

Hi,
Why does c++ not support packing modules into packages like in java?
Its way more easy to work with large scale applications in this way.
Would that be possible in the future with c++?

What exactly do you expect from Java like Packages that you can not get
with C++?

Christof
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,159
Messages
2,570,879
Members
47,414
Latest member
GayleWedel

Latest Threads

Top