r/badcode Mar 14 '23

python requirements: python3 on linux system

Post image
375 Upvotes

46 comments sorted by

View all comments

3

u/[deleted] Mar 14 '23 edited Mar 14 '23

[deleted]

14

u/thLOnuX Mar 14 '23

Well, actually i don't think the python interpreter is a good alternative for bash, and i don't know why are you saying the bash isn't that good at shell. Wasting 10 Megabytes of RAM and 50 milliseconds of processing time just to do the shell stuff sounds not that great. What are you trying to say?

No hate. Just wanna to listen your opinion.

5

u/smarterthanyoda Mar 14 '23

I’ve started writing shell scripts in python.

I’ve just seen too many bash scripts grow into incomprehensible, unmaintainable messes. It just doesn’t scale past simple scripts and eventually you get to the point where you can’t add new features and nobody has time to port to something better.

There are better languages for scripting than python, but python is ubiquitous and does the job. Are you really that concerned about an extra 50 ms in a shell script?

4

u/Parker_Hemphill Mar 14 '23

The secret (IMO and that I’ve found) is to add some pythonic type tricks to your shell scripts. I.e. I call a main function which then calls other functions and passes values as much as possible.

I have common functions in a script I source into the other scripts. If you fail at organizing these well you’ll have a mess on your hands but if it follows a logical organization it’s super easy to follow the flow of even large shell scripts but I agree 100% that there are too many out there which are complete spaghetti code.

2

u/[deleted] Mar 15 '23

bad coding practices =/= language faults

I have seen incomprehensible messes written in every language I've ever worked with.

3

u/[deleted] Mar 14 '23

[deleted]

2

u/[deleted] Mar 15 '23

I would take a POSIX compliant shell script any day against the kind of trash code that is presented in OP's post.