1 / 13

The Variety of Programming Languages

The Variety of Programming Languages. D Goforth COSC 3127. 1. Grouping Languages by Paradigm. imperative functional logical object.oriented scripting??. Imperative Languages (Procedural). since 1940’s, high level since 1950’s statement-oriented closest to underlying machine model

Download Presentation

The Variety of Programming Languages

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. The Variety of Programming Languages D Goforth COSC 3127

  2. 1. Grouping Languages by Paradigm • imperative • functional • logical • object.oriented • scripting??

  3. Imperative Languages (Procedural) • since 1940’s, high level since 1950’s • statement-oriented • closest to underlying machine model • e.g. Fortran, COBOL, Algol, Pascal, c

  4. ALGOL 60 example: (see p. 60, Sebesta) (part of program, read in array and find sum) comment input integers into array and find sum; begin integer array intlist[1:99]; integer listlen, counter, sum; sum = 0; readint(listlen); if (listlen>0) ^ (listlen < 100) then begin comment loop to read values; for counter := 1 step 1 until listlen do begin readint(intlist[counter]); sum := sum + intlist[counter] end; printint(sum) end end

  5. Functional Languages (Applicative) • since 1950’s • based on mathematical concept of function • data storage is a ‘side-effect’! • Command-line interpreter model • e.g. LISP, APL, Maple, unix, DOS • BASIC is an imperative/functional hybrid

  6. LISP example: (in a pseudo-lisp dialect) (function to add all numbers in a list ‘lis’; lis may not be a list, or, when it is a list, may contain items others than numbers that can be added ? (define (sumnum lis) (if ((not (list? lis)) ( 0 )) ((number? (firstOf lis)) (plus (firstOf lis)(sumnum (restOf lis)))) ( true (sumnum (restOf lis))))) sumnum ? (sumnum ‘( 4 w (u n 66) 5 3)) 12

  7. Logic Languages • since 1970’s • based on logical implication expressions (=>) • programs determine what combinations of data make expressions true • e.g. Prolog

  8. Prolog example: (program to find the greatest common divisor of two integers U, V; result is value of W) gcd(U, 0, U). gcd(U, V, W) :- not(V=0), R is U mod V, gcd(V, R, W). ?- gcd(10, 15, W). W = 5 ?- gcd(20,30,7). no.

  9. Object-oriented Languages • since 1970’s • abstract data types manipulated by messages invoking methods • e.g. Smalltalk, Actor • C++, java are imperative/object-oriented hybrids

  10. Smalltalk example: (see p. 481, Sebesta) (method to replace two arrays of objects with longer arrays; the arrays ‘names’ and ‘codes’ are instance variables) grow | oldNames oldCodes| oldNames <- names. oldCodes <- codes. names <- Array new: names size + 1. codes <- Array new: codes size + 1. names replaceFrom: 1 to: oldNames size with: oldNames codes replaceFrom: 1 to: oldCodes size with: oldCodes

  11. Scripting Languages • since 1950’s • based on large libraries of routines • e.g. JCL, AWK, Perl

  12. 2. Grouping Languages by Kinship • Sebesta, p. 39 • languages are related to others developed before • many languages mix programming paradigms

More Related