Live data from Hacker News

Rust: “Explain GATs Like I'm 5 Years Old”

old.reddit.com

111–120 of 193 posts

Re: Rust: “Explain GATs Like I'm 5 Years Old”

#111

Earlier quoted context omitted.

I hope you don't. To establish my credentials for this comment - GATs were my idea. The entire point of GATs was to carve out a design space that solved peoples' problems without being so high-minded as monads and HKT and so on. Unfortunately, a lot of people who like monads like to talk about GATs in the same way. But its really as simple as this: when you add an associated type to a trait, you can make that type ge…

Not trying to make you feel like you have failed, but whenever I encounter language features on this level - aka not comprehensible for a mortal like myself - I do tend to want to shamefully turn away from this profession entirely. The good news is that I am most likely a total dunce. I wish I could become reasonable with rust because I do like the concepts that I think I grasp.

When I find a language feature I don't understand even after reading what's out there, I ignore it. Then I plod along with my own code. Eventually I'll notice I've been writing the same boilerplate code again and again, and I'll finally see the use for the feature. At that point it's less a matter of "understanding" in a grand intellectual sense, and more just fitting my needs to the syntax. After a few such instances, I know the feature well enough to unblock someone else who doesn't get it. That's a good practical test of understanding.

TL;DR: don't worry about it. When you need it, you'll learn it.

Re: Rust: “Explain GATs Like I'm 5 Years Old”

#112

Earlier quoted context omitted.

>Stick to things like apple, orange, pear While I am no pedagogical psychologist, I have witnessed mutiple times, how poor unrealistic examples give people a bad understanding of the thing they are trying to learn. Going with Apple, Orange, Pear would give people an idea of what the keywords did, but no understanding of when it was a good idea to apply the technique. I think that is one of the primary reasons OO suck…

The solution to this is to have two examples: Beginner and Practical/Advanced

I think the point is that even for beginners these examples are dumb. If you want to explain OOP and inheritance you can use simple but realistic examples, like `class Shape { fn draw() }`, `class Rectangle extends Shape`, `class Circle extends Shape`, rather than `class Dog extends Animal` or some dumb stuff like that.

Re: Rust: “Explain GATs Like I'm 5 Years Old”

#113

Earlier quoted context omitted.

>Stick to things like apple, orange, pear While I am no pedagogical psychologist, I have witnessed mutiple times, how poor unrealistic examples give people a bad understanding of the thing they are trying to learn. Going with Apple, Orange, Pear would give people an idea of what the keywords did, but no understanding of when it was a good idea to apply the technique. I think that is one of the primary reasons OO suck…

The solution to this is to have two examples: Beginner and Practical/Advanced

At only twice the cost! A bargain.

Re: Rust: “Explain GATs Like I'm 5 Years Old”

#114

Earlier quoted context omitted.

>Stick to things like apple, orange, pear While I am no pedagogical psychologist, I have witnessed mutiple times, how poor unrealistic examples give people a bad understanding of the thing they are trying to learn. Going with Apple, Orange, Pear would give people an idea of what the keywords did, but no understanding of when it was a good idea to apply the technique. I think that is one of the primary reasons OO suck…

The solution to this is to have two examples: Beginner and Practical/Advanced

The post you're complaining about starts with "because everyone likes to use that LendingIterator example I would offer a bit non-trivial example." It sounds like they are already doing that.

Re: Rust: “Explain GATs Like I'm 5 Years Old”

#115

I feel like they are making languages too complicated. Most projects should just be garbage collected, most don't need to deal with pointers or anything advanced. We need variables, functions, conditionals, loops, exception handling, struts, and a library with a bunch of standard utilities (including simple I/O and string managment). Everything else should be optional and kept out of sight unless you are looking for…

I will agree with you that most languages should just be gc. Rust is niche; targeted at applications where you need control over memory and layout. It is not a good general purpose language. That being said, most of things you pointed out as “no reason to be this complex” do have good reasons. String and &str could be renamed to StringBuf and StringSlice. The String type lets you manipulate the string value, but it i…

Agreed, people should not assume that the design of Rust is some sort of statement about how higher-level languages should operate. It's a very targeted design with specific goals. For instance, the fact that Rust eschews exceptions should not be interpreted as "exceptions are bad", but rather "we don't think exceptions are a fit for what we're trying to achieve in this one specific domain".

Re: Rust: “Explain GATs Like I'm 5 Years Old”

#116

Earlier quoted context omitted.

I hope you don't. To establish my credentials for this comment - GATs were my idea. The entire point of GATs was to carve out a design space that solved peoples' problems without being so high-minded as monads and HKT and so on. Unfortunately, a lot of people who like monads like to talk about GATs in the same way. But its really as simple as this: when you add an associated type to a trait, you can make that type ge…

Not trying to make you feel like you have failed, but whenever I encounter language features on this level - aka not comprehensible for a mortal like myself - I do tend to want to shamefully turn away from this profession entirely. The good news is that I am most likely a total dunce. I wish I could become reasonable with rust because I do like the concepts that I think I grasp.

GATs seem easily understandable to me and I'm a "mere mortal". Like most things in software, the utility becomes clear when you actually have a practical purpose for its use. Don't get ahead of yourself.

Re: Rust: “Explain GATs Like I'm 5 Years Old”

#117

There is a simple but fundamental observation that many experienced software engineers discover sooner or later: Reading/understanding code is much more difficult than writing it. Because of that, programming languages should be designed to make the reading part as easy as possible. What is the point of those high-level abstract features if they make reading/understanding the code too difficult?

But this feature makes reading code easier? It allows library authors to absorb the complexity into themselves, allowing them to present easier and more convenient APIs for the users of those libraries. Because programs that consume libraries outnumber the libraries themselves, that results in a net reduction in complexity.

Re: Rust: “Explain GATs Like I'm 5 Years Old”

#118

Earlier quoted context omitted.

I hope you don't. To establish my credentials for this comment - GATs were my idea. The entire point of GATs was to carve out a design space that solved peoples' problems without being so high-minded as monads and HKT and so on. Unfortunately, a lot of people who like monads like to talk about GATs in the same way. But its really as simple as this: when you add an associated type to a trait, you can make that type ge…

Not trying to make you feel like you have failed, but whenever I encounter language features on this level - aka not comprehensible for a mortal like myself - I do tend to want to shamefully turn away from this profession entirely. The good news is that I am most likely a total dunce. I wish I could become reasonable with rust because I do like the concepts that I think I grasp.

There are other people, who are also mere mortals, that can understand them. I think you could understand them if you tried. You're not a dunce!

Re: Rust: “Explain GATs Like I'm 5 Years Old”

#119
post #87
post #82

Earlier quoted context omitted.

Wait. Why are Monads complicated? Yes the math definition is complicated, but so is math definition of number 1 in set theory You have a Rust-like enum that contains data like Option or Maybe, you want to abstract over it. There you have a rudimentary Monad.

> you want to abstract over it. What does that mean? Any example you could point to?

Are you familiar with flat_map? It's the ability to take, for example, an iterator, then map over each element which itself can return an iterator.

Similarly, you have Option::and_then, which takes a callback that takes T and returns an Option. Or Result::and_then.

"Monad" is simply the umbrella term for all flat_maps, and things like it, in existence.

Why would you want to abstract over it? For one, it's a surprisingly common design pattern in programming. You also quickly notice, for example, that filter_map is actually just a special case of flat_map since Option implements Iterator.

You can also study the properties of how such patterns behave. Monads are particularly interesting for a number of reasons. Monads are a kind of "most general" and least constrained form of sequencing, and it turns out that if your large-scale system is monad-like it can have a significant performance impact!

You don't need to have a thing called "Monad" in your type system to do any of the above. Having a thing called "Monad" in your type system does let you write code that abstracts over all flat_maps (and things like it) in existence, which has been used in the Haskell world to build a number of interesting libraries. But "monads" as a concept are useful to everyone in programming.

Re: Rust: “Explain GATs Like I'm 5 Years Old”

#120
post #83

Okay, so this is like so in C++: template T> class C{}; Am I right, Rustaceans? :)

You can do similar things with it, but GATs can't live on their own like that. Instead they are always a member of some trait, so a closer comparison would be with something like this:

    class C {
        template 
        using T = ...;
    };
Post reply on HN