[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #55622] for loop does not run over a matrix wi

From: Rik
Subject: [Octave-bug-tracker] [bug #55622] for loop does not run over a matrix with colums but no row
Date: Thu, 14 Feb 2019 12:14:03 -0500 (EST)
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko

Follow-up Comment #13, bug #55622 (project octave):

I still disagree, and think we should leave Octave's current behavior as is.

In terms of UX/UI design I prefer to have the minimum number of principles and
be able to to derive the behavior from these, rather than having lots of ad
hoc exceptions.

For example, from the Declaration of Independence, "All men are created
equal".  But, starting in 1896 (Plessy vs. Ferguson and doctrine of "separate
but equal"), you had to special case the general principle based on location. 
If you were in the North or West of the U.S. the general principle applied,
but if you were in the South then you used the exception.  This turned out to
be a dumb idea and the U.S eventually went back to just one guiding principle
in 1954 (Brown vs. Board of Education of Topeka).

My conception of a for loop over an object (as opposed to a range like 1:1000)
is that it is equivalent to a foreach loop over the elements of the object. 
Hence, if the object is empty, there should be no looping.  For me, looping
over empty matrices means creating a mental exception only for "for" loops
which seems unneccessary.

Of course, Matlab, like Moses, has said, "looping occurs over the number of
columns".  But, I guess I'm skeptical of the stone tablets.  We don't always
follow Matlab when they veer off the rails which I think is the case here.

As a practical matter, I think user's code would be improved by choosing the
loop variable more explicitly, rather than relying on this questionable
behavior.  If you want to look a certain number of times, do that.

%% Clear code
for i = 1:5
  disp ("Hello World");

%% Unclear code
idx = zeros (0,5);
for i = idx
  disp ("Hello World");

Also as a practical matter, I don't think this odd construct occurs with much
frequency so changing the few instances that occur wouldn't be burdensome.

With all that said, this isn't an issue I'm particularly interested in arguing
over.  If you need to commit the patch for some clients who require 100%
compatibility then it happens.


Reply to this item at:


  Message sent via Savannah

reply via email to

[Prev in Thread] Current Thread [Next in Thread]