cpsc lecture1

download cpsc lecture1

of 46

Embed Size (px)

Transcript of cpsc lecture1

  • 7/28/2019 cpsc lecture1

    1/46

    CPSC 111Introduction to Computation

    May 4, 2009

  • 7/28/2019 cpsc lecture1

    2/46

    Who I Am

    Your instructor is

    Kurt [email protected]

    ICICS 233

    office hours soon to be determined

    (but come on in anytime the

    door is open)

  • 7/28/2019 cpsc lecture1

    3/46

    What This Course Is About

    Calendar description: Basic programming constructs,

    data types, classes, interfaces, protocols and the design

    of programs as interacting software components.

    Prerequisites: Mathematics 12.

    Ignore the buzzwords for now. Youre going to learn

    about computers and how to put together

    sequences of instructions to make them do useful stuff.

  • 7/28/2019 cpsc lecture1

    4/46

    Who this course is for...

    Although it is expected that you will have used a computer

    prior to taking the course and that you are familiar with

    basic keyboard and mouse operations, no prior

    programming experience is assumed. This course willteach you basic programming constructs that will allow

    you to unleash your creativity and develop your own

    applications software.

    In other words, you can succeed here even if you havenever ever written a computer program.

  • 7/28/2019 cpsc lecture1

    5/46

    ...but note this

    If you have already received credit for CPSC124 and

    CPSC126 or for CPSC122 and CPSC128 then you

    cannot receive credit for CPSC111. If you have taken

    CPSC124 but not CPSC126 then you must takeCPSC111 in order to advance through the computer

    science program. If you have taken CPSC122 but not

    CPSC128, please consult with a department advisor.

    This probably isn't relevant to any of you. The importantthing to know is that you must have taken Mathematics 12

    before now, or you'll most likely be dropped from the

    course.

  • 7/28/2019 cpsc lecture1

    6/46

    Administrative Stuff

    Your textbook is Big Java by Cay Horstmann

    (Wiley and Sons). The third edition is in the

    bookstore, plus some copies of the second edition.

  • 7/28/2019 cpsc lecture1

    7/46

    Administrative Stuff

    Your textbook is Big Java by Cay Horstmann

    (Wiley and Sons). The third edition is in the

    bookstore, plus some copies of the second edition.

    You should get a copy of either one. Seriously.

    Read chapter 1 and chapter 2 before Wednesday.

  • 7/28/2019 cpsc lecture1

    8/46

    Administrative Stuff

    Tentative schedule

    First midterm exam: Friday, May 15 (in class)

    Second midterm exam: Friday, May 29 (in class)

    Final exam: Friday, June 12 (in class)

    Tentative grade calculation (subject to change)

    Quizzes 5%

    10(?) labs 10%

    5(?) assignments 10%

    First midterm 10%Second midterm 20%

    Final exam 45%

  • 7/28/2019 cpsc lecture1

    9/46

    Administrative Stuff

    I post all my PowerPoint slides on our WebCT page.

    We're using the new WebCT Vista (www.vista.ubc.ca).

    I post the slides sometime (not instantly) after class, not

    before. Our WebCT pages should be available today.

    Until you get up to speed with WebCT (in lab) you can

    find out more about CPSC 111 at

    http://www.ugrad.cs.ubc.ca/~cs111/. Note that the

    "outline" and "schedule" sections are not up to date yet --

    they describe the section that ended Friday. We'll tryupdate those pages within the next 48 hours. But please

    read the "policies" section.

  • 7/28/2019 cpsc lecture1

    10/46

    Administrative Stuff

    No labs or tutorials today.

    Labs and tutorials begin on Wednesday of this

    week, then on Friday, then every Wednesday andFriday thereafter.* You should do Lab 0 (a take

    home lab) as soon as WebCT for 111 is ready.

    Typically well use the entire 2.5 hours every

    Monday, Wednesday, and Friday, with a ten

    minute break somewhere in the middle. That

    break is for me as well as you.

    * Except possibly on exam days.

  • 7/28/2019 cpsc lecture1

    11/46

    Administrative Stuff

    Lab work is marked by your TAs at the lab.

    Those marks impact your final grade.

    Tutorial work is not marked, but skipping tutorialsis not a good idea.

  • 7/28/2019 cpsc lecture1

    12/46

    How intense is the summer version?

    3 lectures per week x 6 weeks = 18 lectures

    3 exams: subtract 3 lectures = 15 lectures

    1 holiday: subtract 1 lecture = 14 lectures

    In the winter, this class runs 13 weeks. So in the summer,

    we have 14 lectures to cover 13 weeks of material. One

    lecture in the summer is almost a week's worth of material

    from the winter session. Do not fall behind.

    Oh, did I mention that your first midterm exam is next week?

  • 7/28/2019 cpsc lecture1

    13/46

    More Administrative Stuff

    Please note that in order to pass the course you must:

    obtain an overall grade of at least 50%

    obtain a grade of at least 50% on the final exam

    obtain an overall grade of at least 50% on the combined lab and

    assignment grades

    If you fail to satisfy any of the above criteria, a grade no greater than

    45% will be assigned in the course. The instructor reserves the right

    to modify this grading scheme as necessary throughout the term.

    Note that you will not pass the course if you are not enrolled in a labsection. More lab seats will be added very very soon.

    Thats enough administrative details for now. There will be more

    details to wrestle with in the days to come.

  • 7/28/2019 cpsc lecture1

    14/46

    This is a first course in computer science...

    ...but what is computer science?

    "Computer science is as much about computers as

    astronomy is about telescopes."

    Edsger Dijkstra

  • 7/28/2019 cpsc lecture1

    15/46

    This is a first course in computer science...

    ...but what is computer science?

    Computer science revolves around computational

    processes.... A process is a dynamic succession of

    events.... When your computer is busy doing something,a process is going on inside it.

    Oliver Grillmeyer

  • 7/28/2019 cpsc lecture1

    16/46

    This is a first course in computer science...

    ...but what is computer science?

    Computer science is the study of what computers do, not

    of what they are.

    me

  • 7/28/2019 cpsc lecture1

    17/46

    Processes, procedures, and programs

    A process is what happens when a computer

    follows a procedure - its a procedure in execution.

    A procedure is a collection of instructions in somemeaningful order that results in useful behaviour

    on behalf of the device that executes the

    instructions.

    When the instructions are written in a symbolic

    language that can be executed by a computer, the

    procedure is called a computerprogram.

  • 7/28/2019 cpsc lecture1

    18/46

    Processes, procedures, and programs

    What we do in CPSC 111 is

    think in terms of procedures

    use a programming language called Java

    to write the procedures as computer

    programs

    and execute the programs on a computer

    to generate useful processes

  • 7/28/2019 cpsc lecture1

    19/46

    Procedures and algorithms

    Computer people often use the words procedure

    and algorithm interchangeably...we will too.

    An algorithm is

    a finite procedure

    written in a fixed symbolic vocabulary

    governed by precise instructions

    moving in discrete steps, 1, 2, 3, ...

    whose execution requires no insight, cleverness,

    intuition, intelligence, or perspicuity

    and that sooner or later comes to an end

    David Berlinski in The Advent of the Algorithm

  • 7/28/2019 cpsc lecture1

    20/46

    Procedures and algorithms

    Lets dive right in and write a procedure or

    algorithm, just for fun.

    Well make a peanut butter and jelly sandwich.

    (Is anyone here allergic to peanuts? You should go

    way to the back of the room.)

    Form a small group with your neighbours. Grab

    some paper and a pen, and write down how to

    make a peanut butter and jelly sandwich as a

    sequence of steps. Number each step. Bring me

    your procedure when youre finished.

  • 7/28/2019 cpsc lecture1

    21/46

    Procedures and algorithms

    Was my interpretation of your instructions a little bit

    frustrating?

    If telling me how to make that sandwich had been

    really important to you, you might be quite upset

    right now.

    Getting other people to do what you want them to

    do isnt easy. Getting computers to do what you

    want them to do is less easy -- a lot less.

  • 7/28/2019 cpsc lecture1

    22/46

    Procedures and algorithms

    Heres why we get frustrated when we start to learn

    to write programs to make computers do stuff:

    An algorithm is

    a finite procedure

    written in a fixed symbolic vocabulary

    governed by precise instructions

    moving in discrete steps, 1, 2, 3, ...

    whose execution requires no insight, cleverness,

    intuition, intelligence, or perspicuity

    and that sooner or later comes to an end

    We dont have a lot of practice at being precise!

  • 7/28/2019 cpsc lecture1

    23/46

    Procedures and algorithms

    Heres why we get frustrated when we start to learn

    to write programs to make computers do stuff:

    An algorithm is

    a finite procedure

    written in a fixed symbolic vocabulary

    governed by precise instructions

    moving in discrete steps, 1, 2, 3, ...

    whose execution requires no insight, cleverness,

    intuition, intelligence, or perspicuity

    and that sooner or later comes to an end

    We dont have a lot of practice at working with stupid!

  • 7/28/2019 cpsc lecture1

    24/46

    Why working with stupid isnt easy

    The languages that computers understand are very different

    from the languages that humans understand, and for good

    reason.

    Unlike computers, humans bring enormous amounts ofknowledge to bear on the simple problem of figuring out

    what just a single sentence means.

    You may not be able to articulate the knowledge that youre

    using, but you do have it, and you can apply it in real time,as you read or listen, even if the sentence is one you've

    never encountered before. (Like the one you've just read.)

  • 7/28/2019 cpsc lecture1

    25/46

    Why working with stupid isnt easy

    So why is that important to you, the budding young computer

    programmer?

    Because the natural language you use, whether English,

    Chinese, French, Klingon, or whatever, is highly ambiguousand you deal with it automatically and unconsciously. Every

    sentence you write, every utterance you speak, lacks

    precision (to say the very least) and you count on the

    understander on the receiving end to disambiguate it without

    even a glimpse of recognition that the disambiguation ishappening. Its an inherent trait of natural language and the

    humans who understand natural language.

    Its what we do. It sets us apart from everything else.

  • 7/28/2019 cpsc lecture1

    26/46

    Why working with stupid isnt easy

    But imagine that youve been transported to a world where

    the other inhabitants cope with ambiguity even less well than

    I did when I tried to follow your instructions for making a

    sandwich. A world, in fact, where they dont cope with

    ambiguity at all, a world where they bring almost noknowledge whatsoever to bear on the problem of

    understanding what youre saying. How painfully tedious

    would that be?

    You dont have to imagine it -- youre going to be living in itfor the next six weeks. Its the world of computer

    programming. Welcome to our world.

  • 7/28/2019 cpsc lecture1

    27/46

    How to avoid frustration

    Practice, practice, practice.

    This material isn't conceptually incomprehensible, but...

    It takes a lot of practice to learn to be precise enough tomake a computer do what you want

    It takes a lot of practice to keep from assuming that the

    computer is smarter than it really is

    It takes a lot of practice to get good at this stuff

  • 7/28/2019 cpsc lecture1

    28/46

    How to avoid frustration

    Dont try to game the system. It wont work for most of you.

    Your presence at the big university means youve mastered

    the art of cramming for exams, writing term papers the night

    before theyre due, and so on. It works with subjects whereyou have years of experience, but it doesnt work so well

    where you have no previous experiencelike in this course.

  • 7/28/2019 cpsc lecture1

    29/46

    How to avoid frustration

    Learning to write computer programs is similar to learning to

    play a musical instrument or write stories. Its a skill. Skill

    requires practice.

    You wouldnt put off all your piano practice until the nightbefore your recital.

    You dont want to put off all your programming practice until

    the night before a programming assignment is due or (worse

    yet) until the night before your exam.

    Practice, practice, practice.

  • 7/28/2019 cpsc lecture1

    30/46

    How to avoid frustration

    Study your book frequently, dont just read it. (Recent

    studies suggest you should read, then close the book and try

    to write a summary of what you've been reading.)

    Play with the programs from your book and from class.Type them in, run them, change them, run them, repeat.

    Go to the labs.

    Go to the tutorials.

    Ask questions.

    Do more than we require. Practice, practice, practice.

  • 7/28/2019 cpsc lecture1

    31/46

    Dont wait until the last minute to get help

  • 7/28/2019 cpsc lecture1

    32/46

    Bad things happen while learning a new skill. Start

    homework early; give yourself time for mistakes.

    Hey, can I still passif I can get enough

    partial credit?

  • 7/28/2019 cpsc lecture1

    33/46

    Dont be too ambitious with your course load. You cant

    slack off in this class, even for a few days.

  • 7/28/2019 cpsc lecture1

    34/46

    So what will you learn here?

    How to get a computer to do your bidding:

    How to represent solutions to problems as

    procedures or algorithms

    How to represent those procedures as

    programs written in a programming language

    How to get the computer to turn your programs

    into processes that do useful stuff

  • 7/28/2019 cpsc lecture1

    35/46

    Why should you learn it?

    If youre one of the few computer science majors

    enrolled in this class right now, the answer should

    be obvious.

    But what if youre not a computer science major?

    As an informed citizen, the more you know about

    how these machines work, the better youll be

    able to weigh in on decisions that affect your life

    in a very technology-dependent future.

    Also, no matter what your chosen field of study

  • 7/28/2019 cpsc lecture1

    36/46

    Thinking in terms of process is crucial

    formulas are no longer sufficient for describing

    how our world works. For example,

    Economic systems are processes

    Political systems are processes

    How HIV invades cells is a process

    How pharmaceuticals interfere with HIV is also a

    process, and so on

    Being able to think about complex systems in terms

    of procedures and processes will be of value to you

    even if you never write another program after 111.

  • 7/28/2019 cpsc lecture1

    37/46

    But wait, there's more*...

    It's not obvious to you, but you're in the middle of a

    revolution. Think about the changes that have

    happened already...

    This computer from the 1950s had roughly the

    computing power of today's musical greeting cards.* most of the following examples have been stolen from Ed Lazowska's very inspiring

    2008 SIGCSE keynote address. Thanks Ed.

  • 7/28/2019 cpsc lecture1

    38/46

    But wait, there's more...

    It's not obvious to you, but you're in the middle of a

    revolution. Think about the changes that have

    happened already...

    The computing power that was aboard Apollo 11 on

    its flight to the moon in 1969 can be found in a

    Furby.

  • 7/28/2019 cpsc lecture1

    39/46

    But wait, there's more...

    It's not obvious to you, but you're in the middle of a

    revolution. Think about the changes that have

    happened already...

    The power of my first computer in 1972 that served

    a university and its surrounding business

    community...

  • 7/28/2019 cpsc lecture1

    40/46

    But wait, there's more...

    It's not obvious to you, but you're in the middle of a

    revolution. Think about the changes that have

    happened already...

    The power of my first computer in 1972 that served

    a university and its surrounding business

    community is exceeded by my iPhone.

  • 7/28/2019 cpsc lecture1

    41/46

    But wait, there's more...

    There are now roughly 1,000,000,000 PCs in the world (or 1

    for every 6 people on the planet), yet that number represents

    less than 2% of all the processors in the world. Where are

    the others? Everywhere around you:

    GPS systems

    cell phones

    DVD players

    compact disc players All 50,000,000,000

    iPods of these processors

    calculators execute programsdigital cameras

    automobiles

    household appliances

    children's toys

    and so on...

  • 7/28/2019 cpsc lecture1

    42/46

    But wait, there's more...

    In 1995, a group of computer science experts tried to

    anticipate where computer science research was going.

    Here are some of the things they missed:

    entertainment technologydata mining

    portable communications

    the World Wide Web

    speech recognition

    The ways in which people put computing technology to use

    continue to astound the experts.

  • 7/28/2019 cpsc lecture1

    43/46

    But wait, there's more...

    Advances in computing have already changed the way we

    live, work, learn, and communicate in ways most people

    couldn't have imagined.

    Advances in computing drive advances in nearly all otherfields (see biology, for example).

    Advances in computing drive our economy (especially

    through the uptake of computing by traditional industries

    making them more efficient).

  • 7/28/2019 cpsc lecture1

    44/46

    What's coming? Just imagine...

    much greater understanding of our environment (e.g.,

    wide-spread remote sensor oceanography)

    comprehensive energy management solutions

    automobiles that don't/can't crashindividualized education

    neurobotics

    nanomachines in medicine

    robotic care-givers

    personalized pharmaceuticals based on individual genome

    mapping

  • 7/28/2019 cpsc lecture1

    45/46

    It all starts here

    While we love our computer engineering sisters and

    brothers for continuing to make computers smaller and

    more powerful at the same time, all the advances we just

    talked about depend on software: the computer programs

    that make the machines do something useful.

    And for almost everyone everywhere, the path to creating

    that software starts in introductory computer science

    classes in schools all over the world. You have to learn

    some of the boring stuff before you can start building thecool stuff.

    If you want to play an active role in the ongoing revolution,

    this is where you begin.

  • 7/28/2019 cpsc lecture1

    46/46

    Data collection

    In addition to turning you into incredibly powerful

    computer programmers, we'll also be using you as

    lab rats. We'll of course be using information from

    your quizzes, homework, and exams to inform us

    as to how to facilitate your understanding.

    But we'll also be asking you to participate in other

    data gathering efforts as well. We'll ask you to

    answer questions on various surveys, including theone we'll hand out now. This particular survey will

    help us determine how much programming

    experience you already have.