Live data from Hacker News

Using Rust for 'Scripting'

chriskrycho.com

91–100 of 126 posts

Re: Using Rust for 'Scripting'

#91
post #77
post #55

Earlier quoted context omitted.

Despite that, Windows is still the most popular desktop OS in the world by an enormous margin. You don't help a friend who needs to rename a load of files by saying "well, it'd be much easier if you first installed Linux". Or cygwin, or even the Windows Subsystem for Linux if they're running Windows 10 Anniversary Update.

You help a friend by giving him a one liner COMMAND.COM shell script, instead of turning it into a cross-compiling hackfest just because you're a Rust fanboy (in author's own words).

Or, you figure out the cross-compilation steps and document them for the whole Rust community, because there isn't yet a readily searchable resource on it. I actually knew exactly what I was doing with this, and it wasn't just solving that one specific problem. It was solving a bunch of different issues, including some for the whole Rust community, some for my own personal experience, and that one for my friend. Heck, I asked him if he minded waiting while I did all of this, and he gave the thumbs-up. ;)

Re: Using Rust for 'Scripting'

#92
post #79

Earlier quoted context omitted.

>[...] the standard library is about as complete as you can get (and probably better than the classical scripting languages — all of Ruby/Python/Perl missed a good API for some things like HTTP, which led to the rise of separate packages like Faraday/Requests/etc) What? Rust basically has no standard library. At least Python doesn't require pulling in third-party libraries to do globbing, create a zip/tar, create a t…

it sort of does, though. Trying to use urllib2 is like pulling teeth

Which is why you use httplib[1] for sending HTTP requests.

    >>> import httplib, json
    >>> conn = httplib.HTTPConnection("httpbin.org")
    >>> conn.request("GET", "/get")
    >>> res = conn.getresponse()
    >>> print res.status, res.reason
    200 OK
    >>> data = json.load(res)
    >>> print data
    {u'origin': '0.0.0.0', ...}
    >>> conn.close()
[1] https://docs.python.org/2.7/library/httplib.html#examples

Re: Using Rust for 'Scripting'

#93

It's a shame the author didn't frame this article differently by strictly focusing on how to cross compile a simple rust app on macOS and Windows. The focus on "scripting" seems to have really brought out the negativity in people here. I definitely learned something, I had no idea I could compile a Windows binary from my Mac.

The author here: I agree with your assessment. Apparently the scare quotes didn't convey my intent: it's easy to do something (including cross-platform) where I normally would have used a traditional scripting language, and the portability is nice. ¯\_(ツ)_/¯

Well thanks anyway, I enjoyed it!

Re: Using Rust for 'Scripting'

#94
post #20

I love this idea. There's an implicit assumption that the reason scripting languages are suitable for scripts is that they play fast and loose with type systems, which allow enough shortcuts and escape hatches to be productive. But that's only part of the story. Along with typing, scripting languages also had the major advantage of being fast to bootstrap and run (`ruby script.rb`) and were fully "batteries included"…

>[...] the standard library is about as complete as you can get (and probably better than the classical scripting languages — all of Ruby/Python/Perl missed a good API for some things like HTTP, which led to the rise of separate packages like Faraday/Requests/etc) What? Rust basically has no standard library. At least Python doesn't require pulling in third-party libraries to do globbing, create a zip/tar, create a t…

Admittedly they did ship a lot out of core outright, but a single line in `Cargo.toml` fetches any of these things pretty expediently, and they're still well standardized across the ecosystem.

    zip = "0.2"
    tempfile = "2.1.4"
    getopts = "0.2"
    hyper = "0.9.12"

Re: Using Rust for 'Scripting'

#95
post #49

While this can be seen as an interesting exercise, I can't help but feel that rust isn't the best tool here. First, there are a handful of existing tools, as other have pointed out (I would personally go for AntRenamer). Then, there are a few scripting languages already installed (admittedly maybe not the best or most well-known). A quick Google search would probably have given a result right away, since this is a pr…

For the "right tool for the problem", you're right; really, see up-thread where someone posted the one-liner.

For MSVC over MinGW/Clang: part of my point here was to first learn and then document for the community how you do cross-compilation for MSVC. There are lots of projects out there where being able to link against MSVC is important, and it's also harder than linking against MinGW (which would have just been `rustup target add x86_64-pc-windows-gnu` and `cargo build --release --target=x86_64-pc-windows-gnu`, I believe; no extra linker stuff needed), so there's more value in documenting it and putting it out there for MSVC.

Re: Using Rust for 'Scripting'

#96
post #32

One could also use Haskell [0] for scripting [1] using the turtle [2] library. turtle is a reimplementation of the Unix command line environment in Haskell so that you can use Haskell as both a shell and a scripting language. [0] https://www.haskell.org/ [1] http://www.haskellforall.com/2015/01/use-haskell-for-shell-s... [2] http://hackage.haskell.org/package/turtle

Big +1 to turtle, which is a really neat piece of software that manages both to be super useful on its own and to provide what looks like a really helpful way of learning Haskell.

Re: Using Rust for 'Scripting'

#97

http://www.pyinstaller.org/ Single file executable. Job done. Of course, if you want to write something in Rust, it's not much use.

Oh, nice! PyInstaller didn't have Python 3 support the last time I looked at using it (mid-2015; I think it was in-work at that point), so I'm glad it's landed.

Re: Using Rust for 'Scripting'

#99
post #72

This reads less as “Python style scripting in Rust” and more as “I like Rust, also it’s cross-platform.” Not that this is a bad thing, but it feels like a bit of a far cry from my hacked together workflow of throw code in iPython and write out when I’m happy. I don’t see anything here that makes Rust any more attractive than whatever your multiplatform language of choice is for this use case scenario. That being said…

I've been using Rust to build a relatively large cross-platform command-line tool, and I've been genuinely impressed at how easy it is to get things to work on Windows. The Rust standard libraries Just Work on Windows, and they provide pathname handling, threads, environment variables, and a wealth of other tools. Many third party libraries will build for Windows without any problems as well. I actually do think that…

> such as the way Windows permits slightly invalid Unicode

Windows allows invalid UTF-16 while Unixes allow invalid UTF-8.

Re: Using Rust for 'Scripting'

#100

This reads less as “Python style scripting in Rust” and more as “I like Rust, also it’s cross-platform.” Not that this is a bad thing, but it feels like a bit of a far cry from my hacked together workflow of throw code in iPython and write out when I’m happy. I don’t see anything here that makes Rust any more attractive than whatever your multiplatform language of choice is for this use case scenario. That being said…

Totally fair. I summed up that way because this is the kind of thing I'd have done with Python historically, and it struck me as neat that it's so easy to do with Rust. As someone pointed out on Reddit: this isn't really "scripting", and that's correct. I put it in "scare quotes" for a reason. ;p

Is it fair to assume the actual task was more complicated than renaming .cha to .txt and you just made it more generic here for example's sake?
Post reply on HN