4 ms·
Based on my experience with python, the python used global variables (which is idiomatic for scripts), making it about 10x slower than normal python. The other
by hedora 6y ago
Based on my experience with python, the python used global variables (which is idiomatic for scripts), making it about 10x slower than normal python.
The other 10x? That also matches my experience with other people’s python.
Someone probably tried to implement an abstraction, or something foolish like that.
- saila 6y agoI'm curious what you mean when you say global variables are idiomatic in Python scripts. I work on Python scripts on a daily basis and very rarely use globals except for the occasional "const" value. If globals ever do cause a noticeable slowdown due to dynamic lookup, this can easily be fixed by pointing a local var at the global at the start of a function.
- hedora 6y agoGlobals are idiomatic in all scripting languages except python. You don’t define a function called main, then manually invoke it at the bottom of your bash, perl, etc... script. In python, you do, partially because there is a severe performance penalty for not doing that.
- saila 6y agoAh, I see. I read "which is idiomatic for scripts" as applying to Python scripts and not scripts generally.
- RHSeeger 6y agoDefining a main function and then calling it from the bottom of your script is a mainstay of many people who program in scripting languages. It's certainly how I did things in Tcl. Really, it depends on the type of thing you're writing in the language, moreso than the language itself.