I personally use sub routines to break up tasks in my program flow.
I use functions for repeated calculations that are required for more than just one task.
sometimes you will have variables that permanently exist and change, subroutines will work well with these as changes in their data will be preserved.
Functions have self contained variables which can be nice if you to repeatedly use the same variables but do not wish to leave them with values in them. eg x y z co-ordinates of objects.
you could declare your variables as global. That way the values altered within the global variable will remain after it has completed rather than being deleted upon function completed.
eg. my screen setup sequence is a subroutine. It is only performed once at the start of the program.
Then I might load my images, this will be specific to this program and values will be required globally = subroutine.
Then i might set up my sky, which is performed once and required variables to exist during program execution - this will be a subroutine
Then I might set up my terrain. -this is a common setup function which i will use in a lot of programs. the textures and object number will be different each time. - this will be a function
mouselook using collision object - again common routine with variables-my object number may be different each program so it is a function
so my program flow would look like this.
gosub setup_screen
gosub load_images
gosub setup_sky
setup_terrain(Terrainno,heightmap,texture,scale,posx#,posy#,posz#)
`_____________________________________________________________________________
do
mouselook(collisionobject)
sync
loop
end
`_____________________________________________________________________________
setup_screen:
general setup tasks
return
load_images:
load image commands
return
setup_sky:
setup components of sky
return
`______________________________________________________________________________
function setup_terrain(Terrainno,heightmap,texture,scale,posx#,posy#,posz#)
setup terrain commands
if terrain exists then success = 1
endfunction success
function mouselook(objectno)
perform mouselook operations
endfunction
you can see that my program flow is readable in plain english. This is important for productivity and debugging.
It wont always be possible for it to be so straight forward as your program becomes more complex, however it is good to try and keep it readable.
I find that using subroutines to break up chunks of code helps with readability.
I find that if I need a certain routine in more than one program and it requires variables then a function is called for.
This is just the way I use them.
so far as your program order is concerned, I think when the code is compiled the compiler tags your included files onto the end of the first pages code, so the include command may indeed work anywhere, however for readability sake I would always put includes at the top.
the same with gobal declarations. you don't want to go wading through pages of code to find where you left that global declaration.
in my case I would make a subroutine to house the global declarations - however I use indigo and it has a feature that allows to you select a routine or function from a dropdown menu and takes you right there, very nice feature says I.
That's how I go about things anyway.
Ok, Jokes over, No more eye burn.