It's not forbidden, it's just usually a sign that a function should take a parameter and return a value instead. The example shows it so you understand what it does and can recognise it in other people's code.
Acceptable uses: small scripts, configuration that's set once at startup, simple counters in a quick tool.
Comments 4
Join the discussion CommentAlready have an account? Log in
It's not forbidden, it's just usually a sign that a function should take a parameter and return a value instead. The example shows it so you understand what it does and can recognise it in other people's code.
Acceptable uses: small scripts, configuration that's set once at startup, simple counters in a quick tool.
"Understand it so you can recognise it" — fair enough.
Bigger problem than global itself: functions that secretly change global state are hard to test.
When I refactored my first project, removing globals made half the bugs disappear.