Stories
Slash Boxes
Comments
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

use Perl Log In

Log In

[ Create a new account ]

DBD::SQLite 1.31 releasing next week and may break your code

Posted by Alias on 2010.09.08 21:11 (#40526)
0 Comments
User Journal

After 6 or 7 months (mainly waiting around for the next "recommended upgrade instruction" from the SQLite project) the latest DBD::SQLite release should occur next week.

You can get the 1.30_06 release candidate from the CPAN, or from the following URL if your mirror hasn't synced yet.

http://svn.ali.as/cpan/releases/DBD-SQLite-1.30_06.tar.gz

Apart from the normal batch of SQLite upgrades (from 3.6.22 to 3.7.2), bug fixes, and minor enhancements, this release has two changes that may break your code.

These changes have been in the dev releases for some time, but you may want to take the opportunity to test more intensively if you use either of the following features.

1. BLOB columns with UTF8 content

- Resolved #54271: Inserting a string with utf-8 flag on
  corrupts BLOB data; now BLOB data is always stored as bytes
  (without the utf-8 flag) even if it has the flag set (ISHIGAKI)

2. FTS3 queries

- Added support for FTS3 tokenizers written in Perl. Added tests
  and documentation on how to use FTS3. Changed compilation flag
  to use the recommanded -DSQLITE_ENABLE_FTS3_PARENTHESIS
  *** MAY POSSIBLY BREAK OLD APPLICATIONS THAT ALREADY USED FTS3 ***
  (DAMI)

If you are currently using FTS3, please see DBD::SQLite::FTS3Transitional which contains a helper function for automatically upgrading old FTS3 queries to the new syntax.

use Perl; Shutting Down Indefinitely

Posted by pudge on 2010.09.08 17:07 (#40525)
0 Comments
use Perl

See here.

Should Module::Install move to explicit plugin declaration?

Posted by Alias on 2010.09.05 21:26 (#40523)
6 Comments
User Journal

Module::Install has been through a long period of gradual stability over the last year, without any really dramatic improvements to the grammar or APIs.

With the more urgent "it doesn't work with blah" stuff mostly solved now, one of the big remaining issues is around error clarity and excessive magic.

For example, some random author that is trying to checkout a Catalyst project needs:

1. To have Module::Install installed.
2. To have Module::Install::Catalyst installed.

In the case of the former, you get the semi-cryptic but at least standard "Can't find inc/Module/Install.pm in @INC" message, so the error is resolvable.

But in the latter case, you're likely to get something like "Unknown command 'catalyst_ignore'", with no real obvious resolution mechanism.

I think this idea of automatic plugin discovery is starting to hit it's limits in terms of clarity.

And so I'd like to do something counter to my natural instincts here, and make M:I more verbose.

I'm thinking of something like the following for explicitly declaring the use of a non-core Module::Install extension.

use inc::Module::Install qw{ Catalyst XSUtil };

This would both allow M:I to error with a much more meaningful error when you don't have a plugin, and also prevent the loading of unused plugins which should prevent accidental plugin collisions (some of which I've seen occurring in the CPAN Testers machines).

Thoughts?

Speaking at Microsoft TechEd - Any issues you want raised?

Posted by Alias on 2010.08.19 22:20 (#40508)
7 Comments
User Journal

Next week I will at Microsoft's TechEd Australia event, courtesy of Microsoft Australia and Microsoft Open Source Labs.

More specifically, I'll be attending the Open Source mini-conf and discussion day on Tuesday, and presenting in the Community Presentations to Microsoft session on the current state of Perl and Windows on Wednesday.

Likely topics will include a review of the first year of the CPAN Testing Lab and a second-generation based on their Cloud Services, free code signing certificates for open source developers, and what issues are slowing us down or blocking progress.

So consider this your opportunity to raise any outstanding issues you have with Microsoft and Perl. What problems are you still seeing, what would like fixed or changed, and what is on your want-to-have list?

I'll try to address as many of your issues as possible in the time I have available with them (which is actually pretty substantial).

Cute caps

Posted by jdavidb on 2010.08.19 16:55 (#40507)
8 Comments
User Journal

I'm doing some quick code generation (the output is Java), and I found myself writing the below routine. I like it because of the names I picked for the variables. Not exactly self-documenting (although it is when you think about it), but this is throwaway. You can probably tell what the code is doing and why I named the variables as I did, and you might be entertained.

sub uc_prop
{
  my($prop) = @_;
  my $p = substr($prop, 0, 1);
  my $P = uc($p);
  my $rop = substr($prop, 1);
  return "$P$rop";
}

Class::XSAccessor now even faster'er

Posted by Alias on 2010.08.15 22:04 (#40497)
1 Comment
User Journal

The new 1.07 release of Class::XSAccessor mentions the use a new somewhat-evil technique for making the code even faster than it was previously.

But how much faster is it?

The following are being run on a fairly typical corporate Windows XP machine, with Strawberry Perl 5.10.1 and thread support.

First, some benchmarks using the previous 1.05 release (two runs)

Benchmark: timing 10000000 iterations of accessor_get, accessor_set, constructor, false, getter, predicate, setter, true...
accessor_get:  1 wallclock secs ( 2.51 usr +  0.00 sys =  2.51 CPU) @ 3976143.14/s (n=10000000)
accessor_set:  2 wallclock secs ( 3.09 usr +  0.00 sys =  3.09 CPU) @ 3233107.02/s (n=10000000)
constructor: 16 wallclock secs (15.67 usr +  0.00 sys = 15.67 CPU) @ 638080.65/s (n=10000000)
     false:  2 wallclock secs ( 1.91 usr +  0.00 sys =  1.91 CPU) @ 5243838.49/s (n=10000000)
    getter:  1 wallclock secs ( 2.34 usr +  0.00 sys =  2.34 CPU) @ 4266211.60/s (n=10000000)
  predicate:  1 wallclock secs ( 2.38 usr +  0.00 sys =  2.38 CPU) @ 4210526.32/s (n=10000000)
    setter:  2 wallclock secs ( 3.27 usr +  0.00 sys =  3.27 CPU) @ 3061849.36/s (n=10000000)
      true:  1 wallclock secs ( 1.80 usr +  0.00 sys =  1.80 CPU) @ 5564830.27/s (n=10000000)
 
Benchmark: timing 10000000 iterations of accessor_get, accessor_set, constructor, false, getter, predicate, setter, true...
accessor_get:  3 wallclock secs ( 2.51 usr +  0.00 sys =  2.51 CPU) @ 3976143.14/s (n=10000000)
accessor_set:  3 wallclock secs ( 3.14 usr +  0.00 sys =  3.14 CPU) @ 3183699.46/s (n=10000000)
constructor: 15 wallclock secs (15.73 usr +  0.00 sys = 15.73 CPU) @ 635566.29/s (n=10000000)
     false:  2 wallclock secs ( 1.86 usr +  0.00 sys =  1.86 CPU) @ 5379236.15/s (n=10000000)
    getter:  3 wallclock secs ( 2.50 usr +  0.00 sys =  2.50 CPU) @ 4000000.00/s (n=10000000)
  predicate:  3 wallclock secs ( 2.47 usr +  0.00 sys =  2.47 CPU) @ 4050222.76/s (n=10000000)
    setter:  4 wallclock secs ( 3.13 usr +  0.00 sys =  3.13 CPU) @ 3200000.00/s (n=10000000)
      true:  2 wallclock secs ( 1.98 usr +  0.00 sys =  1.98 CPU) @ 5037783.38/s (n=10000000)

And now again with the new 1.07 release.

Benchmark: timing 10000000 iterations of accessor_get, accessor_set, constructor, false, getter, predicate, setter, true...
accessor_get:  2 wallclock secs ( 1.75 usr +  0.00 sys =  1.75 CPU) @ 5711022.27/s (n=10000000)
accessor_set:  1 wallclock secs ( 2.69 usr +  0.00 sys =  2.69 CPU) @ 3721622.63/s (n=10000000)
constructor: 15 wallclock secs (15.62 usr +  0.00 sys = 15.62 CPU) @ 640000.00/s (n=10000000)
     false:  1 wallclock secs ( 1.28 usr +  0.00 sys =  1.28 CPU) @ 7806401.25/s (n=10000000)
    getter:  1 wallclock secs ( 1.56 usr +  0.00 sys =  1.56 CPU) @ 6397952.66/s (n=10000000)
  predicate:  2 wallclock secs ( 1.92 usr +  0.00 sys =  1.92 CPU) @ 5205622.07/s (n=10000000)
    setter:  3 wallclock secs ( 2.50 usr +  0.00 sys =  2.50 CPU) @ 4000000.00/s (n=10000000)
      true:  2 wallclock secs ( 1.55 usr +  0.00 sys =  1.55 CPU) @ 6464124.11/s (n=10000000)
 
Benchmark: timing 10000000 iterations of accessor_get, accessor_set, constructor, false, getter, predicate, setter, true...
accessor_get:  2 wallclock secs ( 1.78 usr +  0.00 sys =  1.78 CPU) @ 5614823.13/s (n=10000000)
accessor_set:  3 wallclock secs ( 2.63 usr +  0.00 sys =  2.63 CPU) @ 3809523.81/s (n=10000000)
constructor: 16 wallclock secs (15.69 usr +  0.00 sys = 15.69 CPU) @ 637429.88/s (n=10000000)
     false:  2 wallclock secs ( 1.22 usr +  0.00 sys =  1.22 CPU) @ 8203445.45/s (n=10000000)
    getter:  2 wallclock secs ( 1.53 usr +  0.00 sys =  1.53 CPU) @ 6535947.71/s (n=10000000)
  predicate:  2 wallclock secs ( 1.78 usr +  0.00 sys =  1.78 CPU) @ 5614823.13/s (n=10000000)
    setter:  2 wallclock secs ( 2.56 usr +  0.00 sys =  2.56 CPU) @ 3903200.62/s (n=10000000)
      true:  2 wallclock secs ( 1.48 usr +  0.00 sys =  1.48 CPU) @ 6738544.47/s (n=10000000)

The numbers are pretty impressive.

The 'accessor', 'setter', 'predicate' and 'true' methods are about 25% faster, while 'getter' is a whopping 60% faster and (curiously) 'false' is about 50% faster as well.

Constructors are really the only thing that hasn't changed.

Impressive work, even if the code is a bit risky.

Why does Object::Tiny only support getters

Posted by Alias on 2010.08.14 20:39 (#40496)
2 Comments
User Journal

http://perlalchemy.blogspot.com/2010/08/objecttinyrw-and-moosexnonmoose.html

Zbigniew Lukasiak tries out Object::Tiny and wonders why it is that I didn't allow for the creation of setters when it is only a one line change.

Like most ::Tiny modules the reason is a bit complex and the result of compromises.

Object::Tiny began as an attempt to create a lighter, faster, version of Class::Accessor. A way to bulk-generate the accessor code I had to type over and over again.

However, where I differ is a strong preference for light and elegant API design.

And so I decided to implement mine with as little implementation code as possible, and as little API code as possible.

Once you have decided to go down the simplicity path, there's a couple of standard techniques you often end up using.

The first and most important is state reduction.

In their introduction to Erlang, the founders of that language describe state as one of the main sources of failures in programs. And so anything that removes state, at the very least unnecessary state, is a positive. Especially if the state reduction also results in code reduction, and a reduction in computation.

So take the following example, where we create an object with some attributes and then run some code that will use those object attributes..

my $object = Class->new;
$object->foo(1);
$object->bar(2);
$object->do_something;

This is a use case that we see fairly often, but it's really quite horrible code. It is really only the object-oriented equivalent of something like the following.

our $Object::foo = 1;
our $Object::bar = 2;
do_something('Object');

It is especially bad code if the following code would throw an exception.

my $object = Class->new;
$object->do_something;

If this blows up, then you are REALLY doing something wrong, because you have allowed the creation of completely invalid objects. Now anybody taking one of these objects as a parameters needs to do with following.

sub foo {
    my $object = shift;
    unless (
        $object->isa('Class')
        and
        defined $object->foo
        and
        $object->foo > 0
        and
        defined $object->bar
        and
        $object->bar > 2
    ) {
        die "Invalid object";
    }
}

If you are going to create an object for something, you HAVE to be sure that the objects are trustworthy.

And so you should never allow objects to exist that are invalid. EVERY object should be a valid object.

At the absolute minimum objects should be able to default every attribute to something reasonable and unlikely to cause problems.

But this still results in excess and wasteful work, because the object has to transition through two or more states.

You start with an object with parameters and defaults, and you validate them. And then you change on of the attributes immediately, validating it AGAIN. In the mean time, your object exists in a state that it will never actually be used in.

And so everywhere you possibly can, you should be setting attributes in the constructor rather than afterwards.

my $object = Class->new(
    foo => 1,
    bar => 2,
);
$object->do_something;

Less state, less complexity, less CPU, and less bugs.

If we accept this model of pushing all the configuration into the object up front to reduce state, then why change the object arbitrarily?

In fact, anything that you ARE going to change should be done under very controlled conditions.

It should require a dedicated method to apply the change, it should require validation, and work. It shouldn't be trivial, and it shouldn't be automatic.

If I had my way, Moose would set is => 'ro' by default, to make people think before they go about simply allowing stuff to change.

It also happens to let you shrink down the API markedly.

There are three potential use cases available when implementing accessors. Everything readonly, everything readwrite, or mixed.

With Object::Tiny, I was aiming for the smallest possible code.

Implementing either all-readonly or all-readwrite can be done with the following.

use Class qw{
    foo
    bar
};

By contrast, if we want to allow mixed readonly and readwrite, we would need some way of distinguishing. Something like the following.

use Class {
    readonly => [ 'foo' ],
    readwrite => [ 'bar' ],
};
 
use Class [ qw{
    foo
} ], [ {
    bar
} ];
 
use Class {
    foo => 'ro',
    bar => 'rw',
};

No matter how you try, there's always an inherent additional element of complexity that results from the split between them.

And so the decision to go with all-readonly in Object::Tiny is a combination of these two issues.

If went with all-readwrite, I'm practically encouraging bad behaviour and more bugs. If I went with mixed accessors, the API would remain relative complex.

In the end, the best way to achieve both API simplicity and code safety is to only provide read-only accessors, and anything more complex should require both though and effort.

use Perl;

Posted by pudge on 2010.08.11 18:34 (#40493)
15 Comments
User Journal

I am no longer working for Slashdot/Geeknet as of September 30. I am actively seeking new employment. Unless you want to hire me, you don't need to care, unless you also care about use Perl;, because it has been generously hosted by Geeknet since I started the site over 10 years ago, shortly after I was hired by Andover.Net to work on Slashdot.

Long story short, I have not done much with the site in recent years, so my options at this point are to do nothing; migrate the site to a new server and keep it running as-is; or take the data and do something with it on a new site. Or something I haven't thought of.

I am hereby accepting proposals for what to do with use Perl;. In short, I would like to donate it to someone who will give it a good home. If you're interested, give me your best pitch.

Cross-posted on <pudge/*>.

Matt Trout, aka mst, is insane

Posted by pudge on 2010.08.11 11:41 (#40492)
17 Comments
User Journal

Wow. I occasionally, but not too often, go into #perl. Very busy with family and life. So I go in today, and for no reason, mst bans me and tells me to not come back.

What's up with him being such an irrational dick?

Trailer Theory - Reinvented for Ignite Sydney as Economics

Posted by Alias on 2010.08.04 0:40 (#40480)
0 Comments
User Journal

Back in 2005 in only my fifth use.perl post ever, I outlined an idea I had been developing for a couple of years that I called "Trailer Theory".

A few years ago on my Portable Perl world hack'a'tour, I took with me a lightning talk version of the concept. It was a pretty crude talk but was received, it seemed, fairly well by the development community.

Since that trip, and inspired by the unexpected conversion of my "Perl is unparsable" claims in the PPI docs into a formal mathematical proof (complete with "Kennedy's Lemma") I've been wondering if this "Trailer Theory" idea could really be developed as a proper scientific proof, and if so what would that look like.

A couple of months ago I presented a new version of the talk at Ignite Sydney, speaking to an mixed audience of Twitterati, social media, advertising and journalist types.

I've rebuilt the talk from scratch and tried to outline the same idea, but in the form of a kind of layman's Economics Proof.

I hope you enjoy the result.

Adam Kennedy - Using Economics to make movies suck less


Notes for other speakers:

1. Ignite advances slides every 15 seconds, no clickers allowed. This turns out to take a shitload of practice to get right.

2. When someone says to you "Here's your mark, you need to stay on this line to be in the fixed spot" it helps to pay attention. FAIL :)