<div dir="ltr">I'd go with the former, especially if the method is pretty short and there's only one test. In most cases I'd probably be answering self, unless the nature of the method is such that it should answer something else (e.g., nil.)<div>
<br></div><div style>In general I find the early return to be idiomatic and familiar from a lot of other Smalltalk code, but to an extent this perception could be colored by a personal aesthetic preference, so YMMV. And I want the up-arrow glyph back, too :P</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Oct 23, 2013 at 2:39 PM, Louis LaBrunda <span dir="ltr"><<a href="mailto:Lou@keystone-software.com" target="_blank">Lou@keystone-software.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Thank you everyone for your answers.<br>
<br>
Lou<br>
<div class="HOEnZb"><div class="h5"><br>
>Kent Beck refers to the former as "Guard Clause" in his BP book and<br>
>agrees with you about when to use it.<br>
><br>
>I think it's good to only have returns at the top (guard clauses) or<br>
>bottom. Not in the middle.<br>
><br>
><br>
>On Wed, Oct 23, 2013 at 9:12 AM, Louis LaBrunda<br>
><<a href="mailto:Lou@keystone-software.com">Lou@keystone-software.com</a>> wrote:<br>
>> Hi,<br>
>><br>
>> I'm about to write a method where I need to test whether to do something or<br>
>> just get out. What is the best practices way to do this? For example:<br>
>><br>
>> (a = b) ifTrue: [^nil].<br>
>> *The code that does the work*<br>
>><br>
>> or:<br>
>><br>
>> (a = b) ifFalse: [<br>
>> *The code that does the work*<br>
>> ].<br>
>><br>
>> I think the second is better style but I have used both. Generally using<br>
>> the first when *The code that does the work* is long and the second when it<br>
>> is short.<br>
>><br>
>> Is there any speed difference between them? I doubt it but I thought I<br>
>> would ask anyway.<br>
>><br>
>> Lou<br>
>> -----------------------------------------------------------<br>
>> Louis LaBrunda<br>
>> Keystone Software Corp.<br>
>> SkypeMe callto://PhotonDemon<br>
>> mailto:<a href="mailto:Lou@Keystone-Software.com">Lou@Keystone-Software.com</a> <a href="http://www.Keystone-Software.com" target="_blank">http://www.Keystone-Software.com</a><br>
>><br>
>><br>
><br>
-----------------------------------------------------------<br>
Louis LaBrunda<br>
Keystone Software Corp.<br>
SkypeMe callto://PhotonDemon<br>
mailto:<a href="mailto:Lou@Keystone-Software.com">Lou@Keystone-Software.com</a> <a href="http://www.Keystone-Software.com" target="_blank">http://www.Keystone-Software.com</a><br>
<br>
<br>
</div></div></blockquote></div><br></div>