6: What is a programming language Eventdriven programming - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

6: What is a programming language Eventdriven programming

Description:

onclick= alert('you clicked me')' onload= alert('You are loading a page' ... onClick. onDblClick. onKeyDown. onKeyPress. onKeyUp. onError. onAbort. onLoad ... – PowerPoint PPT presentation

Number of Views:47
Avg rating:3.0/5.0
Slides: 17
Provided by: markels
Category:

less

Transcript and Presenter's Notes

Title: 6: What is a programming language Eventdriven programming


1
6 What is a programming language? /
Event-driven programming
  • Mark Elsom-Cook 1999

2
Programming vs. Description
  • Programming language is not a description
    language
  • It does things
  • Define things to do, then do them (execute)
  • Instructions vs. control structure
  • Interpreted vs. compiled

3
What makes a programming language?
  • Instructions
  • Conditionals
  • Repeated behaviour
  • Variables and data structures
  • Input and Output
  • Data plus Algorithms that work on that data

4
Classes of languages
  • Command
  • Procedural
  • Functional
  • (Logic)
  • Object-oriented

5
Command languages
  • Linear sequence
  • Jump, go to and Return
  • e.g. Basic, Assembly language
  • 1 x 3
  • 2 y 3
  • 3 z x y
  • 4 print z

6
Procedural languages
  • Procedure is named and has parameters
  • Local and Global variables
  • reusable
  • Top procedure
  • e.g. C, Pascal
  • procedure greet(name)
  • writeln(Hello there name)
  • end procedure

7
Functional languages
  • Functions
  • like procedures but return values
  • Embed functions in functions
  • Top function
  • Can ignore values and treat like procedural
  • e.g. Lisp, JavaScript
  • (defun hypot (x y)
  • (sqrt (plus (times x x) (times y y))))

8
Object-oriented languages
  • Objects contain data and procedures
  • Objects communicate via messages
  • e.g. Java, Smalltalk, C
  • class triangle extends shape
  • int base, height
  • int angle
  • int area ()
  • area height base / 2

9
So
  • We will be learning
  • Functional programming
  • in JavaScript
  • Java and JavaScript are proper languages except
    they do not allow reading and writing files

10
Event-Driven programming
11
What is event-driven?
  • Old languages go from beginning to end
  • Event-driven languages call procedures/fns
  • from other procedures
  • when an event happens
  • Event-driven essential for interfaces and GUI
  • e.g. Mac OS, Windows
  • Most modern language support events

12
Event concepts
  • An event
  • type data
  • keypress a
  • click 230, 421
  • Event Loop
  • Processes User Events
  • Calls correct procedures

13
Events, HTML and JavaScript
  • Some HTML tags have event attributes
  • These attributes can have Javascript values
  • onclickalert(you clicked me)
  • onloadalert(You are loading a page)
  • onmouseenteralert(Hello mouse)
  • Definitely need string quotes round code

14
Easy JavaScript code for events
  • Three very useful bits for events
  • alert(This is a message)
  • prompt(What day is it?)
  • confirm(Fancy a coffee? Y/N)
  • Attaching these to bits of tag
  • good for debugging
  • quick incremental development

15
Some useful tag events
  • onClick
  • onDblClick
  • onKeyDown
  • onKeyPress
  • onKeyUp
  • onError
  • onAbort
  • onLoad
  • onUnload
  • onMouseDown
  • onMouseUp
  • onMouseOver
  • onMouseEnter
  • onMouseOut
  • onFocus
  • onBlur

16
Summary
  • JavaScript is a functional programming language
  • Events in HTML tags allow an event-driven
    interface
  • We will combine HTML and JavaScript to create
    interactive web pages
Write a Comment
User Comments (0)
About PowerShow.com