why no "do : until"?

dalf dalf at nospam.org
Fri Jan 5 11:51:50 EST 2001


Steve Lamb <grey at despair.rpglink.com> wrote:
> On 03 Jan 2001 21:26:49 -0500, Lloyd Zusman <ljz at asfast.com> wrote:
>>But you know damn well that the person who said that was not using the
>>word "arbitrary" as you're using it above, and therefore, you're
>>deliberately playing with words here, just to be argumentative.
>
>     I am using it in the exact same way.  To an arbitrary value, not set it
> arbitrarily.  To set it to a known value.  That is initting a variable.  A
> value you choose for your own devices.

There are two problems:

- You set the variable to a value that has no meaning, except that for
  this variable you are able to simulate the control flow of the program
  in your head, and the value you chose is going send you at the right
  point.
    This is ugly and bug-prone. This is a hack. The very least people 
  would admit here would be:
    temperature=None
    while temperature==None or temperature<25:
       ...

  Also what value would you use with a different test, such as:
    temperature= ???
    while 0.5 <= math.sin(temperature)+1.0/temperature <= 0.6:
      ...

- Your idiom requires an arbitrary but predictible value, which
  is ugly as well, since such a value a) might not exist, 
  b) might well require 64 MB of memory, c) might change suddenly
  when code elsewhere is modified. Consider the following Java code:

  VeryBigObject veryBigObject=new VeryBigObject("21323EZRer234");
              # "21323EZRer234" is the value I know it will pass the test
	      # "21323EZRer235" would NOT do nor 1e100 other values.
	      # Note: uses 64 MB of memory
  while (veryBigObject.test()) {
       ...
  }
  

  Now if one change VeryBigObject definition 10 years from now,
so that veryBigObject.test() is now verified for "21323EZRer235",
but not "21323EZRer234", congrats! You have splendid code breakage,
which might be extremely hard to debug. Not to mention the 64 MB of
memory wasted until next GC.


The conclusion is that you *cannot* use this idiom everywhere. 
It's just a complete hack.

.dalf



More information about the Python-list mailing list