Welcome to Comp210!
Admnistrivia
- The Comp210 home page and what you can find
there
- General course info = the
handout. The key points:
- Who -- the staff
- What -- the assignments, etc.
- Once a week homework plust 3 exams.
- Working in pairs.
- Where - the labs
- Sign up for a lab.
- Go to your preferred lab this week
- How - the Honor System
What is Computing?
- What do computers do anyway?
-
What does it mean to "compute" something?
- What are we saying about the specifics of what a computer does?
- How does one accomplish the task of "general purpose" computing?
- The difference between
- General = can do everything.
- Abstract = does the "essence" of things. Needs
"concrete", specific inputs to do anything in particular.
- Does a computer perform general tasks (does everything possible) or
does it do "abstract" tasks?
- What is a "program"?
- Specific tasks vs. abstract tasks
- How do we represent abstract tasks?
- What is "mathematics"?
- What is a mathematical "function"?
- The relationship between tasks and functions.
- Programs can be represented by functions.
Programming with Functions
There are lots of examples of functions:
- [get examples from class]
Note that arithmetic's notation wasn't always the clearest: you've been
taught "y=x+1" is a function; what is the input? What is the output? (Is
"x=y+1" the same function? What about "m=n+1"?) Really, "add1" might be
a better name for the function, and we could write "let add1(n) = n+1".
- The Academy Awards (takes in a list of movies, and returns (ahem) the
best one. Note that the Academy is what performs the computation.
- The registrar has a function from student to library-fine. (Well, okay,
at-which-time is also an implicit input to the function.)
- A web-search-engine is a function, taking in keywords, return a web-page
(with links to other pages).
So functions aren't always about numbers. That said, today we'll only use
functions on numbers. (We'll start enriching our world starting next time.)
Examples of computing, and generalizing to programs:
- A pizza costs $12, and has eight slices.
If you eat 2 pieces, you owe $12*(2/8) = $3.
If you eat 1 pieces, you owe $12*(1/8) = $1.50
If you eat 8 pieces, you owe $12*(8/8) = $12.00
Of course, we learn to abstract out the parts of the calcuation in
common, and express it as a more general rule:
owes(p) = $12*(p/8). owes(p) does not
represent the calculation of any particular amount of money owed, but instead
is the abstraction of all such calculations.
- A different formula, that you once memorized in school (since it's not
so obvious, if you're not taught it).
A disc of radius 6" has an area of 36pi sq. in.
In general: dough-area(r) = pi*r^2.
- Consider the folks who make the pizza. For a given diameter,
how much of the pizza is covered with toppings? Note that there is a 1-inch
border, which is crust-only.
A pizza of diameter 14" has a radius of 7", of which 1" is crust, so
the toppings cover a disc of radius 6": Draw picture.
pizza-topping-area(14) = dough-area(6) = 36pi.
In general: pizza-topping-area(d) = dough-area( d/2 - 1).
Does this rule make sense? Let's try some more tests:
pizza-topping-area(8) = dough-area(8/2 - 1) = dough-area(3).
pizza-topping-area(2) = dough-area(2/2 - 1) = dough-area(0).
Finally, a question: we could instead have written
pizza-topping-area(d) = pi (d/2 - 1)^2, or even
pizza-topping-area(d) = pi/4*d^2 - pi*d + pi.
Do we have a preference? Yes! The first version reflects how we think
about the problem, while the second makes the reader scratch their head
and wonder if it's really correct.
The First Law of Programming: Your code should
reflect the way you think about a problem.
The code in a program is an expression of how you conceptualize the problem.
Programming is a very personal process since it depends on the individual
programmer's view of the world.
Code that reflects a natural way of looking at the problem is both easier
to understand, easier to maintain, and more likely to be correct.
Summary:
- computing as asbstractions
- abstractions as functions;
- as algebra, substitute equal expressions until value reached
- single point of control
- First law of programming
- This vs. other comp courses:
- comp 210, comp212
- comp 100: intro to IT
- comp 110: solving problems w/ mathematica (for engineers w/o computing)
- comp 200: computer science for poets -- overview, some programming
- caam 210: solving problmes w/ matlab; basis for engineering courses
- Your responsibilities:
- expect to think, especially while in class and lab.
- review previous lecture, before each class; do the daily problem.
- homework: better in small steps, than all the night before.
- Ask questions in lecture (or communicate otherwise), or lab sections,
or web feedback.
- Your rights:
- Clear idea of what is expected for homeworks.
- Access to class staff.
- Explanations of grades.
- A challenging, rewarding course!
©2002 Stephen Wong