Programming Languages Dan Grossman 2013

Slides:



Advertisements
Similar presentations
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Winter 2013.
Advertisements

CSE341: Programming Languages Lecture 23 OO vs. Functional Decomposition; Adding Operations & Variants; Double-Dispatch Dan Grossman Fall 2011.
Objectives Introduction to Inheritance and Composition (Subclasses and SuperClasses) Overriding (and extending), and inheriting methods and constructors.
CSE341: Programming Languages Lecture 26 Subtyping for OOP Dan Grossman Fall 2011.
CSE341: Programming Languages Lecture 22 OOP vs. Functional Decomposition; Adding Operators & Variants; Double-Dispatch Dan Grossman Spring 2013.
CSE 341 Programming Languages Dynamic Dispatch vs. Closures OOP vs. Functional Decomposition Wrapping Up Zach Tatlock Spring 2014.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
(c) University of Washington06-1 CSC 143 Java Inheritance Tidbits.
Notes Over 4.2 Finding the Product of Two Matrices Find the product. If it is not defined, state the reason. To multiply matrices, the number of columns.
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Spring 2013.
Programming Languages Dan Grossman 2013 Datatype-Programming in Racket Without Structs.
CSE341: Programming Languages Lecture 26 Course Victory Lap
Programming Languages Dan Grossman 2013
CSE341: Programming Languages Lecture 21 Dynamic Dispatch Precisely, and Manually in Racket Dan Grossman Spring 2016.
Programming Languages Dan Grossman 2013
CSE341: Programming Languages Lecture 22 OOP vs
Programming Languages Dan Grossman 2013
Programming Languages Dan Grossman 2013
Programming Languages Dan Grossman 2013
CSE341: Programming Languages Lecture 21 Dynamic Dispatch Precisely, and Manually in Racket Dan Grossman Winter 2013.
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Autumn 2017.
Programming Languages Dan Grossman 2013
Programming Languages Dan Grossman 2013
CSE341: Programming Languages Lecture 21 Dynamic Dispatch Precisely, and Manually in Racket Dan Grossman Spring 2017.
Programming Languages Dan Grossman 2013
CSE 341 Section 9 Nick Mooney Spring 2017
Chapter 2: Data Abstraction 2
Programming Languages Dan Grossman 2013
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Winter 2013.
CSE341: Programming Languages Lecture 21 Dynamic Dispatch Precisely, and Manually in Racket Dan Grossman Autumn 2017.
CSE341: Programming Languages Lecture 22 OOP vs
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Spring 2017.
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Spring 2013.
ATS Application Programming: Java Programming
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Zach Tatlock Winter 2018.
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Spring 2017.
11/16/2018 The PL Part of CS2013 Dan Grossman Department of Computer Science & Engineering University of Washington SPLASH-E October 28, 2013.
Chapter 10 Thinking in Objects
CSE341: Programming Languages Lecture 26 Course Victory Lap
CSE341: Programming Languages Lecture 21 Dynamic Dispatch Precisely, and Manually in Racket Dan Grossman Autumn 2018.
CSE341: Programming Languages Lecture 22 OOP vs
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Autumn 2018.
CSE 341 Section 9 Winter 2018 Adapted from slides by Eric Mullen, Nick Mooney, Nicholas Shahan, Cody Schroeder, and Dan Grossman.
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Winter 2018.
Advanced Java Programming
Week 4 Object-based Programming (2) Classes and Objects: A Deeper Look
CSE341: Programming Languages Section 9 Dynamic Dispatch Manually in Racket Zach Tatlock Winter 2018.
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Autumn 2018.
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Autumn 2017.
CSE341: Programming Languages Lecture 26 Course Victory Lap
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Spring 2016.
Nicholas Shahan Spring 2016
CSE341: Programming Languages Lecture 26 Course Victory Lap
CS 240 – Lecture 7 Boolean Operations, Increment and Decrement Operators, Constant Types, enum Types, Precedence.
Unit 6 part 5 Test Javascript Test.
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Spring 2016.
CSE341: Programming Languages Lecture 22 OOP vs
CSE 341 Section 9 Fall 2017 Adapted from slides by Nick Mooney, Nicholas Shahan, Cody Schroeder, and Dan Grossman.
Introducing Java.
Programming Languages Dan Grossman 2013
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Spring 2019.
CSE341: Programming Languages Lecture 22 OOP vs
Brett Wortzman Summer 2019 Slides originally created by Dan Grossman
CSE341: Programming Languages Lecture 21 Dynamic Dispatch Precisely, and Manually in Racket Dan Grossman Spring 2019.
CSE341: Programming Languages Lecture 22 OOP vs
CSE341: Programming Languages Lecture 26 Course Victory Lap
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Spring 2019.
Presentation transcript:

Programming Languages Dan Grossman 2013 OOP vs. Functional Decomposition

Dan Grossman, Programming Languages Breaking things down In functional (and procedural) programming, break programs down into functions that perform some operation In object-oriented programming, break programs down into classes that give behavior to some kind of data Beginning of this unit: These two forms of decomposition are so exactly opposite that they are two ways of looking at the same “matrix” Which form is “better” is somewhat personal taste, but also depends on how you expect to change/extend software For some operations over two (multiple) arguments, functions and pattern-matching are straightforward, but with OOP we can do it with double dispatch (multiple dispatch) Jan-Mar 2013 Dan Grossman, Programming Languages

The expression example Well-known and compelling example of a common pattern: Expressions for a small language Different variants of expressions: ints, additions, negations, … Different operations to perform: eval, toString, hasZero, … Leads to a matrix (2D-grid) of variants and operations Implementation will involve deciding what “should happen” for each entry in the grid regardless of the PL eval toString hasZero … Int Add Negate Jan-Mar 2013 Dan Grossman, Programming Languages

Standard approach in ML eval toString hasZero … Int Add Negate Define a datatype, with one constructor for each variant (No need to indicate datatypes if dynamically typed) “Fill out the grid” via one function per column Each function has one branch for each column entry Can combine cases (e.g., with wildcard patterns) if multiple entries in column are the same [See the ML code] Jan-Mar 2013 Dan Grossman, Programming Languages

Standard approach in OOP eval toString hasZero … Int Add Negate Define a class, with one abstract method for each operation (No need to indicate abstract methods if dynamically typed) Define a subclass for each variant So “fill out the grid” via one class per row with one method implementation for each grid position Can use a method in the superclass if there is a default for multiple entries in a column [See the Ruby code] [Optional: See the Java code] Jan-Mar 2013 Dan Grossman, Programming Languages

Dan Grossman, Programming Languages A big course punchline eval toString hasZero … Int Add Negate FP and OOP often doing the same thing in exact opposite way Organize the program “by rows” or “by columns” Which is “most natural” may depend on what you are doing (e.g., an interpreter vs. a GUI) or personal taste Code layout is important, but there is no perfect way since software has many dimensions of structure Tools, IDEs can help with multiple “views” (e.g., rows / columns) Jan-Mar 2013 Dan Grossman, Programming Languages