Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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

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.

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 rifling through the Monastery: (14)
As of 2015-07-01 19:52 GMT
Find Nodes?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...

    Results (19 votes), past polls