Skip to content
DevMeme
3017 of 7435
The Only Good Global Variable Is a Commented-Out One
CodeQuality Post #3332, on Jun 25, 2021 in TG

The Only Good Global Variable Is a Commented-Out One

Description

This image is a screenshot of a tweet by a user named Richard (@zzaaho). The tweet is structured as a simple Q&A. The question is, 'Q: What is the best prefix for global variables?'. The answer provided is, 'A: //'. This is a highly technical and witty joke for experienced developers. Global variables are generally considered bad practice in software engineering because they can be accessed and modified from anywhere in a codebase, leading to unpredictable behavior, hidden dependencies, and debugging nightmares. The joke's punchline, '//', is the syntax for a single-line comment in many popular programming languages (like C++, Java, C#, and JavaScript). Therefore, the 'best prefix' for a global variable is to turn it into a comment, effectively advising against its use altogether. The humor resonates with senior developers who have experienced the pain caused by global state

Comments

17
Anonymous ★ Top Pick Global variables are like public restrooms. They're convenient when you need one, but you never know who used it before you or what state they left it in
  1. Anonymous ★ Top Pick

    Global variables are like public restrooms. They're convenient when you need one, but you never know who used it before you or what state they left it in

  2. Anonymous

    Our coding standard says every global must start with “//” - it keeps the linter silent, the architect’s blood pressure stable, and reminds future archaeologists that even our singletons didn’t deserve runtime

  3. Anonymous

    The same architect who insists on proper dependency injection will defend that one global config object like it's their firstborn child

  4. Anonymous

    The real tragedy isn't that global variables exist - it's that after 15 years of architecture reviews, you still find them lurking in production code like undocumented legacy endpoints. At least with '//' you're being honest about their lifecycle: deprecated on arrival, yet somehow still in the codebase during the next major refactor

  5. Anonymous

    Globals: the shared mutable state that haunts multithreaded monoliths, best exorcised with a // prefix

  6. Anonymous

    Globals are a distributed cache with no TTL - choose //, or choose on-call

  7. Anonymous

    Best prefix for global variables? // - restores referential transparency and lets on-call sleep

  8. @sylfn 5y

    Python programmers: I think it isn't

    1. @VlP_AI_TG 5y

      And Ruby

  9. Deleted Account 5y

    Or /* if you like to break things

    1. @azizhakberdiev 5y

      The best prefix for the whole shitty code

      1. Deleted Account 5y

        Yes

  10. @maxgraey 5y

    dont_use_or_you_will_be_fired_

  11. @dsmagikswsa 5y

    What is the correct answer then? LOL

  12. @misesOnWheels 5y

    writes shitty, buggy code of course it's those pesky global variables

  13. @ZgGPuo8dZef58K6hxxGVj3Z2 5y

    😂😂😂😂😂😂 Or /**/

    1. @affirvega 5y

      /**/ float g_globalVariable = 1.0f; xD

Use J and K for navigation