14 ms·
I like this explanatory comment by Manishearth, a Servo dev, in the thread over on /r/rust: "This blog post brought to you by the 'how many times can you say '
by kibwen 9y ago
I like this explanatory comment by Manishearth, a Servo dev, in the thread over on /r/rust:
"This blog post brought to you by the 'how many times can you say 'fearless concurrency' and keep a straight face' cabal.
"Seriously though, I now appreciate that term a lot more. One thing that cropped up in the review of this post was that I didn't have examples of bugs Rust prevented. Because I couldn't think of any concrete ones. Because Rust's safety doesn't work that way, it prevents your concurrency bugs before you realize you had them, by making sure you don't paint yourself into a corner. 'Fearless concurrency' really is the best way of putting this; the benefit was not that it prevented concrete bugs, but that it let us fearlessly and aggressively write code knowing that it would be concurrency bug free."
https://www.reddit.com/r/rust/comments/7cwpbq/fearless_concurrency_in_firefox_quantum/ https://www.reddit.com/r/rust/comments/7cwpbq/fearless_concu...
- pimeys 9y agoI've built now several concurrent services with Rust. The language definitely gives confidence to try several things with different approaches to concurrency. None of my services crash (except once per 3-4 months when I deployed something "that will never crash" using `.unwrap()`). The crashes are always my own laziness, but if I follow the pattern of checking return values and unwraping only when the input is static and visible a few lines before, the resulting programs are fast, have a small footprint and basically never crash. Oh and the tooling! I hope other projects take a serious example how cargo works. It's very hard to use any other build system.
- rkangel 9y agoNote that the panic you get by calling unwrap() where you shouldn't isn't a crash. It's a controlled program exit due to an unexpected condition. While yes, the panic will cause your program to stop, it will do it in a clean deterministic way (with a backtrace). Actual crashes (due to segfaults) can happen a long way from the bug that actually caused the issue, can happen intermittently and generally be a nightmare to debug.
- pimeys 9y agoThank you for correction. My native language is not English, but I meant a controlled exit. It requires a bit of thinking how your library is structured when you need to avoid unwrap(). But in the end the result just works and I like how Rust forces a certain design to be safer.
- alkonaut 9y agoI think the use of the term "crash" varies. While it's true for e.g. a C program that there are better or worse crashes, in most other modern langs with some more safety guarantees, the term "crash" is normally used for controlled program termination due to unhandled exceptions. So coming from that type of language (where you can't segfault) I'd definitely call a panic a "crash" simply because it's the analog of an unhandled exception, which I always called a crash. So this terminology probably varies between ecosystems
- eru 9y agoFor yet another different, but related, use of the word, check out 'crash-only software': https://lwn.net/Articles/191059/ https://lwn.net/Articles/191059/ or https://en.wikipedia.org/wiki/Crash-only_software https://en.wikipedia.org/wiki/Crash-only_software It's a concept implemented in eg Erlang. Crash in their sense means basically, 'kill -9'.
- chriswarbo 9y agoIt's interesting that the phrase "unhandled exception" has crept so pervasively into our terminology, since "exception" has connotations (e.g. first-class values representing errors, which we can construct, pass around and "throw") and "unhandled" implies that they could be "handled". Haskell is a great example of how handling errors can be harmful, since it violates confluence, even though throwing errors is fine! Confluence is the property that evaluation order doesn't change the meaning of a program, e.g. we can do: (1 + 2) * (3 + 4) 3 * (3 + 4) 3 * 7 21 Or: (1 + 2) * (3 + 4) (1 + 2) * 7 3 * 7 21 We could inline some function calls if we like, thanks to referential transparency; we can even evaluate "under a lambda" (i.e. evaluate the body of a function before calling it, or evaluating the branches of an `if/then/else` before picking one); regardless of which way we evaluate, if we reach an answer (i.e. don't get stuck in a loop) then it will be the same answer: (1 + 2) * (3 + 4) (1 + 2) * (if 3 == 0 then 4 else pred 3 + inc 4) (1 + 2) * (if 3 == 0 then 4 else pred 3 + 5) (1 + 2) * (if 3 == 0 then 4 else 2 + 5) (1 + 2) * (if 3 == 0 then 4 else 7) (1 + 2) * (if False then 4 else 7) if (1 + 2) == 0 then 0 else (if False then 4 else 7) + (pred (1 + 2) * (if False then 4 else 7)) if (1 + 2) == 0 then 0 else 7 + (pred (1 + 2) * (if False then 4 else 7)) if 3 == 0 then 0 else 7 + (pred (1 + 2) * (if False then 4 else 7)) if 3 == 0 then 0 else 7 + (pred (1 + 2) * 7) if False then 0 else 7 + (pred (1 + 2) * 7) if False then 0 else 7 + (pred 3 * 7) 7 + (pred 3 * 7) 7 + (2 * 7) 7 + 14 21 Exception handlers break this, since we can write expressions like: try (head [42, Exception1, Exception2]) catch Exception1 -> 1 Exception2 -> 2 We can evaluate this one way: try (head [42, throw Exception1, throw Exception2]) catch Exception1 -> 1 Exception2 -> 2 try 42 catch Exception1 -> 1 Exception2 -> 2 42 Or another way: try (head [42, throw Exception1, throw Exception2]) catch Exception1 -> 1 Exception2 -> 2 try throw Exception1 catch Exception1 -> 1 Exception2 -> 2 1 Or another way: try (head [42, throw Exception1, throw Exception2]) catch Exception1 -> 1 Exception2 -> 2 try throw Exception2 catch Exception1 -> 1 Exception2 -> 2 2 This gives 3 different answers. Note that the throwing itself doesn't cause this problem, because we treat an "unhandled exception" as not getting an answer (equivalent to an infinite loop). When I first grokked this it was quite enlightening: adding features to a language can make it less useful. It's not that certain features (like throwing or catching exceptions) are "good" or "bad", but that we must think of languages as a whole, and knowing that some things aren't possible (like observing evaluation order) can be just as useful as allowing more things. This contrasts strongly with the tendency of languages to accumulate features over time, especially when the major justification is often "we should have it because they do" :) There's also a nice discussion on errors vs exceptions at https://wiki.haskell.org/Error_vs._Exception https://wiki.haskell.org/Error_vs._Exception
- atilaneves 9y agoWhat would you say are the advantages of cargo over any other package manager / build system?
- vanderZwan 9y agoQuoting what I just replied in that thread: > Given that this Servo code replaces an existing code base, couldn't we get a "guestimate" by looking at how many unsolved bug reports are now closed because their associated previous (presumably C++) code has been replaced? How many open bugs existed in Stylo's precursor that are removed now?
- wtetzner 9y agoBut was the existing code base that was replaced running concurrently?
- vanderZwan 9y agoAh, true. But I thought Rust was supposed to help with more than just concurrency related bugs?
- Zenbit_UX 9y agoI'd love to know what this concurrency thing is and why it's so fearless in rust.
- CodesInChaos 9y agoRust ensures that while one thread is accessing a datastructure that no other thread will modify it. It does this by only allowing you to have either one mutable or multiple readonly references to a datastructure. Code marked unsafe could violate this, which is why it should be rare and well reviewed.
- odabaxok 9y agoHere is a nice game about concurrency. It should answer your question why it should be feared by understanding how it works: https://deadlockempire.github.io/ https://deadlockempire.github.io/ As of my understanding it is fearless in Rust, because the problems that might came up are solved on language level or the compiler warns you about them. (I have never coded Rust, I just deduced this from the comments)
- ekidd 9y agoI've spent the last few days aggressively parallelizing some Rust code with crossbeam, and it's really just... painless (once you're used to Rust). Rust actually understands data races, and it grumbles at me until my code is provably safe, and then everything Just Works. The Rayon library is also lovely for data parallelism. Sometimes, I think, "Rust is basically a nicer C++ with the obvious foot guns removed and great tooling", but then there are those moments where I'm just blown away by what a good job it does. (I think it helps that I have some functional programming experience under my belt, and that I tend to use mutability sparingly, and mostly in very simple ways.)
- StavrosK 9y ago> painless (once you're used to Rust) This needs to be Rust's motto or something.
- kbenson 9y agoRust: Front-loading the pain so the rest is relatively easy. Just like High School. ;)
- naasking 9y ago> This needs to be Rust's motto or something. Rust: climb that mountain so you can see further.
- forgot-my-pw 9y agoRust: it's relatively easy when you're an expert!
- StavrosK 9y agoRust: Expected String, got str.
- Buttons840 9y agopainless (after some amount of pain)