chapter 13: scripting languages - computer …langley/cop4020/2015-summer/lectures/13.pdf ·...
TRANSCRIPT
![Page 1: Chapter 13: Scripting Languages - Computer …langley/COP4020/2015-Summer/Lectures/13.pdf · Chapter 13: Scripting Languages ... I CGI scripting is quite simple; ... Scripting languages](https://reader034.vdocuments.mx/reader034/viewer/2022050814/5b90525509d3f21c788bbb37/html5/thumbnails/1.jpg)
Chapter 13: Scripting Languages
July 28, 2015
![Page 2: Chapter 13: Scripting Languages - Computer …langley/COP4020/2015-Summer/Lectures/13.pdf · Chapter 13: Scripting Languages ... I CGI scripting is quite simple; ... Scripting languages](https://reader034.vdocuments.mx/reader034/viewer/2022050814/5b90525509d3f21c788bbb37/html5/thumbnails/2.jpg)
Why scripting?
I Scripting languages are strongest at asking other programs todo something; call it “glue” if you like.
![Page 3: Chapter 13: Scripting Languages - Computer …langley/COP4020/2015-Summer/Lectures/13.pdf · Chapter 13: Scripting Languages ... I CGI scripting is quite simple; ... Scripting languages](https://reader034.vdocuments.mx/reader034/viewer/2022050814/5b90525509d3f21c788bbb37/html5/thumbnails/3.jpg)
Batch and interactive mode common
I REPL-type batch quite common
![Page 4: Chapter 13: Scripting Languages - Computer …langley/COP4020/2015-Summer/Lectures/13.pdf · Chapter 13: Scripting Languages ... I CGI scripting is quite simple; ... Scripting languages](https://reader034.vdocuments.mx/reader034/viewer/2022050814/5b90525509d3f21c788bbb37/html5/thumbnails/4.jpg)
Brevity is often the case
I print “Hello world!”; is likely to work just fine in a scriptinglanguage, with perhaps a bit of syntactic sugar.
I Reification of quite a bit of user-land experience as syntax forpre-existing objects inside the language environment.
![Page 5: Chapter 13: Scripting Languages - Computer …langley/COP4020/2015-Summer/Lectures/13.pdf · Chapter 13: Scripting Languages ... I CGI scripting is quite simple; ... Scripting languages](https://reader034.vdocuments.mx/reader034/viewer/2022050814/5b90525509d3f21c788bbb37/html5/thumbnails/5.jpg)
Flexible, dynamic typing is the usual case
I Coercion is quite common; also, types can become quitebaroque (look at the perlio manual page, for instance)
![Page 6: Chapter 13: Scripting Languages - Computer …langley/COP4020/2015-Summer/Lectures/13.pdf · Chapter 13: Scripting Languages ... I CGI scripting is quite simple; ... Scripting languages](https://reader034.vdocuments.mx/reader034/viewer/2022050814/5b90525509d3f21c788bbb37/html5/thumbnails/6.jpg)
Primary Access to system-level objects.
I io, file/directory manipulation, process management, databaseaccess, ipc, networking. . .
![Page 7: Chapter 13: Scripting Languages - Computer …langley/COP4020/2015-Summer/Lectures/13.pdf · Chapter 13: Scripting Languages ... I CGI scripting is quite simple; ... Scripting languages](https://reader034.vdocuments.mx/reader034/viewer/2022050814/5b90525509d3f21c788bbb37/html5/thumbnails/7.jpg)
Pattern-matching and string manipulation
I PCRE
![Page 8: Chapter 13: Scripting Languages - Computer …langley/COP4020/2015-Summer/Lectures/13.pdf · Chapter 13: Scripting Languages ... I CGI scripting is quite simple; ... Scripting languages](https://reader034.vdocuments.mx/reader034/viewer/2022050814/5b90525509d3f21c788bbb37/html5/thumbnails/8.jpg)
High-level data types
I Sets, bags, dictionaries, lists, tuples, . . .
![Page 9: Chapter 13: Scripting Languages - Computer …langley/COP4020/2015-Summer/Lectures/13.pdf · Chapter 13: Scripting Languages ... I CGI scripting is quite simple; ... Scripting languages](https://reader034.vdocuments.mx/reader034/viewer/2022050814/5b90525509d3f21c788bbb37/html5/thumbnails/9.jpg)
Shells
I Truest type of scripting; consists literally of the commands toa given shell
I Globs and regular expressionsI Pipes and redirectionI Here documentsI Quoting with interpolation and withoutI Functions
![Page 10: Chapter 13: Scripting Languages - Computer …langley/COP4020/2015-Summer/Lectures/13.pdf · Chapter 13: Scripting Languages ... I CGI scripting is quite simple; ... Scripting languages](https://reader034.vdocuments.mx/reader034/viewer/2022050814/5b90525509d3f21c788bbb37/html5/thumbnails/10.jpg)
The crunch-bang
I Dire but neat hack
![Page 11: Chapter 13: Scripting Languages - Computer …langley/COP4020/2015-Summer/Lectures/13.pdf · Chapter 13: Scripting Languages ... I CGI scripting is quite simple; ... Scripting languages](https://reader034.vdocuments.mx/reader034/viewer/2022050814/5b90525509d3f21c788bbb37/html5/thumbnails/11.jpg)
Text processing and report general
I PERL = “Practical Extraction and Reporting Language”I Sed, stream editingI Awk, the moribund
![Page 12: Chapter 13: Scripting Languages - Computer …langley/COP4020/2015-Summer/Lectures/13.pdf · Chapter 13: Scripting Languages ... I CGI scripting is quite simple; ... Scripting languages](https://reader034.vdocuments.mx/reader034/viewer/2022050814/5b90525509d3f21c788bbb37/html5/thumbnails/12.jpg)
Python
I Unusually, it actually cares about indentation and end-of-linecharacters
I Structurally, well, some people really like it and some don’t;fundamentally, it’s not a lot different than most scriptinglanguages, but certainly is willing to take on (and sometimesdrop) new features.
![Page 13: Chapter 13: Scripting Languages - Computer …langley/COP4020/2015-Summer/Lectures/13.pdf · Chapter 13: Scripting Languages ... I CGI scripting is quite simple; ... Scripting languages](https://reader034.vdocuments.mx/reader034/viewer/2022050814/5b90525509d3f21c788bbb37/html5/thumbnails/13.jpg)
Ruby
I A purely object-oriented language; the author wanted alanguage more expressive than Perl and more object-orientedthan Python.
![Page 14: Chapter 13: Scripting Languages - Computer …langley/COP4020/2015-Summer/Lectures/13.pdf · Chapter 13: Scripting Languages ... I CGI scripting is quite simple; ... Scripting languages](https://reader034.vdocuments.mx/reader034/viewer/2022050814/5b90525509d3f21c788bbb37/html5/thumbnails/14.jpg)
Extension languages
I If a software package exposes an API, then one can buildaround that API; while this might be external, the scriptingcould also incorporated into that environment. For instance,GIMP, Inkscape, and emacs all have significant extensioncapabilities. Some software packages have their own extensionlanguages; others are more oriented to an API-typeenvironment.
![Page 15: Chapter 13: Scripting Languages - Computer …langley/COP4020/2015-Summer/Lectures/13.pdf · Chapter 13: Scripting Languages ... I CGI scripting is quite simple; ... Scripting languages](https://reader034.vdocuments.mx/reader034/viewer/2022050814/5b90525509d3f21c788bbb37/html5/thumbnails/15.jpg)
CGI scripting
I CGI scripting is quite simple; a process receives a http request(often moderated in some fashion, though not necessarily)and then replies with a similarily formatted response. Text ->text is a modality ideally suited to scripting languages.
![Page 16: Chapter 13: Scripting Languages - Computer …langley/COP4020/2015-Summer/Lectures/13.pdf · Chapter 13: Scripting Languages ... I CGI scripting is quite simple; ... Scripting languages](https://reader034.vdocuments.mx/reader034/viewer/2022050814/5b90525509d3f21c788bbb37/html5/thumbnails/16.jpg)
CGI scripting
I PHP: a lamentable language; of all the languages we will talkabout this semester, is probably the most troubled. Widelydeployed, it has awkward constructions such as == versus===.
![Page 17: Chapter 13: Scripting Languages - Computer …langley/COP4020/2015-Summer/Lectures/13.pdf · Chapter 13: Scripting Languages ... I CGI scripting is quite simple; ... Scripting languages](https://reader034.vdocuments.mx/reader034/viewer/2022050814/5b90525509d3f21c788bbb37/html5/thumbnails/17.jpg)
CGI scripting
I Server-side javascript is now competing strongly with PHP;see this article.
![Page 18: Chapter 13: Scripting Languages - Computer …langley/COP4020/2015-Summer/Lectures/13.pdf · Chapter 13: Scripting Languages ... I CGI scripting is quite simple; ... Scripting languages](https://reader034.vdocuments.mx/reader034/viewer/2022050814/5b90525509d3f21c788bbb37/html5/thumbnails/18.jpg)
Scripting languages and innovation
I Names and Scopes
I Wide variety of ideas here: Perl, in its usual accommodatingfashion allows about any type of scoping you like; Python andJavascript use classical nesting and lexical scoping
I TCL has unusua methods for “external” scoping (see fig 13.18)
![Page 19: Chapter 13: Scripting Languages - Computer …langley/COP4020/2015-Summer/Lectures/13.pdf · Chapter 13: Scripting Languages ... I CGI scripting is quite simple; ... Scripting languages](https://reader034.vdocuments.mx/reader034/viewer/2022050814/5b90525509d3f21c788bbb37/html5/thumbnails/19.jpg)
Scripting languages and innovation
I TCL, like Pleasant, uses strings for everything
![Page 20: Chapter 13: Scripting Languages - Computer …langley/COP4020/2015-Summer/Lectures/13.pdf · Chapter 13: Scripting Languages ... I CGI scripting is quite simple; ... Scripting languages](https://reader034.vdocuments.mx/reader034/viewer/2022050814/5b90525509d3f21c788bbb37/html5/thumbnails/20.jpg)
Scripting languages and innovation
I Perl has the very unusual idea of letting the program haverather direct access to subroutine parameters as ananonymous array
![Page 21: Chapter 13: Scripting Languages - Computer …langley/COP4020/2015-Summer/Lectures/13.pdf · Chapter 13: Scripting Languages ... I CGI scripting is quite simple; ... Scripting languages](https://reader034.vdocuments.mx/reader034/viewer/2022050814/5b90525509d3f21c788bbb37/html5/thumbnails/21.jpg)
Scripting languages and innovation
I Scripting languages generally have excellent stringmanipulation tools as built-in features; i.e., there existslanguage syntax for the tool rather than expressing its use ascalls to library routines.
![Page 22: Chapter 13: Scripting Languages - Computer …langley/COP4020/2015-Summer/Lectures/13.pdf · Chapter 13: Scripting Languages ... I CGI scripting is quite simple; ... Scripting languages](https://reader034.vdocuments.mx/reader034/viewer/2022050814/5b90525509d3f21c788bbb37/html5/thumbnails/22.jpg)
Scripting languages and innovation
I One outstanding example is Perl’s support for regularexpressions as part of the syntax of the language.