>> Just name it "size" please. There is no <comment: ''> pragma in
>> methods. Finally, please put a single ^ outside the if blocks.
>
> So no return from within the if? What is the reasoning? What would be
> preferred, assign to a local variable and then return, or put the return
> before the object ifNil check?
Answering both question with a citation from "Smalltalk Best Practice Patterns":
Assignment and return are often found in both branches of a
conditional. Look for opportunities to factor both to the outside of
the conditional. Here is an example of a return on both branches of a
conditional:
cost
self isInitialized
ifTrue: [^self calculateCost]
ifFalse: [^0]
If I write code like this, I don’t mean “here are two alternative
paths of execution,”, I mean, “here are two alternative values to be
returned.” Thus, a Conditional Expression expresses my intent more
clearly:
cost
^self isInitialized
ifTrue: [self calculateCost]
ifFalse: [0]
Paolo
_______________________________________________
help-smalltalk mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-smalltalk