Thread overview
[Issue 1297] New: Static modules, aka enforcing static import.
Jun 28, 2007
d-bugmail
[Issue 1297] [modules] Static modules, aka enforcing static import.
Nov 13, 2009
Leandro Lucarella
[Issue 1297] [module] Static modules, aka enforcing static import.
Feb 07, 2013
Andrej Mitrovic
June 28, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1297

           Summary: Static modules, aka enforcing static import.
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: spec
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: ibisbasenji@gmail.com


I find myself using the very nice static-renaming-import scheme to provide namespacing capability.  For example, rather than have a module full of database functions with, for example, a 'db_' prefix to avoid collisions, its useful to just use 'static import Db = foo.bar.Db;' and call all functions via 'Db.func()'.

Since some modules are tailored toward use in this way, I feel it would be nice to have a way to specifically enforce our module being static-imported.  The proposal is simple enough: allow the 'static' attribute on 'module' declerations, with the meaning that any corresponding 'import' must also be 'static'.  Example:

-----[ foo/bar/Db.d ]-----
static module foo.bar.Db;

void func () {}

-----[ fred.d ]-----
import foo.bar.Db; // <- Error: import for module 'foo.bar.Db' must be static

-----[ greg.d ]-----
static import foo.bar.Db; // <- Ok


Naturally, static-modules should still play nice with renaming imports and selective imports.


-- 

November 13, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=1297



--- Comment #1 from Leandro Lucarella <llucax@gmail.com> 2009-11-13 15:32:20 PST ---
I think static import should be the default, and there should be an explicit way to import everything, not the other way around.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 07, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=1297


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich@gmail.com


--- Comment #2 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-02-06 17:07:34 PST ---
Since D is supposed to prevent symbol hijacking I don't see much benefit for this. If the user has conflicts he will use one of several techniques such as using static imports, using aliases, using renamed imports and/or selective imports.

I don't see why you would force a module to be imported one way or another. It seems like a sure way to make importing modules annoying for the user.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------