[Newbies] Re: A do with ONLY index? (plus,. a style question)

Blake blake at kingdomrpg.com
Fri Feb 9 01:17:28 UTC 2007

On Sun, 04 Feb 2007 02:16:09 -0800, Klaus D. Witzel  
<klaus.witzel at cobss.com> wrote:

> 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.

When you say "sent automatically by Behavior>>new" is that true? In other  

x := abitraryObject new.

results in an attempt to call arbitraryObject>>initialize?

>  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.

I suppose we don't worry much about the "waste" of, say, setting up some  
features with default values and then having to discard those when the  
user sets them to something actually useful?


More information about the Beginners mailing list