4 ms·
Circular imports in JS matter when the imported code is being called immediately at import time. If a file defines functions that later call functions from anot
by brundolf 5y ago
Circular imports in JS matter when the imported code is being called immediately at import time. If a file defines functions that later call functions from another file (and vice-versa), but those symbols will be populated before the function actually gets called, there's no problem
- Waterluvian 5y agoYeah. It’s so flexible. I get frustrated at Python (Django) serializers that legitimately need to depend on each other. And the answer on the forums is to create a near duplicate class.
- nyrikki 5y agoJavaScript does not provide namespaces by default which allows this. Python is built upon namespaces and cycles in dependencies, either viewed as graph theory or kSAT introduce that fun NP-complete problem of version hell. Using `need` in Javascript maintains the directed acyclic graph structure, but if you get fancy you will run into the same problems with circular depends in Python. Karp's 21 and/or SAT will catch up with you at some point if you don't respect the constraints that make the problem tractable. Note I am not saying I prefer or like pythons choices...but that they had to make one.
- Waterluvian 5y agoSorry what’s ‘need’ ? I can’t seem to find it as a keyword.