Working my way through some OpenEdge courses, my eye fell on the explanation of the concept of procedures and how to return from them. One recommendation that struck me was this one:
A best practice is to place a return statement as the last statement of a procedure.
Now, nothing better than a religious war at the start of my holiday, so can anybody explain me why on earth I would want to have a RETURN statement at the end of my procedure? Like it doesn't return? Or does the AVM start hanging about or something?
There are only 2 cases where I would expect a RETURN statement:
1) If you get paid per line of code
2) If you are working with RETURN-VALUE
I think both of them are bad things, so why would you want to explicitely RETURN?
I believe it would reset the ERROR-STATUS
I totally agree with you. It makes no sense to me and is just a waste of time.
ah...clears RETURN VALUE
No, I don't use the RETURN-VALUE because I think it is a dangerous concept. It is not clear what it tries to do. If you really need to give something back to the caller, better make it explicit by using parameters. This also prevents you from accidentally breaking the system.
I have (more than once) broken a RETURN-VALUE concept, just by adding an extra intermediate call and not giving back the RETURN-VALUE. Simply because I overlook it. You cannot forget to use parameters if the program has them. Or at least the runtime will kindly remind you of them :)
Hi Patrick,
I think it was one of those things that was added long, long ago but as you say there are much better options available now.
Brian
Sorry - still don't agree. If the procedure EVER does RETURN <value>, then it should always do so. If it doesn't EVER do that, then it doesn't need a RETURN statement and that is part of the API of the procedure. The caller should not be looking at RETURN-VALUE if the caller of the procedure never sets it.
P.S. - The same comment regarding ERROR-STATUS. No one should be looking at ERROR-STATUS unless they just did a statement with NO-ERROR on it. Otherwise its contents are unpredictable.
just "END" or "END PROCEDURE"?
I always use end procedure, it takes more time but clarify the code.
Maybe RETURN. END. is the equivalent version: hey! this is your end procedure line!
@Peter I agree that it is mandatory on functions and methods and if you think of it, it is kind of strange that the compiler does not raise a warning for you. Might be a good candidate for the -strict startup option
I worked in a shop in the past where we had a global {&ResetError} preprocessor. All that did was assign something no-error to reset the flag. Horrible. It was everywhere in the code, just before any statement where the code was checking the value of error-status afterwards. A complete mess.
Just stop using procedures altogether and only use classes/methods unless the language is forcing you to (e.g. bootstrapping, .p to access AppServer, async callback procedure etc...).
That seems to work for me ;-)