Re: Poll: global buffers (another long one)

From: Del (
Date: 07/21/01

With all the responses, several have stated that using global variables (or
other global stuff) is tought to be bad and lazy coding. Each comment
someone elses thoughts.
Ok, here is my thoughts on that. First off, I have noticed I have to pay more
attention to the globals and ensure I don't overwrite them. This does not
seem to be lazy coding on my part, since I have to pay more attention to what
I am doing.
Second, not all buffers are globals. Those 'general' buffers that
can be used throughout are used for general thing to fill a buffer and
send that buffer off (example, send_to_char). Being that global buffer is only
passing off the data to another function rather than holding the data for
another fuction!
Third, there has been mention that using globals takes up memory. DUH!!!
I can see if you declare a global and only use it once in a great while that
it would be a concern about it taking up space that other variables could be
using. However, in this case the global 'buf' is used over and over. It
appears to me to be a hell of a lot more efficient to declare it once and
be done with it, rather than delcare it over and over. Lets take a case of
several people fighting a mob. How many times is the hit function called?
When the functions send the fight messages to the characters, how often
would a local buffer be allocated and released? (hint: ALOT!) Now why would
this be considered bad coding to use a global in an instance like this?

Now I personally would have to disagree with those who have been told
that using globals is bad coding. It is bad coding if you do not use them
properly. I am not trying to say anyone out there is a 'bad' coder, but if
the coder does not pay attention to what he/she is doing with the globals
and why they declare them it can be bad coding. Just because the general
rule is not to do something, the more experinced coders will realize that
thier use can benefit thier code. I think the global buffers in Circle are
a perfect example of good use of them.
My only problem with them would be determining (in a long function with lots
of variables/buffers) which one is supposed to be used. But that is not
the fault of what buffer (global/local or typing in the right buf), it is my
own stupidity if I forget what I am doing or misstype it. So if there is a
problem with overwriting the buffer I can find out where the problem is fairly
quickly because I know where I was just working. Someone mentioned that
tracking down the problem would be difficult. It would be if you didn't test
your code before you committed your changes for good.
It all boils down to coding techniques! Do you pay attention to what you're
doing? Do you test fully your functions? Do you make backups?
Ok.. Sorry for it being so long, but some of the comments to me were
overrated and based on teachings and words of others.

   | FAQ: |
   | Archives: |

This archive was generated by hypermail 2b30 : 12/06/01 PST