Dr.Ruud wrote:
Why do people who write these books have exercises of little
practical value?
An exercise needs to be educational.
I have worked in programming for 25 years and during that time I have never use
a closure and have never seen one used. I may be harsh in my definitions but
to me something that is never used is useless. Teaching people to do useless
things is not educational.
closure introduce another layer of compile/run to the program. They
should be avoided.
Why would a "closure introduce another layer of compile/run"?
A closure carries an environment, so just call it an object.
Dealing with a closure has two phases. A phases when its created (compiled
phase) and one when it's executed (run phase). When you write a closure you
have to keep the two phases in mind (and separate).
For example, in the OP's problem there are three parameters: the start time,
the stop time, and the staring directories. Since it doesn't make much sense
to separate the start ans stop times, I shall treat them as a data set called
times. There are four ways to distribute them:
1. All are parameters to the closure generator. In this case, the closure is
not very flexible. What it can tell are if a file has been modified between
its runs.
2. The times are closure-generator parameters and the starting directories are
closure parameters. This gives a closure that can look at different
directories but in the same time interval.
3. The starting directories are closure-generator parameters and the times are
closure ones. This gives a closure that looks at the same directories but with
different time intervals.
4. All are parameters are closure ones. This gives a closure that is very
flexible but is little different from a common sub.
The problem with closures is that you have to write them and their generators
at the same time. So you have to keep two different phases in mind, the
compile phase and the run phase, while remembering what parameters belong to
which phase.
Objects can do the same things as closures, which is store and hide data, but
don't have this problem of having to keep in mind two phases of the same code.
--
Just my 0.00000002 million dollars worth,
Shawn
"For the things we have to learn before we can do them, we learn by doing them."
Aristotle
"If you think Terrans are comprehensible, you don't understand them."
Great Fang Talphon
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/