mpl - Click to edit Master subtitle style Chapter One...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Click to edit Master subtitle style Chapter One Modern Programming Languages, 2nd ed. Programming Languages Chapter One Modern Programming Languages 11 Chapter One Modern Programming Languages Outline What makes programming languages an interesting subject? The amazing variety The odd controversies The intriguing evolution The connection to programming practice The many other connections Chapter One Modern Programming Languages, 2nd ed. 22 Chapter One Modern Programming Languages The Amazing Variety There are very many, very different languages (A list that used to be posted occasionally on comp.lang.misc had over 2300 published languages in 1995) Often grouped into four families: Imperative Functional Logic Object-oriented Chapter One Modern Programming Languages 33 Chapter One Modern Programming Languages Imperative Languages Example: a factorial function in C Hallmarks of imperative languages: Assignment Iteration Order of execution is critical Chapter One Modern Programming Languages 44 int fact(int n) { int sofar = 1; while (n>0) sofar *= n--; return sofar; } Chapter One Modern Programming Languages Functional Languages Example: a factorial function in ML Hallmarks of functional languages: Single-valued variables Heavy use of recursion Chapter One Modern Programming Languages 55 fun fact x = if x <= 0 then 1 else x * fact(x-1); Chapter One Modern Programming Languages Another Functional Language 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 Chapter One Modern Programming Languages 66 (defun fact (x) (if (<= x 0) 1 (* x (fact (- x 1))))) Chapter One Modern Programming Languages Logic Languages Example: a factorial function in Prolog Hallmark of logic languages Program expressed as rules in formal logic Chapter One Modern Programming Languages 77 fact(X,1) :- X =:= 1. fact(X,Fact) :- X > 1, NewX is X - 1, fact(NewX,NF), Fact is X * NF. Chapter One Modern Programming Languages Object-Oriented Languages Example: a Java definition for a kind of object that can store an integer and compute its factorial Chapter One Modern Programming Languages 88 Chapter One Modern Programming Languages Chapter One Modern Programming Languages 99 public class MyInt { private int value; public MyInt(int value) { this.value = value; } public int getValue() { return value; } public MyInt getFact() { return new MyInt(fact(value)); } private int fact(int n) { int sofar = 1; while (n > 1) sofar *= n--; return sofar; } } Chapter One Modern Programming Languages Object-Oriented Languages Hallmarks of object-oriented languages: Usually imperative, plus Constructs to help programmers use objectslittle bundles of data that know how to do things to themselves Chapter One Modern Programming Languages 1010 Chapter One...
View Full Document

This note was uploaded on 09/30/2011 for the course CS 6371 taught by Professor Hamlen during the Spring '11 term at University of Texas at Dallas, Richardson.

Page1 / 39

mpl - Click to edit Master subtitle style Chapter One...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online