Page 3 of 4
Re: The sky is falling, the sky is falling!!
Posted: Wed Aug 05, 2009 2:15 am
by jaoudestudios
josh wrote:Would much rather have [proper] lambda. And Jab, no. I would rather use objects to control my execution thru composition

I'm sure some people would rather use the goto too.
I'm with Josh on this! There is no need for GOTO - this is a step back for PHP

Why dont they spend their time doing more important features. i.e multi-threading, daemonisation etc...
Re: The sky is falling, the sky is falling!!
Posted: Wed Aug 05, 2009 8:22 am
by Jenk
There is absolutely no need for Multithreading in PHP.
Re: The sky is falling, the sky is falling!!
Posted: Wed Aug 05, 2009 10:01 am
by pickle
GOTO, like guns, are tools to be used by the user. They can be used for good, or for bad. For example, I think this is a valid use of this GOTO
Code: Select all
$myArray = array(1,3,2,58,47,19);
$sum = 0;
$count = 0;
foreach($myArray as $number)
{
if($number < 20)
{
$sum += $number;
$count ++;
if($sum > 15)
goto found:
}
}
found:
echo $number.'<br />';
echo $count.'<br />';
It doesn't jump around the code, is easy to follow, and is more efficient than you could do without the goto. PHP 5.3 is giving us more power, we just need to accept the responsibility to use it properly.
Re: The sky is falling, the sky is falling!!
Posted: Wed Aug 05, 2009 10:03 am
by jaoudestudios
Jenk wrote:There is absolutely no need for Multithreading in PHP.
That is not true! It depends on the project. Multi-threading can be a huge benefit in many places, especially when dealing with large applications and data sets.
Re: The sky is falling, the sky is falling!!
Posted: Wed Aug 05, 2009 11:29 am
by Eran
pickle, you can use 'break' to achieve the same effects. I agree with you about the GOTO sentiments though
Re: The sky is falling, the sky is falling!!
Posted: Wed Aug 05, 2009 12:21 pm
by josh
It depends on what you're writing, what could be of use to some may not be to others, the only practical use for goto I can see so far is for your designer to use to jump to an HTML block within a phtml file or something, even then there are better ways of doing it. Too bad you can't do
$goto = 'foo';
goto $goto;
foo:
echo 'works';
exit();
I assume this doesn't work but I'm not at a terminal with PHP 5.3
Re: The sky is falling, the sky is falling!!
Posted: Wed Aug 05, 2009 2:15 pm
by redmonkey
jaoudestudios wrote:I'm with Josh on this! There is no need for GOTO - this is a step back for PHP

Why dont
they spend their time doing more important features. i.e multi-threading, daemonisation etc...
There is no 'they' in the true sense, PHP is an open source project, you could always implement these features yourself and submit a patch to the project.
Personally I think goto can be useful for getting out of deeply nested loops but, like some other language constructs, used heavily can lead to code which could be difficult to read/follow.
If you don't like it don't use it, your scripts are not suddenly going to start failing because your not using goto. I can't imagine the inclusion of goto adds any real noticeable overhead to the interpreter so, if you don't need or want it does it really matter if it's available or not?
Re: The sky is falling, the sky is falling!!
Posted: Thu Aug 06, 2009 2:27 am
by jaoudestudios
redmonkey wrote:if you don't need or want it does it really matter if it's available or not?
True, but when collaborating with other developers on a project, if it is there and can be an easier route (not necessarily the best), there is a huge possibility that it will get used and abused - thats my only concern!
Re: The sky is falling, the sky is falling!!
Posted: Thu Aug 06, 2009 3:14 am
by Christopher
jaoudestudios wrote:I'm with Josh on this! There is no need for GOTO - this is a step back for PHP
It is not a step back because they have not removed any features.
I think this has been discussed many times, but there are a class of problems, parsers are the common example given, where using goto products cleaner, clearer code. You can go back to the inventors of the structured programming constructs to see that even they understood that they were not the best solution for all programming problems. Nothing is perfect.
And for those who are not clear, the new PHP goto is really a break-to-label and not a pure goto. So you can only goto out of loops, not into them, etc.
Re: The sky is falling, the sky is falling!!
Posted: Thu Aug 06, 2009 4:22 am
by Darhazer
Actually goto is usefull in other languages if you need to exit from a nested loop, for example:
Code: Select all
while ($something)
while($someother)
if ($somecondition) goto end;
end:
But in PHP you have break $x to exit from nested loops
Re: The sky is falling, the sky is falling!!
Posted: Thu Aug 06, 2009 5:43 am
by Christopher
Darhazer wrote:But in PHP you have break $x to exit from nested loops
But goto label is less error prone than break n. If you add/remove a nesting level the goto label still works, but you can forget to update the break n.
Re: The sky is falling, the sky is falling!!
Posted: Thu Aug 06, 2009 8:28 am
by jackpf
But surely you could do this instead:
Code: Select all
$break = false;
while ($something && $break !== true)
while($someother && $break !== true)
if ($somecondition) $break = true;
Goto would use less code...but still, it's not necessary.
Re: The sky is falling, the sky is falling!!
Posted: Thu Aug 06, 2009 8:45 am
by VladSun
jackpf wrote:But surely you could do this instead:
Code: Select all
$break = false;
while ($something && $break !== true)
while($someother && $break !== true)
if ($somecondition) $break = true;
Goto would use less code...but still, it's not necessary.
What about recoding this:
Code: Select all
while ($something)
{
while($someother)
{
process($someother);
if ($somecondition) goto end;
process2($someother);
}
process3($something);
}
end:

Re: The sky is falling, the sky is falling!!
Posted: Thu Aug 06, 2009 8:58 am
by redmonkey
jaoudestudios wrote:redmonkey wrote:if you don't need or want it does it really matter if it's available or not?
True, but when collaborating with other developers on a project, if it is there and can be an easier route (not necessarily the best), there is a huge possibility that it will get used and abused - thats my only concern!
Any project that involves more than one developer should have a coding standard.
Re: The sky is falling, the sky is falling!!
Posted: Thu Aug 06, 2009 9:13 am
by jackpf
VladSun wrote:jackpf wrote:But surely you could do this instead:
Code: Select all
$break = false;
while ($something && $break !== true)
while($someother && $break !== true)
if ($somecondition) $break = true;
Goto would use less code...but still, it's not necessary.
What about recoding this:
Code: Select all
while ($something)
{
while($someother)
{
process($someother);
if ($somecondition) goto end;
process2($someother);
}
process3($something);
}
end:

Code: Select all
$break = false;
while ($something && $break !== true)
{
while($someother && $break !== true)
{
process($someother);
if ($somecondition){$break = true; break;}
process2($someother);
}
if($break !== true)
process3($something);
}
But yeah, I see your point now

Still, I think they should have gone with the original idea and allowed break to jump to a label, rather than having a full blown goto statement.