🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: rec.games.programmer
Article #2020

Re: Should I learn C or C++ first?

#2020
From: Matt Austern
Date: Tue, 29 Aug 1995 19:56
26 lines
2107 bytes
In article <41vlgv$q33@druid.borland.com> pete@borland.com (Pete Becker) writes:

> >:       Or, to turn the question around the other way, why separate them?
> >
> >Obviously when using an array where each object is initialized to a
> >different value.  Especially a resizable array.
> 
> That's not the example you posted, which allocated a single
> object. So, let me ask again: in the code you posted, what benefit
> is there in separating allocation from initialization?

There occasionally are benefits; that's why placement operator new and
explicit destructor calls exist.  A lot of container classes use those
features, for example.  (Not that Pete needs lectures from anyone else
about container class libraries.)  

Needless to say, though, I'm happiest when low-level stuff like this
is nicely encapsulated away deep in the guts of some class where I'll
never see it.  Storage allocation and initialization are naturally two
parts of creating a new object, and it's best to keep them together.
In fact, even operator new is a bit too low level for my tastes, and I
prefer to encapsulate it, too, whenever possible.
-- 
  Matt Austern                             He showed his lower teeth.  "We 
  matt@physics.berkeley.edu                all have flaws," he said, "and 
  http://dogbert.lbl.gov/~matt             mine is being wicked."
Technical Details
Message-ID: <MATT.95Aug29125655@godzilla.EECS.Berkeley.EDU>
Path: arc1-ca.pugleaf.net!howland.reston.ans.net!agate!agate!matt
References: <DDJ2Lp.3DG@pentagon-ai.army.mil> <41afe9$d10@newsbf02.news.aol.com> <41kici$p4t@deyke3.fc.hp.com> <41ngln$qau@druid.borland.com> <41tjep$2hn@deyke3.fc.hp.com> <41vlgv$q33@druid.borland.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!howland.reston.ans.net!agate!agate!matt
From: matt@godzilla.EECS.Berkeley.EDU (Matt Austern)
Newsgroups: rec.games.programmer,comp.lang.c++
Subject: Re: Should I learn C or C++ first?
Date: 29 Aug 1995 19:56:55 GMT
Organization: University of California at Berkeley (computational neuroscience)
Message-ID: <MATT.95Aug29125655@godzilla.EECS.Berkeley.EDU>
References: <DDJ2Lp.3DG@pentagon-ai.army.mil>
 <41afe9$d10@newsbf02.news.aol.com> <41kici$p4t@deyke3.fc.hp.com>
 <41ngln$qau@druid.borland.com> <41tjep$2hn@deyke3.fc.hp.com>
 <41vlgv$q33@druid.borland.com>
Reply-To: matt@physics.berkeley.edu
NNTP-Posting-Host: godzilla.eecs.berkeley.edu
In-reply-to: pete@borland.com's message of 29 Aug 1995 18:15:59 GMT