Issue with cyclic Import statements

BlitzMax Forums/BlitzMax Programming/Issue with cyclic Import statements

Hi,

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!