News for hackers. Stuff that matters.
Re:Why is Rust difficult? by bitL on Monday January 22, 2018 @01:01AM (#16202236)
Isn't the problem with Rust that it uses crappy pessimistic heuristics (borrow checker) for essentially NP-C problem, causing complaints where code is perfectly OK? IMO interesting design decision but I am staying away precisely because of this.
Re:Why is Rust difficult? by ohazi on Monday January 22, 2018 @01:07AM (#16202247)
"Crappy pessimistic heuristics"

Are you talking about the borrow checker from half a decade ago? [0] Have you used the language since then? This is FUD -- it's really not hard to get code past the borrow checker anymore. Maybe every thousand lines or so you'll need to add a block or pull a temporary variable out of a one-liner, but the compiler basically tells you exactly what to do when something like that is relevant.

[0] https://pcwalton.github.io/blog/2013/01/21/the-new-borrow-ch...

Re:Why is Rust difficult? by onli on Monday January 22, 2018 @01:36AM (#16202343)
Oh, I'd love if that were true. But in my limited experience with Rust it was still the borrow checker that absolutely made writing in the language hard. That was in 2017. My mental model of what should be safe was not at all the model the borrow checker had. And I really read the documentation about that part of the language.

I guess a confirmation that there were problems there is that they tried to improve the borrow checker in the releases after that.

Re:Why is Rust difficult? by majewsky on Monday January 22, 2018 @05:19AM (#16203282)
I started working with Rust last month, and wrote about 2000 LOC since then. While I had my fair share of errors coming from the borrow checker, I've always found its complaints to be valid and easily resolved. Except for that one time where I tried to shuffle data between different threads and shouted at the borrow checker for two hours, until I realized that the borrow checker was actually right and what I tried to do was literally impossible without data races.
Re:Why is Rust difficult? by smaddox on Tuesday January 23, 2018 @10:44AM (#16214423)
Were you writing functions/procedures under the implicit assumption that they would be executed under a single threaded context? Because Rust does not allow this assumption without using "unsafe". I've run into this before, and it can be a bit irritating, but if there's even a small chance you'll later want to execute the code in a multithreaded context, it will more than pay for the inconvenience. And if you're sure you won't, then you can just throw the data into an UnsafeCell and call it a day.
Re:Why is Rust difficult? by steveklabnik on Tuesday January 23, 2018 @11:41AM (#16214894)
It's not even inherently about multi-threading https://manishearth.github.io/blog/2015/05/17/the-problem-wi...
Re:Why is Rust difficult? by pjmlp on Monday January 22, 2018 @02:20AM (#16202503)
Try to use the borrow checker of this decade to write callbacks in GUI frameworks, without polluting the code with Rc and RefCell, even though it is obvious there is only one path to the data being used.
Re:Why is Rust difficult? by Rusky on Monday January 22, 2018 @03:18AM (#16202762)
Callbacks by definition create multiple paths to the data.

(You can also often get away with Cell rather than RefCell.)

Re:Why is Rust difficult? by pjmlp on Monday January 22, 2018 @03:40AM (#16202874)
> Callbacks by definition create multiple paths to the data.

How come, when you have a struct method, accessing field members only visible to that specific method.

Something that is very easy to do with moving in lambda contexts in C++.

Re:Why is Rust difficult? by Rusky on Monday January 22, 2018 @04:55PM (#16208309)
Because the closure itself contains a reference either to the struct or to its fields. That's the second path, and it can be invalidated by the first path either a) freeing the struct or b) changing its "shape" in memory (resizing a `Vec`, changing enum variants, etc.)

You can alternatively move the struct or its fields into the closure, but then you lose the first path. I know you're not doing that because if you were you wouldn't be having lifetime problems (and you wouldn't be able to share the state across event handlers, so it's not a great solution anyway).

Re:Why is Rust difficult? by pmarcelll on Monday January 22, 2018 @11:23AM (#16205552)
The quoted sentence is not true, but most practical callbacks will create multiple paths to objects via borrows. Or you can move your structs into closures (like in C++). But I think what you originally wrote (using callbacks without Rc/RefCell) is fundamentally hard. You have to guarantee somehow that the struct is still alive when you access it though the borrow in the callback, otherwise you have a memory safety problem.
Re:Why is Rust difficult? by pjmlp on Monday January 22, 2018 @12:39PM (#16206227)
The situation I was having issues is explicitly acknowledged by the NLL RFC as being an issue.

It is related to closure desugaring.

https://github.com/nikomatsakis/nll-rfc/blob/master/0000-non...

Re:Why is Rust difficult? by cortesoft on Monday January 22, 2018 @01:05AM (#16202245)
I think this comes down to philosophy; do you want the compiler to just check that the program works for all the current parts, or to have the compiler make sure that the program will work for all the possible ways the interfaces can be used as described?

Basically, Rust makes you ensure that your code can actually do all the things it says it can do, not just the things it is currently doing. Personally, I find that very helpful; I would rather do the work up front than have to go back and fix a lot of things later as my code grows. This might be based on my experience designing and maintaining very long lived systems, where I wish I had been forced to do things correctly from the beginning.

Re:Why is Rust difficult? by bitL on Monday January 22, 2018 @01:08AM (#16202251)
I'd love if it were able to predict correctness of the program, but it can't (halting problem something). It can only approximate it and to be meaningful, it has to be pessimistic. Which is one more headache to casual developers.
Re:Why is Rust difficult? by bronson on Monday January 22, 2018 @01:25AM (#16202302)
Are you saying that Rust is trying to predict the correctness of the program? Sure, parts like deadlocks and memory use, but the whole thing?

This seems to be a common misconception, maybe from interacting with overzealous Rust fan clubbers.

Re:Why is Rust difficult? by tatterdemalion on Monday January 22, 2018 @01:05AM (#16202243)
Do you stay away from all type systems? This would be an accurate negative framing for any type system, which all necessarily reject some correct programs.
Re:Why is Rust difficult? by bitL on Monday January 22, 2018 @01:07AM (#16202246)
Not really. Just it's super difficult to understand how exactly borrow checker operates and when would it allow program to compile or not, causing all kinds of unpredictable situations and unless you are "black belt"-level, difficulty providing any estimates. Not mentioning loss of morale when you have to fight it every single day.
Re:Why is Rust difficult? by tatterdemalion on Monday January 22, 2018 @01:09AM (#16202253)
This is not my experience using Rust. I had six months of programming experience when I first tried Rust. I definitely got confusing errors at first, but I grasped the system within a month or two. And that was in 2014 - the borrowchecker and especially its errors have way improved since then!

But this is also a very different objection from your initial objection, which was just a statement of fact about type systems for turing complete languages.

Re:Why is Rust difficult? by bitL on Monday January 22, 2018 @01:22AM (#16202293)
I'll take a look once I am done learning another hot language ;-) Thanks!
Re:Why is Rust difficult? by hateduser2 on Monday January 22, 2018 @01:45AM (#16202370)
So your issue isnt about rust, its about changing popularity and language trendiness?
Re:Why is Rust difficult? by bitL on Monday January 22, 2018 @01:57AM (#16202410)
Not at all; currently I am able to write non-trivial programs in >60 languages and ranging from low-level distributed transactions (did own Paxos already) through 3D visualizations, business software, mobile apps, Deep Learning models and AI, system software all the way to advanced ETL pipelines using imperative, functional, logical, co-routine-based, generics, reactive, declarative etc. concepts and am always on the lookout for a better language as I can't find the perfect one ;-) So I want to understand where Rust stands and if it is meaningful investment to learn it, both programming "pleasure"-wise and business sense-wise.
Re:Why is Rust difficult? by pjmlp on Monday January 22, 2018 @02:22AM (#16202508)
Have you tried to write GUI code in Rust?
Re:Why is Rust difficult? by SamReidHughes on Monday January 22, 2018 @01:13AM (#16202266)
Is it? Could you give an example? I've found a borrow checker bug in the current release but the rest of the time its behavior is perfectly predictable. Granted, I wouldn't be surprised if the documentation was horrible, my understanding of the checker is based on one way I would do it.
Re:Why is Rust difficult? by bitL on Monday January 22, 2018 @01:21AM (#16202284)
It's simply one more thing you need to keep in your internal "context" while writing a program, taking mental resources you could spend elsewhere. Perhaps an IDE guiding you and outright rejecting the code or offering code completion that is compatible with borrow checker might be a solution, though we aren't there yet I believe.
Re:Why is Rust difficult? by adrianN on Monday January 22, 2018 @01:52AM (#16202389)
You have to keep the kind of problems the borrow checker nags you about in your mind anyway. Memory errors and concurrency problems don't go away because the compiler doesn't complain about them. Personally, I find it easier to use Rust than C++, because I don't have to worry so much about iterator invalidation and stuff like that.
Re:Why is Rust difficult? by steveklabnik on Monday January 22, 2018 @10:05AM (#16204821)
Experienced Rust programmers usually say the opposite: the borrow checker frees you from thinking about it since the compiler lets you know when you mess up.
Re:Why is Rust difficult? by SamReidHughes on Monday January 22, 2018 @01:22AM (#16202287)
You have the same thing in C++, right?
Re:Why is Rust difficult? by bitL on Monday January 22, 2018 @01:30AM (#16202321)
Yes, and sometimes I wish C++ stayed somewhere in pre C99 levels where a single person could master it. As much as new features are useful, they make codebases unreadable to anyone that doesn't grasp all concepts. Even Google internally "javaizes" C++ and uses a strict subset to keep some sanity. Scala is another language that can go insane in the same fashion if teams don't enforce strict rules.
Re:Why is Rust difficult? by SamReidHughes on Monday January 22, 2018 @03:08PM (#16207444)
Rust is a "Javaization" of C++ checked by the compiler.