I think the most common reason for an accidental infinite loop is just a situation where the exit condition can never be reached which can take multiple forms in multiple languages. Corrupting the prior example:
Code:
for ($i = 1; $i <= 10; $i++) { if ($i = 5) { echo "half way there!"; } echo $i; }
That said, it is quite common to have a loop that continues until some process is completed (perhaps you are calculating the first prime with more then 10 digits...) your loop will proceed indefinitely until that is found... in many programs the exit conditions of these loops may require user input or information from another "thread"... so it would be possible for these loops to run forever if not interupted.
So, while it is true to say that you would never purposefully program an infinite loop, they are easy to make by accident and "indefinite loops" are quite common.
EDIT: I can recall having written 2 infinite loops on purpose. The first was to see what would happen if I just kept moving the pointer to new memory locations and zeroing the value there... the second was a "find the first prime with 10 digits" type problem where I figured it would execute faster if I let the program just spit out primes and then I could count the digits myself and then force quit the program when I saw a big enough number get spit out... but in both cases I intended for the program to stop executing eventually... I just didn't intend for that to happen due to something within my code.
Joined: 22 Feb 2006, 01:02 Location: cheap kitchen
Quote:
second was a "find the first prime with 10 digits" type problem where I figured it would execute faster if I let the program just spit out primes and then I could count the digits myself and then force quit the program when I saw a big enough number get spit out
for (;;) basically means while (true) - infinite but scroll down, there is no sleep, only short breaks. Because it is a typed language this allows c to run full throttle real runtime, all the time. It is basically http://en.wikipedia.org/wiki/Double-clutching the processor.
That makes languages other than Lua so much faster and easier to optimize. For example in phython you can count to potato no problem and the consequences will never be the same as in Lua. (check it out)
Quote:
Now, I want you to copy-paste and run this in PHP:
I put an extra echo 'Hello World'; in the loop and tested it with http://writecodeonline.com/php/ It did not crash/hang which makes sense because php also has a c-style synthax.
Joined: 17 Nov 2005, 02:43 Location: Raegquitting Spring on 04/24/12
Z, What is your deal? I am well aware of the fact that an infinite loop is bad.
I am fully aware that you CAN create an infinite loop in any language that supports looping.
You obviously didn't pay any attention to the commit you linked to, if you had, you would have noticed that I removed an entire side of the factory. As such, I was removing large swaths of bos. Obviously, I just selected 1 line too many, as there are other places were the sleeps stayed perfectly fine.
It didn't cause a problem then, because the loop never got run! It wasn't until I got the bright Idea to add a tech requirement to the factory that that code finally got run!
Have you never overlooked something trivial that caused huge problems? If that code had been getting run, then when i removed that side of the factory, It would have started crashing and I would have known that something was fucked up. It was an easy thing to overlook, because the code in question never got run!
In the meantime, you've been going off the rockers for a reason I haven't quite figured out yet. You act as though I don't know that an infinite loop in bos is bad ... Well of course it's bad, it causes spring to asplode. I have caused an infinite loop before in bos, but that was back when infolog actually wrote instead of being held in memory and then summarily lost (what a silly thing to change), and considering that I had made a change, started spring, and tested it, I KNEW what went wrong right away. This problem here was caused on Feb 8, 2012. I never knew about it, because the code in question never got run!
I was worried because your previous posts read like you thought it was a problem that can't happen in PHP. And also because you answered with a to-ten loop when asked about an infinite one.
Joined: 17 Nov 2005, 02:43 Location: Raegquitting Spring on 04/24/12
Ahhh ok I see where you're coming from now. I was really confused because I didn't understand why you were (from my perspective), going on and on about something I already knew.
What I was trying to point out was that it is a bit more difficult to create an infinite loop in php because one of the basic parameters is specifying when it starts and stops. In bos, that is defined within the loop, which is a little strange imo (not the least of which, the fact that the sleep can be accidentallied). Without the second parameter of a loop in php the loop will completely fail, whereas without the sleep in bos, it becomes infinite. This seems inefficient to me.
I was only trying to illustrate that it was much more difficult to majorly screw it up in php.
Moreover, php and servers generally have protections in place to protect vs infinite loops without causing the entire script to die a painful death.
This in stark contrast to one missing sleep bringing spring to it's knees. Quite radically different.
As shitty as scriptor is, if lua had a parser that told you where the fuckups were, that would be really neat. I do not consider spring to be a good debugger. Like swatting flies with an elephant stampede. Course, I'm sure everyone disagrees with that for one reason or another. For me, I would like a parser just so i can know if the code will run. If I want to see the result I would load up spring.
As a friend of mine says, Wish in one hand and Shit in the other, see which one fills up faster
Joined: 17 Nov 2005, 02:43 Location: Raegquitting Spring on 04/24/12
It's automatically better if you have just written the code and it screws up. It's much harder to diagnose when everything has been fine and all of a sudden, several months later, it starts causing issues.
It's automatically better if you have just written the code and it screws up. It's much harder to diagnose when everything has been fine and all of a sudden, several months later, it starts causing issues.
No, because whatever value you were computing that caused div0 will be garbage at that point, and so the app can as well be killed now (no sence processing undefined value any longer).
Some databases return a NULL after div0 instead of crashing, which can actually be worse if you don't check for it :)
Most of the time you can catch div0 with exception handling or with checks for 0 before doing division, and process the situation yourself without crash.
Users browsing this forum: No registered users and 1 guest
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum