Ask your own question, for FREE!
Computer Science 14 Online
OpenStudy (anonymous):

Use of global variables to pass information between functions does not affect portability since we can just copy the global variables accoss to any program that uses the functions. Is this true or false? Please help to clarify thanks.

OpenStudy (anonymous):

This should be fine as long as you copy the globals, depending on the language you can also choose to pass the variable into the function to modify it there, (in python you would want to return the modifyed variable and assign it from there.

OpenStudy (farmdawgnation):

I would disagree with this statement. Using global variables does affect portability because it means there are certain assumptions about the environment surrounding the function. Specifically, that the global variable you want to use isn't going to be used by another suite of functions. So, the developer using your code installes your package into his project and some package from Acme Widgets Inc, and if the Acme package uses the same global variables as you - well... that developer isn't going to be too thrilled because neither your package or the Acme package will work as expected. All in all, globals are bad. You should, whenever possible, pass in everything the function is going to need and pass out everything it needs to communicate.

OpenStudy (anonymous):

Global variables also cause problems on the compiler's side, particularly symbol tables in syntax analyzers.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!