[Catalyst] JavaScript::Minifier new version

Nilson Santos Figueiredo Junior acid06 at gmail.com
Sat May 26 21:57:48 GMT 2007


On 5/26/07, Peter Michaux <petermichaux at gmail.com> wrote:
> I'm new to Perl and Catalyst. I thought I'd give first (before the
> onslaught of Catalyst questions;-)). I wrote a new version of
> JavaScript::Minifier and since you are web folks I thought some might
> find it userful.

This is probably something handy to have around. However I think you
forgot to clean up your SVN working copy before committing the module
to CPAN.

By the way, I looked at the code and I think I'll make some
suggestions. First of all: don't be afraid to use regular expressions.
They're fast and can make your code cleaner and shorter.

One example:

  sub isInfix {
    my $x = shift;
    return ($x eq ',' || $x eq '=' || $x eq ';' ||
            $x eq '?' || $x eq ':' || $x eq '&' ||
            $x eq '%' || $x eq '*' || $x eq '|' ||
            $x eq '<' || $x eq '>' || $x eq "\n");
  }

This could be rewritten as:

  sub isInfix_re {
    my $x = shift;
    $x =~ /[,=;?:&%*|<>\n]/;
  }

It's shorter and (arguably) cleaner. But it's also faster:

         Rate normal     re
normal 3765/s     --   -48%
re     7189/s    91%     --

In fact, all of your isXXX() functions could be rewritten as regular
expressions. If you really wanted speed improvements, you could store
the precompiled regexes (using qr//) and do away with the function
call. Doing that will earn you another two-fold speed improvement.

But I'll stop here because this is already way off topic for a
Catalyst mailing list.

Since you're new to Perl and, according to your blog posts, you're
wondering if a language could be any uglier than Perl, may I suggest
you take a look at more modern ways of coding Perl such as using Moose
or even reading Higher Order Perl (since you seem to like Lisp). I
won't suggest Catalyst itself (along with DBIx::Class) because, since
you're here, you're probably already aware of it. ;-)

-Nilson Santos F. Jr.



More information about the Catalyst mailing list