3 ms·
For many singletons it does not matter at all. E.g. 99% of all desktop gui programs and 99.9995% of games have a single main window by design - trying to abstra
by jcelerier 7y ago
For many singletons it does not matter at all. E.g. 99% of all desktop gui programs and 99.9995% of games have a single main window by design - trying to abstract that with an API that simulates that you could have more than one just makes the code harder to read for no benefit (as no widget system except beOS' can be used outside the main thread anyways)
- lmm 7y ago> E.g. 99% of all desktop gui programs and 99.9995% of games have a single main window by design - trying to abstract that with an API that simulates that you could have more than one just makes the code harder to read for no benefit Being able to test UI behaviour is a huge difference maker. (Also even if you do believe that a singleton is ok in this case, it's clearly no different from a global variable). > as no widget system except beOS' can be used outside the main thread anyways Which is a problem in itself.
- jcelerier 7y ago> Being able to test UI behaviour is a huge difference maker. obviously UI tests are being run today so this is not really an issue, right ? > (Also even if you do believe that a singleton is ok in this case, it's clearly no different from a global variable). yes, that's global state all the same > Which is a problem in itself. maybe, does not prevent writing a lot of very useful apps.
- lmm 7y ago> obviously UI tests are being run today so this is not really an issue, right ? UI tests are notoriously slow, flaky and generally worse than other kinds of tests. They're absolutely a significant pain point in software development today. > maybe, does not prevent writing a lot of very useful apps. People write useful code with global state. People wrote useful code with gotos, with no memory safety... that computers are useful does not mean there isn't plenty of room for improvement.
- kazinator 7y agoAvoiding singletons in the app implementation will not put a dent in UI testability. If you instantiate the MainWindow as a local variable in the top-level function, and pass that object everywhere it is required as an argument, external testing of your UI is not any easier.
- lmm 7y agoIt's a step in the right direction, and it gives some immediate value: you can see which functions don't actually need the MainWindow and can therefore be tested conventionally (you might argue that those were never actually UI tests, but in practice you'll end up using your UI testing techniques for things that don't actually use UI if you can't tell), and you're nudged towards only passing it where it's needed; also you could try to mock or stub it, which might cover at least some of the simple cases.