I have some Java like this:
if (!fooclass.getInfoText().equals(""))
{
this.setInfoText(fooclass.getInfoText());
}
Is there a neater way of setting one value based on the test results of another value? It seems nasty to me that the method is run twice, but putting the result in a variable when it may be empty and not used at all seems equally messy.
In PHP I might do:
if (($foo = $bar->baz()) !== "")
{
$this->set_info_text = $foo;
}
But I know some people are quite strongly for and against this method, though I can't recall a good justification against it.