Python and Object-Oriented Programming: Interpreters, Languages, and Computation - Prof. W, Study notes of Computer Science

The concept of object-oriented programming (oop) in python through various sources, including one-slide summaries, exam questions, and historical context. It covers the benefits of learning new programming languages, the history of oop with simula and smalltalk, and the practical applications of python. The document also includes information about specific python features, such as interpreters and classes.

Typology: Study notes

Pre 2010

Uploaded on 07/29/2009

koofers-user-erq
koofers-user-erq 🇺🇸

5

(1)

10 documents

1 / 9

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Objects Python Interpreters
Objects Python Interpreters
#2
One-Slide Summary
Object-Oriented Programming encapsulates state
and methods together into objects. This hides
implementation details (cf. inheritance) while
allowing methods to operate on many types of input.
Learning new languages has pragmatic value,
expands our minds, deepens our understanding,
builds confidence, and may even be fun.
Python is a universal, imperative, object-oriented
language.
Building an interpreter is a fundamental idea in
computing. Eval and Apply are mutually recursive.
#3
Outline
Object Lessons
Why Python?
Ali G
Interpreters
#4
Exam 2 Extra Credit
2 points on Exam 2: attend talk Thursday
(tomorrow) in GILMER 190 from 3:30 to 4:30pm
Scott Aaronson from MIT:
In the popular imagination, quantum computers would be
almost magical devices, able to "solve impossible problems in an
instant" by trying exponentially many solutions in parallel. In
this talk, I'll describe various results in quantum computing
theory that directly challenge this view. For example, at least
in the "black-box model" that we know how to analyze,
quantum computers would need exponential time to break
cryptographic hash functions or find local optima, just as
classical computers would. As time permits, I'll also describe
how studying the limitations of quantum computers can lead to
new insights even into classical computation.
#5
Where is Gilmer 190?
(17)
upper
left
We are in
(27) now
#6
BACS Info Session
Thursday (tomorrow) 5-6pm Olsson 236D
Enter by the front steps: there will be signs up
For students curious about the BA in CS
The Minor
The Major
Distinguished Majors Program
Required courses, etc.
Can't make it but are interested?
Email Tom Horton (horton@cs.virginia.edu)
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Python and Object-Oriented Programming: Interpreters, Languages, and Computation - Prof. W and more Study notes Computer Science in PDF only on Docsity!

ObjectsObjects PythonPython InterpretersInterpreters

# 2

One-Slide Summary

  • Object-Oriented Programming encapsulates state and methods together into objects. This hides implementation details (cf. inheritance) while allowing methods to operate on many types of input.
  • Learning new languages has pragmatic value, expands our minds, deepens our understanding, builds confidence, and may even be fun.
  • Python is a universal, imperative, object-oriented language.
  • Building an interpreter is a fundamental idea in computing. Eval and Apply are mutually recursive. # 3

Outline

  • Object Lessons
  • Why Python?
  • Ali G
  • Interpreters # 4

Exam 2 Extra Credit

  • 2 points on Exam 2: attend talk Thursday (tomorrow) in GILMER 190 from 3:30 to 4:30pm
  • Scott Aaronson from MIT:
    • In the popular imagination, quantum computers would be almost magical devices, able to "solve impossible problems in an instant" by trying exponentially many solutions in parallel. In this talk, I'll describe various results in quantum computing theory that directly challenge this view. For example, at least in the "black-box model" that we know how to analyze, quantum computers would need exponential time to break cryptographic hash functions or find local optima, just as classical computers would. As time permits, I'll also describe how studying the limitations of quantum computers can lead to new insights even into classical computation.

Where is Gilmer 190?

  • upper
  • left
  • We are in (27) now

BACS Info Session

  • Thursday (tomorrow) 5-6pm Olsson 236D
    • Enter by the front steps: there will be signs up
  • For students curious about the BA in CS
    • The Minor
    • The Major
    • Distinguished Majors Program
    • Required courses, etc.
  • Can't make it but are interested?

# 7

Components

in Sketchpad

Actual Sketchpad: # 8

Objects in Sketchpad

In the process of making the Sketchpad system operate, a few very general functions were developed which make no reference at all to the specific types of entities on which they operate. These general functions give the Sketchpad system the ability to operate on a wide range of problems. The motivation for making the functions as general as possible came from the desire to get as much result as possible from the programming effort involved. For example, the general function for expanding instances makes it possible for Sketchpad to handle any fixed geometry subpicture. The rewards that come from implementing general functions are so great that the author has become reluctant to write any programs for specific jobs. Each of the general functions implemented in the Sketchpad system abstracts, in some sense, some common property of pictures independent of the specific subject matter of the pictures themselves. Ivan Sutherland, Sketchpad: a Man-Machine Graphical Communication System , 1963 (major influence on Alan Kay developing OOP in 1970s) # 9

Simula

  • Considered the first “object-oriented” programming language
  • Language designed for simula tion by Kristen Nygaard and Ole-Johan Dahl (Norway, 1962)
  • Had special syntax for defining classes that package state and procedures together # 10

Counter in Simula

class counter; integer count; begin procedure reset(); count := 0; end; procedure next(); count := count + 1; end; integer procedure current(); current := count; end; end XEROX Palo Alto Research Center (PARC)

  • 1970s:
  • Bitmapped display
  • Graphical User Interface
    • Steve Jobs paid $1M to visit PARC (bought their stock), and returned to make Apple Lisa/Mac
  • Ethernet
  • First personal computer (Alto)
  • PostScript Laser Printers
  • Object-Oriented ProgrammingDon’t worry about what anybody else is going to do… The best way to predict the future is to invent it. Really smart people with reasonable funding can do just about anything that doesn't violate too many of Newton's Laws!” — Alan Kay, 1971

Dynabook,

(Just a model)

# 19 Ada, Countess of Lovelace, around 1843

First Object-Oriented Programmer?

By the word operation, we mean any process which alters the mutual relation of two or more things, be this relation of what kind it may. This is the most general definition, and would include all subjects in the universe. Again, it might act upon other things besides number, were objects found whose mutual fundamental relations could be expressed by those of the abstract science of operations, and which should be also susceptible of adaptations to the action of the operating notation and mechanism of the engine... Supposing, for instance, that the fundamental relations of pitched sounds in the science of harmony and of musical composition were susceptible of such expression and adaptations, the engine might compose elaborate and scientific pieces of music of any degree of complexity or extent. # 20

Liberal Arts Trivia: Biology

  • This family of non-venomous serpents contains the longest snake in the world. They have teeth, heat-sensing organs, and ambush prey. They kill by a process of constriction: sufficient pressure is applied to the prey to prevent it from inhaling, and the prey succumbs to asphyxiation and is swallowed whole. # 21

Liberal Arts Trivia: Chemistry

  • This element is a ductile metal with very high thermal and electrical conductivity. When pure and fresh it has a pinkish or peachy color, but it turns green with age (oxidation). It has played a significant role in the history of humanity. In the Roman era it was usually mined on Cyprus; hence the provenance of its modern name (Cyprium to Cuprum). ImplementingImplementing Interpreters Interpreters

Why learn

Python?

Reason 1: Vocational Skill

Python Java SQL Scheme Job listings at monster.com in Virginia (27 March 2007, postings in last 3 months):

770 $35-200K

27 $40-200K

55 $100-999K

1138 $60-400K

PS5, PS8 & 9

# 25 “ Scheme” Jobs # 26

Reason 2: Expanding Minds

Languages change the way we think. The more languages you know, the more different ways you have of thinking about (and solving) problems. # 27 “Jamais Jamais Jamais” from Harmonice Musices Odhecaton A. Printed by Ottaviano Dei Petrucci in 1501 (first music with movable type) # 28 J S Bach, “Coffee Cantata”, BWV 211 (1732) www.npj.com/homepage/teritowe/jsbhand.html “Jamais Jamais Jamais” from Harmonice Musices Odhecaton A. (1501) Reason 3: Deepening Understanding By seeing how the same concepts we encountered in Scheme are implemented by a different language, you will understand those concepts better (especially classes/objects, assignment, data abstraction).

Reason 4: Building Confidence

By learning Python (mostly) on your own, the next time you encounter a problem that is best solved using a language you don’t know, you will be confident you can learn it (rather than trying to use the wrong tool to solve the problem).

# 39

Ali G was Right!

  • Theory assumes ideal computers:
    • Unlimited, perfect memory
    • Unlimited (finite) time
  • Real computers have:
    • Limited memory, time, power outages, flaky programming languages, etc.
    • There are many computable problems we cannot solve with real computer: the actual inputs do matter (in practice, but not in theory!) # 40

Liberal Arts Trivia: Philosophy

  • In the philosophy of mind, this is used to describe views in which the mind and matter are two ontologically separate categories. In this , neither mind nor matter can be reduced to each other in any way. This is typically opposed to reductive materialism. A well- known example of this is attributed to Descartes, holding that the mind is a nonphysical substance.

Liberal Arts Trivia: Statistics

  • A t-test is a statistical hypothesis test in which the test statistic has a This distribution of the null hypothesis is true. The This distribution arises when estimating the mean of a normally distributed population when the sample size is small. It was first published by William Gosset in 1908 while he worked at a Guinness Brewery in Dublin. The brewery forbade the publication of research by its staff members (!), so he published the paper under a pseudonym.

Implementing

Interpreters

# 43

Inventing a Language

  • Design the grammar
    • What strings are in the language?
    • Use BNF to describe all the strings in the language
  • Make up the evaluation rules
    • Describe what everything the grammar can produce means
  • Build an evaluator
    • A procedure that evaluates expressions in the language # 44

Is this an exaggeration?

It is no exaggeration to regard this as the most fundamental idea in programming: The evaluator, which determines the meaning of expressions in the programming language, is just another program. To appreciate this point is to change our images of ourselves as programmers. We come to see ourselves as designers of languages, rather than only users of languages designed by others. (SICP, p. 360) # 45 Environmental Model of Evaluation

  • To evaluate a combination, evaluate all the subexpressions and apply the value of the first subexpression to the values of the other subexpressions.
  • To apply a compound procedure to a set of arguments, evaluate the body of the procedure in a new environment. To construct this environment, make a new frame with an environment pointer that is the environment of the procedure that contains places with the formal parameters bound to the arguments. # 46

Eval Eval

Apply Apply

Eval and Apply are defined in terms of each other. def meval(expr, env): if isPrimitive(expr): return evalPrimitive(expr) elif isConditional(expr): return evalConditional(expr, env) elif isLambda(expr): return evalLambda(expr, env) elif isDefinition(expr): evalDefinition(expr, env) elif isName(expr): return evalName(expr, env) elif isApplication(expr): return evalApplication(expr, env) else : evalError ("Unknown expression type: " + str(expr))

Implementing

meval

def mapply(proc, operands): if (isPrimitiveProcedure(proc)): return proc(operands) elif isinstance (proc, Procedure): params = proc.getParams() newenv = Environment(proc.getEnvironment()) if len(params) != len(operands): evalError ("Parameter length mismatch: ...") for i in range(0, len(params)): newenv.addVariable(params[i], operands[i]) return meval(proc.getBody(), newenv) else : evalError("Application of non-procedure: %s" % (proc))

Implementing

mapply