I am writing app (not libary) so I don’t need generic struct or even in my situation several instances. I need just a singleton so are there any reasons (except obviously a feeling that it is wrong) to not just declare pub var ... and necessary functions in file and use it as singleton/global state?

pasta July 22, 2026, 5:35pm 2

Primarily - testing. Doing this can make it quite hard to write sensible tests.

Sze July 22, 2026, 5:45pm 3

My primary reason is that I hate singletons, because of years of being burned by them (both when I initially used them myself and then when others used them, but that was also in old c++ times which may have something to do with it…).

I find it preferable to just explicitly create your instance and use it, which is relatively simple in Zig and also has the benefit that you can more easily refactor stuff and understand the code.

I also think that the idea of “I only need one of these” often turns out to be a false assumption, right in the moment when you have written so much code that it becomes a pita to change it.