4 ms·
This is cute. This is clever. Whether or not it's too clever time will tell. A year ago, I noted that Rust was starting out at roughly the cruft level C++ too
by Animats 10y ago
This is cute. This is clever. Whether or not it's too clever time will tell. A year ago, I noted that Rust was starting out at roughly the cruft level C++ took 20 years to reach. Rust is now well beyond that.
All this "futures" stuff strongly favors the main path over any other paths. You can't loop, retry, or easily branch on an error, other than bailing out. It's really a weird syntax for describing a limited type of state machine.
I'm not saying it's good or bad, but it seems a bit tortured.
- steveklabnik 10y agoWhat's your definition of "cruft," and where does it appear in Rust? I will be the first to admit that Rust is not perfect, but that adjective does not come to mind. I am of course incredibly biased.
- vvanders 10y agoCruft? Coming from C++ I find it quite the opposite.
- pcwalton 10y ago> All this "futures" stuff strongly favors the main path over any other paths. You can't loop, retry, or easily branch on an error, other than bailing out. You can do all of that.
- Animats 10y agoOK, make an HTTP request, and if it fails, wait 2 seconds and retry. After 10 times, give up.
- pcwalton 10y agoTimeouts are covered here. http://alexcrichton.com/futures-rs/futures/index.html#examples http://alexcrichton.com/futures-rs/futures/index.html#exampl... As for repeating something multiple times, you would either repeat the chain 10 times or write your own future combinator. Probably writing a custom future combinator would make the most sense here; actually, such a thing ought to be built-in to futures.rs.
- Animats 10y agoThat's the problem - having to roll your own control structures. IF, WHILE, and FOR cover just about everything. This semi-functional style doesn't break down into a small number of simple, well-known primitives.
- Manishearth 10y agoHow does futures count as cruft? It's a pure library. This is like saying GObject is cruft in C. It is a library that some folks don't like (like most libraries), but it is not part of the language and nobody is forced to use it in their code. Why do you think Rust has cruft anyway? It has a lot of typesystem features, yes, but this is no different from languages like Haskell. These features work together nicely and are useful. C++ has lots of features which for better or for worse have been hacked in to the language (can't be made an organic part of the language because backcompat). This is not the case with Rust (or D, which is to me a cruft-less organically-designed C++)
- Animats 10y agoYes, it's a pure library. But this sort of thing is becoming standard for Rust. If your code isn't full of "foo.and_then(|x| ...)" it's uncool. This isn't "functional"; these functions have major side effects. The bothersome thing is that the control structures of the language are hidden under object-specific functions. "Things really start getting interesting with futures when you combine them. There are endless ways of doing so." I'd rather have "there's only one way to do it", as in Python, rather than "endless ways of doing so". That usually leads to code that's hard to read and debug. As in "how did control get there?". At least in traditional code, you can see control flow easily. Adding an user-definable level of abstraction hides that.
- andrewflnr 10y agoYour definition of cruft is rather strange. Yes, Rust code can be kind of complicated and messy-looking, but it makes sense when you think about it. All the parts justify their existence. IMO, cruft is stuff that doesn't make sense or is extraneous; incidental rather than essential complexity, in general.
- Manishearth 10y ago> This isn't "functional"; these functions have major side effects uh, no, I've rarely seen adaptors like and_then being used with side effects (folks use regular loops if they want that). Rust doesn't have a strict notion of purity, but that doesn't mean that most rust code isn't pure. There's nothing wrong with having lots of adaptors scattered around the code, either. It's not less readable, it's just different. > There are endless ways of doing so." I'd rather have "there's only one way to do it", as in Python Uh, "there are endless ways of combining future adaptors", not "there are endless ways of solving a problem". Each combination of adaptors solves a different problem (mostly). > That usually leads to code that's hard to read and debug This is async code. This has always been hard to read and debug. Futures make the control flow more explicit, if anything (especially if you have async and await), because the flow is now in one place, at least. Grokking manual event loop code is much more annoying. Sure, the async argument doesn't apply to regular iterators and Option. However, these "object specific functions" are not object specific. All futures have the same adaptors. All iterators have the same adaptors. The only special objects with their own set of such methods are Result and Option. These share the names of the methods, and these are used often enough to justify it. There aren't that many of them either, so this really isn't that big a deal. You just need to know what each of this small number of methods does. It only hides control flow if you're not aware of these methods, which is a state of mind that goes away quickly after the first few rust programs. Besides, because of the closures it's pretty obvious that some tweaking of control flow is happening, so it isn't hidden. You can check the docs for that function to know exactly what the tweaking is. I also don't know what you mean by "traditional code", this pattern is exceedingly common in languages which aren't C or C++.