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.
  • i would name the function name as history_size instead of history to avoid confusion. but i agree what you have said.
    • Most of the time, the method is used to get the whole history as an array.

      To give a more concrete background, I was working with the GetHistory method from Term::ReadLine::Gnu, Term::ReadLine::Perl and Term::ReadLine::Zoid when used by Shell::Base. That said, instead of trying to convince all involved authors to change code or/and documentation, I tried to work with the contrived and actual API.

      I agree that introducing a GetHistorySize method would eliminate instantly the problem associated to the ov

  • sub history { shift; return my @h = reverse @history; }

    Ugh! You really have two return values, so say so: sub history { shift; return wantarray ? reverse @history : scalar @history; } This saves the extra work of reversing something that you don't need to reverse.

    --
    • Randal L. Schwartz
    • Stonehenge
  • This goes for "sort" too.

    I'd say that in application code 97.21% (plus/minus .03%) of all subs are meant to be context insensitive.

    So there really is a need for a Perl::Critic plugin that warns against "return CALL_TO_CONTEXT_AWARE_FUNCTION" where the context of the caller leaks into the sub and causes this severe action-at-a-distance.

    (meta: five timeouts posting this)