![]() ![]() |
| |||||||||
| Hotspots: Slides and Code TA Corner Comments? Announcements FAQ Static Webspace | ||||||||||
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
| For #2, are methods and functions used the same way? Do they look different? How does recursion relate to #3? What are some characteristics that make cells a good model for programming?(#4) Lauren Biddle |
| #5 above is pretty good. Certainly more could be said, e.g., about robustness. What doesn't make sense? Mark Guzdial |
>>> pic=makePicture(getMediaPath("barbara.jpg"))
>>> pic.show()
def show(picture):
if not picture .__class__==Picture:
print "show(picture): Input is not a picture"
raise ValueError
picture.show()
| Functional programs tend to rely on recursion for looping. Since the functions in a functional program tend to work on very small amounts of data at a time, they lend themselves to recursion easily. Don't forget other forms of polymorphism we discussed, like setRed() and writeTo(). makePicture() is NOT a method. show() is a method. Recipes can be made up of methods or functions. |
| When we were doing import random and import os, we weren't really importing objects. We were importing modules, which are used like objects in the sense of using dot notation, but they don't have any of the characteristics of objects. For example, you can make instances of an object class – you can't make instances of modules. Functional programming is about programming with functions, including functions that take functions as input (like map, reduce, and filter) and recursive functions. Procedural programming is what we've been doing where some of our "functions" didn't take inputs and didn't return anything. Functional programming is always using REAL functions, like in math, that always return something. There's not hard and fast lines between these things – many programs blend all three kinds of programming. Even the programming we were doing with procedures was using objects, so you could say that we've always blended procedural (sometimes called imperative – we're commanding the computer to do things) with object-oriented. But they are different styles and have their distinct strengths and weaknesses. Mark Guzdial |
| The topic area for the program. If you were building a program to replace Banner, the domain would be class scheduling and student registration. Mark Guzdial |
| Yup. Mark Guzdial |
| What error did you get? Don't type class slide: in the command area. You just need it in the program area. Mark Guzdial |
| Combining both data and behavior. Mark Guzdial |