Dependency Injection in MediaWiki

Today I read the documentation for how Dependency Injection is done in MediaWiki.

I had a few small nits to pick (such as their statement that services should be stateless) but… fair enough.

For myself I don’t usually use Dependency Injection and a Service Container, instead I prefer the Service Locator pattern which I find is simpler and more economical to use, especially in PHP where there is a single process per request.

Extreme late binding

There’s a famous quote from Alan Kay that you will see bandied about:

OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things.

I think I agree with him, but I often find myself wondering quite what he meant by “extreme late-binding”. I suspect he means that object instances can redefine stuff they inherited from their concrete class. If your OOP platform doesn’t support that, you can emulate it with data and API.

ChatGPT for the day

ChatGPT 4:

User: explain profundity

ChatGPT:

Profundity refers to a state of being deep in thought or insight. It’s often associated with ideas, thoughts, or expressions that have significant depth of meaning, understanding, or insight. Profundity can apply to various contexts, including intellectual discussions, philosophical concepts, artistic works, and emotional experiences. When something is described as profound, it usually means it has a deep impact, is very thoughtful, or offers substantial wisdom or insight. Profundity involves layers of meaning that may not be immediately apparent and often requires contemplation or reflection to fully appreciate.

Context object versus global variables

I’m reading A Philosophy of Software Design by John Ousterhout and he says:

The context object unifies the handling of all system-global information and eliminates the need for pass-through variables. If a new variable needs to be added, it can be added to the context object; no existing code is affected except for the constructor and destructor for the context. The context makes it easy to identify and manage the global state of the system, since it is all stored in one place. The context is also convenient for testing: test code can change the global configuration of the application by modifying fields in the context. It would be much more difficult to implement such changes if the system used pass-through variables.

Contexts are far from an ideal solution. The variables stored in a context have most of the disadvantages of global variables; for example, it may not be obvious why a particular variable is present, or where it is used. Without discipline, a context can turn into a huge grab-bag of data that creates nonobvious dependencies throughout the system. Contexts may also create thread-safety issues; the best way to avoid problems is for variables in a context to be immutable. Unfortunately, I haven’t found a better solution than contexts.

Okay, so I’m just gonna step way out of line over here and suggest something heretical… but shouldn’t you just use global variables? You only introduced the context object so you could tweak it in unit tests, and you could just change your tests so that each one ran in a new process. Just sayin’.

…I suppose for the sake of completeness I should add a little more from Ousterhout which he said prior to the above:

Another approach is to store the information in a global variable, as in Figure 7.2(c). This avoids the need to pass the information from method to method, but global variables almost always create other problems. For example, global variables make it impossible to create two independent instances of the same system in the same process, since accesses to the global variables will conflict. It may seem unlikely that you would need multiple instances in production, but they are often useful in testing.

…so he is bending over backward to support multiple tests in one process, but he could just run each test in its own process and his problem evaporates.

Large Language Models and The End of Programming – CS50 Tech Talk with Dr. Matt Welsh

Here’s an interesting talk about how we won’t need programmers very soon: Large Language Models and The End of Programming – CS50 Tech Talk with Dr. Matt Welsh.

If refers to the following books:

The Divided Brain

Here is a presentation of the work of Iain McGilchrist: The Divided Brain.

McGilchrist has written a number of books, including:

Stolen Focus

I have finished reading Stolen Focus by Johann Hari (affiliate link).

I went into this book much more worried about the state of attention in our communities than I was when I came out. Having read about it I kinda don’t feel that we really do have an urgent problem with so many people on earth being constantly engaged with their smart phones.

I might have trouble now starting a conversation with a family member because they are engrossed in their phone, and I might think this is new or different, but thirty years ago it would have been the same thing if they had their nose in a book or a newspaper.

I think by and large it’s good when we’re paying attention to things and engaging with them. That’s not only how entertainment gets done, that is also how work gets done.

I suspect one of the driving forces behind the surge in ADHD diagnoses (and Hari didn’t say this) is that people are getting the diagnosis deliberately because they want access to prescription amphetamines.

Anyway. I would still recommend reading this book. Hari does a good job of covering all the bases and investigating all the topics, including:

  • context switching and its effects
  • effects on flow
  • physical and mental exhaustion
  • sustained reading
  • mind wandering
  • tracking and manipulation
  • stress and its triggers
  • diet and pollution
  • ADHD
  • physical and psychological confinement