On Mon, Feb 15, 2016 at 11:11 AM, Denis Kudriashov <dionisi...@gmail.com> wrote:
> I compared doesNotUnderstand: vs cannotInterpret: versions of proxies. > > DNUProxy>>doesNotUnderstand: aMessage > lastMessage := aMessage. > ^'from DNU proxy' > > CannotInterpretProxy>>cannotInterpret: aMessage > lastMessage := aMessage. > ^'from cannot interpret proxy' > > > And DNU proxy works 2 times faster then #cannotInterpret proxy. > > [proxy someMessage] benchFor: 2 seconds. > > DNU: > "a BenchmarkResult(22,377,669 iterations in 2 seconds. 11,188,835 per > second)" > > CannotInterpet: > "a BenchmarkResult(13,148,735 iterations in 2 seconds 2 > milliseconds. 6,567,800 per second) > > Also DNU version is much more easy to explain. > > So why Ghost uses #cannotInterpret for proxies? (after reading Ghost paper > I can't understand this). > Naked proxy can be easily done by setting superclass to nil: > > ProtoObject subclass: #DNUProxy > instanceVariableNames: '' > classVariableNames: '' > package: 'DNUProxy'. > DNUProxy superclass: nil > As far as I can remember (this was about 4 years ago) The use of #cannotInterpret: was the only way to be able to intercept everything without breaking the system. Subclassing from ProtoObject make your proxy to understand some messages. Subclassing from nil was technically possible, but I found out the system would simply crash as it didn't know at all how to handle other subclasses of nil. Even with the debugging support I added as you can read in the paper. Maybe things have changed. If subclassing from nil does not break the system and you can still inspect, debug proxies, then sure, you can give a try to Ghost using #dnu rather than #cannotInterpret:. In fact, I would like to have a dnu-based approeach that is as reliable as it was #cannotInterpret: in the sense of how much I can intercept. With #cannotInterpret I could trap EVERYTHING (everything but #==) and then decide what to do. Subclassing from nil would get you there too if you make it work. The #cannotInterpret: over #dnu: is only one of the decisions behind Ghost. That is, you can still get some of the Ghost benefits if you use dnu (separation of proxy from handler, dynamically allow debugging or not, be able to proxy and become classed and methods, etc etc). ps: I don't remember if there was something also with the fact of proxying (and becoming) classes and methods. Ghost allows to proxify classes and methods, and even leave instances of them in the system...and sending a message to those instances (whose class is a proxy) would intercept the message in the class. Ghost has several tests for all these cases. So if you want to give it a try with the DNU approach you should check if this still works... The #cannotInterpret may have some trick for when we proxy classes... I cannot remember... but maybe. Cheers, -- Mariano http://marianopeck.wordpress.com