After reading various articles on the internet and hearing arguments against namespaces, I am still unsure about the benefits of using modules with a module loader instead. Some claim that namespaces are outdated and problematic, but I'm not convinced by these points. Can someone provide real-world examples to support these arguments?
- People argue that namespaces create at least 1 global variable. But why is that considered a problem? Personally, I don't see any harm in having a global variable like 'angular'.
Some say that modules allow consumers to name imported variables as they wish. But how common is it for there to be duplicate variable names like 'angular'? And in cases where duplicates do occur, can't we simply rename one of them without much trouble?
Another argument is that module loaders make bundling scripts easier by organizing them in the correct order. However, couldn't this order also be achieved by manually arranging imports at the top of each file or using tools like Typescript's "outFile" option in tsconfig.json?
There's also the claim that module loaders improve performance. But if I end up with a single large JavaScript file either way, will the difference in performance really be significant? Even with dynamic loading, does the incremental loading of a few kilobytes make a noticeable impact?
Finally, even if modules and module loaders are superior to bundling and referencing in HTML, wouldn't using a module loader for building a library require users to install the loader dependency as well?
Thank you all for your insights.