Extended Types and Globals

Previous topic - Next topic

bigsofty

Hi,

Just messing around with the extended types. A feature came to mind that I think would be beneficial for using extended types. Static global variables within extended types.

If an extended type has a variable, say X, then each instance of that extended type has a unique variable X.

If there was method of telling the compiler to create only one instance of a variable and share it between all the instances of the type it was defined in, then this would allow for the information to be shared within the type.

So...


Code (glbasic) Select
TYPE myType
   GLOBAL a
ENDTYPE

x1 as myType
x2 as myType

x2.a = 1
x1.a = 100

DEBUG "myType 'a' = " + x2


Result is "myType 'a' = 100"

Not a great example I know. :P

This is a similar method to BlitzMax I think.

This would remove the need for external global variables for types, making them more modular and  a bit easier to control IMHO.

Many thanks,


Ian
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

MrTAToad

I dont see it being useful myself. If you want to get rid of globals, you would put the variable in the type where it will be used or in a base type which will then be used by other types.

bigsofty

I don't want to define external globals that are only used within a certain type. This is quite a common syntax feature of many languages.

Its not essential though as it can easily be worked around if need be.

Cheers,


Ian
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)