[squeak-dev] Best practices question
Francisco Garau
francisco.garau at gmail.com
Wed Oct 23 18:02:00 UTC 2013
I also prefer the first case as it is more readable.
The disadvantage is that you end up having a non local return. And running that same code from a block will fail when a=b.
- Francisco
On 23 Oct 2013, at 16:10, Tobias Pape <Das.Linux at gmx.de> wrote:
> On 23.10.2013, at 16:22, Bob Arning <arning315 at comcast.net> wrote:
>
>> I prefer the first - it gets one case out of the way quickly.
>
> I would say, it depends :)
> If it is only one (or at most two) tests,
> the first case,
>
> but on the other hand, I try to stick to the rule
>
> Only One Return per method, if possible
>
> This helps following the control flow.
>
> Best
> -Tobias
>
>
>>
>> Cheers,
>> Bob
>>
>> On 10/23/13 10:12 AM, Louis LaBrunda wrote:
>>> Hi,
>>>
>>> I'm about to write a method where I need to test whether to do something or
>>> just get out. What is the best practices way to do this? For example:
>>>
>>> (a = b) ifTrue: [^nil].
>>> *The code that does the work*
>>>
>>> or:
>>>
>>> (a = b) ifFalse: [
>>> *The code that does the work*
>>> ].
>>>
>>> I think the second is better style but I have used both. Generally using
>>> the first when *The code that does the work* is long and the second when it
>>> is short.
>>>
>>> Is there any speed difference between them? I doubt it but I thought I
>>> would ask anyway.
>>>
>>> Lou
>>> -----------------------------------------------------------
>>> Louis LaBrunda
>>> Keystone Software Corp.
>>> SkypeMe callto://PhotonDemon
>>>
>>> mailto:Lou at Keystone-Software.com http://www.Keystone-Software.com
>
>
>
More information about the Squeak-dev
mailing list
|