1 / 51

Programming Languages Presentation

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

delano
Download Presentation

Programming Languages Presentation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming Languages Presentation Perl, Simula and Smalltalk

  2. PERL

  3. 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

  4. 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";

  5. 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

  6. 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

  7. 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

  8. 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

  9. 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

  10. 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

  11. 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

  12. Perl – Object oriented Features • Polymorphism (Method Override) • Implicitly polymorphic, because of weak typing, we can override and redefine methods in subclasses

  13. 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

  14. 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

  15. 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

  16. 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

  17. SIMULA

  18. 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

  19. Simula: “Hello World” • An example of a Hello world program in Simula: Begin OutText ("Hello World!"); Outimage; End;

  20. 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)

  21. 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

  22. 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

  23. 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.

  24. 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

  25. 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

  26. 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

  27. 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”

  28. Simula: Evaluation • Readability • Too complicated • Missing data types (records, sets) as such orthogonality very poor • Writability • Limited file access facilities (typed files)

  29. 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

  30. 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

  31. SMALLTALK

  32. 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

  33. 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

  34. 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

  35. 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

  36. 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)

  37. 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

  38. 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)

  39. 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

  40. 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

  41. 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

  42. 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.

  43. 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

  44. 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

  45. 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

  46. 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

  47. 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

  48. 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

  49. 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

  50. 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

More Related