octave-maintainers
[Top][All Lists]
Advanced

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

Re: stupid Matlab-style short-circuit behavior for | and &


From: John W. Eaton
Subject: Re: stupid Matlab-style short-circuit behavior for | and &
Date: Thu, 7 Oct 2010 13:55:26 -0400

On  7-Oct-2010, Søren Hauberg wrote:

| I am not entirely against such a change. I think everybody here agrees
| that the "feature" is just plain stupid, but it is not an uncommon
| feature request. I do, however, think we should raise a warning every
| time a | or a & is interpreted when the feature is enabled. I really
| fear it will be hard to track down silly bugs otherwise.

I agree there should be a warning, so I'll add one.

I've been wondering whether having the ability to turn the feature on
and off at will is a good thing.  It could be quite confusing if
someone takes code that relies on this feature and runs it with the
feature turned off and gets different results.  It is not hard to come
up with cases where the lack of short-circuiting does not make things
fail, but just gives different results.  For example, this can happen
because of side effects or having an empty matrix on the RHS of an &
or | expression.

Another option would be to always have the feature enabled and the
warning turned on.  The warning would only be issued when the stupid
short-circuiting feature could be triggered (i.e., an & or |
expression in a WHILE or IF statement condition in which the first
argument is a scalar value).  Of course, you could turn off the
warning, but maybe the default would be considered too annoying for
most people?  I dunno.  They should probably be learning to not use |
and & for logical operations, but for some people old habits die
hard.  Even after Matlab has had || and && operators for years now
(and Octave even longer; && and || have short-circuited for more than
16 years now), we still encounter people who have never heard of them
and don't understand the difference between the logical and
element-wise operators.

jwe



reply via email to

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