Copyright © 2009 Elsevier Chapter 13 :: Scripting Languages.

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

Java Script Session1 INTRODUCTION.
XHTML Basics.
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
Tutorial 6 Creating a Web Form
Languages for Dynamic Web Documents
Copyright 2004 Monash University IMS5401 Web-based Systems Development Topic 2: Elements of the Web (g) Interactivity.
BY: ALBERTO CABEZAS 4/19/2010. INTRODUCTION: PHP is considered today as one of the most famous scripting languages. PHP is widely used as a general purpose.
Server-Side vs. Client-Side Scripting Languages
Introduction to Web Application Architectures Web Application Architectures 18 th March 2005 Bogdan L. Vrusias
Scripting Languages CS351 – Programming Paradigms.
SCRIPTING LANGUAGE. The first interactive shells were developed in the 1960s to enable remote operation of the first time-sharing systems, and these,
Scripting Languages CS351 – Programming Paradigms.
Guide To UNIX Using Linux Third Edition
Russell Taylor Lecturer in Computing & Business Studies.
Chapter 11 ASP.NET JavaScript, Third Edition. 2 Objectives Learn about client/server architecture Study server-side scripting Create ASP.NET applications.
COMPUTER TERMS PART 1. COOKIE A cookie is a small amount of data generated by a website and saved by your web browser. Its purpose is to remember information.
1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)
Introduction to scripting
 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing.
8/17/2015CS346 PHP1 Module 1 Introduction to PHP.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
UFCEKG-20-2 Data, Schemas & Applications Lecture 4 Server Side Scripting & PHP.
INTRODUCTION TO WEB DATABASE PROGRAMMING
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
Using Data Active Server Pages Objectives In this chapter, you will: Learn about variables and constants Explore application and session variables Learn.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
Copyright © cs-tutorial.com. Introduction to Web Development In 1990 and 1991,Tim Berners-Lee created the World Wide Web at the European Laboratory for.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
Chapter 1: Introduction to Web
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
1 In the good old days... Years ago… the WWW was made up of (mostly) static documents. –Each URL corresponded to a single file stored on some hard disk.
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.
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
CSCI-383 Object-Oriented Programming & Design Lecture 13.
20-753: Fundamentals of Web Programming 1 Lecture 12: Javascript I Fundamentals of Web Programming Lecture 12: Introduction to Javascript.
Web Pages with Features. Features on Web Pages Interactive Pages –Shows current date, get server’s IP, interactive quizzes Processing Forms –Serach a.
Active Server Pages  In this chapter, you will learn:  How browsers and servers interacted on the Internet when the Internet first became popular 
Kingdom of Saudi Arabia Ministry of Higher Education Al-Imam Muhammad Ibn Saud Islamic University College of Computer and Information Sciences Chapter.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
CGI Common Gateway Interface. CGI is the scheme to interface other programs to the Web Server.
Objects & Dynamic Dispatch CSE 413 Autumn Plan We’ve learned a great deal about functional and object-oriented programming Now,  Look at semantics.
Introduction to JavaScript CS101 Introduction to Computing.
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
Web Pages with Features. Features on Web Pages Interactive Pages –Shows current date, get server’s IP, interactive quizzes Processing Forms –Serach a.
ASP (Active Server Pages) by Bülent & Resul. Presentation Outline Introduction What is an ASP file? How does ASP work? What can ASP do? Differences Between.
David Lawrence 7/8/091Intro. to PHP -- David Lawrence.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
 Previous lessons have focused on client-side scripts  Programs embedded in the page’s HTML code  Can also execute scripts on the server  Server-side.
 Web pages originally static  Page is delivered exactly as stored on server  Same information displayed for all users, from all contexts  Dynamic.
Web Programming Overview. Introduction HTML is limited - it cannot manipulate data How Web pages are extended (include): –Java: an object-oriented programming.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 2: Introduction to IS2803 Rob Gleasure
Copyright © 2009 Elsevier Chapter 13 :: Scripting Languages Programming Language Pragmatics Michael L. Scott.
Scripting Languages Info derived largely from Programming Language Pragmatics, by Michael Scott.
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
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.
Tutorial 6 Creating a Web Form
Chapter 14 :: Scripting Languages Programming Language Pragmatics, Fourth Edition Michael L. Scott Copyright © 2016 Elsevier.
1 Chapter 1 INTRODUCTION TO WEB. 2 Objectives In this chapter, you will: Become familiar with the architecture of the World Wide Web Learn about communication.
CS 3304 Comparative Languages
Scripting Languages Info derived largely from Programming Language Pragmatics, by Michael Scott.
Learning to Program D is for Digital.
PHP Introduction.
PHP.
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
Web Application Development Using PHP
Presentation transcript:

Copyright © 2009 Elsevier Chapter 13 :: Scripting Languages

Copyright © 2009 Elsevier Another Problem Domain Extension Languages –An extension language is something that allows a user to create new commands inside a program Most commercial products have their own unique scripting languages to do this –Examples: AutoCAD, Flash Some are done using existing languages: –Examples: Adobe with JavaScript, Applescript on a mac, VB on a PC, AOLServer using Tcl, etc Formally, to admit extension, a tool must: –Incorporate or communicate with an interpreter for a scripting language –Provide hooks to allow scripts to call existing commands –Allow the user to tie new commands to user interface

Copyright © 2009 Elsevier Extension languages An example: one of the oldest existing extension mechanisms is that of the emacs text editor, used to write this book –Many come standard with emacs, although users may not take advantage of them –In emacs, built in functionality is actually pretty small – most good stuff comes from extensions that are just standard now –Book has an example (fig 13.9) – see next slide

Copyright © 2009 Elsevier Problem Domains

Copyright © 2009 Elsevier Scripting the World Wide Web Much of the web is static, but the need for dynamic content is increasing Scripts are a key component of this dynamic content, with two options: –Server side: content should (or must) be controlled by service provider –Client side: when proprietary information is not needed Original mechanism: Common Gateway Interface (CGI) scripts Since then, other options have evolved. –Client side scripts –Applets –HTML itself

Copyright © 2009 Elsevier CGI scripts: the beginning A CGI script is an executable program residing in a special directory known to the web server program –When a client requests the URI corresponding to such a program, the server executes the program and sends its output back to the client this output needs to be something that the browser will understand: typically HTML. CGI scripts may be written in any language available on the server –Historically, Perl is particularly popular: its string-handling and “ glue ” mechanisms are suited to generating HTML it was already widely available during the early years of the web

Copyright © 2009 Elsevier CGI Perl script

Copyright © 2009 Elsevier Server side scripts Though widely used, CGI scripts have several disadvantages: –The web server must launch each script as a separate program, with potentially significant overhead –Scripts must generally be installed in a trusted directory by trusted system administrators –The name of the script appears in the URI (typically with directory info), so static and dynamic pages look different to end users –Each script must generate not only dynamic content, but also the HTML tags that are needed to format and display it, which is annoying to code Most web servers now provide ways for scripts in supported languages to be embedded in the web page –Then the web server can interpret these directly, without launching external program, and replace them before they are sent to the client

Copyright © 2009 Elsevier PHP sample script

Copyright © 2009 Elsevier Client side scripts Embedded server-side scripts are generally faster than CGI script, communication across the Internet is still too slow for interactive pages –Real time changes in the page can’t be sent across the internet! Client-side scripts, by contrast, require an interpreter on the client ’ s machine –There is a powerful incentive for convergence in client-side scripting languages: most designers want their pages to be viewable by as wide an audience as possible –(This is a huge different with server side, where client only ever gets html)

Copyright © 2009 Elsevier Client side scripts - options Visual basic is commonly used for explorer, but not so much others Most common is probably JavaScript (probably because it was just in the right place at the right time, rather than any native virtue) –JavaScript can interact with almost any part of HTML pages through use of the Document Object Model (DOM) in HTML specifications.

Copyright © 2009 Elsevier JavaScript

Copyright © 2009 Elsevier Java and HTML Java applets are an alternative to client side scripts –Browsers will instead support plug-ins that assume responsibility for a particular part of the page, where it can display anything it wants –To support execution of applets, most modern browsers contain a Java virtual machine. –Historically, plug-ins exist for content that HTML supported poorly, such as animations and video Example:

Copyright © 2009 Elsevier Other embedded scripts The JVM is not the only option: –As of 2015, the most widely used plug-in is actually Adobe’s Flash Player –It is scriptable, but is almost more of a multimedia display engine rather than a general purpose tool Worthwhile note: plugins are notorious for security issues: –They almost always require access to OS –Not always upgraded by the user –Not really owned by the browser, either HTML 5 expansion is really due to these issues.

Copyright © 2009 Elsevier Innovative Features Earlier we listed several common characteristics of scripting languages: –both batch and interactive use –economy of expression –lack of declarations; simple scoping rules –flexible dynamic typing –easy access to other programs –sophisticated pattern matching and string manipulation –high level data types

Copyright © 2009 Elsevier Innovative Features: Scope and Names Most scripting languages do not require variables to be declared –Perl and JavaScript permit optional declarations - sort of compiler-checked documentation –Perl can be run in a mode that requires declarations With or without declarations, most scripting languages use dynamic typing –The interpreter can perform type checking at run time, or coerce values when appropriate –Tcl is unusual in that all values—even lists—are represented internally as strings

Copyright © 2009 Elsevier Innovative Features: nesting and scope Nesting and scoping conventions vary quite a bit –Scheme, Python, JavaScript provide the classic combination of nested subroutines and static (lexical) scope –Tcl allows subroutines to nest, but uses dynamic scope –Named subroutines (methods) do not nest in PHP or Ruby Perl and Ruby join Scheme, Python, and JavaScript in providing firstclass anonymous local subroutines –Nested blocks are statically scoped in Perl –In Ruby, they are part of the named scope in which they appear –Scheme, Perl, Python provide for variables captured in closures –PHP and the major glue languages (Perl, Tcl, Python, Ruby) all have sophisticated namespace rules mechanisms for information hiding and the selective import of names from separate modules

Copyright © 2009 Elsevier Innovative Features: scope Undeclared variables with static scope present an interesting issue: how do we know if x is local, global, or in-between (if scopes can nest)? –In Perl, all variables are global unless otherwise specified. –In PHP, local unless explicitly imported. –Ruby has only two levels: $foo is global, foo is is instance of current object, and is instance variable of current object ’ s class –In Python and R, all variables are local by default, unless explicitly imported

Copyright © 2009 Elsevier Innovative Features: scope Scope in Python –In Python, all variables are local by default, unless explicitly imported: i=1; j=3 def outer(): def middle(k): def inner(): global i #from main program, not outer i = 4 inner() return i,j,k #3 element tuple i=2 return middle(j) #old (global) j print outer() print i,j –This prints: (2,3,3) 4 3

Copyright © 2009 Elsevier Innovative Features: scope Scope in Python –By default, there is no way for a nested scope to write to a non-local or non-global scope - so in previous example, inner could not modify outer ’ s i variable. R has an interesting convention: –Normal assignment puts value into the local variable: i <- 4 –Superassignment puts value into whatever variable would be found under normal (static) scoping rules: i <<- 4 Tcl uses dynamic scoping, but in an odd way - the programmer must request other scopes explicitly: upvar i j ;#j is the local name for caller’s I uplevel 2 {puts [expr $a + $b] } #executes ‘puts’ two scopes up on dynamic chain

Copyright © 2009 Elsevier Innovative Features: Pattern matching Regular expressions are present in many scripting languages and related tools employ extended versions of the notation –extended regular expressions (which we already saw) in sed and awk, Perl, Tcl, Python, and Ruby –grep, the stand-alone Unix is a pattern-matching tool, is another useful program that you might be familiair with In general, two main groups. –The first group includes awk, egrep (the most widely used of several different versions of grep), the regex routines of the C standard library, and older versions of Tcl These implement REs as defined in the POSIX standard –Languages in the second group follow the lead of Perl, which provides a large set of extensions, sometimes referred to as “ advanced REs ”

Copyright © 2009 Elsevier Pattern matching: POSIX REs Basic operations are familiar: /ab(cd|ef)g*/ - Matches abcd, abcdg, abefg, abefgg, etc. Other quantifiers: –?: 0 or 1 repetitions –+: 1 or more repetitions –{n}: exactly n repetitions –{n,}: at least n repetitions –{n,m}: between n and m repetitions –^ and $ force the match to be at the beinning or end of the line –Brackets can indicate a character class: [aeiou] - any vowel –Ranges: [0-9] –A dot. matches any single character –^ before a character class is negation

Copyright © 2009 Elsevier Pattern matching: extended REs Perl adds on to this extensively. Example: $_ = “albatross”; if (/ba.*s+/) … #true if (/^ba.*s+/) … #false - no match at start =~ tests if it matches, !~ tests if it does not (or defaults to checking against $_, if not specified) Substitution is done by s///: $foo = “albatross”; $foo =~ s/lbat/c; #now across

Copyright © 2009 Elsevier Pattern matching: extended REs Variations on normal REs: –Trailing i makes the match case insensitive. $foo = “Albatross”; if ($foo =~ /^al/i) … #true –Trailing g will replace all occurances. $foo = “albatross”; $foo =~ s/[aeiou]/-/g … # “-lb-tr-ss” –Trailing x has Perl ignore all comments and embedded white space in the pattern, so that you can break up long patterns into multiple lines.

Copyright © 2009 Elsevier Pattern matching: greedy matches If multiple matches are possible, it will take the “left-most longest” possible one. For example, in the string abcbcbcde, the pattern /(bc)+/ will match abcbcbcde. This is knows as the “greedy” match. Other options: –*? matches the smallest number of instances of the preceeding subexpression that will allow it to succeed. –+? matches at least one instance, but no more than necessary –?? matches either 0 or 1 instance, with a preference for 0

Copyright © 2009 Elsevier Innovative Features: Data Types As we have seen, scripting languages don ’ t generally require (or even permit) the declaration of types for variables Most perform extensive run-time checks to make sure that values are never used in inappropriate ways Some languages (e.g., Scheme, Python, and Ruby) are relatively strict about this checking –When the programmer wants to convert from one type to another, it must say so explicitly Perl (and likewise Rexx and Tcl) takes the position that programmers should check for the errors they care about –in the absence of such checks the program should do something reasonable

Copyright © 2009 Elsevier Innovative Features: Data Types Numeric types have a bit more variation across languages, but emphasis is universally that the programmer shouldn ’ t worry about the issue unless necessary. Won ’ t say too much here, except be cautious about arithmetic if it matters to your program. Some of these even store numbers as strings, so calculations may not always be what you expect, although most do a good job of auto-converting if needed.

Copyright © 2009 Elsevier Innovative Features: Data Types For composite types, a heavy emphasis is on mappings (also called dictionaries, hashes, or associated arrays). –Generally these are similar to arrays, but access time depends upon a hash funtion. –Example: director = {} director[‘Star Wars’] = ‘George Lucas’ director[‘The Princess Bride’] = ‘Rob Reiner’ print director[‘Star Wars’] print ‘Buffy’ in director Behind the scenes, this is actually using a hash function. Still O(1) access time (mostly), but the constant is not nearly as fast as normal array access.

Copyright © 2009 Elsevier Innovative Features Object Orientation –Perl 5 has features that allow one to program in an object- oriented style –PHP and JavaScript have cleaner, more conventional-looking object-oriented features both allow the programmer to use a more traditional imperative style –Python and Ruby are explicitly and uniformly object-oriented –Perl uses a value model for variables; objects are always accessed via pointers –In PHP and JavaScript, a variable can hold either a value of a primitive type or a reference to an object of composite type. In contrast to Perl, however, these languages provide no way to speak of the reference itself, only the object to which it refers

Copyright © 2009 Elsevier Innovative Features Object Orientation (2) –Python and Ruby use a uniform reference model –Classes are themselves objects in Python and Ruby, much as they are in Smalltalk –They are types in PHP, much as they are in C++, Java, or C# –Classes in Perl are simply an alternative way of looking at packages (namespaces) –JavaScript, remarkably, has objects but no classes its inheritance is based on a concept known as prototypes –While Perl ’ s mechanisms suffice to create object-oriented programs, dynamic lookup makes both PHP and JavaScript are more explicitly object oriented