I personally don't find assignments in conditions any less readable. This seems 
to be a point of style.

The only input I have in this discussion pertains to getting accurate code 
coverage stats with lime. When multiple conditions are provided, like so...

if ($foo && $bar)
{
}

Lime won't tell you whether that second condition has coverage. The expanded 
conditional style used in symfony sometimes will give you more accurate 
coverage stats:

if (
  $foo
  &&
  $bar
)
{
}

It's pretty ugly when the conditions are as basic as they are here, but there 
are quantifiable benefits to using the latter style in this case.

Just my 0,014 €...

--

Kris Wallsmith | Release Manager
[email protected]
Portland, Oregon USA

http://twitter.com/kriswallsmith

On Dec 17, 2009, at 9:11 AM, Geoffrey Bachelet wrote:

> The biggest problem with assignement in condition is when you have more than 
> one condition:
> 
> if ($foo = foo() && bar())
> 
> Will not work as expected (given you wanted the result of foo() in $foo). 
> you'd rather write:
> 
> if (($foo = foo()) && bar())
> 
> Also, to avoid confusion with ==, you can invert the terms of the condition:
> 
> if (bar() == 'bar')
> 
> since forgetting a = will raise a fatal error
> 
> also, +1 to what David said
> 
> 
> On Wed, Dec 16, 2009 at 10:24 PM, David at Artefactual 
> <[email protected]> wrote:
> I think this code example is a bit problematic because the conditional
> statement is not actually returning a boolean value, it's relying on
> php's loose comparisons to evaluate the truth of the conditional.  I
> think it's clearer to explicitly indicate your true / false condition:
> 
> if (null !== ($results = $this->getResults()))
> {
> 
> Just my two bits.
> 
> David Juhasz
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "symfony developers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/symfony-devs?hl=en.
> 
> 
> 
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "symfony developers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/symfony-devs?hl=en.

--

You received this message because you are subscribed to the Google Groups 
"symfony developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/symfony-devs?hl=en.


Reply via email to