|
|
|
Your skill will accomplish what the force of many cannot |
|
| PerlMonks |
OO vs. procedural styleby markjugg (Curate) |
| on Aug 19, 2000 at 14:02 UTC ( [id://28635]=note: print w/replies, xml ) | Need Help?? |
This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.
Thanks ncw. I had thought of an arrangement like the one above. I think the code design could be considered to cleaner, but here's what bothers me about it:
One programming principle is "optimizing for the common case". The common case here is that I create a new "err" call in a script, as above. If I switch the OO style, instead of writing out 'err' each time, I'm now writing out '$err->err', so the solution makes more work in the common case. What about the magic that CGI.pm uses, where you can call routines with an OO style, or with a procedural style, and you don't even have to start with "new CGI", because there's a default object created. Can someone explain that? As far as fetching the caller's package, perl makes that easy: $callers_pkg = caller; I did end up using that in an inbetween module once, with the logic of "If my caller's package has defaults use those, otherwise use the defaults in CGI::Err". It worked, but that didn't seem clean either... Thanks for any further comment. -mark
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||