Hello
Joshua 'Schwa' Gargus
schwa at cc.gatech.edu
Sat May 17 23:17:49 UTC 2003
On Sun, May 18, 2003 at 12:27:41AM +0100, Dominic Fox wrote:
> Hi,
>
> I'm a Squeak/Smalltalk newbie with some experience of doing OO in other
> languages, chiefly VB (which is not at all great for that purpose) and Python
> (which is rather better, but not in use in my place of work), and a
> smattering of FP that's still not settled in my mind. I'm trying to get my
> head round a couple of things in Smalltalk, and the documentation I've
> browsed so far hasn't helped much: my queries more to do with idiom than
> anything else. Can anyone give me a clue as to where I might find some
> answers to questions like these:
>
> * If I want to expose an instance's private fields, do I have to code accessor
> methods every time? Is there an alternative to writing
>
> getFoo
> ^ foo
>
> and
>
> setFoo: newFoo
> foo := newFoo
>
> over and over again?
Yes, there is an alternative. If you open the Preferences browser, the
"general" section has a pref named "autoAccessors" that might do what
you want.
>
> * Is the best way to make what in C++ or Java you'd call "constructors" to
> write class methods that create, initialize and then return an instance, e.g.
>
> newFooWithBar: initialBar
> | newFoo |
> newFoo := Foo new; setBar: initialBar.
> ^ newFoo
>
> or is there a more concise way?
>
That looks about right.
> * Can I treat blocks as first-class entities, e.g. return them from methods,
> pass them around etc? Can I use them to implement LISP-like closures? Even if
> I can, is this a "natural" smalltalky way to do things?
>
Yes, yes, and yes. The second yes is dependent on the block closure work done
by Anthony Hannan. No URL 'cause I'm in a hurry, but check the list archives
for the past couple of months.
> * What about function/method pointers? Can I treat one of an instance's
> methods as a block, or do I have to make a new block and call the method
> inside that?
>
The latter. You might also be interested in Object>>perform:/perform:with:,
and the class MessageSend.
> Finally,
>
> * Is this list a good place to ask questions like this? If it isn't, is there
> a more suitable one?
This is the right place.
Joshua
>
> thanks,
> Dominic
More information about the Squeak-dev
mailing list
|