Splitting projects into multiple files

BlitzMax Forums/BlitzMax Beginners Area/Splitting projects into multiple files

abelian_grape(Posted 2010) [#1]
Hi all,

So now that I've begun working on a new project, and after the debacle of my last project, I thought that perhaps it would be helpful to split my project up into more manageable pieces rather than some interminable main file. My last project was done entirely in one source file, and was generally unorganized. Being my first real project it was pieced together as I thought of things and made to work piece-by-piece, rather than outlining the project and writing abstract code that could handle my tasks, only to later be dressed up by specifics to the game.

It was a huge pain having to do a "Find" string constantly when I wanted to edit a block of code in a huge source file. I was wondering: how does one use things like header files in BlitzMax IDE properly (including them, what goes in them, etc.) and in general how do you split your code up to make it more manageable? I would really like to make this project as organized and lucid as possible, and I think having header files, source files, etc. will aid in this.

-muffins


CS_TBL(Posted 2010) [#2]
My latest project is an editor of 3200+ lines, all in one file, nothing included. The code tree in maxIDE is enough for me to quickly move around. It depends on the amount of lines and/or the structure of your code and/or the amount of types. In my case I had around 4 large types and nothing more worth mentioning. These types are around 600-1000 lines each, so that's already rather big

But if you really want to split up your code, then I'd make a file per type, including related things like globals, instance create functions, user event definitions etc.) I would also make an include file for global functions.

You could at least try it, but in a way there's little difference between clicking a type in the code tree and clicking a file tab. An advantage of tabs is that you can keep the focus on a certain line in tabs while working in another tab, but I'm not sure how often this situation happens..


plash(Posted 2010) [#3]
If you're writing a big project with an object oriented approach you'll easily get flooded with a big, unmanageable, pile of files (if you separate code per type).
You should separate code into topics/related groups. I would also recommend writing modules (with documentation) out of the code that is general (if it can be used on multiple projects without (much) modification).


CS_TBL(Posted 2010) [#4]
An IDE with code folding may also help while keeping everything in one file.


Xerra(Posted 2010) [#5]
I would kill for code folding in the community editor. I really would :(


Czar Flavius(Posted 2010) [#6]
If you are in Windows, look into using the Blide editor. It's much easier to manage a large project in. Personally I have each Type in its own file, a misc file with various handy functions, a load file which contains startup code and a main file which contains the main game loop.


beanage(Posted 2010) [#7]
If you are in Windows, look into using the Blide editor.

Let me add some emphasis to that, Blide can REALLY enhance youre quality of life as a BlitzMax programmer. I'm telling from experience. Its just not comparable.. The managed projects, code folding, an advanced module builder, icon integration, dockable panels, online code analyzation, ....... its just comfortable! PLUS if you come to LUA scripting and/or programing in C/C++ Blide even works for these too! [Take a look at the free version: http://blide.org/index.php?section=getfree ]


abelian_grape(Posted 2010) [#8]
Wow! BLIde really is great. I honestly don't know how to use HALF its features (like the managed projects, since I only currently make one file programs, or the advanced module builder, etc.) but the code folding is really helpful once Types get lengthy. It's set up almost identically to Visual Studio 2005 which is what I used to program in, so I enjoy it very much. Thank you :)


Czar Flavius(Posted 2010) [#9]
A managed project just means all your includes and imports are handled automatically. Normally you will need to put Include "TPlayer.bmx" Include "TTile.bmx" etc on your main file. Now you just right click the program folder and click add new file or type and bam - ready to go.


abelian_grape(Posted 2010) [#10]
Ahh okay, well that is convenient. The only problem I'm having with BLIde is that it has to rebuild documentation each time it starts up...and I'm even running it as an administrator and Windows UAC is disabled, so I think it's complaining about the version of BlitzMax or that BlitzMax's documentation is not properly built. As a result, BlitzMax's commands/functions aren't being highlighted...commands/functions like Graphics, or AutoMidHandle, etc. Everything else is being recognized except the BlitzMax specific functions. Does anyone know of a way to fix this?


Czar Flavius(Posted 2010) [#11]
Click Modules and then click Advanced module builder. Select all the catagories and then click Document selected. Hopefully that should fix the problem.


abelian_grape(Posted 2010) [#12]
Apparently I have to have BLIde Plus in order to use the Advanced module builder...aye aye aye. :(


Glenn Dodd(Posted 2010) [#13]
But Blide Plus is very cheap for the power you receive.

Regards
Glenn


ziggy(Posted 2010) [#14]
@muffins: Be sure to be using latest BlitzMax. You can get latest version on the accout tab of the blitzbasic or blitzmax website. IF you're using a very old version of BlitzMax, the documentation build process can be not compatible with BLIde (as it was modified some versions ago).


GfK(Posted 2010) [#15]
Get BLIdePlus. You'll never go back. Think of it like.... oh I dunno... making the choice between investing in a hammer, or bashing nails in with your forehead. The latter will work but its a longer, more painful process.

My last project was ~30,000 lines of code with ~150 includes, and BLIde handled it all with ease.


CS_TBL(Posted 2010) [#16]
30,000? What kind of project was that?


GfK(Posted 2010) [#17]
Game - the one in my sig.


Czar Flavius(Posted 2010) [#18]
Match 3 games are getting so complex these days I fear they may develop sentience!


abelian_grape(Posted 2010) [#19]
@Czar: Seriously...nothing scarier to me than machines developing sentience. I hate robots.

@ziggy: Thanks for the tip. I checked and turns out I had BlitzMax v1.18, so I uninstalled it and updated to the newest version. BLIde starts up without any complaints now, thank you :)

@everyone else: Honestly, if I were able to take advantage of everything BLIde Plus had to offer, I would just shell out the cash for it. I've only programmed one full game, I'm working on my second, as well as a map editor tool for that game, so I am still quite a newbie when it comes to BlitzMax. Once I become a cracker-jack programmer like you guys, I will invest in tools that are useful to people who are really good at what they do. As a novice, I can't justify it at this point.

Thanks again to all for the help! :)

-muffins


ziggy(Posted 2010) [#20]
Honestly, if I were able to take advantage of everything BLIde Plus had to offer, I would just shell out the cash for it. I've only programmed one full game, I'm working on my second, as well as a map editor tool for that game, so I am still quite a newbie when it comes to BlitzMax. Once I become a cracker-jack programmer like you guys, I will invest in tools that are useful to people who are really good at what they do. As a novice, I can't justify it at this point.
Then, if you like it, BLIde Free Edition is for you, and it's free :D


abelian_grape(Posted 2010) [#21]
A managed project just means all your includes and imports are handled automatically. Normally you will need to put Include "TPlayer.bmx" Include "TTile.bmx" etc on your main file. Now you just right click the program folder and click add new file or type and bam - ready to go.


I created a new solution, then took the main source code file that I had been using, and cut and pasted sections into multiple files to make things easier to manage. I split it into four files:

Variables (all of my variable declarations)
Types (all type declarations)
Main (main game loop)
Functions (all function declarations)

I then made the Main file the entry point for the solution, and at the top of the Main file, I put
Include "Variables.bmx"
Include "Types.bmx"
Include "Functions.bmx"

and the debugger yells at me. It compiles just fine when not split up into separate files so I am doing something wrong either by using Include improperly or missing key things in my files. Can anyone think of a reason this is not working? This is all part of an unmanaged solution, by the way.

-muffins


Jaydubeww(Posted 2010) [#22]
You could try and put "public" at the top of each of your include files. Although according to bmx documentation, this is default. Second, I'm assuming your included files are in in same directory as your main.bmx? Because you didnt give a url to them. Last, I DONT think this is the issue, but are the included files first letter actually capitalized?


Czar Flavius(Posted 2010) [#23]
Taking an existing project and rearranging its structure usually results in a lot of headaches - it's easier to simply start again.

Splitting your program into types of code such as variables and functions might seem natural but it doesn't really provide much benefit. How is mixing graphics functions with logic functions, and putting the graphics variables in another file, meant to help? :P It's much better to split your program into different catagories of concepts. I personally put each Type in its own file, have a misc file for functions that don't fit elsewhere (eg maths/file op), and a "main" file with the main game loop.


abelian_grape(Posted 2010) [#24]
@John: I did try putting public at the top of each of the includes, and I get the same result. All of the files are in the same directory, so there shouldn't be a problem there. And, indeed, all file names are spelled correctly with proper punctuation and capitalization.

@Czar: I will certainly try that approach with the next project, but I've come so far with this one (far for me, at least) that I would hate to scrap it and start again. For me, this method of organization splits the file up into chunks that make sense to me. While it may not be a huge time-saver, it helps me organize it this way so that I can quickly get to a type, function, variable, or main loop which are the 4 big things in this project. Your method of organization breaks these files down further and sorts them by their relevance (graphics, logic, maths, file op, etc.), so I will probably adopt that scheme. However, it is broken down further than what I have, and I still can't even get this method of organization to work :[


Czar Flavius(Posted 2010) [#25]
Perhaps one file relies on something defined in a later file?


ziggy(Posted 2010) [#26]
and the debugger yells at me. It compiles just fine when not split up into separate files so I am doing something wrong either by using Include improperly or missing key things in my files. Can anyone think of a reason this is not working? This is all part of an unmanaged solution, by the way.

How could the debugger yell? I mean if there's any issue with includes, the compiler (not de debuger) will show the errors. If it is a error at debug time I'm pretty sure it's not related to how you import things, but if we could have a detailed information of what is happening (wich erroes, when and under what circunstances) it will help a lot to find a solution!