Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Perl's static type system cares more about containers than values. Ponder that for a while, if you really want to confuse the debate.

    • That's actually a point explicitly raised in the article. Dynamic systems focus tracking what kinds of data are used in a system, not on syntactic evaluation of expressions. See the "Problems with Common Definitions" section which begins with this:

      One common saying, quoted often in an attempt to reconcile static and dynamic typing, goes something like this: Statically typed languages assign types to variables, while dynamically typed languages assign types to values. Of course, this doesn't actually defin

      • That's not quite the same. Perl 5's built-in static types are scalar, array, and hash (and Maybe reference, if you pardon the Haskellish pun). You do get compile-time checks on using them appropriately.

        • The important point is that Perl's type system is still primarily dynamic in nature, though as the article points out, static languages all have dynamic elements and vice versa. Perl's compiler is incapable of arbitrary reasoning about the adding two scalars together. They might be overloaded. They might be overloaded at runtime. They might have strings, they might have numbers, etc.

          Perl's extremely limited type system in fact, must be explicitly requested:


          print "foo ($test[1]) bar";
          foo () bar

          If if you do ask for extra compile time checks, they're easy to subvert:


          use strict;
          my $test = {};
          print "foo ($test->{foo}[1]{baz}) bar";
          foo () bar

          What? I don't have a hashref of arrayref of hashrefs! Or we can get the less common but more obscure error messages:


          use strict;
          my $test = {};
          print "foo ($test->{foo}[bar]{baz}) bar";
          Bareword "bar" not allowed while "strict subs" in use at line 5.

          I know why that error is thrown, but that's only because I now know how Perl parses that.

          Another example of having good type systems is exemplified in Tom Moertel's article on using types to prevent injection attacks []. With Perl 6's grammars, we'll be able to achieve similar goals, but Perl 5 just ain't there because while Perl 5 can do the same thing, it cannot do the same thing easily because static typing is heavily dependent on static evaluation of expressions. Many of my favorite Perl 5 modules are ones I can't use in production because the best they can do is fake things like this with source filters.

          In short, as the article points out, static typing is really based on having extra (and potentially mutable) domain-specific information embedded directly into the syntax of a language (and I'm not referring to explicit typing. That's a holdover from days when compilers needed that). Perl 5 doesn't have the arbitrary flexibility to do that. Perl 6 will. I don't think this means that Perl 6 will necessarily be static, but we have the potential.