D community's view on syntactic sugar
Sjoerd Nijboer
sjoerdnijboer at gmail.com
Thu Jun 21 22:18:51 UTC 2018
On Sunday, 17 June 2018 at 16:52:59 UTC, Neia Neutuladh wrote:
I agree with you for the whole bunch.
Except this one
> allocator.make!Foo(args)
> new!allocator Foo(args)
>
> One character difference. Doesn't seem like a big deal.
new is a keyword in D right now which gcallocs an object and
emplaces a T on top of it.
make does thesame thing, but you can pass it any allocator you
want.
allocating and emplacing a type is so often done that you might
want a keyword for it.
Why not unify these two?
Seems like there's now a duplicate way to do thesame thing in the
language standard.
Even worse, new has a strictly defined meaning accross a lot of
languages, while make doesn't.
Its just an oddity right now.
But my biggest reason to unify it is to do something different,
introducing a feature where one could get the allocator with
which the current class has been instantiated, and allow the
current class to allocate and conditional deallocate if
neccesarily with that one. This would allow gc code to be @nogc
depending on the used allocator. Overloading `new` for this, and
retaining the default behaviour would allow current code to be
relatively easily converted, and for gc allocator dependant
libraries a calculated find and replace would allow conversion to
different gc allocators... but that's a different story. (Mainly
just an idealistic wish from me.)
My main reason to start this threat was to see if there was
spirit to add syntactic sugar as a language feature.
And it quite provided in that goal.
While adding sugar as libraries using mixins isn't my preference
and as far as I think should be used as a last resort, it is
something I haven't explored before.
I also understand that some things aren't neccesarily good
candidates of syntactic sugars, but these were some examples I
could come up with quite easily at the time.
All with all I like D and the community for the level of talk
behind the language design.
It is something I haven't seen before around a language quite
like this. :)
More information about the Digitalmars-d
mailing list