Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Untillian Headache or about the semantic of until

by BrowserUk (Pope)
on Feb 11, 2013 at 14:31 UTC ( #1018152=note: print w/ replies, xml ) Need Help??


in reply to Untillian Headache or about the semantic of until

The first thing I noticed is that the ordering of the sub conditions is probably wrong in the original.

As constructed, if $wheel < 0, it won't be detected until after the first sub condition has already accessed a negative subscripted array element, which is almost certainly wrong.

So, I'd suggest you start with switching that around: until( $wheel < 0 || $odometer[ $wheel ] > 9 ) { ....

Then, I'd suggest you translate that into prose in your preferred language. (I use English; for you probably Italian?).

Loop, until the array index reduces past the start of the array; or, the value of the array element at the current index is greater than 9.

Then invert the logic of that prose description:

Loop, while the array index hasn't reduced past the start of the array; and, the value of the array element at the current index is less than or equal to 9.

And then translate it back to code: while( $wheel >=0 && $odometer[ $wheel ] <=9 ) {


And finally, the inevitable question about why you want to do that anyway?

How do Italian recipes phrase the common situation: Bake for 15 minutes or until the cheese is melted and bubbling.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
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.


Comment on Re: Untillian Headache or about the semantic of until
Select or Download Code
Re^2: Untillian Headache or about the semantic of until
by tmharish (Friar) on Feb 11, 2013 at 15:14 UTC
    And finally, the inevitable question about why you want to do that anyway?

    Interestingly this is not as straight forward as one might assume. In have studied cognitive development in children for the purpose of AI and it turns out that thinking in negation is a higher order cognitive function that children develop much later - This of course translates into the effort that one needs to put in when analyzing logic ( or code ). ( Basic papers on Google Search )

    In terms of programmers I have actually seen, even experienced programmers, ( over 10,000 hours of programming ) make mistakes when reading other peoples code that contains negation of large expressions. Of course they can write them very easily.

    I have seen a similar argument put forth in the book Perl Best Practices

      In have studied cognitive development in children for the purpose of AI ...

      I cannot argue against your claimed experience. But ...

      thinking in negation

      I can counter that.

      Waiting, or repeating something until something happens; is not thinking in negation.

      However, waiting or repeating something while something has not happened; is!

      even experienced programmers, ... make mistakes [when] code that contains negation of large expressions.

      I'll take it that by "large expressions" you really mean "complex expressions".

      And that points up the error in this justifiction. until (used properly) does not contain a negation.

      until (used properly), captures the positive expression of the terminating condition.

      Eg. Contrast:

      • until(  eof ) { Loop until you get to the end of file.
      • while( !eof ) { Loop while you haven't reached the end of the file.

      Which requires "thinking in negation"?

      I have seen a similar argument put forth in the book Perl Best Practices

      Never in the history of programming, has so much, been screwed up for so many; by so little justification.

      This is far from the worst atrocity that book has inflicted.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      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.

        Let me try and summarize what you have said so I can respond better:

        • Until when used properly should not contain a negation.
        • You implicitly seem to agree that negations in complex expressions do complicate programs.

        Of course until simplifies things when used properly which is why I said :

        However I believe that the use of until and unless and the likes are dangerous for precisely this reason. I find it far better to use while( ! ) and if(!) for complex conditions.

        The problem is that one might start with:

        until( eof ) {
        Which might becomes:
        until( eof or $found_all_elements_i_was_looking_for ) {
        which might then become:
        until( $no_error_opening_file or ( eof and $need_not_process_beyond_eof ) or $found_all_elements_i_was_looking_for ) {

        Of course when each of $no_error_opening_file ... are themselves expressions its not simple anymore.

        It is for exactly the same reason that I believe its good to have a ',' after the last element of a hash or to always ensure that ifs have blocks even if whats in the if is a single statement.

        I will ignore the first and last chunks as they have little to do with my original thesis.

        Given this I dont see where the disagreement lies? Did I miss something?

Re^2: Untillian Headache or about the semantic of until
by SuicideJunkie (Priest) on Feb 11, 2013 at 15:30 UTC
    This because in english until want a positive sentence but in italian 'finché' bring the possibility to use a negative form of the sentence after it, and in this way is commonly used: 'i wait until you arrive' can be translated as 'aspetto finché arrivi' but also sounds good as 'aspetto finché NON arrivi'.

    Which I read as "I will wait until you have not arrived".

    Translating via prose doesn't work well when that prose is invalid in a boolean sense due to slang, double negation or whatever.

      In italian the double negation is admitted and correct:

      I don't speak Italian, but I do note the OP said:

      In italian the double negation is admitted and correct:

      I do know that in English, there are some sentiments that cannot be adequately captured without a double negation: Eg.

      I like toast. does not fully capture the semantics of I don't not like toast. (Or perhaps more grammatically correct; I don't dislike toast.)

      I cannot attempt to divine the true sentiments of the double negation in a language I do not speak; but from my limited experience of other non-English languages that have constructions that make little or no sense when translated literally to English, I know that often such constructions are perfectly logical in that language.

      Eg. When speaking English, a Dutch person (who are usually very competent in English) will often say "When you were a woman..." instead of "If you were a woman ..." and conversely, "If the baby is born ... " when they actually mean "When the baby is born ...". It all comes down to the duality of the Dutch words 'als'.

      Similarly, expressing 8:35 in English as 5 minutes past half an hour before 9:00 makes no sense at all; but that is exactly how it is commonly expressed in Dutch: vijf over half negen.

      Which I read as "I will wait until you have not arrived".

      Basically, your attempts to apply non-native logic to a language you do not speak doesn't make for a sound basis of argument.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      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.
        I am not sure about Italian, but in Spanish negation does not always sum up. For instance, we say "I don't have no book" instead of "I don't have any book" or "I don't do it never" instead of "I never do it"... but "I never do it" is also correct and have the same meaning!

        Italian is the same. The more negation, the more emphatic but the meaning doesn't change.

Re^2: Untillian Headache or about the semantic of until
by Discipulus (Curate) on Feb 11, 2013 at 19:22 UTC
    BrowserUK: unfortunately your example until( $wheel < 0 || $odometer[ $wheel ] > 9 ) result in a broken odometer was: 0 0        No more Wheels to turn!.
    Even in the negated form.

    I have no reason to do this (and the author of the book state introducing the permutation problem that is a meaningless problem); i'm learning and when i encountered this idiom, the headache begun.. because it was not translatable in the, poor, logic in my brain. When I code i simply avoid thinking in this way and, hopefully, ther more way to do it..

    Finally the cook sentence you propose is a trivial case in which the plain 'finché' translation is okay. You miss the point: when you use a keyword as a logical operator and this word have a translation in your language it can create some semantic headache.

    Anyway thanks for the interest you put in such anomalous meditation.

    L*
    there are no rules, there are no thumbs..
Re^2: Untillian Headache or about the semantic of until
by Anonymous Monk on Feb 12, 2013 at 21:31 UTC
    Oddly enough, the $wheel < 0 may be unnecessary even if it does aid in clarification.

    Only in the case of the odometer 'turning over' will $wheel go negative. When $wheel is -1, $odometer[ $wheel ] will be the same as $odometer[ $#odometer ], which will have already been set to 0.

    ... of course relying on this in your code will piss off your maintainers.

    TJD

      Oddly enough, the $wheel < 0 may be unnecessary

      Indeed.

      When I originally posted my suggestion, it was purely on the basis of reading the code snippet in the OP. In general, when doing this kind of iteration with a while loop, I check the range of the index before attempting to use it to access the array.

      Only after discipulus refuted the idea, did I download the snippet and play with it and found that as posted, it "worked okay".

      It took a little more investigation to understand that it gets away with it because of perl's propensity to accept negative array indices.

      The funny thing is, that in one way, coding it "wrongly" has a benefit:

      #! perl -slw use strict; sub incOdo { my @odo = @_; my $wheel = $#odo; # until( $wheel < 0 || $odo[ $wheel ] < 9 ) { until( $odo[ $wheel ] < 9 || $wheel < 0 ) { $odo[ $wheel ] = 0; $wheel--; } if( $wheel < 0 ) { return; } else { $odo[ $wheel ]++; return @odo; } } my @odo = (0) x 2; for( 1 .. 102 ) { print join '', @odo = incOdo( @odo ); }
      • Coded 'correctly' attempts to iterate beyond the scale of the odometer fail silently:
        1 2 3 ... 97 98 99
      • But coded 'wrongly', that beyond range attempt fails noisely:
        1 2 3 ... 98 99 Use of uninitialized value within @odo in numeric lt (<) at C:\test\ju +nk31.pl line 9. Use of uninitialized value within @odo in numeric lt (<) at C:\test\ju +nk31.pl line 9.

        which could be seen as an advantage :)

        Of course, there are better ways of detecting the failure...


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1018152]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2014-07-31 00:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (241 votes), past polls