I've been thinking about reuse, and integration, for a few months now from the context of maintaining the PWS. It's almost a holiday weekend (for us in the U.S.), so perhaps I might waste some bandwidth describing some of these ideas. I doubt that the solutions I've been considering are at all new, but perhaps someone could kindly point me toward similar thoughts.
A bunch of people on the PWS list are generating some wonderful additions to the system. However, these additions often conflict with one another. The most common conflict is that two additions modify the same method, but one modifies a couple lines at the top (for example), while the other modifies a couple of lines at the bottom.
One answer is, "Better factoring." If that one method were several smaller methods, then each contributor would only be modifying unit methods. That may be, but it seems to me that there is no one factoring that would mean that *all* possible enhancements/additions/modifications to the system would only touch unitary methods. There's probably a theorem about O-O systems that makes this case somewhere.
While the PWS could clearly use better factoring, even if there isn't a perfect factoring, I've been wondering about the general case. How can I add or replace functionality in units-smaller-than-a-method, without disturbing existing functionality?
I've been thinking about units of code not as lines, but as tuples. Methods could be assembled from these tuples. Each tuple has three elements: ({A statement or guarantee of purpose}, {A predicate to determine ordering}, {An expression})
------<example> Let me take an example from PWS to describe what I mean. The portion of code in ServerAction that responds to a request with a file assembles a header might look something like this in Tuple form:
(SendSuccess, First, request reply: PWS success) (SendType, After SendSuccess, request reply: PWS textContent) (SendFile, After SendType, request reply: (FileStream fileNamed: pieces) contentsOfEntireFile)
Recently, someone wanted to serve GIFs, and we realized that we were still (after all this time!) only wired to send text files in normal server mode. (Ted fixed it a long time ago from Swikis.) I'd love to have been able to distribute the single Tuple, which wouldn't modify anything else in the method:
(SendType, After SendSuccess, request reply: 'Content-type:',(MIMEDocument guessTypeFromName: pieces), PWS crlf)
Further, someone else came up with something relevant to put in the header, as I recall, to prevent proxy servers from caching an edit page. I don't recall the exact details, but perhaps it could be distributed as a single tuple like this:
(SendMeta, After SendType and Before SendFile, request reply: 'do not cache me!')
-----</example>
This is different than just methods and factoring, because of the ability to insert new functionality by modifying the predicates, but without rewriting the whole method. It's similar to production rule systems, in some sense, but the ordering can be determined before execution, so it can be much faster.
There are lots of holes here. For example, how small does that expression unit have to be to be useful? Do we end up writing assembly code, for example? But again, it's nearly a holiday weekend, so perhaps you'll excuse some half-baked discussion.
I haven't read much of Bertrand Myer's work, but my guess is that he's someone who's probably worked out things like this. Any suggestions?
Thanks, Mark
-------------------------- Mark Guzdial : Georgia Tech : College of Computing : Atlanta, GA 30332-0280 (404) 894-5618 : Fax (404) 894-0673 : guzdial@cc.gatech.edu http://www.cc.gatech.edu/gvu/people/Faculty/Mark.Guzdial.html
squeak-dev@lists.squeakfoundation.org