The thing is, you need to have a balance of both procedures and functions in your programs. Use functions when you need them and procedures the rest of the time.
There are no real benefits speed-wise to either of them and they both do pretty much the same thing in slightly different ways.
A program which uses all procedures and no functions is OK. A program which uses all functions and no procedures is not so OK...
In my opinion, functions are more restrictive and less flexible than procedures - but please don't read that as saying 'not as good'.
For a start, in DBC, every variable you use in your main program cannot be seen inside a function so you have to pass a list of those you want to use in the function. Procedures however can see them already.
Likewise, everything you calculate inside a function cannot be seen by the main program, so you have to pass the result back. But you can only pass a single variable back (unless you use arrays which due only to a quirk in DBC act as global variables - if they worked as they should you wouldn't be able to do this).
With procedures, the main program can see any changes made to any variables in the procedure.
It sounds like I'm a bit anti-function, but that's not the case.
They can be very useful and allow you to do something that you can't do with procedures - create new commands. And to be honest, that's only because of the way that functions are called.
The DB command RGB() is a function. Three parameters are passed to it (the red, green and blue colour values) and one parameter is returned - the colour value.
If you need a single value calculating in this way then a function is what you need. And, as previously mentioned, the function can be used just like a native DB command.
If you create a function called MyFunc() you can use:
Print MyFunc(X,Y,Z)
just like you would:
Print RGB(128,128,128)
At the end of the day, local variables aside, there's nothing you can do
inside a function that you can't do inside a procedure.
So, if you need to access or alter lots of main program variables then a procedure is probably better than a function.
If you need local variables which won't affect those with the same name in your main program and calculate just a single result then a function is better.
And one final thing in favour of functions... #Include files are meant only to include functions, so if you want to build libraries of often used code and place them in external files then they should be written as functions.
TDK_Man