CSC 1800 Organization of Programming Languages Introduction, - - PDF document

csc 1800 organization of programming languages
SMART_READER_LITE
LIVE PREVIEW

CSC 1800 Organization of Programming Languages Introduction, - - PDF document

CSC 1800 CSC 1800 Organization of Programming Languages Introduction, Welcome & Getting Started 1 Course Overview Welcome! Web site Syllabus Schedule Slides, Reading Assignments Video Recordings Attendance


slide-1
SLIDE 1

CSC 1800 1

CSC 1800 Organization of Programming Languages

Introduction, Welcome & Getting Started

2

Course Overview

⚫ Welcome! ⚫ Web site ⚫ Syllabus ⚫ Schedule ⚫ Slides, Reading Assignments ⚫ Video Recordings ⚫ Attendance ⚫ Blackboard – handing in, gradebook, etc.

1 2

slide-2
SLIDE 2

CSC 1800 2

3

Assessment

50% Assignments (questions, tasks, programming) 15% Exam #1 (midterm) 10% Programming language presentation 15% Exam #2 (final) 10% Participation (attendance, class discussion, intellectual contribution to class)

4

Class Style

⚫ Lecture ⚫ Demo ⚫ Hand-on Activities ⚫ Problem solving ⚫ Language design & programming ⚫ Presentations ⚫ Blackboard – gradebook, assignments, exams ⚫ Discussion (Blackboard or Piazza) – questions & answers

3 4

slide-3
SLIDE 3

CSC 1800 3

5

Goals for Week One

⚫ Names and faces ⚫ Seating chart filled out ⚫ Intro to Programming Languages ⚫ First experiments ⚫ Start homework assignment #1

6

INTRODUCTION TO PROGRAMMING LANGUAGES

5 6

slide-4
SLIDE 4

CSC 1800 4

7

Why Study Programming Languages?

⚫ Increased capacity to express ideas ⚫ Improved background for choosing appropriate

language

⚫ Increased ability to learn new languages ⚫ Better understanding of the significance of

implementation

⚫ Better use of languages that are already known ⚫ Overall advancement of computing

8

Programming Domains

⚫ Scientific Applications (Fortran) ⚫ Business Applications (COBOL) ⚫ Artificial Intelligence (LISP, Prolog) ⚫ Systems Programming (C) ⚫ Web Software (HTML, PHP, Java)

7 8

slide-5
SLIDE 5

CSC 1800 5

9

Language Evaluation Criteria

⚫ Readability: the ease with which programs can be

read and understood

⚫ Writability: the ease with which a language can be

used to create programs

⚫ Reliability: conformance to specifications (i.e.,

performs to its specifications)

⚫ Portability: moving program from one

implementation to another

⚫ Generality: applicability to a wide range of domains ⚫ Well-definedness: completeness of language ⚫ Cost: easy to learn, use, maintain

10

Influences on Language Design

⚫ Computer Architecture

Languages are developed around the prevalent computer architecture, known as the von Neumann architecture ⚫ Programming Methodologies

New software development methodologies (e.g., object-oriented software development) led to new programming paradigms and by extension, new programming languages

9 10

slide-6
SLIDE 6

CSC 1800 6

11

The von Neumann Architecture

12

The von Neumann Architecture

⚫ Fetch-execute-cycle

initialize the program counter repeat forever fetch the instruction pointed by the counter increment the counter decode the instruction execute the instruction end repeat 11 12

Memory (stores both instructi ans and data) R

esults of

Instructions and data

  • perations

Arithmetic and Control logic unit

i-

unit

  • Input and output devices

Central processing unit

slide-7
SLIDE 7

CSC 1800 7

13

Programming Methodologies Influences

⚫ 1950s and early 1960s: Simple applications; worry

about machine efficiency

⚫ Late 1960s: People efficiency became important;

readability, better control structures

– structured programming – top-down design and step-wise refinement

⚫ Late 1970s: Process-oriented to data-oriented

– data abstraction

⚫ Middle 1980s: Object-oriented programming

– Data abstraction + inheritance + polymorphism

⚫ Since: Write-once-run-anywhere, rapid devel, long-term

maintainability, focus on OOP

14

LANGUAGE PARADIGMS & IMPLEMENTATIONS

13 14

slide-8
SLIDE 8

CSC 1800 8

15

Language Categories or Paradigms

⚫ Imperative

Central features are variables, assignment statements, and iteration

Include languages that support object-oriented programming

Include scripting languages

Include the visual languages

Examples: C, Java, Perl, JavaScript, Visual BASIC .NET, C++

⚫ Functional

Main means of making computations is by applying functions to given parameters

Examples: LISP, Scheme

⚫ Logic

Rule-based (rules are specified in no particular order)

Example: Prolog

⚫ Markup

Markup languages extended to support some programming

Examples: HTML, LaTex, XML

16

Implementation Methods

⚫ Compilation

– Programs are translated into machine language

⚫ Interpretation

– Programs are interpreted by another program known as an

interpreter

⚫ Hybrid

– A compromise between compilers and interpreters

15 16

slide-9
SLIDE 9

CSC 1800 9

17

Compilation

⚫ Translate high-level program (source language) into

machine code (machine language)

⚫ Slow translation, fast execution ⚫ Compilation process has several phases:

– lexical analysis: converts characters in the source program into

lexical units

– syntax analysis: transforms lexical units into parse trees which

represent the syntactic structure of program

– Semantics analysis: generate intermediate code – code generation: machine code is generated

18

Compilation Process

17 18

lexical analyzer LexicaluniU

Syntax analyzer Intermediate code generator (and~ntic ;malyzer) Intermediate

,_

M!lthine Language Compu1.cr Resulu Op(1m1zatloo (oplional) lnputdala

slide-10
SLIDE 10

CSC 1800 10

19

Interpretation

⚫ No translation ⚫ Easier implementation of programs (run-time errors can

easily and immediately be displayed)

⚫ Slower execution (10 to 100 times slower than compiled

programs)

⚫ Often requires more space ⚫ Now rare for traditional high-level languages ⚫ Significant comeback with some Web scripting

languages (e.g., JavaScript, PHP)

20

Interpretation Process

19 20 Source program Interpreter Results

/Input

data

slide-11
SLIDE 11

CSC 1800 11

21

PARADIGM EXAMPLES

22

How Many Languages?

⚫ There are over 700 programming languages that were

developed and used enough to be recognized

⚫ How many languages should you know? ⚫ Good to know:

HTML, CSS, JavaScript, Java, C, C++, C#, Python, PHP, Perl, Swift, Go, R, TypeScript, Shell, PowerShell, Batch, SQL, MATLAB, Ruby, Groovy, Scala, Haskell, Fortran, COBOL

21 22

slide-12
SLIDE 12

CSC 1800 12

23

Factorial

⚫ A factorial of N! an integer N is the product of all

integers from 1 to N

⚫ For example:

24

Imperative Languages - C

⚫ Example: a factorial function in C ⚫ Hallmarks of imperative languages:

Assignment

Iteration

Order of execution is critical

Fast, maps easily to hardware instructions

int fact(int n) { int sofar = 1; while (n>0) sofar *= n--; return sofar; }

23 24

n! = n x (n - 1) x (n - 2) x (n - 3) x · · · x 3 x 2 x 1

5! = 5 X 4 X 3 X 2 X 1 = 120

slide-13
SLIDE 13

CSC 1800 13

25

Functional Languages - ML

⚫ Example: a factorial function in ML ⚫ Hallmarks of functional languages:

Single-valued variables

Heavy use of recursion

fun fact x = if x <= 0 then 1 else x * fact(x-1);

26

Functional Languages - Lisp

⚫ Example: a factorial function in Lisp ⚫ Looks very different from ML ⚫ But ML and Lisp are closely related

Single-valued variables: no assignment

Heavy use of recursion: no iteration

(defun fact (x) (if (<= x 0) 1 (* x (fact (- x 1)))))

25 26

slide-14
SLIDE 14

CSC 1800 14

27

Logic Languages - Prolog

⚫ Example: a factorial function in Prolog ⚫ Hallmark of logic languages

Program expressed as rules in formal logic

Also known as "Declarative" languages

fact(X,1) :- X =:= 1. fact(X,Fact) :- X > 1, NewX is X - 1, fact(NewX,NF), Fact is X * NF.

28

Object Oriented Languages - Java

⚫ Objects are when you attach the code as close as you

can to the data it manipulates

⚫ Paradigm can be considered imperative but data-

centered.

⚫ Simple Example: a Java definition for a kind of object

that can store an integer and compute its factorial

27 28

slide-15
SLIDE 15

CSC 1800 15

29

Object Oriented Languages - Java

public class Factorial { public Factorial() { } public int fact(int n) { int sofar = 1; while (n > 1) sofar *= n--; return sofar; } public static void main(String[] args) { int f = (new Factorial()).fact(5); System.out.println("result: " + f); } }

30

Which paradigm? - Forth

⚫ Example: a factorial function in Forth ⚫ A stack-oriented language

Postscript is similar

Could be called imperative, but has little in common with most imperative languages

: FACTORIAL 1 SWAP BEGIN ?DUP WHILE TUCK * SWAP 1- REPEAT ; 29 30

slide-16
SLIDE 16

CSC 1800 16

31

Which paradigm? - APL

⚫ Example: a factorial function in APL ⚫ An APL expression that computes X’s factorial

Expands X it into a vector of the integers 1..X, then multiplies them all together

(You would not really do it that way in APL, since there is a predefined factorial operator: !X)

Could be called functional, but has little in common with most functional languages

   X

32

DEFINING LANGUAGES

31 32

slide-17
SLIDE 17

CSC 1800 17

33

Language Partisans

⚫ Be aware… ⚫ There is a lot of argument about the relative merits of

different languages

⚫ Every language has partisans, who praise it in extreme

terms and defend it against all detractors

⚫ All languages (programming and otherwise) EVOLVE!

34

Language Standards

⚫ The documents that define language standards are

  • ften drafted by international committees

⚫ Can be a slow, complicated and rancorous process ⚫ Not many languages preserve backward compatibility

  • ver the long-term

33 34

slide-18
SLIDE 18

CSC 1800 18

35

Tricky Terminology

⚫ Some terms refer to fuzzy concepts: all those language

family names, for example

⚫ No problem; just remember they are fuzzy ⚫ Bad: Is X really an object-oriented language? ⚫ Good: What aspects of X support an object-oriented

style of programming?

⚫ Some specific concepts have conflicting terminology:

  • ne person’s argument is another person’s actual

parameter

36

Widely Used - Java

⚫ Quick rise to popularity since 1995 release ⚫ Java uses many ideas from C++, plus some from Mesa,

Modula, and other languages

⚫ C++ uses most of C and extends it with ideas from

Simula 67, Ada, Clu, ML and Algol 68

⚫ C was derived from B, which was derived from BCPL,

which was derived from CPL, which was derived from Algol 60

35 36

slide-19
SLIDE 19

CSC 1800 19

37

Not Widely Used - Algol

⚫ One of the earliest languages: Algol 58,

Algol 60, Algol 68

⚫ Never widely used ⚫ Introduced many ideas that were used in later

languages, including

– Block structure and scope – Recursive functions – Parameter passing by value

38

Language Dialects

⚫ Experience with languages reveals their design

weaknesses and leads to new dialects

⚫ New ideas pass into new dialects of old

languages

37 38

slide-20
SLIDE 20

CSC 1800 20

39

Language Dialects - FORTRAN

⚫ FORTRAN – FORmula TRANslation

Original Fortran, IBM Major standards:

− Fortran II − Fortran III − Fortran IV − Fortran 66 − Fortran 77 − Fortran 90 − Fortran 95 − Fortran 2003 − Fortran 2008?

Deviations in each implementation Parallel processing

− HPF − Fortran M − Vienna Fortran

And many more…

40

Connection to Programming Practice

⚫ Languages influence programming practice

– A language favors a particular programming style — a

particular approach to algorithmic problem-solving ⚫ Programming experience influences language

design and programming style

– Object-oriented languages: a style making heavy use of

  • bjects

– Functional languages: a style using many small side-

effect-free functions

– Logic languages: a style using searches in a logically-

defined problem space

39 40

slide-21
SLIDE 21

CSC 1800 21

41

Don’t Fight the Style

⚫ Languages favor a particular style, but do not

force the programmer to follow it

⚫ It is always possible to write in a style not

favored by the language

⚫ It is not usually a good idea…

42

Imperative ML

⚫ ML makes it hard to use assignment and side-effects.

But it is still possible: fun fact n = let val i = ref 1; val xn = ref n in while !xn>1 do ( i := !i * !xn; xn := !xn - 1 ); !i end;

41 42

slide-22
SLIDE 22

CSC 1800 22

43

Non-object-oriented Java

⚫ Java, more than C++, tries to force you to adopt an

  • bject-oriented mode. But you can still put your whole

program into static methods of a single class: class JustWhy { public static void main (String[] args) { // whole program here! } }

44

Functional Pascal

⚫ Any imperative language that supports recursion can be

used as a functional language:

function ForLoop(Low, High: Integer): Boolean; begin if Low <= High then begin {for-loop body here} ForLoop := ForLoop(Low+1, High) end else ForLoop := True end; 43 44

slide-23
SLIDE 23

CSC 1800 23

45

Other Connections

⚫ Computer Architecture

Language design is driven by available computer hardware

Stack based, parallel computing, Internet based ⚫ Theory of Formal Languages

Regular grammars, finite-state automata – lexical structure of programming languages, scanner in a compiler

Context-free grammars, pushdown automata – phrase-level structure

  • f programming languages, parser in a compiler

⚫ Turing Equivalence

Languages have different strengths, but fundamentally they all have the same power

Idea: Anything that you can compute in one programing language, you can compute in any other

46

What Did We Learn?

⚫ Many languages and reasons to learn them ⚫ Compiled vs. interpreted vs. hybrid ⚫ Paradigms: imperative, functional, logic, object-oriented ⚫ Lots of paradigm overlap ⚫ Languages are influenced by computer architecture,

domains, intended use, formal language theory

⚫ Languages each have things they do well and less well ⚫ First Examples:

C, ML, Lisp, Prolog, Java, Forth, APL, Pascal

45 46