Difference between Sub-Procedure and Function

Krishan Gopal

New Member
Hi All,

I have one more silly question the difference between Sub-procedure and Function. One I know is that Returning Value. Are there any more differences?
Functions are faster compare to Procedures, I heard but don't know why.

Functions generally used for small business logic not for lengthy business logic.

Please give me your thought.
 

RealHeavyDude

Well-Known Member
Basically it's up to you to choose - whatever suits you better.

Differences OTOH:

  • For a function call the parameter signature is checked at compile-time (but not when you use DYNAMIC-FUNCTION) whereas for procedures it's not.
  • In functions or methods there are no input blocking statements like WAIT-FOR or PROCESS EVENTS allowed - these are only allowed in procedures.
  • The RUN statement has a default search order whereas a function call requires the function to reside in the same procedure unless you use DYNAMIC-FUNCTION.
Regards, RealHeavyDude.
 

RealHeavyDude

Well-Known Member
Out of experience I can tell you that this is at least not true for the PROCESS EVENTS statement which will throw a run time error when issued from a function or method.

HTH, RealHeavyDude.
 

GregTomkins

Active Member
In an attempt to think of something RHD did not ... functions are pickier than procedures, regarding type compatability. I don't know all the ins and outs of this, but here is an example:

function f returns char (p as int):
end.

f ("1"). /* this will not compile */

run p ("1"). /* this will compile and will also run cleanly, even though it passes a CHAR to an INT */

procedure p:
def input param p as i no-undo.
end.

Whether this is a good thing or not is a matter of opinion, I suppose.
 

GregTomkins

Active Member
Oh, and after many years of screwing around with external procedures vs. internal procedures vs. functions, my opinion is, unless it is being called in a tight loop, external procedures are generally best; there are many considerations in choosing between the three, but I generally prefer external procedures because they are the simplest and guarantee isolation of variables and buffers.
 

TomBascom

Curmudgeon
I like functions because returning a value is so much cleaner and more elegant.

Also -- functions can live in another procedure... the definition takes IN proc-handle or IN SUPER. Works great for building and accessing code libraries.
 

Krishan Gopal

New Member
My sincere thanks to all for replying.

AS all we know, nothing can replace External Procedure in Progress as it's the heart of progress 4GL, unitl we go for OOPs (OpenEdge - ABL).

I was trying to clear the things only between Sub procedures and Functions.
@ Tom - Sub procedures is also the part of External procedure and we can execute those by running procedures persistently and calling that procedure IN that persistent procedure.

So may I assume that choosing between Sub - Procedures and Functions depends upon individual interest?
 

GregTomkins

Active Member
I'm tempted to get into a debate about Super Procedures and libraries and so on... but I suppose I should do some real work. Anyway, I think what you said is a fair statement. Basically, functions vs. internal procedures is mostly a matter of style and preference. Both can be used in bad ways and both can be just fine.
 
Top