Import code mid Type ?
BlitzMax Forums/BlitzMax Beginners Area/Import code mid Type ?
| ||
Would it be possible to 'include' or 'import' additional functions and methods to a user-defined-type from an external source file? I.e. Without creating a new derived type? I have a large source file which I simply which to split up into groups of smaller and more manageable chunks, for example: Type TMine field a# Function Create:int() 'code here End Function 'THIS is what I'd like: Import MoreTMineFunctions.bmx Import MoreTMineMethods.bmx Import AndSoOn.bmx End Type Where one of these imported/included files, would for example contain additional functions or methods to the Type. Such as: Method Blah() '-- End Method I've tried the obvious hacks (using import/include), but the compiler won't take it -not surprisingly- but just checking if there's perhaps a way to do this?! Cheers, Danny Last edited 2011 |
| ||
Nope, without messing with the .o and .s files using some kind of voodoo magic which may/may not work, you'll have to use derived types. |
| ||
A preprocessor could combine the split files into a single file in a smart way and then pass only a single file to the compiler. Unfortunately no such program exists yet. Blide allows automatic use of a preprocessor I think. |
| ||
I think, if you have files of this size, IMHO it means that the class should be splitted on smaller classes. Having classes with thousands of source code lines usually increases the maintenance costs of the application, and it usually means "spagetty" code. Don't get me too seriously, but if you can reorganize the logic/design of the classes to make them smaller, it may make things easier for you in the long run. It does for me. |
| ||
what ^ ziggy said, but this is one method to do that: main.bmx: Include "test_foo.bmx" Type test Field a Method bar() Print "bar" a=100 End Method Method foo() _foo(Self) End Method End Type Local t:test = New test t.bar t.foo test_foo.bmx: Function _foo(t:test) Print "FOO" Print "A=" + t.a t.bar End Function |
| ||
Ok I understand the code now.. ^ Last edited 2011 Last edited 2011 |
| ||
lets ask big brother...... http://en.wikipedia.org/wiki/Foobar |
| ||
@All I hear what you're saying about spaghetti code, but that's not the situation / problem in my case. Actually, I don't have a problem at all :) I was just curious if it was was possible (without crazy hacks of course ;) and see if I might improve the readability of some of my larger source files (only 3K lines - half of which are empty lines or comments).. Cheers, D. |
| ||
Jesse, how did you know my question as I edited it right after posting? |
| ||
I have a large source file which I simply which to split up into groups of smaller and more manageable chunks I think where the problem arrises for most of us is that these "smaller and more manageable chunks" are calledf methods and functions.Lets say you have a function which is (for example) 8 screen hights long, a lot of ppl here would be tempted to say that this fuction is 8 times too long. There are two ways you can achieve what you asked, first you can take a block of your "Fuction" and sticl it into another function, which you call in its place. This has the mian problem that in Bmax without "Inline" you are going to get an additional over head. The other way, which Im surprised Ziggy didnt point out, is to use blide, and to fold bits of the code, (That is you still have say 20 lines but it displays as one) Last edited 2011 |
| ||
The other way, which Im surprised Ziggy didnt point out, is to use blide, and to fold bits of the code I was really tempted :D |
| ||
I am a faithful BLIde user (as I'm sure Ziggy knows ;) - and I make full use of collapsing code and other features to 'quickly go where I need to be'. But even with a great editor like that, structured code, functions neatly grouped and so on, when an app starts to grow bigger, navigating through dozens of sources files and hundreds of functions becomes a sport of its own ;) Sorry if my question was taken too heavily. I'm just cursing my fingers for never being fast enough to keep up with my crazy brain ;) Ironically, I'm working on a visual language and 3D framework to prevent many of the typical 'text based' coding problems and issues (incl. code navigation). Even though the visual language will be much faster to develop in than old fashioned text, I'm sure it will bring it's own quirks along ;) Cheers all, D. Last edited 2011 |