Why do we need to require certain stdlibs?


#1

Following #7487. “big” is understandable as it requires some C libs, AFAIK. But why do we need to explicitly require “json”, “yaml” and “uuid”? Why not require them automatically, as if we don’t use them in our code, it doesn’t get into the binary anyway…


#2

I think there are different reasons for this.

One is simply practical: Even if unused code won’t end up in the binary after all, it still adds work to the compiler. Compile time performance is already a weak point, so it makes sense to avoid any unnecessary overhead, even if it would be comparatively small.

Another reason is that these parts of the stdlib should be considered as somewhat independent libraries. They’re provided as parts of the stdlib because they’re very commonly used, but they’re not essential to the language runtime (like the features in corelib). So it’s better to think of them not as a feature always present in the language. Because they’re not. Some of these libraries might eventually be removed from stdlib and continue as a separate shard. And developers should also be able to use custom libraries for these tasks without having any features provided by the stdlib library in their code unless it’s explicitly required.


#3

Thanks for response.

JSON, YAML and siblings monkey-patch objects, so it is understandable why they are separate.

But shouldn’t uuid be a part of the stdlib? I mean, there aren’t any more ways to implement UUIDs… And it does not alter other objects.


#4

As @straight-shoota said, there’s no need to have the compiler do more work defining the uuid classes and methods if you are not going to use them. If you need them you can require them, it’s just one line.


#5

Also uuid could be a shard. Same with pretty much everything in the standard library.


#6

What’s the line defining what should be included and what not then? Is some small apps Arrays aren’t used, or Deques, or Time…


#7

Things that have literals (numbers, arrays, hashes, etc.) and things that the runtime needs (deque, set), which is an unfortunate consequence of how require makes everything available everywhere. Everything else must be required manually.