Download presentation
Presentation is loading. Please wait.
1
Program Design Invasion Percolation: Aliasing
Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See for more information.
2
Use lists of lists to implement a 2D grid 3 5 7 7 5 8 6 3 2 4 2 6 5 4
3
Use lists of lists to implement a 2D grid 3 5 7 7 5 8 6 3 2 4 2 6 5 4
4
Use lists of lists to implement a 2D grid 3 5 7 7 5 8 6 3 2 4 2 6 5 4
5
assert N > 0, "Grid size must be positive"
# Correct code assert N > 0, "Grid size must be positive" assert N%2 == 1, "Grid size must be odd" grid = [] for x in range(N): grid.append([]) for y in range(N): grid[-1].append(1) 5
6
assert N > 0, "Grid size must be positive"
# Incorrect code assert N > 0, "Grid size must be positive" assert N%2 == 1, "Grid size must be odd" grid = [] EMPTY = [] for x in range(N): grid.append(EMPTY) for y in range(N): grid[-1].append(1) 6
7
assert N > 0, "Grid size must be positive"
# Incorrect code assert N > 0, "Grid size must be positive" assert N%2 == 1, "Grid size must be odd" grid = [] EMPTY = [] for x in range(N): grid.append(EMPTY) for y in range(N): grid[-1].append(1) 7
8
"Aren't meaningful variable names supposed to be a good thing?"
# Incorrect code assert N > 0, "Grid size must be positive" assert N%2 == 1, "Grid size must be odd" grid = [] EMPTY = [] for x in range(N): grid.append(EMPTY) for y in range(N): grid[-1].append(1) "Aren't meaningful variable names supposed to be a good thing?" 8
9
grid = [] grid 9
10
grid = [] EMPTY = [] grid EMPTY 10
11
grid = [] EMPTY = [] for x in range(N): # x == 0 grid.append(EMPTY)
11
12
grid = [] EMPTY = [] for x in range(N): # x == 0 grid.append(EMPTY)
for y in range(N): # y == 0 grid[-1].append(1) grid EMPTY 1 12
13
grid = [] EMPTY = [] for x in range(N): # x == 0 grid.append(EMPTY)
for y in range(N): # y == 1 grid[-1].append(1) grid EMPTY 1 1 13
14
grid = [] EMPTY = [] for x in range(N): # x == 0 grid.append(EMPTY)
for y in range(N): # y == 2 grid[-1].append(1) grid EMPTY 1 1 1 14
15
grid = [] EMPTY = [] for x in range(N): # x == 1 grid.append(EMPTY)
15
16
grid = [] EMPTY = [] for x in range(N): # x == 1 grid.append(EMPTY)
for y in range(N): # y == 0 grid[-1].append(1) grid EMPTY 1 1 1 1 16
17
You see the problem... grid = [] EMPTY = []
for x in range(N): # x == 1 grid.append(EMPTY) for y in range(N): # y == 0 grid[-1].append(1) grid EMPTY 1 1 1 1 You see the problem... 17
18
Indirection allows aliasing
19
Indirection allows aliasing
Aliasing can be useful
20
Indirection allows aliasing
Aliasing can be useful (In fact, sometimes it's indispensible)
21
Indirection allows aliasing
Aliasing can be useful (In fact, sometimes it's indispensible) But it's also a rich source of bugs
22
Indirection allows aliasing
Aliasing can be useful (In fact, sometimes it's indispensible) But it's also a rich source of bugs When in doubt, draw a picture!
23
Indirection allows aliasing
Aliasing can be useful (In fact, sometimes it's indispensible) But it's also a rich source of bugs When in doubt, draw a picture! Tools that do this automatically exist...
24
Indirection allows aliasing
Aliasing can be useful (In fact, sometimes it's indispensible) But it's also a rich source of bugs When in doubt, draw a picture! Tools that do this automatically exist... ...but none has really taken off (yet)
25
Greg Wilson created by May 2010 Copyright © Software Carpentry 2010
This work is licensed under the Creative Commons Attribution License See for more information.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.