Why are allocator interfaces and implementations split across `std.mem` / `std.heap`, while IO is colocated under `std.Io`?

I’d be a bit more in favor of std.alloc. It’s an abbreviation, but so is std.mem.

Although the standard library is moving more toward “fat types”, Io being the prime example, by which I mean: containers which can be instantiated, but also have a whole namespace of other goodies, I’m not convinced this is the best way to do it.

When you look at the docs for std, there’s a bunch of types at the top, and a bunch of namespaces below it. Some of the types are just types: if you click on ArrayList, that’s all you’re going to find, a function called ArrayList which does what you think.

Click on Thread, though, that being the longstanding example, and there’s lots of stuff in it: Mutex, Condition, and so on. Granted that they’re all topical, there’s not much point in having Mutex if your code doesn’t use Thread.

But the distinction I’m referring to is not visible. Which types are fat and which are skinny is guesswork. That makes std less discoverable, I wrestled with this a lot when I was learning the language.

I would go so far as to have std expose no capital-letter types at all, in fact. Pure lowercase namespace, so std.thread.Thread, std.thread.Mutex, std.alloc.Allocator, std.io.Io, and so on.

Instantiable types within instantiable types is fine, those should be return values or otherwise components of the type which they inhabit. So std.io.Io.VTable, not std.io.VTable, for instance. But back to std.io.File.

“None at all” is going too far, actually. std.option.Option would be a waste of a level. But so many things come in two flavors due to alignment, or four due to auto: I count fourteen types which could all go in std.map, and I think that would be nicer, especially for beginners. Could be fifteen, I’d put EnumMap in std.enum though. Definitely think everything should have one home in the standard library, it could be put in two places but… let’s not do that.

Now, this is a big change, and I have quite a bit of code which would need to be extensively modified in bouts of pure busywork. Many of us do, I nonetheless believe that it would make std much easier to learn, and that would be worthwhile.

10 Likes