http://qs321.pair.com?node_id=925910

metaperl has asked for the wisdom of the Perl Monks concerning the following question:

Logic::Kleene implements three-valued logic. For a long time, I couldnt imagine a practical use of this, but now I know one: user authentication. Currently, the authenticate method of Mojolicious::Plugin::Authentication returns true if the user authentication worked and false if not.

But there's a third possibility. He existed but did not authenticate. And presumably you would want different feedback to the user in that case. So 3-valued logic would be nice. But I think it's a bit fixed. Better just to return 0 for success and a status code for each form of failure?

  • Comment on A practical use of Logic::Kleene (3-valued logic)

Replies are listed 'Best First'.
Re: A practical use of Logic::Kleene (3-valued logic)
by BrowserUk (Patriarch) on Sep 14, 2011 at 14:44 UTC

    "Three value logic" is of little use when you only have binary control mechanisms.

    To be of value, you'd have to have a control structures that had three branches:

    if( <condition> ) { ... } else { ... } otherwise { } my $var = <COND> ? $a :: $b :: $c;

    Given that about 90% of programmers seem unable to handle the idea of:

    unless( <cond> ) { ... } else { ... }

    It seems unlikely that they'd go for trinary control mechanisms any time soon.

    Without them, you'd just end up coding the direct equivalent of:

    if( $loginAttempted ) { if( $loginSuccessful ) { ... } else { ... } } else { ... }

    But in a far more obscure way.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: A practical use of Logic::Kleene (3-valued logic)
by keszler (Priest) on Sep 14, 2011 at 14:15 UTC

    If someone is attempting to crack into a system, knowing that they have a valid username but incorrect password is helpful to them. If every random attempt yields "invalid username or password" they learn nothing.