in reply to Re: is use strict a compile time directive?
in thread is use strict a compile time directive?

I asked this question at Why is 'our' good?, and I have looked through a number of discussions of the feature.

Not one has left me with the feeling that our is really a good addition to the language.

Perhaps there is something basic that I am missing, but it really seems to me to be a misfeature. For instance in this example just reversing the order is conceptually simpler and doesn't declare $VERSION to be in the current package (even overriding further package declarations). Even aside from the backwards compatibility issue, those facts are more compelling to me than the convenience issue for the occasional case wehre I want to have multiple packages declared in the same file. (Which is the only advantage to our that I see.)

Am I missing something?

Replies are listed 'Best First'.
Re: Why would you use our?
by TheDamian (Vicar) on Oct 19, 2001 at 01:26 UTC
    Am I missing something?

    Avoiding use vars and being able to give package variables associated types (our Dog $spot) wasn't enough to convince you?

    Well, perhaps my new Attributes::Filtered module will be. Once it's available, by using our you'll be able to declare package variables (or parts of package variables, such as individual hash entries) with attributes.

      I never had a problem with vars in the first place. The internals may be a hack, but I am perfectly happy with the external interface.

      I guess I haven't really seen the point of the associated types feature. I mean I understand it, but the amount of work that I need to do to get a modest optimization is enough that I don't want to bother. Plus I work in a job where we may have a number of people who are pretty good at Perl, but that is because they learned on the job. And the associated types feature is one feature more than I really want people to maintain. (After all I start with people who have not been exposed to when to use hashes, and take them through OO, anonymous functions, etc. That is already quite a lot.)

      So no, package access to a feature I don't use isn't a big deal to me.

      As for attributes, well I work in a 5.005 environment that we have not upgraded yet (when we do, I will have a couple of parsing bugs to look for), so that is not available to play with. However I would think that you could get attributes to work on package variables something like this:

      { my $tmp :some_attribute = "bar"; *foo = \$tmp; }
      And if you can do it, then you can find some way to put synthetic sugar around it.

      If you can't, then I would wonder why not. It would feel to me like a design kludge, unless I had a pretty good explanation why that naive expectation didn't make any sense. Even so, if I can't find a fairly nice way to explain to co-workers what the feature is, how to use it, and what the caveats are, then I won't use it. Perl has some obscure misfeatures that we already ignore (like prototypes). Adding a few more to that list is no problem...

Re: Why would you use our?
by davorg (Chancellor) on Oct 18, 2001 at 18:10 UTC

    I have a great reason for not using our. I don't have the luxury of assuming that all of my code is going to run on 5.6.x..

    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you don't talk about Perl club."