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

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Speaking as one who has added methods to UNIVERSAL and, on at least one occasion, set @UNIVERSAL::ISA, I'd say there's nothing wrong with monkeying with classes you don't 'own'. What always gave me the heeby jeebies about the way Rails does it is that they chose names that were obvious hostages to fortune.

    When I was hacking on Pixie and needed to add methods to UNIVERSAL, everything that went in got a px_ prefix and should probably have had a pixie_ one. (Actually, now I think about it, we used to take advantage of the way you can override Perl's method dispatch by doing $obj->px::pickle, so we could have arranged to use totally opaque names on UNIVERSAL itself:


    package px;

    {
        my $pickle = "pixie_" . SHA1(random() + 'pixie');

        sub pickle {
            my $self = shift;
            $self->can('pixie_pickle')
                ? $self->pixie_pickle(@_)
                : $self->$pickle(@_);
        }
    }

    I just tried writing something similar in Ruby and it can't be done (for values of "can't be done" that involve no more than 10 minutes thought), you're left having to use a hopefully unique prefix for the methods you add.

    But you're right; that particular post left me gasping. I particularly liked the "It's the fault of those dashed Japanese people for not understanding that if you change the sub sub version number, you shouldn't go changing the interface of your core classes!" protest. It's not like it hasn't happened with pretty much every sub release of Ruby so far. You'd think he'd be used to it by now. You might, further, think that the maintainers of Rails might have learned by now...

    Sometimes, I miss perl programming a great deal.

    • Yes, the algorithm for choosing a safe name is, ah, less than wonderful. Should at probably be SHA1('pixie:pickle'), assuming we don't mind outsiders being able to guess the opaque method's name.

    • I'd say there's nothing wrong with monkeying with classes you don't 'own'.

      ... until Daddy comes home, anyway.

      My amusement comes from the idea that Rails could have done the right thing (incidentally avoiding Primitive Obsession [jamesshore.com] as well as monkeysquatting) by using its own String subclass. It's opinionated software. You use its own APIs throughout your system. This is cheap insurance -- and think how easy it would be to fix HTML escaping in one place, for all time.

      I particularly liked the "It's the fau