Live data from Hacker News

Using Rust for 'Scripting'

chriskrycho.com

21–30 of 126 posts

Re: Using Rust for 'Scripting'

#21
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. Even if it is an example a better one should be used.

The moral of the story should he use the best tool for the job, don't shoe horn a bad language for a into a solution, and also Google is usually the best tool for every job.

Re: Using Rust for 'Scripting'

#22

I found myself doing the same just a few days ago when my local server suddenly had a new ip address. I made a simple script to scan IP addresses in the range: https://gist.github.com/johshoff/bed463ce8a122123e60bbc84bd1... There are probably faster ways, but none that I could think of a the time.

Cool program.

Other quick ways besides the mentioned nmap: ping the broadcast address (if ICMP is allowed) or install avahi-daemon and you can just refer to "your-machines-hostname.local"

Re: Using Rust for 'Scripting'

#25
post #13
post #8

By the way, to solve the specific problem mentioned in the article, see "man 1 rename".

Is this available on Windows? The author made it pretty clear the target user was on a Windows machine

The Windows rename command doesn't support recursively processing subfolders, but it can be achieved using one line of powershell:

  Get-ChildItem . -Recurse -Include *.cha | Rename-Item -NewName { $_.name -Replace '\.cha','.txt' }

Re: Using Rust for 'Scripting'

#26

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.…

I don't think the author is really expecting people to go out and start uninstalling Python to do all their scripting in Rust. Seems to me like he saw this as an opportunity to show off the clap and glob crates, as well as write a little documentation for how to cross-compile Rust from Mac to Windows.

Re: Using Rust for 'Scripting'

#27

> Add the dependencies... Nope. The beauty of a decent systems scripting language is that it includes everything you need (and ideally is already installed everywhere).

The author explains that the intended target is Windows, which has neither Perl nor Python (nor even Bash) installed by default, so "already installed everywhere" is already off the table. At that point, since Rust can produce static binaries, it doesn't matter what deps you pull in.

Re: Using Rust for 'Scripting'

#29
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…

I agree. Instead the "friend" is taught the bad behavior of running untrusted (and I didn't see any tests, so untested and undocumented too) code in binary format on their machine. The glob-rename is exactly the sort of problem a script is supposed to solve easily. I feel the author justified the use of Rust and cross-compilation simply to avoid usage of a Windows OS (or VM) for such a trivial task. If the goal was t…

What? You mean like every other program they've ever run in their lives if they're not a developer, except developed by a personal friend?

Compiling is easy. Configuring path variables and installing interpreters are arcane to non-developers.

Re: Using Rust for 'Scripting'

#30
post #25
post #13

Earlier quoted context omitted.

Is this available on Windows? The author made it pretty clear the target user was on a Windows machine

The Windows rename command doesn't support recursively processing subfolders, but it can be achieved using one line of powershell: Get-ChildItem . -Recurse -Include *.cha | Rename-Item -NewName { $_.name -Replace '\.cha','.txt' }

From what I remember Include will only match items from the base directory and powershell gets stupidly complicated very quickly:

http://flukus.github.io/2015/03/13/2015_03_13_Powershell-is-...

Post reply on HN