Scripting Languages LECTURE 1 INTRODUCTION Georges Khazen by

  • Slides: 20
Download presentation
Scripting Languages LECTURE 1 INTRODUCTION Georges Khazen

Scripting Languages LECTURE 1 INTRODUCTION Georges Khazen

by John K. Ousterhout

by John K. Ousterhout

Introduction Scripting languages are designed for different tasks than are system programming languages like

Introduction Scripting languages are designed for different tasks than are system programming languages like C, C++ or Java • System programming languages were designed for building data structures and algorithms from scratch. • Scripting languages were designed for gluing • They use existing powerful components and connect them together.

Introduction - Scripting languages and system programming languages are complimentary. - Most major computer

Introduction - Scripting languages and system programming languages are complimentary. - Most major computer platforms since the 1960 s include both kinds of languages - Several recent trends, such as faster machines, graphical user interfaces (GUI) and the growth of the Internet, have greatly expanded the applicability of scripting languages.

System programming Languages • They were introduced as an alternative to assembly languages (low

System programming Languages • They were introduced as an alternative to assembly languages (low level programming, register allocation and procedure-calling sequence) • By the late 1950 s, higer-level languages such as List, Fortran and Algol began to appear. • No more need for machine instructions • Compilers are needed to translate each statement in the source program into a sequence of binary instructions • Over the time, other system programming languages evolved including PL/1, Pascal, C, C++ and Java • Quicker than assembly languages for developing applications but less efficient

System programming Languages Higher Level System programming languages differ from assembly languages in two

System programming Languages Higher Level System programming languages differ from assembly languages in two ways: they are higher level and they are strongly typed. • Register allocation is handled by the compiler • Procedure calling sequences are generated automatically; • Programmers can use simple keywords such as while and if for control structures; the compiler generates all the detailed instructions to implement the control structures. On average, each line of code in a system programming language translates to about five machine instructions.

Typing • Typing refers to the degree to which the meaning of information is

Typing • Typing refers to the degree to which the meaning of information is specified in advance of its use. In a strongly typed language, the programmer declares how each piece of information will be used, and the language prevents the information from being used in any other way. In a weakly typed language, there are no a priori restrictions on how information can be used; the meaning of information is determined solely by the way it is used, not by any initial promises.

Typing Today’s system programming languages are strongly typed. For example: • Each variable in

Typing Today’s system programming languages are strongly typed. For example: • Each variable in a system programming language must be declared with a particular type such as integer or pointer to string, and it must be used in ways that are appropriate for the type. • Data and code are segregated; it is difficult if not impossible to create new code on the fly. • Variables can be collected into structures or objects with welldefined substructure and procedures or methods to manipulate them. An object of one type cannot be used where an object

TYPING Typing has several advantages It makes large programs more manageable by clarifying how

TYPING Typing has several advantages It makes large programs more manageable by clarifying how things are used and differentiating among things that must be treated differently. Compilers use type information to detect kinds of errors, such as an attempt to use a floating-point value as a pointer. Typing improves performance by allowing compilers to generate specialized code. For example, if a compiler knows that a variable always holds an integer value, then it can generate integer instructions to manipulate the variable; if the compiler does not know the type of a variable, then it must generate additional instructions to check the variable’s type at runtime.

Degree of Typing - System programming are strongly typed to help manage complexity -

Degree of Typing - System programming are strongly typed to help manage complexity - Scripting languages are typed less to simplify connections among components and provide rapid

Scripting Languages Generalizations about Scripting Languages • Interpreted (some compiled internally) ◦Rapid Development —

Scripting Languages Generalizations about Scripting Languages • Interpreted (some compiled internally) ◦Rapid Development — no compilation required ◦Portability — cross platform (since not compiling — no machine code) ◦Slower than compiled languages • Frequently no “main” • Good for controlling and connecting other applications • Flexibility ◦Easy to extend ◦Vast libraries and extensions available

Introduction Popular Applications of Scripting Languages • System Administration • System Automation • Text

Introduction Popular Applications of Scripting Languages • System Administration • System Automation • Text Manipulation • Web Development ◦Client-side ◦Server-side • Graphical User Interfaces • System Prototyping • Hacking & Cracking • Merging ◦Interfacing Incompatible Programs ◦Connecting Programs

Other Observations Used for gluing together existing components • Higher level than other languages

Other Observations Used for gluing together existing components • Higher level than other languages • Abstract operations are built-in — regular expressions, string operations are part of language level constructs • Tcl 1 -liner example in paper same work as 25 lines using Microsoft Foundation Classes • More work per line of code • Weaker typing means variables can hold whatever, need not explicitly declare them of a given type • Interpreted — run inside another application (the interpreter) • Trade-off between slower execution for faster development

Different Tools for Different Tasks Both types of languages have their strengths and weaknesses.

Different Tools for Different Tasks Both types of languages have their strengths and weaknesses. Each type tends to lend itself better for some tasks. You should consider choosing a scripting programming language when: • The application's main task is to connect preexisting components • The application will manipulate a variety of different things • The application requires a GUI • The application will do a lot of string manipulation • The functions of the application evolve rapidly over time • The application needs to be easily extensible You should consider choosing a system programming language when: • The application implements complex algorithms or data structures • The speed of the application is absolutely critical

Object Oriented Programming (OOP) is commonly held as a significant step in the evolution

Object Oriented Programming (OOP) is commonly held as a significant step in the evolution of programming languages. OOP features such as strong typing and inheritance are often claimed to produce dramatic reductions in development time. Strong typing encourages narrowly defined interfaces, which do not lend themselves for reuse • Inheritance poses a number of challenges — ties implementation of inherited classes together, adds complexity, and then there is multiple inheritance OOP does provide some good features: • Data Encapsulation — combine data and code in a manner that hides implementation • Interface Inheritance — same API, multiple implementations (i. e. Java Interface) These same OOP benefits have been applied to scripting languages: • Perl (historically procedural) adopted OOP along side its standard procedural style • Python is a semi-object oriented scripting language • Ruby treats everything as an object (including literals and so called “primitives”)

Scripting Languages vs. Systems Languages Scripting Languages Higher Level Gluing Components Loosely Typed Interpreted

Scripting Languages vs. Systems Languages Scripting Languages Higher Level Gluing Components Loosely Typed Interpreted Runs Slower Faster Development Dynamic Code Smaller Code Size Systems Languages Lower Level Building Components Strongly Typed Compiled Runs Faster Slower Development Static Code Larger Code Size

Examples (Fi. BONACCI) C C++ Java

Examples (Fi. BONACCI) C C++ Java

Examples (Fi. BONACCI) Perl Python Ruby

Examples (Fi. BONACCI) Perl Python Ruby

Text EDitors Problems with Normal Text Editors - They include formatting and layout information

Text EDitors Problems with Normal Text Editors - They include formatting and layout information in addition to the text - This might corrupt your files by filling them with unmanipulating text data and or scripts. Some Recommended Text Editors - Emacs, vi, vm for Linux - Emacs, Text. Wrangler BBEdit, Text. Mate for MAC - Emacs, Text. Wrangler, Notepad++ for Windows

Scripting Languages Covered • Shell Scripting • Python • Perl • Ruby • PHP

Scripting Languages Covered • Shell Scripting • Python • Perl • Ruby • PHP and Javascript (not in depth)