in reply to Re^7: Is it ok to mix functional and oo programming in one package?
in thread Is it ok to mix functional and oo programming in one package?
...do you always know when exactly when everything gets declared?
Generally, yes. The use inevitably appears lexically before, and by general definition is compiled before, any statements that call methods that the used module contains.
There are situations, particularly when using require in a thread to avoid cloning, where the loading of the module is deferred, but that is a situation that requires other special considerations--like the explicit invocation of export()--that one has to be aware of.
How about in programs that use Module::Pluggable or another extension mechanism?
I've never had occasion to use that module or anything similar, but looking at the POD it seems that you would always need to obtain a 'handle' to the module first, and using direct method invocation on objects and handles is the natural way to go. There is no bare-word upon which to invoke a class method indirectly.
(I've also debugged the $_ gets localized implicitly except when it doesn't.)
Kind of a strange aside given the subject matter, but useful. Given that this problem is far more subtle, and unlikely to be detected at compile time much less give a clear diagnostic as you get with most incorrectly parsed indirect method invocations, do you generally advocate always explicitly localising $_?
I know there are those that eschew all uses of $_, but I don't recall you as being one of them. It seems to me that when this problem arises, it is far more insidious, far less likely to produce a clear diagnostic and far harder to debug. So why not advocate:
Not that I would subscribe to it, but it seems like a far stronger candidate to me.
In general, I only use indirect method invocation for class methods, not instance methods.
Why use it at all? Maybe it's a throwback to my (hated) C++ days. Or maybe it just 'feels right'. I tend to say: "I'm going to by a new car", not "I'm going to by a car new". But mostly I think that applying direct method invocation to a bare-word is unintuitive.
And the use of contrived examples to deprecate things that work perfectly well in normal situations just seems like bad karma.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^9: Is it ok to mix functional and oo programming in one package?
by chromatic (Archbishop) on Oct 19, 2007 at 18:28 UTC |