Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More real world example in destructive read documentation #281

Open
bloodearnest opened this issue Apr 15, 2018 · 8 comments
Open

More real world example in destructive read documentation #281

bloodearnest opened this issue Apr 15, 2018 · 8 comments
Labels
good first issue Good for newcomers

Comments

@bloodearnest
Copy link

In the introductory documentation for assignment and destructive reads (pony-tutorial/types/classes.md), a simple example is given of how you can swap a value in Pony with:

a = b = a

I mentioned this was a bit opaque on twitter, and exchanged some comments with @ponylang account, leading to this issue being filed.

It would perhaps be better to given a more concrete real world example here, or maybe link to the section that documents the "awesome things with a capabilities-secure type system".

@SeanTAllen
Copy link
Member

Something like a destructive read to swap an iso would be my idea (like in TCPConnection) but that might be a bit much for an example.

@jemc
Copy link
Member

jemc commented Apr 16, 2018

I think we may want to avoid getting into capabilities stuff like iso and ephemerality this early in the tutorial.

Maybe just making it an example with a Map would be enough?

let map = Map[String, U64]
map("key1") = 100
map("key2") = 200
map("key1") = map("key2") = map("key1")

@rhagenson
Copy link
Member

There is currently an example of destructive read using an iso later in the tutorial:

```pony
class Aardvark
var buddy: Wombat iso
new create() =>
buddy = recover Wombat end
fun ref test(a: Wombat iso) =>
var b: Wombat iso = buddy = consume a // Allowed!
```

The Twitter thread appears like it was a barrier of first look at syntax, not lack of presence in the tutorial. The use in types/classes:

```pony
var temp = a
a = b
b = temp
```
In Pony, you can just do:
```pony
a = b = a
```

May be a bit much too soon. Do we want a "real world" example using Map (which then might confuse with the square brackets of generics), or for me to modify in-place to present it as a shorthand of syntax for swapping variables?

@SeanTAllen
Copy link
Member

I'm thinking that rather than the tutorial, perhaps we want to cover the usage of destructive read in 1 or more pony patterns. As it is, a more "advanced" topic.

At the least using on iso fields is definitely an advanced topic worthy of a pony pattern.

@rhagenson
Copy link
Member

I agree on destructive reads as a pattern entry. Destructive reads are an essential part of using Pony to its fullest (IMO), but their use amounts to a pattern as it is not something one must use, but should be aware of when reading Pony code.

@rhagenson
Copy link
Member

A "real world example" using something like Map might fit in a Collections chapter as requested in #190

@SeanTAllen SeanTAllen changed the title More real world example in destructive read documentaion More real world example in destructive read documentation Dec 3, 2019
@Theodus
Copy link
Contributor

Theodus commented Dec 3, 2019

I think that the destructive read pattern comes up so infrequently in practice that the existing example mentioned by @rhagenson is sufficient for explaining when it may be needed.

@rhagenson rhagenson added the good first issue Good for newcomers label Dec 16, 2020
@rhagenson
Copy link
Member

Added the "good first issue" label because I want someone's perspective on where a review/reminder of destructive read may be useful. The concept is not not covered, but a second mention that is not distracting would be helpful for anyone reading the Tutorial through the first time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

5 participants