<?xml version="1.0" encoding="windows-1252"?>
<node id="437076" title="Re^2: For clarity and cleanliness, I'd recommend..." created="2005-03-06 14:29:29" updated="2005-08-13 12:44:21">
<type id="11">
note</type>
<author id="107600">
TheDamian</author>
<data>
<field name="doctext">
I agree with you. I would certainly never recommend that people write:

&lt;code&gt;
if ($result = thatroutine()) {
     return $result;
}
&lt;/code&gt;

But, as your &lt;tt&gt;while&lt;/tt&gt;-based variant shows, non-constant assignments in a conditional are always fine if you're &lt;em&gt;declaring&lt;/em&gt; the lvalue variable at that point:

&lt;code&gt;
if (my $result = thatroutine()) {
     return $result;
}
&lt;/code&gt;
In such cases, the &lt;tt&gt;=&lt;/tt&gt; &lt;em&gt;must&lt;/em&gt; be intentional, since &lt;tt&gt;==&lt;/tt&gt; on a newly-created variable doesn't make any sense.

&lt;p&gt;
As for your alternative suggestion, I don't feel it's a clear or as clean as using an &lt;tt&gt;if&lt;/tt&gt;, because the use of a &lt;tt&gt;while&lt;/tt&gt; implies looping behaviour, which the &lt;tt&gt;return&lt;/tt&gt; undermines in a not-entirely-obvious way. That could be especially misleading to subsequent readers of the code if the number of statements in the &lt;tt&gt;while&lt;/tt&gt; block later increases, pushing the &lt;tt&gt;return&lt;/tt&gt; away from the loop keyword it's subverting.</field>
<field name="root_node">
436920</field>
<field name="parent_node">
437047</field>
</data>
</node>
