Back in 2019, I switched to C (from C++, with experience in many languages). I did this in order to get better at computer science, and gain knowledge that would apply to my programming, whichever languages I ended up using in future. Over the years since then, I’ve run into various problems with C, and found my preferred ways of programming. Things like tagged unions, fat pointers, error handling, etc.
I’ve also had an interest in Zig during that time, and I’ve occasionally taken a look to see how Zig handles the things I find painful in C. Consistently, the Zig team has already solved the problem in exactly the way I would want, or in an even better way than I had thought of! However, there was one decision I didn’t like: removing @usingnamespace. As a game programmer, I often want to have the same types and basic functions available in the global namespace across many files. I can accept one wart on an otherwise brilliant language, but in my dissatisfaction, I decided to read through the git issue regarding this removal.
And, I must admit, the Zig team was right!
I read through the reasoning around the issue, and while the functionality of @usingnamespace was nice, I don’t think it’s worth having invisible declarations - that is, declarations present in the file’s namespace, with no hints about where they’re from. Let’s say the “bob.zig” namespace has a “jim” declaration. When you open bob.zig and CTRL+F “jim”, nothing comes up. Now you have to check every instance of @usingnamespace, which could be arbitrarily many files deep!
With the cost being greater than the benefit, I think a jankier solution to this problem is preferable. Either:
- Just make a short namespace for these things.
- Copy-paste the declarations to the bottom of the file, possibly with a nice big comment at the beginning and end to make it easy to search for and replace when the source declarations change.
All this is to say: even when the Zig team makes what I think is the wrong decision, they’re probably making the right decision.
Thanks Zig team!
PS: Sorry for the odd choice of category; I didn’t see one that fit better.