Globals... What's Your Opinion...

Miscellaneous Forums/General Discussion/Globals... What's Your Opinion...

... on using em in Blitz3D?

a good thing... a bad thing... do they hurt performance any...

i have a feeling it would be best not to use em extensively, but i'm finding it necessary to make extensive use of globals in this project i'm working on...

what's your take on this...

thx


---Mike

I only use them in small projects, usually when I just want to put something together quickly for a single use. I doubt they hurt performance but they do make code very messy. They really hinder designing nice neat code that is easy to modify. If I do want to use globals I put them in a type called "GlobalType" or similar.

IIRC, when BlitzMax came out, people who were porting projects from B3D to BMax found that Globals were much slower in BMax, but locals were not. This would lead me to conclude that there is little or no optimization of local vs global variables in B3D, and thus there is no real penalty to using them.

With Blitz3D ... use 'em. With BlitzMax there's no real need if you're going OO. Globals are useful sometimes use them when you can't do it another way.

thx guys... strangely enough, i'm using nothing but globals in this OO_Blitz based game im working on...

--Mike

I use globals in blitzmax within the scope of a type. So are these really global, or in fact, local?

So are these really global, or in fact, local?


They're local Globals.

OEJ: well they won't sit in a CPU register for sure. I'd imagine they are the same as normal globals.

Yeah. Thats the problem with everyone panicing about using locals, it's all about how OFTEN they are going to be used in tight, intensive loops.

In fact my game's graphics are way more intensive than my logic anyway.

It's generally considered good programming practice to only give variables the scope they actually need. Making virtually everything global is probably not a great idea. However, Blitz3D has limitations that makes the use of globals necessary when they're not strictly needed - the lack of static variables (that retain their value between function calls) for one.

Sometimes GLobal vars are inevitable, but you know, if its global at least you have quick access to everything, no hundreds of gets and sets everywhere.

Best is to use whichever ones you need, locals are certainly an advantage in many cases, but in other cases globals are more usefull. Of course in a multi-programmer environment globals can be a problem and lead to all sorts of bugs.

I wish BP/B3D would let you pass-by-reference (pointers), which would for me, would make globals redundant.

Static variables would be nice too, for use in 'include.bb' files.

Though, I'll probably just have to keep on wishing! :)

Dabz