CSCE 431 Lecture 20

From Notes
Jump to navigation Jump to search

« previous | Thursday, April 3, 2014 | next »


Late from Dr. Jones' Discussion

System and Scripting Languages

Typeless Scripting

Self-modifying code.

variables are containers (usually string-oriented for uniform representation)

Allows code reuse

  • e.g. UNIX filters read/write byte streams


Typing

  • Find errors at compile time
  • Permits optimizations
  • Makes code-reuse difficult
  • Might have to do type conversion (e.g. integer vs. floating point division)
  • Might have to recompile, but may not have source


Tcl Example

button .b -text Hello! -font {Times 166} -command {puts Hello}
  • "Hello!" in 16-pt Times on button
  • Prints "hello" when clicked

6 things in one statement:

  1. command name (button)
  2. button control (.b)
  3. property names (-text, -font, -command)
  4. strings (Hello!, hello)
  5. Font name (Times 16)
  6. Tcl script (puts hello)

Everything represented as strings

In Java

7 lines in 2 methods

In C++/MFC

Takes 25 lines in 3 procedures

Just to create a Font:

CFont *fontPtr = new CFont();
fontPtr->CreateFont(/* 14 parameters */)


Error Checking

Strong typing helps to find errors

Efficiency No need for run-time checks


Scripting languages check values when used

  • (e.g. cannot have font size xyz)
  • Must pay cost at runtime
  • Must thoroughly test code to find errors.

Interpretation

Most scripting languages are "interpreted"

  • "compiled on the fly"
  • "quickly compile and then execute"

Speeds up development loop

Flexibility for users to program apps at runtime (e.g. Tcl interface extension language on Synopsys Design Compiler)


Efficiency

Scripting Languages are less efficient:

  • Rely on interpretation rather than compilation
  • Run-time "type" checking
  • Power and ease-of-use rather than running on "bare metal" of processor.


Example:

  • scripting: variable length string vs. System: binary value in machine word
  • scripting: hash table vs. System: indexed array

Efficiency is usually not an issue (esp. in smaller scripted apps). More time is spent in components, not scripting.


Higher Level Programming

Scripting statements execute 100s to 1000s of machine instructions

In contrast, system programming language statements execute about 5 machine instructions.

For example:

  • Perl regular expression substitution is as easy as integer addition
  • Tcl variable trace triggers updates when variable is set

Scripting is thus 5–10 times more productive.

System Programming Language Benefits

Scripting is useful for gluing, system integration, extension languages, and portablity.

System Programming Languages are best for complex data structures and algorithms where performance matters.


Most systems provide both

IBM
Job Control Language
Jobs ran in FORTRAN, PL/1, Algol, COBOL, Assembler
UNIX
Shell: sh / tch
C
Windows
Visual Basic
Visual C++


Why Scripting's Popularity?

Better scripting technology

  • Garbage collection
  • Faster machines
  • advanced language features

Casual programmers:

  • quickly learn language
  • "whip up" solution script for few-times use
  • e.g. DB queries in spreadsheet.
  • Speed of development and use, not execution