[NIT] Pretty pretting #ifFalse:ifTrue:

Tim Rowledge tim at sumeru.stanford.edu
Mon Nov 19 16:36:10 UTC 2001


"Andrew C. Greenberg" <werdna at mucow.com> is widely believed to have written:

> Aren't these expressions semantically identical?  Doesn't
> 
> 	bool ifTrue: block
> 
> evaluate to nil if bool is false?
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]

... or similar. I know it's a bit ugly but there y'go.

Pretty printing will remove the branch that sets b to nil and since b is
a method temp that will very possibly have been set to something else in
a previous loop around.... whoops.

tim
-- 
Tim Rowledge, tim at sumeru.stanford.edu, http://sumeru.stanford.edu/tim
Press [ESC] to detonate or any other key to explode.





More information about the Squeak-dev mailing list