note 69637 added to control-structures.alternative-syntax

From: Date: Wed, 13 Sep 2006 14:29:11 +0000
Subject: note 69637 added to control-structures.alternative-syntax
Groups: php.notes 
Request: Send a blank email to php-notes+get-117108@lists.php.net to get a copy of this message
n response to rlynch AT lynchmarks DOT com: matheo's example is just what it is ... an example!!! Instead of "0" and "1", it could have been "Apple" and "Banana" or "Positive" and "Negative". There's no need to get pedantic (or use HTML tags if you had actually bothered to read the posting instructions). You can't just assume from the example that 0 and 1 equate to true and false. Maybe $is_a_bigger gets multiplied by some other number so that it can "zero it" in the case that $a isn't greater than $b. It's just a simple example and you can't really infer anything further from it. If it was then it's overkill, but that's a pretty big "if" on a simple example without any other code for context Pretty much anyone can learn to program and then apply the skill. Engineering good quality software on the other hand takes a varying amount of practice/experience depending on the person. As such, you can't outright expect *everyone* to code as "brilliantly". While that last statement is overkill on lines for something that could be done in one line, There can be good reasons for using an if/else block with one statement in each over the a trinary form of the if/else, especially if one can easily forsee more lines of code getting added to the block in the short term (adding a line to the block is less prone to accidental syntax errors than having to restructure an existing trinary operator into an if/else block). Again, this is where it's more about "being a good Software Engineer" than "being a good PHP Programmer" In closing, I'm all for the trinary operator for things like simple string echos where either one value gets displayed or another, though I've used it in some wierd ways too that cut down on the lines of code (while still trying to maintain code-readibility). It all just depends on the situation. Whatever makes the code short, "simple", and "easily comprehended" (not necessarily always in that order). ---- Server IP: 66.163.161.117 Probable Submitter: 12.47.22.190 ---- Manual Page -- http://www.php.net/manual/en/control-structures.alternative-syntax.php Edit -- https://master.php.net/note/edit/69637 Del: integrated -- https://master.php.net/note/delete/69637/integrated Del: useless -- https://master.php.net/note/delete/69637/useless Del: bad code -- https://master.php.net/note/delete/69637/bad+code Del: spam -- https://master.php.net/note/delete/69637/spam Del: non-english -- https://master.php.net/note/delete/69637/non-english Del: in docs -- https://master.php.net/note/delete/69637/in+docs Del: other reasons-- https://master.php.net/note/delete/69637 Reject -- https://master.php.net/note/reject/69637 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#117108) next »