[Top][All Lists]

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

Philosophy help.

From: John W. Eaton
Subject: Philosophy help.
Date: Wed, 6 Dec 2000 11:02:09 -0600

On  6-Dec-2000, Douglas Eck <address@hidden> wrote:

| Why doesn't Octave stay matlab compatible
| when it seems easy to be matlab compatible? 
| Isn't it a design goal of octave to be matlab compatible?

No.  As I have said many times, I never set out to create a Matlab
clone.  We chose to use Matlab syntax because we knew people who were
using Matlab, and we thought it would be easier for them to start
using Octave if they didn't have to learn something completely new.

| For example matlab's default is to short-circuit 
| the or operator (|). Why does octave have a new
| short-circuit operator (||) and make (|) not short-circuit.

If you examine the way Matlab's short-circuiting actually works, you
might conclude (as I did) that it is a really stupid feature.  For
example, it only behaves as a short circuiting operator if it is in
the condition of an if statement or while loop, and only if the first
operand is a scalar.  Unfortunately, this causes trouble in several
cases.  When it came up on comp.soft-sys.matlab about 5 years ago that
this feature was planned for Matlab 5, I suggested that it might cause
existing programs to break, and that it was unnecessarily inconsistent
for it to behave differently depending on whether you wrote

  if (a | b) ... end


  t = a | b;
  if (t) ... end

(think about what happens if the operands are functions that have side
effects, for example) and suggested leaving the old behavior for | and
& alone and adding new || and && operators that always exhibited
short-circuiting behavior.  Within a few hours, I had implemented this
feature, posted a patch to the Octave ftp site, and invited people to
give it a try.  The response from the MathWorks was essentially
"people don't write much code like that, so these are minor problems
that people will never notice".  My guess at a translation was "we've
already written the docs, done the QA, and have the CDs ready to ship,
so there's no way we're going to redesign this now".

More recently on the Matlab newsgroup, someone pointed out that there
were some bad inconsistencies when one of the operands is an empty
matrix.  That seemed to get the attnetion of the people at the
MathWorks, but as far as I know, they have not posted their plans for
resolving the problem yet.

| Isn't it clear that changes like this make it
| absolutely hell to have code that is both matlab and
| octave clean? 

Sorry.  If you want Matlab, I guess you know where to find it.

| I'm not trying to be nasty or negative. I'm just confused.
| I've got roughly 10,000 lines of matlab code to port. I'm happy,
| very very happy, to port it to octave and am excited to get away
| from Mathworks!

Then quit complaining and get to work!  Also, please stop to consider
for a moment that just because Matlab has some feature does not
necessarily make it good.

|  But I need somehow to get a grip on these
| differences early so that I don't go insane. And clearly
| I still want to be able to run my code under matlab.

Ah.  That's too bad.  I thought you wanted to get away from the

| I guess the real question is: is it possible to write clean
| matlab-octave code?

Sure, some people do it.  But they usually do it from the outset, not
by coming from Matlab to Octave and then complaining about how the
free software alternative is somehow inferior because it is not
exactly like Matlab.  Are you sending similar complaints to the
MathWorks asking them why they have developed features that are
incompatible with Octave?

| And is it a design goal of the octave
| group to make this possible?

Although there have been a number of contributors over the years (and
I do appreciate the work done by all of them), the `Octave group' has
for the most part always been just one person.  So, if you are asking
my opinion, bug-for-bug compatibility has definitely not been a design

| It *seems* possible, but when
| you come to examples like the or operator, it starts to 
| feel a bit daunting to really have a big project work in both. 
| Ah well, I could always use make (laugh, its funny...)
| function [bar] = myfun(foo)
| #ifdef OCTAVE
| if nargin<1 | isempty(foo)
| #endif
| #ifdef MATLAB
| if nargin<1 || isempty(foo)
| #endif

Wouldn't it be cleaner to write

  if (nargin < 1 __MY_OR_OPERATOR__ isempty (foo))

and simply run sed over your scripts to replace __MY_OR_OPERATOR__
with whatever is appropriate?


Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:
How to fund new projects:
Subscription information:

reply via email to

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