Lecture 2

Influences on language design

  • the von Neumann architecture influenced the creation of imperative languages; see p. 19 of Sebesta
  • programming methodologies
    • structured programming from the 1970s emphasized the use of functions and loops, and de-emphasized the use of goto (i.e. jumping to arbitrary lines of code in a program)
    • object-oriented programming (OOP) through the 1980s and onwards encourages the use of objects as a way to group data and related functions

Basic implementation issues

  • see Sebesta p. 25 diagram

  • compiling versus interpreting and things in between

  • compiling: converts source code to machine code in a multi-step process; done before program is run; see Sebesta p. 26 diagram

  • interpreting: convert lines of source code to machine code as the programs run

  • compilers tend to produce faster running programs than interpreters because the they convert the source code to machine code before the program runs; interpreters intertwine translation and execution and so are inherently doing more in most cases

  • interpreters are typically much easier to write and use than compilers, and are often better for debugging

  • interpreters allow for fast, interactive computation, such as evaluating single statements, that is hard to simulate efficiently in a compiler

  • hybrid compilers/interpreters can be written that try to get the benefits of both compilers and interpreters

    • languages such as Perl, Python, and Java are hybrid interpreted/compiled languages

    • e.g. Python source code is converted to a special Python bytecode that looks like machine language; this bytecode is then run by interpreter; for instance:

      >>> import dis
      >>> def triple(x): return 3 * x
      ...
      >>> dis.dis(triple)
        1           0 LOAD_CONST               1 (3)
                    3 LOAD_FAST                0 (x)
                    6 BINARY_MULTIPLY
                    7 RETURN_VALUE
      
    • a just-in-time compiler (JIT) is a program that converts an intermediate language to machine code before a program runs; languages such as Java and C# use JITs

Some language history

  • Konrad Zuse designed Plankalkul in 1945/46, and it seems to be the first programming language in the sense that it was a formal language designed explicitly for writing programs on a computer (it was not implemented until the 1990s)

  • FORTRAN, which stands for FORmula TRANslating System, was available in 1957 and proved extremely popular, going through many revisions throughout its life. Developed by an IBM team lead by John Backus, FORTRAN is still in use today, notably in scientific applications.

    See p.46 of Sebesta for some sample FORTRAN code.

  • Lisp was developed by AI pioneer John McCarthy, and is based on a mathematical formalism called the lambda calculus.

    Lisp stands for LISt Processing, and singly-linked lists are traditionally its main data structure (in contrast to arrays, which are the main data structures of languages like FORTRAN).

    Interestingly, Lisp source code is itself written as lists, and so it is relatively easy to write programs the process Lisp programs.

    Lisp is also important because it is perhaps the first implementation of functional programming. The idea of functional programming is, very roughly, to avoid the use of explicit loops and assignment statements, and instead rely on recursion and so-called higher-order functions (i.e. functions that take functions as input).

    In practice Lisp is not purely functional, although it can be used that way.

    Lisp has many dialects. Recent popular Lisp dialects include Scheme, Clojure, and Common Lisp.

    Here is a sample Lisp function:

    (defun factorial (n)
      (if (<= n 1)
          1
          (* n (factorial (- n 1)))))
    

    Note that Lisp uses prefix notation, e.g. (<= n 1) is written as n <= 1 in many other languages. Getting used to prefix notation is one of the challenges of learning Lisp.

    Functional programming has become more popular in recent years, especially in languages such as Haskell, ML, and even JavaScript. Many of its basic ideas where first seen in Lisp.

  • ALGOL is important family of languages that were designed by a committee of computer scientists. Many of the ideas we consider to be basic features of programming languages were defined and clarified by ALGOL.

  • COBOL was one of the first languages designed explicitly for use in business. It was immensely successful, and is still in use today.

    See p. 61 of Sebesta for some sample COBOL code.

  • SIMULA 67 is important for being the language that implemented most of the basic ideas of object-oriented programming, including classes, objects, inheritance, and virtual functions. It influenced the design of some later OOP languages, notably C++.

    Smalltalk, developed in the 1970s by Alan Kay, is generally considered to be the language that made OOP popular. Essentially everything in SmallTalk is an object, and it was the first language to make extensive use of now common object-oriented design patterns.

  • Pascal was a once popular language designed by Niklaus Wirth. It was, for instance, commonly used as a teaching language in the 1980s.

  • C is an extremely influential language developed in 1972 at Bell Labs by Dennis Ritchie. It was created largely to implement the Unix operating system, and so is a systems language the emphasizes speed and flexibility. Many aspects of its syntax have been copied by later languages.

    C++ was originally developed in the early 1980s as a cross between C and SIMULA.

  • Prolog is an interesting language developed in the 1970s. It is sometimes taken by the exemplar of a style of programming called logic programming, although logic programming has not yet caught on. Most programmers find it to be a radically different way of thinking about programs, and it is often used in AI thanks to its built-in backtracking capabilities.

  • Java was developed in the 1990s in part as a response to the frustration of using C++. Its syntax is similar to C++, but beyond that it is a substantially different language. Notably, Java was one of the first mainstream programming languages to rely on an automated garbage collector to free unused memory.

  • the Python language was developed in the early 1990s by Guido van Rossum for use as a general- purpose scripting language. It has proven to be immensely popular due to its good readability and writability, plus its focus on using a small number of highly optimized data structures (tuples, list, and dictionaries).

    A couple of other popular scripting languages that share the same spirit as Python are Ruby and Lua.