Lecture Notes
Introduction to Programming and Algorithm Design (COP-1000)

The way of the program

This chapter introduces you to several of the basic concepts of computer science (CS). It is easy to read, but like much in CS, is deeper than it at first appears. There are a lot of definitions you need to learn (listed in the Glossary at the end of the chapter) learn them, because this is the language we will be using to study CS.

Two definitions

  • Our text does not provide a definition two of the most basic terms we need
  • First, what is a computer?

... a machine that stores and manipulates information under the control of a changeable program.

  • Both parts of this definition are important: the first part describes what a computer does, the second how it does it
von Neumann Architecture

John von Neumann (1903-1957)

  • Some questions to consider:
    • Why do we (humans) need to manipulate information?
    • How did we do this before we had computers?
    • Have computers enabled us to do that we could not do before?
  • Second, what is computer science?

... the study of what can be computed.

  • This is much broader than the usual definition of CS as simply the "study of computers"
  • For a deeper discussion of the areas in CS, refer to the very fine free online encyclopedia Wikipedia; this link will get you started
  • A question to ponder:
    • How is computer science different from electrical engineering? From mathematics? From Physics? In what ways is it similar?

The most important CS skill: Problem Solving

  • The "study of what can be computed" means to study how problems can  be solved computationally

Who is a Computer Scientist?

A computer scientist needs to be able to:
  • State a problem precisely
  • Think creatively about solutions
  • Express a solution clearly and accurately

To do this, a computer scientist uses a variety of skills, including:

  • Analysis
  • Pattern recognition
  • Patience and persistence

(At left is Barbara Liskov, MIT Institute Professor and 2008 Turing Award winner.)

  • Learning to program allows you to develop these abilities, and apply them to both CS and other areas as well

The Python programming language

  • Python is a high-level language (like C, C++, Java, COBOL)
  • The arithmetic and logic circuits in a computer's central processing unit (CPU) can execute only instructions written in binary, low-level languages (also called machine languages)
  • High-level languages are human readable, but must be translated into the binary, low-level language a computer understands before it can be run; this translation is handled either by an interpreter or a compiler, depending on the language:

  • Python is an interpreted language; you can use Python in one of two modes:
    • Command-line mode: you type a statement at the keyboard, and the Python interpreter translates and executes it immediately; this is the way we demonstrate or test a single statement
    • Script mode: you type a series of statements using a text editor, and save them in a file; the Python interpreter can then read the file and execute each command; this is the usual way we write Python programs we want to save
  • The easiest way to use Python in either mode is with the IDLE program provided with the Python installation; it includes both the Python Shell that lets you use command-line mode, and a text editor you can use to code and save Python scripts
  • You can download Python for free from www.python.org; follow the instructions here to download and install it on your personal computer

What is a program?

  • A program is:

        a sequence of instructions that specifies how to perform a computation
  • What kind of instructions can we use? There are only five types:

    • input: obtain a value from the keyboard, a file, or other device
    • output: display data on the monitor, send it to a file or other device
    • math: calculate a value using math operations
    • conditional execution: check a condition to determine what sequence of instructions to execute
    • repetition: check a condition to see if a sequence of instructions should be repeated
  • The job of a programmer is to take a complex problem and reduce it to smaller and smaller problems until each one can be solved using just the basic instructions above

Who is a Programmer?

A programmer is a ...
  • Problem solver: Engineer
  • Discoverer: Scientist
  • Creator: Artist
  • Designer: Architect
  • Revolutionary: Rebel

(At right is Bill Atkinson, creator of MacPaint, HyperCard, and the Mac QuickDraw toolbox)

  • A programmer develops a program through a series of activities call the program development cycle:

What is debugging?

  • In the process of creating a program, a programmer can make many errors, but they are mainly of two types:

    • Syntax errors are those related to the form of the program its grammar and structure. These errors are identified by the interpreter or compiler, because they are unable to translate the statements in the program's high-level language to machine language
    • Semantic errors (also called logic errors) are those related to design of the program. A program may be syntactically correct, yet produce the wrong output. Because an interpreter or compiler can't identify semantic errors, these are much harder to find and fix than syntax errors.
  • Debugging is the process of identifying and correcting syntax and semantic errors

  • A third type of error that can occur is a runtime error (also called an exception); these occur when something unexpected occurs when the program is executing, such as a missing file, or data that is input in the wrong format

Formal and natural languages

  • Natural languages are those that people use to communicate, like English. They may have rules, but the language has evolved over time.
  • Formal languages are those that have been designed for a specific application, like chemistry, music, mathematics, or programming
  • Programmers analyze problems described in a natural language, but must design and implement solutions in a formal language in the case of this class, English and Python, respectively. What is the difference?
  English Python
Ambiguity Lots None
Redundancy High Low
Literalness Fuzzy Exact
  • As a result, Python (like all programming languages) must be read and written differently from English (or any other natural language); pay close attention to:
    • Spelling (and case)
    • Syntax rules (grammar)
    • Structure (indentation)
    • Sequence (order of instructions)
  • Is this a language? What kind?

The first program

  • Start the Python IDLE and type in the universal first program in the Python Shell:

>>> print "Hello, world!"
Hello, world!

  • Now do the programming lab available here
 Updated: 12.13.2010