11 ms·
"[For writing complex scripts] JavaScript is a perfect choice". Not sold on that. Why should I choose it over Python, PHP or others?
by Fragoel2 3y ago
"[For writing complex scripts] JavaScript is a perfect choice".
Not sold on that. Why should I choose it over Python, PHP or others?
- chupasaurus 3y agoThis [pun very much intended]
- rrr_oh_man 3y agoWhere's the pun in that?
- justech 3y agoI’m assuming it’s this https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... (no pun intended)
- thewisenerd 3y ago`this` in javascript
- cerved 3y agoIt's asynchronous, which is pretty neat
- Mandatum 3y agoA script, by its very nature, is synchronous. You run, you get a result. If you want a service, don't use a script.
- frizkie 3y agoThis is pedantic to the point of being conversationally hostile.
- wruza 3y agoThat’s a completely arbitrary limitation which should not exist. When my scripts contain independent non-instant subprocesses, I run them in parallel. I’m also using js/ts to write all my scripts, because why wouldn’t I use a proper programming language instead of that “bash” thing that can’t even handle its single datatype well and resorts to all sorts of gibberish to perform trivial operations on it.
- cerved 3y agoHow? Pipes are not synchronous
- cultofmetatron 3y agoyea same here. I wrote nodejs programs for years. the focus on the eventloop and everything being asynchronous is great for servers and network IO but does NOT make it the perfect choice for scripts. Its a different use case entirely. scripts are supposed to be small simple programs that run in sequence and terminate. I shouldn't need to deal with concurrency primitives at all in that particular situation.
- colordrops 3y agoWith modern JavaScript (as in last 5-7 years) it's pretty straightforward to write sequential scripts.
- petre 3y agoThere's more to it than writing a simple sequential python, ruby or perl script. You have to write everything using async/await.
- colordrops 3y agoasync/await are dead simple. And many Node libs have synchronous versions. It's pretty straightforward if you are familiar with the language. If you aren't, well that isn't really the fault of JS nor any different from bash or python, which can both be just as painful for those unfamiliar.
- anonymous_sorry 3y ago> scripts are supposed to be small simple programs that run in sequence and terminate. I shouldn't need to deal with concurrency primitives at all in that particular situation. I suppose bash pipes are a concurrency primitive, but I don't object to them. I think it's more about appropriate primitives.
- larusso 3y agoEspecially because these languages are only one package/install away and not two. I don‘t really get for which audience is targeted here. Usage in JS projects maybe, but then why not write it as npm tasks. .. I‘m playing around with dotnet-scripts [1] at the moment (C# shop mainly) and this has the same issue imho. The reason why I looked into it was because we have developers not accustomed to bash etc. I still find it silly and would rather use ruby so… [1] https://github.com/dotnet-script/dotnet-script https://github.com/dotnet-script/dotnet-script
- Vinnl 3y ago> why not write it as npm tasks. Do you mean writing the entire script in a single line in a string in a JSON file (package.json)? Of do you mean that string just calling out to a non-inline script? Because the use case for this is very much that latter script - it will often still be started via `npm run`.
- Vinnl 3y agoBecause you (i.e. I) already use it and have the full toolchain set up for your project?
- Sammi 3y ago100% Use whatever you're proficient in. For A LOT of devs that means js. Why spendtime pulling python into my js project?
- deleted 3y ago[deleted]
- Sammi 3y agoModern js is not what it was. Ergonomics of nodejs v20 are not in the same ballpark as node v6. A lot has happened since v12 even. Js definitely has become a pleasant language to script in. And it's sooooo much faster that python and Ruby.
- lloeki 3y ago> And it's sooooo much faster that python and Ruby. That advantage becomes vanishingly small when the language task is to glue together a bunch of spawn/fork/exec to external processes. If the glue code somehow needs actual heavy processing, that processing can be factored out into another program dedicated to that, leaving only glue code. Side effect: the heavy processing code immediately becomes composable!
- petre 3y agoStill the same footguns for the sake of backwards compatibility. Things like: typeof '' == 'string' false And many others that I'm are too depressing to mention. This is the latest one that I got surprised with. Yes, it's fast but so is Lua, Dart or even Racket.
- Sammi 3y agoCan I qoute my comment verbatim back at you? Seriously. Just don't use ==. Use ===. Et voila you're using a modern pleasant scripting language. Modern guides on js won't ever mention ==. As a noob today you won't ever learn it. In a big project there will be a linter to stop you
- DemocracyFTW2 3y agowha? Welcome to Node.js v19.9.0. Type ".help" for more information. > typeof '' == 'string' true ???
- DemocracyFTW2 3y ago> Why should I choose [JavaScript] over [...] PHP [...]? LOL dude made my day
- deergomoo 3y agoPHP is a surprisingly capable scripting language. Some relatively recent version is installed by default on a lot of Linux distros and its standard library has tons of functions for dealing with strings, files, and the network.