blob: 94001409daa2ab1b3e753b35dc9f9e70f43877f0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
Avoiding unintended copying / Making copying stand out
======================================================
Use a "copy" keyword everwhere where there is a copy?
Should this be done at the type level, expression, or both?
func f(copy Thing th) -> copy Thing
{
copy Thing other
other = copy th
return copy do_stuff(copy th)
}
Problems:
- This performs a shallow copy! That might not be clear to the user!
- Is it possible to force deep copying somehow?
Is it possible to make it work across modules?
- Maybe too much visual noise?
Solutions?
- Use a stack keyword instead?
- Use it on types and parameter expressions only?
func f(stack Thing th) -> stack Thing
{
stack Thing other
other = th
return do_stuff(stack th)
}
|