[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: LFM + LFSP = LFE?




On Monday, June 16, 2003, at 04:04  PM, Michael Vanier wrote:

>
> But does anyone actually do this?  All I've ever seen is the 
> equivalent of:
>
> /bar/ ifTrue: foo.

Sure, it's all over the place.

As in Ruby, you can do stuff that's basically equivalent in different 
ways, choosing whichever variety is most expressive in context:

baz ifTrue; [...] ifFalse: [...].
baz ifFalse: [...] ifTrue: [...].

[self shouldContinue] whileTrue: [...].
[self exitCondition] whileFalse: [...].

Often it's handy to detect and deal with nil values:

foo ifNil: [...].
foo ifNil: [...] ifNotNil: [...].
self someExpresssion ifNotNilDo: [:result | result doSomething].


Best of all, it lets you encapsulate complicated flow control inside an 
expressive method call. This is especially handy for dealing with 
errors. Ruby's syntax for exception handling does reduce the need to 
put if statements all over the place, but it's not as expressive or 
flexible as Smalltalk :

tempVar := aDictionary at: anObject ifAbsent: [DefaultValue].
tempVar := aDictionary at: anObject ifAbsentPut: [DefaultValue].
aDictionary at: anObject ifPresent: [...].

[...] on: Exception do: [...].

[...] ensure: [...].

Socket createIfFail: [...]



Cheers,

Colin