Am 28.04.2011 10:28, schrieb Jacob Carlborg:
On 2011-04-27 22:28, Daniel Gibson wrote:
Am 27.04.2011 22:13, schrieb so:
One thing that is perhaps obvious, but eludes me; when dropping the
delete-operator, are there any obvious reason to not also drop the
"new" keyword? ("new" is a fairly good method/variable name, if
nothing else)

I could see two possible alternatives:

Global (and defined-by-default) template new!(Type): (as suggested
elsewhere in this thread by so)
This is very close to the current situation, but makes it possible
to use as a method-name, and clearly states there's nothing "magic"
about it.

Explicit Allocator, such as GC.new!(Type).
Would have the benefit of clearly showing who did the allocation,
and would map nicely to other allocators. (Malloc.new/free!(T)!(T)).

It would also allow library-methods that might allocate instances,
take an allocator as an optional template argument. I.E.
auto obj = dict.createObject("key");
OR
auto obj = dict.createObject!(Malloc)("key");
scope(exit) Malloc.free(obj);

Possibly an obvious bad idea, but I haven't seen it discussed?

Regards
/ Ulrik

With the deprecated "delete", custom allocators and such i don't see
much of a reason other than saving an "!" (actually we don't save a char
here, " " also a char :) ), and "()" if you are calling the default
constructor. I don't consider these points negative, quite contrary, you
just got rid of an arcane syntax.

It is understandable for C++ has it. If nothing else, the lack of many
basic features (maybe the reason of this syntax).

Rather then removing all together, i would drop them from language and
go for a library solution, if there is an obvious blocker, i also fail
to see it :)

It'd create template bloat and uglier syntax (expecially confusing for
people coming from about any other popular OO language) for a really
common, standard feature.
These drawbacks are acceptable for custom allocation and other stuff the
average user shouldn't care about, but not for an elemental feature like
"new".

Cheers,
- Daniel

Ruby uses "ClassName.new" to create a new instance and Objective-C uses
"[[ClassName alloc] init]". Not all languages use "new ClassName".


Ok. And probably Python doesn't as well.
However D has this C/C++/Java/C# like syntax (Objective-C probably has that as well, but anyway), i.e. curly braces for blocks, C-like syntax for functions, try {..} catch(Foo f) {..} (yeah I know C doesn't have that, but no alternative different syntax either), ... so IMHO it makes sense for D to have the same syntax as the majority of these languages for the same feature (if that syntax doesn't have big enough drawbacks like <> for templates).

Cheers,
- Daniel

Reply via email to