Live data from Hacker News

Using Rust for 'Scripting'

chriskrycho.com

81–90 of 126 posts

Re: Using Rust for 'Scripting'

#81

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

Re: Using Rust for 'Scripting'

#82

This is over engineering if I've ever seen it. For one this is a single line bash script that would allow you to even handle drag and drop. Best user experience. Second, if you're going to over engineering just look for someone who has already done that for you: http://www.den4b.com/products/renamer It's no use to engineer something that has been solved (unless you're learning) if there are already better solutions.…

1. Of course it's over-engineered.

2. It wouldn't be a bash script; it would have to be batch or PowerShell, neither of which I know well, and neither of which I like.

3. It was fun.

Re: Using Rust for 'Scripting'

#83
post #70

This topic is dear to me, I often deal with people without any software stacks on their machines and strict IT limits on installing new things. If I were on the same OS as the target user, I'd use pyinstaller. I've used it with very few issues over the past year on many projects. Most of them included Flask/Bottle and parts of numpy, it all worked like a charm. Cross compilation in Python is a bit of an issue, I for…

Re: Python, I've had success with running pyinstaller from within wine. I do most of my development from within linux, and so this covered my use case. No luck in cross-compiling into an OSX executable, though.

Re: Go, I've had the opposite experience. So long as you only use pure-Go libraries, cross-compiling works. If you use any C libraries (which last time I checked, include some of the standard library), you run into issues. For me, it was OpenGL bindings that made cross-compiling impossible.

Re: Using Rust for 'Scripting'

#84

Earlier quoted context omitted.

I do like activex/js and wsh, but Wsh might require permissions to modify the filesystem, so installation/setup step can be harder than just copying and running a statically compiled executable.

Last time I checked, doing new ActiveXObject("Scripting.FileSystemObject") did not require any extra 'permissions'.

I remembered the problem, it was the execution of unsigned/remotely signed powershell scripts where you have to open powershell and give a permission[1] by typing something like:

  Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
[1] https://technet.microsoft.com/en-us/library/bb613481.aspx

Re: Using Rust for 'Scripting'

#85
post #4

>Writing it in Rust means I can compile it and hand it to him, and he can run it. And that’s it. As wonderful as they are, the fact that languages like Python, Perl, Ruby, JavaScript, etc. require having the runtime bundled up with them makes just shipping a tool a lot harder—especially on systems which aren’t a Unix derivative and don’t have them installed by default. I'm wondering what part of the twelve step compi…

Python scripts can also be compiled to an exe file, although I think that the following batch one-liner is the best for this job: for /r startdir %%i in (*.cha) do ECHO ren "%%i" "%%~ni.txt"

For the record, as the author of the linked post… this is exactly what one "should" do for convenience in this situation.

Compiling Python to exe from Mac to run on Windows is actually a lot of work, though it's doable (I've done it more than once in the past).

Re: Using Rust for 'Scripting'

#86
post #4

>Writing it in Rust means I can compile it and hand it to him, and he can run it. And that’s it. As wonderful as they are, the fact that languages like Python, Perl, Ruby, JavaScript, etc. require having the runtime bundled up with them makes just shipping a tool a lot harder—especially on systems which aren’t a Unix derivative and don’t have them installed by default. I'm wondering what part of the twelve step compi…

My friend actually has the source code, so yes, he could do all of this. :)

Also, worth note that these "twelve steps" are:

- inclusive of literally everything including installing Rust and adding dependencies; this is like including "install Python" and "pip install" for a Python tutorial. The point was to be approachable for anyone. I think it succeeded.

- inclusive of the "copy the executable to hand to a friend" step in both cases, which is intentionally over the top in the true listicle style

- inclusive of a bunch of steps you only ever have to do once to get full MSVC-compatible cross compilation happening for Windows.

It's almost like I was intentionally using this tiny project (which isn't especially interesting in its own right; as many have noted it's a one-liner batch file) to provide a one-stop shop for the basics of getting a cross-compiled setup with Rust. ;)

Re: Using Rust for 'Scripting'

#87

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. ¯\_(ツ)_/¯

Re: Using Rust for 'Scripting'

#88

Was it too difficult to ask his friend to do right click -> create text document-> open it and write 'ren STAR.cha STAR.txt' -> save it as rename.bat and double click on it? Seriously, I'm not sure if this whole thing is a joke... edit: not sure why I cannot write the jolly character here

It was an excuse to figure out the cross-compilation story with a tiny tool; he got his tool, I got my experience with a part of the Rust ecosystem I hadn't interacted with before. It was a win all around. (Note as well that I said explicitly that I asked if this was a "just give me a tool" or a "teach me something about scripting" kind of day!) :)

Re: Using Rust for 'Scripting'

#89

This guy has likely not prototyped in environment such as Jupyter notebooks or ptipython. It is not just language - there is whole ecosystem build around Python scripting: pandas, matplotlib, numpy, etc. And don't forget about debuggers and IDEs once your projects grow out of scripting environment. Did I mention hooking up to GUI or web app?

I've done a lot in those kinds of things, actually; they're awesome. I don't feel obliged to mention every possible alternative in every blog post; that would be absurdly tiring to do, and probably wouldn't add much value. (Edited so it didn't read as hostile as the original version of the comment did.)

Re: Using Rust for 'Scripting'

#90
post #42
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"…

So, I'm going to stop you right there on the fast to bootstrap & run... Certainly Java is kind of a hybrid worst if both worlds kind of thing, but C/C++? For simple scripting problems you don't need complex build logic. You can usually get by with "cc foo.c -o foo", which you can embed in the source file. Sure, if you have library dependencies it can be a bit more involved, but most modern IDE's (even less than moder…

A bit tangential but here goes: I have some friends whose background is mostly algorithmic problems in competitive programming environments. I enjoy that kind of practice occasionally, but for them, it's the 90% of code they've written, and they are just too good at that stuff.

This means they know C++ best, as this is usually the language you use in those competitions. It's interesting to see the approach to scripting of these guys. While I tend to resort to shell pipelines and maybe throw in a short Lua program in-between, they write C++ code for everything, escaping to the shell for some stuff while using ordinary text files instead of piping, e.g. system("curl somesite >input.txt") and then fopen("input.txt", "r"). They write the glue between these calls, call the C compiler and run the binary.

They know their C++ and know how to write it fast; as a result, they can get a valid script running about as fast as I can do the same using a shell pipeline.

When I see this, I'm reminded how awesomely tools can be bent to do something they're not primarily designed for, when in the hands of someone skilled who knows them inside-out.

Post reply on HN