Path: news.mathworks.com!newsfeed-00.mathworks.com!fu-berlin.de!nuzba.szn.dk!pnx.dk!feeder.eternal-september.org!eternal-september.org!not-for-mail
From: dpb <none@non.net>
Newsgroups: comp.soft-sys.matlab
Subject: Re: genvarname doesn't work
Date: Fri, 10 Jul 2009 17:52:10 -0500
Organization: A noiseless patient Spider
Lines: 62
Message-ID: <h38h6o$9b8$1@news.eternal-september.org>
References: <h37t8i$6kh$1@fred.mathworks.com> <op.uwu54zbja5ziv5@uthamaa.dhcp.mathworks.com> <h389nd$omc$1@fred.mathworks.com> <h38a6i$pud$1@fred.mathworks.com> <h38c66$5f9$1@fred.mathworks.com> <h38dor$hld$1@fred.mathworks.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.eternal-september.org U2FsdGVkX18noIDQTH1m9XM/nV1dybs4NMWJ6sF/yUZZbUKadNUAYoCLYkWeW8NdCUQt9xz0ua/LwVD09l5nZUYP52l4FMdUTEQyvDSYuGrX2SvbbkPjO3g0HrwVTM5yE6hG8X9W7daF5O29ewfaQw==
X-Complaints-To: abuse@eternal-september.org
NNTP-Posting-Date: Fri, 10 Jul 2009 23:00:42 +0000 (UTC)
In-Reply-To: <h38dor$hld$1@fred.mathworks.com>
X-Auth-Sender: U2FsdGVkX19pP84fe7fCh0k7AKSZ2bZ9aqB/4fxJx7w=
Cancel-Lock: sha1:pnYORzrC+7DetUGIKTdfo0PQDbw=
User-Agent: Thunderbird 2.0.0.22 (Windows/20090605)
Xref: news.mathworks.com comp.soft-sys.matlab:554598


Juliette Salexa wrote:
> I read the FAQ page, thank you Steven and Oleg. It seems that Matlab
> is very adament about us not poofing variable names at runtime.

In this case "TMW" instead of "ML" but, yes... :)

> Is this only because it's harder to read, and therefore harder to
> debug ??

That's one of the given reasons.

> Because they could change the syntax so that it's not so hard to
> read:
> 
> x=['a' 'b' 'c' 'd']; for i=1:4 Mygenvarname(x(i))=i end

But reread the examples on potential problems w/ variable naming, etc.

But don't undersell the importance of clarity in written code and the 
use of some slight additional complexity (perhaps) in the 
implementation.  Unless the code is simply a "throw away" one-use hack, 
it's quite possible it may be needed to be maintained and developed for 
quite some time and also by somebody else.  This effort often in real 
life will dwarf the initial effort and anything that can do up front to 
help in that process later on is well worthwhile.  Also, even if it us 
"just your code", a few months from now when it's no longer so familiar, 
you'll thank yourself you didn't obuscate...(damhikt :) ).


..snip another explanation/justification...

> Matlab's solution to this on the FAQ page is to use a structure s.a,
> a.b, s.c .... s.n ....
> 
> I'm not too familiar with structures .. but it seems as if they take
> up more memory and are a more complex data structure in general .. it
> seems like its harder to access or view information contained in
> them.. I'm probably wrong, but can someone please explain to me why
> ??

Again from the FAQ...

"MATLAB arrays (either numeric or cell) will let you do the same thing 
in a much faster, much more readable way."

"...use structures instead of cell arrays. The fields of the structure 
can be the variable names you want. And you can index into them with 
dynamic field references."

I would suggest re-reading that subsection and looking at the sample 
code.  The level of indirection is minor and the benefit is major.  Is 
it really _THAT_ much more effort to type x.name that you'll go to the 
trouble to poof the name "name" w/ the possible syntax issues outlined?

And, lastly, go back to the first sentence in the FAQ quoted above--it's 
simply better-performing.  It avoids the high overhead operation of 
EVAL(), _a_good_thing (tm) in its own right...

Time and experience will breed familiarity and you'll soon be glad you 
escaped the trap despite some initial growing pains...

--