New guideline to place import statements as locally as possible
monarch_dodra
monarchdodra at gmail.com
Fri Mar 21 01:05:08 PDT 2014
On Friday, 21 March 2014 at 07:24:43 UTC, Steve Teale wrote:
> Can someone tell me where this is written up?
>
> Thanks
> Steve
You mean generally, or in phobos?
The rational in phobos is that since it is heavily templated, it
makes sense to pull the imports on a "as needed" basis.
If we placed all the imports needed *anywhere* in the module at
the top, in *all* modules, then importing *anything* in std would
import the world.
for example, something as "dumb" as TypeTuple:
=> need std.typetuple
=> pulls traits
=> pulls typecons and algorithm
=> pulls array, string, uni, ascii, utf, conv
=> pulls everything remaining
The new scheme allows massively reducing these dependencies. At
least, that's the point. cross-module aliasing, and template
constraints tend to make this as smooth as we'd like it.
In end user code, or in non-template code, there is less rational
for doing this. At that point, it only becomes a style, issue, of
whether or not you want to "pollute" your namespace with imported
symbols.
More information about the Digitalmars-d
mailing list