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: Mon, 21 Apr 2008 00:32:02 +0000 (UTC)
Organization: University of Florida
Lines: 52
Message-ID: <fugna2$i57$1@fred.mathworks.com>
References: <d6f9728b-07d7-4ebc-8264-e2485cde6259@c65g2000hsa.googlegroups.com> <Pine.LNX.4.50.0804210807080.8195-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 1208737922 18599 172.30.248.37 (21 Apr 2008 00:32:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 21 Apr 2008 00:32:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 45902
Xref: news.mathworks.com comp.soft-sys.matlab:464208



Timo Nieminen <timo@physics.uq.edu.au> wrote in message
<Pine.LNX.4.50.0804210807080.8195-100000@localhost>...
> On Sun, 20 Apr 2008, Tim Davis wrote:
> 
> > 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.
> 
> Excellent advice for robust programming. Especially for
scripts.
> 
> > 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.
> 
> Perhaps, but now we must live with it.
> 
> -- 
> Timo Nieminen - Home page:
http://www.physics.uq.edu.au/people/nieminen/
> E-prints:
http://eprint.uq.edu.au/view/person/Nieminen,_Timo_A..html
> Shrine to Spirits:
http://www.users.bigpond.com/timo_nieminen/spirits.html

Very true.

Please don't get me wrong, bye the way ... In spite of my
comment you make some excellent points in your post.  This
"what is i"? question is a philosophical one and reasonable
points about good coding practice can be made on both sides.