in reply to Re^10: Making a variable in a sub retain its value between calls
in thread Making a variable in a sub retain its value between calls
you apparently consider INIT blocks to be at best useless, at worst harmful, and certainly misnamed (i.e. not suitable for initialization). Do you have any use for them?
Useless: no. Harmful: no. Misnamed: no. Misunderstood: yes! They're useful when, and only when, you need to delay execution of something to before the program starts. For instance, Attribute::Handlers use INIT out of necessity, because it has no way of doing what it needs to do (for subroutines) at compile-time, so it needs to delay it to run-time (but even there it's not optimal to use INIT because it delays execution unnecessarily much, but it's the best Perl currently gives you). INIT should be used when you need to delay initialization code, not just execute initialization code in general.
Regarding p 223 in Camel 3rd: It doesn't say that BEGIN and INIT may be equivalently used. It says that you can use both. It doesn't mean that one of them in general isn't better or that they don't have different uses.
If INIT blocks are so evil, why is the Camel giving such advice?
I guess that's a question the authors answer best. Update: As should be clear in my very first four sentences in this post I don't consider INITs evil. The misuse of them is though. (Whether the Camel misuse them or not I don't know since I don't own the Camel.)
ihb
See perltoc if you don't know which perldoc to read!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^12: Making a variable in a sub retain its value between calls
by TimToady (Parson) on Apr 19, 2005 at 16:28 UTC |