<<

Trends in Design Professor Alfred V. Aho Department of Computer Science Overview Columbia University – The most influential languages Trends in – Trends in language design Programming Language Design – Design issues in the AWK programming language

16 October 2002

1 Al Aho 2 Al Aho

The Most Influential Programming The Most Influential Programming Languages of All Time Languages of All Time

• Assembler • Fortran – 1950s – 1950s – Step up from machine language – Created by a team led by of IBM – Available on virtually every machine – Initial focus: scientific computing – Influenced FI, FII, FIV, F77, F90, HPF, F95

3 Al Aho 4 Al Aho

The Most Influential Programming The Most Influential Programming Languages of All Time Languages of All Time

• Cobol • Lisp – 1950s – 1950s – Created by U.S. DOD – Created by John McCarthy – Grace Murray Hopper influential in initial – Initial focus: symbol processing development – Influenced Scheme, Common Lisp, MacLisp, – Initial focus: business data processing Interlisp – Influenced C68, C74, C85, PL/1 – Dominant language for programming AI applications – The world’s most popular programming language for many years until the early 1990s

5 Al Aho 6 Al Aho The Most Influential Programming The Most Influential Programming Languages of All Time Languages of All Time

• Algol 60 • Basic – 1960 – Early 1960s – Algol 60 Report introduced BNF as a notation for – Created by John Kemeny and Thomaz Kurtz of describing the syntax of a language Dartmouth – Initial focus: general purpose programming – Initial focus: a simple, easy-to-use imperative – First -structured language language – Influenced Algol 68, Pascal, Modula, Modula 2, – Influenced dozens of dialects, most notably Visual Oberon, Modula 3 Basic, probably the world’s most popular – Revised Algol 60 Report: P. Naur, J. Backus, F. programming language today Bauer, J. Green, . Katz, J. McCarthy, A. Perlis, H. Rutishauer, K. Samelson, . Vauquois, J. Wegstein, A. van Wijngaarden, M. Woodger

7 Al Aho 8 Al Aho

The Most Influential Programming The Most Influential Programming Languages of All Time Languages of All Time

67 • C – 1967 – 1970s – Created by Ole-Johan Dahl, Bjorn Myhrhaug and – C was created by Dennis Ritchie at Bell Labs initially at the Norwegian Computing as a systems programming language for Centre, Olso implementing UNIX – Algol 60 with classes and coroutines – C++ was created by Bjarne Stroustrup at Bell Labs in – First object-oriented programming language the 1980s adding object orientation to C – Designed for discrete-event simulation – Influenced ANSI C, Java – Influenced C++, Smalltalk, Java – C/C++ has become the world’s most widely used systems programming language

9 Al Aho 10 Al Aho

The Most Influential Programming The Most Influential Programming Languages of All Time Languages of All Time

• ML • Scripting Languages – 1970s – Typeless languages for “glue programming” – Created by Robin Milner at – awk – Initial focus: meta-language for program verification – perl – One of the most widely used functional – sh programming languages – tkl – Influenced Standard ML, Miranda, Haskell – many more

11 Al Aho 12 Al Aho Other Influential Languages Contemporary Issues in Language Design

• Simplicity and expressiveness for productivity • ADA • PL/1 • Robustness, safety and security • Architecturally neutral and portable • APL • Postscript • Internet savvy • C# • • Concurrency • Performance • HTML • SQL • Object orientation • Interoperability • Java • Visicalc

13 Al Aho 14 Al Aho

Overview of Awk Awk Program

From The AWK Programming Language, by Alfred V. • Format of an awk program Aho, Brian W. Kernighan and Peter J. Weinberger, pattern { action } Addison Wesley, 1988 pattern { action } … pattern { aciton } “Awk is a convenient and expressive programming language that can be applied to a wide variety of common computing and data-processing tasks.” • Execution model repeatedly read input line apply patterns for each pattern that matches execute associated action

15 Al Aho 16 Al Aho

Example How much did each person earn during their shift?

Data file Name Hours-worked Hourly-rate Bob 5 10 Stephen 0 8 Name Hours-worked Hourly-rate Susan 10 15 Bob 5 10 Bob 6.5 11 Stephen 0 8 Susan 10 15 Command line Bob 6.5 11 awk ‘$2 > 0 { print $1, $2 * $3 }’ data

Awk output Bob 50 Susan 150 Bob 71.5

17 Al Aho 18 Al Aho How many hours did Bob work? What are everyone’s wages?

Name Hours-worked Hourly-rate Name Hours-worked Hourly-rate Bob 5 10 Bob 5 10 Stephen 0 8 Stephen 0 8 Susan 10 15 Susan 10 15 Bob 6.5 11 Bob 6.5 11 Awk program { wages[$1] += $2 * $3 } Awk program END { for (emp in wages) $1 ~ /Bob/ { hw += $2 } print emp “ earned $” wages[emp] } END { print “Bob worked “ hw “ hours” } Awk output Stephen earned $0 Awk output Bob earned $121.5 Susan earned $150 Bob worked 11.5 hours

19 Al Aho 20 Al Aho

What are everyone’s wages, sorted by Awk Patterns name?

Name Hours-worked Hourly-rate • BEGIN Bob 5 10 • END Stephen 0 8 Susan 10 15 • Expression Bob 6.5 11 • Regular expression Awk program • Compound pattern { wages[$1] += $2 * $3 } END { for (emp in wages) • Range pattern print emp “ earned $” wages[emp] | “sort” } Awk output Bob earned $121.5 Stephen earned $0 Susan earned $150

21 Al Aho 22 Al Aho

Awk Actions Some useful awk “one-liners”

• expressions • Print the total number of input lines •print/printf END { print NR } •if ( expression ) statement • Print every line longer than 80 characters length($0) > 80 •if ( expression ) statement else statement • Print the last field of every input line •while ( expression ) statement { print $NF } •for( expression ; expression ; expression ) statement • Print the first two fields, in opposite order, of every line •for( variable in array ) statement { print $2, $1 } •do statement while ( expression ) • Print in reverse order the fields of every line •break/continue/next/exit/exit expression { for ( i = NF; i > 0; i = i-1 ) printf(“%s “, $I) •{ statements } printf(“\n”) }

23 Al Aho 24 Al Aho