in reply to Why you shouldn't use the Indirect notation with AUTOLOAD

That is why you shouldn't use the Indirect notation.
And not because of the reasons pointed out since way back by Perl illuminators like Tom Christiansen and Mark-Jason Dominus, some of those having found its way into the documentation?

Your AUTOLOAD example is just a special case of the more fundamental problems mentioned in perldoc perlobj - the manual page that recommends:

The "->" notation suffers from neither of these disturbing ambiguities, so we recommend you use it exclusively.
Emphasis not mine.
  • Comment on Re: Why you shouldn't use the Indirect notation with AUTOLOAD

Replies are listed 'Best First'.
Re^2: Why you shouldn't use the Indirect notation with AUTOLOAD
by chromatic (Archbishop) on Feb 28, 2005 at 18:47 UTC

    Yet for some reason, indirect new calls have found their way into the documentation of many, many CPAN modules. I've seen code snippets that mixed direct and indirect new() calls depending on the examples in the docs.

    There seems to be a persistent belief that new is a keyword. I don't know that anyone would every explain it that way, but indirect constructor code looks like people believe that it is a keyword, not a normal class method call.

      I always assumed that it was because of C, C++, Java, PHP, JavaScript/ECMAScript and VB. These languages (and more, I'm sure) all use new as a keyword. With so many languages constructing objects as new Foo it's no wonder why many do it in Perl. I look at it as yet another example of how perl's flexability allows people to program in a way comfortable to them.

      Ted Young

      ($$<<$$=>$$<=>$$<=$$>>$$) always returns 1. :-)
        Yet, that way provides for bugs, precisely because new isn't a keyword. Larry has said that he meant it as a migration aid, not as a syntax.

        Being right, does not endow the right to be rude; politeness costs nothing.
        Being unknowing, is not the same as being stupid.
        Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
        Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

      Yet for some reason, indirect new calls have found their way into the documentation of many, many CPAN modules.
      Indeed, and that's very unfortunate. Let me try to give an explaination (I don't know whether that's the explaination, it's more a theory of mine):

      In the early years of perl5, new Module @args was the recommended way of calling a constructor. It's shorter than Module -> new (@args), and it's what C++ and some other languages use. So, CPAN modules, and also modules coming with perl5, used this syntax, and so did the main documentation.

      It wasn't that after a few years (1997 I think) that people like Tom and Mark-Jason noticed the potential problems, and started warning against its use. The documentation got updates, but there was still quite some code/documentation using the indirect object syntax out there. Which invites people to copy it when they write new syntax. So there has always been a large amount of module on CPAN using the indirect object syntax - and it has enough critical mass to make some new authors use this as well.

      Also, the problems with the indirect object syntax is infrequent enough that many people will never run into problems with indirect objects, even if they use it daily. How venerable you are to get bitten by the indirect object syntax also depends on your way of coding.

      There seems to be a persistent belief that new is a keyword.

      It's not, but sometimes I wonder whether it would have been better if it was.

Re^2: Why you shouldn't use the Indirect notation with AUTOLOAD
by Mugatu (Monk) on Feb 28, 2005 at 21:18 UTC
    That is why you shouldn't use the Indirect notation.
    And not because of the reasons pointed out ... [in] the documentation?

    I didn't read that sentence as excluding any other reasons for avoiding this syntax, but merely adding one reason with emphasis. Perhaps you can take issue with the emphasis he put to his reason, but I think it's a bit too strong to say he is actually excluding the other reasons.