1. 23
  1.  

  2. 9

    I was really hoping this was going to be a revival of rusti.

    For anyone who doesn’t know/remember, rusti is Rust’s unofficial equivalent to Haskell’s ghci which allows you to prototype with a repl (much like many are used to with “scripting” languages). It used to be officially supported (if memory serves) and touted as one of the language’s coolest features, but seems to have fallen out of the view of most rust folk.

    rusti would allow you to sensibly author scripts in rust; actually, much like runhaskell, you could put a shebang at the top of the .rs file, make it executable and call it as if it were a regular old script.

    Instead, the post is about exploring Rust for things that should really be written in a shell (not python). The task presented (renaming a bunch of files to change the file extension) would be a one-liner with a for-loop:

    for i in *.someext; do mv "$i" "${i/.someext/.someotherext}"; done
    

    There are other and even simpler ways of doing this too (e.g., zmv). Hell, even if this is a Windows machine, powershell would do just fine for this.

    Don’t get me wrong, exploring new languages is a GoodThing™ because it has the opportunity to help you get familiar with the new language’s workflow in a general setting. But, advocating for doing this generally seems like a really bad idea; passing your friends a giant (in order to take advantage of what the author is talking about, you need to keep rust’s static linking) binary for a tiny bit of work instead of writing up a three-line shell script (to do the argument handling would be a couple more lines) for them seems like it is massively over-complicating the job.

    1. 3

      If you’re looking for the script parts of rusti and not the REPL parts, https://crates.io/crates/cargo-script

      1. 3

        Is there any reason why rusti or a REPL is not included with Rust?

        1. 9

          We used to have a sorta-kinda-repl included with Rust, but it never really worked super well, and was a maintenance nightmare, so it was removed.

          rusti’s README describes it as a work in progress; if it were something that was mature, then it might be considered, but its author hasn’t asked for this it to be included, either. So it really depends. It’s not something that we’d rule out, but I’m not sure any party involved is ready to take that step right now.

      2. 11

        “it’s so much easier than installing Python!”

        • installs rust
        • bootstraps a project dir
        • writes a dependencies file with version numbers which you have to look up
        • writes rust code;
        • compiles
        • installs a bunch of libs and ldd on his Mac to cross compile for Windows
        • hands friend an opaque binary blob to run

        Yeeeeahhh, thanks, but no thanks. I appreciate what he’s saying though.

        1. 23

          One of his points is that all of this work would be on him, whereas with a scripting language, most of the work would be on his friend. That’s a good tradeoff a lot of the time.

          Also, to be fair, you could write the same list for Python:

          • Install Python
          • Write a requirements.txt with version numbers which you have to look up (NB: you could also just use * instead.)
          • Writes Python Code
          • Hands friend source code
          • They install Python
          • Give them instructions on how to actually run the thing, which can be complex in itself (“no you need to pip install -r requirements.txt before you run the script)

          It really depends at what granularity you write these steps, based on what you think is trivial vs what you think is hard.

          (Oh and finally, the author has said elsewhere that really, this post is two things: “wow, I can write Rust for some simple stuff that I might have used Python in the past” and “hey here’s a quick guide to cross-compiling from Mac -> Windows”, and the latter certainly has merit, regardless of quibbling over languages :smile:)

          1. 3

            A few thoughts:

            First, the “Friend installs Python” step is a one time cost.

            Second, in this particular case there would be no requirements.txt or pip install because all of the required functionality from problem description is built in to the std lib.

            Three, if third party libs were required it’s trivial to give the friend a batch script that would call pip if necessary and then run the python script.

            Finally, the convenience of standalone binaries isn’t unique to Rust, he could have written it in Haskell, C++, Delphi, Pascal, Common Lisp, etc. and gave the friend a single .exe, too.

            1. 10

              First, the “Friend installs Python” step is a one time cost.

              Maybe. What happens when they had a Python 2 installed from the last time, but this new script needed Python 3?

              all of the required functionality from problem description is built in to the std lib.

              This is true, but only in this exact case. Which is again, more intended as an exemplar than “omg Rust crushes it for renaming files.”

              Three, if third party libs were required it’s trivial to give the friend a batch script that would call pip if necessary and then run the python script.

              Which kind? Do they have PowerShell? What version? Are you sure that’s compatible? Etc.

              the convenience of standalone binaries isn’t unique to Rust

              Nobody is claiming otherwise.

              1. 1

                Maybe. What happens when they had a Python 2 installed from the last time, but this new script needed Python 3?

                Assuming this scenario played out sometime within the last 5 years, then there’s really no good reason to choose Python 2 for a command line or GUI app. In any case, the onus would be on the computer literate friend to use a consistent version each time if he’s trying to simplify things.

                Which kind? Do they have PowerShell? What version? Are you sure that’s compatible? Etc.

                I have to claim ignorance here because I haven’t used Windows in almost a decade. Has MS (finally) deprecated plain old batch files? If not, why not use one? It’s like 2 lines of code.

                1. 3

                  Maybe I hang out around too many “never Python 3” people…

              2. 5

                First, the “Friend installs Python” step is a one time cost.

                Many users get stuck at locating the script/program they downloaded between the time they hit the button in their browser/email and go to find it. Now imagine explaining needing to install a language runtime, or (God forbid) a package manager beforehand.

                In some sense, this is a big explanation for why webapps took off: users don’t have to do anything, much less need install privileges.

                1. 2

                  Many users get stuck at locating the script/program they downloaded between the time they hit the button in their browser/email and go to find it. Now imagine explaining needing to install a language runtime, or (God forbid) a package manager beforehand.

                  It’s really unlikely the friend from the article is that computer illiterate if they’re competent to have the original requirement of needing to rename a bunch of files in an organized directory structure.

                  Also, home and office computers have been popular for well over 20 years now, it’s safe to assume people using them aren’t completely clueless any more.

                  1. 3

                    This article https://www.nngroup.com/articles/computer-skill-levels/ would argue that it is safe to assume that at least 92% of the population don’t have those skills.

                    Although, I’m not sure the methodology is not floored.

                    1. 2

                      I don’t know how much the results of that survey can be used to gauge computer skills because the entire focus is on information processing, and not really computer skills. For example, here’s a description of one of the difficult tasks from the article:

                      “One of the difficult tasks was to schedule a meeting room in a scheduling application, using information contained in several email messages. This was difficult because the problem statement was implicit and involved multiple steps and multiple constraints. It would have been much easier to solve the explicitly stated problem of booking room A for Wednesday at 3pm, but having to determine the ultimate need based on piecing together many pieces of info from across separate applications made this a difficult job for many users.”

                      It’s not at all clear if people failed because they lacked computer skills, or because they couldn’t process the information and connect the dots between a bunch of emails.

                      Furthermore, I don’t see where you got that 92% number. The study itself claims almost 60% of people were able to use “widely available and familiar technology applications, such as e-mail software or a web browser,” with half of those (31% of the total) scoring at an even higher level, which indicates to me that most people would be able to download and locate files or setup a simple directory structure.

                      And those percentages are actually lower than they should be because almost 25% of the respondents didn’t take take the technology portion of the test for various reasons.

                      1. 2

                        The 92% was based on the population of Japan with below level 3 skills - an arbitrary figure - but I was assuming a need for a level 3 ability to do this task as a computer user.

                        I agree with your analysis of the report - it doesn’t correctly identify if the issue was not understanding the problem space or a lack of computer skills. However, I do think that we have to be careful on our expectations peoples abilities and their willingness to learn new skills.

              3. 2

                You also assume the user is allowed to install Python. I’m not allowed to install new programs but if I can get the exe on my desktop (say, thru a thumb drive) then I have permission to run it.

              4. 11

                “it’s so much easier than installing Python!”

                He actually reflects on that topic and points out that he doesn’t want to ask his friend to install python. For the user (his friend) it’s actually much easier this way. The point here is that the target machine doesn’t need anything rust-related whereas a python version would require a working python interpreter with a matching version. Just think about your mother/father having to install python and some libraries on their windows box.

                writes a dependencies file with version numbers which you have to look up

                You can use "*" as a placeholder.

                1. 3

                  or install cargo-edit, and then you can run cargo add my-dep, and it will add it to your project as a dependency, with the latest version filled in.

                  1. 1

                    I thought you could turn Python scripts into a standalone EXE. I remember doing it a long time ago but not the tool’s name.

                    1. 2

                      Are you thinking of py2exe? I don’t think it ever really caught on. I tried to use it once and found that it was more trouble than it was worth and the resulting binary was massive. It also (AFAIK) only supports Windows.

                      http://www.py2exe.org/

                      1. 2

                        Not extremely large… I’ve shipped software using py2exe that was only five or six megabytes. Not bad for including its own Python interpreter.

                        1. 1

                          Hmm, perhaps I’m mistaken, but I remember the binary being more like 20MB. This was maybe seven years ago though, and I didn’t really know what I was doing.

                        2. 1

                          That was probably it. ChadSki’s numbers sound like what mine were.

                    2. 5

                      In a similar vein, but different direction, perhaps the “I don’t like powershell” decision could be revisited. powershell is rarely my first pick for a project, but after evaluating various options and the work required by various parties, I suspect it’s going to start bubbling to the top.

                      1. 3

                        Yeah, I agree. The machinations he goes through, AND the code he writes, IMO disprove his thesis.

                        This very much feels like stunt coding / when all you have is a hammer, everything looks like a nail.

                      2. 1

                        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 not sure I agree with the argument against JavaScript for non-Unix systems. The runtime is built into practically every OS, in the form of the browser. I would argue that JavaScript is the most portable programming language of all.

                        1. 1

                          Same should apply for Crystal and Go. Binaries are underrated.