Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: somewhat related.. (OT)

by Wassercrats
on Mar 17, 2002 at 04:31 UTC ( #152269=note: print w/replies, xml ) Need Help??

in reply to somewhat related.. (OT)
in thread Do-nothing loops

Yes, but if it was up to me, I'd eliminate sleep and make Perl smart enough to know when a loop does nothing but waste time so it will work as sleep and waste no resources. Unless sleep has other uses.

Replies are listed 'Best First'.
Re: Re: somewhat related.. (OT)
by dragonchild (Archbishop) on Mar 18, 2002 at 14:28 UTC
    How would Perl know how long a given no-op loop is supposed to run?

    For example, very old games, like from the early '80's, were written using CPU timers (which are your do-nothing loops). They were built for a computer whose speed was within certain parameters. When you improved your computer, those games got so fast it was ridiculous. (Try playing Pong where the ball moves faster across your screen than your computer can track a keypress!)

    sleep is built so that it receives a certain amount of time. It passes that as a message to the operating system who knows how long a second is. Perl should not make those determinations. That's what operating systems are for. :-)

    So, use the right tool for the right situation. If you need sleep, then use sleep. If you need a no-op loop, then use a no-op loop. (There are uses for them other than spinning your computer's wheels.)

    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

      I "learned" programming on a TRS-80 (I failed the class). Then I taught myself on a Commodore and used those for-next loops to waste time, which is why I figured their used in Perl. I admit that sleep saves a bit of time, but both sleep and do-nothing loops don't work for all the things I used to use them for. As far as I know, you can't write a game like you described in Perl becuase time delays don't work when you want them to work. A time delay for displaying a message before something loads works, but the amount of time isn't very important in that case, and if computers triple in speed in five years, it wouldn't be a big deal.

      But if there is really a use for empty loops in perl besides wasting time, then I guess Perl wouldn't know when to sleepize the empty loop and when not to, so sleep would be needed. If it's just a matter of testing processing speed, something can be put within the loop to prevent Perl from sleepizing it, and sleep can be put to sleep.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://152269]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2018-04-26 00:56 GMT
Find Nodes?
    Voting Booth?