tags:

views:

120

answers:

2

Every now and again I see people on StackOverflow promote the use of autodie. But in the code here and elsewhere in the net I don't see autodie very often. Are there some disadvantages? Do I lose something when using autodie? (I have the idea of getting spoiled, when using autodie)

+11  A: 

The autodie documentation lists a couple of gotchas and bugs you should be aware of. However, most of those are relatively minor, and also fixable in the long run.

Other than that there are no real disadvantages, other than maybe the additional dependency when running on old perl versions. The fact that it isn't used very often yet might very well be caused by it being relatively new. Nevertheless, autodie (and even the old Fatal module) are generally a good idea.

rafl
I interpret the docs as saying that any user-defined subroutines you want to use with `autodie` must be declared before *any* call to `use autodie;` Seems to suggest you must declare (does that mean prototype?) any subs you want to use before `use`ing any module, since that module may internally `use autodie;` -- any thoughts? Also wondering about interactions with AUTOLOAD.
j_random_hacker
That means if you want to use `autodie` to make one of non-builtins fatal, you'll have to either fully define it or pre-declare it first. That's not related to prototypes. The use-case for that are usually modules you have no control over, but that have the weird semantic of indicating failure by returning magic values. So all you have to do for those is load them before autodie. easy enough. For your own functions you can always just make it fail with a proper exception instead, or and possibly write a magic-retval wrapper around it, in case you have backward compatibility to consider.
rafl
`AUTOLOAD` is for *methods*, `autodie` is for making *functions* fatal.
rafl
Thanks. I wasn't aware that functions could be "pre-declared" in Perl without using a prototype, but some googling suggests `use subs qw(foofunc barfunc);` does just that. Is that what you meant? Also my concern is whether *other* modules that you load might cause problems if *they* `use autodie;`. Suppose I want to use modules A and B, and to autodie-ify `f()` which is defined in B.pm. I write `use A; use B; use autodie qw(f);`. But what if A.pm internally called `use autodie;`, e.g. in its `import()`? Does the world blow up?
j_random_hacker
Re your 2nd comment: Are you implying that `autodie` cannot be used with methods generally? (That seems like an arbitrary restriction.) Or just autoloaded methods? (Still undesirable, but somewhat understandable.)
j_random_hacker
`use subs ...` isn't usually needed to predeclare subs. You can use a sub declaration without a body. `sub foo; ... later in the code ...; sub foo { ... }`
Ven'Tatsu
Thanks @Ven'Tatsu. Just checked in perlsub, and sure enough it's the very 1st line in the synopsis :)
j_random_hacker
+4  A: 

The technology is mostly fine, but it's action at a distance and magical. Some people who read only sections of the code might not understand what happens since autodie is far away from the code they inspect. Since not everyone uses it and it's only become a practice recently, I suspect most people don't expect it. It's not really a big deal, but that sort of thing always seems ugly to me.

brian d foy
I have some difficulties with the translation of your answer. Could you explain me the "don't expect it" part? Means expect here await? What does the "it" refer to?
sid_com
Many people won't know that autodie is enabled be because it's declaration is far away from the code they are looking at.
brian d foy