"Jacob Read" <23*7*9*
6@s*u*e*t*u*a*e*u*a*> wrote:
> For project 1, would you rather we pass multiple pointers to all of our functions instead of using global variables, or are you ok with global variables if the scope of the variable is almost global or global. The pointers approach can obviously make code less readable and more complicated, and require the passing of arguments to functions when those arguments will always be the same, making the functions slightly less readable.
Hi Jacob,
I understand (most of) your question, but there's no general one-size-fits-all answer. The best choice is going to be specific for a particular program - number of variables and functions, required degree of sharing between functions and, if concerned about memory and execution time, how large is the global data, whether copies of the data must be made if passed or parameters, or whether you actually want to use pointers in your program.
Readability is certainly important but, of course, whether a program is less (or even more) readable if it uses pointers depends on who's reading the program. I've deliberately written the sample solution without pointers, to demonstrate (as claimed) that it can be done that way, and to not require students to use pointers. The result is many more global variables than I'd prefer to use, and I find it less readable.
I'm unsure what you meant by "...the variable is almost global or global". Almost global? Whether a variable is global or not refers to the lexical level where it is defined, either inside or outside of a function.