teaching machines

CS 330 Lecture 36 – Object-oriented Programming

May 2, 2016 by . Filed under cs330, lectures, spring 2016.

Agenda

TODO

Note

We’ve trekked through the shell as a tool to program out interaction with the computer, regular expressions as a pattern language for recognizing structured text, the inner workings of an interpreter, assembly as the foundational language for talking with our machines, C as a pretty spare layer of abstraction over assembly, and the ability of functional programming to express a vast number of algorithms but leave little holes in them that we may customize their work according to our needs. Now it’s time to hit up object-oriented programming.

Our treatment of OOP begins with C++. Many modern languages support C++, but C++ was probably the first language with OOP to achieve widespread adoption.

Object-oriented programming is said to be founded on three pillars:

We will define this, but focus on encapsulation. Inheritance is great for library writers who must craft a hierarchy of types. Polymorphism is great for library users who want the library to process their types just as well as its own. On the ground, though, we spend far more time just organizing our own code into classes.

In our discussion, we’ll touch upon a variety of issues that are relevant to our study of programming languages:

Code

world.rb

/usr/lib/ruby/2.7.0/rubygems/dependency.rb:311:in `to_specs': Could not find 'coderay' (>= 0) among 56 total gem(s) (Gem::MissingSpecError)
Checked in 'GEM_PATH=/.gem/ruby/2.7.0:/var/lib/gems/2.7.0:/usr/lib/ruby/gems/2.7.0:/usr/share/rubygems-integration/2.7.0:/usr/share/rubygems-integration/all:/usr/lib/x86_64-linux-gnu/rubygems-integration/2.7.0:/home/johnch/.gems', execute `gem env` for more information
	from /usr/lib/ruby/2.7.0/rubygems/dependency.rb:323:in `to_spec'
	from /usr/lib/ruby/2.7.0/rubygems/core_ext/kernel_gem.rb:62:in `gem'
	from ./coderay:24:in `
'

twoface.cpp

/usr/lib/ruby/2.7.0/rubygems/dependency.rb:311:in `to_specs': Could not find 'coderay' (>= 0) among 56 total gem(s) (Gem::MissingSpecError)
Checked in 'GEM_PATH=/.gem/ruby/2.7.0:/var/lib/gems/2.7.0:/usr/lib/ruby/gems/2.7.0:/usr/share/rubygems-integration/2.7.0:/usr/share/rubygems-integration/all:/usr/lib/x86_64-linux-gnu/rubygems-integration/2.7.0:/home/johnch/.gems', execute `gem env` for more information
	from /usr/lib/ruby/2.7.0/rubygems/dependency.rb:323:in `to_spec'
	from /usr/lib/ruby/2.7.0/rubygems/core_ext/kernel_gem.rb:62:in `gem'
	from ./coderay:24:in `
'