[ANSI-Smalltalk] Re: A list of interesting methods, ifNotNil:

Richard O'Keefe ok at cs.otago.ac.nz
Mon Sep 29 04:29:31 BST 2008


On 27 Sep 2008, at 2:08 am, Eliot Miranda wrote:
> Slightly inaccurate.  It is really
>         | name |
>         ...
>        name := expression.
>        name ifNotNil: [...]
>
> vs
>         expression ifNotNil: [:name|...]

You are assuming that 'name' would not find other uses.
Looking in my code, where there was a name introduced
for use in #ifNil: or #ifNotNil:, in 6/7 of the cases
I had found another use for that name.  I was actually
surprised that the "wasteful" proportion was as high as
1/7.  I've now reviewed that that code, and decided not
to change it, largely on Andres Valloud's grounds.
>
> Being readably concise, free of boiler-plate and economical with  
> vertical real-estate are far better style than their converses, IMO.

Other things being equal, yes.

I'd much rather be arguing about whether to have #timesRepeat: in
the standard.  It's there on page 20 as one of the restricted
selectors, but it isn't mentioned anywhere else at all.  Would it
not be nice to add

Protocol <integer>

#.#.#.# Message: timesRepeat: operation
Synopsis
	Repeat an operation with no argument some number of times.
Definition: <integer>
	If the receiver is negative or zero, do nothing.
	If the receiver is positive, evaluate operation that
	many times with no argument.
Parameters:
	operation <niladicBlock> unspecified
Return Values
	UNSPECIFIED
Errors
	none

It's traditional, it's common, it's easy to implement,
and it's clearer than making up dummy names.
	Integer>>
	timesRepeat: aBlock
	    1 to: self do: [:i | aBlock value].
	    ^"unspecified"




More information about the ANSI-Smalltalk mailing list