11 ms·
Things I hate about Rust, redux
- Aissen 5y agoVery interesting how advanced those grievances are. If that's not a sign of maturity, I don't know what is. Otherwise, seems like a good list, thanks for sharing @woodruffw.
- goombacloud 5y agoFor panic detection or overflow detection there are static analysis solutions but I hope they get more integrated and standardized (as was attempted in cargo-verify)
- sophacles 5y agoI'd like to see a `#[no_panic]` tag similar to the `#[no_std]` one.
- vbezhenar 5y agoHow to you expect it to work?
- adament 5y agoCould you not enforce that functions tagged can only call other functions with the tag and must not call panic? This would not protect against stack overflow or similar environmental panics.
- vbezhenar 5y agoThat's the issue. Rust panics on division-by-zero, Rust panics on out-of-bounds, Rust panics on signed integer overflow in debug mode. Stack overflow can happen on every function call which is also panic. Too many implicit panic sources.
- woodruffw 5y agoYep, exactly something like this! Implementation is the challenging part: the standard library and community ecosystem is full of legitimate uses of panic, and there are instances where panics might appear in the source code of dependencies but not in (optimized) builds.
- nicoburns 5y ago> full of legitimate uses of panic Yes, but the whole point of `no_panic` is that in this context there are no legitimate uses of panic. If that means making a bunch of parallel APIs that return results for this super-correct code then so be it.
- woodruffw 5y agoYou're absolutely right. I meant primarily in terms of the challenge of writing panic-free code while still being a consumer of the crate ecosystem.
- pdimitar 5y agoThat, or a subset of Rust that has all the panicking functions removed and only has std API that works with Result and Option.
- gpderetta 5y agosurely it should be #[DONT_PANIC] in large friendly letters.
- dureuill 5y agoOr implied by the #[keep_calm] attribute
- sophacles 5y agoHah, nice one. I think we could get the unicode folks to accept an emoji form of this: https://thebullelephant.com/wp-content/uploads/2016/12/dontpanic.png https://thebullelephant.com/wp-content/uploads/2016/12/dontp... and alternately accept `#[$UNICODE_FOR_SAID_EMOJI]`.
- chrismorgan 5y agoRust doesn’t allow emoji in identifiers, following the UAX #31 rules. It would require a significant break in someone’s tradition to get such a thing through. … quite apart from the implausibility of getting such a character into Unicode in the first place.
- sebzim4500 5y agoPresumably using `#[no_panic]` would require `#[no_std]`? Would you be allowed to use unchecked arithmetic, which panics in dev builds but not release builds?
- chrismorgan 5y agoWhy would #[no_panic] require #[no_std]? There are perfectly legitimate reasons for not wanting panicking in code that uses std, and it’s possible to panic without std.
- 37ef_ced3 5y agoComplication without benefit.
- jhatemyjob 5y agoRust's popularity is pure mimesis. C is fine, but it's not the hot new tech, you can't get a cool job writing C because it's "unsafe", so now we have Rust. And Swift.
- woodruffw 5y agoI don't think this is what you should take away from this post. Rust makes me very productive as a programmer, and reduces the "long tail" of debugging that I do when I write C and C++ (which I have for over a decade). (And, for what it's worth, there are plenty of "cool jobs" writing C/C++. I have one!)
- pdimitar 5y agoVery curious to hear your take on OpenSSL's Heartbleed bug and would you avoid it if you were the maintainer.
- infamouscow 5y agoOther classes of bugs will take the place of memory safety bugs. For example, I don't think the recent Log4j exploit is a memory safety bug, but could be wrong.
- zbentley 5y agoWithout weighing in on Rust specifically, that's a fallacy, though I'm unsure of the formal name of it: "any solution that doesn't solve all problems is equivalent to the status quo". Nobody is claiming all bugs will go away. But the claim that new classes of bugs will manifest specifically to take the place of memory safety bugs is extraordinary and needs justification. It's a bit like going into the wilderness and packing survival gear: the argument "you don't need a warm jacket, because if you get lost the starvation will kill you even if the frostbite doesn't" doesn't hold up.
- epage 5y ago> Every file in the tests directory is a separate crate, compiled to its own executable. This is a reasonable decision, with undesirable consequences: Other problems with this: - You have to link each test file which can be slow - You get less parallel test running because you've broken things up into smaller parallel batches. cargo-nextest is a proof-of-concept that shows this problem [0] - Fixture initialization reuse becomes trickier Projects like cargo explicitly combine all integration tests into a single binary. I'd love it if we explored implicitly rolling everything up into a single test binary except for any explicit test targets defined by the user. [0] https://nexte.st/book/benchmarks.html https://nexte.st/book/benchmarks.html
- scns 5y ago> You have to link each test file which can be slow Using Mold [0] as the linker might help. Written by the author of lld. Program (linker output size): GNU gold | LLVM lld | mold Chrome 96 (1.89 GiB): 53.86s | 11.74s | 2.21s Clang 13 (3.18 GiB): 64.12s | 5.82s | 2.90s Firefox 89 libxul (1.64 GiB): 32.95s | 6.80s | 1.42s [0] https://github.com/rui314/mold https://github.com/rui314/mold edit: add citation, info, times, link, will -> might, and formatting.
- tlamponi 5y agoFWIW, I tried it on a rust project here, the difference was in the noise range only; that way I knew that I was rather IO limited (linking produces lots of IO) and also that mold benchmarks _may_ potentially overpromise a bit much, at least when applied at my use case.
- skywal_l 5y ago"Crystal has a wonderful and extremely ergonomic macro system that Rust could learn from, one that doesn’t require ad-hoc reinterpretation of language tokens and that integrates seamlessly with syntax highlighting in editors". What about zig, where there is no macros per-se, and you just write zig code which is then interpreted by the compiler...
- woodruffw 5y agoAuthor here: I haven't written any Zig, but I've read a little bit about `comptime` (which I thought was very cool). I like compile-time programming, but I also recognize that it's programmer catnip: we love it because it lets us be clever, including in ways that aren't conducive to maintainability. That's a big part of why I like Crystal's macro system: I think it does a good job of balancing readability, expressivity, but also constraining the programmer away from compile-time gymnastics. But like I said, I have no Zig experience, so it's very possible that Zig has much better ergonomics than I'm afraid of!
- pitaj 5y agoOn the IntoIterator topic: I do think it was a mistake to `impl IntoIterator for &[mut] T` for the collections. I think it would have been better to just standardize on `.iter[_mut]()` instead. Would have avoided the whole "IntoIterator for arrays" issue and would be more explicit.
- epage 5y agoFor me, the reason I like an explicit `.iter()` is because its more refactor-friendly. If I have an existing loop over `&collection` but want to call an iterator method, I have to switch to `collection.iter().enumerate()`.
- pie_flavor 5y agoAnother thing that would have avoided the whole 'IntoIterator for arrays' issue would have been implementing IntoIterator for arrays. What benefit would your version provide over the 2021 edition as-is, and why would it be worth the major consequence of fracturing the iterator system into T, &T, and &mut T, as opposed to &T and &mut T just being special cases of T?
- pitaj 5y agoThe whole IntoIterator for arrays issue was that there was existing code using IntoIterator of the slice deref, which was incompatible with an array IntoIterator impl that would take precedence. A compiler hack was introduced to hide the array implementation on older editions. Requiring `.iter()` to get a reference iterator install of just doing it automatically would have avoided the need for a hack.
- pie_flavor 5y agoThat would require into_iter to behave differently from every other method.
- pitaj 5y agoI have no idea what you mean by this. Currently the following impls exist: (1) `Vec<T>`, `HashMap<T>` (2) `&[T]` (equiv to `slice.iter()`), `&HashMap<T>` (equiv to `map.iter()`) (3) `&mut [T]` (equiv to `slice.iter_mut()`), `&mut HashMap<T>` (equiv to `map.iter_mut()`) All I'm saying that `IntoIterator` should only be used for owned iterators, and it should be standard to provide `.iter()` and `.iter_mut()` for producing reference iterators. That is, only the (1) impls should exist, and the (2) and (3) impls should not. I don't understand how that requires it to act differently from every other method.
- loeg 5y agoYeah, I think I agree with all of this.
- eole666 5y agoWhy is there "redux" in the title ?
- blub 5y agoThis reads like praising by faint criticism. The number one problem Rust has now is that it’s overall not significantly better than C++ and sometimes the reverse is true. I’ve learned for example quite a good chunk of Rust, implemented a project (actually a rewrite from C++) and now I’ve mostly reverted to C++ and Go. The only reason that I’d use Rust is if I had to ensure that a program is memory safe (e.g. it’s planned to be handed over to developers unexperienced with C++, it will be heavily changed in the near future, etc). It’s no coincidence that I’ve only learned a chunk of Rust - I skipped async, concurrency and parts of the standard library which I didn’t need. The language and the ecosystem are big and complex, very comparable to the complexity of C++. It’s in a different difficulty league compared to C or Go and I wouldn’t say that it’s hard per se to learn, as the concepts themselves are similar to C++, but there’s a lot to study, remember and categorize and map in relation to how things are done in e.g. C++. One exception is Rust’s equivalent to C++ template-heavy code which is simply not worth wasting one’s life on. Whoever writes that is either a library developer or an asshat. Compile times are too long and what makes it worse is that everything seems to be distributed as source and has to be compiled. Because cargo is so convenient to use, dependencies are completely out of control: adding a single crate can end up pulling in dozens of dependencies. In my case I ended up with ~150 for ~5 crates! All in all the benefits barely outweigh the costs for me, especially since I know C++ well. Rust to me is a language for large-scale or low-level projects that need solid performance and provable memory safety, but it’s overkill for many things where one can use Go or a simplified dialect of C++.
- royjacobs 5y ago"The number one problem Rust has now is that it’s overall not significantly better than C++" This might be true for your specific use cases, but I've worked on reasonably large projects in both Rust and C++ and the fact that I don't have to chase various issues related to use-after-free, returning local variables, dealing with external libraries or general metaprogramming is definitely causing me to mark Rust as significantly better. As always, if you're a C++ expert you'll bound to disagree, YMMV etc.
- epage 5y ago> The number one problem Rust has now is that it’s overall not significantly better than C++ and sometimes the reverse is true. Maybe we are coming at this from different angles but I disagree. I remember seeing some discussions in the C++ community about challenges with using `std::string_view` that seemed like they were discouraging it and thinking to myself "this isn't a problem in Rust". In fact, I refactored a crate I maintain from cloning objects all over the place to using references. I looked at what i did with my C++ hat on and realized that I'd consider myself irresponsible to do the same in C++ without a *very* high bar to justify it, not just because of the cost of the global analysis to ensure it was safe but the fact that that global analysis would need to be repeated on every subsequent change. Being in Rust, it compiled and I knew I was good. I even had an idea for reducing even more allocations that I thought was safe (20+ years of C++ experience, 10 in life-or-death mission-critical software) and the compiler found a case where I was wrong and the approach doesn't work.
- assbuttbuttass 5y ago> it’s sometimes nice to have the assurance that no code being executed can possibly panic. I struggling to think of any language that can provide this guarantee. Even Python can segfault while executing C extensions. Maybe java?
- loeg 5y agoI think it's a property that you could validate via static analysis in relatively strongly-typed languages. I agree it would be impossible for Python, just because everything can change at runtime.
- ajkjk 5y agoBut most languages don't have all their libraries willing to intentionally panic, so it's not a big deal in practice.
- ansible 5y agoIt would be nice to have an overall scorecard for a library. It would show a bunch of stuff related to the crate: existence of unit tests, fuzz testing, and measures of the test coverage, if the code passes clippy checks, which edition of Rust, and such. We could also grade crates by how many open tickets they have which haven't seen a response, etc. This wouldn't be intended to shame the library maintainers, but more to indicate which projects are active, and which ones have issues fixed promptly. It would be easy enough to also scan the source for sources of panics.
- oefrha 5y agoYou can easily segfault in pure Python: import sys sys.setrecursionlimit(1048576) def recurse(): recurse() recurse()
- orf 5y agoA slightly simpler way is just: import ctypes ctypes.string_at(0)
- 5y ago
- nickysielicki 5y agoI’d like to add one: There is too much control at the language level between static and dynamic dispatch. Slimming down your binaries by using dynamic dispatch requires significant code changes when it shouldn’t necessarily have to. I don’t know what I’d propose instead that wouldn’t be just as bad, but I think it’s a wart.
- loeg 5y agoNot sure I agree with this. The relative similarity between static and dynamic dispatch in C++ is pretty confusing (to me) (edit: as in, 'virtual' vs non-'virtual' methods).
- nickysielicki 5y agoOh, let’s not set the bar so low by comparing to C++. ;) Two ends of the spectrum and I think the ideal is somewhere in the middle.
- chubot 5y ago?? They appear completely different in C++, i.e. virtual functions vs. templates https://eli.thegreenplace.net/2013/12/05/the-cost-of-dynamic-virtual-calls-vs-static-crtp-dispatch-in-c https://eli.thegreenplace.net/2013/12/05/the-cost-of-dynamic... I also wish they were more similar in both C++ and Rust. I find that most programs get more dynamic as they get bigger, get more usage, and get more extensible ... but the tendency is to want them to be as efficient as possible at the beginning.
- loeg 5y ago> They appear completely different in C++, i.e. virtual functions vs. templates Virtual vs non-virtual functions.
- chubot 5y agoOK there is some static dispatch in regular functions with respect to argument overloading, e.g. f(int) and f(char), or obj.f(int) and obj.f(char). But I think what is more commonly thought of as "static dispatch" is various template programming patterns, as in the blog post, which are more flexible, and has equivalents in Rust AFAIK. Overall it does feel like there are too many similar mechanisms that look extremely different!
- andrewmcwatters 5y ago> If that sounds extremely generic to you, it’s because it is! Here are just a few of the ways IntoIterator is used in the wild, using a generic Container<T> for motivation: > • For producing “normal” borrowing iterators: &T for T in Container<T> > • For producing iterators over mutable references: &mut T for T in Container<T> > • For producing “consuming” (i.e., by-value) iterators: T for T in Container<T> > • For producing “owned” (i.e., copying or cloning) iterators: T for T in Container<T: Clone>1 Life is too short for this kind of unreadable crap.
- ncmncm 5y agoIn general, if there is nothing you hate about a language, it always means you don't know it very well. What do you hate about X is a useful interview question, with discussion of the effect, and alternative formulations that might have saved it.
- bluefirebrand 5y agoThat's a great thought, I'm going to keep that one tucked away as a question in my back pocket.
- bazurbat 5y agoThe thing I've hated from the day 1 and still can not forget is the reserving of the "type" keyword. Basically every module has these ugly "tp" or "typ" or "type_" structure members everywhere but type aliases are rarely seen in comparison.
- zozbot234 5y agoRaw identifiers can be used to get around any reserved keyword. So r#type would be as idiomatic a workaround as any. Arguably a lot clearer than the alternatives.