[rust-dev] Placement new and the loss of `new` to keywords
Patrick Walton
pcwalton at mozilla.com
Tue Dec 3 00:41:17 PST 2013
On 12/3/13 12:34 AM, Val Markovic wrote:
> This is an interesting thread. A few points:
>
> - "box" makes a lot more sense than "new"; as others have pointed out,
> the latter maps to a different concept in C++ which makes it familiar in
> the worst way.
> - "Foo::init" is terrible, agreed, but "Foo::new" is less than ideal as
> well. "Foo::create" might be better. Just read this aloud: "this
> function news a value." What? That makes no sense. "This function
> creates a value." Much better, isn't it? Point being, it should be a
> verb. JavaScript does it with Object.create, so there's precedent.
> - placement new might be common in Servo and browser engines, but it's
> not that common in most C++. After 10 years and 200k+ LOC of C++ across
> many, many different programs and paradigms I've yet to use it once.
> Sure, that's just one person's experience but others seem to be echoing
> the same sentiment. I'm not saying let's not have placement new, just
> that we shouldn't put on an undeserved pedestal.
Rust and C++ are different. You don't use placement `new` for
`shared_ptr` in C++; however, you will use placement `new` (or `box`)
for `RC` in Rust (the equivalent). For this reason I suspect that
placement `new` will be much commoner in Rust than in C++.
Patrick
More information about the Rust-dev
mailing list