3 ms·
That’s just the way Python works though, an import reads a script line by line defining the functions and executing calls. I think that’s true of any scripting
by buildbot 2y ago
That’s just the way Python works though, an import reads a script line by line defining the functions and executing calls. I think that’s true of any scripting language?
- DonHopkins 2y agoHow it works and how it should be used are different. Say “no” to import side‐effects in Python: https://news.ycombinator.com/item?id=7536246 https://news.ycombinator.com/item?id=7536246 https://chrismorgan.info/blog/say-no-to-import-side-effects-in-python https://chrismorgan.info/blog/say-no-to-import-side-effects-... >I must be able to import your module— any module— at any time without anything breaking. Or even the beneficial side effect of some other module running 10% faster. ;) What side-effects, if any, are okay when importing a python module? https://softwareengineering.stackexchange.com/questions/454069/what-side-effects-if-any-are-okay-when-importing-a-python-module https://softwareengineering.stackexchange.com/questions/4540... >Q: Is this a better design pattern or does it just kick the issue down the road? >A: Kicking the issue down the road is the basic idea of the "functional core, imperative shell" design pattern. Functional Core, Imperative Shell (2012): https://news.ycombinator.com/item?id=34860164 https://news.ycombinator.com/item?id=34860164 https://www.destroyallsoftware.com/screencasts/catalog/functional-core-imperative-shell https://www.destroyallsoftware.com/screencasts/catalog/funct...
- buildbot 2y agoWell yeah, I wouldn't hold it that way either. The number of PRs I've commented on to take side effects out from imports is like , 75% of all the PRs I've seen in my current job. Maybe Python 4 can make anything except a function definition or import be a syntax error in a module haha.