Am 15.04.2009 um 20:55 schrieb Robin Skoglund:

Those aren't errors, and the coding standards say nothing about assignments
in if statements.

Right, nothing to find there… but I really wonder about that.


Putting the assignment in the second condition makes the code more readable.

The alternative is butt-ugly:
if ($this->getUseTranslator() {
  $t = $this->getTranslator();
  if ($t) {
      // translate
  }
}

3 lines extra, which are absolutely not needed. They only make the code
harder to read/follow.

Another alternative -- mentioned in another reply -- is this:
$t = $this->getTranslator();
if ($this->getUseTranslator() && $t) {
  // translate
}

...which is even uglier and harder to read/follow, in addition to retrieving
the translator even though it isn't used.

So no, those aren't errors, and they won't be fixed. You should use the
features of the language you're coding in (PHP), and write lean and
aesthetically pleasing code.



I read many different things about that…
(Zend Studio throws errors on asssignments in if/while statements)

Would be really interesting how other developers think about that!!!

I think "aesthetically pleasing code" is perhaps more a personal thing.
(For example: there are people on this world used to reading right to left)


Cheers

Michael Scholl

[I would prefer 1 line extra…]

Reply via email to