Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
Global variables make the code hard to reason about This is especially visible when debugging. Say you have a function which errors. The stacktrace tells you where the function got it's arguments,...
Answer
#1: Initial revision
# Global variables make the code hard to reason about This is especially visible when debugging. Say you have a function which errors. The stacktrace tells you where the function got it's arguments, *but not who last modified the global variables it might have read*. They could have been modified literally anywhere in the program, perhaps asynchronously. Reconstructing the chain of events that led to this particular errorous state may be next to impossible. Use function arguments for passing everything. Keep your functions [refenrentially transparent](https://en.wikipedia.org/wiki/Referential_transparency). I.e. the same arguments should always produce the same output. (I recommend looking into functional programing more broadly too while you're at it.)