1 JavaScript 2.0: Evolving a Language for Evolving Systems Waldemar Horwat Netscape.

Slides:



Advertisements
Similar presentations
the javascript language BY SA.
Advertisements

Introducing JavaScript
Semantic Analysis Chapter 6. Two Flavors  Static (done during compile time) –C –Ada  Dynamic (done during run time) –LISP –Smalltalk  Optimization.
Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Winter 2013.
1 CSC 551: Web Programming Spring 2004 client-side programming with JavaScript  scripts vs. programs  JavaScript vs. JScript vs. VBScript  common tasks.
Portability and Safety Mahdi Milani Fard Dec, 2006 Java.
The Web Warrior Guide to Web Design Technologies
CS 211 Inheritance AAA.
Road Map Introduction to object oriented programming. Classes
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Tutorial 10 Programming with JavaScript
Advanced Object-Oriented Programming Features
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
Creating Classes from Other Classes Chapter 2. 2 Chapter Contents Composition Adapters Inheritance Invoking constructors from within constructors Private.
Javascript II Expressions and Data Types. 2 JavaScript Review programs executed by the web browser programs embedded in a web page using the script element.
Lecture 9 Concepts of Programming Languages
Compilation 2007 Scopes and Environments Michael I. Schwartzbach BRICS, University of Aarhus.
Abstract Data Types and Encapsulation Concepts
Introduction to Ruby CSE 413 Autumn 2008 Credit: Dan Grossman, CSE341.
OOP Languages: Java vs C++
JavaScript CMPT 281. Outline Introduction to JavaScript Resources What is JavaScript? JavaScript in web pages.
Programming Languages and Paradigms Object-Oriented Programming.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
An Overview of ActionScript The Powerful Scripting Language of Macromedia Flash.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
1 Chapter 10: Data Abstraction and Object Orientation Aaron Bloomfield CS 415 Fall 2005.
Javascript. Outline Introduction Fundamental of JavaScript Javascript events management DOM and Dynamic HTML (DHTML)
JAVA SERVER PAGES. 2 SERVLETS The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
Programming Language C++ Xulong Peng CSC415 Programming Languages.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
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.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
1 JavaScript 2.0: Evolving a Language for Evolving Systems Waldemar Horwat Netscape.
Inheritance - Polymorphism ITI 1121 Nour El Kadri.
Client-side processing in JavaScript.... JavaScript history Motivations –lack of “dynamic content” on web pages animations etc user-customised displays.
Javascript. What is JavaScript? Scripting (interpreted) language designed for the web Beware: JavaScript is case sensitive.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
Object-Oriented Programming Chapter Chapter
CIS 270—Application Development II Chapter 8—Classes and Objects: A Deeper Look.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Java Programming, Second Edition Chapter Twelve Advanced Inheritance Concepts.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Rich Internet Applications 2. Core JavaScript. The importance of JavaScript Many choices open to the developer for server-side Can choose server technology.
Object-Oriented Programming “The Rest of the Story”, CS 4450 – Chapter 16.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Expressions and Data Types Professor Robin Burke.
JavaScript and AJAX 2nd Edition Tutorial 1 Programming with JavaScript.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
Dart Omar Ansari, Kenneth Jones, Isaac Wilder. 1. Overview l Object Oriented Language l Developed By Google l Primarily used for building websites, servers,
More Sophisticated Behavior
Learning to Program D is for Digital.
JavaScript an introduction.
Slides by Steve Armstrong LeTourneau University Longview, TX
More Object-Oriented Programming
Barb Ericson Georgia Institute of Technology Oct 2005
Tutorial 10 Programming with JavaScript
JavaScript CS 4640 Programming Languages for Web Applications
CSE 341 Lecture 11 b closures; scoping rules
JavaScript CS 4640 Programming Languages for Web Applications
Presentation transcript:

1 JavaScript 2.0: Evolving a Language for Evolving Systems Waldemar Horwat Netscape

2 Outline History Motivation Challenges of evolving interfaces –Versioning –Integrity –Convenience Evolving a language Tools

3 JavaScript History Web page scripting language invented by Brendan Eich at Netscape Used in 25% of web pages More than an order of magnitude more widely used than all other web client languages combined

4 JavaScript Evolution JavaScript 1.0 in Navigator 2.0 JavaScript 1.5 is most recent JavaScript 2.0 in 2002 Open source (NPL or LGPL)

5 JavaScript and ECMAScript JavaScript standardized by the ECMA TC39 committee –ECMA 262 –ISO JavaScript 1.5 = ECMAScript Edition 3 JavaScript 2.0 = ECMAScript Edition 4 TC39 leading the design of Edition 4

6 JavaScript 2.0 Motivation Evolving programs –Compatibility –Modularity –Safety –Interoperability with other languages Common Patterns –Class declarations Efficiency

7 Evolving Programs “Programming in the large” Programs written by more than one person Programs assembled from components (packages) Programs that use evolving interfaces

8 Evolution Problem 1 Name conflicts

Library package BitTracker; public class Data { public var author; public var contents; function save() {…} }; function store(d) {... storeOnFastDisk(d); } 9

Library Web page package BitTracker; public class Data { public var author; public var contents; function save() {…} }; function store(d) {... storeOnFastDisk(d); } import BitTracker; class Picture extends Data { function size() {…} var palette; }; function orientation(d) { if (d.size().h >= d.size().v) return "Landscape"; else return "Portrait"; } 10

Library rev2 Web page package BitTracker; public class Data { public var author; public var contents; public function size() {…} function save() {…} }; function store(d) {... if (d.size() > limit) storeOnSlowDisk(d); else storeOnFastDisk(d); } import BitTracker; class Picture extends Data { function size() {…} var palette; }; function orientation(d) { if (d.size().h >= d.size().v) return "Landscape"; else return "Portrait"; } 11

Library rev2 Web page package BitTracker; public class Data { public var author; public var contents; public function size() {…} function save() {…} }; function store(d) {... if (d.size() > limit) storeOnSlowDisk(d); else storeOnFastDisk(d); } import BitTracker; class Picture extends Data { function size() {…} var palette; }; function orientation(d) { if (d.size().h >= d.size().v) return "Landscape"; else return "Portrait"; } 12

Library rev2 Web page package BitTracker; public class Data { public var author; public var contents; public function ?() {…} function save() {…} }; function store(d) {... if (d.?() > limit) storeOnSlowDisk(d); else storeOnFastDisk(d); } import BitTracker; class … extends Data { ? }; 13

14 Non-Solutions Assume it won’t happen –It does, especially in DOM Have programmer detect/fix conflicts (C++) –Old web pages linked with new libraries Have compiler bind identifier to definition (Java) –Programs distributed in source form Explicit overrides + static type system (C#) –Doesn’t work in dynamic languages –Burden on library user instead of library developer

15 Solution: Namespaces Each name is actually an ordered pair namespace :: identifier A use namespace( n ) statement allows unqualified access to n’s identifiers within a scope Default namespace is public Namespaces are values

Library Web page package BitTracker; public class Data { public var author; public var contents; function save() {…} }; function store(d) {... storeOnFastDisk(d); } import BitTracker; class Picture extends Data { function size() {…} var palette; }; function orientation(d) { if (d.size().h >= d.size().v) return "Landscape"; else return "Portrait"; } 16

Library rev2 Web page package BitTracker; namespace v2; use namespace(v2); public class Data { public var author; public var contents; v2 function size() {…} function save() {…} }; function store(d) {... if (d.size() > limit) storeOnSlowDisk(d); else storeOnFastDisk(d); } import BitTracker; class Picture extends Data { function size() {…} var palette; }; function orientation(d) { if (d.size().h >= d.size().v) return "Landscape"; else return "Portrait"; } 17

Library rev2 Web page rev2 package BitTracker; namespace v2; use namespace(v2); public class Data { public var author; public var contents; v2 function size() {…} function save() {…} }; function store(d) {... if (d.size() > limit) storeOnSlowDisk(d); else storeOnFastDisk(d); } import BitTracker; use namespace(v2); class Picture extends Data { function dims() {…} var palette; }; function orientation(d) { if (d.dims().h >= d.dims().v) return "Landscape"; else return "Portrait"; } … d.size() … 18

Library rev2 Web page rev2 package BitTracker; explicit namespace v2; use namespace(v2); public class Data { public var author; public var contents; v2 function size() {…} function save() {…} }; function store(d) {... if (d.size() > limit) storeOnSlowDisk(d); else storeOnFastDisk(d); } import BitTracker, namespace(v2); class Picture extends Data { function dims() {…} var palette; function size() {…} }; function orientation(d) { if (d.dims().h >= d.dims().v) return "Landscape"; else return "Portrait"; } 19

20 Versioning Namespaces distinguish between accidental and intentional identifier matches Library publisher annotates new functionality with new namespaces Web page imports a specific namespace Versioning affects name visibility only — there is only one library implementation

21 Other Uses of Namespaces private, internal, etc. are syntactic sugars for anonymous namespaces Export private functionality to privileged clients Can use namespaces to add methods to an already existing class

Classes Lookup class A { function f() // fA } class B extends A { function f() // fB } class C extends B { function f() // fC } use namespace(public); c = new C; c.f(); // fC 22

Classes Lookup 1 class A { N function f() // fA } class B extends A { N function f() // fB } class C extends B { function f() // fC } use namespace(public); c = new C; c.f(); // fC use namespace(public); use namespace(N); c = new C; c.f(); // fB, not fC! 23 Lookup 2

24 Member Lookup c.f Find highest (least derived) class that defines a member f that’s visible in the currently used namespaces to pick a namespace n Find lowest (most derived) definition of c. n ::f –Gives object-oriented semantics

25 Evolution Problem 2 Leakage of implementation details

Library public function find(x) { while (x >= 0) if (a[x]) return a[x]; else x -= 2; return null; } 26

Library Web page public function find(x) { while (x >= 0) if (a[x]) return a[x]; else x -= 2; return null; } var c = find(34); var d = find("42"); 27

Library Web page public function find(x) { x += 2; while ((x -= 2) >= 0) if (a[x]) return a[x]; return null; } var c = find(34); var d = find("42"); 28

Library Web page public function find(x) { x += 2; while ((x -= 2) >= 0) if (a[x]) return a[x]; return null; } var c = find(34); var d = find("42"); // same as find(420) 29

30 Solution: Type Annotations LibraryWeb page public function find(x: Integer) { x += 2; while ((x -= 2) >= 0) if (a[x]) return a[x]; return null; } var c = find(34); var d = find("42"); // now same as find(42)

31 Type Annotations Optional Language is not statically type-checked No concept of a static type of an expression; only dynamic type of an expression matters class A { function f() } class B extends A { function g() } var a:A = new B; a.f(); // OK a.g(); // OK

32 Supportive Features Package syntax Class definition syntax Attributes Function signature checking Named function parameters Native integer and floating-point types Decimals and bignums Operator overriding and units

33 Class Definition Syntax class Dance { const kind; var name: String; static var count; constructor function start(partner, length: Integer) {…} }; class Swing extends Dance { var speed: Integer; function acrobatics(): Boolean {…} };

34 Why Classes? Ubiquitous idiom Few users get it right with prototypes Difficult to evolve a program that uses prototypes –Little knowledge of invariants Classes model cross-language interaction Prototypes poorly supported by CLI JS2 classes will co-exist with prototypes

35 Attributes static debug v3 final foo(3) bar var x:Integer = 5; Restricted expressions that evaluate to: Built-in attributes such as final and static Namespaces true or false User-defined attributes

36 Attributes const debug = true; static debug v3 final foo(3) bar var x:Integer = 5; const A = static debug v3; A bar var y:Integer; private { var z; function f(); }

37 Named Function Parameters function f(a: Integer, b = 5, named c = 17, named d = 3) f(4) f(4, d:6) Why is the named attribute needed?

38 Omitted Features Overloading Interfaces Lots of built-in libraries

39 Evolving the Language An implementation will run three kinds of programs: JavaScript 1.5 –Run unchanged Non-strict JavaScript 2.0 –Almost all JavaScript 1.5 programs run unchanged Strict JavaScript 2.0 –Turns off troublesome quirks (scope hoisting, newline dependencies, etc.)

40 Tools ECMAScript standards use semantic descriptions of the language Use extended typed lambda calculus with Algol- like syntax for ECMAScript Edition 4 Wrote Common Lisp engine to: –Run and test grammar and semantics directly –Auto-generate web page descriptions –Auto-generate chapters of draft ECMAScript standard Freely available

41 More Information Waldemar Horwat