www.digitalmars.com         C & C++   DMDScript  

D - "from module import element"

reply Jon Thoroddsen <Jon_member pathlink.com> writes:
I propose that we should be able to import only part of the module symbols using
the syntax

from c.stdio import printf

this makes things more explicit when we want just a little bit of the module
anyway, easier to find the module that the symbol is from, and possibly a
smaller executable.


I also propose that when you do

import module

you can only access the symbols through the module namespace. ie

yada = module.func()

If you can't live with the typing, you can always make an alias. You could also
use the "from .." syntax above.

Why? Makes it easier for programmers to find the source of a (class, funciton,
whatever) when maintaining code.

This is all Pythonesque BTW.
There was a thing in Python like this:

from module import *

which imported all the symbols from a module much like "import module" in D is
now. This has now been deprecated, because even though it saved typing at the
time, people found that it made maintenace much more difficult and rallied
against it :-)

This would also make it much easier for IDEs to take you directly to the source
of some function, same as humans.
Dec 04 2003
parent reply J Anderson <REMOVEanderson badmama.com.au> writes:
Jon Thoroddsen wrote:

I propose that we should be able to import only part of the module symbols using
the syntax

from c.stdio import printf

this makes things more explicit when we want just a little bit of the module
anyway, easier to find the module that the symbol is from, and possibly a
smaller executable.


I also propose that when you do

import module

you can only access the symbols through the module namespace. ie

yada = module.func()

If you can't live with the typing, you can always make an alias. You could also
use the "from .." syntax above.

Why? Makes it easier for programmers to find the source of a (class, funciton,
whatever) when maintaining code.

This is all Pythonesque BTW.
There was a thing in Python like this:

from module import *

which imported all the symbols from a module much like "import module" in D is
now. This has now been deprecated, because even though it saved typing at the
time, people found that it made maintenace much more difficult and rallied
against it :-)

This would also make it much easier for IDEs to take you directly to the source
of some function, same as humans.

  

import c.stdio (printf, scanf); //I prefer this version or import c.stdio only (printf, scanf); or import c.stdio with (printf, scanf); or import c.stdio symbols (printf, scanf); A good compiler should be able to strip out the unnessary. It's may only be a namespace issue.
Dec 04 2003
parent "Matthew Wilson" <matthew.hat stlsoft.dot.org> writes:
Either way is good. Maybe the second is slightly more amenable to wizards
and code instrumentation.

We do need this facility, however it looks.

"J Anderson" <REMOVEanderson badmama.com.au> wrote in message
news:bqn6u5$545$1 digitaldaemon.com...
 Jon Thoroddsen wrote:

I propose that we should be able to import only part of the module


the syntax

from c.stdio import printf

this makes things more explicit when we want just a little bit of the


anyway, easier to find the module that the symbol is from, and possibly a
smaller executable.


I also propose that when you do

import module

you can only access the symbols through the module namespace. ie

yada = module.func()

If you can't live with the typing, you can always make an alias. You


use the "from .." syntax above.

Why? Makes it easier for programmers to find the source of a (class,


whatever) when maintaining code.

This is all Pythonesque BTW.
There was a thing in Python like this:

from module import *

which imported all the symbols from a module much like "import module" in


now. This has now been deprecated, because even though it saved typing at


time, people found that it made maintenace much more difficult and


against it :-)

This would also make it much easier for IDEs to take you directly to the


of some function, same as humans.

import c.stdio (printf, scanf); //I prefer this version or import c.stdio only (printf, scanf); or import c.stdio with (printf, scanf); or import c.stdio symbols (printf, scanf); A good compiler should be able to strip out the unnessary. It's may only be a namespace issue.

Dec 04 2003