[squeak-dev] DynamicObjects

Levente Uzonyi leves at caesar.elte.hu
Mon Apr 27 22:32:54 UTC 2020


On Mon, 27 Apr 2020, Fabio Niephaus wrote:

> Instead of DynamicObject, couldn't you just introduce a very slim subclass of Dictionary, because such objects are really just dictionaries? I'm assuming you're just redirecting calls via DNU anyway? Something like a MessageDictionary or DispatchingDictionary maybe?

Such subclassing is always a bad idea, because it either makes it 
harder to change the superclass (yes, collection implementations tend to 
change even if seldomly, and changing them already requires careful 
migration) or it breaks the subclasses.
Another reason not to subclass is the existence of protocols that make 
sense for a general purpose Dictionary, but not for an expandable object.
Encapsulation is the way to do this.


Levente

> 
> Fabio
> 
> On Mon, 27 Apr 2020 at 9:05 am, Marcel Taeumel <marcel.taeumel at hpi.de> wrote:
>       Hi Christoph.
> > And you should *really* only use this in tests :-)
> 
> Then, as a first step, re-design (and re-name) DynamicObject to not be confused with other use cases. What about mapping the idea of Dictionary class >> #newFrom: to Class or ClassDescription? Make it easier to add/remove methods to/from classes in scripts and tests.
> 
> Best,
> Marcel
>
>       Am 26.04.2020 20:10:15 schrieb Thiede, Christoph <christoph.thiede at student.hpi.uni-potsdam.de>:
>
>       I agree with all your comments about confusion.
>
>       Still, there is one thing you could do with this approach of "DynamicObjects" which our usual meta protocol does not support afaik:
> 
>
>       d := DynamicObject withMethods: {
>     'somePrefix*' -> [:sel | sel allButFirst: 'somePrefix' size].
>     'selector(Regex)+' asRegex -> [:match | match size - 'selector' size / 'Regex' size]
> } asDictionary.
> d somePrefixBanana. "'Banana'"
> d selectorRegexRegexRegex. "3"
> 
> 
> And you should *really* only use this in tests :-)
> 
> @Torge: Interesting point. I could only find a ReverseTrampoline (by googling for smalltalk "subclass trampoline"). :-)
> 
> Best,
> Christoph
> 
> __________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________
> Von: Squeak-dev <squeak-dev-bounces at lists.squeakfoundation.org> im Auftrag von Taeumel, Marcel
> Gesendet: Montag, 20. April 2020 11:03 Uhr
> An: gettimothy via Squeak-dev
> Betreff: Re: [squeak-dev] DynamicObjects  
> Uhh! This feels like JavaScript ... :o) I would rather work on improving Squeak's meta-object protocol and with it class construction and refinement. Especially for tests. Let's not undermine the idea of having classes in Smalltalk.
> -1 for DynamicObject.
> 
> Objects in Squeak/Smalltalk are quite dynamic already. That name is misleading. :-)
> 
> Best,
> Marcel
>
>       Am 18.04.2020 19:55:05 schrieb Thiede, Christoph <christoph.thiede at student.hpi.uni-potsdam.de>:
>
>             d := DynamicObject withMethods: {
> 
> #origin -> [2 @ 3].
> 
> #corner -> [3 @ 7] } asDictionary.
> 
> d origin "2 at 3"
> 
> 
> Did we already have something like this for Squeak? May this become a pattern for situations where you actually don't need a class (e. g., when writing very small mock objects for tests)?
> 
>
>       d := DynamicObject new.
> 
> d xxxMethodAt: #foo put: [self inform: 'Hi!'].
> 
> d xxxMethodAt: #foo: put: [:x | x halt].
> 
> d foo: 3.
> 
> 
> Best,
> Christoph
> 
> 
> 
>


More information about the Squeak-dev mailing list