-
-
Notifications
You must be signed in to change notification settings - Fork 444
Mention pass by reference in episode 3 #700
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
base: main
Are you sure you want to change the base?
Conversation
🆗 Pre-flight checks passed 😃This pull request has been checked and contains no modified workflow files, spoofing, or invalid commits. It should be safe to Approve and Run the workflows that need maintainer approval. |
|
Thank you for the PR @katrinabrock and apologies for the late review! This is great. I made some minor revisions, does it still read well to you? |
|
Yes, still looks good as a whole. I think the term "canonical" is a little jargony though. |
alee
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking this on! I think this is an improvement but would love to hear from other community members.
I have one minor concern on clarifying the analogy to spreadsheet formulas.
The text that describes lists / dictionaries / objects as similar to spreadsheet formulas might be confusing for the following example:
'''
example_list = [1, 2, 3]
a = example_list[0] * 3
example_list[0] = 5
print(a) # 3 or 15?
'''
what we are trying to explain in the text is more related to something like this:
'''
example_list = [1, 2, 3]
b = example_list
b[0] = 5
print(example_list) # is the first element 1 or 5?
'''
What do you all think? Non-issue, merge and move on?
|
Yes, indeed I'm trying to explain the second case and not the first case that you mention. The first case is "like pasting a value" because To make it clear, here's how I'm envisioning the "pasting formula" example: Starting with a listb = ["Red", "Green", "Blue", "Purple"]
Copy the listc = b
Change a valueb[0] = "Pink"
c[0]
That's what I'm going for at least, but not sure if on balance the spreadsheet analogy is helpful or distracting. I think it is worth worrying about through. |
| - Afterwards, `variable_two` is set to this new value and *is not dependent on `variable_one`* so its value | ||
| does not automatically change when `variable_one` changes. | ||
|
|
||
| Some data types that we haven't encountered yet (e.g. _lists_, _dictionaries_, and _objects_) have "links" inside them so they behave somewhat differently when you assign values to their *contents*. An example of this is shown in [Episode 12: Lists](../11-lists.md#copying-or-not). Assigning a list value to a new variable is like copying and pasting a formula from one cell to another. When you update an item in that list with the new value, you're updating that item in the original list as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Some data types that we haven't encountered yet (e.g. _lists_, _dictionaries_, and _objects_) have "links" inside them so they behave somewhat differently when you assign values to their *contents*. An example of this is shown in [Episode 12: Lists](../11-lists.md#copying-or-not). Assigning a list value to a new variable is like copying and pasting a formula from one cell to another. When you update an item in that list with the new value, you're updating that item in the original list as well. | |
| Some data types that we haven't encountered yet (e.g. _lists_, _dictionaries_, and _objects_) have "links" inside them so they behave somewhat differently when you assign values to their *contents*. An example of this is shown in [Episode 12: Lists](../11-lists.md#copying-or-not). Making an item part of a list is more like putting an item in a container than like making a copy of it. |
@alee what do you think about this wording? It avoids getting too much in the weeds.
If this pull request addresses an open issue on the repository, please add 'Closes #NN' below, where NN is the issue number.
Closes #370
Please briefly summarise the changes made in the pull request, and the reason(s) for making these changes.
As requested in #370 , this change warns users about of pass-by-reference when they first learn about the concept of assignment.
In order avoid introducing and fully explaining the concepts of objects, pass-by-reference, and mutable/immutable (as @alee does beautifully in this comment), I use the term "links inside [the object]" to describe mutable objects with mutable references. Hopefully this describes the behavior without saying anything technically incorrect or getting too in-the-weeds for Episode 3. Maybe some of this more comprehensive explanation could be added to Episode 11, since the concept is introduced there but not thoroughly explained.
If any relevant discussions have taken place elsewhere, please provide links to these.
I used #499 as a basis and kept the example and structure, but reworded completely.
For more guidance on how to contribute changes to a Carpentries project, please review the Contributing Guide and Code of Conduct.
Please keep in mind that lesson Maintainers are volunteers and it may be some time before they can respond to your contribution. Although not all contributions can be incorporated into the lesson materials, we appreciate your time and effort to improve the curriculum. If you have any questions about the lesson maintenance process or would like to volunteer your time as a contribution reviewer, please contact The Carpentries Team at [email protected].