[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-smalltalk] Re: Question regarding DatagramSocket...
From: |
Paolo Bonzini |
Subject: |
Re: [Help-smalltalk] Re: Question regarding DatagramSocket... |
Date: |
Sat, 12 Jun 2010 10:30:15 +0200 |
>> 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] Question regarding DatagramSocket..., Holger Hans Peter Freyther, 2010/06/11
- Re: [Help-smalltalk] Question regarding DatagramSocket..., Paolo Bonzini, 2010/06/11
- Re: [Help-smalltalk] Question regarding DatagramSocket..., Holger Hans Peter Freyther, 2010/06/11
- [Help-smalltalk] Re: Question regarding DatagramSocket..., Paolo Bonzini, 2010/06/11
- [Help-smalltalk] Re: Question regarding DatagramSocket..., Holger Hans Peter Freyther, 2010/06/12
- Re: [Help-smalltalk] Re: Question regarding DatagramSocket...,
Paolo Bonzini <=
- Re: [Help-smalltalk] Re: Question regarding DatagramSocket..., Holger Hans Peter Freyther, 2010/06/16
- Re: [Help-smalltalk] Re: Question regarding DatagramSocket..., Paolo Bonzini, 2010/06/16
- Re: [Help-smalltalk] Re: Question regarding DatagramSocket..., Stefan Schmiedl, 2010/06/16