DynamicObjects

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

DynamicObjects

Christoph Thiede

d := DynamicObject withMethods: {

#origin -> [2 @ 3].

#corner -> [3 @ 7] } asDictionary.

d origin "2@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




DynamicObject.st (2K) Download Attachment
Carpe Squeak!
Reply | Threaded
Open this post in threaded view
|

Re: DynamicObjects

Jakob Reschke
Would be nice for mock objects indeed. For everything else, well it is not so much Smalltalk, rather Self or JavaScript, but without their syntax (and maybe without prototype inheritance). Could be interesting and I am not particularly against it, but users should know that this is not basic Smalltalk. It might "delude" beginners if they get confronted with it too early.

Thiede, Christoph <[hidden email]> schrieb am Sa., 18. Apr. 2020, 19:55:

d := DynamicObject withMethods: {

#origin -> [2 @ 3].

#corner -> [3 @ 7] } asDictionary.

d origin "2@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




Reply | Threaded
Open this post in threaded view
|

Re: DynamicObjects

timrowledge


> On 2020-04-18, at 11:16 AM, Jakob Reschke <[hidden email]> wrote:
>
> Would be nice for mock objects indeed. For everything else, well it is not so much Smalltalk, rather Self or JavaScript, but without their syntax (and maybe without prototype inheritance). Could be interesting and I am not particularly against it, but users should know that this is not basic Smalltalk. It might "delude" beginners if they get confronted with it too early.

Yeah; this seems a good place to remind people of the old but very important programming aphorism -
"Debugging is at least twice as hard as writing code. So if you write the cleverest code you can..."

My advice - if you can't create a tool to help use a neat new trick you just came up with, that will allow other more mortals to make sense of it; don't foist the neat trick on us. We already have way too many things that are hard to follow, find, understand, use, etc  - and that's just in the squeak image!

tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
Strange OpCodes: LOW: Launch on Warning



Reply | Threaded
Open this post in threaded view
|

Re: DynamicObjects

Squeak - Dev mailing list
Amen

/—————————————————————/
For encrypted mail use [hidden email] - Free account at ProtonMail.com
Web: https://objectnets.net and https://objectnets.org
https://datascilv.com https://datascilv.org


On Apr 18, 2020, at 11:22, tim Rowledge <[hidden email]> wrote:



On 2020-04-18, at 11:16 AM, Jakob Reschke <[hidden email]> wrote:

Would be nice for mock objects indeed. For everything else, well it is not so much Smalltalk, rather Self or JavaScript, but without their syntax (and maybe without prototype inheritance). Could be interesting and I am not particularly against it, but users should know that this is not basic Smalltalk. It might "delude" beginners if they get confronted with it too early.

Yeah; this seems a good place to remind people of the old but very important programming aphorism -
"Debugging is at least twice as hard as writing code. So if you write the cleverest code you can..."

My advice - if you can't create a tool to help use a neat new trick you just came up with, that will allow other more mortals to make sense of it; don't foist the neat trick on us. We already have way too many things that are hard to follow, find, understand, use, etc  - and that's just in the squeak image!

tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
Strange OpCodes: LOW: Launch on Warning





Reply | Threaded
Open this post in threaded view
|

Re: DynamicObjects

Torge Husfeldt
In reply to this post by Christoph Thiede
Hi Chris, 
something very similar actually used to be a “thing” in squeak back in the olden times.
It was called a “trampoline” iirc.
Might be worth trying to google that ;)
Hth
Torge

Von meinem iPhone gesendet

Am 18.04.2020 um 19:55 schrieb Thiede, Christoph <[hidden email]>:



d := DynamicObject withMethods: {

#origin -> [2 @ 3].

#corner -> [3 @ 7] } asDictionary.

d origin "2@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

<DynamicObject.st>



Reply | Threaded
Open this post in threaded view
|

Re: DynamicObjects

marcel.taeumel
In reply to this post by Christoph Thiede
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 <[hidden email]>:

d := DynamicObject withMethods: {

#origin -> [2 @ 3].

#corner -> [3 @ 7] } asDictionary.

d origin "2@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



Reply | Threaded
Open this post in threaded view
|

Re: DynamicObjects

Squeak - Dev mailing list

Such a constructed DynamicObject would be useful for Raven. The plan is to extend ASN1 de/encoding to callback to the Scope for each object in the graph being serialized to check for substitution. So using ASN1 to encode between machines. Consider a machine at level 1 and another machine who has advanced to level 3. Level 3 knows about #passByCopy objects that the level 1 machine knows not.

DynamicObject use cases, A) model an unknown class' instance, B) class generation & C)dynamic code loading

A) Level 3 machine sends such an advanced class to the level 1 machine. As this class structure gets decoded, without such a class available, construct as a DynamicObject and set the modeled instance variables with values. I am assuming that in addition to methods, instance variables can be defined with the DynamicObject, to model the ASN1 encoded object.

B) At this point level 1 does not know what to do about the level 3 dynamicObject. During development, an engineer could convert this DynamicObject to a class. So class definition meta-protocol will be needed.

C) During deployment, the DynamicObject could lookup the code Monticello package on the code server, for this new instance's class, and load it. In this fashion a network of nodes can stay updated.

Anyways, here are my use cases for DynamicObject or a similar construct.

K, r

On 4/20/20 5:03 AM, Marcel Taeumel wrote:
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 [hidden email]:

d := DynamicObject withMethods: {

#origin -> [2 @ 3].

#corner -> [3 @ 7] } asDictionary.

d origin "2@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

-- 
Kindly,
Robert


Reply | Threaded
Open this post in threaded view
|

Re: DynamicObjects

timrowledge
In reply to this post by marcel.taeumel


> On 2020-04-20, at 2:03 AM, Marcel Taeumel <[hidden email]> wrote:
>
> 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. :-)

I agree.


tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
CChheecckk yyoouurr dduupplleexx sswwiittcchh..



Reply | Threaded
Open this post in threaded view
|

Re: DynamicObjects

Squeak - Dev mailing list

Yalp! Sure, already have what I need, right?

So define:

ASN1Value subclass: #ASN1DomainObject
    instanceVariableNames: 'className'
    classVariableNames: ''
    poolDictionaries: ''
    category: 'CryptographyASN1-Objects'

Then whenever we have an unknown object to write or reading in the same, output in ASN1 a class structure, with className (let us say #SessionConfig and instance variables:  '

  • selectedCipherName
  • selectedEncoderName
  • cryptoCiphers
  • dataEncoders
  • protocolMap
  • preferredProtocol '

So using ASN1WrapperConstructedType or ASN1ExplicitContextValue,

ASN1WrapperType subclass: #ASN1WrapperConstructedType
    instanceVariableNames: ''
    classVariableNames: ''
    poolDictionaries: ''
    category: 'CryptographyASN1-Types'

Dynamically create a subclass of ASN1DomainObject, with the right ivars (className in the superclass) and accessors:

ASN1DomainObject subclass: #ASN1DOSessionConfig
    instanceVariableNames: 'selectedCipherName selectedEncoderName cryptoCiphers dataEncoders protocolMap preferredProtocol'
    classVariableNames: ''
    poolDictionaries: ''
    category: 'CryptographyASN1-Types'

Thus we dynamically defined a domain object class for the unknown #SessionConfig structure. This meets the needs of A, B & C.

K, r

On 4/20/20 4:10 PM, tim Rowledge wrote:


On 2020-04-20, at 2:03 AM, Marcel Taeumel [hidden email] wrote:

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. :-)
I agree.


tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
CChheecckk yyoouurr dduupplleexx sswwiittcchh..



-- 
Kindly,
Robert


Reply | Threaded
Open this post in threaded view
|

Re: DynamicObjects

Christoph Thiede
In reply to this post by marcel.taeumel

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 <[hidden email]> 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 <[hidden email]>:

d := DynamicObject withMethods: {

#origin -> [2 @ 3].

#corner -> [3 @ 7] } asDictionary.

d origin "2@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



Carpe Squeak!
Reply | Threaded
Open this post in threaded view
|

Re: DynamicObjects

marcel.taeumel
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 <[hidden email]>:

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 <[hidden email]> 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 <[hidden email]>:

d := DynamicObject withMethods: {

#origin -> [2 @ 3].

#corner -> [3 @ 7] } asDictionary.

d origin "2@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



Reply | Threaded
Open this post in threaded view
|

Re: DynamicObjects

fniephaus
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?

Fabio

On Mon, 27 Apr 2020 at 9:05 am, Marcel Taeumel <[hidden email]> 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 <[hidden email]>:

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 <[hidden email]> 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 <[hidden email]>:

d := DynamicObject withMethods: {

#origin -> [2 @ 3].

#corner -> [3 @ 7] } asDictionary.

d origin "2@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




Reply | Threaded
Open this post in threaded view
|

Re: DynamicObjects

Jakob Reschke
You could have a look at MiniSMock (for VA Smalltalk): http://vastgoodies.com/maps/MiniSMock

Fabio Niephaus <[hidden email]> schrieb am Mo., 27. Apr. 2020, 09:22:
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?

Fabio

On Mon, 27 Apr 2020 at 9:05 am, Marcel Taeumel <[hidden email]> 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 <[hidden email]>:

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 <[hidden email]> 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 <[hidden email]>:

d := DynamicObject withMethods: {

#origin -> [2 @ 3].

#corner -> [3 @ 7] } asDictionary.

d origin "2@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





Reply | Threaded
Open this post in threaded view
|

Re: DynamicObjects

Levente Uzonyi
In reply to this post by fniephaus
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 <[hidden email]> 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 <[hidden email]>:
>
>       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 <[hidden email]> 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 <[hidden email]>:
>
>             d := DynamicObject withMethods: {
>
> #origin -> [2 @ 3].
>
> #corner -> [3 @ 7] } asDictionary.
>
> d origin "2@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
>
>
>
>