Namespaces & Modules in Rust, Zig, C++20, and More

preview_player
Показать описание
Language covered: Python, C, C++, C++20, JS, Zig, Ruby, Elixir, & Rust
Рекомендации по теме
Комментарии
Автор

I feel like a lot of OOP's pattern can be made a lot cleaner with modules.
So much of the cpp/java classes I would write would be just an excuse to wrap a bunch of procedures into a namespace that can be imported.

cunningham.s_law
Автор

Interesting video!
I was just recently playing around with modules in JavaScript and wondered how they worked in some other languages.

On that note, an interesting video might be a look into how higher-level languages handle primitive variables and large objects when passed around through functions.
When looking through modules, I always assumed that JavaScript made a copy of some sort when importing modules. I don't know why I assumed that, but I did. Turns out that multiple modules can edit properties of an object from some other module and both see the changes.

brukts
Автор

You should've also shown Go, as it brings yet another way to think about namaspaces (one that I quite enjoy). The biggest thing being that all files in the same directory belong to the same namespace and that exporting happens by with capital letters.

xremming
Автор

For the python example, it does what you tell it to. If you import at global scope, it will be also exportedm, but contrary to other languages, you can also import in any other scope. So in your example, if you want 'c' to not be exported, don't import it at global scope, just import it within the function you're using it in. 'c' won't be exported so won't be accessible from outside.

AinurEru
Автор

noob question: how did you generate an elf file from the a.zig file at 10:15?

nazarottto
Автор

Julia's module system is one of the bests I have ever seen. Similar to JavaScript, you access to everything that is exported by `using moduleB`. But also it allows importing the variables individually `import ModuleB : b`. Using `import`, you can import things that are not exported at all. This latter isn't available in JavaScript. This gives the best of both worlds.

nivo
welcome to shbcf.ru