Live data from Hacker News

Rust is for Professionals

gregoryszorc.com

151–157 of 157 posts

Re: Rust is for Professionals

#151
Anyone who has a bunch of rust experience: does writing things like mutable tries, or other data structures with complex ownership semantics ever become truly natural? I find rust really straightforward to write when the ownership is straightforward, but I find myself out of my depth in a lot of cases.

Re: Rust is for Professionals

#152

Earlier quoted context omitted.

For web work, are there benefits to using Rust over a garbage collected language that also benefits from a similar type system?

Do you have a specific language in mind? Honestly, I don't feel that I spend time managing memory in Rust: I use ARC pointers for long-lived shared object (Database connections pool, mailer...) and otherwise the ownership is pretty straightforward during the lifecycle of a request, data is moved from the top layer (HTTP handlers) to the bottom (Repositories to access Database) and back for the response.

From my limited knowledge, Rust's type system is quite close to the ML family-- so perhaps F# would be a general-purpose GC'd language equivalent?

I am mainly interested to know how much overhead time is spent appeasing the borrow checker and managing memory that would otherwise free up mental cycles if a GC were available . The async story for Rust also seems confusing (but I hold my hands up and plead ignorance on this count).

Re: Rust is for Professionals

#153
post #39

Earlier quoted context omitted.

I mean yeah, that's why I went and read a bunch of the book. But I still run into lots of issues. Like what the hell is a borrow cow and when would I want to use it? And how do I fix the "temporary value dropped when borrowed" error in a series of maps on options?

If you don't mind sharing snippets for the diagnostics you couldn't figure out, I would love to see them in case we can mechanically suggest the appropriate code, but in general a well placed .clone(), .cloned() or .collect() will be what you want. Likely what's happening is you're iterating over a sequence (you can think of options as a sequence of only one iteration as well), but that iterator is over borrows of th…

I have to agree that at the beginning those unfortunate names (Arc, Cow) confused me more than they should, given that I know perfectly well what Copy on Write and reference count means.

If only it was spelled CoW and ARC I would very quickly grasp it (probably).

But it's an extremely minor inconvenience and arguably makes the whole thing very memorable

Re: Rust is for Professionals

#154
post #97
post #12

Here I am on day three of an attempt to modify a rust program with logic that would have taken about twenty minutes to implement in C# or Java. It has to do with operations on strings (use a regex to find a string in some text, escape all the regex-reserved characters in that string, then use the string as a regex to find other occurrences of itself in the text) so I get that I'm really thrown into the borrow-checker…

> use a regex to find a string in some text, escape all the regex-reserved characters in that string, then use the string as a regex to find other occurrences of itself in the text) This took 2 min: https://play.rust-lang.org/?version=stable&mode=debug&editio... and I don't recall what's the last time I used the regex crate. I'm certainly doing all the regex stuff incorrectly, no idea how to match regex-reserved char…

Also, this function is just regex::escape https://docs.rs/regex/1.4.5/regex/fn.escape.html

Re: Rust is for Professionals

#155
Even learning Rust on the surface already change a lot on how you perceive errors, type-based error, thread-safety, expression-oriented code and lifetime.

I write typescript for work. I have adapted some concepts such as the encoding invariants into type (using a proven library such as fp-ts and io-ts) and using return over throw for error handling has been yielding better and scalable code.

Not to mention Rust's types for managing concurrency and shared objects, like Rc, Arc, Mutex, that drive the architecture of your software. I have been doing a similar thing in my projects in other language and the impact has been very positive

Edit: typo

Re: Rust is for Professionals

#156
post #74

> Rust Makes You a Better Overall Programmer I agree with that, but this applied to nearly any language for me. I started doing Python back when 2013, then i learned Go, i started writing better Python code, then i learned C, i started writing better Go code, then i learned Rust, i started writing better code in general. The more you play with other language the more you learn other programming paradigms, it changes…

Well, it's like saying that wearing a straightjacket makes you a better person.

Just like a straitjacket stops you from hurting others, Rust stops you from writing memory unsafe code.

Re: Rust is for Professionals

#157

Earlier quoted context omitted.

It is. It's not going to replace Python, and if maintenance is the metric, then "rewrite it in rust" is not the right move. But I do think Rust will gain traction, be a round a long time, and slowly become a complement to existing C/C++ ecosystems through wrapping and binding. I'm just not sure the other way will materialize. Until Rust can be used to feed back into C/C++ ecosystems and long-standing projects (like t…

At this point Rust is not the prmary ecosystem for anything. The important and exciting new things are written in C++, not Rust. Rust has no advantages over C++ once you know C++.

I would counter then that it's impossible to ever "know C++" then given that even C++ experts write in memory-based security exploits from time to time.
Post reply on HN