digitalmars.D.learn - module vs import
- hukedonfonix (1/1) Jun 04 2008 I'm having some trouble understanding how module differs from import. As...
- Saaa (6/10) Jun 04 2008 You import modules with 'import' . A module is a .d file.
- Robert Fraser (4/5) Jun 04 2008 The "module" keyword is used to assign a name to your module (which
- =?ISO-8859-1?Q?Tomasz_Sowi=f1ski?= (3/6) Jun 08 2008 By the way, why do you have to repeat the filename in the file itself? I...
- Jarrett Billingsley (16/23) Jun 08 2008 I think it might have to do with making it possible to make D work on
- =?ISO-8859-1?Q?Tomasz_Sowi=f1ski?= (4/12) Jun 08 2008 Interesting and sensible this db-oriented filesystem seems to be. Sort o...
- Jarrett Billingsley (10/19) Jun 08 2008 I'm no filesystems researcher but I'd imagine that if an implementation ...
- BCS (4/28) Jun 08 2008 with a good search system like that thing in vista, google desktop or an...
- Robert Fraser (7/10) Jun 08 2008 This man would agree:
- BCS (5/13) Jun 09 2008 I still use directories (and don't see that changing) but more often tha...
- Leandro Lucarella (11/27) Jun 08 2008 You mean *relational* database, right? Because hierarchical filesystems
- Jarrett Billingsley (3/6) Jun 08 2008 /me is no database expert.
- Leandro Lucarella (12/20) Jun 09 2008 http://en.wikipedia.org/wiki/Database#Database_models
- Lars Ivar Igesund (12/22) Jun 08 2008 It is only really omittable if you have no hierarchy. The full module na...
- Yigal Chripun (37/61) Jun 08 2008 Personally I think that the current module/package model is broken. the
- Lars Ivar Igesund (15/72) Jun 09 2008 This has been discussed before, and I agree that the current situation i...
- Yigal Chripun (11/85) Jun 09 2008 I don't see any /new/ problems of ambiguity with such a scheme. The
- Lars Ivar Igesund (9/21) Jun 09 2008 Personally I think implementing such a scheme would be introducing
- Tomas Lindquist Olsen (13/22) Jun 10 2008 First, the module identifier *must* not coincide with the file path.
- Koroskin Denis (3/26) Jun 10 2008 Good point!
- Jarrett Billingsley (8/9) Jun 10 2008 English pedantry: "must not" is sort of a set phrase and does not have t...
I'm having some trouble understanding how module differs from import. As far as i see it they both pretty much do the exact same thing, ie allow you access to functions, classes etc. of another .d file. Or am i overlooking something quite basic and obvious here?
Jun 04 2008
You import modules with 'import' . A module is a .d file. You only use the 'module' keyword to name your module. ie. module test.main; import test.error; ..I'm having some trouble understanding how module differs from import. As far as i see it they both pretty much do the exact same thing, ie allow you access to functions, classes etc. of another .d file. Or am i overlooking something quite basic and obvious here?
Jun 04 2008
hukedonfonix wrote:I'm having some trouble understanding how module differs from import. As far as i see it they both pretty much do the exact same thing, ie allow you access to functions, classes etc. of another .d file. Or am i overlooking something quite basic and obvious here?The "module" keyword is used to assign a name to your module (which incidentally must coincide with its filename & folder structure) while "import" gives you access to the module with the given name.
Jun 04 2008
Robert Fraser Wrote:The "module" keyword is used to assign a name to your module (which incidentally must coincide with its filename & folder structure) while "import" gives you access to the module with the given name.By the way, why do you have to repeat the filename in the file itself? I'm sure there must be some reason, but I can't see it now. Tomek
Jun 08 2008
"Tomasz Sowiński" <tomeksowi gmail.com> wrote in message news:g2h5f2$1jnq$1 digitalmars.com...Robert Fraser Wrote:I think it might have to do with making it possible to make D work on filesystems where there is no concept of "directories", such as a database-oriented FS. In such a filesystem, there might not be any way to identify a module other than by doing so inside the module. `select contains(*, "module foo.bar;") from files where extension = "d"`. Though even that wouldn't necessarily work since you'd really have to parse the module since it could be written "module foo . bar ;". But in that case, why is the module declaration optional? It's kind of confusing and to be honest, I'm not sure what purpose the module declaration holds. It would be far more efficient in a DB-oriented FS to instead follow some naming convention for modules, allowing you to select them without looking at their contents. ...now I want to remove module declarations from MiniD :)The "module" keyword is used to assign a name to your module (which incidentally must coincide with its filename & folder structure) while "import" gives you access to the module with the given name.By the way, why do you have to repeat the filename in the file itself? I'm sure there must be some reason, but I can't see it now. Tomek
Jun 08 2008
Jarrett Billingsley Wrote:I think it might have to do with making it possible to make D work on filesystems where there is no concept of "directories", such as a database-oriented FS. In such a filesystem, there might not be any way to identify a module other than by doing so inside the module. `select contains(*, "module foo.bar;") from files where extension = "d"`. Though even that wouldn't necessarily work since you'd really have to parse the module since it could be written "module foo . bar ;".Interesting and sensible this db-oriented filesystem seems to be. Sort of an extension of the emerging tendency of getting rid of hierarchies and managing everything as a bag of objects with attributes. I assume this approach will sooner or later be hyped and the-next-big-thinged but heck... I'm tired of directories because of the maintainance cost and the where-to-put-this-file delays. Do you know of any working solution of this kind? I googled and the only thing I came across was a Slashdot art saying MS strives to put it in the new Windows. Tomek
Jun 08 2008
"Tomasz Sowiński" <tomeksowi gmail.com> wrote in message news:g2hhv4$2g9l$1 digitalmars.com...Interesting and sensible this db-oriented filesystem seems to be. Sort of an extension of the emerging tendency of getting rid of hierarchies and managing everything as a bag of objects with attributes. I assume this approach will sooner or later be hyped and the-next-big-thinged but heck... I'm tired of directories because of the maintainance cost and the where-to-put-this-file delays. Do you know of any working solution of this kind? I googled and the only thing I came across was a Slashdot art saying MS strives to put it in the new Windows.I'm no filesystems researcher but I'd imagine that if an implementation did exist, it'd probably extremely experimental or a proof of concept. I've certainly never heard of one. They might exist on systems that don't get a lot of publicity like mainframes. I'd be interested to see such a filesystem. IIRC Vista was supposed to have something along the lines of a DB-oriented FS, but that was one of the many, many interesting features that was dropped during development, hence what your googling turned up.
Jun 08 2008
Reply to Tomasz,Jarrett Billingsley Wrote:with a good search system like that thing in vista, google desktop or an app a friend of mine wrote*, you don't really need directories much even now. *http://www.espsw.com/I think it might have to do with making it possible to make D work on filesystems where there is no concept of "directories", such as a database-oriented FS. In such a filesystem, there might not be any way to identify a module other than by doing so inside the module. `select contains(*, "module foo.bar;") from files where extension = "d"`. Though even that wouldn't necessarily work since you'd really have to parse the module since it could be written "module foo . bar ;".Interesting and sensible this db-oriented filesystem seems to be. Sort of an extension of the emerging tendency of getting rid of hierarchies and managing everything as a bag of objects with attributes. I assume this approach will sooner or later be hyped and the-next-big-thinged but heck... I'm tired of directories because of the maintainance cost and the where-to-put-this-file delays. Do you know of any working solution of this kind? I googled and the only thing I came across was a Slashdot art saying MS strives to put it in the new Windows. Tomek
Jun 08 2008
BCS wrote:with a good search system like that thing in vista, google desktop or an app a friend of mine wrote*, you don't really need directories much even now.This man would agree: http://forums.thedailywtf.com/forums/t/7593.aspx He's even found new uses for it: "Video is by far the most exciting part of Search. I can video in a book and go directly to a given page and play that back in slow motion. I can video in forum screens."
Jun 08 2008
Reply to Robert,BCS wrote:I still use directories (and don't see that changing) but more often than not the lookup/access is done through a search system. I don't /need/ dirs the same way I don't /need/ anything higher level than ASM. :-)with a good search system like that thing in vista, google desktop or an app a friend of mine wrote*, you don't really need directories much even now.This man would agree: http://forums.thedailywtf.com/forums/t/7593.aspx
Jun 09 2008
Jarrett Billingsley, el 8 de junio a las 13:54 me escribiste:"Tomasz Sowiński" <tomeksowi gmail.com> wrote in message news:g2h5f2$1jnq$1 digitalmars.com...You mean *relational* database, right? Because hierarchical filesystems *are* databases (hierarchical databases in fact =). LDAP is another popular example of hierarchical database. -- Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/ ---------------------------------------------------------------------------- GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05) ---------------------------------------------------------------------------- ASALTAN, GOLPEAN SALVAJEMENTE A ANCIANA Y LE COMEN LA PASTAFROLA. -- CrĆ³nica TVRobert Fraser Wrote:I think it might have to do with making it possible to make D work on filesystems where there is no concept of "directories", such as a database-oriented FS.The "module" keyword is used to assign a name to your module (which incidentally must coincide with its filename & folder structure) while "import" gives you access to the module with the given name.By the way, why do you have to repeat the filename in the file itself? I'm sure there must be some reason, but I can't see it now. Tomek
Jun 08 2008
"Leandro Lucarella" <llucax gmail.com> wrote in message news:20080609011323.GA31950 homero.springfield.home...You mean *relational* database, right? Because hierarchical filesystems *are* databases (hierarchical databases in fact =). LDAP is another popular example of hierarchical database./me is no database expert.
Jun 08 2008
Jarrett Billingsley, el 8 de junio a las 21:55 me escribiste:"Leandro Lucarella" <llucax gmail.com> wrote in message news:20080609011323.GA31950 homero.springfield.home...http://en.wikipedia.org/wiki/Database#Database_models BTW, I'm not a database expert either, but I find very curious that people don't realize that filesystems are databases when they are probably the older most used database (and for a *lot* of problems, probably the clearer and more efficient =). -- Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/ ---------------------------------------------------------------------------- GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05) ---------------------------------------------------------------------------- 41% of all people take people with curly hair less seriouslyYou mean *relational* database, right? Because hierarchical filesystems *are* databases (hierarchical databases in fact =). LDAP is another popular example of hierarchical database./me is no database expert.
Jun 09 2008
Tomasz Sowif1ski wrote:Robert Fraser Wrote:It is only really omittable if you have no hierarchy. The full module name is used in the symbol name mangling (for instance when compiling an object from a module using the -c switch). When you import the same module using the module name (say foo.bar.Util), your application will only link if the mangling (and module names match). The compiler can't guess the hierarchy specified by the importing code when that code isn't part of the compile. For all-at-once compiling, the compiler probably could get it right. Lars Ivar Igesund blog at http://larsivi.net DSource, #d.tango & #D: larsivi Dancing the TangoThe "module" keyword is used to assign a name to your module (which incidentally must coincide with its filename & folder structure) while "import" gives you access to the module with the given name.By the way, why do you have to repeat the filename in the file itself? I'm sure there must be some reason, but I can't see it now. Tomek
Jun 08 2008
Lars Ivar Igesund wrote:Tomasz Sowif1ski wrote:Personally I think that the current module/package model is broken. the artificial distinction between modules and packages is wrong. if I have a bunch of small classes, should I put them in one module/file or have a different file for each class and group them together in a package/folder? and more importantly, what if I choose to change between having one huge file and having many small ones without changing the logical hierarchy of my code? it makes sense to put a big class in it's own file but then it's name would be Name.Name (since the best name of the module is the same as the contained class). what if I want to separate the logical structure from the physical one on disk (for a practical example - each sub project is handled by a different team and has it's own sub-folder but this structure is different from the structure of the API - Derelict's package structure is a good example of such issues). I usually do not like anything Microsoft does, but I have to admit that their .net separation of physical assemblies on disk from logical structure of the code in namespaces is genius. this is also tied with files at all, not even auto generated ones like D's .di files. the latest DMD knows how to split obj files when creating a static lib. thus the 1-1 relation between code units and the compiled binary units is already broken. I think this should be taken to the next logical level and the code organization should be separated from the organization on disk. either the algorithm the compiler uses to find symbols needs to change or another flag can be added to the makefile/dsss.conf that directs the compiler to the physical location of symbols it needs (since we all use build tools anyway to compile code) this is similar to a "project" file in a IDE. regarding deployment: Java jars contain a manifest file with metadata, so does .net assemblies. that kind of file can and should be generated by the compiler and it can contain the above mapping of logical modules to physical locations inside the lib archive. this would be much better than the traditional .a files and .so files. --YigalRobert Fraser Wrote:It is only really omittable if you have no hierarchy. The full module name is used in the symbol name mangling (for instance when compiling an object from a module using the -c switch). When you import the same module using the module name (say foo.bar.Util), your application will only link if the mangling (and module names match). The compiler can't guess the hierarchy specified by the importing code when that code isn't part of the compile. For all-at-once compiling, the compiler probably could get it right. Lars Ivar Igesund blog at http://larsivi.net DSource, #d.tango & #D: larsivi Dancing the TangoThe "module" keyword is used to assign a name to your module (which incidentally must coincide with its filename & folder structure) while "import" gives you access to the module with the given name.By the way, why do you have to repeat the filename in the file itself? I'm sure there must be some reason, but I can't see it now. Tomek
Jun 08 2008
Yigal Chripun wrote:Lars Ivar Igesund wrote:This has been discussed before, and I agree that the current situation isn't ideal for refactoring the codebase, and there is also the estetic issue you mention (Name.Name). Dropping the current restrictions would incur more prolems with ambigiuty when resolving the hierarchy. And note that your example about the new DMD feature regarding object files really doesn't compare - they're more akin to split the source for a modules interface into several implementation files, and thus not in conflict with the current module naming scheme. Oh, and there is a difference between "broken" and "not perfect". The current scheme does work, so it can hardly be considered broken. Lars Ivar Igesund blog at http://larsivi.net DSource, #d.tango & #D: larsivi Dancing the TangoTomasz Sowif1ski wrote:Personally I think that the current module/package model is broken. the artificial distinction between modules and packages is wrong. if I have a bunch of small classes, should I put them in one module/file or have a different file for each class and group them together in a package/folder? and more importantly, what if I choose to change between having one huge file and having many small ones without changing the logical hierarchy of my code? it makes sense to put a big class in it's own file but then it's name would be Name.Name (since the best name of the module is the same as the contained class). what if I want to separate the logical structure from the physical one on disk (for a practical example - each sub project is handled by a different team and has it's own sub-folder but this structure is different from the structure of the API - Derelict's package structure is a good example of such issues). I usually do not like anything Microsoft does, but I have to admit that their .net separation of physical assemblies on disk from logical structure of the code in namespaces is genius. this is also tied with files at all, not even auto generated ones like D's .di files. the latest DMD knows how to split obj files when creating a static lib. thus the 1-1 relation between code units and the compiled binary units is already broken. I think this should be taken to the next logical level and the code organization should be separated from the organization on disk. either the algorithm the compiler uses to find symbols needs to change or another flag can be added to the makefile/dsss.conf that directs the compiler to the physical location of symbols it needs (since we all use build tools anyway to compile code) this is similar to a "project" file in a IDE.Robert Fraser Wrote:It is only really omittable if you have no hierarchy. The full module name is used in the symbol name mangling (for instance when compiling an object from a module using the -c switch). When you import the same module using the module name (say foo.bar.Util), your application will only link if the mangling (and module names match). The compiler can't guess the hierarchy specified by the importing code when that code isn't part of the compile. For all-at-once compiling, the compiler probably could get it right. Lars Ivar Igesund blog at http://larsivi.net DSource, #d.tango & #D: larsivi Dancing the TangoThe "module" keyword is used to assign a name to your module (which incidentally must coincide with its filename & folder structure) while "import" gives you access to the module with the given name.By the way, why do you have to repeat the filename in the file itself? I'm sure there must be some reason, but I can't see it now. Tomek
Jun 09 2008
Lars Ivar Igesund wrote:Yigal Chripun wrote:I don't see any /new/ problems of ambiguity with such a scheme. The compiler will just use two completely separate mechanisms - one for resolving physical locations (i.e. files/directories) and another for resolving the logical hierarchy of symbols. maybe my saying that the current system is broken was too strong, but it definitely is not perfect and has issues. as the saying goes: "good enough is the enemy of perfect" I prefer to side with perfect while others may choose otherwise. I wonder what is Walter's position in this regard. --YigalLars Ivar Igesund wrote:This has been discussed before, and I agree that the current situation isn't ideal for refactoring the codebase, and there is also the estetic issue you mention (Name.Name). Dropping the current restrictions would incur more prolems with ambigiuty when resolving the hierarchy. And note that your example about the new DMD feature regarding object files really doesn't compare - they're more akin to split the source for a modules interface into several implementation files, and thus not in conflict with the current module naming scheme. Oh, and there is a difference between "broken" and "not perfect". The current scheme does work, so it can hardly be considered broken. Lars Ivar Igesund blog at http://larsivi.net DSource, #d.tango & #D: larsivi Dancing the TangoTomasz Sowif1ski wrote:Personally I think that the current module/package model is broken. the artificial distinction between modules and packages is wrong. if I have a bunch of small classes, should I put them in one module/file or have a different file for each class and group them together in a package/folder? and more importantly, what if I choose to change between having one huge file and having many small ones without changing the logical hierarchy of my code? it makes sense to put a big class in it's own file but then it's name would be Name.Name (since the best name of the module is the same as the contained class). what if I want to separate the logical structure from the physical one on disk (for a practical example - each sub project is handled by a different team and has it's own sub-folder but this structure is different from the structure of the API - Derelict's package structure is a good example of such issues). I usually do not like anything Microsoft does, but I have to admit that their .net separation of physical assemblies on disk from logical structure of the code in namespaces is genius. this is also tied with files at all, not even auto generated ones like D's .di files. the latest DMD knows how to split obj files when creating a static lib. thus the 1-1 relation between code units and the compiled binary units is already broken. I think this should be taken to the next logical level and the code organization should be separated from the organization on disk. either the algorithm the compiler uses to find symbols needs to change or another flag can be added to the makefile/dsss.conf that directs the compiler to the physical location of symbols it needs (since we all use build tools anyway to compile code) this is similar to a "project" file in a IDE.Robert Fraser Wrote:It is only really omittable if you have no hierarchy. The full module name is used in the symbol name mangling (for instance when compiling an object from a module using the -c switch). When you import the same module using the module name (say foo.bar.Util), your application will only link if the mangling (and module names match). The compiler can't guess the hierarchy specified by the importing code when that code isn't part of the compile. For all-at-once compiling, the compiler probably could get it right. Lars Ivar Igesund blog at http://larsivi.net DSource, #d.tango & #D: larsivi Dancing the TangoThe "module" keyword is used to assign a name to your module (which incidentally must coincide with its filename & folder structure) while "import" gives you access to the module with the given name.By the way, why do you have to repeat the filename in the file itself? I'm sure there must be some reason, but I can't see it now. Tomek
Jun 09 2008
Yigal Chripun wrote:Lars Ivar Igesund wrote: I don't see any /new/ problems of ambiguity with such a scheme. The compiler will just use two completely separate mechanisms - one for resolving physical locations (i.e. files/directories) and another for resolving the logical hierarchy of symbols. maybe my saying that the current system is broken was too strong, but it definitely is not perfect and has issues. as the saying goes: "good enough is the enemy of perfect" I prefer to side with perfect while others may choose otherwise. I wonder what is Walter's position in this regard.Personally I think implementing such a scheme would be introducing complexity for a questionable gain - you'd rather use a tool for a major refactoring job in any case, and not depend on language mechanics. -- Lars Ivar Igesund blog at http://larsivi.net DSource, #d.tango & #D: larsivi Dancing the Tango
Jun 09 2008
Tomasz Sowiński wrote:Robert Fraser Wrote:First, the module identifier *must* not coincide with the file path. One case where this is useful, and not mentioned in the other replies (I think), is when a module can have multiple implementations. The module that imports find could be a .di file, for example foobar.di, while the actual implementation .d files could have other file names, for example foobar_win32.d, foobar_linux.d etc, here the module identifier is necessary to mangle symbols correctly. If you're using Makefiles or simple scripts to build your software this is an entirely feasible setup! Of course D has the 'version' keyword for this, but sometimes the code can be very big and seperate files might be more maintainable. I personally prefer switching my editor to another file than scrolling a hundreds of lines to look at the other implementation. TomasThe "module" keyword is used to assign a name to your module (which incidentally must coincide with its filename & folder structure) while "import" gives you access to the module with the given name.By the way, why do you have to repeat the filename in the file itself? I'm sure there must be some reason, but I can't see it now. Tomek
Jun 10 2008
On Tue, 10 Jun 2008 14:17:10 +0400, Tomas Lindquist Olsen <tomas famolsen.dk> wrote:Tomasz SowiƱski wrote:Good point!Robert Fraser Wrote:First, the module identifier *must* not coincide with the file path. One case where this is useful, and not mentioned in the other replies (I think), is when a module can have multiple implementations. The module that imports find could be a .di file, for example foobar.di, while the actual implementation .d files could have other file names, for example foobar_win32.d, foobar_linux.d etc, here the module identifier is necessary to mangle symbols correctly. If you're using Makefiles or simple scripts to build your software this is an entirely feasible setup! Of course D has the 'version' keyword for this, but sometimes the code can be very big and seperate files might be more maintainable. I personally prefer switching my editor to another file than scrolling a hundreds of lines to look at the other implementation. TomasThe "module" keyword is used to assign a name to your module (which incidentally must coincide with its filename & folder structure) while "import" gives you access to the module with the given name.By the way, why do you have to repeat the filename in the file itself? I'm sure there must be some reason, but I can't see it now. Tomek
Jun 10 2008
"Tomas Lindquist Olsen" <tomas famolsen.dk> wrote in message news:g2lkaq$18e7$1 digitalmars.com...First, the module identifier *must* not coincide with the file path.English pedantry: "must not" is sort of a set phrase and does not have the same meaning as "does not have to". What you said is something like "it is not possible/legal for the module identifier to coincide with the file path," whereas if "must not" were replaced with "does not have to," it would mean what you expected: "it's not necessary for the module identifier to coincide with the file path." :)
Jun 10 2008