Skip to content

Commit 649cf80

Browse files
committed
Update learning_julia2
1 parent efbd3e0 commit 649cf80

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

homeworks/learning_julia2.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
22
title: "Learning Julia (Part 2)"
33
author: Timothy E. Holy, Washington University in St. Louis
4-
date: Oct 5, 2021
4+
date: Feb 6, 2023
55
geometry: margin=1in
66
output: pdf_document
77
---
88

9-
# Learning for week 2
9+
# Learning Julia: week 2
1010

1111
## Main reading
1212

@@ -112,7 +112,7 @@ julia> v1[1] === v2[1]
112112
true
113113
```
114114

115-
So it creates a new *outer* container, but then copies the *references* rather than duplicating the internal array. If you need to copy recursively, you can use `deepcopy`. Note, however, that `deepcopy` can cause significant concerns of its own; these are well-described in the [Python documentation](https://docs.python.org/3/library/copy.html) which uses the same names as Julia. In real code, it's almost always better to know what you are dealing with and what you're trying to accomplish, and then handle it by more careful `copy`ing.
115+
So it creates a new *outer* container, but then copies the *references* rather than duplicating the internal array. If you need to copy recursively, you can use `deepcopy`. Note, however, that `deepcopy` can cause significant concerns of its own; these are well-described in the [Python documentation](https://docs.python.org/3/library/copy.html) which uses the same names as Julia. In real code, it's almost always better to know what you are dealing with and what you're trying to accomplish, and then handle it by more careful `copy`ing. (In Julia, unlike Python, you can add your own methods to `Base.copy` and customize the behavior for any new types you create.)
116116

117117
By understanding the issues, you can always get whatever behavior you actually want. For example, we could have created `y` like this:
118118

@@ -154,7 +154,7 @@ julia> y
154154
[7]
155155
```
156156

157-
It should be noted that this doesn't happen in Matlab, because Matlab uses a technique "behind the scenes" known as [copy-on-write](https://en.wikipedia.org/wiki/Copy-on-write). This has the major advantage of preventing surprises like the one above, while also avoiding the worst performance costs of unnecessary copying. It has the major disadvantage of making it impossible to create functions that modify their inputs: in Matlab, you can't create a function like Julia's `push!` or any others with a `!`. You also can't create objects that "maintain their links" with others in a manner that supports mutation. Languages like Julia, Python, C, and many others therefore avoid copy-on-write.
157+
It should be noted that this doesn't happen in Matlab, because Matlab uses a technique "behind the scenes" known as [copy-on-write](https://en.wikipedia.org/wiki/Copy-on-write). This has the major *advantage* of preventing surprises like the one above, while also avoiding the worst performance costs of unnecessary copying. It has the major *disadvantage* of making it impossible to create functions that modify their inputs: in Matlab, you can't create a function like Julia's `push!` or any others with a `!`. (This is why it's slow to append to a vector in Matlab, but fast in Julia.) You also can't create objects that "maintain their links" with others in a manner that supports mutation. Most languages--including Julia, Python, and C--choose to avoid copy-on-write.
158158

159159
## Workflow tips
160160

@@ -166,4 +166,4 @@ Some debugging tips:
166166

167167
# Assignment for week 2
168168

169-
The entire assignment is in the associated [`learning_julia2_exercises.jl`](learning_julia2_exercises.jl).
169+
The entire assignment is in the GitHubClassroom repository.

0 commit comments

Comments
 (0)