Solved

Is using global always bad?

NoahLoopsOP

Every forum says "don't use global". But the example teaches it. Mixed signals!

5

Comments 4

Join the discussion

Already have an account? Log in

  1. SophieDev Solutionreplies: 1

    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.

    8
    1. CharlieH

      Bigger problem than global itself: functions that secretly change global state are hard to test.

      2
      1. EmmaCodes

        When I refactored my first project, removing globals made half the bugs disappear.

        1