FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Proposal for making DDMD-based projects easier to maintain

 
Post new topic   Reply to topic     Forum Index -> ddmd
View previous topic :: View next topic  
Author Message
Abscissa



Joined: 23 Feb 2005
Posts: 40
Location: Cleveland, OH, US

PostPosted: Sat Oct 30, 2010 6:19 pm    Post subject: Proposal for making DDMD-based projects easier to maintain Reply with quote

I have an idea for making projects based off of DDMD easier to maintain and keep in-sync with DDMD. I can make the change myself if it sounds like a good idea.

DMD and by extension DDMD have a LOT of source files and classes, particularly classes used for the AST. Projects based off DDMD are likely going to need to hook into many of these, but that can create a lot of work when merging new versions of DDMD. The merging process can be made very easy by not changing any of the existing members and only adding members. But due to the number of classes/files involved that can still be quite a lot of tedious grunt work.

So here's my idea: We take advantage of D's mechanism for splitting implementations across multiple files, ie, template mixins: For every module/class that a DDMD-based project might need to expand, we add exactly three lines of code. I'll use "class Module" from "Module.d" as an example:

The way it is right now:
Code:
// All the imports here
import blah.blah.blah;
import blah.blah.blah;

// Sometimes some global-space stuff here

class Module : Package
{
    // All the members here
}


Suggested change:
Code:
// All the imports here
import blah.blah.blah;
import blah.blah.blah;
import dmd.DDMDExtensions;

// Sometimes some global-space stuff here

mixin insertGlobalExtension!"Module";

class Module : Package
{
    mixin insertMemberExtension!"Module";
    // All the members here
}


Then DDMDExtensions.d would look something like this:
Code:
module dmd.DDMDExtensions;

// Whatever imports this might need,
// can't think of anything offhand though
import blah.blah.blah;
import blah.blah.blah;

template insertGlobalExtension(string name)
{
}

template insertMemberExtension(string name)
{
}


It's probably possible to do insertMemberExtension!Module and insertMemberExtension(T) instead of insertMemberExtension!"Module" and insertMemberExtension(string name). I dunno, I haven't tried, but that might be better.

So, by default, DDMDExtensions doesn't add anything. But then when someone makes a project based off DDMD (say, "DSuperTool") and needs to add stuff to some classes/modules, they modify DDMDExtensions.d like this:

Code:
module dmd.DDMDExtensions;

import DSuperTool.DDMDExtension;

template insertGlobalExtension(string name)
{
    mixin insertGlobalDSuperTool!name;
}

template insertMemberExtension(string name)
{
    mixin insertMemberDSuperTool!name;
}


And then leave it alone. Then in "DSuperTool/DDMDExtension.d", they create the "insertGlobalDSuperTool" and "insertMemberDSuperTool" templates, use either "static if" or template specialization to put code into whatever specific modules/classes they want, and divide all the work up into whatever package structure they want.

Then, when they want to update to a newer DDMD, all they'd have to do in most cases is copy over all the changed files, without merging. The only files they'd typically need to actually merge would be "Main.d" and maybe "dmd/DDMDExtensions.d" in the rare case it got changed.

I'm currently doing something like this in my Dax project (still only pre-alpha though) ( http://www.dsource.org/projects/dax ), and it seems to be working so far, but I still have to merge those couple of changed lines in each of many different files when updating to a new DDMD. If I put my suggestion above into DDMD, then not only would I not have to do that merging, but neither would anyone else who wants to make a project based off DDMD.

Good idea? Bad idea? Alternate idea? Comments?
Back to top
View user's profile Send private message
doob



Joined: 06 Jan 2007
Posts: 367

PostPosted: Sun Oct 31, 2010 2:54 am    Post subject: Reply with quote

One thing that I can think of is that if there's many of these mixins it can slow down the compilation.
Back to top
View user's profile Send private message
Abscissa



Joined: 23 Feb 2005
Posts: 40
Location: Cleveland, OH, US

PostPosted: Fri Mar 25, 2011 3:13 pm    Post subject: Reply with quote

doob wrote:
One thing that I can think of is that if there's many of these mixins it can slow down the compilation.


If that is so, I suspect it would only apply to projects that actually make use of it. I can't imagine it would significantly slow down compilation when they're not actually used (such as when building DDMD itself).

One other thing I thought of is that DVCSs might already make the merging process trivial anyway. I have no idea how true that is since I haven't made the leap from SVN yet, but even if it is so, this proposal might still be helpful for those who, for whatever reason, aren't using a DVCS.
Back to top
View user's profile Send private message
Abscissa



Joined: 23 Feb 2005
Posts: 40
Location: Cleveland, OH, US

PostPosted: Tue Jun 07, 2011 9:40 pm    Post subject: Reply with quote

I've gone ahead and implemented this, but without the "insertGlobalExtension" (at least for now), and using "T" instead of "string name".
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> ddmd All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group