Re: gurus: example code as main level code ? [message #32735] |
Tue, 05 November 2002 12:23 |
Pavel A. Romashkin
Messages: 531 Registered: November 2000
|
Senior Member |
|
|
David Fanning wrote:
> Well, Pavel, you are in a particularly cranky mode
> this morning. And well you should be!
>
> Cheers,
>
> David
>
> P.S. Let's just say that "hat" looked ridiculous on you
> last night. :-)
Now, wait a minute! That was not *me* whos head you put that old truck
tire on!
What day is it anyway? Geez, has it been 5 days since *that* party?... I
will resign once the hangover is over and I can spill... I mean, spell again.
Or maybe not, you don't get to see David do what he was doing all that
often. Maybe the hangover is worthit :-)
Cheers,
Pavel
|
|
|
Re: gurus: example code as main level code ? [message #32747 is a reply to message #32735] |
Mon, 04 November 2002 13:09  |
R.Bauer
Messages: 1424 Registered: November 1998
|
Senior Member |
|
|
R.G. Stockwell wrote:
> Reimar Bauer wrote:
>> Dear Bob,
>>
>> I am wondering a bit what happens to the example if I do
>>
>> .compile range
>> resolve_all
>> save,file='range.sav',/routines,/compress
>>
>> It seems only the function is saved in the sav binary.
>>
>> First I was thinking this could be a problem for the routine
>> itselfs, but it works fine. I can miss the example by runtime routines.
>>
>> Normally if we have more complicated routines you need more as one
>> testcase. Or did you think about having a large main program which tells
>> what it is testing and what the result should be and is. At the moment I
>> am using the EXAMPLES: tag in the comments.
>>
>> By graphic routines this is nearly impossible. There is a saved image
>> better for comparisons. For the plotenvironment I have already a large
>> image / testcases which is very useful during beta tests.
>>
>> Your idea will make it very easy to check math functions and to show
>> differences if the output is redirected to a file.
>>
>>
>> regards
>>
>> Reimar
>
> Very good point Reimar, I had not considered what would
> happen in a sav file. I rarely use them, usually only for an
> interim data storage solution in development.
> Perhaps I will switch over to an /examples keyword.
>
> I also include a /help keyword too, to remind the user (i.e. me)
> what keywords are available and how to use the routine, but it
> would probably be better to make a help file or some other real
> documentation.
Dear Bob,
For this case may be my call_help routine is interesting too.
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_source/idl _html/dbase/download/call_help.tar.gz
This routine is able to read out the comments from the description.
So it is not necessary to describe things always twice. And it is much
easier to do changes at only one place.
For example if you have a routine which needs two positional parameters
(I have added only a subset of the header and the routine.)
If you enter less parameters always the text from
; CALLING SEQUENCE: is printed out.
IDL> x=diff_struct()
% DIFF_STRUCT:
result=diff_struct(struct1,struct2,[diff1=diff1],[diff2=diff 2])
I am using the example comment too to describe by many examples
what the routine is doing.
This could be extracted too. If you have a look in the catalog
by
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_source/idl _html/examples/diff_struct_example.pro.html
regards
Reimar
;+
; NAME:
; diff_struct
;
; PURPOSE:
; This function returns all differences of all values from two structures.
; Pointer or values could be compared.
; Only tags which are in both structures are compared.
; Differences could be returned by ARG_PRESENT by diff1 or diff2.
;
; CATEGORY:
; PROG_TOOLS/STRUCTURES
;
; CALLING SEQUENCE:
; result=diff_struct(struct1,struct2,[diff1=diff1],[diff2=diff 2])
;-
FUNCTION diff_struct,struct1,struct2,diff1=diff1,diff2=diff2
IF N_PARAMS() LT 2 THEN BEGIN
MESSAGE,call_help(),/cont
RETURN,-1
ENDIF
return,1
END
--
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
http://www.fz-juelich.de/icg/icg-i/
============================================================ ======
a IDL library at ForschungsZentrum Juelich
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_lib_intro. html
|
|
|
Re: gurus: example code as main level code ? [message #32749 is a reply to message #32747] |
Mon, 04 November 2002 06:11  |
R.G. Stockwell
Messages: 363 Registered: July 1999
|
Senior Member |
|
|
Reimar Bauer wrote:
> Dear Bob,
>
> I am wondering a bit what happens to the example if I do
>
> .compile range
> resolve_all
> save,file='range.sav',/routines,/compress
>
> It seems only the function is saved in the sav binary.
>
> First I was thinking this could be a problem for the routine
> itselfs, but it works fine. I can miss the example by runtime routines.
>
> Normally if we have more complicated routines you need more as one testcase.
> Or did you think about having a large main program which tells what it is
> testing and what the result should be and is. At the moment I am using the
> EXAMPLES: tag in the comments.
>
> By graphic routines this is nearly impossible. There is a saved image better
> for comparisons. For the plotenvironment I have already a large image /
> testcases which is very useful during beta tests.
>
> Your idea will make it very easy to check math functions and to show
> differences if the output is redirected to a file.
>
>
> regards
>
> Reimar
Very good point Reimar, I had not considered what would
happen in a sav file. I rarely use them, usually only for an
interim data storage solution in development.
Perhaps I will switch over to an /examples keyword.
I also include a /help keyword too, to remind the user (i.e. me)
what keywords are available and how to use the routine, but it
would probably be better to make a help file or some other real
documentation.
Cheers,
bob
|
|
|
|
Re: gurus: example code as main level code ? [message #32760 is a reply to message #32758] |
Fri, 01 November 2002 10:51  |
Pavel A. Romashkin
Messages: 531 Registered: November 2000
|
Senior Member |
|
|
I am not quite sure I figured out what this is supposed to do. I guess
this is because I never run any code longer than a line from the main level.
In any case, if I happen to write a program longer than 50 lines, I try
to write an intelligeable header or even an HTML page for it, with
examples of use and explanations. If the code is shorter than 50 lines,
it is assumed to be self-explanatory. Using a main level example seems
insufficient for any modestly complex program.
I do not mean to say it is bad for any reason. Just to say I personally
don't really see any use for it.
Cheers,
Pavel
"R.G. Stockwell" wrote:
>
> 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?
> --snip--
|
|
|
Re: gurus: example code as main level code ? [message #32762 is a reply to message #32760] |
Fri, 01 November 2002 09:56  |
R.Bauer
Messages: 1424 Registered: November 1998
|
Senior Member |
|
|
R.G. Stockwell wrote:
> 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.
>
Dear Bob,
I am wondering a bit what happens to the example if I do
.compile range
resolve_all
save,file='range.sav',/routines,/compress
It seems only the function is saved in the sav binary.
First I was thinking this could be a problem for the routine
itselfs, but it works fine. I can miss the example by runtime routines.
Normally if we have more complicated routines you need more as one testcase.
Or did you think about having a large main program which tells what it is
testing and what the result should be and is. At the moment I am using the
EXAMPLES: tag in the comments.
By graphic routines this is nearly impossible. There is a saved image better
for comparisons. For the plotenvironment I have already a large image /
testcases which is very useful during beta tests.
Your idea will make it very easy to check math functions and to show
differences if the output is redirected to a file.
regards
Reimar
>
> 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
--
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
http://www.fz-juelich.de/icg/icg-i/
============================================================ ======
a IDL library at ForschungsZentrum Juelich
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_lib_intro. html
|
|
|
Re: gurus: example code as main level code ? [message #32763 is a reply to message #32762] |
Fri, 01 November 2002 09:46  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
> Oh, bravo! You just missed this year's dinner
> (update to follow when my headache goes away),
> but this will get you an automatic invite to
> next year's IEPA dinner!
It just occurs to me, Bob, that maybe you *were*
at last night's dinner. I don't know...I can't
remember. Everything got a little fuzzy for me
when the dancers showed up with those little
twirly things. :-(
Anyway, let's just say I'd be working on a speech
in any case.
Cheers,
David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|
Re: gurus: example code as main level code ? [message #32764 is a reply to message #32763] |
Fri, 01 November 2002 09:39  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
R.G. Stockwell (sorry@noemail.now) writes:
> 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.
Oh, bravo! You just missed this year's dinner
(update to follow when my headache goes away),
but this will get you an automatic invite to
next year's IEPA dinner!
Cheers,
David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|