320 likes | 335 Views
Learn various programming languages, compare paradigms, and explore language history. Submit assignments using VMware Workstation.
E N D
COMP 205Survey of Computer Languages Dr. Chunbo Chu
About me • Lead Faculty in Computer Science • Education in Computer Science • BS (1997) • MS (2000) • PhD (2008) • Specialty and Interests • Distributed Systems, Networking, CS Education
About COMP205 • Overview of the concepts and practice with several programming languages • The Syllabus
Error in gradebook • Assignment 13-2 :Working with Prolog is missing • 25 points
About COMP205 • Structure • Module 1 (week 1)Introduction to Programming Languages: HTML/XML/XSLT • Module 2 (week 2-6)Markup and Scripting Languages: JavaScript/PHP • Module 3 (week 7-8) Scripting Languages: Perl, Ruby • Midterm (week 8) • Module 4 (week 9-10) Microsoft .Net and C# • Module 5 (week 11-14) Non-Imperative Languages: Lisp, Prolog • Final (week 15)
About COMP205 • Outcomes • Write simple programs in a variety of languages • HTML/XML/XSLT • JavaScript/PHP • Perl/Ruby • MS .Net/C# • Lisp/Prolog • Compare and contrast language paradigms (imperative, functional, declarative). • Demonstrate the ability to move between programming languages.
About COMP205 • Virtual Machine DVD • VMware Workstation: desktop-based virtualization program that permits a guest operating system to run as an application under your host operating system. • Virtual Machine for COM205 • Submit your assignment in Drop Box • Turnitin.com • class: COMP205 V1FF Summer 2009 • class ID: 2711966 • enrollment password: COMP205Su09
Module 1 • Outcomes: • Describe language paradigms. • Explore the history of programming languages. • Examine the general features of programming languages.
Computer languages • A notational system for describing computation in machine-readable and human-readable form • Machine-readable: the existence of a (more or less) linear-time translation algorithm; the syntax must be given by a context-free grammar. • Computation Described by a Turing Machine - a very simple computer that can carry out all known computations
Language Paradigms • Imperative • traditional sequential programming (passive data, active control). Characterized by variables, assignment, and loops. • Procedural: • Object-oriented: data-centric, data controls its own use, action by request to data objects. Characterized by messages, instance variables, and protection.
Language Paradigms • Declarative • Logic and functional paradigms share this property: state “what” needs computing, not “how” (sequence). • Functional: passive data, but no sequential control; all action by function evaluation (“call”), particularly recursion. No variables! • Logic: assertions are the basic data; logic inference the basic control. Again, no sequential operation. • Parallel • well, maybe not really a paradigm, but some think so. Again, no sequential operation. • … …
K. Louden, Programming Languages Examples in three languages (Euclid’s gcd algorithm):Compute the greatest common divisor of two integers input by the user, and print the result. For example, the gcd of 15 and 10 is 5.
K. Louden, Programming Languages C: #include <stdio.h> int gcd(int u, int v) /* “functional” version */ { if (v == 0) return u; else return gcd (v, u % v); /* “tail” recursion */ } main() /* I/O driver */ { int x, y; printf("Input two integers:\n"); scanf("%d%d",&x,&y); printf("The gcd of %d and %d is %d\n", x,y,gcd(x,y)); return 0; }
K. Louden, Programming Languages Java: import java.io.*; class IntWithGcd { public IntWithGcd( int val ) { value = val; } public int getValue() { return value; } public int gcd ( int v ) { int z = value; /* “imperative” version */ int y = v; while ( y != 0 ) { int t = y; y = z % y; z = t; } return z; } private int value; }
K. Louden, Programming Languages Java (continued): class GcdProg /* driver */ { public static void main (String args[]) { System.out.println("Input two integers:"); BufferedReader in = new BufferedReader( new InputStreamReader(System.in)); try /* must handle I/O exceptions */ { IntWithGcd x = /* create an object */ new IntWithGcd(Integer.parseInt(in.readLine())); int y = Integer.parseInt(in.readLine()); System.out.print("The gcd of " + x.getValue() + " and " + y + " is "); System.out.println(x.gcd(y)); } catch ( Exception e) { System.out.println(e); System.exit(1); } } }
K. Louden, Programming Languages Scheme: (define (gcd u v) (if (= v 0) u (gcd v (modulo u v))))
K. Louden, Programming Languages Scheme: (define (euclid) ; sequential! (display "enter two integers:") (newline) ; goes to next line on screen (let ((u (read)) (v (read))) (display "the gcd of ") (display u) (display " and ") (display v) (display " is ") (display (gcd u v)) (newline)))
K. Louden, Programming Languages Paradigm use is rarely "pure” • The C program defined the gcd function in a purely functional style, even though C is mainly imperative. • The Java program used some imperative code to compute the gcd, and was not completely object-oriented (integers aren’t objects). • The Scheme code used sequencing to do I/O, an imperative feature.
K. Louden, Programming Languages Examples of languages that are pure (mostly): • Imperative: (old) FORTRAN • Functional: Haskell • Object-oriented: Smalltalk
Evaluation Criteria • Usability: how easy it is to read, write, and change programs • Support for abstraction: the ability to define and then use complicated structures or operations in ways that allow many of the details to be ignored. • Orthogonality: components are independent of each other and they behave in the same way in any circumstance. • Reliability: behaves as advertised and produces results the software engineer expects
Evaluation Criteria • Efficiency: it can produce programs that are consistent with system specifications • Portability: if the source code can be moved from one platform to another without modification. • Cost: availability of software engineers who know the language, usability, reliability, efficiency, and portability.
Language Discussion • Create a list of the languages you know • Group them into: • Interactive • Compiled • Paradigm • Old • New
K. Louden, Programming Languages Language definition • Syntax: the structure of a program. Usually given a formal (i.e., mathematical) definition using a context-free language. (Lexical structure - the structure of the words or tokens - uses regular expressions.) • Semantics: the actual result of execution. Usually described in English, but can be done mathematically. • Semantics can have a static component: type checking, definition checking, other consistency checks prior to execution.
K. Louden, Programming Languages Syntax • Syntax is the structure of a language, i.e., the form that each program or source code file must take. • Since the early 1960s, syntax has been given as a set of grammar rules in a form developed by Noam Chomsky, John Backus, and Peter Naur. (Context-free grammar, Backus Naur Form [BNF].) • Syntax includes the definition of the words, or tokens, of the language, which can be called its lexical structure. • Both lexical and syntactic structure have precise mathematical definitions that every computer scientist should know.
Grammar and BNF <program> -> begin <stmts> end <stmts> -> <stmt> | <stmt> ; <stmts> <stmt>-><var> = <expr> <var> ->a | b | c | d <expr> -><term> + <term> | <term> - <term> | <term> <term> -> <var> | const begin a = a + c end
K. Louden, Programming Languages Language translation • Compiler: two-step process that translates source code into target code; then the user executes the target code. • Interpreter: one-step process in which the source code is executed directly. • Hybrids are also possible (Java).
K. Louden, Programming Languages Error classification • Lexical: character-level error, such as illegal character (hard to distinguish from syntax). • Syntax: error in structure (e.g., missing semicolon or keyword). • Static semantic: non-syntax error prior to execution (e.g., undefined vars, type errors). • Dynamic semantic: non-syntax error during execution (e.g., division by 0). • Logic: programmer error, program not at fault.
K. Louden, Programming Languages Attributes • Properties of language entities, especially identifiers used in a program. • Important examples: • Value of an expression • Data type of an identifier • Maximum number of digits in an integer • Location of a variable • Code body of a function or method
Attributes • Declarations ("definitions") bind attributes to identifiers. • Different declarations may bind the same identifier to different sets of attributes.
K. Louden, Programming Languages Binding times can vary widely: • Value of an expression: during execution or during translation (constant expression). • Data type of an identifier: translation time (Java) or execution time (Smalltalk, Lisp). • Maximum number of digits in an integer: language definition time or language implementation time. • Location of a variable: load or execution time. • Code body of a function or method: translation time or link time or execution time.
New Assignments • Assignment 1-1: Survey of Languages • Assignment 1-2: Programming Language History Paper • Turnitin.com • Drop box