Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

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

by metaperl (Curate)
on Sep 14, 2011 at 14:02 UTC ( #925910=perlquestion: print w/replies, xml ) Need Help??

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 (Pope) 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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://925910]
Approved by tye
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2020-09-29 10:45 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (146 votes). Check out past polls.