Wecome - CSC 301 CSC 301- Foundations of Programming Languages Instructor: Dr. Lutz Hame Emai: hame@cs.uri.edu Office: Tyer, Rm 251 Office Hours: TBA TA: TBA
Assignments Assignment #0: Downoad & Read Syabus upoad a copy of it into Sakai
Why Study Programming Languages? Amazing variety One of the moderated emai ists counted ~2300 different programming anguages (comp.ang.*) Strange controversies Shoud a programming anguage have a goto statement? Shoud an OO anguage aow for goba functions? Terminoogy: argument vs. actua parameter. Many connections Programming anguages touch upon virtuay a areas of computer science: from the mathematica theory of forma anguages and automata to the impementation of operating systems. Intriguing evoution Programming anguages change! New ideas and experiences trigger new anguages. New anguages trigger new ideas, etc.
Programming Language Casses There are many different programming anguage casses, but four casses or paradigms stand out: Imperative Languages Functiona Languages Logic/Rue Based Languages Object-Oriented Languages
Exampe Computation Recursive definition of the factoria operator x!= # 1 if x =1, $ % x(x 1)! otherwise. for a x > 0.
Imperative Languages Hamarks: assignment and iteration Exampes: C, FORTRAN, COBOL Exampe Program: factoria program in C int fact(int n) { int sofar; sofar = 1; whie (n > 1) { iteration } sofar = sofar*n; n--; } return sofar; assignment
Imperative Languages Observations: The program text determines the order of execution of the statements. We have the notion of a current vaue of a variabe accessibe state of variabe. This is not aways true in other anguages.
Functiona Languages Hamarks: recursion and singe vaued variabes. Exampes: ML, Lisp, Haske Exampe Program: factoria program in ML fun fact x = if x = 1 then 1 ese x*fact(x-1); recursion
Functiona Languages Observations: There are no expicit assignments. The name stems from the fact that programs consist of recursive definitions of functions.
Logic Programming Languages Hamarks: programs consist of rues that specify the probem soution. Exampes: Proog, Maude Exampe Program: factoria program written in Proog rues fact(1,1). fact(x,f) :- X > 1, X1 is X-1, fact(x1,f1), F is X*F1. and fact(in,out) assignment
Logic Programming Languages Observations: Rues do not appear in the order of execution in the program text. No specific order of execution is given rues fire when necessary.
Object-Oriented Languages Hamarks: bunde data with the aowed operations F Objects Exampes: Java, C++, Smatak Exampe Program: factoria program in Java data aowed operations cass FactInt { private int va; pubic FactInt(int x) { va = fact(x); } pubic int getva() { return va; } } Pubic operations private int fact(int n) { int sofar = 1; whie (n>1) { sofar = sofar*n; n--; } return sofar; } Operation ony aowed by the object itsef (or subobjects)
Programming Language Casses Genera Observations: Programming anguages guide programmers towards a particuar programming stye: Functiona mathematica functions OO objects Logic rues Programming itsef guides the deveoper towards new anguage ideas: Recursion was introduced by John McCarthy in the 1950 s with the programming anguage Lisp to sove probems in AI. Casses and objects were deveoped by Nygaard and Dah in the 1960 s and 70 s for the anguage Simua in order to sove probem in simuations.
Take Away There exist many programming anguages today (> 2000) In order to understand the simiarities and differences Þ sort into casses Imperative assignment and iteration Functiona Recursion, singe vaued variabes Logic/rue based programs consist of rues Object-oriented bunde data with the aowed operations
Assignments Read Chapters 1&2