102

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?

you are viewing a single comment's thread
view the rest of the comments
[-] nous@programming.dev 62 points 1 year ago

With familiarity, can Rust’s intuitiveness match Python’s “from idea to deployment” speed?

Likely not at the start. Rust can take some time to learn to use it effectively it is not the fastest at throwing shit together quickly.

Or should I only learn Rust if I intend to create applications that need tight performance?

Also no. IMO rusts performance is only a nice by product of the language, yeah it encourages people to try it out, but they don't stay for the speed. They stay for the tooling and the feeling that once it compiles it will likely just work they way you intended. Rust forces you to think more about correctness and edge cases of your code - which does slow down initial idea to working prototype a bit. But IMO it quickly pays back dividends when you get something into production and it just works with no random crashing in the middle of the night.

It also makes refactoring a joy to do, where I hate refactoring in languages like python as you never know what you might have broken - likely something that you will find out only after you have deployed to production. Instead the compiler catches basically every thing that you missed before it will even let you run the code - so those edge cases are taken care of when you are developing, not after it fails in production.

I also find it is very nice with data processing/transformation as it lets you use functional coding styles which tend to lean towards clearer/easier to read series of data transforms.

If you want to learn it I would recomend starting out with the offical book, but you might also find zero to production or datawithrust interesting reads as well.

[-] TehPers@beehaw.org 14 points 1 year ago* (last edited 1 year ago)

Likely not at the start. Rust can take some time to learn to use it effectively it is not the fastest at throwing shit together quickly.

To add, Python lets you make a new file, write up a quick script, and start running it. You even have a REPL environment prepared for you to start throwing code at and see what happens. Rust is nothing like this (though some "script runners" exist for Rust). You'll usually end up creating a new folder, creating a Cargo.toml, then a src directory and a main.rs file. Now you can start writing code, but the Python developer has already ran their code a few times and iterated on it a little.

For experienced users, development speed in Rust starts to pick up after the initial project setup and once the basic "boilerplate" (this depends per domain, could be arg parsing, reading a config file, setting up telemetry, etc) for their specific application type has been created, in my experience. For quickly throwing together a small script, a developer equivalently experienced in Python and Rust will likely find Python faster to use, but when looking at mid to large sized codebases, that could flip due to how strict Rust is and how that prevents problems over the long term.

[-] 5C5C5C@programming.dev 13 points 1 year ago

It only took me ~2 weeks of playing with Rust before it became my scripting language of choice over Python (which I had been using casually for ~5 years by that point).

The initial setup for Rust can be whipped up with $ cargo init. You're right that there's more setup boilerplate because of the mandatory Cargo.toml and directory structure, but cargo init will provide all that in a snap.

As for the domain specific boilerplate, I actually find that Rust is better at that than Python in almost all cases. I feel that Rust's clap is much simpler, more reliable, and less boilerplate than Python's argparse. Python might win in cases where there's a very mature domain specific package that you need which isn't available in the Rust ecosystem, but that's becoming rare as crates.io grows.

And then when it comes to the actual "scripting", very often my IDE's intellisense can practically fill in the Rust code for me. One keystroke per word and it knows what function I want, or I can quickly scroll through the recommendations until I find what I'm looking for. Meanwhile with Python I always have to consult docs to find any API that isn't part of the basic standard library. As a result I'll often get the scripting done faster in Rust than in Python.

It does absolutely take some time to reach that point, though. Most programmers will definitely feel significant discomfort with Rust initially, but that's just because you need to deprogram your brain from the bad habits that other languages encourage. There's a tipping point in that deprogramming where all the other languages start to feel uncomfortable because you know it won't let you write as good quality of code as Rust would.

[-] Sigmatics@lemmy.ca 5 points 1 year ago

I can't confirm the point about autocompletion with Python. When using strictly typed Python (mypy), the suggestions are just as good

[-] 5C5C5C@programming.dev 9 points 1 year ago

Using visual studio code this only happens if the library has thorough type annotation. While that's becoming more popular, it's not enforced at the language level so lots of libraries have enormous gaps in the autocomplete.

[-] Sigmatics@lemmy.ca 6 points 1 year ago

It's improved a lot over the past year, but you're right. Not even the standard library is typed

load more comments (1 replies)
load more comments (4 replies)
load more comments (5 replies)
this post was submitted on 01 Sep 2023
102 points (100.0% liked)

Programming

17213 readers
129 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 1 year ago
MODERATORS