Software Design Lecture Notes Fall 2004 Project plan ------------ 1) Demos will be December 6, 7, 9, 13, 14 2) Final report due on December 14. 3) Expo is December 21 (not the 14th) In preparing your final report, please review the Project Plan (now on the class web page) Make sure that you include all the required elements, and remember your audience. Demo schedule ------------- Roughly 15 minutes per group. Not an evaluated exercise -- your opportunity to show the class something you have been working on. No structural requirements, but here are some suggestions: 0) Start by explaining your project as if none of us have every heard of it. 1) If at all possible, demonstrate _something_, even if it is a hollow prototype. Practice the demo, and TIME IT! 2) Tell a design story, good, bad or in-between. 3) Teach us something that you learned. Where are we? ------------- Framework vs. library --------------------- A library is a collection of related functions / classes. You work with a library by writing programs that instantiate classes and call functions from the library. A framework is a customizable application. You work with a framework by customizing it to do what you want, often by providing callbacks. "You call a library; a framework calls you." Frameworks we have seen ----------------------- 1) Python special methods (Chapter 5 from Python in a Nutshell) __init__ __str__ Math operators (see Appendix B) See also Chapter 5 of the Python Cookbook. 2) tkinter (and GUIs in general) a) create a GUI b) bind callbacks c) invoke mainloop 3) OpenGL glutDisplayFunc(self.display) glutReshapeFunc(self.reshape) glutKeyboardFunc(self.keyboard) glutMouseFunc(self.mouse) glutIdleFunc(self.idle) A new example ------------- Parsing HTML (Chapter 7 from Goerzen, Foundations of Python Network Programming) from HTMLParser import HTMLParser import sys class TitleParser(HTMLParser): def __init__(self): self.title = '' self.readingtitle = 0 HTMLParser.__init__(self) def handle_starttag(self, tag, attrs): if tag == 'title': self.readingtitle = 1 def handle_data(self, data): if self.readingtitle: # Ordinarily, this is slow and a bad practice, but # we can get away with it because a title is usually # small and simple. self.title += data def handle_endtag(self, tag): if tag == 'title': self.readingtitle = 0 def gettitle(self): return self.title fd = open(sys.argv[1]) tp = TitleParser() tp.feed(fd.read()) print "Title is:", tp.gettitle() Pros and cons of frameworks --------------------------- Pro: Many applications are based on a few common structures. Frameworks encapsulate the structure; you provide the details. Pro: If you have an example that is similar to what you want to do, you can often build very complicated things very quickly. Pro: Frameworks can be used to eliminate some kinds of errors from otherwise error-prone programs (Twisted is a good example). Con: With libraries it is often natural to build new abstractions on top of the old. With frameworks, you sometimes find yourself fighting with the structure. Con: People haven't figured out how to document frameworks well. Con: It can be hard to evaluate whether a given framework can handle a given application. Beware the 90/10 rule! Other examples of frameworks ---------------------------- Turtle3D moral: building a framework can help manage pre/post conditions and invariants Twisted asynchronous client/server communication