Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The one thing about Python that makes it so much more compelling over Bash is that thing you discover you need once your script starts getting long and repetitive: functions, with arguments, and return values. Python does this much better than Bash. It’s the one thing that makes me no longer use Bash. Oh and exceptions. Exceptions!

The TWO things about Python that make it more compelling are functions and exceptions. You stand a chance of handling errors in Python. In bash there’s very little else you can do, when encountering an exceptional situation that is an error, except stop. The nice thing about all these functions is you can put them in modules as well. Modules! Of course! A namespaced way of laying out non trivial amounts of code!

Ok so real functions, exceptions, modules. Three things that makes Python my default tool of choice. And libraries. Bash doesn’t have pip. Sure, bash’s “pip” is the commands it can run aka /usr/bin, but if that’s your interface then it’s hardly as flexible as say gitlab.py or requests.py.

So: apart from the functions, exceptions, modules, libraries. And speed. SPEED! And code formatting. And a debugger. And stack traces. …what has Python ever given us that makes it a no brainer replacement for bash scripts?

“Brought Unicode”

”Unicode! Oh shut up!”

After MP



> And speed. SPEED!

Maybe I'm just a terrible python programmer and also all those around me suck at it but in 20+ years I have yet to see a well optimized python script faster than a well optimized bash/ash/csh/ksh/zsh script. Maybe your point is true if a script constantly does foo=`some thing` and constantly shells out other commands.


I was thinking of the time I calculated IPV6 EUI64 suffixes in bash for a kind of janky IPAM thing, and how even the barest minimum of arithmetic turned “instantaneous” into “takes seconds”.

The bash-centric solution was to write a little eui64.c and call that from the script. Bash isn’t for doing things, it’s for making other programs do things. That worked fine for a bit, but in the end it just became easier to factor and reason about the project when it wasn’t a weird mixture of clever things, and one Pythonic lump of boring and predictable things.


Typically you don't want to do dependency management for simple scripts, but that's fine because python is batteries included




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: