6 ms·
Rust Cookbook
- reificator 8y agoWhere can I go to suggest new "recipes"? I see that it starts with random numbers, but when I was learning I got tripped up a bit when trying to generate seeded randoms.
- steveklabnik 8y agoThe little “edit” button at the top takes you to the github repo, filing an issue is the way to go. It might take some time to respond to, because this project got really far but not quite across the finish line, and I think the main maintainer has dropped out. We’ll get to it...
- amelius 8y agoI'd like to see an official recipe for using closures as callbacks (for example in a UI library), where variables in outer scopes are potentially modified from within the closure. See e.g. [1] for a possible approach. [1] https://gtk-rs.org/docs-src/tutorial/closures https://gtk-rs.org/docs-src/tutorial/closures
- steveklabnik 8y agoI’m a bit torn about this one, because it’s not universally clear that this is the correct way to build these kinds of systems in Rust. GTK has to due to the constraints of the system it binds to, but there’s a lot of experimentation of different ways that may be more Rust-y and not have the huge pain points this approach has. Once its sorted, I think comparing and contrasting this kind of thing would be amazing though.
- amelius 8y agoWhat would be an alternative, equally flexible way to handle callbacks?
- steveklabnik 8y agohttps://raphlinus.github.io/personal/2018/05/08/ecs-ui.html https://raphlinus.github.io/personal/2018/05/08/ecs-ui.html is an entry point into the main alternative that’s being explored, see “druid” as a package that’s an implementation of (an evolution of) these ideas, though it’s still early days. In general, Rust hates big balls of intertwined mutable state. And traditional OOP-y UI frameworks are basically giant balls of intertwined mutable state. You can do it, but it’s not great. We’ll see.
- int_19h 8y agoRealistically, this is still a necessity, because even if Rust comes up with its own quality UI frameworks - which takes years, looking at the history of the ones that we have - some people will still need to integrate with what's already there.
- steveklabnik 8y agoSure, it's still necessary, but that doesn't mean that it needs to be promoted as the correct pattern to use in the general case.
- bibyte 8y agoAnother great book that is completely free and open source. Rust might be a little harder to learn then other languages but you can't deny that it has great resources if you decide to learn it.
- adamnemecek 8y agoI wouldn’t say harder, like learning c++ well (patterns + concurrency etc) is legit hard. Same for other languages. Rust has surprisingly few concepts, it’s just that they combine nicely.
- jayd16 8y agoIt's harder like people think static typing is hard. It's more about how many concepts you need to be aware of to write something. Garbage collection is a complex topic you can ignore at first, for example. Rust pointer management takes immediate investment. Even freeing pointers you can be lazy about at first. Rust makes it easier to write good code at the cost of making it hard to write bad code.
- mjw1007 8y agoI find myself able to deny that it has great resources. The reference manual is very weak.
- steveklabnik 8y agoIt’s going to be a big area of work this year!
- jake_the_third 8y agoThis is really good news. Hopefully a more well-developed and thorough reference will allow for a GCC rust frontend to be developed.
- steveklabnik 8y ago
- danso 8y agoIt's been awhile since I've done anything resembling C/C++, and have put off looking too much into Rust for the moment, but I was surprised at how readable the examples on CSV processing were: https://rust-lang-nursery.github.io/rust-cookbook/encoding/csv.html https://rust-lang-nursery.github.io/rust-cookbook/encoding/c...
- nukeop 8y agoOne of Rust's major advantages over C and C++ and a huge reason why I choose it for new projects that call for a low level language is better learning resources. Others are better, established tools (like cargo), helpful community, sane dependency management, and expressive syntax. Even if it didn't have any of the borrow checking features I'd still use it just for those reasons alone. It can also be painlessly integrated into Node.js programs as native modules and interoperability makes a Rust + Node combo a perfect mix for many use cases.
- stochastic_monk 8y agoIf I wrote a different kind of C++ (not competing for state-of-the-art speed), I would absolutely use Rust. Package management, versioning, debugging; everything is just more convenient. It’s not quite as expressive as I’d like, but that may yet change, too.
- pducks32 8y agoI love all of Rust’s documentation it has really been great to see as I learn the language. I can pick up a language easy enough but to pick up a language’s specific idioms is really hard without examples and this resource is great for that. One issue I have had though is how often the resource is out-of-date in some sense. Rust 2018 switched how modules were included and I constantly was confused what the difference was until I learned one was just older (by like a month). Also error handling is very confusing for me. I used error-chain first and everything worked but then I heard failure was the way to go yet there are very few resources on using either idiomatically.
- saagarjha 8y agoThis is nice, but it looks like some of these rely on third-party dependencies to make the examples trivial. I'm not really sure it's useful to have an example for say argument parsing which is essentially "here's how to use this argument parser from GitHub".
- sanxiyn 8y agoIt's useful for people who want to do argument parsing.
- saagarjha 8y agoI get that, but that makes it less a "Rust Cookbook" and more "here's some high-quality libraries that do common tasks".
- 2bitencryption 8y agoI think that's part of the philosophy of Rust, though. The crate system should be robust enough that the most common tasks can be handled by whatever becomes the community's de-facto standard. If you need something simpler than the community's choice and don't want a dependency, roll your own. Otherwise, the ecosystem has you covered. I will admit that I don't understand why Random is its own crate, and not in the standard library, however...
- nicoburns 8y agoLargely because the design wasn't finished in time for the Rust 1.0 release, and they didn't want to commit to the API. This way of doing things has it's advantages though. People are still coming up with new ways of generating random numbers, and in an external library you can release a major version and remove deprecated functionality without breaking anybody's code.
- int_19h 8y agoFor comparison, here's how it worked out with C++, which now suffered through not one, but (if you count the original C standard library) two iterations of random number generation APIs with significant flaws in them. http://www.pcg-random.org/posts/cpp-seeding-surprises.html http://www.pcg-random.org/posts/cpp-seeding-surprises.html