News for hackers. Stuff that matters.
Re:No script is too simple by freedomben on Tuesday September 22, 2020 @02:51PM (#24558369)
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.

Re:No script is too simple by ajuc on Tuesday September 22, 2020 @03:34PM (#24558830)
Ever 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.

Re:No script is too simple by freedomben on Tuesday September 22, 2020 @03:45PM (#24558952)
Haven'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.

Re:No script is too simple by ajuc on Tuesday September 22, 2020 @04:00PM (#24559120)
We (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.

Re:No script is too simple by verall on Tuesday September 22, 2020 @05:43PM (#24560297)
I 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.

Re:No script is too simple by chubot on Wednesday September 23, 2020 @01:25AM (#24563290)
Life'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-p...

(It's our upgrade path from bash)

Re:No script is too simple by reificator on Tuesday September 22, 2020 @03:56PM (#24559077)
I 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.

Re:No script is too simple by jdc on Tuesday September 22, 2020 @10:55PM (#24562467)
JMESPath works pretty well: https://github.com/jmespath/jmespath.py
Re:No script is too simple by tingletech on Tuesday September 22, 2020 @08:21PM (#24561565)
there 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
Re:No script is too simple by ak217 on Tuesday September 22, 2020 @07:24PM (#24561208)
Shameless plug: my project 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-...) so you can use jq to query XML.
Re:No script is too simple by kasabali on Tuesday September 22, 2020 @07:46PM (#24561376)
If 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.

Re:No script is too simple by anon73044 on Tuesday September 22, 2020 @08:43PM (#24561709)
>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.

Re:No script is too simple by yowlingcat on Tuesday September 22, 2020 @08:37PM (#24561665)
I 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.

Re:No script is too simple by lmm on Tuesday September 22, 2020 @08:34PM (#24561640)
Python 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.
Re:No script is too simple by shrimp_emoji on Tuesday September 22, 2020 @09:26PM (#24561981)
Python as new shell lang when?
Re:No script is too simple by Gunax on Wednesday September 23, 2020 @01:34AM (#24563330)
Maybe 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.