Try::Tiny::Tiny

Last year I released this new module.

I want to talk about its purpose briefly, because in the time since, people have published benchmarks of how it performs compared to other modules that offer alternatives to eval. The latest example of such a benchmark is part of the Exceptions chapter in Minimum Viable Perl (via), but they go as far back as Diab Jerius’ shootout right after I released the module.

It is, of course, interesting to see the figures to see where Try::Tiny::Tiny falls.

However, simply treating it like another contender in such a contest misunderstands its purpose. Try::Tiny::Tiny is not meant to compete with any of the other modules. It is not meant to be your choice for exception block syntax.

I do not recommend that you use Try::Tiny::Tiny in your own code.

For CPAN modules, I actually recommend that you use raw eval. Nothing else has an even remotely comparable performance or dependency footprint. And while you may or may not agree with that recommendation, I will say this: if you list Try::Tiny::Tiny as a dependency of your CPAN distribution, you have made a mistake.

At the same time, if you are running Perl in production, I do recommend that you use Try::Tiny::Tiny in all cases – regardless of what exception block syntax you chose to use in your own code.

Confused? What exactly is the point of Try::Tiny::Tiny?

It’s this: to be a little bit of a solution for all the CPAN code that is already written using Try::Tiny. If you use such modules in production and don’t want the drawbacks, your options are to either try to submit dozens of patches and convince as many maintainers… or use Try::Tiny::Tiny to clean them up just a little, all of them, in one fell swoop.

Hence my usage guidance as its author: you use Try::Tiny::Tiny to fix-up other people’s code, not as a solution in your own.

And so the kind of benchmark result that I am most interested would be something like “I ran our test suite from my day job with ‘PERL5OPT=-MTry::Tiny::Tiny’ and it saved 3% CPU”. Or, maybe it didn’t. Consider this my official request for such results.

Finally, I want to add an observation regarding Syntax::Keyword::Try, which routinely ends up as the recommendation of such shootouts. Namely, it requires keyword plugin support in Perl, which was added in 5.14. But that happens to be the version of Perl which also fixed some warts in eval as well as the problem that it would sometimes lose exceptions. So if you require Syntax::Keyword::Try, then your code’s requirements indirectly include a version of Perl in which raw eval is safe and simple to use. Maybe there’s no need for the module.

Leave a comment

About Aristotle

user-pic Waxing philosophical