Software Design Spring 2008 For today you should have: 1) got your environment squared away 2) read Chapters 1 and 2 of "How to think..." 3) started on Homework 1 4) got a three-ring binder For next time: 1) work on Homeworks 0 and 1 2) read Chapter 3 of "How to think..." What's the plan? ---------------- Object-oriented programming in Python Software design patterns Basic algorithms and data structures Graphical user interfaces Network programming/distributed applications Project ------- Student-initiated project, two kinds 1) something that serves your educational goals 2) something that addresses the needs of a client If you want to pursue #2, you should start looking for clients! You can assume that by the time you get into the project you will know how to write programs 1) graphics and animation 2) graphical user interfaces 3) networking. Requirements: 1) The project should involve a substantial software design component; that is, you should have to make non-trivial design decisions. 2) More than one person per project. Software development processes are qualitatively different when there is more than one person involved. Feel free to use the class mailing list to shop ideas. Class philosophy ---------------- Wide range of preparation, one room school house. 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 --------------------- Analogy: lego basic bricks 1) given capabilities and 2) ways of interacting In a typical software design, you have a library of 1) built-in objects 2) built-in operations which you assemble into a solution. 1) design by assembly 2) design patterns 3) design by abstraction Basic algorithms ---------------- 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 this better? ------------------- 1) more efficient algorithm (so what?) 2) more readable / less error prone 3) more reusable -- it creates a new, useful, named type (Hist) Design by Abstraction --------------------- defining new functions and classes creates new higher-level tools... that can be used to build the next layer of tools... and so on. Designing interfaces (between functions and between objects) is: 1) hard to do well 2) interesting and creative 3) where big brains pay off Style ----- Good code is 1) demonstrably correct 2) self-documenting (with comments that explain the non-obvious) 3) reusable (it creates new general-purpose abstractions) Some "style" is arbitrary convention, BUT Good style is mostly objective (not a matter of taste). A surprising amount of good style is good IDENTIFIER NAMES. def run(self): self.running = 1 while self.exists and self.running: self.step() self.update() sleep(self.delay) def stop(self): self.running = 0 Class organization ------------------ 2 one-hour classes per week (MR 10-11) short classes: more efficient IF we don't lose the first 10 minutes! quizzes first thing, no makeups, first one is free. Dr Allen* says "make a lifestyle commitment" 1) eat well 2) sleep well 3) get some exercise 4) wash your hands frequently * Dr Allen has a Doctorate in Philosophy, and is not licensed to give medical advice. 2 two hours of lab per week during Wednesday 1-5pm, Short "entrance quiz" at the beginning of each lab. Start homework in lab, done by the beginning of the next. Das Buch -------- We will be using my book, "How to think like a (Python) programmer", but you should also buy one other Python book of your choice. I have several in the lounge outside my office. Also check out the reviews at http://www.awaretek.com/book.html and Amazon.com. Note, almost all are intended for programmers. Exceptions (that I know of) are: Python Programming by John M. Zelle Python: How to Program by Deitel and Deitel Learn to Program Using Python by Alan Gauld