100 likes | 115 Views
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!
E N D
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?
Jotto: The Program Architecture • You write jottoModel.py • 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 • We provide two views: command-line and GUI • 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
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"
Useful Computer Science • http://maps.google.com/maps?f=d&source=s_d&saddr=300+W+Morga n+St,+Durham,+NC+27701+(Blue+Coffee+Express)&daddr=2324+Duke +University+Road,+Durham,+NC+27708&hl=en&geocode=FcNJJQIdYw5 M-yGT6vAZOfvdQg%3B&mra=ls&sll=36.088126,-79.01786&sspn=1.333 898,2.11212 Blue Coffee Express Durham 2324 Duke University Road
How does this work? • http://tinyurl.com/d5o8mr
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
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
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
Accessing map • Index a map by a key, using […] • 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 • Methods for dictionaries: • .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
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?