4 ms·
Python used to be my "main" language, but that was only due to familiarity. For most IO intensive tasks (especially networking), Python is not the best choice [
by chatmasta 10y ago
Python used to be my "main" language, but that was only due to familiarity. For most IO intensive tasks (especially networking), Python is not the best choice [0]. Recently I've been using nodejs with promises and async/await for heavy IO. I really like the productivity gains of Javascript's functional programming style, and the event loop lends itself well to network/IO intensive tasks. (I would prefer to use golang for this, but haven't gotten around to learning it yet)
Now I use python when it's the best tool for the job, where the "job" is a part of a project. My projects usually involve a combination of three languages: python, javascript (node and/or frontend), and bash scripting. The bulk of the code is node, but for scripts I use a combination of bash and python.
I use bash scripts for anything that involves piping data between processes, simple file I/O, backup scripts, etc. I prototype almost every script in bash. When it gets too complicated, or requires parsing a lot of data, I switch to Python (sometimes I even inline the Python in bash with heredocs).
In my experience, bash is usually the best tool for the job if the "job" involves invoking lots of shell commands and piping their outputs somewhere. Using Python to call shell commands is of course possible, but I find it to be much less readable than bash for that specific use case.
Nothing beats Python for parsing and manipulating data, which is why it can be so powerful when combined with bash. Here [1] is an example bash script I wrote in ~30 minutes that uses inline Python. It deploys schema from a JSON file to parse-server. Bash handles the raw IO of reading files, network requests, etc, but inline Python does the simple manipulation of the JSON files.
[0] I haven't worked much with python3 or async/await... but that looks promising (hah) for increased throughput. I've even seen some benchmarks inline with node.
[1] https://gist.github.com/milesrichardson/b30acef8827c53aae0885186cc6078b3 https://gist.github.com/milesrichardson/b30acef8827c53aae088...
- deleted 10y ago[deleted]