5 ms·
This is a neat experiment, kind of making Rust look more like f# or haskel. I admit that Rust can get a little verbose, so I'm happy to see folks taking a fresh
by zengid 5y ago
This is a neat experiment, kind of making Rust look more like f# or haskel. I admit that Rust can get a little verbose, so I'm happy to see folks taking a fresh perspective towards it.
While I like `^` for marking mutability, other things might not need to be so abstract (`=:` instead of `fn`) or re-purposed, like using `|i|` for loops instead of a Rust closure.
- zozbot234 5y agoRust does get a little verbose, but this syntax proposal isn't doing much to simplify it either. It's mostly a lexical choice of symbols over reserved words, but the amount of separate symbols is IMHO a bit too high for comfort. (The choice of semantic indentation leads to additional drawbacks when copy/pasting code.) Reserved words may be inelegant in principle (since they intrude on the namespace for identifiers), but at least they're easier to type on most keyboards. And Rust seems to be going for a rather minimalistic syntax already. It's certainly not as verbose as languages in the BASIC, Pascal or Ada lineage, let alone Cobol.
- bscphil 5y ago> I admit that Rust can get a little verbose Heh. As a self-taught developer with a dumb ape brain, if anything I wish it was more consistently verbose. I've read through the Rust book and tutorials multiple times, and I've still not been able to wrap my brain around how lifetimes work. Personally I think the incomprehensible <a'> syntax has a lot to do with that. I'd love to see a kind of pseudocode that compiles to rust simply for the purpose of making it easier to learn the real language. Maybe you're thinking "wait, lifetimes are easy, you just..." but I think the reality is probably that most people who want to learn programming on their own, don't have a job in the field, and have never had a compsci class are going to have trouble wrapping their heads around the concepts. I can write good Python code. I can write safe C code (because it's easy to understand explicit allocation and freeing of memory), but I've never been able to make lifetimes work in my head. The complexity of rustc's error messages doesn't help much either, last time I tried it.
- zozbot234 5y agoIf anything, lifetimes are one key part of Rust where I don't really see how a different syntax would help. The <'a> and &'a syntax is nicely self-contained, but the semantics can be obscure to novices.
- unrealhoang 5y agoI don't see how different syntax can have any impact on the understandability of lifetime. Imagine every usage of `'` will be replaced with a `lifetime` keyword, `<'a>` becomes `<lifetime a>`, `&'a b` becomes `&lifetime a b`, I'd argue it would make the situation even worse. Lifetime in Rust is actually an explicit generic type system over lifetime is a new concept (you would not see it anywhere else) so it will indeed feel alien as you can't map it to other construct that you have already learned in other language. So to learn it you must treat it as such: a new concept, learn it by remember how you first learned recursive (yes, Rust's lifetime is not harder than recursive), pointers, ... Don't expect it to be easy or familiar because you already know how to code in other languages. I see many people struggle with learning Rust just because of this weird expectation that new language should be *very* similar and they do not have to spend much effort to understand.
- bscphil 5y agoPart of the issue is just that Rust is actually very good at working out lifetimes in certain situations, so they become implicit. This makes it even harder for the inexperienced to know when and why one has to specify a lifetime, as well as what the lifetime ought to be. The issue isn't so much that you can't map lifetimes onto a concept from another language so much as it is that you can't map the concept onto anything you already know at all. If you know what a function is (i.e. you've taken an algebra class required of all U.S. students), you can work out for yourself in 10 minutes how a recursive function works. It may be surprising at first that a recursive function can return a value (instead of just calling itself forever), but by examining a simple one (like nth Fibonacci) any student with an understanding of algebra can determine that it does. Incidentally, most high school students who progress as far as calculus meet with recursive functions like the following (though usually not expressed with this notation): f(x) = x/2 + f(x/2) I'd say the concept of a function is itself something new and extremely difficult (I remember finding the syntactic ambiguity between function notation and multiplication very confusing), but fortunately most students encounter it well before they ever try programming.