Generality creep

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Fri Mar 29 13:05:31 UTC 2019


On 3/28/19 10:47 PM, Mike Franklin wrote:
> On Thursday, 28 March 2019 at 20:02:17 UTC, Andrei Alexandrescu wrote:
> 
>>> I'm still wondering, though, how we're going to drop druntime while
>>> still maintain backward compatibility.  Or how we could skip the startup
>>> code that invokes module ctors and packages command-line args into
>>> string[].  It would be awesome if we could pull this off, but I don't
>>> currently see how we could do it without major breakage.
>>
>> Compiler flag.
> 
> D is so powerful, this can also be done in other ways as well.
> 
> As Andrei alluded to in another post, we just need to embrace addition.  
> Keep the existing logic path in place, and create a new one that does 
> what we want it to do.  With design-by-introspection, and probably a 
> number of other awesome D facilities, the correct logic path can be 
> chosen at compile-time based on what the user has declared in their code.

*nod*

> Another idea is allowing "module inheritance" for lack of a better 
> term.  Users can "inherit" from an "abstract" module but override the 
> default startup and shutdown logic.  Perhaps we refactor the current 
> logic path to inherit from this "abstract" module but add all of the 
> existing startup and shutdown implementation as overrides.  The compiler 
> is then modified to "inherit" from that module by default.  Users that 
> don't want the default can "inherit" from the "abstract" module and 
> provide their own implementation.

Yah, I actually had even code for an idea - after each module is loaded, 
the following code is automatically injected at the end of it:

mixin(__onImportedModule(__MODULE__));

This is evaluated in the context of the importer (not imported), an 
essential detail. By default of course the function returns the empty 
string.

This allows user code to add things like serialization, factories and 
other introspection-based utilities automatically upon import.


More information about the Digitalmars-d mailing list