5 ms·
As someone who hasn't used Python in ages, and finds it quite unreadable, I would be saddened and dismayed if instead of shell (which is the lingua franca) a pr
by freedomben 6y ago
As someone who hasn't used Python in ages, and finds it quite unreadable, I would be saddened and dismayed if instead of shell (which is the lingua franca) a project used Python everywhere.
The exception being if it's a Python app in the first place, then it's fine since it can be assumed you need to be familiar with Python to hack on it anyway. For example I write a lot of Ruby scripts to include with Sinatra and Rails apps.
For a general purpose approach however, everybody should learn basic shell. It's not that hard and it is universal.
- ajuc 6y agoEver tried to parse XML or json in linux shell? It's not a matter of familiarity with linux shell. It's a matter of wasting time debugging/implementing stuff in shell that is trivial to implement in any modern scripting language.
- freedomben 6y agoHaven't parsed XML in quite a number of years but I parse JSON to extract values from a curl command all the time with jq and it's really not that bad. If there's anything more than simple extraction required then I agree it's not good for the shell. For that I turn to the primary language of the project preferably (which these days is Elixir and sometimes Ruby for me). But even JSON and (X|HT)ML you'd be amazed how often a simple grep can snag what you want, and regular expressions are also mostly universal so nearly everybody can read them.
- ajuc 6y agoWe (2-person team doing embedded QT app on linux) did it the exact way you're arguing for - starting with shell, struggling with it for several months every time something went wrong or we had to change it, and finally giving up and rewriting it in python. Python wasn't our main language (the app was in C++ and QML which is basically java script). But we both knew Python and it's the easiest language for these sort of things that we both knew and that comes with the system. My main conclussion is - I'm starting with python the next time. Life's too short to check for the number of arguments in each function.
- verall 6y agoI think there is a big difference between this and the parent. If you are working on projects where the "primary language" is Ruby or Python or Elixr than sure, use that, but if your project's primary language is C++, like most embedded applications, you do NOT want to use that. Any complex or cross-platform C++ projects will need a scripting language in addition to shell and a build system.
- chubot 6y agoLife's too short to check for the number of arguments in each function. Ha! The Oil shell does that for you :) https://www.oilshell.org/release/0.8.0/doc/idioms.html#use-procs-better-shell-functions https://www.oilshell.org/release/0.8.0/doc/idioms.html#use-p... (It's our upgrade path from bash)
- deleted 6y ago[deleted]
- reificator 6y agoI do JSON pretty frequently with jq and idiomatic python[0] can't even approach its ease of use. [0]: I'm sure there's a jq style library for python somewhere but it's definitely not the norm.
- tingletech 6y agothere are a couple of bindings from python to jq, I can't remember which I've used, but it makes it super simple to do jq queries from python
- jdc 6y agoJMESPath works pretty well: https://github.com/jmespath/jmespath.py https://github.com/jmespath/jmespath.py
- deleted 6y ago[deleted]
- ak217 6y agoShameless plug: my project yq (https://github.com/kislyuk/yq https://github.com/kislyuk/yq) (pip install yq) includes a utility, xq, which transcodes XML to JSON using the Goessner JsonPath transformation (https://www.xml.com/pub/a/2006/05/31/converting-between-xml-and-json.html https://www.xml.com/pub/a/2006/05/31/converting-between-xml-...) so you can use jq to query XML.
- kasabali 6y agoIf you're trying to implement stuff in shell you're doing it wrong. It's a glue language. and yes, parsing XML or JSON in "linux shell" is very easy. For JSON use jq, for XML use xml2 or xmlstarlet.
- anon73044 6y ago>json in linux shell? Yes! Fortunately for me a 10 whole lines of sed, awk and some trimming and a for loop turned my json into a CSV to pass back to a legacy system. No curl or json modules necessary. That being said, if I needed anything more complex Python would be my default.
- lmm 6y agoPython is far more of a lingua franca than shell is. Learning basic Python is a much better use of your time than learning basic shell - it's easier and more widely useful.
- shrimp_emoji 6y agoPython as new shell lang when?
- yowlingcat 6y agoI can understand finding the Python unreadable but where I disagree is that "everybody should learn basic shell" -- no it's not that hard, yes it's universal, but there's more to finding a sustainable solution than that. Try to pivot that shell into something slightly more sophisticated and you run into muddy waters. I really like Ruby as a replacement shell language because its syntax for shelling out is very succinct and elegant. Python is a bit more verbose but a lot more explicit. Either one is a step function better than shell. You get a real programming language. Let's extend your analogy to a logical conclusion. Should you write something in a shell because it's "not that hard and universal" or should you insist on using a programming language that lends itself to writing maintainably? If not, we should have no problems with PHP and COBOL, no? But we do. Use the right tool for the right job. If you're not sure what that is, don't hesitate to pull out a glue language. Python, Ruby, JS -- whatever you need to get the job done. Your shell should be just that -- a shell, not the core.
- Gunax 6y agoMaybe shell makes sense to you, but I recently wrote my first real shell script and it was nothing but pain. Brackets don't mean what you think they mean. 'If' does not work sometimes? and I am not sure why. Sometimes I am supposed to quote variables but not always? And after all that it broke once it moved to a AIX machine since it was not POSIX compliant. Maybe it's obvious to you, but when I cannot even figure out if an if statement will work, something is horribly wrong. I don't even use python and I can just about guarantee it's easier for someone who knows neither.