3 ms·
Interesting. Coming from an FP background I'd say the opposite - the confusing part of Rust is all these special-case imperative control flow keywords, a more s
by lmm 7y ago
Interesting. Coming from an FP background I'd say the opposite - the confusing part of Rust is all these special-case imperative control flow keywords, a more smalltalk-like "everything is just values and functions" syntax would be the best way to simplify it.
I'd agree with stepping away from guarantees about when allocations happen etc. But I think at the point where you remove those from Rust you really just have OCaml.
- cmrdporcupine 7y agoWell, it'd be OCaml without a garbage collector. And to be honest, that would be a very useful and handy language for systems development.
- masklinn 7y agoOCaml has for and while loops. Its for loop is even more imperative than Rust's (which simply drives an iterator, whereas OCaml's has "for a to b" and "for b downto a"). OCaml doesn't have break or continue though.
- lmm 7y agoOCaml is already a good language for systems development - people are far too scared of garbage collectors. And if you make the changes in the article then I think you give up most of the concrete benefits of non-GC - you won't have easy C interop without control of stack/heap/allocation, and since trait objects could end up nested arbitrarily far, I think you might still get GC-like pauses where a simple-looking code line ended up doing an arbitrary amount of unwrapping and freeing work.
- cmrdporcupine 7y agoI guess it depends on your definition of systems development. If you mean "writing systemsy applications" like IoT things or whatever, sure, fine, a GC isn't going to be an issue and probably will help. If you're talking about a language to write drivers or an operating system, etc in then a GC is just a big No. In that domain we don't even have Malloc/Free, let alone GC services. Having the overhead and normative lifestyle assumptions of _any_ kind of runtime is a big Nope.
- wiml 7y agoMirage exists and works reasonably well.
- atombender 7y agoCounterpoint: The Oberon System successfully implemented a garbage-collected OS kernel: https://en.wikipedia.org/wiki/Oberon_(operating_system) https://en.wikipedia.org/wiki/Oberon_(operating_system).
- viraptor 7y ago> special-case imperative control flow keywords, Which ones do you mean?
- masklinn 7y agoNot OP but from what they're saying I'd guess loop, while, for, continue, break, return. Possibly do (which is reserved but not used), could be a do{}while or a monadic block, who knows. Though it should be noted that Smalltalk provided a non-local return.
- 0815test 7y ago> a more smalltalk-like "everything is just values and functions" syntax Can you do that sort of thing without a GC? Some functional languages use tailcall as their control flow primitive, but that's just a glorified GOTO.
- lmm 7y agoI don't see why not? Rust has first-class functions and its lifetime support is supposed to be a big selling point, so it ought to be possible to implement things like "if" and "for" as userspace functions - and if not, then that suggests important limitations to its lifetime/ownership model.
- _bxg1 7y agoI think one thing that confuses people about Rust is it sends mixed signals with regard to functional vs imperative. It gives you lots of nice functional toys - closures, implicit returns, pattern matching - but you end up having to write a lot of imperative stuff too. I've found that Rust flows much more nicely when you just embrace an imperative style "by default". That's its native tongue; the functional stuff is more of an exception. Those of us used to multi-paradigm languages have taught ourselves that imperative == bad (actual for-loops! egads!), but the thing is, Rust is specifically designed to make it not-bad. It gives you all these tools to carefully control and limit mutability, so you can do imperative stuff with much less fear. It takes getting used to but in my (limited) experience this mindset significantly reduces friction when working with Rust.
- skohan 7y agoI haven't spent a lot of time with FP languages over the years, but implicit returns are one of my least favorite features of Rust. Especially the use of semicolons to denote a terminated statement vs. a return value: a semicolon-related typo is such an easy mistake to make, and an annoying reason for a build to fail, especially when so many modern languages have shown it's quite possible and pleasant to work without semicolons.
- steveklabnik 7y agoTo be clear, Rust does not have "implicit returns" nor does it use semicolons to indicate return values. Expressions evaluate to a value, and semicolons take an expression, throw away its value, and evaluate to () instead. That's it. The other behaviors you're talking about fall out of these semantics, but are also different than what you've said; functions evaluate to a value, so the final expression's value determines the value it evaluates to, but you cannot "implicitly return" from the middle of a function by dropping a ;, for example.
- _bxg1 7y agoWhat I meant was the fact that you can omit the "return" keyword: fn foo(x: i32) -> i32 { x * 2 }