Gosub for a procedural call?

Blitz3D Forums/Blitz3D Beginners Area/Gosub for a procedural call?

Gladen(Posted 2006) [#1]
OK, I'm probably just an idiot that cannot see the basics of a basic oriented language, but...
I'm very used to writing low-level code that is generally organized in sub-routines such as Procedures for generalized tasks and functions for tasks that manipulate data.

Well functions are there in the coding language, and work exactly like functions do for any programming language, but I cannot see any evidence of procedures.

Am I correct in assuming that I could use a GOSUB for basic procedures, or is it better / faster to use a function for my procedural calls and simply pass null variables through?


big10p(Posted 2006) [#2]
Just use functions. You don't have to pass any parameters to a function, so there's no need to pass in 'null' ones.


Stevie G(Posted 2006) [#3]
No reason why you can't use gosub for your procedures and it will be faster that using a function with null parameters. The time difference will be unnoticable unless you're making thousands of calls to it in the main loop.

IMHO, using function makes your code more readable and better structured - hence I avoid gosubs like the plague.

Stevie


Gladen(Posted 2006) [#4]
Thanks. So either way will actually work. I just like to have all my calculations and events set into their own little areas of the program. that way my main loop is always short and logical. If I ever want to change a thing, or have a problem with a section I know exactly where it is.


Nicstt(Posted 2006) [#5]
Personally I write as much as possible in funtions, once it works i copy it to another file and then include it eg:

Include "Function Check Place.bb"
Include "Function Letters.bb"
Include "Function Board Setup.bb"
Include "Function Scoring.bb"
Include "Function Time & Player Change.bb"
Include "Function Start Options.bb"
Include "Function Comp Setup.bb"

Same can be done with gosub, however I try to limit global variables as much as possible. I find it helps with debugging knowing that a problem is situated in a certain place.:D

(of course, this knowing has got me into trouble a time or two /sigh)