On Friday, 24 August 2018 at 06:41:35 UTC, Jonathan Marler wrote:
Ever since I read
https://dlang.org/blog/2017/02/13/a-new-import-idiom/ I've very
much enjoyed using the new `from` template. It unlocks new
idioms in D and have been so useful that I thought it might be
a good addition to the core language. I've found that having
it in a different place in each project and always having to
remember to import it makes it much less ubiquitous for me.
One idea is we could add this template to `object.d`. This
would allow it to be used from any module that uses druntime
without having to import it first. The template itself is also
very friendly to "bloat" because it only has a single input
parameter which is just a string, extremely easy to memoize.
Also, unless it is instantiated, adding it to object.d will
have virtually no overhead (just a few AST nodes which would
dwarfed by what's already in object.d). It would also be very
easy to add, a single PR with 4 lines of code to druntime and
we're done.
Of course, if we don't want to encourage use of the `from`
template then this is not what we'd want. Does anyone have any
data/experience with from? All I know is my own usage so feel
free to chime in with yours.
There's no reason to mess with `object.d` or add it to phobos.
Just make a dub package and use it!
I just published it on the dub registry in public domain (I hope
Daniel Nielsen is ok with that. After all, it's just 3 lines of
code)
Package page: https://from.dub.pm/
Have a good day and don't overthink simple things,
Anton