Lecture 1 Slides - Data Flow Diagrams (Pre-Recorded)

1 of 21

Lecture 1 (Pre-Recorded)

Data Flow Diagrams

2 of 21

The functional model of computation

A computation

  • Takes a set of inputs
    • Information encoded in some representation(s)
  • Does some stuff (computes)
  • Generates an output
    • Again, information encoded in some representation
  • Stops

input(s)

output

COMPUTE

3 of 21

Programming is a psychological discipline

  • Reasoning about the actual physical layout of data as binary text is an unnecessary burden on programmers
    • Most people don’t think well in binary
  • So we design programming languages to match how we think about our data so much as possible
  • Your programming language’s compiler and run-time system manage storage for you so you can think in terms of objects instead of bits

4 of 21

Objects

  • A computer’s memory is ultimately implemented as binary text
    • In other words, a series of 0s and 1s.
  • In practice, that text is really a bunch of separate representations of different pieces of data
  • Each of those representations of a piece of data is known as an object

5 of 21

Everything is an object

  • So from now on, everything in your computer’s memory is an object
    • Primitive (indivisible) data objects
      • Numbers (1, 7, -3.5)
      • Text strings ("bla bla bla")
      • functions
    • Compound data objects
      • Tables of data
      • Lists of objects
      • Bitmaps (contain many little color objects, one per pixel)
      • Sounds (contain 1 number per sound sample)

6 of 21

Objects and computation

When we do computation, we traffic in objects

    • Objects are the inputs to functions
    • Objects are the outputs of functions

7 of 21

Types of Objects (aka Data Types)

  • Computers have a taxonomy of types of data objects
  • Every object has a type
    • The object’s type determines what functions it can be used with
    • Example: Can add numbers, but not pictures or functions

object

number

integer

float

function

point

color

picture

string

boolean

exception

contract-violation

arity-mismatch

8 of 21

Calls and data flow

9 of 21

Function calls

  • When we run a function/program, we
    • Specify one data object for each of its inputs
    • Receive one data object as its output
  • Calls are so important, they have many synonyms
    • Run: execute, call, apply, invoke
    • Input: argument, parameter
      • Or: pass (as in “pass the function 2 as an argument”)
    • Output: result, return value

10 of 21

Data flow diagrams

  • Most programming languages use textual notations
  • We will start with a graphical notation called a data flow diagram
    • Easy to understand what is an input to what and what’s the output
    • Doesn’t scale well to complicated programs

  • We’re using this as an informal learning tool: don’t get hung up on trying to memorize the details of it

11 of 21

Changing the inputs changes the output

12 of 21

Except when it doesn’t

13 of 21

Chaining calls

  • In functional programming, programs/functions are built up by chaining together calls of existing functions
    • The output of one becomes the input of another
  • Data flows through the chain, from left to right
    • Hence the name data flow diagram

14 of 21

Chaining chains

15 of 21

A single object can be used as input to many functions

16 of 21

Order of inputs (usually) matters

17 of 21

Different diagrams can produce the same result

18 of 21

Computers are literal-minded

19 of 21

What versus how

  • Over time, you’ll want to learn how to look past the code to understand what a function is trying to do
    • What it computes
    • Versus how it computes it

20 of 21

What versus how

  • Over time, you’ll want to learn how to look past the code to understand what a function is trying to do
    • What it computes
    • Versus how it computes it

Gives the first however many

characters of the input string

21 of 21

Big ideas

  • Data consists of objects
  • Objects come in different types
    • Determines what operations can be performed on it
  • Inputs and outputs of functions are objects
  • Most computation is done by chaining function calls