SPL Lesson 2 2017
SPL Lesson 2 2017
SPL Lesson 2 2017
COSC306
Lesson 2
Fundamental Concepts of Modern
Programming Languages
Outline
Class Exercise from Take-Home Assignment
2 COSC306
Review of SPL - Lesson 1
1990s: the Internet age
The rapid growth of the Internet in the mid-1990s was the next major historic
event in programming languages. By opening up a radically new platform for
computer systems, the Internet created an opportunity for new languages to be
adopted. In particular, the Java programming language rose to popularity because
of its early integration with the Netscape Navigator web browser, and various
scripting languages achieved widespread use in developing customized application
for web servers. The 1990s saw no fundamental novelty in imperative languages ,
but much recombination and maturation of old ideas. This era began the spread of
functional languages. A big driving philosophy was programmer productivity.
Many "rapid application development" (RAD) languages emerged, which usually
came with an IDE, garbage collection, and were descendants of older languages.
All such languages were object-oriented. Java in particular received much
attention. More radical and innovative than the RAD languages were the new
scripting languages. These did not directly descend from other languages and
featured new syntaxes and more liberal incorporation of features. Many consider
these scripting languages to be more productive than even the RAD languages, but
often because of choices that make small programs simpler but large programs
more difficult to write and maintain. Nevertheless, scripting languages came to be
the most prominent ones used in connection with the Web.
3 COSC306
Review of SPL – contd.
There is inevitably some overlap in these paradigms:
Imperative programming – defines computation as statements
that change a program state
Procedural programming, structured programming –
specifies the steps the program must take to reach the desired state.
Declarative programming – defines computation logic without
defining its control flow .
Logic programming – programs are executed by applying
inference rules over them until an answer to the problem is found
Functional programming – treats computation as the evaluation
of mathematical functions and avoids state and mutable data
Object-oriented programming (OOP) – organizes programs as
objects : data structures consisting of data fields and methods together
with their interactions.
4 COSC306
List of High-Level PLs - 1
Assembly Language – Nathaniel Simula – Nygaard/Dahl
Rochester SNOBOL - David J.
Autocode – Alick Glennie Farber/Ralph E. Griswold
IPL – Allen Newell/Cliff Shaw CPL – Christopher Strachey
FLOW-MATIC – Grace Hopper BASIC – John George
FORTRAN – John Backus Kemeny/ Thomas Kurtz
COMTRAN - Bob Berner PL/I – IBM
LISP – John McCarthy JOSS – Roger Hui
ALGOL – Bauer, Backus, McCarthy, BCPL – Martin Richards
Wijngaarden, Green Logo –Wally Feurzeig
FACT – Comp Sci Corp, Honeywell B – Ken Thompson
COBOL – Grace Hopper Pascal – NiklausWirth
RPG – IBM Forth – Charles H. Moore
APL – Kenneth E. Iverson C – Dennis Ritchie
5 COSC306
List of High-Level PLs - 2
Smalltalk – Alan Kay/Dan Ingalls Erlang – Joe Armstrong
Prolog – Colmerauer/ Perl – Larry Wall
Roussel/Kowalski Tcl – John Ousterhout
ML – Robin Milner Mathematica –Wolfram
Scheme – Guy L. Steele/Gerald Jay Research
Sussman FL – John Backus
SQL – Donald D Chamberlin/ Haskell – Simon Peyton
Raymond F. Boyce Jones/ Lennart Augustsson
C++ – Bjarne Stroustrup Python – Guido Van Rossum
ADA – Jean Ichbiah Visual Basic – Alan Cooper
Common Lisp – Scott Fahlman Ruby –Yukihiro Matsumoto
MATLAB - MathWorks
CLOS – (see LISP)
Eiffel – Bertrand Meyer
Java – James Gosling
6 COSC306
List of High-Level PLs - 3
Delphi – Anders Hejisberg Objective-C – Brad
JavaScript – Ryan Lienhart Cox/Tom Love/Apple
Dahl/Joyent Scala – Martin Odersky
PHP – Rasmus Lerdorf Clojure – Rich Hickey
D – Walter Bright/Digital F# – Don Syme/Microsoft
Mars/Andrei Alexandrescu Groovy – James Strachan/
ActionScript – Adobe Flash Guillaume LaForge
Developer Go – Robert Griesemer/
C# – Anders Hejlsberg Rob Pike/Google
Visual Basic .NET – Dart – Google
Microsoft Swift - Apple
7 COSC306
PLs and Acronyms –1
BASIC –
Beginner’s All-purpose Symbolic Instruction Code
FORTRAN –
FORmula TRANslator
COBOL –
COmmon Business Oriented Language
ALGOL –
ALGOrithmic Language
PL/I –
Programming Language One
LISP –
LISt Processing
SQL –
Structured Query Language
8 COSC306
PLs and Acronyms –2
PHP –
Personal Home Page (now – Hypertext Preprocessor)
PERL –
Practical Extraction and Report Language
GO –
Golang (GoLang or Google Language)
CLOS –
Common Lisp Object System
ADA –
(named after Ada Lovelace)
MATHLAB –
MATrix LABoratory
9 COSC306
PLs and Acronyms –3
COMTRAN –
COMmercial TRANslator
IPL –
Information Processing Language
FACT –
Fully Automated Computing Technique
TCL –
Tool Common Language
CPL –
Combined Programming Language (Cambridge
PL/Computer PL)
BCPL –
Basic Combined Programming Language
10 COSC306
PLs and Acronyms –4
LOGO –
Logic Oriented Graphic Oriented
RPG –
Report Program Generator
SNOBOL –
String-Oriented Symbolic Language
APL –
A Programming Language
FL –
Function Level
JOSS –
Johnniac Open Shop System
11 COSC306
Concepts of Programming Languages
There are so many PL Concepts that can be discussed
depending on the approach to be taken. For this class, the
following will be consider:
Rules of Programming
Naming in Programming
Binding in Programming
Scope in Programming
Paradigms Approach
PLs Approach
Syntax in various PLs
Semantics of PLs
Modern PLs
12 COSC306
Rules of Programming
Create programs that are easy to VALIDATE (check that the
results are correct) and MAINTAIN (change to suit different
future needs).
Build units of program that are GENERAL (suitable for many
similar application and FLEXIBLE (able to handle different
types of input and computing requirements as possible which
promotes CODE REUSABILITY (using parts of old programs
in new ones).
Programs should have a well organized internal structure; the
MODULARITY PROGRAMMING PARADIGM requires
partitioning every program into relatively small units, each
performing a well defined tasks.
13 COSC306
Rules of Programming – contd.
Programs should be fully documented. Documentation
consists of:
Self-explaining names for variables, procedures, etc.
Short comments explaining the algorithms used, variables’ roles and
computation steps
Program header containing a description, bugs and problems, planned
improvements, copyright and redistribution information
Procedure headers similar to the program header
Text file explaining how to compile, link, install and use the program
Programs should be portable by strictly adherence to the
STANDARDs, avoid using operating system routines and any
processor dependent features
Carefully select appropriate algorithms; very important
14 COSC306
Rules of Programming – Summary
Clarity is more important than efficiency; must be readable
Don’t re-invent the codes (without fully understanding the
bigger picture, changing 1 variable could result in breaking the
entire system)
Keep coding as simple as possible; think of the next developer
Learn from others’ mistakes mostly, not yours. Studying the
habits of other developers expands your mental dictionaries
Bug free code is more important than clean code
Begin with an end in mind; never start if you cannot finish
If its not broken, don’t fix it; its more difficult to debug
First seek to understand, then to be understood
15 COSC306
Naming in Programming
The Computer Programming, a naming convention is a set of
rulers for choosing the character sequence to be used for
identifiers which denote variables, types, functions and other
entities in source code and documentation.
Name variables, functions, classes, methods, etc. with nouns, noun
phrases, adjective phrases and verbs
Do not use the keywords for naming in programming, e.g. class, int,
float, double, function, friend, abstract, this, private, public, etc.
Use prefixes, suffixes and delimiters where necessary
Consistency is a key in naming convention in programming
Use capitalization and initial caps where necessary
Name must be expressive of what it is intended for, readable, sensible,
meaningful and understandable
16 COSC306 (Examples in the Class)
Naming in Programming – contd.
Most important feature of high level languages: programmers
able to give names to program entities (variable, constant,
function, type, ...). These names are called identifiers.
Variable has 6 components
1. Name
2. Type
3. Location (l-value)
4. Reference (r-value)
5. Scope - where variable accessible and manipulable –
static vs dynamic
6. Lifetime - interval of time in which location bound to
variable
17 COSC306
Binding in Programming
Binding in PL is referred to in the context of any computer
programming language describes how a variable is created and
used (or bound) by and within the given program and possibly
by other programs.
Attributes of parts of programs must be “bound" to object
before or during computation. A binding fixes a value or other
property of an object (from a set of possible values)
Time at which binding occurs is called binding time.
Dynamic binding – at execution or run-time. Lisp and some script
languages apply dynamic binding.
Static binding – at translation, language implementation, language
definition or compile time. Most languages apply static binding (C,
Haskell, Pascal, Java, …
18 COSC306
Binding in Programming – contd.
Many language design decisions relate to binding time
Late – more flexible
Early – more efficient
More efficient to bind “+" at translation than execution
Early – supports compilation, late – supports interpretation
Programming choices may delay binding time
Bindings stored both at compile and at run-time.
Compilation
Declarations stored in Symbol table (Names -> Attributes)
Most bindings used only in the compilation process
Execution
Run-time environment keeps track of meanings of names (Names ->Locations)
Contents of locations stored in memory (also called the state) (Locations ->
Values)
An interpreter keeps all 3 kinds of bindings together in one environment
19 COSC306
Scope in Programming
Variable Scope determines which variables in the program are
visible to other portions of the program and dictates “how long” a
variable is available while the program is executing.
This variable visibility issue includes the ability for one portion of
the code to access a variable in other parts of the code. The scope
of the variable is determined by the location where the variable is
declared.
A Local Scope means a variable is defined inside a function and is
not accessible outside the function.
A Global Scope means a variable is defined outside all functions
and is accessible to all functions in the its scope.
Static Scope helps a program to „remember‟ what value is stored
between function calls. An initialized static local variable in a
function, when called more than once in a program, will retain its
value throughout the execution.
20 COSC306
Assignments for next Class
Review Acronyms, paying more attention to the common and
mostly used PLs. Note: not Programming Paradigms (PPs)
Review examples or scenario-based cases where PPs (not
done in class) can be applied
Benefits (advantages) and cost (disadvantages) of applying Multi
and/or Hybrid PPs
Review the main reasons for developing some selected
Scripting and High Level PLs
Research more details on how to apply rules to programming
and relate these rules to naming and binding
Study ways by which a programmer or developer can select
the appropriate PL(s) and/or PP(s) for specific projects
21 COSC306