Title: Introduction to Programming Language Concepts
1Introduction to Programming Language Concepts
2What is this course about?
- Teaches students about the underlying concepts
behind all programming languages - Uses a variety of languages to illustrate the
concepts - Ada
- C
- C
- Java
- Lisp
- Mathematica
- ML
- Pascal
- Prolog
- Scheme
3Who Cares?
- Programmers
- Ease of programming
- Productivity
- Maintainability
- Readability
- Language Designers
- Lexical structure
- Syntax
- Semantics
- Compiler Writers
- Portability
- Performance
4Course Goals
- After taking this course a student should be able
to - Quickly learn new programming languages
- Select appropriate languages for solving specific
problems - Write more efficient and readable programs
- Solve problems that they could not previously
solve - connection between languages skills and
high-level problem solving
5What is a Programming Language
- Natural-language refers to a human language
- Used by humans
- A system of symbols used to communicate
- English, Spanish, French, Arabic, Tamil, etc
- Programming languages
- Used by computers (and programmers)
- A way of thinking
- Definition
- A programming language is a system of notations
used to specify, organize, and reason about
computation
6Historical Overview
7A Brief History
- Assembly
- A common low-level language used prior to any
higher-level language was developed - Only low-level operations supported
- Copy values from memory locations
- Basic mathematical operations
- Basic logical operations
an X86 assembly program dosseg .model small
.stack 100h .data hello_message db 'Hello,
World!',0dh,0ah,'' .code main proc mov
ax,_at_data mov ds,ax mov ah,9 mov
dx,offset hello_message int 21h mov
ax,4C00h int 21h main endp end main
8Sample Fortran Code
- C Fortran 90 Example Program
- C Input An integer LIST_LEN less than 100
followed by - C LIST_LEN integer values
- C Output The number of input values that are
greater than - C the average of all the input values
- INTEGER INTLIST(99)
- INTEGER LIST_LEN, COUNTER, SUM, AVERAGE,
RESULT - RESULT 0
- SUM 0
- READ , LIST_LEN
- IF ((LIST_LEN .GT. 0) .AND. (LIST_LEN
.LT. 100)) THEN - DO 10 COUNTER 1, LIST_LEN
- READ , INTLIST(COUNTER)
- SUM SUM INTLIST(COUNTER)
- CONTINUE
- AVERAGE SUM / LIST_LEN
- DO 20 COUNTER 1, LIST_LEN
- IF(INTLIST(COUNTER) .GT. AVERAGE)
THEN - RESULT RESULT 1
9Example Lisp Code
- (defun sum (alist)
- (reduce alist))
- (defun average (alist)
- (/ (sum alist) (length alist))
- counts the number of items greater than the
- average value in the list
- (defun greater-than-average (alist)
- (length
- (remove NIL (map list
- (lambda (x) (gt x (average
alist))) alist))))
10Algol Example Code
- comment ALGOL 60 program
- Input An integer, listlen, where listlen is
less than 100, - followed by listlen-integer values
- Output the number of input values that are
greater than - the average of all the input values
- begin
- integer array intlist 199
- integer listlen, counter, sum, average, result
- sum 0
- result 0
- readint(listlen)
- if(listlen gt 0) (listlen lt 100) then
- begin
- for counter 1 step 1 until listlen do
- begin
- readint(intlistcounter)
- sum sum intlistcounter
- end
- average sum / listlen
11Cobol Example Code
- IDENTIFICATION DIVISION
- PROGRAM-ID. FACTORIAL
- ENVIRONMENT DIVISION
- CONFIGURATION SECTION.
- SOURCE COMPUTER. IBM-370-145.
- OBJECT COMPUTER. IBM-370-145.
- DATA DIVISION
- WORKING-STORAGE SECTION.
- 77 I PIC S9(9) COMP.
- LINKAGE SECTION
- 77 N PIC S9(9) COMP.
- 77 F PIC S9(9) COMP.
- PROCEDURE DIVISION USING N, F.
- MOVE 1 TO F.
- PERFORM S1 VARYING I FROM 1 BY 1 UNTIL I N
OR I gt N. - S1. COMPUTE F F I.
- S2. EXIT PROGRAM.
12BASIC Example Code
- REM QuickBasic example program
- REM Input An integer, listlen, where listlen is
less than 100 - REM followed by listlen integer values
- REM Output The number of input values that are
greater than the - REM average of all the input values
- DIM intlist(99)
- result 0
- sum 0
- INPUT listlen
- IF listlen gt 0 AND listlen lt 100 THEN
- FOR counter 1 TO listlen
- INPUT intlist(counter)
- sum sum intlist(counter)
- NEXT counter
- average sum/listlen
- FOR counter 1 TO listlen
- IF intlist(counter) gt average THEN
- result result 1
- NEXT counter
13C Example Code
- / C Example program
- Input An integer, listlen, where listlen is
less than 100 - followed by listlen-integer values
- Output The number of input values that are
greater than - the average of all the input values /
- void main()
- int intlist99, listlen, counter, sum,
average, result - sum 0
- result 0
- scanf(d, listlen)
- if((listlen gt 0) (listlen lt 100))
- for(counter 0 counter lt listlen
counter) - scanf(d, intlistcounter)
- sum sum intlistcounter
-
- average sum / listlen
- for(counter 0 counter lt listlen
counter) - if(intlistcounter gt average) result
- printf(Number of values gt average is
d\n, result)
14A Brief History
- Prolog (1972)
- Alain Colmerauer and Phillippe Roussel
- Established a new programming paradigm logic
programming - Used mostly for AI and some database applications
- Primary difficulty is efficiency
mother(joanne, jake). father(vern,
joanne). grandparent(X, Z) - parent(X,Y),
parent(Y,Z).
15A Brief History
- ADA (1977-1983)
- Requirements developed by committee
- Attempt to standardize software for use by DOD
- Phase 1 was developed independently by
- Softech, SRI International, Honeywell/Bull,
Intermetrics - Phase 2 was developed by
- Intermetrics, Honeywell/Bull
- Final winner was Honeywell/Bull (a French firm)
- Mil-Std 1815
- Features
- Generic packages
- Exception handling
- Concurrency
with Text_To use Text_To procedure hello is
begin put("Hello World") end hello
16Some Ways of Classifying Languages
- Low-level language
- Any language that is closer to machine
instructions - High-level language
- Any language that is closer to natural language
- Easier to read and understand
- Portable
17Some Ways of Classifying Languages (Low/High
Level)
Low Level close to machine language Non-portable
High Level close to a natural description
of an algorithm Easy to read and portable
18Low Level Example
- Machine Language Example (Pentium III Linux Box)
-
- 01111111 01000101
- 01001100 01000110
- 00000001 00000001
- 00000000 00000000
-
-
Can you understand this code?
19Intermediate Level Example
- Assembly Example (Pentium III Linux Box)
- .file hello.c
- .version 01.01
- .section .rodata
- .LCO
- .string Hello World\n
- .text
- .align 4
- .globl main
- .type main,_at_function
- main
- pushl ebp
- movl esp,ebp
- pushl .LCO
- call printf
- addl 4,esp
- xorl eax,eax
- jmp .L1
Can you understand this code?
20High Level Example
- C Language Example (machine independent)
- include ltstdio.hgt
- void main()
- printf(Hello World\n)
Can you understand this code?
21Some Ways of Classifying Languages(Programming
Paradigms)
- Imperative Programming
- A computation is viewed as a sequence of actions
(commands) - Fortran/C/Pascal/Basic
- Functional Programming
- Emphasizes functions (data-flow) over data
- Lisp/ML/Scheme
- Object Oriented Programming
- Emphasizes hierarchical organization of data and
methods - Encapsulation/Inheritance/Polymorphism
- Java/C/Smalltalk/CLOS
- Logic Programming
- Emphasizes logic as a means of specifying
computation - Prolog/Mathematica
- Event Driven
- Code is executed in response to generated events
- Java Swing, Visual Basic
- Concurrent
- Code is executed in a threaded fashion. Multiple
operations occur simultaneously - Java,Ada,Concurrent Pascal
22Classifying Languages(Compiled vs. Interpreted)
- Compilation
- The high-level language is brought down to the
level of the machine using a translator. The
translator is called a compiler.
- Interpretation
- The machine is brought up to the level of the
language by the use of a virtual machine built in
software. This machine is known as an
interpreter.
23Compiled vs. Interpreted
- Compiled
- Faster execution
- Smaller memory requirements
- Often more difficult to program
- Less flexible
- Fortran/C/Pascal/Java
- Interpreted
- Slower execution
- Larger memory requirements
- Often easier to program
- More flexible (run-time modification of programs
and data types) - Perl/Java/Tcl
24What is the Best Language?(Criteria for
language evaluation)
- Simplicity and Readability
- How easy is it to write/read a program?
- How easy is the language to learn/teach?
- C allows great expressiveness at expense of
readability - Pascal easy to learn but more keystrokes to
write - Binding
- Binding is the association of a property to a
language element - When does binding occur?
- When the language is defined? (3.5 ? double in C)
- At compilation? (1.5 ? IEEE 754)
- At run-time? (x 3.5 ? the value 3.5 is assigned
to x)
25Obfuscated C
include ltstdio.hgt char T"IeJKLMaYQCEjbZRskcS
ldUV\\X\\/_ltlt90!\"434-./2gts", K31000,F,
x,A,M2,J,r4,g,N,Y,Q,W,k,q,DX()r
r r3M1-(x1)rW,1,2Q2,1x1Y,g
((((x 7) -1)gtgt1)-1)?rrxgtgt3,(xltr)X()
E()AX(x0,g J ),x7(TgtgtA3),J(xF-W
-x)A7Qx3A(M)2
( x1),gJ((xk-W)A7)-A,g1(M)gMTA
,1 x1,x1,(A1)(E(),JW)l()
E(--ql () )B()JB((DJ,Q2ltD
Dltk1(g1
), !(D-WD-9D-10D-13)(!r(g0)
, r1)64ltDDlt91(r0,gD-63)
D gt 97Dlt123(r0,gD-9
5)!(D-k
3 )(r0,g12)Dgtk3Dltk
1 -1(r0,gD-47),J))j(
) putchar(A)b()(j(A(K)
D
W r2Yx),xltY)b()t
() (j((b(Dqg,x0),AW)
), qlt((r1)ltY?(r1)
Y) )t()R()(A(t(
q 0),'\n'),j(),r
2 ltN)R()O()
( j((r20,R(
)) ),r1-q)
O(g--q)
C()(
J gets
(K 1))C((B(gK2),r!(!r(g0)),(r)r
g-K2,gK2 ,r 1 O()) ) main ()C ((l( (
J( A0) K, AM (F (k( M!A (Q T( q(Y
(W 32)- (N4 )))) N) 2)7 )7) ),Y Nltlt( r! -
A)) )
This program is a simple filter that translates
ASCII text into semaphore code. It reads from
standard input and converts all alphanumeric
characters to their corresponding semaphore
codes. The codes themselves are written to
standard output as a depiction of a person
holding two flags, using only ASCII characters
(semaphore smileys, if you will).
Best Use of Flags Glyn Anderson Jl. Raya Serang
KM 18.2 Desa Bojong Cikupa, Tangerang, 15710
Indonesia
26What is the Best Language?(Criteria for
language evaluation)
- Orthogonality
- Does a symbol or word always mean the same thing?
- Are there a small number of operations that can
interact and combine in powerful, predictable
ways? - What does the sybol mean?
- a, a1, hi there, 3
- Applicability
- Does the language provide support for application
specific operations? - Matlab has support for vector/matrix operations
- Prolog has support for logical deduction
27What is the Best Language?(Criteria for
language evaluation)
- Abstraction
- Does the language support an appropriate level of
abstraction? - Machine languages support only numbers
- In Lisp, code and data are written at the same
level of abstraction - Efficiency
- Can the language be implemented? Can it be
implemented efficiently? - Algol 68 was elegantly designed but extremely
difficult to implement. Same with C (generic
types and exception handling)
28What is the Best Language?(Criteria for
language evaluation)
- Reliability does the program perform as desired
under all conditions? - Type checking automatic checking for type errors
either by the compiler or during run-time - Exception handling the ability of a program to
intercept run-time errors, take corrective
action, and continue - Aliasing can a programming have two names for
one object - Readability and Writability programs that are
difficult to read/write are more likely to be
incorrect - Famous Bugs
- 2000 Mars explorer is lost due to software bugs
in the navigational system - 1996 An Ariane 5 exploded 40 seconds after
launching due to software problem with the
inertial reference system - 1995 Opening of the Denver airport is delayed at
an estimated cost of 3.2 billion.
29What is the Best Language?
What is the problem to be solved????
Business Cobol, VBasic Artificial
Intelligence Lisp, Prolog Scientific Fortran,
(some C) Real-Time C, Assembler Large
Systems C Document Formatting/Layout Postscript
, LaTex
Internet Java, XML, HTML, Perl Verification
Systems Prolog Database C, Prolog,
SQL Experimentation ML, Lisp, Haskell Rapid
Prototyping Tcl/Tk, Perl, Delphi,
VBasic Distributed Computing IDL