Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Most useless function.

by tweetiepooh (Friar)
on Feb 16, 2006 at 16:15 UTC ( #530693=perlmeditation: print w/ replies, xml ) Need Help??

Back in the days of yore I programmed in Clipper (xBase compiler).

The producer (Nantuket, then CA) held annual DevCons in London for European developers and usually ran a "silly" competetion. One year it was to come up with the Most Useless Function.

The winner (I think it was one Rick Spence) came up with ispoweron().

Can you do better? For Perl that is. Or at least is Perly in nature.

Comment on Most useless function.
Re: Most useless function.
by Anonymous Monk on Feb 16, 2006 at 17:16 UTC
    Perl doesn't have any "useless" builtin functions, as far as I can tell; they all have (or had) a purpose.

    Perl has a lot of redundant functionality; there's many ways to get the same job done.

    If you're talking about user defined functions, look up the term "JAPH" sometime. ;-)

      Of course I mean user defined.

      And JAPH's are not useless, well not in the same way as a ispoweron() is useless.

        The point of a ispoweron() function is to detect whether the main power source is on, or whether you're running under backup power (UPS, generator, etc).

        Once you detect that you're running under UPS power, you can then do a controlled shutdown of the system before power runs out.

        It's much less useless than a JAPH, which is a complicated way of writing something that could be written in a straightforward way.

Re: Most useless function.
by swampyankee (Parson) on Feb 16, 2006 at 17:52 UTC

    is_perl_installed;

    would seem to be as about as useless as it could get, as well as quite difficult to implement in Perl for the case returning 'false'.

    emc

    " When in doubt, use brute force." — Ken Thompson
      You can create freestanding applications with PerlApp, so you could write a PerlApp to check to see if perl was installed on the host system. That would be 1 (unlikely) use of "is_perl_installed"

      :)
        sub is_perl_installed { if(rand() < 0.5) { recursively_unlink(find_perl_on_disk()); return 0; } return 1; }
      Ah someone in the true spirit of the thing.

Re: Most useless function.
by samtregar (Abbot) on Feb 16, 2006 at 18:03 UTC
    My vote goes to dump. It may have had a use at some point in the past but it's pretty damn useless today!

    -sam

      If it works worse than perlcc, that's pretty darned bad!

      I try perlcc every few years; last I checked, it would finally compile "hello, world" (it didn't the first time I tried!!!), but it still failed on the second script I tested it on.

      Maybe by the time Perl6 replaces perl5, perlcc will work reliably...

        Afaik perlcc is a dead project. Dont expect it to change.

        ---
        $world=~s/war/peace/g

Re: Most useless function.
by brian_d_foy (Abbot) on Feb 16, 2006 at 18:17 UTC
    Mark Jason Dominus has some interesting candidates under the "Perl Stupidity" section of his website. The Addition module might be a winner.
    --
    brian d foy <brian@stonehenge.com>
    Subscribe to The Perl Review
Re: Most useless function.
by chromatic (Archbishop) on Feb 16, 2006 at 18:54 UTC
Re: Most useless function.
by eyepopslikeamosquito (Canon) on Feb 16, 2006 at 20:19 UTC

      Then there is the ever useful variation :)

      no less 'important';

      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Most useless function.
by Moriarty (Abbot) on Feb 17, 2006 at 01:53 UTC

    I have heard that ispoweron() isn't all that useless. It's used by some systems to unmount filesystems, park drive heads and other useful stuff before the capacitors are drained after the power has been turned off.

      I really, really hope that story is apocryphal and wrong.
      What, you're going to poll that status until it goes false?
      Things like this should be event driven.

      We're building the house of the future together.
        AFAIK, there's also a signal that gets sent in event of a power fluctuation. From there, you can use "ispoweron()" to tell the difference between a momentary power blip, and a real outage condition.

        You'll only bother to poll when you've got a signal that said there was a potential outage issue, and then only to check to see if the situation has resolved itself (power back on or not). Depending on that knowledge, you can implement a variety of recovery policies (shutdown immediately; wait 10 minutes, then shutdown if the power is still out; etc).

        From what I remember, it's not a useless function; albeit rarely very useful, either. AFAIK, it's been implemented on one of the BSD varients (BSDI Unix, perhaps?)

        --
        Ytrew

Re: Most useless function.
by McDarren (Abbot) on Feb 17, 2006 at 02:11 UTC
    This one tickled my fancy :)
    #!/usr/bin/perl -wl use strict; use Acme::Don::t; print "this" and don't {print "that"};

      Really? I love Acme::Don::t!

      do { # some debugging stuff } #becomes don't { # some debugging stuff }

      It's essentially a block comment for code removal, and while I wouldn't put it in production, it's a very useful programming tool. IMO, anyhow.

      <-radiant.matrix->
      A collection of thoughts and links from the minds of geeks
      The Code that can be seen is not the true Code
      I haven't found a problem yet that can't be solved by a well-placed trebuchet
        That is not only a clever trick, but it provokes thoughts I should have been having for years.


        -----------------------
        You are what you think.

Re: Most useless function.
by Steve_p (Priest) on Feb 17, 2006 at 14:09 UTC

    I wouldn't have thought it, but some fairly basic usage of not (as apposed to ! which worked just fine) caused core dumps from 5.6.0 through at least 5.8.5. Although technically an operator, the core dump went over five years without a single bug filed on not. Its ranking fairly high on the uselessness scale for me right now.

      What was the actual Perl code triggering the core dump?
        Actually, I was a bit wrong. It was actually a fairly useless use of not.
        perl -e 'not() || 1' perl -e 'die unless not()'
Re: Most useless function.
by Aristotle (Chancellor) on Feb 21, 2006 at 03:29 UTC

    The BeOS kernel actually has such functions:

    int32 is_computer_on(void)

    Returns 1 if the computer is on. If the computer isnít on, the value returned by this function is undefined.

    double is_computer_on_fire(void)

    Returns the temperature of the motherboard if the computer is currently on fire. If the computer isnít on fire, the function returns some other value.

    Makeshifts last the longest.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://530693]
Approved by wfsp
Front-paged by Courage
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2014-08-28 04:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (256 votes), past polls