On Fri, 2004-07-30 at 15:13, Andi Gutmans wrote: > At 03:11 PM 7/30/2004 -0400, Robert Cummings wrote: > >On Fri, 2004-07-30 at 13:11, Andi Gutmans wrote: > > > Rob, > > > > > > First of all I don't know where you are getting O(n) from because the > > > operation is O(1). > > > Secondly, I just don't understand what the sudden necessity for the goto > > > construct is when over the years we have barely ever had a PHP developer > > > asking for it. > > > And please guys, don't use C optimization comparisons as an example. This > > > doesn't apply to PHP... > > > >Goto is O(1) -- cascading through switch cases till you hit the right > >one is O(n) where there are n possible cases. Now if I have to run > >through that damn switch time m times, then my runtime is O(mn) whereas > >with goto it's O(m). This isn't a C optimization, this is just the best > >way to do it sometimes. Even if goto was a runtime lookup I'm still > >better off with O(m lg n). > > But you have break n in PHP. I guess we are talking about different things. > Can you show me an example of when it'd be O(n)?
You're on about the while emulation, I was talking about emulation using a status var and switch to determine what to do based on the status var's value. In which case for every possible status (n possibilities) the average time to find the desired block in a switch is O(n). I agree break n is O(1) since the jump is hard wired. However, I do argue that the while implementation is much dirtier than that of goto since you are using a while loop as a 1 time conditional rather than it's purpose of traversal over some data set or until some condition is met. This makes the purpose of code much harder to determine since the first reaction is not to think, "oh, he's using a while loop to emulate the preferable goto", but rather "what the hell is this loop doing here" :) I admit I used to use the same semantics in my C code, and still do so in PHP, to avoid the demonized goto, but then I learned that goto has a time and a place and can often be the most concise and succinct method of achieving a goal. I think you mentioned also (correct me if it wasn't you) that this wasn't an issue till recently, why has nobody had this concern before. To be honest I almost brought it up a year ago, but I hadn't heard anyone else, and with the preconceptions many have with goto, I just let it go. Now that I see there's plenty of users who want it, I think it's time to put up a good argument and try to see it into the engine. Cheers, Rob. -- .------------------------------------------------------------. | InterJinn Application Framework - http://www.interjinn.com | :------------------------------------------------------------: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `------------------------------------------------------------' -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php