[Newbies] Re: A do with ONLY index? (plus,. a style question)
Klaus D. Witzel
klaus.witzel at cobss.com
Sun Feb 4 10:16:09 UTC 2007
Hi Blake,
on Sun, 04 Feb 2007 10:35:33 +0100, you wrote:
> On Sat, 03 Feb 2007 20:44:50 -0800, Todd Blanchard wrote:
>
>> initializeWithPoint: aPoint
>>
>> rows := (interval 1 to: aPoint x) collect: [:r | Array new: aPoint y].
>
> Also, stylistically, is it preferred to have an instance-based
> initializer rather than a class-based variation on "new"?
You might want to compare:
class side>>new
| instance |
instance := self new.
instance thisAndThat "extra code needed".
^ instance
instance side>>initialize
"sent automatically by Behavior>>new"
iVar1 := 'text'.
iVar2 := 0
The latter is preferable over the former (less code, less maintenance).
But often people put utility methods like #on:, #with: etc on the class
side, for non-trivial initializations.
From the (re-)usability point of view, if you had getters/setters (like in
traits), the perfect approach is
x := MyClass new setY: 'text';
setZ: 0;
yourself.
Or, like I prefer to do it
(x := MyClass new)
setY: 'text';
setZ: 0.
/Klaus
More information about the Beginners
mailing list