For Next Time
On Monday you’ll be sending your code to instructors for a code review. We’ll work on a framing document for the exercise in class next time, but for now you should make sure you have a solid body of work completed and committed before then.
“The Goodies” Debrief
Think Python Chapter 19 includes some very useful Python odds and ends that can help you write powerful, efficient, “Pythonic” programs.
- list comprehensions and generator expressions
- sets and library types (Counter, defaultdict, namedtuple)
- gather and scatter operators, e.g.
def my_function(*args, **kwd): ...
Exceptions and Assertions
- Read about Exceptions and try some examples
- Exercise: Examine your system architecture diagram for the final project and identify places where errors are likely to occur - make a list and be specific. Common culprits include anywhere you take input from a user, from the web, a database, or the filesystem. Decide what types of exceptions should be raised in each case and how they should be handled. Implement at least one exception in your code.
- Read about Assertions and try some examples
- Exercise: Take 2-3 of your functions from the final project (or a past miniproject) and make your assumptions explicit by adding assertions. There’s a bit of an art to using assertions - if you defensively try to account for every single thing that could go wrong you’ll wind up with an unreadable mountain of tests for a small amount of code. Try to aim for the most impactful checks - things most likely to go wrong/be misused, and those most likely to be difficult to debug if used incorrectly.