Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

12
  • 17
    I think that passing a context object either by function parameter or dependency injection would cause problems if the context is mutable, same problem as using mutable global state. Commented May 11, 2012 at 16:34
  • 2
    All good stuff, and amen! But the question is about immutable global state Commented May 11, 2012 at 19:26
  • 4
    +1 for mutable/immutable. Immutable globals are ok. Even ones that are lazy loaded but never change. Of course, don't expose global variables, but a global interface or API. Commented Mar 7, 2014 at 19:30
  • 1
    @MarkJ: I cannot find the word immutable in the question, and there is no such thing as "immutable state": as soon as something is immutable, it is a constant and does not model any state. Maybe you meant global constants? Commented Mar 22, 2014 at 13:12
  • 2
    @giorgio The question makes it clear that the variables in question get their values at startup and never change afterwards during program execution (system folders, database credentials). I.e. immutable, it does not change once it has been given a value. Personally I also use the word "state" because it can be different from one execution to another, or on a different machine. There may be better words. Commented Mar 22, 2014 at 14:47