Re: Re: Question regarding import, include and multiple files
Home › Forums › TimelineFX Module › Question regarding import, include and multiple files › Re: Re: Question regarding import, include and multiple files
imported_peterigz
I would just use include if you want to separate your types into separate files, that’s exactly what it’s for really. You can use import if the code you’re importing will compile on its own, but if you have types that reference other types and objects/variables in separate files then you will have to use include instead.
The only other thing about include is that you have to make sure you include files in the right order so that every object/variable that an included file needs has already been declared.
I found this thread on blitz forums where Mark Sibly explain cyclic issues best:
Import’s can not be cyclic, so you are correct in saying that 2 types cannot mutually refer to each other via imports.
The solution to this is simple, if initially a little scary: 2 types which mutually refer to each other must appear in the same source file. You can do this either by physically placing the source code for the types into the same source file, or by using Include to produce a logically ‘large’ source file from several smaller source files. Indeed, this is the *real* reason Include is in there!
In my opinion – and I know this will be contentious – not allowing Import cycles is actually a very good thing. It gives you a very clear dependancy tree and allows for perfectly predictable startup/initialization behaviour, as any Imports are *guaranteed* to be fully initialized (ie: their ‘main’ code has run and returned) by the time you’re initializing.
I have also found that it almost forces you into writer cleaner code, making you think about your file/object dependancies a bit more carefully and occasionally prodding you into a better design – but that may be my imagination!
Link to thread here: http://www.blitzbasic.com/Community/posts.php?topic=44108