The sky is falling, the sky is falling!!

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: The sky is falling, the sky is falling!!

Post 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...
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Re: The sky is falling, the sky is falling!!

Post by Jenk »

There is absolutely no need for Multithreading in PHP.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: The sky is falling, the sky is falling!!

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: The sky is falling, the sky is falling!!

Post 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.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: The sky is falling, the sky is falling!!

Post by Eran »

pickle, you can use 'break' to achieve the same effects. I agree with you about the GOTO sentiments though
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: The sky is falling, the sky is falling!!

Post 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
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Re: The sky is falling, the sky is falling!!

Post 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?
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: The sky is falling, the sky is falling!!

Post 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!
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: The sky is falling, the sky is falling!!

Post 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.
(#10850)
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: The sky is falling, the sky is falling!!

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: The sky is falling, the sky is falling!!

Post 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.
(#10850)
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: The sky is falling, the sky is falling!!

Post 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.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: The sky is falling, the sky is falling!!

Post 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:
;)
There are 10 types of people in this world, those who understand binary and those who don't
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Re: The sky is falling, the sky is falling!!

Post 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.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: The sky is falling, the sky is falling!!

Post 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 :P 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.
Post Reply