Software Design Fall 2004 For next time: 1) buy (or at least order) a book 2) read Chapter 2 of "How to think..." What's the plan? ---------------- Object-oriented programming in Python Software design patterns Basic algorithms and data structures Some sidebars (as time allows and interests dictate): graphical user interfaces, event-driven programming usability engineering, HCI concurrent programming, threads remote objects, distributed programming Methods ------- conventional DisInfo (dissemination of information) collect-transmit (hw00, student presentations) spiral learning (lots of foreshadowing) project-driven learning (medium-sized final project) one-room schoolhouse Goal: everyone learns a lot Corollary: beginners learn basic programming without being overwhelmed people with experience learn more advanced material without being bored beginners have a shot at the advanced material, but not required to master it people with experience _are_ required to do more than demonstrate basic mastery Three kinds of design --------------------- In a typical software design, you start with a library of 1) existing objects 2) existing operations which you assemble into a solution. 1) design by assembly result: a specific solution 2) design patterns result: a category of solutions 3) design by abstraction result: a language for expressing solutions Example: Given two words, how can you determine if they are anagrams (contain the same set of letters)? if is_anagram('tachymetric', 'mccarthyite'): print 'yes' 1) human algorithm? 2) basic python (well, except for the try statement) def is_anagram(s1, s2): t = list(s2) for c in s1: try: t.remove(c) except ValueError: return 0 return len(t) == 0 Problems? 3) a better (!) solution class Hist(dict): def __init__(self, s): for c in s: self[c] = self.get(c, 0) + 1 def is_anagram(s1, s2): return Hist(s1) == Hist(s2) Why is (3) better? 1) more efficient algorithm (so what?) 2) more readable / less error prone 3) more reusable -- it creates a new abstraction, the histogram, which can be used to talk about, and implement, solutions to other problems. Design by Abstraction --------------------- "...you don't just write your program down toward the language, you also build the language up toward your program." Paul Graham, http://www.paulgraham.com/progbot.html My variation on this theme: "Programming is the process of solving a problem by designing a language for expressing the solution." This kind of problem solving is: 1) hard to learn (and teach), but 2) interesting, creative and satisfying. As an aside, it is also impossible to outsource. Handouts -------- 1) syllabus 2) hw00 3) gratutious reading