Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
best programming techniques
#1
I want your opinion on what I believe to be the best programming techniques [in qb] memory wise, especially for larger programs. I learned a lot from Nathan's tutorial http://www.geocities.com/na_th_an_wopr2k/limits.txt

My beliefs now are:
Don't use COMMON. It uses a lot of memory since the variable always exists. Instead, use modifiers and observers (read tut), or pass variables to routines as parameters. Avoid DIM SHARED since you can use SHARED alone within a routines, which will erase the variable from memory when the routine is done. When possible, use REDIM for large arrays and then ERASE them when their use has completed for the time.

Any corrections? Further enlightenment?
__________________________________

Mr Toad
Blue Castle Productions
Reply
#2
Well, at least it is my coding style, and it works for me. I am not saying it is the best. I only wanted do make some advices, may you take them or not Smile.

Now Mr Toad and I have almost the same project organizing techniques Wink - Thanks for reading the article.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#3
well, i want what's best. a lot of your technique is good, but i recently got some replies on neobasic that implies COMMON variables don't use more memory, and there is a way to use them efficiently.

http://www.neozones.com/Board/Messages/37802.shtml

everyone's got something to say about it... Big Grin
__________________________________

Mr Toad
Blue Castle Productions
Reply
#4
if you use local variables and keep reddiming them a large amount, you're losing time. (than if you had just stuck to global)

Right?
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#5
losing time? you mean program speed? or coding time?

I think if COMMON is used correctly, you can save yourself coding time. I think that's what you mean. But for arrays and stuff that are really big, and not constantly being used in the code, those should be erased and redimmed when possible so they aren't always hogging that memory but only for a brief moment instead.
__________________________________

Mr Toad
Blue Castle Productions
Reply
#6
Avoid blanket rules.
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Reply
#7
One of the main reason that globals are discouraged in programming practice is because they lack protection in large projects.

If you create a global variable then potentially any function or module has access to it and can change it at will, this is generally a bad thing (ignoring Glenn's blanket rule ;-)) because in a largish project it can become difficult to tell when and what changed the value of a global.

By having local variables and passing them as parameters to functions you limit this problem because only functions which you pass the variable to are able to modify it. You can also more easily add checking code for illegal/invalid values in each of the functions.
Some programming languages provide extra protection mechanisms for global and local variables (like the public, private and protected keywords in Java, which allow variables to be made global to a file, a package or everything).

Basically its a design decision as to what variables you want to make global and which ones to keep local and pass as arguments. If a variable (or array/structure/whatever) may need to be accessed from just about anywhere in a file, its probably not a bad idea to make it global, for instance a player structure in a game. If a variable only has a limited scope its probably better to pass it around as an argument, this would be useful for say the players weapon structure which is only needed by a few combat functions.

The program speed versus coding time is a good issue as well, if it really matters go for program speed (although nowdays the big push is towards coding time, because computers are always getting faster). Remember to add debugging time to that list, global variables could be faster to code and execute but if they take hours to find and debug problems with them, it may not be worth it.

All in all, take Glenn's advice, there is no blanket rule for variable scope, it depends entirely on the situation at hand.
esus saves.... Passes to Moses, shoots, he scores!
Reply
#8
Quote:well, i want what's best. a lot of your technique is good, but i recently got some replies on neobasic that implies COMMON variables don't use more memory, and there is a way to use them efficiently.

http://www.neozones.com/Board/Messages/37802.shtml

everyone's got something to say about it... Big Grin

My point was not that common variables used more memory, but that they used memory at any time - and I dislike them for that reason, being a "free-memory-freak" Smile
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#9
Yah, Na_th_an i'm the same way Tongue

Caboose, thanks for the interesting info. Smile It does dependon the situation, so a few globals in my case would be helpful... but not so many as i once had.
__________________________________

Mr Toad
Blue Castle Productions
Reply
#10
Um, I meant programming speed. I don't think the coding speed changes at all in QBASIC, since it is easy to find where the variables are, even if they're in subs, and if you know and remember what should be where.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)