Hello all,

I am a data center engineer of about 8 years now. I’ve spent the last 3 years or so slowly learning Python(I say slowly not because of my effort, but because learning Python was actually very difficult for me.) I am not an expert in any way shape or form, I understand the concepts of OOP, inheritance, classes, functions, methods, etc and I have found that the python documentation that can be found within the language is usually enough for me to be able to write the programs that I want to write. Very rarely have I had to write programs that have to bypass the GIL, but occasionally, I have created threadpools for applications that are not I/O intensive. What I’m saying is, for most things that I create, performance is enough with Python.

However, I have been inspired by how much love Rust is getting from the people who use Rust. I have tried to find some books for using Rust for network automation and unfortunately I have not been able to find any reputable books.

Most of the “automation” work that I do involves parsing data with regex, restructuring the data, converting the data into a modeled format and transforming something with that data. Does anyone have any common use cases for Rust that might interest me? Has anyone used Rust for network automation tools? With familiarity, can Rust’s intuitiveness match Python’s “from idea to deployment” speed? Or should I only learn Rust if I intend to create applications that need tight performance?

  • @[email protected]
    link
    fedilink
    271 year ago

    Context: I am an embedded software engineer. I write a lot of low level code that runs on microprocessors or in OS kernels, as well as networking applications and other things. I write a lot of C, I write some Rust, I write Elixir if I possibly can, I write a lot of Python (I hate C++ with a passion).

    I don’t think you want Rust. Python is unbeatable on “idea to deployment” speed. Python’s downsides:

    • Painful packaging/distribution if you want to get a load of people who don’t have Python installed to run your thing (e.g the GUI program we currently maintain for talking to our hardware)
    • Performance under some circumstances. There are some things that are not quick in Python. They’re not always the things you expect because Python actually drops down to C modules for a lot of the number crunching that you might do. E.g. for ML you are basically using Python to plug a load of bits of fast C code together

    Rust is good when you need at least one of:

    • High speed
    • Control over use of memory
    • Low level systems programming (drivers etc.)
    • Can’t cope with a Garbage Collector
    • Compiling to a microcontroller

    If you’re doing one of those and so have become expert in Rust, then it is actually excellent for a lot of other things. E.g. you might build your data processor in it, and then distribution is easy because it’s just a single binary.

    One option you might look at is Go. You get a lot of performance, you get good parallelism if you need it, it’s designed to be easy to learn, and it also compiles programs to a single binary for easy distribution.

    • @[email protected]
      link
      fedilink
      161 year ago

      One more note on learning Rust: what Rust does is front-load the pain. If you write something in another low-level “direct control of memory” language you can often get something going much more easily than Rust because you don’t have to “fight the borrow checker” - it’ll just let you do what you want. In Rust, you need to learn how all the ownership stuff works and what types to use to keep the compiler happy.

      But then as your project grows, or does a more unusual thing, or is just handed over to someone who didn’t know the original design idea, Rust begins to shine more and more. Your C/C++/whatever program might start randomly crashing because there’s a case where your pointer arithmetic doesn’t work, or it has a security hole because it’s possible to make a buffer overrun. But in Rust, the compiler has already made you prove that none of that is possible in your program.

      So you pay a cost at the start (both at the start of learning, and at the start of getting your program going) but then over time Rust gives you a good return on that investment.

    • @[email protected]OP
      link
      fedilink
      51 year ago

      I think you’re right. Despite my bandwagon fandom, I Believe Go is more appropriate for my needs. I think a compiled language with more intuitive parallelism is what I need

    • @okamiueru
      link
      41 year ago

      Go doesn’t let you control memory, avoid garbage collector, or compile well to a microcontroller, no? It’s been a while since I paid attention.

      • TechNom (nobody)
        link
        fedilink
        English
        31 year ago

        You’re right - though I don’t know about the ‘control memory’ part. However, the other person is addressing the use-case of ‘network automation’, not of microcontrollers. There it really doesn’t matter what the exact memory layout is, or if GC stops your job for a microsecond. Go is sufficient for that. Go is sufficient even for many web backends and network infrastructure. In fact, much of kubernetes is written in Go.

        I use Rust for where one would normally use a shell script. But I have been using it for nearly a decade now (yes, I started before it reached 1.0). I have gotten used to the strict type system and even rely on it to write proper code. I also have a background in hardware - so much of it makes sense to me. Even so, I can’t recommend Rust to a beginner who values productivity. Rust takes a lot of time getting used to. And no matter how you try, you will never be as fast as you are with python or go. It’s not always bad considering what you get in return for the sacrifice. But it’s better to set your expectations straight.

    • Dark Arc
      link
      fedilink
      English
      21 year ago

      It’s worth noting the garbage collector is optional in Python. If you write your code “right” (avoid unbroken cyclic references) you don’t need it.