Not really a bug report but rather a defect report, so to speak.
I don't understand why global variables inside types are restricted to constant values.
Global MyVar:MyType = New MyType compiles perfectly when outside of a type, but not within. Which can easily look inconsistent given that practically, putting a global variable inside a type affects only its scope.
This was for the "at first sight" side of things. Actually I do see the difference: when doing "Global MyVar:MyType = New MyType" at global scope we not only declare a variable, but also put a statement (MyVar = New MyType) in the main program code, *at the location of the declaration*.
When declaring a global variable inside a type, comes the question of where to put that "MyVar = New MyType" statement.
I'd like to advocate in putting it right before the type declaration.
That is
As long as it is clearly specified in the docs I can't see any problem with this solution.
A practical example of what it would allow:
I don't understand why global variables inside types are restricted to constant values.
Global MyVar:MyType = New MyType compiles perfectly when outside of a type, but not within. Which can easily look inconsistent given that practically, putting a global variable inside a type affects only its scope.
This was for the "at first sight" side of things. Actually I do see the difference: when doing "Global MyVar:MyType = New MyType" at global scope we not only declare a variable, but also put a statement (MyVar = New MyType) in the main program code, *at the location of the declaration*.
When declaring a global variable inside a type, comes the question of where to put that "MyVar = New MyType" statement.
I'd like to advocate in putting it right before the type declaration.
That is
Type MyType Global obj:MyType2 End Typeis equivalent to
Global obj:MyType2 Type MyType End TypeExcept of course for the fact that you'd still access it via MyType.obj and not just obj
As long as it is clearly specified in the docs I can't see any problem with this solution.
A practical example of what it would allow:
Type MyType Global g_List:TList = New TList Method New() g_List.AddLast(Self) End Method Method Delete() g_List.Remove(Self) End Method End TypeThat is, emulating the blitzbasic global list for a given class. Currently we are forced to put the global variable at the global scope, and to pollute the global namespace with something that should really be inside the the type. Or worse, always check inside the MyType instances if the list is allocated and if not do it.