CS10: The Beauty and Joy of Computing - Fall 2021
Lecture 14: Programming Paradigms, Midterm Review
As We Prepare To Step Into Python
Monday 10/11 was our last day of Snap! in lecture before we move on to Python.
Python, though quite similar to Snap! in many ways, will make you think differently.
Programming Paradigms
Programming Paradigms
Paradigm (Merriam Webster): a typical example or pattern of something; a model. Example: "there is a new paradigm for public art in this country"
Programming Paradigm (Joe Turner, Clemson University): “A programming paradigm is a general approach, orientation, or philosophy of programming that can be used when implementing a program.”
Example, three very different approaches to squaring list:
Word of Warning
There is no universally agreed upon taxonomy of human programming styles.
One possible list:
These terms are a bit fluid, and as you’ll see if you read more on wikipedia, there is substantial disagreement about these terms.�
Programming Paradigms
Example, three very different approaches to squaring list:
The Imperative Programming Paradigm
An imperative program provides a sequence of steps.
Example (acronym):
The Functional Programming Paradigm
In functional programming, computation is thought of in terms of the evaluation of functions.
A Hybrid Approach
These paradigms are not official rules. Just attempts to taxonomize approaches taken by humans.
Array operation!
Discussion and Debate
Which of these do you like best?
Easy to come back and read it later.
Less to keep track of.
Liked this more when first learning. More natural. More similar to the way we think about problems.
Imperative vs. Functional
Can argue that functional is a subset of imperative.
Programs in the functional paradigm:
The Object Based Programming Paradigm
In object programming, we organize our thinking around objects, each containing its own data, and each with its own procedures that can be invoked.
Sprites in Snap! are objects.
The Object Based Programming Paradigm
There is a LOT more to object oriented programming.
Declarative Programming
In declarative programming, we express what we want, without specifying how. A program is simply a description of the result we want.
Declarative Programming
In declarative programming, we express what we want, without specifying how. A program is simply a description of the result we want.
Example: coloring a map of Germany using the Prolog language:�
Prolog Example (From Bernardo Pires)
Tell Prolog that colors exist: Tell Prolog that same colors can’t touch:
Tell Prolog all the borders:
Ask Prolog for answer:
Declarative Programming
In declarative programming, we express what we want, without specifying how. A program is simply a description of the result we want.
Another example, coloring a map of Germany using the Prolog language:�
Declarative Programming
Each declarative language has only a limited number of tasks for which you can specify “what”, and not “how”, e.g.
Universality
Each of the discussed paradigms (imperative, functional, object-based, array based, declarative) are simply philosophies.
Recall that any Turing Complete language can perform any computation that any other language can perform.
Open Q&A / Midterm Review