I have over 50000 lines in over 400 source files- all written by me. OK, I borrowed an amount from some of the fine programmers that post code at the forum. That may be about 5% of the code. I can say that not one routine I got from there remained the same. Each is more polished and generalized as a function callable from wide a variety of applications.

General rules: Keep everything as self-contained as possible - pass very little in, pass out as small a thing as possible.
Moving data means copying many, many bytes. Once they arrive, they are only going to be discarded at the end. Both take time. Pass pointers: work can be done in-place. Better yet, pass a pointer to a generic UDT that can hold whatever you need for many functions. Common share the pointer to that one item. No bulk.

LOTS OF COMMENTS - the more comments, the easier it is to make this do what you want, and later, not break it.

Group functions together, even if it is only in the .bi declare file. Less handling for you. The linker will only include what you use, not what you declare. (The linker will complain if it can't find what is declared, even if not used.)

Any globals must have been declared to the compiler/linker, as well as any UDTs you use. If your globals and UDTs are declared in a separate file, then only that needs to be included at the top of the file, before the function. When you use a function from outside the library, it must be declared - ONLY. Put the declare at the top, above the function.


#include "myprogram_dim.bi"
#include "funct1.bi"

function mynewfunction(a as integer) as string
' this converts an integer to a trimmed string

dim sss as string

sss = trim(str(a))

return sss
end function ' mynewfunction

The sample in the wiki or help works. When it gets more complex, you have to do something different.

My setup would have, at least:

Main source - "myprogram.bas"
+#include "myprogram_dim.bi" - global dims only
+#include "funct1.bi" - declarations for functions

Lib:
"funct1.bas" - source file for the function
+#include "myprogram_dim.bi" - global dims only
+#include "funct1.bi" - declarations for functions - only needed if you refer to other functions in this library, or you overload this function.

Example here

home FB stuff