getters, setters, attr?

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

getters, setters, attr?

Steve Moffitt
Hi David
You can download the RefactoryBrowser from squeakmap or you can  
download and install the refactoryengine from http://squeaksource.com/ 
@ehoWsqHVuXjcUYEx/wpgyyYAP.
If you look at the menu from the second top pane ( the class pane )  
in the browser the submenu under instance variables will create  
accessors for you.

Steve
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: getters, setters, attr?

Bert Freudenberg
Steve Moffitt schrieb:
> Hi David
> You can download the RefactoryBrowser from squeakmap or you can download
> and install the refactoryengine from
> http://squeaksource.com/@ehoWsqHVuXjcUYEx/wpgyyYAP.
> If you look at the menu from the second top pane ( the class pane ) in
> the browser the submenu under instance variables will create accessors
> for you.

That's in the regular browser, too, in the class's shifted context menu.

- Bert -
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: getters, setters, attr?

Sophie424
One important difference: in Ruby you are using a mini-DSL. Remove or rename
the attr... and the getters and setters follow. In Squeak once you generate
the accessors you deal with them individually. So if you remove the instance
variable, you have to manually remove the accessors.

Since you are in an image-based world with Squeak, a solution closer to Ruby
would be to extend Class with methods like
  add_attribute: name :rw aBoolean
  remove_attribute :name
and invoke these directly on the appropriate classes. I suppose you can also
extend the environment to put these onto menus.

You could step these up to Active-Record like DSLs (Magritte does equivalent
things)
  add_attribute: name :rw aBoolean multiple: aBoolean inverse: aName

My (naive) understanding is that somehow this DSL-like style does not appear
to have become popular in the Smalltalk world. Is that true?


----- Original Message -----
From: "Bert Freudenberg" <[hidden email]>
To: "A friendly place to get answers to even the most basic questions
aboutSqueak." <[hidden email]>
Sent: Thursday, September 07, 2006 2:14 PM
Subject: Re: [Newbies] getters, setters, attr?


> Steve Moffitt schrieb:
>> Hi David
>> You can download the RefactoryBrowser from squeakmap or you can download
>> and install the refactoryengine from
>> http://squeaksource.com/@ehoWsqHVuXjcUYEx/wpgyyYAP.
>> If you look at the menu from the second top pane ( the class pane ) in
>> the browser the submenu under instance variables will create accessors
>> for you.
>
> That's in the regular browser, too, in the class's shifted context menu.
>
> - Bert -
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

RE: getters, setters, attr?

Ramon Leon-5
> My (naive) understanding is that somehow this DSL-like style
> does not appear to have become popular in the Smalltalk
> world. Is that true?

That's because this style relies on the fact that Ruby programs are text, in
a file, that get's run to create a live environment.  During this run phase,
those call's expand into getters and setters, similar to Lisp macro's.  By
contrast, Smalltalk is always running, you aren't editing text files, you're
editing the live objects directly, essentially the expanded form in
Ruby/Lisp terms.  So this style doesn't really suit Smalltalk.

Smalltalkers would handle dynamic getters and setters by hacking
doesNotUnderstand: and checking a local dictionary for the prop, like
ActiveRecord does, something like...

doesNotUnderstand: aMessage
    ^self properties at: aMessage selector
        ifAbsent: [super doesNotUnderstand: aMessage]

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: getters, setters, attr?

Sophie424
> So this style doesn't really suit Smalltalk.

I was referring to the image-based equivalent I had outlined ...

  Since you are in an image-based world with Squeak, a solution closer to
Ruby
  would be to extend Class with methods like
    add_attribute: name rw: aBoolean
    remove_attribute: name
  and invoke these directly on the appropriate classes. I suppose you can
also
  extend the environment to put these onto menus.

Whether add_attribute and remove_attribute use an #attribute_dictionary on
the class and key off #doesNotUnderstand, or dynamically add/remove real
accessor methods, could be a separate design decision.

My (naive :-) understanding is that this kind of dsl-ish enhancement is not
commonly used in the smalltalk world. e.g. I could not find anything in
squeak-map to automate simple things like maintaining relations / inverse
pointers between objects. I'd be quite glad to be wrong ...


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

RE: getters, setters, attr?

Ramon Leon-5
> Whether add_attribute and remove_attribute use an
> #attribute_dictionary on the class and key off
> #doesNotUnderstand, or dynamically add/remove real accessor
> methods, could be a separate design decision.
>
> My (naive :-) understanding is that this kind of dsl-ish
> enhancement is not commonly used in the smalltalk world. e.g.
> I could not find anything in squeak-map to automate simple
> things like maintaining relations / inverse pointers between
> objects. I'd be quite glad to be wrong ...

Look for Tsunami on Squeak map.

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: getters, setters, attr?

Sophie424
> Look for Tsunami on Squeak map.

Ah, thanks Ramon! Will certainly try this out.


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: getters, setters, attr?

David Pollak
In reply to this post by Ramon Leon-5
Thank you all for your help!

On Sep 8, 2006, at 8:25 AM, Ramon Leon wrote:

>> My (naive) understanding is that somehow this DSL-like style
>> does not appear to have become popular in the Smalltalk
>> world. Is that true?
>
> That's because this style relies on the fact that Ruby programs are  
> text, in
> a file, that get's run to create a live environment.  During this  
> run phase,
> those call's expand into getters and setters, similar to Lisp  
> macro's.  By
> contrast, Smalltalk is always running, you aren't editing text  
> files, you're
> editing the live objects directly, essentially the expanded form in
> Ruby/Lisp terms.  So this style doesn't really suit Smalltalk.
>
> Smalltalkers would handle dynamic getters and setters by hacking
> doesNotUnderstand: and checking a local dictionary for the prop, like
> ActiveRecord does, something like...
>
> doesNotUnderstand: aMessage
>     ^self properties at: aMessage selector
>         ifAbsent: [super doesNotUnderstand: aMessage]
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners