I suppose it depends on your programming ethics when deciding which to use.
As an old-school programmer for over 35 years, I started when only low-level programming languages were available and when BASIC did appear on home computers it only had
Goto LineNum and nothing else. Over the years I've watched as subroutines and functions were introduced to make life easier.
I believe that you choose which one to use on a 'best-suited' basis.
As has already been said, subroutines are faster, but not enough to be of any consequence, so speed doesn't really come into the decision.
Subroutines were designed to take sections of code which are used multiple times in your program and put them in one place, using them as many times as you wish. All variables in your main program are accessible and can be changed without having to specifically create global variables.
Functions on the other hand were designed to calculate a single result from a number of parameters in a 'protected' section of memory using local variables. On exit from a function, a single value is returned and all used variables destroyed.
Think of the hundreds of functions supplied with DB - those in the help files which use the '()' open/close parenthesis symbols. Every single one of them return just a single value - no more and no less.
Ever asked yourself why there's no Get Object Position XYZ() function to get all three values at once instead of having separate functions for all three?
So, I personally would only use functions for anything which needs to make changes to just a single item and subroutines for everything else.
On occasions I will also use a function which would normally be a subroutine - if the code was written for someone else (as functions can be written as self-contained entities) or I want to call the code in an If..Then statement.
At the end of the day though, it doesn't really matter which you use. I personally wouldn't use
only functions for absolutely everything in my programs as the advantages are no greater than the disadvantages. I accept that some do though - it's a personal choice.
Quote: "Another important thing to remember about Functions is that they allow you to build up a useful library of code snippets that you can use time and time again, saving you lots of work!"
That's not really an advantage of functions over subroutines as the same is true of both in an include file. (When a DB program is compiled, everything in #Include files is tagged on the end of the main program so subroutines are no different to functions in this respect).
TDK