1 Prototype-basedPrototype-based scripting languagescripting language.

Slides:



Advertisements
Similar presentations
Introducing JavaScript
Advertisements

JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
1 CSC 551: Web Programming Spring 2004 client-side programming with JavaScript  scripts vs. programs  JavaScript vs. JScript vs. VBScript  common tasks.
The Web Warrior Guide to Web Design Technologies
EIW: Javascript the Language1 The JavaScript Language.
Eiffel Programming Language. Chad Frommeyer CSC 407/507 Fall 2005 Dr. Richard Fox.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
CS 330 Programming Languages 10 / 16 / 2008 Instructor: Michael Eckmann.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
Javascript Client-side scripting. Up to now  We've seen a little about how to control  content with HTML  presentation with CSS  Javascript is a language.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
PHP Server-side Programming. PHP  PHP stands for PHP: Hypertext Preprocessor  PHP is interpreted  PHP code is embedded into HTML code  interpreter.
C++ fundamentals.
Introduction to JavaScript. Aim To enable you to write you first JavaScript.
Lecture 1: Overview of Java. What is java? Developed by Sun Microsystems (James Gosling) A general-purpose object-oriented language Based on C/C++ Designed.
2440: 141 Web Site Administration Web Server-Side Programming Professor: Enoch E. Damson.
Ranga Rodrigo. Class is central to object oriented programming.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
Dynamic Web Pages (Flash, JavaScript)
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Bridges To Computing General Information: This document was created for use in the "Bridges to Computing" project of Brooklyn College. You are invited.
JavaScript II ECT 270 Robin Burke. Outline JavaScript review Processing Syntax Events and event handling Form validation.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
Netprog: JavaScript1 JavaScript Client-side dynamic documents.
1 JavaScript. 2 What’s wrong with JavaScript? A very powerful language, yet –Often hated –Browser inconsistencies –Misunderstood –Developers find it painful.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
What is Java Script? An extension to HTML. An extension to HTML. Allows authors to incorporate some functionality in their web pages. (without using CGI.
Javascript. Outline Introduction Fundamental of JavaScript Javascript events management DOM and Dynamic HTML (DHTML)
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
1 JavaScript in Context. Server-Side Programming.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
1 Lecture #6 Dynamic Web Documents HAIT Summer 2005 Shimrit Tzur-David.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
Lua: The Programming Language. Some Things that Need to be Said Because of increasing demand for customizable applications, the trend nowadays is to split.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Java server pages. A JSP file basically contains HTML, but with embedded JSP tags with snippets of Java code inside them. A JSP file basically contains.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
1 JavaScript
JavaScript - Basic Concepts Prepared and Presented by Hienvinh Nguyen, Afshin Tiraie.
Overview of Form and Javascript fundamentals. Brief matching exercise 1. This is the software that allows a user to access and view HTML documents 2.
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
David Lawrence 7/8/091Intro. to PHP -- David Lawrence.
JavaScript Introduction.  JavaScript is a scripting language  A scripting language is a lightweight programming language  A JavaScript can be inserted.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
1 JavaScript in Context. Server-Side Programming.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
 Web pages originally static  Page is delivered exactly as stored on server  Same information displayed for all users, from all contexts  Dynamic.
1) PHP – Personal Home Page Scripting Language 2) JavaScript.
Rich Internet Applications 2. Core JavaScript. The importance of JavaScript Many choices open to the developer for server-side Can choose server technology.
8 th Semester, Batch 2009 Department Of Computer Science SSUET.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
Introduction to Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
CGS 3066: Web Programming and Design Spring 2016 Introduction to JavaScript.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
“Under the hood”: Angry Birds Maze
Learning to Program D is for Digital.
JavaScript an introduction.
Java Programming Language
JavaScript CS 4640 Programming Languages for Web Applications
Tutorial 10: Programming with javascript
Introducing JavaScript
PHP an introduction.
Web Programming and Design
JavaScript CS 4640 Programming Languages for Web Applications
Presentation transcript:

1 Prototype-basedPrototype-based scripting languagescripting language

 Most browsers support a tag that is used to include executable content in an HTML document.  There are a number of scripting languages that are supported 2

 Netscape and others  JavaScript  Internet Explorer  Jscript (MS name for JavaScript)  VBScript  PerlScript 3

 Add content to a web page dynamically.  Alter a web page in response to user actions.  React to user events.  Interact with frames.  Manipulate HTTP cookies 4

 JavaScript is a very simple scripting language.  Syntax is similar to a subset of Java.  Interpreted language.  Uses objects, but doesn't really support the creation of new object types* *It almost does, but it's cumbersome. 5

 Imperative and structured  Dynamic 1.dynamic typing: As in most scripting languages, types are associated with values, not with variables. For example, a variable x could be bound to a number, then later rebound to a string. JavaScript supports various ways to test the type of an object, including duck typing. 2.run-time evaluation: JavaScript includes an eval function that can execute statements provided as strings at run-time. 6

 Functional closures JavaScript allows nested functions to be created, with the lexical scope in force at their definition, and has a () operator to invoke them now or later. This combination of code that can be executed outside the scope in which it is defined, with its own scope to use during that execution, is called a closure in computer science 7

 JavaScript and the DOM provide the potential for malicious authors to deliver scripts to run on a client computer via the web. Browser authors contain this risk using restrictions. scripts run in a sandbox in which they can only perform web-related actions, not general- purpose programming tasks like creating files. Most JavaScript-related security bugs are breaches of either the same origin policy or the sandbox. 8

 Variables  Literals  Operators  Control Structures  Objects 9

 Untyped!  Can be declared with var keyword: var foo;  Can be created automatically by assigning a value: foo=1; blah="Hi Eve"; 10

 Using var to declare a variable results in a local variable (inside a function).  If you don't use var – the variable is a global variable. 11

 The typical bunch:  Numbers  Strings "Hello Eve"  Boolean: true false  Arrays: [1,"Hi Eve",17.234] 12 Arrays can hold anything!

 Arithmetic, comparison, assignment, bitwise, Boolean + - * / % == != > < && || ! & | > 13

if if-else ?: switch for while do-while  And a few not in C for (var in object) with (object) 14

 Objects have attributes and methods.  Many pre-defined objects and object types.  Using objects follows the syntax of C++/Java: objectname.attributename objectname.methodname() 15

 Arrays are supported as objects.  Attribute length  Methods include: concat join pop push reverse sort 16

var a = [8,7,6,5]; for (i=0;i<a.length;i++) a[i] += 2; b = a.reverse(); 17

 String : manipulation methods  Math : trig, log, random numbers  Date : date conversions  RegExp : regular expressions  Number : limits, conversion to string 18

 JavaScript also includes some objects that are automatically created for you (always available).  document  navigator  screen  window 19

 Many attributes of the current document are available via the document object: TitleReferrer URLImages FormsLinks Colors 20

 document.write() like a print statement – the output goes into the HTML document. document.write("My title is" + document.title); 21 string concatenation!

JavaScript I am a web page and here is my name: document.write(document.title); JavaScript I am a web page and here is my name: document.write(document.title); 22

<!-- document.write("Hi Eve"); document.bgColor="BLUE"; --> 23 HTML comment

 The keyword function used to define a function (subroutine): function add(x,y) { return(x+y); } 24

 JavaScript supports an event handling system.  You can tell the browser to execute javascript commands when some event occurs.  Sometimes the resulting value of the command determines the browser action. 25

Hello - I am a very small page! savewidth = window.innerWidth; saveheight = window.innerHeight; function restore() { window.innerWidth=savewidth; window.innerHeight=saveheight; } // Change the window size to be small window.innerWidth=300; window.innerHeight=50; document.bgColor='cyan'; Hello - I am a very small page! savewidth = window.innerWidth; saveheight = window.innerHeight; function restore() { window.innerWidth=savewidth; window.innerHeight=saveheight; } // Change the window size to be small window.innerWidth=300; window.innerHeight=50; document.bgColor='cyan'; 26

 You can associate buttons with JavaScript events (buttons in HTML forms) 27 <INPUT TYPE=BUTTON VALUE="Don't Press Me" onClick="alert('now you are in trouble!')“ > <INPUT TYPE=BUTTON VALUE="Don't Press Me" onClick="alert('now you are in trouble!')“ >

onUnLoad onLoad onClick onMouseUp onMouseDown onDblClick onMouseOver 28 Window events Button events Link events

 Naming hierarchy used to access individual elements of a HTML document.  Netscape D.O.M. is a little different than IE D.O.M.  Easy to use if you name all entities:  Forms, fields, images, etc. 29 Things are getting better all the time – there are standard DOMs defined by The W3C

<FORM ID=myform ACTION=… Please Enter Your Age: And your weight: 30 From javascript you can get at the age input field as: document.myform.age.value

 You can have JavaScript code that makes sure the user enters valid information.  When the submit button is pressed the script checks the values of all necessary fields:  You can prevent the request from happening. 31

function checkform() { if (document.myform.age.value == "") { alert("You need to specify an age"); return(false); } else { return(true); } function checkform() { if (document.myform.age.value == "") { alert("You need to specify an age"); return(false); } else { return(true); } 32 Needs to return true or false!

<FORM METHOD=GET ACTION=foo.cgi NAME=myform onSubmit="return(checkform())"> AGE: <FORM METHOD=GET ACTION=foo.cgi NAME=myform onSubmit="return(checkform())"> AGE: 33 Needed to prevent the browser from submitting!

 It's a good idea to make sure the user fills out the form before submitting.  Users can bypass your form – they can create requests manually (or their own forms).  Your CGI programs cannot rely (soley) on Client-Side JavaScript to validate form fields! 34

 Speed. Being client-side, JavaScript is very fast because any code functions can be run immediately instead of having to contact the server and wait for an answer.  Simplicity. JavaScript is relatively simple to learn and implement.  Versatility. JavaScript plays nicely with other languages and can be used in a huge variety of applications. Unlike PHP or SSI scripts, JavaScript can be inserted into any web page regardless of the file extension. JavaScript can also be used inside scripts written in other languages such as Perl and PHP.  Server Load. Being client-side reduces the demand on the website server. 35

 Security. Because the code executes on the users' computer, in some cases it can be exploited for malicious purposes. This is one reason some people choose to disable JavaScript.  Reliance on End User. JavaScript is sometimes interpreted differently by different browsers. Whereas server-side scripts will always produce the same output, client-side scripts can be a little unpredictable. Don't be overly concerned by this though - as long as you test your script in all the major browsers you should be safe. 36

37

 Lua from Portuguese meaning " moon ") is a lightweight multi-paradigm programming language designed as a scripting language with extensible semantics as a primary goal. Lua has a relatively simple C API compared to other scripting languages 38

 Lua is a powerful, fast, lightweight, embeddable scripting language. Lua combines simple procedural syntax with powerful data description constructs based on associative arrays and extensible semantics. Lua is dynamically typed, runs by interpreting byte code for a register-based virtual machine, and has automatic memory management with incremental garbage collection, making it ideal for configuration, scripting, and rapid prototyping. 39

 Lua's historical 'father and mother' were data- description/configuration languages SOL (Simple Object Language) and DEL (data-entry language). They had been independently developed at Tecgraf in to add some flexibility into two different projects (both were interactive graphical programs for engineering applications at Petro bras company). 40

 Multi-paradigm language  does not contain explicit support for inheritance  easily with meta tables  implement namespaces and classes  first-class functions  functional programming 41

 Lua is fastest language  Lua is portable  Lua is embeddable  Lua is powerful (but simple)  Lua is free open-source software 42

 An inherent is that it’s a fairly rarely-used language.  An implementation is that it currently dependent on an external Lua binary installation 43

Data Types  Boolean values  numbers (double-precision floating point by default)  strings. Typical data:  Arrays, sets, lists, and records can be represented using Lua’s single native data structure, the table, which is essentially a heterogeneous associative array Data Type 44

 Literals and output in Lua print ('1: Hello World')print ("2: Hello World") The Result: 1: Hello World2: Hello World 45

 A simple array of strings array = { "a", "b", "c", "d" } print(array[2]) print(#array) array[0] = "z" print(#array)  An array of objects: function Point(x, y) return { x = x, y = y } end array = { Point(10, 20), Point(30, 40), Point(50, 60) } print(array[2].y) 46

Vector = {} the class methods function Vector:new(x, y, z local object = { x = x, y = y, z = z } setmetatable(object, { __index = Vector }) return object End function Vector:magnitude() return math.sqrt(self.x^2 + self.y^2 + self.z^2) end vec = Vector:new(0, 1, 0) print(vec:magnitude ()) print(vec.x) 47

 For-loop for variable = 0, 10, 2 do print ( variable ) end Loops:  While-loop: i = 1while i <= 5 do print (i) i = i + 1 end 48

 A very simple configuration file: width = 420 height = width*3/2 -- ensures 3/2 aspect ratio color = "blue 49

 A configuration file using Functions: function Bound (w, h) if w < 20 then w = 20 elseif w > 500 then w = 500 end local minH = w*3/2 -- local variable if h < minH then h = minH end return w, h end width, height = Bound(420, 500) if monochrome then color = "black" else color = "blue" end 50

 Tollgrade’s DigiTest (telephony network testing)  Performance Technologies’ command line interface of CPC4400 (a hot swappable Ethernet switch)  LucasArts’ Escape from Monkey Island and Grim Fandango 51

 How does Lua apply the new configurations to the original program / application? Ans. There are two phases in Lua programming: compilation time (that is when all Lua functions and program lines are compiled) and runtime (that is when C and C++ functions of the original program are called by Lua to apply the new configurations the user has specified) 52

 Extend the meaning of many syntactical constructions  e.g. fallbacks can be used to implement different kinds of inheritance, a feature not present in Lua 53

54

 1985 Language Development Began  Developed by Bertrand Meyer of Interactive Software Engineering  1986 First Compiler Delivered  1987 Commercial Applications Developed  1991 NICE Founded (Non-Profit International Consortium for Eiffel)  NICE controls evolution, standardization and basic class definitions for Eiffel  1996 Commercial Eiffel based development system becomes available (iss-base).  Decendent of Algol and ADA 55

 Pure object oriented language  Strong statically typed  Automatic memory management/Garbage collection  Supports ADTs  Supports Generic Classes  Supports By Value and By reference semantics  Promotes simplicity (Readable, not Writeable)  Non-Object Oriented Capabilities/Low Level Functionality (C-Lang)  Some Compilers only generate C source code  Design By Contract (Reliability)  Exception Handling  Supports separate library compilation  Supports In-Class Documentation  Root class starts execution 56

indexing description: “Basic Hello World author : “Jim Developer” class HELLO_WORLD creation make feature make is do io.put_string ("Hello, world!%N") end 57

 Assignment  Object Creation  Routine Call  Conditional  Iteration  Choice/Switch/Case 58

 i := i + 1  Assignments cannot happen directly to class attributes. Methods/Routines must be used.  Shortcut Assignments don’t exist 59

 Declaration acc:ACCOUNT  acc is “void” when declared  At runtime acc obtains an object by calling  create acc  Which creates a new instance of ACCOUNT and attaches acc  acc can now be used:  acc.open(“John”)  acc.deposit(5000) 60

 The following data types exist, the initialization of variables of these types is automatically initialized  INTEGER initializes to zero  REAL and DOUBLE initialize to 0.0  BOOLEAN initializes to false  CHARACTER initializes to null  Reference types initialize to a null reference  INTEGER, REAL, DOUBLE, BOOLEAN and CHARACTER are all considered Expanded types 61

 A reference is the default object type, when an instance of a class is created it is called a reference, this is created by either calling “create” or using “!!” 62

 An expanded type is one that is already initialized  INTEGER, REAL, DOUBLE, BOOLEAN and CHARACTER are all considered Expanded types  Expanded types don’t require calling “create” or “!!”  If the class is not defined with the keyword “expanded” then it will be a reference type. expanded class INTEGER feature... end -- INTEGER 63

acc.open ("Jill") acc.deposit (5000) if acc.may_withdraw(3000) then acc.withdraw(3000);print(acc.balance) end 64

if x > 10 then... statements... elseif x > 5 then... elsif statements... elseif x > 0 then... more elsif statements... else... else statements... end 65

 Only one looping statement exists, but it could be used to emulate other types of loops. For Loop from i := 1 until i = 10 loop io.put_int (i); io.new_line; i := i + 1; end 66

 While Loop from node := first; until node = Void; loop io.put_string (node.text); node := node.next; end; 67

 Repeat Loop from done := False until done and pages = 10; loop done := True; printer.output_next; pages := pages + 1; end 68

 The inspected value must be enumerable State : INTEGER; State_1, State_2, State_3 : INTEGER is unique;... statements... inspect State when State_1 then... statements... when State_2 then... statements... when State_3 then... statements... else... statements... end; 69

 Exceptions can be thrown in few cases:  Design by contract failures  Low level functions  Rescue (Catch)  Retry (can only exist within a rescue clause)  Retry starts execution of the routine again without the variable initialization 70

read_next_character (f: FILE) is -- Make next character available in last_character ; -- if impossible, set failed to True. require readable: file. readable local impossible: BOOLEAN do if impossible then failed := True else last_character := low_level_read_function ( f ) end rescue impossible := True retry end 71

 Facilitates more reliable techniques  Defines correct usage  Assertions (Boolean Expression):  Precondition (require)  Post condition (ensure)  Class invariants (invariant)  Class invariant must be satisfied upon exit of the creation procedure (constructor) 72

 Assertion monitoring levels are set at compile time  The levels vary from no monitoring to monitoring all require/ensure/invariant  Exceptions will be thrown if assertions are being monitored  If the exception isn’t handled, a run-time error will result 73

 Purely Object Oriented  Everything is an object  Information Hiding  Encapsulation  Polymorphism/Dynamic Binding  Inheritance (Including Multiple) 74

 Supports information hiding/encapsulation  No attributes of a class are allowed to be modified directly. All modifications must happen within a subroutine  No global variables are allowed  No static functions are allowed  Secret attributes/routines are equivalent to private variables/methods 75

 Dynamic binding allows polymorphic object to call the appropriate versioned routine acc : ACCOUNT ; sav : SAVINGS_ACCOUNT acc := sav acc.deposit( 1000 ) 76

 Inheritance is supported  Multiple inheritance is supported  Routine can be overridden (redefine)  Parent is known as a precursor  Keyword precursor can be used to reference the parent  Renaming allows conflicts with multiple inheritance to be resolved 77

indexing description: "Savings accounts" class SAVINGS_ACCOUNT inherit ACCOUNT redefine deposit end feature -- Element change deposit ( sum : INTEGER ) is -- Add sum to account. do precursor (sum) … end … Other features … end -- class SAVINGS_ACCOUNT 78

 The implementation of inheritance supplies many keywords to define how the parents members are recognized  Rename allows renaming of a parent attribute/routine  Export allows changing protection of a parent attribute/routine  Redefine allows overriding a routine  Undefine allows removing a routine 79

 The best page for a language overview is probably Eiffel on Wikipedia  It is very different to other languages but also very simple (there are only a small amount of keywords to learn)  Eiffel code is long compared to C (or similar languages). I. e. you have more words than symbols ( end instead of } ; from-until-loop-do instead of for(...;...;...) {...} ). You can love or hate it. 80

 Every part of the language is defined as much as possible (i. e. there is a BNF for the whole syntax).  Design by Contract (DbC) is part of the language (preconditions, post conditions, class invariants, state-checks, exception handling deeply connected to DbC, etc.).  Garbage Collected (GC) or not - you can choose 81

 Apart from different compilers there is an IDE called Eiffel Studio with a lot of integrated tools (UML / BON diagrams, eiffel doc (similar to java doc), debugger, etc.). The IDE should run fine on Windows and platforms that support GTK  There are compilers that target.Net (Eiffel Software), Java (Smart Eiffel), interpreted (Beta, TE Comp) and C (which is compiled to native code) 82

 There are the commercial ones from Eiffel.com  Free, active ones like: Gobo and EWLC  A lot of dead ones :(, yeah, that is a BIG disadvantage of eiffel 83