Topics Multimedia computing tasks Programming paradigms...

25
CISC 1600 Lecture 2.5 Programming languages Topics: Multimedia computing tasks Programming paradigms Languages we have seen

Transcript of Topics Multimedia computing tasks Programming paradigms...

Page 1: Topics Multimedia computing tasks Programming paradigms ...m.mr-pc.org/t/cisc1600/2017sp/lecture_2_5.pdf · Procedural: sending messages One section of the program can send a message

CISC 1600 Lecture 2.5Programming languages

Topics:Multimedia computing tasks

Programming paradigmsLanguages we have seen

Page 2: Topics Multimedia computing tasks Programming paradigms ...m.mr-pc.org/t/cisc1600/2017sp/lecture_2_5.pdf · Procedural: sending messages One section of the program can send a message

Some multimedia computing tasks

● Compute a number (simulation)

● Draw a picture, generate a sound (synthesis)

● Create a game (interactivity)

Page 3: Topics Multimedia computing tasks Programming paradigms ...m.mr-pc.org/t/cisc1600/2017sp/lecture_2_5.pdf · Procedural: sending messages One section of the program can send a message

How do you makea computer do that?

● Computers read binary instructions and data

● But computers let us build powerful tools– Like programs to make programming easier!

● Compiler: a program that converts programs written in human-readable form into machine-readable form

● Interpreter: a program that runs human-readable programs directly

● Integrated development environment

Page 4: Topics Multimedia computing tasks Programming paradigms ...m.mr-pc.org/t/cisc1600/2017sp/lecture_2_5.pdf · Procedural: sending messages One section of the program can send a message

Programming languages vary by...

● High-level vs low-level– High-level: closer to how people think

– Low-level: closer to how computers operate

● Programming language vs scripting language– Programming: compiled into machine code

– Scripting: interpreted directly

● The programming paradigms they facilitate

Page 5: Topics Multimedia computing tasks Programming paradigms ...m.mr-pc.org/t/cisc1600/2017sp/lecture_2_5.pdf · Procedural: sending messages One section of the program can send a message

High/low, programming/scripting?

Page 6: Topics Multimedia computing tasks Programming paradigms ...m.mr-pc.org/t/cisc1600/2017sp/lecture_2_5.pdf · Procedural: sending messages One section of the program can send a message

Programming paradigms

● Programming paradigm: a style of programming– How you define a program's structure & elements

– Hundreds of different ones

– Each language can support several / many

● We focus on 4 (but you may not have noticed!)– Imperative: a smart list

– Event-driven: responding to events

– Procedural: sending messages

– Object-oriented: a set of interacting objects

Page 7: Topics Multimedia computing tasks Programming paradigms ...m.mr-pc.org/t/cisc1600/2017sp/lecture_2_5.pdf · Procedural: sending messages One section of the program can send a message

Imperative: a smart list

● Tell the computer how to perform a task

● Contrast with– Declarative: telling it what to do, it figures out how

– Event-driven: responds to interrupting events

● Imperative languages need three things– Sequence: an order in which to process information

– Selection: the ability to make a choice (“if” statements)

– Repetition: the ability to repeat an action (“for” loops)

Page 8: Topics Multimedia computing tasks Programming paradigms ...m.mr-pc.org/t/cisc1600/2017sp/lecture_2_5.pdf · Procedural: sending messages One section of the program can send a message

Imperative paradigm in...

Page 9: Topics Multimedia computing tasks Programming paradigms ...m.mr-pc.org/t/cisc1600/2017sp/lecture_2_5.pdf · Procedural: sending messages One section of the program can send a message

Event-driven: responding to events

● Instead of executing a program from top to bottom, execute in response to the environment

● Events can be – User input:

– Network events:

– Messages from other programs:

– Sensor events:

Page 10: Topics Multimedia computing tasks Programming paradigms ...m.mr-pc.org/t/cisc1600/2017sp/lecture_2_5.pdf · Procedural: sending messages One section of the program can send a message

Event-driven: responding to events

● Instead of executing a program from top to bottom, execute in response to the environment

● Events can be – User input: key pressed, button clicked

– Network events: request, response, activity

– Messages from other programs: like network, but on the same computer

– Sensor events: sound or video frame recorded

Page 11: Topics Multimedia computing tasks Programming paradigms ...m.mr-pc.org/t/cisc1600/2017sp/lecture_2_5.pdf · Procedural: sending messages One section of the program can send a message

Event-driven paradigm in...

Page 12: Topics Multimedia computing tasks Programming paradigms ...m.mr-pc.org/t/cisc1600/2017sp/lecture_2_5.pdf · Procedural: sending messages One section of the program can send a message

Procedural: sending messages

● One section of the program can send a message to another section & receive a well-defined response

● Allows for code reuse, modularity

● Types of procedure calls– Function calls within a program

– Message passing between objects / agents

– Remote procedure calls (e.g., REST) over networks

● My advice– Write lots of short single-purpose procedures

– Don’t repeat yourself

Page 13: Topics Multimedia computing tasks Programming paradigms ...m.mr-pc.org/t/cisc1600/2017sp/lecture_2_5.pdf · Procedural: sending messages One section of the program can send a message

Procedural paradigm in...

Page 14: Topics Multimedia computing tasks Programming paradigms ...m.mr-pc.org/t/cisc1600/2017sp/lecture_2_5.pdf · Procedural: sending messages One section of the program can send a message

Object-oriented: interacting objects

● Visualize a program as a set of interacting objects

● Identify facts and functions of each object– Facts: properties of objects, current state

– Functions: procedures, possible operations

● Objects are instances of classes

● ChessPiece is a class, each piece on board is an object– Facts: current position on board

– Functions: possible next moves

Page 15: Topics Multimedia computing tasks Programming paradigms ...m.mr-pc.org/t/cisc1600/2017sp/lecture_2_5.pdf · Procedural: sending messages One section of the program can send a message

Object-oriented paradigm in...

Page 16: Topics Multimedia computing tasks Programming paradigms ...m.mr-pc.org/t/cisc1600/2017sp/lecture_2_5.pdf · Procedural: sending messages One section of the program can send a message

These paradigms are of different types

● Control flow: interactivity– Imperative

– Event-driven

● Code organization: modularity and reuse– Procedural

– Object-oriented

Page 17: Topics Multimedia computing tasks Programming paradigms ...m.mr-pc.org/t/cisc1600/2017sp/lecture_2_5.pdf · Procedural: sending messages One section of the program can send a message

Which paradigms fit these tasks?

● Compute a number (simulation)

● Draw a picture, generate a sound (synthesis)

● Create a game (interactivity)

Page 18: Topics Multimedia computing tasks Programming paradigms ...m.mr-pc.org/t/cisc1600/2017sp/lecture_2_5.pdf · Procedural: sending messages One section of the program can send a message

Programming languages in this course

Page 19: Topics Multimedia computing tasks Programming paradigms ...m.mr-pc.org/t/cisc1600/2017sp/lecture_2_5.pdf · Procedural: sending messages One section of the program can send a message

Processing

● Goal: draw pictures, animations

● Interactivity: moderate– can be event driven

● Modularity: high – object oriented

Page 20: Topics Multimedia computing tasks Programming paradigms ...m.mr-pc.org/t/cisc1600/2017sp/lecture_2_5.pdf · Procedural: sending messages One section of the program can send a message

Processing

● Goal: draw pictures, animations

● Interactivity: –

● Modularity: –

Page 21: Topics Multimedia computing tasks Programming paradigms ...m.mr-pc.org/t/cisc1600/2017sp/lecture_2_5.pdf · Procedural: sending messages One section of the program can send a message

Javascript

● Original goal: add interactivity to web pages

● New goal: general purpose, cross-platform computing

● Interactivity: high– event-driven, imperative

● Modularity: high– object oriented, procedural

Page 22: Topics Multimedia computing tasks Programming paradigms ...m.mr-pc.org/t/cisc1600/2017sp/lecture_2_5.pdf · Procedural: sending messages One section of the program can send a message

Javascript

● Original goal: add interactivity to web pages

● New goal: general purpose, cross-platform computing

● Interactivity: –

● Modularity: –

Page 23: Topics Multimedia computing tasks Programming paradigms ...m.mr-pc.org/t/cisc1600/2017sp/lecture_2_5.pdf · Procedural: sending messages One section of the program can send a message

Scratch

● Goal: build interactive games, animations

● Interactivity high: event-driven, imperative

● Modularity high: sprites are objects, agents

Page 24: Topics Multimedia computing tasks Programming paradigms ...m.mr-pc.org/t/cisc1600/2017sp/lecture_2_5.pdf · Procedural: sending messages One section of the program can send a message

NetLogo

● Goal: simulate interacting “agents”

● Interactivity low: imperative– Agents interact with

each other

● Modularity high: object oriented, agent-based

Page 25: Topics Multimedia computing tasks Programming paradigms ...m.mr-pc.org/t/cisc1600/2017sp/lecture_2_5.pdf · Procedural: sending messages One section of the program can send a message

Summary

● Different programming tasks are easier in different programming paradigms

● Different programming paradigms are easier in different programming languages

● We will cover a decent variety of languages in this course that facilitate the paradigms of– Imperative, event-driven, procedural, and object-oriented

● (Don’t repeat yourself)