gurus: example code as main level code ? [message #32766] |
Fri, 01 November 2002 09:04 |
R.G. Stockwell
Messages: 363 Registered: July 1999
|
Senior Member |
|
|
Greetings all,
I am going through my monster IDL library, and was wondering what
people think of the practice of including a main level "example" or
"Test" code at the end of each function and procedure?
Are there any reasons not to do this?
I don't see any, but I am probably missing something, i usually am :).
I do this almost always (and in fact, I am planning to make this a rule,
so that all my functions will have an example if anyone runs the function.
Cheers,
bob stockwell
As an example of what I mean, here is a tiny (but useful) function:
You call it as result = range(array), but if you want to see an
example of the function, just do
IDL>.run range
function range, ts,_extra=_extra
if n_elements(ts) lt 1 then return,-1
return, [min(ts,_extra=_extra),max(ts,_extra=_extra)]
end
a = findgen(10)+44
print,range(a)
end
|
|
|