Skip to content

Conversation

@katrinabrock
Copy link

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].

@github-actions
Copy link

github-actions bot commented Aug 7, 2025

🆗 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.

@alee
Copy link
Member

alee commented Oct 31, 2025

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?

github-actions bot pushed a commit that referenced this pull request Oct 31, 2025
@katrinabrock
Copy link
Author

Yes, still looks good as a whole. I think the term "canonical" is a little jargony though.

Copy link
Member

@alee alee left a 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?

@katrinabrock
Copy link
Author

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 b there is not a list.

To make it clear, here's how I'm envisioning the "pasting formula" example:

Starting with a list

b = ["Red", "Green", "Blue", "Purple"]
A B C
1 Red
Red
=A1
Red
2 Green
Green
=A2
Green
3 Blue
Blue
=A3
Blue
4 Purple
Purple
=A4
Purple

Copy the list

c = b
A B C
1 Red
Red
=A1
Red
=A1
Red
2 Green
Green
=A2
Green
=A2
Green
3 Blue
Blue
=A3
Blue
=A3
Blue
4 Purple
Purple
=A4
Purple
=A4
Purple

Change a value

b[0] = "Pink"
c[0]
"Pink"
A B C
1 Pink
Pink
=A1
Pink
=A1
Pink
2 Green
Green
=A2
Green
=A2
Green
3 Blue
Blue
=A3
Blue
=A3
Blue
4 Purple
Purple
=A4
Purple
=A4
Purple

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.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Variables copied by reference not mentioned in Lesson 3

3 participants