The Variety of Programming Languages

13
The Variety of Programming Languages D Goforth COSC 3127

description

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 - PowerPoint PPT Presentation

Transcript of The Variety of Programming Languages

Page 1: The Variety of Programming Languages

The Variety of Programming Languages

D GoforthCOSC 3127

D GoforthCOSC 3127

Page 2: The Variety of Programming Languages

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

Page 3: The Variety of Programming Languages

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

Page 4: The Variety of Programming Languages

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) endend

Page 5: The Variety of Programming Languages

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

Page 6: The Variety of Programming Languages

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

Page 7: The Variety of Programming Languages

Logic Languages

since 1970’s based on logical implication expressions (=>) programs determine what combinations of

data make expressions true e.g. Prolog

Page 8: The Variety of Programming Languages

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.

Page 9: The Variety of Programming Languages

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

Page 10: The Variety of Programming Languages

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

Page 11: The Variety of Programming Languages

Scripting Languages

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

Page 12: The Variety of Programming Languages

2. Grouping Languages by Kinship Sebesta, p. 39 languages are related to others developed

before many languages mix programming paradigms

Page 13: The Variety of Programming Languages