Lecture 10: Using ObjectOriented Languages You can't think seriously about thinking without thinking about thinking about something. Seymour Papert Today’s corollary: You can’t think.

Download Report

Transcript Lecture 10: Using ObjectOriented Languages You can't think seriously about thinking without thinking about thinking about something. Seymour Papert Today’s corollary: You can’t think.

Lecture 10: Using ObjectOriented Languages
You can't think seriously about thinking without thinking
about thinking about something.
Seymour Papert
Today’s corollary: You can’t think seriously about
programming, without thinking about programming
something.
Start working in groups as described in the manifest.
CS655: Programming Languages
David Evans
University of Virginia
http://www.cs.virginia.edu/~evans
Computer Science
Menu
• Today’s Task
• Position Paper Hints
• Contravariance, covariance and skiteam room-mates
• Language team sales pitches
6 November 2015
University of Virginia CS 655
2
Today’s Task
• Show a high-level module design for your web
browser
– Depending on the language, this might have
subclassing, subtyping and uses relationships.
• Show a concrete code excerpt for redisplaying
all the elements
• Argue that your design (in conjunction with your
implementation language) is superior to
alternatives
• Assume all languages have equally good
development tools, well-trained programmers,
etc.
6 November 2015
University of Virginia CS 655
3
Position Paper Hints
• Average on Position Paper 2 = 0.89
(12 out of 25 were 1.0 or above)
• Make sure to answer the assigned question
– If it isn’t clear, ask
• If you make general statements, back them
up with real examples
• Don’t turn in a laundry list – select and
organize the important things
• Be resourceful, cite your resources
– Things in your references list should be cited in
your text (e.g., Bounds checking can be added to
C [Wahbe93] ...)
6 November 2015
University of Virginia CS 655
4
Contra/Co-Variance
Athlete
Skier
set_roommate (Skier)
Boy
6 November 2015
Girl
How can Girl override set_roomate?
Covariance: (Eiffel)
set_roommate (Girl)
set_roommate (Boy)
Contravariance: (Sather)
set_roommate (Athlete)
Novariance: (C++ - but changing?, Java)
set_roommate (Skier)
Problem:
s: skier; g: girl; b: boy;
s := g; ... s.set_roommate (b);
University of Virginia CS 655
5
What’s wrong with Meyer’s Rule?
• Disallow polymorphic catcalls:
s.f (t) where some subtype of type of s
hides f or changes covariantly type of
parameters of f.
• Violates useful notion of subtyping:
adding a new subtype breaks existing
programs!
6 November 2015
University of Virginia CS 655
6
What does C++ do?
• Can add covariant methods in subtype, but they
overload the original method, instead of
overriding it!
• Example:
class skier { virtual void set_roommate (class skier *); }
class girl : public skier {
void set_roommate (class girl *); // overloads! }
// class boy similar
skier *s; girl *g; boy *b;
s = g;
s->set_roommate (b); // No type error – calls skier::set_roommate!
g->set_roommate (b); // Some compilers complain (but shouldn’t?)
Good explanation is worth 1 position paper point.
6 November 2015
University of Virginia CS 655
7
Some C++ Facts
• 1996 Draft Standard is 680 pages long
– 50x more complex than Algol60! Is this progress?
• Current open issues list of Core Language
Issues contains 173 issues
– Compare to Knuth’s 9 ambiguities in Algol 60
• Current open issues list for standard library
(Revision 12) is 59 pages
• Good luck!
6 November 2015
University of Virginia CS 655
8
Browser Design Pitches
• Next time: John Viega on Automated
Delegation solution to Multiple
Inheritance
• Think of and send me one good
question.
• Accomplish something interesting to talk
about in your project meetings.
6 November 2015
University of Virginia CS 655
9