Re: Most Common IDL Programming Errors [message #59723 is a reply to message #59721] |
Wed, 09 April 2008 10:11   |
brodzik@nsidc.org
Messages: 7 Registered: July 2005
|
Junior Member |
|
|
On Apr 8, 6:13 pm, David Fanning <n...@dfanning.com> wrote:
> beer in the house again, and it occurred to me that I should
> have a page listing the 10 or 15 most common IDL programming
> errors with their solutions. But I can only think of three.
>
> Here are the three errors I most commonly see in IDL programs.
Using the assignment operator '=' instead of comparison 'eq' in a
conditional test.
One way to be defensive about this is to be in the habit of putting
the constant value
on the left side, so the compiler catches the syntax error long before
runtime.
For example, this will fail the conditional, but happily reassign the
value of a to 0:
IDL>
a=5
IDL> if ( a = 0 ) then print,
'OK'
IDL>
print,a
0
Also a bit of a bear to debug, depending on the conditional
consequences, and how
important it is for a to stay 5...
Whereas this will let the compiler find the problem long before you
run it:
IDL>
a=5
IDL> if ( 0 = a ) then
print,'OK'
if ( 0 = a ) then
print,'OK'
^
% Syntax
error.
IDL>
On the other hand, my coworkers *hate* reading my
"backwards comparison" style, so if you adopt this style,
you'll get a lot of odd looks at walkthroughs.
MJ
|
|
|