Chapter 1 Study Guide -- CSC 200 -

advertisement
CSC 200 Study Guide – Fall 2010
Chapter 15 Functional Programming
Chapter Learning Objectives





To write programs more easily with more functions.
To use functional programming to make powerful programs
quickly.
To understand what makes functional programming different
from procedural or imperative programming.
To be able to use else in Python.
To be able to use global in Python.
Instructions


We covered most of the key concepts from this chapter in Chapter 9 Building
Bigger Programs. Missing information from this chapter is included here.
The only pages required from this chapter are page 339-340, 342 and page 348.
Chapter Concepts
There are 4 basic programming language paradigms.
1. Procedural Programming Model (also called Imperative Model) is the oldest
and most common model. These languages allow the programmer to express
algorithms as a hierarchy of tasks. The imperative paradigm is characterized by
sequential execution of instructions, the use of variables that represent memory
locations, and the use of assignment statements that change the value of the
variables. Languages include FORTRAN, COBOL, BASIC, C, Pascal, and Ada.
2. Functional Programming Model is based on the mathematical concept of the
function. The solution to a problem is expressed in terms of mathematical
functions. The basic mechanism is the evaluation of functions; there are no
variables and no assignment statements. There are no looping constructions;
repetition is expressed in terms of recursion. Functional programming has its roots
in Lambda calculus. Functional models are emphasized in primarily in academic
research instead of commercial software languages. Languages include Lisp,
Scheme, Haskell and ML. Mathematica (symbolic Math) software program is
used in some math classes and is based on the functional model.
3. Logic Programming Model is based on the principles of symbolic logic. The
model comprises a set of facts about objects and a set of rules about the
relationships among the objects. The underlying problem-solving algorithm uses
CSC 200
Page 1
Chapter 15 Study Guide
the rules of logic to deduce the answer from the facts and rules. Logic models are
used primarily in the field of Artificial Intelligence. Programming language include
PROLOG and Lisp.
4. Object-Oriented Programming Model is the newest paradigm. This model
views the world as a collection of interacting objects. Each object is defined by
a class, and the actions are defined by methods. These languages allow the
programmer to express algorithms using a hierarchy of objects. Languages
include SIMULA, Smalltalk, C++, Visual Basic .NET, and Visual C++.
Remember that a programming language can support more than one programming
paradigm. For example programs written in C++ can be purely procedural or purely
object-oriented or contain elements of both.
If you are creating a procedural program, then you need to use the Procedural
Abstraction Process:




State the problem. Figure out what you want to do.
Break the problem into subproblems.
Keep breaking the subproblems into small problems until you know how to write
the program to solve the subproblem.
Your goal is for the main procedure to basically tell all the subprocedures what to
do. Each procedure should do one and only one logical task.
Recursion is writing functions or procedures that call themselves. Instead of writing
loops, you write a function that loops by calling itself. To avoid endless recursion you
need to specify what to do to end the process. (See page 348)
Short History of Programming Languages
1. Machine Language -program instructions were written in binary
2. Assembly Language - program instructions were 4 letter word mnemonics such
as LOAD, ADD, STOR etc. Every computer processor has a different language.
3. Procedural (High-Level) Languages - Program instructions were more English
like statements. Languages included FORTRAN, COBOL and LISP.
4. Structured Programming (High-Level) Languages - These languages included
better programming techniques for a more disciplined approach to programming.
Languages include Pascal, Modula2, BASIC, C and C++. C++ was a language that
allowed a programming access to low-level statements and was the most popular
industry language during this timeframe (1971 - 1989).
5. Object-Oriented Programming Languages - With the advent of GUI interfaces,
Windows O/S and Mac, programmers needed more flexibility to create graphical
interfaces. Object-Oriented languages made GUIs easier to create. Languages
include C++, SIMULA, and Smalltalk.
6. Internet Programming Languages - The Internet brought new challenges for
programmers, so new languages were created including Java, Javascript, and
PERL.
CSC 200
Page 2
Chapter 15 Study Guide
References:
"Programming paradigm" article from Wikipedia.com retrieved 12-2-2010.
Nell Dale and John Lewis, "High-Level Programming Languages Chapter" in Computer
Science Illuminated 3rd Edition Copyright 2007 Johns and Bartlett Publishers
Last Update: February 12, 2016
Study Guide created by Carlotta Eaton
For Introduction to Computing and Programming in Python – A Multimedia Approach by Guzdial & Ericson 2nd
edition
CSC 200
Page 3
Download