Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^4: Untillian Headache or about the semantic of until

by tmharish (Friar)
on Feb 11, 2013 at 19:36 UTC ( #1018223=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Untillian Headache or about the semantic of until
in thread Untillian Headache or about the semantic of until

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?


Comment on Re^4: Untillian Headache or about the semantic of until
Select or Download Code
Re^5: Untillian Headache or about the semantic of until
by BrowserUk (Pope) on Feb 11, 2013 at 20:33 UTC
    Given this I dont see where the disagreement lies? Did I miss something?

    Yes. You missed that I completely disagree with your assertion that [it is] far better to use while( ! ) and if(!) for complex conditions.".

    The disagreement is in the imperativeness of the phrase "for complex conditions".

    It implies -- and by your arguments you are more than just implying, you are stating -- that all complex conditions will be easier to understand if phrased in their while form rather than their until form. And that is patently not so.

    Take your own example -- despite that it is tortuously contrived and completely illogical. This:

    while ( ! $no_error_opening_file and !( eof and $need_not_process_beyond_eof ) and ! $found_all_elements_I_was_looking_for ) {

    Is no clearer -- and is arguably much less clear -- than this:

    until( $no_error_opening_file or ( eof and $need_not_process_beyond_eof ) or $found_all_elements_i_was_looking_for ) {

    (And no matter how you decide to apply deMorgan to it, it will never get any clearer; and will frequently resolve to a conditional that no one understands in terms of the semantics of the surrounding code.)

    Neither of those are clear. And that's because it is a ridiculously contrived example that (hopefully) no one would ever code.

    • Would anyone re-test whether they had succeeding opening the file after having successfully already read a line from it?

      And then continue to do so for every line of that file?

    • $need_not_process_beyond_eof; you mean it is possible to process a file beyond the of that file?

      !?

    • And what logic is there is adding or $found_all_elements_i_was_looking_for to the looping condition?

      In order for flag variable $found_all_elements_i_was_looking_for to change state, it has to be set within the loop.

      And if you can set a flag variable within the loop; why defer the exit action until the loop iterates, when you can just last; at the point of discovery? It makes no sense.

    And that's what happens when you try to contrive an example to support an illogical argument. You end up arguing on the basis of code that no one would write.

    Some conditions -- complex or simple -- lend themselves to clarity when phrased with while. Eg:

    open FH ... or die ...; while( <FH> ) { my $foundEverything = processLine( $_ ); last if $foundEverything; }

    Other are clearer phrased using until. Eg:

    open FH ... or die ..; until( eof FH ) { my $line1 = <FH>; my $line2 = <FH>; my $foundEverything = processRecord( $line1, $line2 ); last if $foundEverything; }

    Having both available to Perl is a strength -- highlighting a weakness in languages that do not -- and should be applauded and lauded; not denigrated away in appeasement to those who think anything not found in their first programing language is weird or dangerous.


    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.
    P
      And that's what happens when you try to contrive an example to support an illogical argument. You end up arguing on the basis of code that no one would write.

      In hindsight that was not a very good example!

      not denigrated away in appeasement to those who think anything not found in their first programing language is weird or dangerous.

      That might be whats happening here - I guess the only way to know would be if I watched myself the next time I use while instead of until and see if I am doing so because its better or because I am more comfortable with it.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2014-07-26 11:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (175 votes), past polls