CSC152 2005F, Class 2: About Object-Oriented Programming Admin: * Outlines don't always match what happens. Deal. * Please scan the course Web and bring questions tomorrow. * Homework! Read "An Intro to Unix" in /Espresso/ * If I type too low, please let me know. Overview: * Some background * OOP, In more detail * Exercise: Rational numbers This is a course in computer science * What is CS? * The science of computers * Science is ... "the study of" "like trying to answer questions in an experimentation-based method" * Trying again ... science is a method of study that follows a set pattern: Observe, Form Hypotheses, Design Experiment, Conduct that Experiment, Analyze Data, go back to the beginning * A "Computer" is ... Something that computes * Computes: Takes instructions and applies those instructions to data to create a result * What kinds of hypotheses can you have? * If you apply these instructions to these data on this computer, you'll get the same result as if you apply these instructions to these ata on another computer * A tool for science * Trying again ... CS is the study of Algorithms. Computers are involved only as the device that runs those algorithms * Three ways to study algorithms: * As scientists: This algorithm does what it's supposed to do ; This algorithm runs in the time that we expect * As mathematicians: *Prove* that this algorithm does what it's supposed to do ; Form models * As engineers: Build and test things * Clueless people equate computer science with computer programming * Programming may be part of CS, but it's not all of CS * This class will do some programming and some non-programming Surveys: * Programming Languages known: * Scheme? * Some basic: No advanced users, about 3 who have used it a little * C++: A few "a little" users * Pascal * Side note: HTML is not a progtramming language because you can't express *how* to do things in it Why are you in this class? * Test the waters for a possible major in CS. (After two days of Sam's bad jokes, it's already clearly a bad idea.) * CS is fun (at least so far)! * Lack the vision to think of any major other than a CS major and need to take this course to continue in the major. * Necessary for "that thing we don't do at Grinnell, but provide a 3-2 plan for those who want to try anyway" * To understand what to do when a computer does not behave as you want. * Normal suggestions: Curse, Defenestrate (learn Latin), Realize that computers are stupid and programmers are more so On to objects: * Object is something that collects functionality and data * A pen is something that * Data * Has a color * Has a name * Functionality * Permits transfer of ink to certain services * Can be thrown across the classroom * A window on the computer screen * Data * Position on screen * Background color * Functionality * "Draw this in this part of the screen" * "Erase yourself" * "Hide yourself" * "Go away" * Why use objects? * Original reason (1960's): Want to simulate the world * More recent reason: Objects tend to better support large-size programs * Why do objects make it easier to write larger programs? * Objects segment the program * Objects encapsulate control (and data), so that it's harder for other programmers to screw up what you've done * Many other characteristics of object-oriented programming are helpful for programming-in-the-large * Characteristic one: Classes * Instead of defining only individual objects, you define commonalities * Characteristic two: Inheritance * You can define new classes of objects in terms of previously-defined classes * When you fix/change something in the original, the change is automatically propagated to the related things * Characteristic three: Polymorphism * If you know how to use something, you know how to use the things defined in terms of it * Old objects can use new objects *without even knowing that the new objects have been defined* [* Non-programming computer scientists like to prove interesting facts about polymorphism and inheritance] Focus early in this class: Designing classes, using classes, implementing classes Side note: We talk about functionality differently in object-oriented programming: * Functional: Do this to this and this (showobject "This" window1) (+ 2 3) * OBjects: Hey object, do this to this window1.showobject("This") 2.add(3) Have a great day!