www.digitalmars.com         C & C++   DMDScript  

D - private imports

reply "Dario" <supdar yahoo.com> writes:
Has anyone already thought about private imports. They can be useful when we
want a module to import another one, but don't want this module to import
any symbols in the module that import it.

Here is an example:

--- tokenization.d ---
private import ctype;

Token[] toTokens(char[] source)
{ /* code which use ctype's functions */ }

--- main.d ---
import tokenization;

int main()
{ /* code which use toTokens() */ }

So if the main module wants to use ctype's functions it have to import ctype
itself. This will cause the user to have less chances to make ambiguity
mistakes.

The fewer symbols are valid in a module the fewer ambiguity errors the
programmer will get.
The fewer errors the programmer will get the more easier programming will be
(IMO, ambiguity errors are usually frustrating because they can be boring to
correct).
Sep 22 2002
parent "Walter" <walter digitalmars.com> writes:
It's a good idea.

"Dario" <supdar yahoo.com> wrote in message
news:amkdqi$1kb8$1 digitaldaemon.com...
 Has anyone already thought about private imports. They can be useful when

 want a module to import another one, but don't want this module to import
 any symbols in the module that import it.

Sep 22 2002