Programming Languages Presentation

advertisement
Programming Languages
Presentation
Perl, Simula and Smalltalk
PERL
Perl – An Overview
 Developed in 1987 by Larry Wall
 High Level, general purpose, interpreted, dynamic language
 Latest major stable version is 5.18 Perl 5
 Perl 5 and Perl 6 – two different languages developed
independently
 Derived broadly from C, SH and AWK
Perl – “Hello World”
 In Perl, one would write the Hello World program as:
print "Hello World!\n";
 Good Perl practices require more complex programs to add
the use strict and use warnings pragmas, leading into
something like:
use strict;
use warnings;
print "Hello World!\n";
Perl-Design & Features
 Names
Letters, numbers and underscores characters
Variables are prefixes with a special sign





$ for scalars
@ for arrays
% for hashes
Variables are case sensitive
 Bindings

Dynamic typed in terms of binding

Can simulate static typing by using “strict”
 Scoping

‘my’ provides static scoping, else generally dynamic

Perl-Design & Features
 Objects
 Reference to a data type, which knows its class
 Stores as reference in a scalar variable
 Class
 A package that contains the methods required to create and
manipulate objects
 Method
 A sub-routine defined within a package
Perl-Design & Features
 Data Types
 Three built in data types
 Scalars
 Arrays of Scalars
 Associative Arrays of Scalars known as “Hashes”
 A scalar is a single string, number or reference
 Arrays are ordered lists of scalars indexed from 0.
 Arrays are versatile and dynamic
 Hashes are unordered collection of scalar values indexed by
their associated string key
Perl-Design & Features
 Expressions and Assignment Statements
 Simplest form – ‘matching expressions’
 Special operator ‘=~’
 Use module ‘overload.pm’ to perform operator overloading
 Stetement Level Control Structures
 while, for, foreach and if statements are most commonly
used control structures
 until and unless - variations of while and if respectively
 control block – another form of while, useful to test
conditions
Perl-Design & Features
 Sub-programs
 Are global in scope, and can be invoked anywhere by name or
by reference
 Cannot be private, however the subroutine variables can be
private
 Exception Handling and Event Handling
 Built in exception handling mechanism- eval{} block
 $@ variable to check for exceptions
 Error.pm module handles OO exception handling
 Event handling procedures offered through a subclass
Perl-Design & Features
 Implementation
 Hybrid Implementation where the program is compiled for
errors and then interpreted using the perl interpreter
 Garbage Collection
 Perl employs reference garbage collector.
 Cannot handle circular references leading to memory leaks
Perl – Object oriented Features
 Inheritance
 Easily defined using special variable “@ISA”, that governs the
inheritance
 Encapsulation constructs
 Known as packages
 Use the constructors and destructors subroutines to handle
incorporation in packages
 Abstractions
 Psedo-hashes: like hashes, but scoped.
 Objects have automatically called methods
Perl – Object oriented Features
 Polymorphism (Method Override)
 Implicitly polymorphic, because of weak typing, we can
override and redefine methods in subclasses
Perl - Evaluation
Readability
 Reputation of being ugly and hard to maintain
 Poor Readability in general
 Variables because of special symbols are easy to read
 Syntax is non trivial
Orthogonality
 Not orthogonal but has many shortcut features
Perl - Evaluation
Writability
 Good writability because of many new features
 Simple data types and data type abstraction, special symbols
increases writability
Reliability
 Increased stability with continuous evolution since 1987
 Security problems due to improperly validated user input
 Increased complexity decreases reliability
Perl - Evaluation
Cost
 Open source software, no cost of ownership
 Similarly compilation costs, execution costs are free.
 Cost of maintenance is a question of time vs money
Perl - Applications
 Widespread popularity as a CGI scripting language
 Powerful text processing facilities without the data length
limitations
 Used in graphics programming, system administration,
network programming and biometrics
 Called the “glue language” or the “duct tape that holds
internet together”
 Favored for database applications
SIMULA
Simula – An Overview
 Initially designed for doing Simulations
 Later recognized as a general purpose programming language
 Developed in 1960s by Ole-Johan Dahl and Kristen Nygard.
 First object oriented programming language
 Two versions – Simula 1 and Simula 67
 Influenced later generations of programming languages
notably C++, Smalltalk
 Extension of Algol 60
Simula: “Hello World”
 An example of a Hello world program in Simula:
Begin
OutText ("Hello World!");
Outimage;
End;
Simula- Design & features
 Class
 A procedure which returns a pointer to its activation record
 Similar to Java, uses “begin ….. end” like braces in Java
 Comments begin with “!” and end with “;”
 Prefix Class (superclass) – defines a superclass and provides
inheritance
 Object
 Activation record produced by call to a class
 Ref(Class) – form of the type of a object variable (Simula term
for pointers)
Simula- Design & features
 Data types
 Integer, Short Integer, Real, Long Real, Character, Boolean
 Text – a class instance
 Case sensitive
 Assignments
 Uses “:=“ for standard value assignments
 And “:-” for reference assignments
 Parameters
 Transmitted by value
 Only for Ref type, parameters are transmitted by reference
Simula- Design & features
 Procedures
 Method/function implemented using keyword procedure in all
cases
 Procedures can be declared anywhere in a program
 No return statements
 Allows procedures to have procedure parameters (“Formal
procedures”)
 Virtual Mechanism
 Procedures can be declared virtual or not
 Can also be abstract as no implementation is given in class
Simula- Design & features
 Co-routines and quasi parallel execution
 A multi stack language
 Each objects executes in quasi parallel, gets its own call stack by
calling procedures
 “Detach” statement transfers the execution control back to main
program
 “Resume” continues the execution from the point of
detachment
 Subclasses can only be declared at the same block level as the
superclass.
Simula- Design & features
 Type checking
 Later versions, type check during compilation was added
 List processing
 Class “Simset” adds list processing capabilities
 Simulation
 Class “Simulation” allows for discrete event simulation
 Modularization
 Separate compilation of classes and procedures
 Strong Typing extends to separately compiled modules
Simula- Design & features
 Memory Management
 Objects are garbage collected automatically
 User destructors considered undesirable
 No issues with life span of objects
 Portability
 Highly standard definition
 Programs are highly portable
 Implementation
 Compiler implementation, uses Simula compiler to implement
Simula – Object Oriented Features
 Dynamic Lookup
 Operations on an object are selected from the activation record
of that object
 Inheritance (“Class prefixing”)
 Form of class prefixing, including the ability to redefine parts
of a class in a subclass
 Subtyping
 Arising from the way types are associated with classes
 Abstraction – introduced in later versions
Simula – Object Oriented Features
Unique Object oriented features of Simula
 Inner
 Indicates that the method of a subclass be called in combination
with execution of superclass code
 Inspect/Qua
 Provide ability to test the type of an object at run time and to
execute appropriate code accordingly
Encapsulation
 Initially no distinction
 Later versions incorporated “protected” and “hidden”
Simula: Evaluation
 Readability
 Too complicated
 Missing data types (records, sets) as such orthogonality
very poor
 Writability
 Limited file access facilities (typed files)
Simula: Evaluation
 Reliability






No multiple inheritance
No interfaces
Long executable files for short programs
No advanced parallelism and real time support
No GUI support
No proper security mechanism
 Cost
 Expensive, never became a widespread language
 Does not have a modern IDE
 Very portable
Simula - Applications
 Designed for doing Simulation during the 1960s
 Also used in wide range of applications such as simulating
VLSI designs, process modeling, protocols, typesetting,
computer graphics and education
SMALLTALK
Smalltalk – An Overview
 An object-oriented, dynamically typed, reflective
programming language
 Developed at Xerox PARC
 Smalltalk-76, Smalltalk-80 important versions
 Created by Alan Kay, Dan Ingalls, Adele Goldberg, Ted
Kaehler, Scott Wallace in the 1970s
 Major language that popularized objects
 Motivating application – Dynabook by Alan Kay
Smalltalk - Overview
 Main advances of Smalltalk over Simula:
 The Object metaphor was extended and refined
 Everything is an object including class
 All operations are messages to objects
 Objects and classes can be used to build entire system
 Abstraction was added using private instance variables, public
methods
Smalltalk – “Hello World”
 Message "show:" is sent to the object "Transcript“
 Invocation of the "show:" method displays the string
Transcript show: 'Hello, World!'.
 To see results, need transcript window
Smalltalk – Design & Features
 Object





A combination of private data and functions
Each object is an instance of some class
Have local memory, inherent processing capability
Ability to communicate with other objects
Can be passed as parameters and returned as objects
 Messages and Methods
 Message is a request to object to perform operation (function
call)
 Methods: (function) implementation of an operation
Smalltalk – Design & Features
 Classes
 A template defining the implementation of a set of objects
 A special editor
 Class variable-shared by all objects in class
 Subclass defined by inheriting from its superclass
 Selector
 The name of a message (function name)
Smalltalk – Design & Features
 Message
 A selector together with actual parameter values
 Contains the names and parameters of methods
 Method
 The code in a class for responding to a message
 Functions to manipulate objects
 Instance Variable
 Data stored in an individual object (instance of a class)
 Repeated for each object
Smalltalk – Design & Features
 Expressions
 Computation achieved by evaluating expressions, which always
return an object
 Types –Literals, Variable names, Message Expressions, Blocks of
Code
 Variables
 All variables are pointers to objects and inherently typeless
 Case sensitive (public –start with upperclass, private lowerclass)
Smalltalk – Design & Features
 Message Expressions
 Involves
 Receiver
 Arguments
 Message selector
 Message Answer
 Message Syntax Types
 Unary (no parameters)
 Binary : 2+3
 Keyword : myArray at: 42 put: 5
Smalltalk – Design & Features
 Self references
 “self ” is used to the object itself
 Assignment
 Uses “:=‘ for assignment
 Blocks
 Control structures formed by passing block objects as parameters
 Expressions evaluated when block receives the message “value”
[index := index+1.
Sum:=sum+index.] value
 Blocks can be assigned to variables
Smalltalk - Design & Features
 Implementation
 Just in time compilation
 Smalltalk programs are usually compiled to byte code, which is
then interpreted by a virtual machine into machine-native code.
 Portability
 All smalltalk systems follow the same virtual machine
specification making it very portable
 Incremental Compilation
 Compilation done at method level, compilation is faster and
instantaneous
Smalltalk - Design & Features
 Garbage Collection
 Automatic garbage collection
 Objects are allocated in a heap and the heap is collected for
garbage automatically
 “Nil” is an object used to check the “NULL” condition
 Error Handling
 On error in objects type, a message “doesnotunderstand” pops
up, and a debugger can be invoked to deal with it.
Smalltalk - Design & Features
 Reflection
 Each object can be examined and if required modified at run
time
 Operating System
 Was originally developed as a complete operating system
 Includes code for activities typically performed at OS level
Smalltalk - Object Oriented Features
 Abstraction
 Provided through protected instance variables
 All methods are public, instance variables accessed only by
methods of the class and subclasses
 Subtyping
 Does not have compile time type system
 Arises implicitly, based on set of messages understood by an
object
Smalltalk - Object Oriented Features
 Inheritance
 Subclasses inherit all instance variables and methods of
superclasses
 Methods of a superclass may be redefined in a subclass or
deleted
 Is a strict tree structure: a subclass can have only one and only
one parent class
 Subclasses can add new variables or methods, also can hide
inherited functionality
Smalltalk - Object Oriented Features
 Polymorphism
 Supports by allowing methods defined in class to be over ridden
with methods of the same name
 Encapsulation
 Encapsulates all objects, which can be interact with other
objects through messages to the objects interface
Smalltalk - Evaluation
 Readability
 Developed for non programming users
 Simple and constructible
 Very few special words
 Orthogonality
 As all constructs are object specific, every possible combination
is possible between the constructs leading to high orthogonality
 Writability
 Readable and Orthogonal
 Good support for abstraction
Smalltalk - Evaluation
 Reliability
 No inherent type checking
 But type checking carried out implicitly at run time for object
types
 Exception handling performed at run time, with debugging
capabilities
 Aliasing possible decreasing reliability
 Cost
 When released relatively expensive and uncommon
 Was not widely adopted resulting in shortage of trained people
and matured models
Smalltalk - Evaluation
 Whole “OS” approach, was a barrier when there were more
widely used OS like Unix
 Hasn’t kept up in the application area
 However very portable because of same virtual machine
specification
Smalltalk - Applications
 Prototyping –a program can be prototyped quickly in
smalltalk and later deployed in other languages. This is
possible due to incremental compilation
 Operating System – not widespread
Thank You
Download