Scripted Components: Problem. Scripted Components. Problems with Components. Single-Language Assumption. Dr. James A. Bednar

Similar documents
Scripted Components Dr. James A. Bednar

Concepts of Programming Languages

Overview. Rationale Division of labour between script and C++ Choice of language(s) Interfacing to C++ Performance, memory

Topic 9: Type Checking

Topic 9: Type Checking

Programming Languages, Summary CSC419; Odelia Schwartz

Overview. Rationale Division of labour between script and C++ Choice of language(s) Interfacing to C++

Chapter 1. Preliminaries

9/7/17. Outline. Name, Scope and Binding. Names. Introduction. Names (continued) Names (continued) In Text: Chapter 5

Static Typing or Dynamic Typing: A Real Issue or a Simple Case of Tribalism

Design & Implementation Overview

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End

SKILL AREA 304: Review Programming Language Concept. Computer Programming (YPG)

Chapter 1. Preliminaries

The role of semantic analysis in a compiler

An Introduction to Tilde

What is Scripting? CSCI: 4500/6500 Programming Languages. Higher-level Programming. Origin of Scripting Languages. Contemporary Scripting Languages

Chapter 1 Preliminaries

Chapter 5. Names, Bindings, and Scopes

Type Bindings. Static Type Binding

Dynamically-typed Languages. David Miller

What is a programming language?

Data Types. Every program uses data, either explicitly or implicitly to arrive at a result.

Principles of Computer Game Design and Implementation. Lecture 3

Data Types. (with Examples In Haskell) COMP 524: Programming Languages Srinivas Krishnan March 22, 2011

Outline. Introduction Concepts and terminology The case for static typing. Implementing a static type system Basic typing relations Adding context

Scripting: Higher Level Programming for the 21st Century

Python for Earth Scientists

NEAR EAST UNIVERSITY

8/27/17. CS-3304 Introduction. What will you learn? Semester Outline. Websites INTRODUCTION TO PROGRAMMING LANGUAGES

The MPI API s baseline requirements

Closing the Case for Groovy (and Ruby, and Python)

Introduction. A. Bellaachia Page: 1


Tales from the Workshops

The MPI API s baseline requirements

Question No: 1 ( Marks: 1 ) - Please choose one One difference LISP and PROLOG is. AI Puzzle Game All f the given

Chapter 11 Introduction to Programming in C

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.

Types. What is a type?

Why study Programming Language Concepts? Chapter One. Language Evaluation Criteria. Programming Domains. Readability Writability Reliability Cost

New Programming Paradigms

Scoping and Type Checking

The Frame API s baseline requirements

Lecture 1: Overview of Java

Chapter Twelve. Systems Design and Development

Chapter 1. Preview. Reason for Studying OPL. Language Evaluation Criteria. Programming Domains

Chapter 5 Names, Binding, Type Checking and Scopes

Memory Allocation II. CSE 351 Autumn Instructor: Justin Hsia

Scripting: Higher Level Programming for the 21st Century

Cunning Plan. One-Slide Summary. Functional Programming. Functional Programming. Introduction to COOL #1. Classroom Object-Oriented Language

Erlang and Thrift for Web Development

Topics Covered Thus Far CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages

Compilation I. Hwansoo Han

CSC 533: Organization of Programming Languages. Spring 2005

Programming Languages 2nd edition Tucker and Noonan"

SOFTWARE ARCHITECTURE 6. LISP

Introduction to Python. Didzis Gosko

Introduction to Engineering Using Robotics Experiments. Dr. Yinong Chen

Scala, Your Next Programming Language

Minsoo Ryu. College of Information and Communications Hanyang University.

CPSC 3740 Programming Languages University of Lethbridge. Data Types

Programmiersprachen (Programming Languages)

Concepts in Programming Languages

Software Project Seminar VII: Tools of the Craft. 23 march 2006 Jevgeni Kabanov

CS252 Advanced Programming Language Principles. Prof. Tom Austin San José State University Fall 2013

Language Translation, History. CS152. Chris Pollett. Sep. 3, 2008.

Type Inference. Prof. Clarkson Fall Today s music: Cool, Calm, and Collected by The Rolling Stones

Advanced Object-Oriented Programming Introduction to OOP and Java

Lecture content. Course goals. Course Introduction. TDDA69 Data and Program Structure Introduction

Design Principles for a Beginning Programming Language

Software Project. Lecturers: Ran Caneti, Gideon Dror Teaching assistants: Nathan Manor, Ben Riva

Principles of Programming Languages. Lecture Outline

A polyglot day: learning from language paradigms. Benson Joeris Kathleen Dollard

Chapter 2 Preview. Preview. History of Programming Languages. History of Programming Languages. History of Programming Languages

Dynamic Languages Toolkit. Presented by Andrey Tarantsov

Compiler Design Spring 2018

Functional Programming Language Haskell

Outline. When we last saw our heros. Language Issues. Announcements: Selecting a Language FORTRAN C MATLAB Java

Advanced Programming & C++ Language

Run-time Environments

Run-time Environments

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher

Business and Scientific Applications of the Java Programming Language

Software Evolution. Dr. James A. Bednar. With material from

CSCI B522 Lecture 11 Naming and Scope 8 Oct, 2009

Introduction to Scripting Languages. October 2017

Where do we go from here?

Structure of Programming Languages Lecture 10

CSC 326H1F, Fall Programming Languages. What languages do you know? Instructor: Ali Juma. A survey of counted loops: FORTRAN

IA010: Principles of Programming Languages

Functional Programming. Introduction To Cool

CSE341: Programming Languages Lecture 19 Introduction to Ruby and OOP. Dan Grossman Winter 2013

Programming Languages FILS Andrei Vasilateanu

Introduction. Primitive Data Types: Integer. Primitive Data Types. ICOM 4036 Programming Languages

Sample Copy. Not for Distribution.

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

LECTURE 1. Overview and History

CS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline

Transcription:

Scripted Components: Problem Scripted Components Dr. James A. Bednar jbednar@inf.ed.ac.uk http://homepages.inf.ed.ac.uk/jbednar (Cf. Reuse-Oriented Development; Sommerville 2004 Chapter 4, 18) A longstanding goal of software developers has been to be able to build a large application by gluing together previously written reusable components. Even after decades of work and massive successes in some areas, such as system or language libraries, this goal has been very difficult to achieve in general. Why? SAPM Spring 2012: Scripted Components 1 SAPM Spring 2012: Scripted Components 2 Problems with Components Reuse of components is hard! E.g.: Components rarely have matching interfaces Existing components are difficult to adapt to new applications Vicious cycle: without expectation of reuse, no incentive for making reusable components Single-Language Assumption Ousterhout 1998: Part of the reason for low levels of reuse has been the mistaken assumption that components should be created and used in a single language. Underlying problem: languages best suited for creating components are worst suited for gluing them together, and vice versa. SAPM Spring 2012: Scripted Components 3 SAPM Spring 2012: Scripted Components 4

Background: Types of Typing (1) Languages differ about enforcing types at run or compile time: Static typing: Types of objects known at compile time Type of each object not usually stored in executable (C, Java) Dynamic typing: Types of objects known only at run time Each object stores its type (Python, LISP) And on how strongly they enforce types: Strong typing: Objects of the wrong type cause failures (e.g. 3+ 5 =error; C++, Python, ML, Haskell) Weak typing: Objects of the wrong type are converted (e.g. 3+ 5 = 35, JavaScript; or 3+ 5 = 8, PHP, Perl5, Tcl) Background: Types of Typing (2) And on whether typing is declared explicitly or implicitly: Nominative typing: Name of declared type must match (checkable at compile time; C++ (except templates), Java) Structural typing: Full set of methods must match (Haskell) Duck typing: If it waddles and quacks like a duck, it s a duck (C++ templates (e.g. iterators and pointers), Python, Ruby) Different type systems offer vastly different levels of flexibility, optimization capability, speed, memory usage, etc. For more info, see e.g. http://en.wikipedia.org/wiki/type_system. SAPM Spring 2012: Scripted Components 5 SAPM Spring 2012: Scripted Components 6 Requirements for Building Components To implement useful, high-performance primitives, you typically need: Speed Memory efficiency Bit-level access to underlying hardware and OS Systems Languages The requirements for building components are met by systems languages like C and C++. Systems languages allow (and typically require) detailed control over program flow and memory allocation. With such power available, strong, static, nominative typing (declaring object and argument types, checking them at compile time against strict inheritance hierarchies, etc.) is necessary to prevent catastrophic errors. SAPM Spring 2012: Scripted Components 7 SAPM Spring 2012: Scripted Components 8

Requirements for Gluing Components To glue primitive components written by multiple independent developers into an application, you want: Dynamic, non-nominative typing, to allow different interfaces to connect freely A small number of high-level, widely shared interface datatypes (e.g. strings, lists, dictionaries) Automatic memory management, etc., to allow one-off data structures to be created easily for gluing Graceful user-relevant error handling, debugging SAPM Spring 2012: Scripted Components 9 Scripting Languages Gluing components from independent developers in systems languages requires huge amounts of code and much time debugging, often swamping any benefit of reuse. Scripting languages excel at gluing, because they insulate the user from the details of program flow, memory allocation, and the operating system. Scripting languages are good for manipulating (analyzing, testing, printing, converting, etc.) pre-defined objects and putting them together in new ways without having to worry much about the underlying implementation. SAPM Spring 2012: Scripted Components 10 Scripting Language Features Typically: Interpreted: for rapid development and user modification High-level: statements result in many machine instructions Garbage-collected: to eliminate memory allocation code and errors Dynamically typed: to simplify gluing Slow: for native code (but can use fast external components) Examples: Python, Perl, Scheme/LISP, Tcl, Ruby, Visual Basic, sh/bash/csh/tcsh Scripted Components: Pattern Use a scripted language interpreter to glue reusable components together, packaging an application as: An interpreter A component library (preferably mostly preexisting) Scripts to coordinate the components into a meaningful system Applications can be tailored to specific tasks by modifying the script code, potentially by end users. Configuration options can be saved within the scripting language itself. SAPM Spring 2012: Scripted Components 11 SAPM Spring 2012: Scripted Components 12

Scripted Components: Advantages Helps make maintaining a large code body practical Increases long-term maintainability because application can be reconfigured as needs change Promotes reuse (and thereby development of reusable components) Provides separation between high-level and low-level issues (and programmers?) Greatly reduces total size of code, and/or expands functionality SAPM Spring 2012: Scripted Components 13 Scripted Components: Liabilities Can be complicated to bind languages together (but see SWIG, weave) Must learn and maintain source code in multiple languages Can be slow if critical components are mistakenly implemented in the script language Largest benefit requires existing components (but see e.g. the huge Python and Perl standard libraries) SAPM Spring 2012: Scripted Components 14 Scripted Components: Example Emacs editor, version 21.3 Core rarely-changed code written in C (265 KLOC), implementing custom LISP interpreter and performance-critical components. Rest in LISP (580 KLOC + huge external codebase), most of it user-contributed (i.e., written independently). Maintained continuously for more than 30 years, by hundreds (thousands?) of people. Scripted Components: Examples Other examples: Matlab GIMP LaTeX Many domain-specific systems Anything with macros, a configuration file, etc. (all large programs?) SAPM Spring 2012: Scripted Components 15 SAPM Spring 2012: Scripted Components 16

Custom vs. Off-the-Shelf Most existing large, long-lived programs use custom languages for macros or configuration, but those are hard to maintain, hard to learn, not shared between programs (limiting reuse), and limited in functionality. Greenspun s tenth rule : Any sufficiently complicated C or Fortran program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp Modern approach: Plug-in scripting languages. Many now available freely, with large bodies of reusable component libraries. Just download one and get to work! Where does Java fit? Ousterhout: Java is a platform-independent systems language, good for implementing components. Me: Maybe. To me Java seems weak as a component implementation language (compared to C or C++ performance), but also weak as a gluing language (due to static typing and poor interactivity). Thus Java seems like a compromise between scripting and systems languages, when Scripted Components offers best of both (at a cost of complexity and limited platform independence). E.g. Python, Guile (Scheme), Tcl, Perl SAPM Spring 2012: Scripted Components 17 SAPM Spring 2012: Scripted Components 18 Required Reading Ousterhout 1998, http://home.pacbell.net/ouster/scripting.html Note that the author developed the Tcl scripting language, and thus is strongly biased towards it. I personally think strongly typed object-oriented scripting languages like Python are much better for scripting object-oriented components, because objects in the component language appear as native objects in the scripting language. Nat Pryce, http://www.doc.ic.ac.uk/ np2/patterns/scripting/scripting.html Summary Scripted Components pattern applies to many (nearly all?) large-scale systems Allows high-level, abstract languages to be used for high-level tasks Allows low-level systems languages to be used for low-level tasks Provides and encourages component reuse Scripting languages now freely available Avoid writing custom configuration or macro languages SAPM Spring 2012: Scripted Components 19 SAPM Spring 2012: Scripted Components 20

References Ousterhout, J. K. (1998). Scripting: Higher level programming for the 21st century. Computer, 31 (3), 23 30. Sommerville, I. (2004). Software Engineering (7th Ed.). Reading, MA: Addison-Wesley. SAPM Spring 2012: Scripted Components 20