[NIT] Pretty pretting #ifFalse:ifTrue:

Stefan Schmiedl s at xss.de
Mon Nov 19 18:36:49 UTC 2001


careful, stupid question ahead.

Tim Rowledge (2001-11-19 08:36):

> Almost; the problem arises (just an example I got bitten by recently in
> swiki code) if you have a temp used in a loop thusly:-
> 
> |temp a b|
> inputCollection do:[el|
>   temp _ Array new:2.
>   a _ el foo.
>   b _ (el bar) isNil ifTrue:[nil] ifFalse:[el bar].
>   temp at: 1 put: a.
>   temp at: 2 put: b.
>   outputCollection add: temp]

maybe my knowledge of smalltalk is not as good as i thought ...

b _ (el bar) isNil ifTrue:[nil] ifFalse:[el bar].

what should this line achieve?
i take it that el bar has no side effects, as you call
it once or twice, so all you need is the return value.

if el bar is nil then b _ nil
if el bar is not nil then b _ el bar

so why not say just b _ el bar ??

s.
-- 
Stefan Schmiedl
EDV-Beratung, Programmierung, Schulung
Loreleystr. 5, 94315 Straubing, Germany
Tel. (0 94 21) 74 01 06
Public Key: http://xss.de/stefan.public

shhhh ... I can't hear my code!




More information about the Squeak-dev mailing list