A Foolish Manifesto

fREWdiculous!

Weekly Status Report 3

I don’t feel great about this past week, but I was really busy with wedding planning stuff. I barely made either of my two main goals (2 blog posts and 2 patches/releases a week.)

Last week I:

I have high hopes for the coming week, that I can get more important releases and more interesting blog posts written. Stay tuned!

  • 0 Comments
  • Filed under: Uncategorized
  • Today we had our Dallas.p6m meeting, which was a lot of fun as usual. This meeting was especially interesting because Rakudo * was released since we last met. In the meeting I discussed my little project to port Log::Contextual to Perl 6. First off, here’s the code.

    There are plenty of positives and negatives to Rakudo *. First the positives!

    Positives

    It works!

    It’s pretty cool that the tests actually pass! Not all of them of course though…

    Pretty Syntax

    People may not take this seriously, but . is better than ->. Seriously. Plus there are types etc.

    Built in Exporter

    So…. this may or may not be a feature. It works for the simple stuff. Is it as flexible as Sub::Exporter?

    Private methods

    In Perl 5 if you want to define a private method you use _ as a prefix. First off that’s an idiom, not part of the language, yadda yadda yadda. More importantly, it’s not really private, just marked as “don’t use this.” With Perl 6 it’s (almost) truly private. Nice.

    Meaningful Whitespace

    A lot of people are gonna hate this one; but it’s meant to solve the “print (5 + 6) * 12″ issue. It has a lot of other implications too, which again, are going to bother people. Now I can name a method log-debug instead of log_debug or lord forbid logDebug. Nice!

    “Everything’s an Object”

    Arguably the best feature of Ruby. Perl 6 does it now. Neat!

    Negatives

    Subroutine signatures are enforced

    This is hard for me. In Perl 6, a block (denoted “{ … }”) should take zero arguments unless you explicitly state otherwise (with $^a etc.) You may not notice that in most places, but Log::Contextual uses that kind of stuff constantly. I expected it to be like Method::Signatures::Simple which just sets values to undef if they are not passed. Anyway, I can live with this, it’s just different.

    Captures vs Parcels

    This is more like Javascript and Ruby, both of which I’ve used with joy, so I’m sure it will be fine. The gist of it is that when you do:

    1
    2
    3
    4
    sub foo (@bar, $baz) { ... }

    my @biff = 1,[2,3];
    foo @biff;

    You will get an error because @biff binds to @bar and $bar is not set. If you want to use an array for arguments you have to do “foo |@biff”. Much nicer than javascript’s apply, and the same as Ruby’s *.

    Glacially Slow

    This is not surprising at all. Not even really a complaint, but must be noted. To run the entire testsuite for Perl 5 takes 1.5 seconds. To run a single test for the Perl 6 version it takes more than 10 seconds. I learned in the meeting that I could precompile my modules and save a lot of time; like, three orders of magnitude difference.

    Incomplete

    Again, this is expected. Still annoying. Features I miss are lack of temp (which Patrick pointed out that I can almost replace it with dynamic variables, and soon I will be able to all the way), lack of caller, and write access to the symbol table.

    Things are… different

    My main example is that in Perl 6 undef == Any(). Patrick explained it. It makes sense. It’s still weird.

    Docs aren’t done yet

    I couldn’t figure out how to get Roles to work. I’m not really sure how it is supposed to work. Am I supposed to use the role in the class that “does” the role? What about the code that is checking if it “does” the role? I thought I tried all permutations. What a hassle.

    The Perl 6 meta object protocol is not Perl 5′s Class::MOP

    There are subtle differences between Class::MOP and Perl 6′s MOP. Do not assume that they are the same. You will get bitten. On the other hand, it has a great shortcut! Perl 5: $class->meta->foo. Perl 6: $class^.foo.

    Those are the major issues I noticed.

    If you are interested, by the way, Log::Contextual has three major features that you might like. First, it returns the arguments you pass it, so you can use it in the middle of subroutine calls and whatnot. Next, it has convenience methods for automatically printing out stringified data structures. Nice! And lastly, (but arguably the whole point) is that it has a great interface based on lisp-y principles. I really should give it it’s own blog post at some point…

  • 3 Comments
  • Filed under: Uncategorized
  • Announcing Log::Contextual

    I really should have posted this sooner. Certainly before I began my next project. Oh well.

    I am proud to announce the next bit of mstware! Log::Contextual is a small module for making your life easier when it comes to logging. Instead of bringing yet another logging infrastructure into the mix (see Log::Log4perl and Log::Dispatch), this module is a thin wrapper around any logging system you choose to use. (Note: we are working with authors of major logging packages to work seamlessly with L::C, but at the time of writing most need some form of adapter.)

    There are a few major features worth noting. First off, ridiculously convenient interface. Once you’ve set up your logger (presumably in the startup of your app or whatever) all your logging code will look like the following:

    1
    2
    3
    4
    5
    use Log::Contextual qw( :log );
    sub hello_world {
      log_trace { 'entered hello world' };
      # ...
    }

    Another great thing is that, like Devel::Dwarn, all of the logging functions are identity functions; that is, they return their arguments. That means you can do cool things like the following:

    1
    2
    3
    4
    5
    6
    use Log::Contextual qw( :log );
    sub hello_world {
      my ($arg1, $arg2) = log_trace { "entered hello world with args $_[0], $_[1]" } @_;
     
      # ...
    }

    Of course, in Perl you may be passing around complex references and the above will get cumbersome fast, so we added shortcuts specifically for logging out data structures:

    1
    2
    3
    4
    5
    6
    use Log::Contextual qw( :dlog );
    sub hello_world {
      my ($arg1, $arg2) = Dlog_trace { "entered hello world with args $_" } @_;
     
      # ...
    }

    The automatic stringification is done with Data::Dumper::Concise, so you will get reasonably indented output for free.

    In a separate package we are going to provide a module to basically turn the logging functions into no-ops at compile time, thus giving you the ability to have your code run just as fast if it never had the logging functions in in the first place. I’ll post more on that once it’s released.

    So what are you waiting for? Go log stuff!

  • 0 Comments
  • Filed under: Uncategorized