Global variables

The question: Would a global variable help?
My answer:

That’s the easy solution. And the when something is way too easy, it means that there is a tradeoff hiding back there.

When you have a small program of about 200 lines it’s ok to use a global variable. You know that this is a global variable, etc.
When you start writing some bigger projects, you will see that even you get fooled by what it is a global variable and which variable does it shadows, etc.

Imagine what will happen, when your projects are read/modified by at least two people. You will protect the others from ruining the code, you will save time and you will avoid chaos.

One can easily say: “Well, ok, let me use global variables now and when the time for BIG projects comes up, I will stop using them.”.
Let me give you an analogy to this:
Assume we have a runner, who when practicing, runs with his back turned to the direction he goes. Imagine how runners run and rotate that man by π (180 degrees), but let him run to the same direction.
His coach asks him, why do you do such thing? It’s easier for me, because it’s fun.
The coach tells him, that in the finals, he will have to run normally, like all the runners. And the runner says, well ok, let me run normally when the the finals come up.
When the finals come up, I do not think he is going to be ready for this.

Page created by G. (George) Samaras (DIT)

3 thoughts on “Global variables

  1. Pingback: Help with local char arrays and returning them to main

  2. Pingback: Array of structs(adding/deleting elements to a file)

  3. Pingback: help writing my first function one error in compiler

Leave a comment