INCLUDE question

BlitzMax Forums/BlitzMax Programming/INCLUDE question

Robby(Posted 2012) [#1]
Hi guys! I had a quick question. My current project is getting pretty big, and I'm worried if Blitz has some sort of max to the code put in one module? My set up right now is that I have all my Global definitions in a module, and all my DefData statements in another.

Then I have the main module which includes these in the places they would have been put in the code. This module contains some set up information, my main loop, and a bunch of functions. its this one that's getting big.

I had tried to split some of it to other modules and got some errors - like object not defined, etc.

So I'm wondering if there are some rules of thumb I should know about what can and cannot be put into a separate module and included in the main module? Any tips on this would be appreciated! -Rob


Midimaster(Posted 2012) [#2]
a easy way is to use INCLUDE:

main code: MAIN.BMX
SuperStrict
Include "Second.bmx"
Print Test
Print AddSomething(Test,5)


second module SECOND.BMX
Global Test%=5

Function AddSomething%(A%,B%)
        Return (A+B)
End Function



matibee(Posted 2012) [#3]
I can't help you arrange your code obviously without seeing it, but here are the reasons for splitting code across multiple files;

Code reuse.
Having a single type (or related set of types) in a single file helps you use them in multiple projects.

Organisation
Being able to locate a specific type or function quickly really helps as projects grow.

Compile times
Most languages go through a process of compiling and linking and Blitzmax is the same. Files not edited since the last build won't have to go through the compilation process. This can be a massive time saver even on medium sized projects. That's what the quick-build option does in the IDE.

The hardest part for any coder is making truely standalone functions and types, and its even more difficult refactoring code that wasn't written with that methodology in mind.

But my advice is to start small, for example if you've got several types that have X and Y fields change them for a Position, or even a Vector2D type that exists in its own source file.

But don't be concerned about any Blitzmax or IDE limitations.


Robby(Posted 2012) [#4]
Hi guys! Wanted to get back to this sooner. It was a me <-- DUH thing.
I didn't realize I was running the separate modules instead of the main one with the includes, so of course there would be errors if referencing like globals not included, etc. Typical and silly over-sight.

But you're absolutely right, matibee, making truly stand alone functions is indeed tricky, but done properly, one can see the advantages in future coding and projects in how the code can be reused.