What's ahead in Compsci 6/101? modules and how communication works

advertisement
What's ahead in Compsci 6/101?

Software architecture and design, why Jotto has
modules and how communication works



We write small programs, want to understand some
principles of larger programs
Software design in the small and in the large: different!
Dictionaries: associating keys with values




Arguably the most useful method for structuring data
How does Google find 'good' sites for a query?
How do we find what region in a genome encodes a
protein?
How do we determine literary/other fingerprints?
Compsci 06/101, Fall 2010
11.1
Jotto: The Program Architecture

You write jottoModel.py




We provide two views: command-line and GUI



This is the guts, brains, state of the program
Keeps track of how the game is progressing
Functions in the module communicate via global state
These all you to view and control the model
Both view-controllers: jottoMain.py and jottoGui.py know
about the model, but model doesn't know about them
Model-View or Model-View-Controller

Often the model knows there is/are view(s) not Jotto
Compsci 06/101, Fall 2010
11.2
Maria Klawe
Chair of Computer Science at
UBC, Dean of Engineering at
Princeton, President of Harvey
Mudd College, ACM Fellow,…
Klawe's personal interests include
painting, long distance running,
hiking, kayaking, juggling and
playing electric guitar. She
describes herself as "crazy about
mathematics" and enjoys playing
video games.
"I personally believe that the most
important thing we have to do today
is use technology to address societal
problems, especially in developing
regions"
Compsci 06/101, Fall 2010
11.3
Useful Computer Science
http://maps.google.com/maps?f=d&source=s_d&saddr=300+W+Morg
a
n+St,+Durham,+NC+27701+(Blue+Coffee+Express)&daddr=2324+Duk
e
+University+Road,+Durham,+NC+27708&hl=en&geocode=FcNJJQIdYw
5 M-yGT6vAZOfvdQg%3B&mra=ls&sll=36.088126,79.01786&sspn=1.333 898,2.11212
Blue Coffee Express
Durham

2324
Duke University
Road
Compsci 06/101, Fall 2010
11.4
How does this work?

http://tinyurl.com/d5o8mr
Compsci 06/101, Fall 2010
11.5
What is a dictionary, map, hash, table?

Abstraction: collection of (key,value) pairs


What kind of ice-cream do you like?
You are the key, ice cream is the value
Robert
Susan
Jeff
Alex
Bruce
Sam
Compsci 06/101, Fall 2010
11.6
What does this code do? How?
def fileStatsList(filename):
file = open(filename)
statList = []
for word in file.read().split():
found = False
for pair in statList:
if pair[0] == word:
pair[1] += 1
found = True
break
if not found:
statList.append([word,1])
file.close()
return statList
Compsci 06/101, Fall 2010
11.7
Faster, Cheaper, Totally in Control
def fileStatsDictionary(filename):
file = open(filename)
stats = {}
for word in file.read().split():
if word in stats:
stats[word] += 1
else:
stats[word] = 1
file.close()
return stats
Compsci 06/101, Fall 2010
11.8
Accessing map

Index a map by a key, using […]




Methods for dictionaries:



Like indexing a list, but index is a string, …. not integer!
Works internally by associating a number with the key
This association is known as hashing the key
.clear(), .get(key), .get(key,default)
.keys(), .values(), .items()
When using iteration or x in d, we're talking keys

Iterate over keys, query about keys, and so on
Compsci 06/101, Fall 2010
11.9
Literary Fingerprint

Timing and playing with code in fingerPrint.py




How do we find out how fast this is?
How do we change the format of the output?
Can we organize output differently?
How can we find 'other' fingerprints


Shazaam, genome, images
What will be the key, what will be the value?
Compsci 06/101, Fall 2010
11.10
Download