|
How could such a simple procedure teach me so much? Well it is. Thank you folks. Next question: Simon and others have spoken of passing in the SleepFor value as a 5 digit value. Why isn't it passed as *HMS? the procedure itself can add the *HMS to the current time, or whatever. The added benefit is that then there is no issues as to how many seconds in 42 minutes. _______________________ Booth Martin Booth@MartinVT.com http://www.MartinVT.com _______________________ "Simon Coulter" <shc@flybynight.com.au> Sent by: owner-rpg400-l@midrange.com 09/20/2000 12:40 AM Please respond to RPG400-L To: RPG400-L@midrange.com cc: Subject: Re: how to let my program sleep a while ? Hello Booth, You wrote: >As usual your suggestion is best. Much better. Two procedures it shall >be. Now, (every body skips over the easy stuff!) why do I want to use >"CallP Sleepfor('00:30:00')" >instead of >"Call 'SleepFor'" >"Parm '00:30:00' Parm8 8" Because CALLP requires a prototype which the compiler uses to verify that the data type specified on the prototype is compatible with the the type of data actually used on the call. With CALLB (and indeed with CALL) the invoker can pass any old crap to the procedure. Prototypes help make robust software by catching stupid programmer errors** during compilation rather than run-time. It's not perfect but it a bloody sight better than the alternative. Barbara's comment on the choice of names is correct (and in fact the choice of name is the single most important aspect of a procedure). In this case you have two similar but different procedures. They need different data types. sleepFor() needs a duration but sleepUntil() needs an absolute time. You should define the prototypes accordingly e.g., D sleepUntil PR D time T VALUE TIMFMT(*HMS) such a prototype will stop the caller from passing character or numeric data unless it can be converted by the compiler into the correct type. Since RPG doesn't have a duration data type we need to content ourselves with a numeric value of some sort e.g., D sleepFor PR D duration 5I 0 VALUE but at least that limits the possible sources of crap data. The onus is still on the programmer to pass the correct stuff but with prototypes you can restrict the truly creative. (You may decide to design sleepFor() to accept a time data type and then convert it to a duration -- you might choose to interpret the time as an offset from midnight and the procedure will sleep for that many hours, minutes, and seconds.) In my example from a few days ago I defined the parameter as a 6,0 packed field because the range of allowable values on DLYJOB is 1 to 999999. Now see if you agree that the two procedures described above are better than one like the following: D sleep PR D delay 5I 0 CONST OPTIONS(*OMIT) D resumeTime T CONST OPTIONS(*OMIT:*NOPASS) I know a lot of this appears to be simply style but think about it for a bit -- and read some stuff on Object Oriented (not Orientated!!) Design. Two good books on the subject are: Designing Object Oriented Software by Rebecca Wirfs-Brock Design Patterns by Erich Gamma et al. These books should be on all programmer's bookshelves alongside the well-thumbed 3-volume (unfinished) set by Donald Knuth. Note that you may choose to create just such a sleep() procedure to do the real work and then wrap it in a facade using the first two prototypes. It depends on how important abstraction and encapsulation is to you. In this case sleep() would be private while sleepFor() and sleepUntil() would be part of the public interface. >I understand that for most of you this is pretty basic, but hey, I just >don't know the answer. And now you do :) ** (i.e., those errors that are human mistakes rather than errors made by stupid programmers -- nothing shields you from those) Regards, Simon Coulter. «»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«» «» FlyByNight Software AS/400 Technical Specialists «» «» Eclipse the competition - run your business on an IBM AS/400. «» «» «» «» Phone: +61 3 9419 0175 Mobile: +61 0411 091 400 «» «» Fax: +61 3 9419 0175 mailto: shc@flybynight.com.au «» «» «» «» Windoze should not be open at Warp speed. «» «»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«» +--- | This is the RPG/400 Mailing List! | To submit a new message, send your mail to RPG400-L@midrange.com. | To subscribe to this list send email to RPG400-L-SUB@midrange.com. | To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com. | Questions should be directed to the list owner/operator: david@midrange.com +---
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.