Java or C++?
danb_83 at yahoo.com
Tue Apr 22 04:19:42 CEST 2008
On Apr 21, 5:26 pm, Jorgen Grahn <grahn+n... at snipabacken.se> wrote:
> On Mon, 21 Apr 2008 06:14:08 -0700 (PDT), NickC <ncogh... at gmail.com> wrote:
> > On Apr 15, 1:46 pm, Brian Vanderburg II <BrianVanderbu... at aim.com>
> > wrote:
> >> This will automatically call the constructors of any contained objects
> >> to initialize the string. The implicit assignment operator
> >> automatically performs the assignment of any contained objects.
> >> Destruction is also automatic. When 'p1' goes out of scope, during the
> >> destructor the destructor for all contained objects is called.
> > Yeah, C++ does try to be helpful, and all of those automatic copy
> > constructor, assignment operator and destructor implementations screw
> > up royally when confronted with pointers
> I think that those are newbie problems. The rules for those three
> "default implementations" are simple and match what C does for
> structs. Use the standard containers, make a habit of forbidding
> copying of objects which make no sense copying, and remember the
> "explicit" keyword, and you will rarely have problems with this.
Yes, but why should you have to remember? Wouldn't it be less error-
prone to make objects uncopyable and constructors explicit unless
stated otherwise? (Yes, default implementations for structs had to
match C, but "class" was a new keyword.)
> > Other things like methods (including destructors!) being non-virtual
> > by default also make C++ code annoyingly easy to get wrong (without it
> > obviously looking wrong).
> The other side of the coin is that you can write tiny classes in C++
> with *no overhead*. If my class Foo can be implemented as an integer,
> it doesn't need to be slower or take more space than an integer. It
> can have value semantics, live on the stack etc, like an integer.
> I assume Java programmers avoid such types, and I assume it decreases
> type safety in their programs.
I haven't written in Java since version 1.3, so maybe things have
changed. But last time I checked, if you want tiny value-semantics
types in Java, you're stuck with the built-in ones. One of my biggest
gripes about that language.
More information about the Python-list