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.
  • Your &run method if/elsif/else chain is very difficult to read. Switching to a dispatch table makes it much easier to understand.

    my %method_for = (
        o => 'action_logout',
        f => 'view_forgot',
        r => 'action_forgot',
        c => 'view_change',
        p => 'action_change',
        n => 'view_new',
        a => 'action_new',
        l => 'view_list',
        m => 'view_promote',
        b => 'action_pro

    • I'm not sure I'd call that simpler, possibly more elegant though
      • It's easier to see which action maps to which method and makes it less likely to have bugs in the future as adding a new action is trivial. You just add a new entry to the hash and don't have to worry about the code.

        • I find that both elegant and easier to read. I haven' used dispatch tables much but time to go read about them again. : )
          • The "but time to go read about them again" is the main reason I don't want to use them... I'm trying to keep stuff as utterly boring and minimalist as possible.

            But you are right the if/else chain is VISUALLY hard to read, so I might do something to fix that instead of moving to dispatch table.
            • Technically that’s not even a dispatch table (since it does not map from strings to coderefs). I don’t know why people “need to read about them” either – I came up with the concept independently long before I knew it had a name. Seems obvious to me, and I don’t think I am a genius… what do I know.

              And actually, I don’t know why Ovid rewrote the code the way he did, because it’s easy to make it even simpler:

              sub run {
                  my $self = shift;