Notes on Chapter 1

Why are there so many programming languages?

  • Wikipedia lists many programming languages (nowhere near all of them!)
  • languages evolve, features are added and removed, e.g. C++11 added the constrexpr feature, C++17 plans to remove autoptr and operator++ on bool
  • special purposes, e.g. Matlab is good for matrices, Perl is good for string processing, C is good for operating systems, Python is good for scripts, Processing is good for simple 2D graphics, ...
  • personal preference, e.g. some programmers prefer different programming styles

What makes a language successful?

  • expressive power
  • ease of use for beginners, e.g. Python is a good language for beginners; Go is easy for programmers to pick up
  • ease of implementation, e.g. LISP interpreters are relatively easy to implement and there are many implementations of it (contrast this to C++ which is exceedingly difficult to implement – but useful!)
  • standardization; open source
  • quality of tooling, e.g. compilers, debuggers, editors, etc.; Go has a reputation for some very good standard tools; JavaScript lives in an ecosystem of some great tools, such as IDEs, debuggers, runtime systems, libraries, etc.
  • economics and society, e.g. COBOL and Ada were made popular in large part due to adoption by the US Dept. of Defense; Objective-C/Swift are popular mostly do to their use by Apple on IOS platform

What kinds of languages have people made?

  • Functional languages are based on the mathematical notion of a function, e.g. LISP, Scheme, ML, Haskell, ...

    Functional programming has been around since the very beginning of computers, and but is still not quite mainstream. However, many practical and popular languages have borrowed ideas and techniques from functional programming, so they have certainly had an impact.

  • Logic/constraint-based languages are based on predicate logic, e.g. Prolog, SQL, XSLT, spreadsheets, ...

    Very roughly, this style of programming requires that the programmer describe their goal, i.e. the programmer specifies what they want. The language then automatically figures out how to achieve the goal. For example, in the SQL databse query language, a programmer can write a query that says “find all the employees who earn more than $100,000 a year”. They do not have to write a loop, they just write the query and SQL does the rest.

  • von Neumann languages are organized around modifying variables, e.g. C, Fortran, Ada, ...

    In practice, these are the most common and successful languages. But in theory, they present many complexities and imperfections that make them hard to reason about.

  • object-oriented languages support the creation and use of independent “objects” that have their own state, e.g. Simula 67, SmallTalk, Java, C++, ...

  • scripting languages are languages designed to “glue” together other programs, and so they emphasize ease-of-use, flexibility, and programmer time, e.g. Python, Ruby, Perl, ...

Many languages mix and match ideas from these basic categories. For example, Java and C++ both have support for functional, von Neumann, and object- oriented programming.

Why study programming languages?

  • programming languages are the basic tool for programming, and understanding them is both interesting and useful
  • programming languages have many intricate related parts and it is instructive to see how different languages implement and connect them
  • understanding issues in language design and implementation gives you a better understanding of why a language is the way it is, which helps you be a better programmer
  • if you want to implement your own programming language, then it is useful to study how other languages have been implemented

Compilation and Interpretation

  • basic compilation
  • basic interpretation
  • compiling to an intermediate language, then run on a virtual machine
  • compiling and linking
  • source-to-source translation, e.g. converting a high-level language into a lower-level language, such as C++ to C
  • dynamic compilation during run-time, e.g. a running LISP program can create and compile new code on the fly
  • just-in-time compilation:
    • Java compile to bytecode, bytecode interpreted; or
    • Java compiled to bytecode, bytecode compiled to assembly code