Embrace the from template?

Jonathan Marler johnnymarler at gmail.com
Fri Aug 24 06:41:35 UTC 2018


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.




More information about the Digitalmars-d mailing list