4 ms·
What's the difference between polluting the global namespace with a class name, or with a function name? I get it, I also experience some reticience when addin
by cerberusss 6y ago
What's the difference between polluting the global namespace with a class name, or with a function name?
I get it, I also experience some reticience when adding free/bare functions in Swift. But maybe it's because of 15 years of OOP programming.
- aarong11 6y agoMaybe not so much of a problem in C++ but look at JavaScript. With the millions of dependencies / libraries you import, if they all used free standing functions you would inevitably end up with collisions.
- wruza 6y agoIn c++ functions can be marked ‘static’ to make them translation-unit local, or you can put them in a library namespace, if they’re public. In a particular js bundler/runtime usually a module system is used (or just iife/umd wrap) which prevents function names from populating globals.
- entha_saava 6y agoThe problem is unqualified imports though, not free functions.
- mcv 6y agoMaybe the problem here is the global namespace. I really like modern javascript where you have to explicitly import everything.