Path: news.mathworks.com!not-for-mail
From: "Tim Davis" <davis@cise.ufl.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: How to be a good Matlab programmer
Date: Sun, 20 Apr 2008 09:18:04 +0000 (UTC)
Organization: University of Florida
Lines: 29
Message-ID: <fuf1oc$dmn$1@fred.mathworks.com>
References: <d6f9728b-07d7-4ebc-8264-e2485cde6259@c65g2000hsa.googlegroups.com> <Pine.LNX.4.50.0804201357230.32104-100000@localhost>
Reply-To: "Tim Davis" <davis@cise.ufl.edu>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1208683084 14039 172.30.248.37 (20 Apr 2008 09:18:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 20 Apr 2008 09:18:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 45902
Xref: news.mathworks.com comp.soft-sys.matlab:464117


Timo Nieminen <timo@physics.uq.edu.au> wrote in message 
...

> While your example above is short enough to not suffer, if
"dims = ..." 
> was a long way from the loop, and the loop was longer, the
reader might 
> well assume that "i" is an integer loop counter when
reading the code. 
> Apart from using i or j as counters being bad practice in
matlab 
> (sqrt(-1) and all that), "for dim = dims" is better for
readability.

I have to disagree about the use of i and j.  One should
never rely on i or j as the imaginary unit value, since they
can be masked by variables.  Use 1i instead, which can never
be overwritten by a variable.  It is always a constant equal
to sqrt(-1).  The variables i and j are not always equal to
sqrt(-1) and should thus not be relied upon.

The variables i and j have been used since time immemorial
as matrix row and column indices.  Stick with standard
mathematical notation and use them as such.

I personally think that the choice made, a long while back,
to use "i" as sqrt(-1) was a mistake.