Skip to content

The Returning a value bit under Ownership and scope section could be improved #117

@alilloig

Description

@alilloig

I'm fixing a couple of minor issues I'm finding through the book in this PR but I thought suggestions will be better as issues.

Maybe this is caused for a lack of knowledge on how Move works, but I find this piece of code inside the Ownership and scope chapter slightly confusing

module book::ownership;

public fun owner(): u8 {
    let a = 1; // a defined here
    a // scope ends, a is returned
}

#[test]
fun test_owner() {
    let a = owner();
    // a is valid here
} // a is dropped here

(I end up editing why I find this confusing after reading the Ability: Copy chapter)

The fact that the returned value is a native u8, and then it has copy and drop makes me think that what is actually happening here is that the value returned by the function is being copied into the test scope a variable, rather than the owner function scope a variable changing ownership.

May be worth to a) call the test variable with a different name, b) clarify this point or choosing a different example?

Probably I will understand this when I got deeper into Move, but considering only the knowledge acquired while getting here (considering the 7.17 Function chapter info) I'm not able to clarify what is exactly going on here

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions