4 ms·
I never programmed in Rust, but I had enough experience in C programming to know that segmentation faults are annoying to debug. I heard Rust prevents memory ma
by ayakang31415 3y ago
I never programmed in Rust, but I had enough experience in C programming to know that segmentation faults are annoying to debug. I heard Rust prevents memory management problems at compilation level, so it forces you to create safer program. Given this, I want to ask Rust programmers here: For people who have no experience in managing memory at coding stage (basically programmer who have no experience in C-like language), can such people appreciate what Rust aims to deliver?
- kag0 3y agodisclaimer: I'm not a big rust programmer, but I appreciate it. I think it's a matter of perspective/background. Depending what language you're coming from you might appreciate a lot of the more modern language features, or binary size, or performance. On the other hand, you might already be working with a pretty cutting edge language with a garbage collector or other and decide that Rust has some cool benefits but not worth the switch.
- love2read 3y agoI heavily appreciate the simplification of the memory model. I was able to go from comfortable with typescript/js to comfortable with rust with essentially zero knowledge of manual memory allocation in just a few months.
- jiggawatts 3y agoIn that scenario Rust can be attractive because of its high performance compared to languages with a garbage collector. No matter what Java fans will tell you, any runtime with a GC will have worse overall performance for most large codebases than a compiled language with no GC. Sure, microbenchmarks might not look too bad, but complex software is a different matter. Rust is great for services such as API endpoints, where low latency and high throughput at a low cost are more important that hot reload during development.
- evrimoztamur 3y agoI think so, I wrote an entire video game from scratch in Rust and my experience has been absolutely delightful. I have to manage nulls via Options, cast things explicitly, cannot do dumb stuff like modifying an array while iterating it, etcetera. It’s guiding my code in ways that I wasn’t able to myself, and eventually leading to essentially what is a bug-free game. Imagine! The experience has been far more than just borrow checking, it’s opened up my mind to a lot of concepts that my previous trials with Java, JavaScript, and Python fully obscured in arcane ways. Rust’s compiler is wonderful, and once you get past the ergonomic struggles (which I did by just going through Advent of Code), you’re set.
- oconnor663 3y agoFor people who've never written C or C++, Rust's biggest selling point is usually performance. Porting code from Python to Rust for example often gives 10-100x speedups right off the bat. You could get the same speedups by porting to C too, but Rust lets you do that without giving up the memory safety and package management convenience that you're used to. Even when you don't care about performance, another issue that comes up sometimes is keeping track of mutable state. If you've ever relied on bytes instead of bytearray or tuple instead of list* to guarantee that no mutation is happening in some Python code, you know what I'm talking about. Rust can give you a similar level of control over who gets to mutate what, without making you change the type of your data or pay the cost of copies. It's basically the const/non-const distinction from C, but much stricter. Another way of saying the same thing is that Rust gives you a lot of the legibility/correctness benefits that you'd expect from a functional programming language, but you get to code in the usual imperative style. * And even then, that only prevents assignment to the elements of the tuple. You can still mutate an element internally if it's not also an immutable type.
- dralley 3y ago>> Porting code from Python to Rust for example often gives 10-100x speedups right off the bat. As long as you don't do a couple of things that, while easy to remember not to do once you know them, a programmer used to languages like Python and Javascript might be oblivious to. Things like: * Forgetting to use buffered IO wrappers * Using println!() for high-volume console printing rather than locking stdout and writing to it manually
- MereInterest 3y agoI’m not sure. Looking through different Rust libraries, I tend to see three different styles, depending on previous programming experience. Each mimics the prior experience, with benefits. * Everything is a struct with concrete types. This is closest to C. It benefits from the improved memory safety, without sacrificing speed. * Everything is a Box<Rc<T>>. This is closest to dynamic garbage-collected languages, but with vastly improved performance. * Everything is an “impl Trait”. This is closest to templated C++, but with much better ergonomics. So, while I think I agree with your specific statement that the improved memory management may only be fully appreciated by those that cut their teeth on C’s segfaults and dangling pointers, I don’t think that’s the only benefit of Rust as a language.
- jowea 3y ago> * Everything is a Box<Rc<T>>. This is closest to dynamic garbage-collected languages, but with vastly improved performance. Wait, reference counting everything all the time is faster than normal garbage collection?
- edflsafoiewq 3y agoIt's probably slower, but unlike normal GCed languages, it's not actually anywhere close to everything.
- riku_iki 3y agoI think more importantly it is reference counting across threads, meaning mutexes and breaking memory barrier with large performance penalty.
- MrRolleyes 3y agoI believe you're discussing 'Arc'. 'Rc' is not thread safe.
- riku_iki 3y agothen this is not "closest to GC languages", since GC langs usually provide memory management with respect to concurrency.
- doubloon 3y agoIn my opinion, until you have spent a lot of time debugging C/C++/assembly issues (memory corruption, null pointer crashes, segfaults, build system problems, exception inception, etc), Rust would probably seem like a total waste of time.
- lmm 3y agoIf you're used to e.g. OCaml, and the problem you're solving does not require avoiding GC, then Rust is a more cumbersome language for no real benefit. If you've never used an ML family language then Rust might still be a breath of fresh air even if you don't care about memory management.
- cchance 3y agoI dunno if it's just me but coming from typescript and c# background it honestly wasn't that hard to grasp things, Maybe it's just me but it seems so much easier to grasp than C.
- justincredible 3y ago[dead]