digitalmars.D - proposal: improved import declaration
- eao197 (14/14) May 29 2007 Hi!
- David B. Held (6/8) May 29 2007 I like Java's syntax better:
- Derek Parnell (14/24) May 29 2007 One problem I have with importing things that you don't actually use, is
- eao197 (9/16) May 30 2007 I think it's better to have both improvements, because
- davidl (3/14) May 30 2007 --
- eao197 (8/25) May 30 2007 I'm in doubt that this will be possible to do by a macro.
- Chris Nicholson-Sauls (13/45) May 30 2007 Something like this:
- Frits van Bommel (30/45) May 30 2007 Other build utilities should be able to easily support this sort of
- eao197 (9/14) May 30 2007 Thanks for your example.
- Frits van Bommel (13/26) May 30 2007 It certainly made my life a lot easier when I found out '-v' showed
- C. Dunn (13/20) Jul 30 2007 I am glad that this is not supported. I do not like the basic import st...
Hi! The proposal is to allow writing: import <module-root>.{<name>[,<name>...]}; For example, instead of: import tango.io.Console; import tango.io.Conduit; import tango.io.FilePath; import tango.io.FileSystem; import tango.io.Stdout; simply write: import tango.io.{Console, Conduit, FilePath, FileSystem, Stdout}; -- Regards, Yauheni Akhotnikau
May 29 2007
eao197 wrote:[...] import tango.io.{Console, Conduit, FilePath, FileSystem, Stdout};I like Java's syntax better: import tango.io.*; It's not as precise, but once you import more than two or three modules, you might as well do the whole namespace. Dave
May 29 2007
On Tue, 29 May 2007 22:36:45 -0700, David B. Held wrote:eao197 wrote:One problem I have with importing things that you don't actually use, is that it makes impact analysis a bit harder. In other words, if I change a module, what other modules might be effected by that change? One way to find out is to see which modules import the one you are planning to change. To say "import whatever.*" doesn't help me know which module the importing source actually uses. I know this is not an absolute or exact way of knowing the impact but it goes a long way towards it. -- Derek (skype: derek.j.parnell) Melbourne, Australia "Justice for David Hicks!" 30/05/2007 4:28:13 PM[...] import tango.io.{Console, Conduit, FilePath, FileSystem, Stdout};I like Java's syntax better: import tango.io.*; It's not as precise, but once you import more than two or three modules, you might as well do the whole namespace.
May 29 2007
On Wed, 30 May 2007 09:36:45 +0400, David B. Held <dheld codelogicconsulting.com> wrote:eao197 wrote:I think it's better to have both improvements, because import some.really.big.package.* is not a good idea if I want only 3 or 5 modules from package with 20+ modules and deep hierarchy. -- Regards, Yauheni Akhotnikau[...] import tango.io.{Console, Conduit, FilePath, FileSystem, Stdout};I like Java's syntax better: import tango.io.*; It's not as precise, but once you import more than two or three modules, you might as well do the whole namespace.
May 30 2007
wait till macro is availableHi! The proposal is to allow writing: import <module-root>.{<name>[,<name>...]}; For example, instead of: import tango.io.Console; import tango.io.Conduit; import tango.io.FilePath; import tango.io.FileSystem; import tango.io.Stdout; simply write: import tango.io.{Console, Conduit, FilePath, FileSystem, Stdout};-- 使用 Opera 革命性的电子邮件客户程序: http://www.opera.com/mail/
May 30 2007
On Wed, 30 May 2007 16:08:40 +0400, davidl <davidl 126.com> wrote:wait till macro is availableI'm in doubt that this will be possible to do by a macro. And I don't think it's a good idea to modify behaviour of 'import declaration' by a macro because it can make life too difficult to D-oriented build tools (like rebuild).-- Regards, Yauheni AkhotnikauThe proposal is to allow writing: import <module-root>.{<name>[,<name>...]}; For example, instead of: import tango.io.Console; import tango.io.Conduit; import tango.io.FilePath; import tango.io.FileSystem; import tango.io.Stdout; simply write: import tango.io.{Console, Conduit, FilePath, FileSystem, Stdout};
May 30 2007
Something like this: macro myImport (pkg, mods...) { foreach (m; mods) { import pkg.m ; } } myImport(tango.io, Console, Conduit, FilePath, FileSystem, Stdout); And seeing as rebuild is based around the compiler's own frontend, where such macros are defined and expanded, I imagine it should adapt to them quite readily. Other build utilities, on the other hand, might have some issue. (Maybe it really is time to provide at least simple support for this in the compiler...) -- Chris Nicholson-Sauls eao197 wrote:On Wed, 30 May 2007 16:08:40 +0400, davidl <davidl 126.com> wrote:wait till macro is availableI'm in doubt that this will be possible to do by a macro. And I don't think it's a good idea to modify behaviour of 'import declaration' by a macro because it can make life too difficult to D-oriented build tools (like rebuild).--Regards, Yauheni AkhotnikauThe proposal is to allow writing: import <module-root>.{<name>[,<name>...]}; For example, instead of: import tango.io.Console; import tango.io.Conduit; import tango.io.FilePath; import tango.io.FileSystem; import tango.io.Stdout; simply write: import tango.io.{Console, Conduit, FilePath, FileSystem, Stdout};
May 30 2007
Chris Nicholson-Sauls wrote:Something like this: macro myImport (pkg, mods...) { foreach (m; mods) { import pkg.m ; } } myImport(tango.io, Console, Conduit, FilePath, FileSystem, Stdout); And seeing as rebuild is based around the compiler's own frontend, where such macros are defined and expanded, I imagine it should adapt to them quite readily. Other build utilities, on the other hand, might have some issue. (Maybe it really is time to provide at least simple support for this in the compiler...)Other build utilities should be able to easily support this sort of thing by parsing the output of "dmd -v -o-". (For GDC, use either "gdmd -v -o-" or "gdc -fsyntax-only -fd-verbose" instead) I have the following clause in one of my makefiles: --- %.d$(DEP_SUFFIX): Makefile echo Processing $*.d dmd -v -o- $*.d $(DFLAGS) \ | grep '^import ' \ | sed -e 's/.*(\(.*\))/\1/' \ | xargs echo "$*.d$(OBJ_SUFFIX) $ : $*.d " \ > $ --- The first (relevant) line invokes DMD as above. -v shows lots of info about the file being processed, -o- suppresses actual compilation. The grep filters down to just lines about imports. The sed command extracts the bit between parentheses (the file name of the imported module). The xargs line prepends some information for Make to it, converting it to a dependency rule; the object file and the dependency file depend on the original file + all imported modules. The output is saved to the dependency file. All dependency files are included into the makefile. This works quite nicely. I would imagine it'd work even better in build utilities that can use the complete power of D (or another high-level language) to parse the output instead of being restricted to (interpreted) shell commands. (And it wouldn't need all of the above steps, since they don't need to generate make-compatible syntax)
May 30 2007
On Wed, 30 May 2007 18:23:02 +0400, Frits van Bommel <fvbommel REMwOVExCAPSs.nl> wrote:This works quite nicely. I would imagine it'd work even better in build utilities that can use the complete power of D (or another high-level language) to parse the output instead of being restricted to (interpreted) shell commands. (And it wouldn't need all of the above steps, since they don't need to generate make-compatible syntax)Thanks for your example. I want to add support of D to my build tool which is written in Ruby. I think your approach can save me a lot of work in implementing dependency analyzer. -- Regards, Yauheni Akhotnikau
May 30 2007
eao197 wrote:On Wed, 30 May 2007 18:23:02 +0400, Frits van Bommel <fvbommel REMwOVExCAPSs.nl> wrote:It certainly made my life a lot easier when I found out '-v' showed imports (prior to that I grepped for 'import' statements, using sed to change '.' to '/' and adding '.d'...). And it got even better when it also started showing the filenames, since I had several '-I' parameters on the command line that would all have to be searched[1] to get it working just right. But now the compiler reports filenames it works perfectly without anything too hackish :). [1]: Which I didn't do by the way; I just assumed imports were from my main import path, which caused some trouble once in a while if a file located elsewhere was changed and I forgot to do a 'make rebuild' instead of 'make'...This works quite nicely. I would imagine it'd work even better in build utilities that can use the complete power of D (or another high-level language) to parse the output instead of being restricted to (interpreted) shell commands. (And it wouldn't need all of the above steps, since they don't need to generate make-compatible syntax)Thanks for your example. I want to add support of D to my build tool which is written in Ruby. I think your approach can save me a lot of work in implementing dependency analyzer.
May 30 2007
David B. Held Wrote:eao197 wrote:I am glad that this is not supported. I do not like the basic import statement at all. I would like it restricted to static, renamed, and selective imports. The reader of a file should not have to guess where any given symbol came from. But I agree with the original poster that there should be something like Python's: from tango.io import a,b,c,...; If you need to import dozens of modules from the same package, you can create a single module which does all the imports publicly. module alltango; public import tango.io.A; public import tango.io.B; public import tango.io.C; // ... Then: import alltango; gives you everthing. But I still prefer static imports.[...] import tango.io.{Console, Conduit, FilePath, FileSystem, Stdout};I like Java's syntax better: import tango.io.*;
Jul 30 2007