Rust Shined over Python for My CLI Tool

(smiling.dev)

1 points | by vinhnx 16 hours ago ago

1 comments

  • zahlman 13 hours ago

    > I’m being intentionally vague about the purpose, but it would take data, convert and standardize it, then upload that data in a special format.

    Well, NDAs are NDAs, but this isn't really enough information to assess whether the task included anything that might make it a poor fit for Python.

    > Where Python Started to Feel Difficult

    None of this comes across as specific to the tool, and comes across as very much more about the author's personal preferences.

    > Testing was another area where I thought Python would shine.

    ... Followed by no actual examination of the testing experience in Python, just a demonstration that Rust lets you mock things. I find the options for this in Python quite easy to work with.

    > Instead of making a function like fn get_posts(&client: &MyClient, data: PostUpload) -> Result<>, it’s better to use a trait:

    This looks like a bunch of boilerplate to describe an interface, which certainly can be emulated in Python as well (and would also be completely optional under gradual typing). We do it with `collections.abc` if we want to be formal.

    > Distributing a Rust binary is much easier than a Python build. I had instructions for users to clone the repository, install uv, and then set up the Python environment.

    Why do this when users can install uv and then `uv tool install` your program from a wheel on PyPI?

    > However, with Rust, I was able to get cross-compilation working. It now compiles to ARM 64 macOS, Windows x86, and Linux. It’s fantastic.

    Yes, it's nice to have access to easy cross-compilation to native, when your code requires compilation to native to run.

    > Another nice benefit is that the Rust binary starts up very quickly.

    When this is the only performance issue in a Python program, it's addressed by being careful about your dependencies and deferring `import`s.

    Basically, everything I concretely see in here is an example of something you can apparently do reasonably easily in Rust that's also trivial in Python.