Re: Assigning variables in if's



Gordon wrote:
On Nov 29, 1:22 pm, Toby A Inkster <usenet200...@xxxxxxxxxxxxxxxxx>
wrote:
taps128 wrote:
or more readable(to me)
Readable perhaps, but boring. echo (true === ($err = somefunc())) ? 'ok' :
"error: $err"; is fun. It invites the reader to explore its mysteries; to
embark in a journey of discovery, a quest filled with a sense of awe and
wonder. And in a sense it helps the reader to uncover new things about
*themselves* and unfold the secrets of their very souls.

Plus it saves almost 30 bytes.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 4 days, 20:07.]
[Now Playing: Keane - On a Day like Today]

Sharing Music with Apple iTunes
http://tobyinkster.co.uk/blog/2007/11/28/itunes-sharing/

And is completely contrary to the principles of writing maintainable
code. :) What code does should be self-evident, or at least self-
explanatory and well commented, because the poor sod who has to look
at the code in 18 months time to figure out why it's not behaving as
intended might be you.

The ternary operator should not be 'confusing' to any competent PHP programmer. Don't just leave out the parts that "Aren't your style". Because you will come unstuck one day, when you don't understand something that is normal and quite common.

besides,
echo(true===$e=somefunc())?'ok':"error: $e";

saves even more bytes ;)

- Michael
.



Relevant Pages

  • Re: Assigning variables in ifs
    ... embark in a journey of discovery, a quest filled with a sense of awe and ... And in a sense it helps the reader to uncover new things about ...
    (comp.lang.php)
  • Re: Assigning variables in ifs
    ... embark in a journey of discovery, a quest filled with a sense of awe and ... And in a sense it helps the reader to uncover new things about ... a Perl programmer would be more confused. ...
    (comp.lang.php)
  • Re: Assigning variables in ifs
    ... embark in a journey of discovery, a quest filled with a sense of awe and ...
    (comp.lang.php)
  • Re: LUL false advertising
    ... you must touch your Oyster card on the reader at ... journey ... (zone 1), changing at Stratford onto the Central Line. ...
    (uk.transport.london)
  • Re: Assigning variables in ifs
    ... just fine with me, but as a general rule, fun code invites ... the code reviewer to explore the mysteries of the ... journey of discovery is the last thing ...
    (comp.lang.php)